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, writeto the Free Software
23 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 # common exit status values
32 capture_test_output_print() {
35 if [[ -f "$f" ]]; then
44 # Generate some traffic for quiet networks.
45 # This will have to be adjusted for non-Windows systems.
47 # the following will run in the background and return immediately
50 for (( x=28; x<=58; x++ )) # in effect: number the packets
52 # How does ping _not_ have a standard set of arguments?
55 ping -n 1 -l $x www.wireshark.org ;;
57 /usr/sbin/ping www.wireshark.org $x 1 ;;
59 ping -c 1 -s $x www.wireshark.org ;;
64 } > ./testout_ping.txt 2>&1 &
69 rm -f ./testout_ping.txt
72 # capture exactly 10 packets
73 capture_step_10packets() {
74 if [ $SKIP_CAPTURE -ne 0 ] ; then
82 $DUT -i $TRAFFIC_CAPTURE_IFACE $TRAFFIC_CAPTURE_PROMISC \
85 -a duration:$TRAFFIC_CAPTURE_DURATION \
90 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
92 capture_test_output_print ./testout.txt
93 # part of the Prerequisite checks
94 # wrong interface ? output the possible interfaces
96 test_step_failed "exit status of $DUT: $RETURNVALUE"
100 # we should have an output file now
101 if [ ! -f "./testout.pcap" ]; then
102 capture_test_output ./testout.txt
103 test_step_failed "No output file!"
107 # ok, we got a capture file, does it contain exactly 10 packets?
108 $CAPINFOS ./testout.pcap > ./testout2.txt
109 grep -Ei 'Number of packets:[[:blank:]]+10' ./testout2.txt > /dev/null
110 if [ $? -eq 0 ]; then
114 $TSHARK -ta -r ./testout.pcap >> ./testout2.txt
115 capture_test_output_print ./testout_ping.txt ./testout.txt ./testout2.txt
116 # part of the Prerequisite checks
117 # probably wrong interface, output the possible interfaces
119 test_step_failed "No or not enough traffic captured. Probably the wrong interface: $TRAFFIC_CAPTURE_IFACE!"
123 # capture exactly 10 packets using "-w -" (piping to stdout)
124 capture_step_10packets_stdout() {
125 if [ $SKIP_CAPTURE -ne 0 ] ; then
133 $DUT -i $TRAFFIC_CAPTURE_IFACE $TRAFFIC_CAPTURE_PROMISC \
135 -a duration:$TRAFFIC_CAPTURE_DURATION \
138 > ./testout.pcap 2>>./testout.txt
140 date >> ./testout.txt
141 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
145 test_step_failed "exit status of $DUT: $RETURNVALUE"
149 # we should have an output file now
150 if [ ! -f "./testout.pcap" ]; then
151 test_step_failed "No output file!"
155 # ok, we got a capture file, does it contain exactly 10 packets?
156 $CAPINFOS ./testout.pcap > ./testout2.txt 2>&1
157 grep -Ei 'Number of packets:[[:blank:]]+10' ./testout2.txt > /dev/null
158 if [ $? -eq 0 ]; then
165 test_step_failed "No or not enough traffic captured. Probably the wrong interface: $TRAFFIC_CAPTURE_IFACE!"
169 # capture packets via a fifo
170 capture_step_fifo() {
172 (cat $CAPFILE; sleep 1; tail -c +25 $CAPFILE) > fifo &
173 $DUT -i fifo $TRAFFIC_CAPTURE_PROMISC \
175 -a duration:$TRAFFIC_CAPTURE_DURATION \
179 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
180 test_step_failed "exit status of $DUT: $RETURNVALUE"
184 # we should have an output file now
185 if [ ! -f "./testout.pcap" ]; then
186 test_step_failed "No output file!"
190 # ok, we got a capture file, does it contain exactly 8 packets?
191 $CAPINFOS ./testout.pcap > ./testout.txt
192 grep -Ei 'Number of packets:[[:blank:]]+8' ./testout.txt > /dev/null
193 if [ $? -eq 0 ]; then
198 test_step_failed "No or not enough traffic captured."
202 # capture exactly 2 times 10 packets (multiple files)
203 capture_step_2multi_10packets() {
204 if [ $SKIP_CAPTURE -ne 0 ] ; then
212 $DUT -i $TRAFFIC_CAPTURE_IFACE $TRAFFIC_CAPTURE_PROMISC \
215 -a duration:$TRAFFIC_CAPTURE_DURATION \
217 >> ./testout.txt 2>&1
220 date >> ./testout.txt
221 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
224 # part of the Prerequisite checks
225 # probably wrong interface, output the possible interfaces
227 test_step_failed "exit status of $DUT: $RETURNVALUE"
231 # we should have an output file now
232 if [ ! -f "./testout.pcap" ]; then
233 test_step_failed "No output file!"
237 # ok, we got a capture file, does it contain exactly 10 packets?
238 $CAPINFOS ./testout.pcap > ./testout.txt
239 grep -Ei 'Number of packets:[[:blank:]]+10' ./testout.txt > /dev/null
240 if [ $? -eq 0 ]; then
245 test_step_failed "Probably the wrong interface (no traffic captured)!"
249 # capture with a very unlikely read filter, packets must be zero afterwards
250 capture_step_read_filter() {
251 if [ $SKIP_CAPTURE -ne 0 ] ; then
258 # valid, but very unlikely filter
260 $DUT -i $TRAFFIC_CAPTURE_IFACE $TRAFFIC_CAPTURE_PROMISC \
262 -a duration:$TRAFFIC_CAPTURE_DURATION \
263 -R 'dcerpc.cn_call_id==123456' \
266 >> ./testout.txt 2>&1
268 date >> ./testout.txt
269 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
272 # part of the Prerequisite checks
273 # wrong interface ? output the possible interfaces
275 test_step_failed "exit status: $RETURNVALUE"
279 # we should have an output file now
280 if [ ! -f "./testout.pcap" ]; then
281 test_step_failed "No output file!"
285 # ok, we got a capture file, does it contain exactly 0 packets?
286 $CAPINFOS ./testout.pcap > ./testout.txt
287 grep -Ei 'Number of packets:[[:blank:]]+0' ./testout.txt > /dev/null
288 if [ $? -eq 0 ]; then
293 test_step_failed "Capture file should contain zero packets!"
298 # capture with a snapshot length
299 capture_step_snapshot() {
300 if [ $SKIP_CAPTURE -ne 0 ] ; then
307 # capture with a snapshot length of 68 bytes for $TRAFFIC_CAPTURE_DURATION seconds
308 # this should result in no packets greater than 68 bytes
310 $DUT -i $TRAFFIC_CAPTURE_IFACE $TRAFFIC_CAPTURE_PROMISC \
313 -a duration:$TRAFFIC_CAPTURE_DURATION \
315 >> ./testout.txt 2>&1
317 date >> ./testout.txt
318 if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
321 # part of the Prerequisite checks
322 # wrong interface ? output the possible interfaces
324 test_step_failed "exit status: $RETURNVALUE"
328 # we should have an output file now
329 if [ ! -f "./testout.pcap" ]; then
330 test_step_failed "No output file!"
334 # use tshark to filter out all packets, which are larger than 68 bytes
335 $TSHARK -r ./testout.pcap -w ./testout2.pcap -R 'frame.cap_len>68' > ./testout.txt 2>&1
337 # ok, we got a capture file, does it contain exactly 0 packets?
338 $CAPINFOS ./testout2.pcap > ./testout.txt
339 grep -Ei 'Number of packets:[[:blank:]]+0' ./testout.txt > /dev/null
340 if [ $? -eq 0 ]; then
345 test_step_failed "Capture file should contain zero packets!"
350 wireshark_capture_suite() {
351 # Q: quit after cap, k: start capture immediately
352 DUT="$WIRESHARK -Q -k"
353 test_step_add "Capture 10 packets" capture_step_10packets
354 # piping to stdout doesn't work with Wireshark and capturing!
355 #test_step_add "Capture 10 packets using stdout: -w -" capture_step_10packets_stdout
356 # read filter doesn't work with Wireshark and capturing!
357 #test_step_add "Capture read filter (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_read_filter
358 test_step_add "Capture snapshot length 68 bytes (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_snapshot
361 tshark_capture_suite() {
363 test_step_add "Capture 10 packets" capture_step_10packets
364 test_step_add "Capture 10 packets using stdout: -w -" capture_step_10packets_stdout
365 if [ $TEST_FIFO ]; then
366 test_step_add "Capture via fifo" capture_step_fifo
368 # tshark now using dumpcap for capturing, read filters won't work by definition
369 #test_step_add "Capture read filter (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_read_filter
370 test_step_add "Capture snapshot length 68 bytes (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_snapshot
373 dumpcap_capture_suite() {
376 test_step_add "Capture 10 packets" capture_step_10packets
377 test_step_add "Capture 10 packets using stdout: -w -" capture_step_10packets_stdout
378 if [ $TEST_FIFO ]; then
379 test_step_add "Capture via fifo" capture_step_fifo
381 # read (display) filters intentionally doesn't work with dumpcap!
382 #test_step_add "Capture read filter (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_read_filter
383 test_step_add "Capture snapshot length 68 bytes (${TRAFFIC_CAPTURE_DURATION}s)" capture_step_snapshot
386 capture_cleanup_step() {
391 rm -f ./testout2.pcap
395 test_step_set_pre capture_cleanup_step
396 test_step_set_post capture_cleanup_step
397 test_remark_add "Capture - need some traffic on interface: \"$TRAFFIC_CAPTURE_IFACE\""
398 test_suite_add "Dumpcap capture" dumpcap_capture_suite
399 test_suite_add "TShark capture" tshark_capture_suite
400 test_suite_add "Wireshark capture" wireshark_capture_suite