Harald Welte | e057146 | 2018-02-14 15:42:14 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Max | e521445 | 2019-03-14 18:15:27 +0100 | [diff] [blame] | 3 | PIDFILE=/tmp/dumper.pid |
Pau Espin Pedrol | 8fdd313 | 2018-02-15 16:01:50 +0100 | [diff] [blame] | 4 | TCPDUMP=/usr/sbin/tcpdump |
Harald Welte | e057146 | 2018-02-14 15:42:14 +0100 | [diff] [blame] | 5 | TESTCASE=$1 |
| 6 | |
Neels Hofmeyr | ced8acf | 2019-02-26 05:03:22 +0100 | [diff] [blame] | 7 | echo "------ $TESTCASE ------" |
| 8 | date |
| 9 | |
Harald Welte | e057146 | 2018-02-14 15:42:14 +0100 | [diff] [blame] | 10 | if [ "z$TTCN3_PCAP_PATH" = "z" ]; then |
| 11 | TTCN3_PCAP_PATH=/tmp |
| 12 | fi |
| 13 | |
| 14 | if [ -e $PIDFILE ]; then |
| 15 | kill "$(cat "$PIDFILE")" |
| 16 | rm $PIDFILE |
| 17 | fi |
| 18 | |
Max | e521445 | 2019-03-14 18:15:27 +0100 | [diff] [blame] | 19 | if [ "$(id -u)" = "0" ]; then |
| 20 | CMD="$TCPDUMP -U" |
| 21 | else |
Harald Welte | e057146 | 2018-02-14 15:42:14 +0100 | [diff] [blame] | 22 | # NOTE: This requires you to be root or something like |
| 23 | # "laforge ALL=NOPASSWD: /usr/sbin/tcpdump, /bin/kill" in your sudoers file |
Max | e521445 | 2019-03-14 18:15:27 +0100 | [diff] [blame] | 24 | CMD="sudo $TCPDUMP -U" |
Harald Welte | e057146 | 2018-02-14 15:42:14 +0100 | [diff] [blame] | 25 | fi |
Max | e521445 | 2019-03-14 18:15:27 +0100 | [diff] [blame] | 26 | $CMD -s 1500 -n -i any -w "$TTCN3_PCAP_PATH/$TESTCASE.pcap" >$TTCN3_PCAP_PATH/$TESTCASE.pcap.stdout 2>&1 & |
Harald Welte | e057146 | 2018-02-14 15:42:14 +0100 | [diff] [blame] | 27 | PID=$! |
| 28 | echo $PID > $PIDFILE |
Pau Espin Pedrol | b01d313 | 2018-02-15 14:43:58 +0100 | [diff] [blame] | 29 | |
Max | e521445 | 2019-03-14 18:15:27 +0100 | [diff] [blame] | 30 | # Wait until packet dumper creates the pcap file and starts recording. |
| 31 | # We generate some traffic until we see packet dumper catches it. |
Pau Espin Pedrol | b01d313 | 2018-02-15 14:43:58 +0100 | [diff] [blame] | 32 | # Timeout is 10 seconds. |
Pau Espin Pedrol | 8fdd313 | 2018-02-15 16:01:50 +0100 | [diff] [blame] | 33 | ping 127.0.0.1 >/dev/null 2>&1 & |
| 34 | PID=$! |
Pau Espin Pedrol | b01d313 | 2018-02-15 14:43:58 +0100 | [diff] [blame] | 35 | i=0 |
Pau Espin Pedrol | 8fdd313 | 2018-02-15 16:01:50 +0100 | [diff] [blame] | 36 | while [ ! -f "$TTCN3_PCAP_PATH/$TESTCASE.pcap" ] || |
Alexander Couzens | d1f4095 | 2018-05-12 16:52:59 +0200 | [diff] [blame] | 37 | [ "$(stat -c '%s' "$TTCN3_PCAP_PATH/$TESTCASE.pcap")" -eq 32 ] |
Pau Espin Pedrol | b01d313 | 2018-02-15 14:43:58 +0100 | [diff] [blame] | 38 | do |
Max | e521445 | 2019-03-14 18:15:27 +0100 | [diff] [blame] | 39 | echo "Waiting for packet dumper to start... $i" |
Pau Espin Pedrol | b01d313 | 2018-02-15 14:43:58 +0100 | [diff] [blame] | 40 | sleep 1 |
| 41 | i=$((i+1)) |
Pau Espin Pedrol | 8fdd313 | 2018-02-15 16:01:50 +0100 | [diff] [blame] | 42 | if [ $i -eq 10 ]; then |
| 43 | break |
| 44 | fi |
Pau Espin Pedrol | b01d313 | 2018-02-15 14:43:58 +0100 | [diff] [blame] | 45 | done |
Pau Espin Pedrol | 8fdd313 | 2018-02-15 16:01:50 +0100 | [diff] [blame] | 46 | kill $PID |