3 # Test the capture engine of the Wireshark tools
7 # Wireshark - Network traffic analyzer
8 # By Gerald Combs <gerald@wireshark.org>
9 # Copyright 2005 Ulf Lamping
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License
13 # as published by the Free Software Foundation; either version 2
14 # of the License, or (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 # common exit status values
33 # capture exactly 10 packets
34 capture_step_10packets() {
35 $DUT -i $TRAFFIC_CAPTURE_IFACE -w ./testout.pcap -c 10 -a duration:$TRAFFIC_CAPTURE_DURATION > ./testout.txt 2>&1
37 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
38 test_step_failed "exit status of $DUT: $RETURNVALUE"
39 # part of the Prerequisite checks
40 # probably wrong interface, output the possible interfaces
45 # we should have an output file now
46 if [ ! -f "./testout.pcap" ]; then
47 test_step_failed "No output file!"
51 # ok, we got a capture file, does it contain exactly 10 packets?
52 $CAPINFOS ./testout.pcap > ./testout.txt
53 grep -i 'Number of packets: 10' ./testout.txt > /dev/null
59 # part of the Prerequisite checks
60 # probably wrong interface, output the possible interfaces
62 test_step_failed "No or not enough traffic captured. Probably the wrong interface: $TRAFFIC_CAPTURE_IFACE!"
66 # capture exactly 10 packets using "-w -" (piping to stdout)
67 capture_step_10packets_stdout() {
68 $DUT -i $TRAFFIC_CAPTURE_IFACE -c 10 -a duration:$TRAFFIC_CAPTURE_DURATION -w - > ./testout.pcap 2>./testout.txt
70 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
71 test_step_failed "exit status of $DUT: $RETURNVALUE"
76 # we should have an output file now
77 if [ ! -f "./testout.pcap" ]; then
78 test_step_failed "No output file!"
82 # ok, we got a capture file, does it contain exactly 10 packets?
83 $CAPINFOS ./testout.pcap > ./testout2.txt 2>&1
84 grep -i 'Number of packets: 10' ./testout2.txt > /dev/null
92 test_step_failed "No or not enough traffic captured. Probably the wrong interface: $TRAFFIC_CAPTURE_IFACE!"
96 # capture exactly 2 times 10 packets (multiple files)
97 capture_step_2multi_10packets() {
98 $DUT -i $TRAFFIC_CAPTURE_IFACE -w ./testout.pcap -c 10 -a duration:$TRAFFIC_CAPTURE_DURATION > ./testout.txt 2>&1
100 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
101 test_step_failed "exit status of $DUT: $RETURNVALUE"
102 # part of the Prerequisite checks
103 # probably wrong interface, output the possible interfaces
108 # we should have an output file now
109 if [ ! -f "./testout.pcap" ]; then
110 test_step_failed "No output file!"
114 # ok, we got a capture file, does it contain exactly 10 packets?
115 $CAPINFOS ./testout.pcap > ./testout.txt
116 grep -i 'Number of packets: 10' ./testout.txt > /dev/null
117 if [ $? -eq 0 ]; then
122 test_step_failed "Probably the wrong interface (no traffic captured)!"
126 # capture with a very unlikely read filter, packets must be zero afterwards
127 capture_step_read_filter() {
128 # valid, but very unlikely filter
129 $DUT -i $TRAFFIC_CAPTURE_IFACE -w ./testout.pcap -a duration:$TRAFFIC_CAPTURE_DURATION -R 'dcerpc.cn_call_id==123456' -c 10 > ./testout.txt 2>&1
131 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
132 test_step_failed "exit status: $RETURNVALUE"
136 # we should have an output file now
137 if [ ! -f "./testout.pcap" ]; then
138 test_step_failed "No output file!"
142 # ok, we got a capture file, does it contain exactly 0 packets?
143 $CAPINFOS ./testout.pcap > ./testout.txt
144 grep -i 'Number of packets: 0' ./testout.txt > /dev/null
145 if [ $? -eq 0 ]; then
150 test_step_failed "Capture file should contain zero packets!"
155 # capture with a snapshot length
156 capture_step_snapshot() {
157 # capture with a snapshot length of 68 bytes for $TRAFFIC_CAPTURE_DURATION seconds
158 # this should result in no packets
159 $DUT -i $TRAFFIC_CAPTURE_IFACE -w ./testout.pcap -s 68 -a duration:$TRAFFIC_CAPTURE_DURATION > ./testout.txt 2>&1
161 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
162 test_step_failed "exit status: $RETURNVALUE"
166 # we should have an output file now
167 if [ ! -f "./testout.pcap" ]; then
168 test_step_failed "No output file!"
172 # use tshark to filter out all packets, which are larger than 68 bytes
173 $TSHARK -r ./testout.pcap -w ./testout2.pcap -R 'frame.cap_len>68' > ./testout.txt 2>&1
175 # ok, we got a capture file, does it contain exactly 0 packets?
176 $CAPINFOS ./testout2.pcap > ./testout.txt
177 grep -i 'Number of packets: 0' ./testout.txt > /dev/null
178 if [ $? -eq 0 ]; then
183 test_step_failed "Capture file should contain zero packets!"
188 wireshark_capture_suite() {
189 # Q: quit after cap, k: start capture immediately
190 DUT="$WIRESHARK -Q -k"
191 test_step_add "Capture 10 packets" capture_step_10packets
192 # piping to stdout doesn't work with Wireshark and capturing!
193 #test_step_add "Capture 10 packets using stdout: -w -" capture_step_10packets_stdout
194 # read filter doesn't work with Wireshark and capturing!
195 #test_step_add "Capture read filter (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_read_filter
196 test_step_add "Capture snapshot length 68 bytes (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_snapshot
199 tshark_capture_suite() {
201 test_step_add "Capture 10 packets" capture_step_10packets
202 test_step_add "Capture 10 packets using stdout: -w -" capture_step_10packets_stdout
203 test_step_add "Capture read filter (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_read_filter
204 test_step_add "Capture snapshot length 68 bytes (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_snapshot
207 dumpcap_capture_suite() {
210 test_step_add "Capture 10 packets" capture_step_10packets
211 test_step_add "Capture 10 packets using stdout: -w -" capture_step_10packets_stdout
212 # read (display) filters intentionally doesn't work with dumpcap!
213 #test_step_add "Capture read filter (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_read_filter
214 test_step_add "Capture snapshot length 68 bytes (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_snapshot
217 capture_cleanup_step() {
221 rm -f ./testout2.pcap
225 test_step_set_pre capture_cleanup_step
226 test_step_set_post capture_cleanup_step
227 test_remark_add "Capture - need some traffic on interface: \"$TRAFFIC_CAPTURE_IFACE\""
228 test_suite_add "TShark capture" tshark_capture_suite
229 test_suite_add "Wireshark capture" wireshark_capture_suite
230 test_suite_add "Dumpcap capture" dumpcap_capture_suite