1#!/bin/sh
2#
3#   $Id: test-step.sh,v 1.1.1.1 1999/05/18 15:33:42 dugsong Exp $
4#
5#   libnet
6#   Copyright (c) 1998, 1999 Mike D. Schiffman <mike@infonexus.com>
7#                             route|daemon9 <route@infonexus.com>
8#   All rights reserved.
9#
10#   Redistribution and use in source and binary forms, with or without
11#   modification, are permitted provided that the following conditions
12#   are met:
13#
14#   1. Redistributions of source code must retain the above copyright
15#      notice, this list of conditions and the following disclaimer.
16#   2. Redistributions in binary form must reproduce the above copyright
17#      notice, this list of conditions and the following disclaimer in the
18#      documentation and/or other materials provided with the distribution.
19#
20#   THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21#   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22#   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23#   ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24#   FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25#   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26#   OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27#   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28#   LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29#   OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30#   SUCH DAMAGE.
31
32#
33#   Hard coded defaults (ie: user hits enter at prompts)
34#
35
36DST_IP=10.0.0.1
37SRC_IP=10.0.0.2
38SRC_PRT=100
39DST_PRT=200
40DEV=de0
41
42echo "Libnet test code step through dealy"
43echo ""
44echo "This script will run you through all the testcode modules and verify
45echo "functionality \(hopefully\).  You may want to use tcpdump in conjuction
46echo "with this script to make sure things are working as they should be."
47echo ""
48echo "Although this script is here to quickly take you through the testcode"
49echo "modules and confirm correct operation, the user is encouraged to descend"
50echo "into the test directories and peruse the code for examples on how to use"
51echo "the library effectively."
52echo ""
53echo "I will need some information from you for some of these tests."
54echo "We don't check for sane input here, so don't be an idiot."
55echo ""
56
57#
58#   Intial setup.
59#
60
61echo -n "Most of the test modules require a source IP address (x.x.x.x): "
62read tmp
63if test "$__tmp" != ""; then
64    SRC_IP=__tmp
65fi
66
67echo -n "And most of the test modules also require a destinaion IP address (x.x.x.x): "
68read __tmp
69if test "$__tmp" != ""; then
70    DST_IP=__tmp
71fi
72
73echo -n "The TCP and UDP tests need a source port: "
74read __tmp
75if test "$__tmp" != ""; then
76    SRC_PRT=__tmp
77fi
78
79echo -n "And a destination port: "
80read __tmp
81if test "$__tmp" != ""; then
82    DST_PRT=__tmp
83fi
84
85echo -n "Some need a link-layer device: "
86read __tml
87if test "$__tmp" != ""; then
88    DEV=__tmp
89fi
90
91echo -n "The ethernet tests need a source ethernet address (x:x:x:x:x:x):"
92read __tmp
93if test "$__tmp" != ""; then
94    SRC_ETH=__tmp
95fi
96
97echo -n "And a destination ethernet address (x:x:x:x:x:x):"
98read __tmp
99if test "$__tmp" != ""; then
100    DST_ETH=__tmp
101fi
102
103echo "Gotit!  The game can start now."
104
105#
106#   Internal win/loss variable setup.
107#
108
109TOTAL_WON=$((0))
110TOTAL_LOST=$((0))
111
112# The TCP tests
113WIN=$((0))
114LOSE=$((0))
115cd TCP
116echo ""
117echo "TCP test suite"
118
119if test -x tcp; then
120    ./tcp -s$SRC_IP.$SRC_PRT -d$DST_IP.$DST_PRT
121    if [ $? -eq -0 ]; then
122        WIN=`expr $WIN + 1`
123    else
124        LOSE=`expr $LOSE + 1`
125    fi
126    echo "-return-"
127    read
128fi
129if test -x tcp+data; then
130    ./tcp+data -s$SRC_IP.$SRC_PRT -d$DST_IP.$DST_PRT
131    if [ $? -eq -0 ]; then
132        WIN=`expr $WIN + 1`
133    else
134        LOSE=`expr $LOSE + 1`
135    fi
136    echo "-return-"
137    read
138fi
139if test -x tcp+data+ipopt; then
140    ./tcp+data+ipopt -s$SRC_IP.$SRC_PRT -d$DST_IP.$DST_PRT
141    if [ $? -eq -0 ]; then
142        WIN=`expr $WIN + 1`
143    else
144        LOSE=`expr $LOSE + 1`
145    fi
146    echo "-return-"
147    read
148fi
149
150echo "completed TCP test suite $WIN test(s) succeeded, $LOSE test(s) failed"
151TOTAL_WON=`expr $TOTAL_WON + $WIN`
152TOTAL_LOST=`expr $TOTAL_LOST + $LOSE`
153cd ..
154
155# The UDP tests
156WIN=$((0))
157LOSE=$((0))
158cd UDP
159echo ""
160echo "UDP test suite"
161
162if test -x udp; then
163    ./udp -s$SRC_IP.$SRC_PRT -d$DST_IP.$DST_PRT
164    if [ $? -eq -0 ]; then
165        WIN=`expr $WIN + 1`
166    else
167        LOSE=`expr $LOSE + 1`
168    fi
169    echo "-return-"
170    read
171fi
172if test -x udp+data; then
173    ./udp+data -s$SRC_IP.$SRC_PRT -d$DST_IP.$DST_PRT
174    if [ $? -eq -0 ]; then
175        WIN=`expr $WIN + 1`
176    else
177        LOSE=`expr $LOSE + 1`
178    fi
179    echo "-return-"
180    read
181fi
182
183echo "completed UDP test suite $WIN test(s) succeeded, $LOSE test(s) failed"
184TOTAL_WON=`expr $TOTAL_WON + $WIN`
185TOTAL_LOST=`expr $TOTAL_LOST + $LOSE`
186cd ..
187
188# The ICMP tests
189WIN=$((0))
190LOSE=$((0))
191cd ICMP
192echo ""
193echo "ICMP test suite"
194
195if test -x icmp_echo; then
196    ./icmp_echo -s$SRC_IP -d$DST_IP
197    if [ $? -eq -0 ]; then
198        WIN=`expr $WIN + 1`
199    else
200        LOSE=`expr $LOSE + 1`
201    fi
202    echo "-return-"
203    read
204fi
205if test -x icmp_timestamp; then
206    ./icmp_timestamp -s$SRC_IP -d$DST_IP
207    if [ $? -eq -0 ]; then
208        WIN=`expr $WIN + 1`
209    else
210        LOSE=`expr $LOSE + 1`
211    fi
212    echo "-return-"
213    read
214fi
215if test -x icmp_timexceed; then
216    ./icmp_timexceed -s$SRC_IP -d$DST_IP
217    if [ $? -eq -0 ]; then
218        WIN=`expr $WIN + 1`
219    else
220        LOSE=`expr $LOSE + 1`
221    fi
222    echo "-return-"
223    read
224fi
225if test -x icmp_unreach; then
226    ./icmp_unreach -s$SRC_IP -d$DST_IP
227    if [ $? -eq -0 ]; then
228        WIN=`expr $WIN + 1`
229    else
230        LOSE=`expr $LOSE + 1`
231    fi
232    echo "-return-"
233    read
234fi
235
236echo "completed ICMP test suite $WIN test(s) succeeded, $LOSE test(s) failed"
237TOTAL_WON=`expr $TOTAL_WON + $WIN`
238TOTAL_LOST=`expr $TOTAL_LOST + $LOSE`
239cd ..
240
241# The Ethernet tests
242WIN=$((0))
243LOSE=$((0))
244cd Ethernet
245echo ""
246echo "Ethernet test suite"
247
248if test -x icmp_mask; then
249    ./icmp_mask -i$DEV -s$SRC_IP -d$DST_IP
250    if [ $? -eq -0 ]; then
251        WIN=`expr $WIN + 1`
252    else
253        LOSE=`expr $LOSE + 1`
254    fi
255    echo "-return-"
256    read
257fi
258if test -x arp; then
259    ./arp -i$DEV
260    if [ $? -eq -0 ]; then
261        WIN=`expr $WIN + 1`
262    else
263        LOSE=`expr $LOSE + 1`
264    fi
265    echo "-return-"
266    read
267fi
268if test -x tcp; then
269    ./tcp -i$DEV -s$SRC_IP.$SRC_PRT -d$DST_IP.$DST_PRT
270    if [ $? -eq -0 ]; then
271        WIN=`expr $WIN + 1`
272    else
273        LOSE=`expr $LOSE + 1`
274    fi
275    echo "-return-"
276    read
277fi
278
279echo "completed Ethernet test suite $WIN test(s) succeeded, $LOSE test(s) failed"
280TOTAL_WON=`expr $TOTAL_WON + $WIN`
281TOTAL_LOST=`expr $TOTAL_LOST + $LOSE`
282cd ..
283
284# Random tests
285
286
287# IP tests
288
289echo "completed entire test suite $TOTAL_WON test(s) succeeded, $TOTAL_LOST test(s) failed"
290
291# EOF
292