2 #==========================================================================
6 # PPP test server script
8 #==========================================================================
9 #####ECOSGPLCOPYRIGHTBEGIN####
10 # -------------------------------------------
11 # This file is part of eCos, the Embedded Configurable Operating System.
12 # Copyright (C) 2003, 2004 eCosCentric Ltd.
14 # eCos is free software; you can redistribute it and/or modify it under
15 # the terms of the GNU General Public License as published by the Free
16 # Software Foundation; either version 2 or (at your option) any later version.
18 # eCos is distributed in the hope that it will be useful, but WITHOUT ANY
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 # You should have received a copy of the GNU General Public License along
24 # with eCos; if not, write to the Free Software Foundation, Inc.,
25 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27 # As a special exception, if other files instantiate templates or use macros
28 # or inline functions from this file, or you compile this file and link it
29 # with other works to produce a work based on this file, this file does not
30 # by itself cause the resulting work to be covered by the GNU General Public
31 # License. However the source code for this file must still be made available
32 # in accordance with section (3) of the GNU General Public License.
34 # This exception does not invalidate any other reasons why a work based on
35 # this file might be covered by the GNU General Public License.
37 # -------------------------------------------
38 #####ECOSGPLCOPYRIGHTEND####
39 #==========================================================================
40 ######DESCRIPTIONBEGIN####
49 #####DESCRIPTIONEND####
51 #==========================================================================
53 # --------------------------------------------------------------------
64 ppp_redboot_baud=38400
65 ppp_baud=$ppp_redboot_baud
69 # --------------------------------------------------------------------
75 # If the previous option needs an argument, assign it.
76 if test -n "$ppp_prev"; then
77 eval "$ppp_prev=\$ppp_option"
82 # If this option is of the form --thing=value then store
83 # the value into $ppp_optarg.
85 -*=*) ppp_optarg=`echo "$ppp_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
89 # Now parse the option
93 --dev) ppp_prev=ppp_dev ;;
94 --dev=*) ppp_dev=$ppp_optarg ;;
96 --myip) ppp_prev=ppp_myip ;;
97 --myip=*) ppp_myip=$ppp_optarg ;;
99 --hisip) ppp_prev=ppp_hisip ;;
100 --hisip=*) ppp_hisip=$ppp_optarg ;;
102 --baud) ppp_prev=ppp_baud ;;
103 --baud=*) ppp_baud=$ppp_optarg ;;
105 --flow) ppp_prev=ppp_flow ;;
106 --flow=*) ppp_flow=$ppp_optarg ;;
108 --redboot) ppp_redboot=y ;;
110 --redboot-baud) ppp_prev=ppp_redboot_baud ;;
111 --redboot-baud=*) ppp_redboot_baud=$ppp_optarg ;;
113 --debug) ppp_debug=y ;;
116 echo "test_server: Unrecognized option: \"$ppp_option\"." >&2
122 # --------------------------------------------------------------------
123 # debug echo function. This only generates output if the --debug
128 if [ $ppp_debug ] ; then
133 # --------------------------------------------------------------------
138 echo "test_server --dev=<devname>"
139 echo " --myip=<myip_addr>"
140 echo " --hisip=<hisip_addr>"
141 echo " [--baud=<baud_rate>]"
142 echo " [--flow=[crtscts|xonxoff|none]]"
143 echo " [--redboot [--redboot-baud=<baud_rate>]]"
148 # --------------------------------------------------------------------
149 # Check that all the required options are present, and report their
152 if [ -z "$ppp_dev" ] ; then usage ; fi
153 if [ -z "$ppp_myip" ] ; then usage ; fi
154 if [ -z "$ppp_hisip" ] ; then usage ; fi
156 dbecho "Device : " $ppp_dev
157 dbecho "My IP : " $ppp_myip
158 dbecho "His IP : " $ppp_hisip
159 dbecho "Baud : " $ppp_baud
160 dbecho "Flow : " $ppp_flow
162 if [ "$ppp_flow" == "none" ] ; then ppp_flow="" ; fi
164 # --------------------------------------------------------------------
165 # Bring the PPP link up by calling pppd. The pid of the PPPD is
166 # stored in pppd_pid for later use.
170 dbecho pppd $ppp_dev $ppp_baud $ppp_flow local nodetach $ppp_myip:$ppp_hisip $* &
171 pppd $ppp_dev $ppp_baud $ppp_flow local nodetach $ppp_myip:$ppp_hisip $* &
173 # dbecho "PPPD Pid: " $pppd_pid
176 # --------------------------------------------------------------------
177 # Simple test for bringing PPP up. Once the link is up the remote
178 # end is pinged for a while and then we bring the link down by
179 # signalling the PPPD.
186 ping -i$ppp_ping_interval -w45 -s3000 -c20 $ppp_hisip
187 kill -SIGINT $pppd_pid
191 # --------------------------------------------------------------------
192 # Up/down test. In this case the link is brought down by the remote
197 dbecho ppp_updown_test
203 # --------------------------------------------------------------------
204 # Chat tests. These use chat itself to test the chat scripts on the
205 # remote end. The tests are:
207 # chat_test_1 - run throught the entire script
208 # chat_test_2 - simulate a carrier drop
209 # chat_test_3 - simulate a timeout
213 chat -V "Chat Test" "CONNECT\rlogin:\c" ppp "Password:\c" hithere "" <$ppp_dev >$ppp_dev
218 chat -V "Chat Test" "CONNECT\rlogin:\c" ppp "NO CARRIER" <$ppp_dev >$ppp_dev
223 chat -V "Chat Test" "CONNECT\rlogin:\c" ppp <$ppp_dev >$ppp_dev
226 # --------------------------------------------------------------------
227 # Authentication tests. These bring up the PPPD with different
228 # authentication requirements against which the remote end tests
229 # itself. The tests are:
231 # auth_test_1 - authenticate by default method (usually CHAP)
232 # auth_test_2 - require PAP authentication
233 # auth_test_3 - require CHAP authentication
240 ps -p $pppd_pid >/dev/null
241 if [ "$?" == "0" ] ; then
242 ping -i$ppp_ping_interval -w45 -s3000 -c5 $ppp_hisip
243 kill -SIGINT $pppd_pid
251 pppup auth require-pap
253 ps -p $pppd_pid >/dev/null
254 if [ "$?" == "0" ] ; then
255 ping -i$ppp_ping_interval -w45 -s3000 -c5 $ppp_hisip
256 kill -SIGINT $pppd_pid
264 pppup auth require-chap
266 ps -p $pppd_pid >/dev/null
267 if [ "$?" == "0" ] ; then
268 ping -i$ppp_ping_interval -w45 -s3000 -c5 $ppp_hisip
269 kill -SIGINT $pppd_pid
275 # --------------------------------------------------------------------
276 # TCP echo test. After bringing up the link this test runs the
277 # tcp_source and tcp_sink test programs to exercise the link. This
278 # can take a long time so it is not really suitable for automated
287 tcp_sink $ppp_hisip &
290 tcp_source $ppp_hisip 60
296 # --------------------------------------------------------------------
297 # Network characterisation test. After bringing up the link this test
298 # runs the nc_test_master test program to exercise the link. This can
299 # take a long time so it is not really suitable for automated testing.
303 dbecho nc_test_slave_test
306 nc_test_master $ppp_hisip
311 # --------------------------------------------------------------------
312 # Change the baud rate. Depending on the value sent as part of the
313 # BAUD message, change the link baudrate.
317 ppp_new_baud=`echo $ppp_test | sed 's/.*BAUD:\([0-9]*\).*/\1/'`
318 dbecho "New Baud " $ppp_new_baud
319 case $ppp_new_baud in
320 016) ppp_baud=14400; ppp_ping_interval=6 ;;
321 017) ppp_baud=19200; ppp_ping_interval=4 ;;
322 018) ppp_baud=38400; ppp_ping_interval=2 ;;
323 019) ppp_baud=57600; ppp_ping_interval=2 ;;
324 020) ppp_baud=115200; ppp_ping_interval=1 ;;
325 021) ppp_baud=230400 ;;
327 *) dbecho "Unknown baud rate: " $ppp_new_baud
329 dbecho "New Baud Rate : " $ppp_baud
334 # --------------------------------------------------------------------
335 # Look for a RedBoot> prompt.
340 dbecho ppp_redboot_prompt
342 stty -F $ppp_dev $ppp_redboot_baud
344 while [ ! $done ] ; do
345 chat -V "RedBoot>" "\c" <$ppp_dev >$ppp_dev
346 if [ "$?" == "0" ] ; then done=1; fi
350 # --------------------------------------------------------------------
355 if [ $ppp_redboot ] ; then ppp_redboot_prompt; fi
359 while [ $ppp_running ] ; do
363 dbecho "Setting baud rate : " $ppp_baud
364 stty -F $ppp_dev $ppp_baud
366 dbecho "Waiting for test..."
368 read ppp_test ppp_junk < $ppp_dev
370 ppp_test=`echo $ppp_test | sed 's/\([a-zA-Z_:0-9]*\).*/\1/'`
372 dbecho "PPP test: >" $ppp_test "<"
376 PPP_UPDOWN) ppp_updown_test ;;
378 PPP_UP) ppp_up_test ;;
380 CHAT_TEST_1) chat_test_1 ;;
381 CHAT_TEST_2) chat_test_2 ;;
382 CHAT_TEST_3) chat_test_3 ;;
384 PPP_AUTH_1) auth_test_1 ;;
385 PPP_AUTH_2) auth_test_2 ;;
386 PPP_AUTH_3) auth_test_3 ;;
388 TCP_ECHO) tcp_echo_test ;;
390 NC_TEST_SLAVE) nc_test_slave_test ;;
394 FINISH) unset ppp_running ;;
396 *) echo "Unknown test: " $ppp_test ;;
404 # --------------------------------------------------------------------
405 # end of test_server.sh