OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [ppp/] [current/] [tests/] [test_server.sh] - Blame information for rev 838

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
#! /bin/bash
2
#==========================================================================
3
#
4
#      tests/test_server.sh
5
#
6
#      PPP test server script
7
#
8
#==========================================================================
9
# ####ECOSGPLCOPYRIGHTBEGIN####
10
# -------------------------------------------
11
# This file is part of eCos, the Embedded Configurable Operating System.
12
# Copyright (C) 2003, 2004 Free Software Foundation, Inc.
13
#
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
17
# version.
18
#
19
# eCos is distributed in the hope that it will be useful, but WITHOUT
20
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22
# for more details.
23
#
24
# You should have received a copy of the GNU General Public License
25
# along with eCos; if not, write to the Free Software Foundation, Inc.,
26
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
27
#
28
# As a special exception, if other files instantiate templates or use
29
# macros or inline functions from this file, or you compile this file
30
# and link it with other works to produce a work based on this file,
31
# this file does not by itself cause the resulting work to be covered by
32
# the GNU General Public License. However the source code for this file
33
# must still be made available in accordance with section (3) of the GNU
34
# General Public License v2.
35
#
36
# This exception does not invalidate any other reasons why a work based
37
# on this file might be covered by the GNU General Public License.
38
# -------------------------------------------
39
# ####ECOSGPLCOPYRIGHTEND####
40
#==========================================================================
41
######DESCRIPTIONBEGIN####
42
#
43
# Author(s):    nickg
44
# Contributors:
45
# Date:         2003-06-26
46
# Purpose:
47
# Description:
48
#
49
#
50
#####DESCRIPTIONEND####
51
#
52
#==========================================================================
53
 
54
# --------------------------------------------------------------------
55
# Global variables
56
 
57
ppp_prev=
58
ppp_optarg=
59
 
60
ppp_dev=
61
ppp_myip=
62
ppp_hisip=
63
ppp_debug=
64
ppp_redboot=
65
ppp_redboot_baud=38400
66
ppp_baud=$ppp_redboot_baud
67
ppp_flow=crtscts
68
ppp_ping_interval=1
69
 
70
# --------------------------------------------------------------------
71
# Parse the options:
72
 
73
for ppp_option
74
do
75
 
76
  # If the previous option needs an argument, assign it.
77
  if test -n "$ppp_prev"; then
78
    eval "$ppp_prev=\$ppp_option"
79
    ppp_prev=
80
    continue
81
  fi
82
 
83
  # If this option is of the form --thing=value then store
84
  # the value into $ppp_optarg.
85
  case "$ppp_option" in
86
  -*=*) ppp_optarg=`echo "$ppp_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
87
  *) ppp_optarg= ;;
88
  esac
89
 
90
  # Now parse the option
91
 
92
  case "$ppp_option" in
93
 
94
  --dev) ppp_prev=ppp_dev ;;
95
  --dev=*) ppp_dev=$ppp_optarg ;;
96
 
97
  --myip) ppp_prev=ppp_myip ;;
98
  --myip=*) ppp_myip=$ppp_optarg ;;
99
 
100
  --hisip) ppp_prev=ppp_hisip ;;
101
  --hisip=*) ppp_hisip=$ppp_optarg ;;
102
 
103
  --baud) ppp_prev=ppp_baud ;;
104
  --baud=*) ppp_baud=$ppp_optarg ;;
105
 
106
  --flow) ppp_prev=ppp_flow ;;
107
  --flow=*) ppp_flow=$ppp_optarg ;;
108
 
109
  --redboot) ppp_redboot=y ;;
110
 
111
  --redboot-baud) ppp_prev=ppp_redboot_baud ;;
112
  --redboot-baud=*) ppp_redboot_baud=$ppp_optarg ;;
113
 
114
  --debug) ppp_debug=y ;;
115
 
116
  *)
117
          echo "test_server: Unrecognized option: \"$ppp_option\"." >&2
118
          exit 1
119
          ;;
120
  esac
121
done
122
 
123
# --------------------------------------------------------------------
124
# debug echo function. This only generates output if the --debug
125
# flag was given.
126
 
127
dbecho()
128
{
129
    if [ $ppp_debug ] ; then
130
        echo $*
131
    fi
132
}
133
 
134
# --------------------------------------------------------------------
135
# Usage message
136
 
137
usage()
138
{
139
    echo "test_server --dev=<devname>"
140
    echo "            --myip=<myip_addr>"
141
    echo "            --hisip=<hisip_addr>"
142
    echo "            [--baud=<baud_rate>]"
143
    echo "            [--flow=[crtscts|xonxoff|none]]"
144
    echo "            [--redboot [--redboot-baud=<baud_rate>]]"
145
    echo "            [--debug]"
146
    exit 1
147
}
148
 
149
# --------------------------------------------------------------------
150
# Check that all the required options are present, and report their
151
# values.
152
 
153
if [ -z "$ppp_dev" ] ; then usage ; fi
154
if [ -z "$ppp_myip" ] ; then usage ; fi
155
if [ -z "$ppp_hisip" ] ; then usage ; fi
156
 
157
dbecho "Device : " $ppp_dev
158
dbecho "My IP  : " $ppp_myip
159
dbecho "His IP : " $ppp_hisip
160
dbecho "Baud   : " $ppp_baud
161
dbecho "Flow   : " $ppp_flow
162
 
163
if [ "$ppp_flow" == "none" ] ; then ppp_flow="" ; fi
164
 
165
# --------------------------------------------------------------------
166
# Bring the PPP link up by calling pppd. The pid of the PPPD is
167
# stored in pppd_pid for later use.
168
 
169
pppup()
170
{
171
    dbecho pppd $ppp_dev $ppp_baud $ppp_flow local nodetach $ppp_myip:$ppp_hisip $* &
172
    pppd $ppp_dev $ppp_baud $ppp_flow local nodetach $ppp_myip:$ppp_hisip $* &
173
    pppd_pid=$!
174
#    dbecho "PPPD Pid: " $pppd_pid
175
}
176
 
177
# --------------------------------------------------------------------
178
# Simple test for bringing PPP up. Once the link is up the remote
179
# end is pinged for a while and then we bring the link down by
180
# signalling the PPPD.
181
 
182
ppp_up_test()
183
{
184
    dbecho ppp_up_test
185
    pppup
186
    sleep 6
187
    ping -i$ppp_ping_interval -w45 -s3000 -c20 $ppp_hisip
188
    kill -SIGINT $pppd_pid
189
    wait $pppd_pid
190
}
191
 
192
# --------------------------------------------------------------------
193
# Up/down test. In this case the link is brought down by the remote
194
# end.
195
 
196
ppp_updown_test()
197
{
198
    dbecho ppp_updown_test
199
    pppup
200
    wait $pppd_pid
201
}
202
 
203
 
204
# --------------------------------------------------------------------
205
# Chat tests. These use chat itself to test the chat scripts on the
206
# remote end. The tests are:
207
#
208
# chat_test_1 - run throught the entire script
209
# chat_test_2 - simulate a carrier drop
210
# chat_test_3 - simulate a timeout
211
 
212
chat_test_1()
213
{
214
    chat -V "Chat Test" "CONNECT\rlogin:\c"  ppp "Password:\c"  hithere ""  <$ppp_dev >$ppp_dev
215
}
216
 
217
chat_test_2()
218
{
219
    chat -V "Chat Test" "CONNECT\rlogin:\c"  ppp "NO CARRIER"  <$ppp_dev >$ppp_dev
220
}
221
 
222
chat_test_3()
223
{
224
    chat -V "Chat Test" "CONNECT\rlogin:\c"  ppp  <$ppp_dev >$ppp_dev
225
}
226
 
227
# --------------------------------------------------------------------
228
# Authentication tests. These bring up the PPPD with different
229
# authentication requirements against which the remote end tests
230
# itself. The tests are:
231
#
232
# auth_test_1 - authenticate by default method (usually CHAP)
233
# auth_test_2 - require PAP authentication
234
# auth_test_3 - require CHAP authentication
235
 
236
auth_test_1()
237
{
238
    dbecho ppp_up_test
239
    pppup auth
240
    sleep 6
241
    ps -p $pppd_pid >/dev/null
242
    if [ "$?" == "0" ] ; then
243
        ping -i$ppp_ping_interval -w45 -s3000 -c5 $ppp_hisip
244
        kill -SIGINT $pppd_pid
245
        wait $pppd_pid
246
    fi
247
}
248
 
249
auth_test_2()
250
{
251
    dbecho ppp_up_test
252
    pppup auth require-pap
253
    sleep 6
254
    ps -p $pppd_pid >/dev/null
255
    if [ "$?" == "0" ] ; then
256
        ping -i$ppp_ping_interval -w45 -s3000 -c5 $ppp_hisip
257
        kill -SIGINT $pppd_pid
258
        wait $pppd_pid
259
    fi
260
}
261
 
262
auth_test_3()
263
{
264
    dbecho ppp_up_test
265
    pppup auth require-chap
266
    sleep 6
267
    ps -p $pppd_pid >/dev/null
268
    if [ "$?" == "0" ] ; then
269
        ping -i$ppp_ping_interval -w45 -s3000 -c5 $ppp_hisip
270
        kill -SIGINT $pppd_pid
271
        wait $pppd_pid
272
    fi
273
}
274
 
275
 
276
# --------------------------------------------------------------------
277
# TCP echo test. After bringing up the link this test runs the
278
# tcp_source and tcp_sink test programs to exercise the link.  This
279
# can take a long time so it is not really suitable for automated
280
# testing.
281
 
282
tcp_echo_test()
283
{
284
    local sink_pid
285
    dbecho tcp_echo_test
286
    pppup
287
    sleep 10
288
    tcp_sink $ppp_hisip &
289
    sink_pid=$!
290
    sleep 5
291
    tcp_source $ppp_hisip 60
292
    wait $sink_pid
293
    sleep 5
294
    wait $pppd_pid
295
}
296
 
297
# --------------------------------------------------------------------
298
# Network characterisation test. After bringing up the link this test
299
# runs the nc_test_master test program to exercise the link.  This can
300
# take a long time so it is not really suitable for automated testing.
301
 
302
nc_test_slave_test()
303
{
304
    dbecho nc_test_slave_test
305
    pppup
306
    sleep 10
307
    nc_test_master $ppp_hisip
308
    sleep 5
309
    wait $pppd_pid
310
}
311
 
312
# --------------------------------------------------------------------
313
# Change the baud rate. Depending on the value sent as part of the
314
# BAUD message, change the link baudrate.
315
 
316
new_baud()
317
{
318
    ppp_new_baud=`echo $ppp_test | sed 's/.*BAUD:\([0-9]*\).*/\1/'`
319
    dbecho "New Baud " $ppp_new_baud
320
    case $ppp_new_baud in
321
        016) ppp_baud=14400; ppp_ping_interval=6 ;;
322
        017) ppp_baud=19200; ppp_ping_interval=4 ;;
323
        018) ppp_baud=38400; ppp_ping_interval=2 ;;
324
        019) ppp_baud=57600; ppp_ping_interval=2 ;;
325
        020) ppp_baud=115200; ppp_ping_interval=1 ;;
326
        021) ppp_baud=230400 ;;
327
 
328
        *) dbecho "Unknown baud rate: " $ppp_new_baud
329
    esac
330
    dbecho "New Baud Rate : " $ppp_baud
331
}
332
 
333
 
334
 
335
# --------------------------------------------------------------------
336
# Look for a RedBoot> prompt.
337
 
338
ppp_redboot_prompt()
339
{
340
    local done=
341
    dbecho ppp_redboot_prompt
342
 
343
    stty -F $ppp_dev $ppp_redboot_baud
344
 
345
    while [ ! $done ] ; do
346
        chat -V "RedBoot>" "\c" <$ppp_dev >$ppp_dev
347
        if [ "$?" == "0" ] ; then done=1; fi
348
    done
349
}
350
 
351
# --------------------------------------------------------------------
352
# Main loop.
353
 
354
while true ; do
355
 
356
    if [ $ppp_redboot ] ; then ppp_redboot_prompt; fi
357
 
358
    ppp_running=y
359
 
360
    while [ $ppp_running ] ; do
361
 
362
        dbecho ""
363
 
364
        dbecho "Setting baud rate : " $ppp_baud
365
        stty -F $ppp_dev $ppp_baud
366
 
367
        dbecho "Waiting for test..."
368
 
369
        read ppp_test ppp_junk < $ppp_dev
370
 
371
        ppp_test=`echo $ppp_test | sed 's/\([a-zA-Z_:0-9]*\).*/\1/'`
372
 
373
        dbecho "PPP test: >" $ppp_test "<"
374
 
375
        case $ppp_test in
376
 
377
            PPP_UPDOWN) ppp_updown_test ;;
378
 
379
            PPP_UP) ppp_up_test ;;
380
 
381
            CHAT_TEST_1) chat_test_1 ;;
382
            CHAT_TEST_2) chat_test_2 ;;
383
            CHAT_TEST_3) chat_test_3 ;;
384
 
385
            PPP_AUTH_1) auth_test_1 ;;
386
            PPP_AUTH_2) auth_test_2 ;;
387
            PPP_AUTH_3) auth_test_3 ;;
388
 
389
            TCP_ECHO) tcp_echo_test ;;
390
 
391
            NC_TEST_SLAVE) nc_test_slave_test ;;
392
 
393
            BAUD:*) new_baud ;;
394
 
395
            FINISH) unset ppp_running ;;
396
 
397
            *) echo "Unknown test: " $ppp_test ;;
398
 
399
        esac
400
 
401
    done
402
 
403
done
404
 
405
# --------------------------------------------------------------------
406
# end of test_server.sh
407
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.