This repo is obsolete, please see git://git.code.sf.net/p/dummynet/code@master
[ipfw.git] / test / basic_ipfw.sh
1 #!/bin/sh
2
3 IPFW=./ipfw/ipfw
4 PING=/bin/ping
5 RH=127.0.0.1            # remote host
6 R=10                    # test rule number
7 P=1                     # test pipe number
8
9 abort()
10
11 echo $* 
12 }
13
14 #insmod dummynet2/ipfw_mod.ko
15 #$IPFW show > /dev/null
16 #$IPFW pipe show 
17 echo "Flushing rules, do you agree ?"
18 $IPFW flush
19
20 # test_msg rule counter
21 clean() 
22
23         $IPFW delete $R 2> /dev/null
24         $IPFW pipe $P delete 2> /dev/null
25 }
26
27 # simple counter/allow test
28 echo -n "counter/allow test..."
29 clean
30 $IPFW add $R allow icmp from any to 127.0.0.1 > /dev/null
31 $PING -f -c100 $RH > /dev/null
32 counter=`$IPFW show | grep $R | head -n 1 | cut -d " " -f3`
33 [ ! $counter -eq 400 ] && abort "Wrong counter $counter 400"
34 echo "...OK"
35
36 # simple drop test
37 echo -n "deny test..."
38 clean
39 $IPFW add $R deny icmp from any to 127.0.0.1 > /dev/null
40 $PING -f -c10 -W 1 $RH > /dev/null
41 counter=`$IPFW show | grep $R | head -n 1 | cut -d " " -f4`
42 [ ! $counter -eq 10 ] && abort "Wrong counter $counter 10"
43 echo "...OK"
44
45 # pipe delay test
46 echo -n "pipe delay test..."
47 clean
48 $IPFW pipe $P config delay 2000ms >/dev/null
49 $IPFW add $R pipe $P icmp from any to $RH >/dev/null
50 $PING -f -c10 -W 1 $RH > /dev/null
51 counter1=`$IPFW show | grep $R | head -n 1 | cut -d " " -f4`
52 sleep 2
53 counter2=`$IPFW show | grep $R | head -n 1 | cut -d " " -f4`
54 [ ! $counter1 -eq 10 ] && abort "Wrong counter $counter 10"
55 [ ! $counter2 -eq 20 ] && abort "Wrong counter $counter 20"
56 echo "...OK"
57
58 # pipe bw test
59 echo -n "pipe bw test..."
60 clean
61 $IPFW pipe $P config bw 2Kbit/s >/dev/null
62 $IPFW add $R pipe $P icmp from any to $RH >/dev/null
63 $PING -i 0.1 -c10 -W 1 $RH > /dev/null
64 counter=`$IPFW show | grep $R | head -n 1 | cut -d " " -f4`
65 [ $counter -gt 30 ] && abort "Wrong counter $counter should be < 30"
66 sleep 1
67 counter=`$IPFW show | grep $R | head -n 1 | cut -d " " -f4`
68 [ $counter -gt 30 ] && abort "Wrong counter $counter should be < 30"
69 echo "...OK"
70
71 # Final clean
72 clean