Create dummy gsmtap sink with netcat

otherwise ICMP messages appear in pcap files and some messages are lost
since they seem to be dropped by the kernel.

Change-Id: Id69d98db63f8260067ad6bc1525fb05c936912f2
diff --git a/ttcn3-tcpdump-start.sh b/ttcn3-tcpdump-start.sh
index 9bf3c0a..3ad14c0 100755
--- a/ttcn3-tcpdump-start.sh
+++ b/ttcn3-tcpdump-start.sh
@@ -1,10 +1,22 @@
 #!/bin/sh
 
-PIDFILE=/tmp/dumper.pid
+PIDFILE_PCAP=/tmp/pcap.pid
 TCPDUMP=/usr/sbin/tcpdump
 DUMPCAP=/usr/bin/dumpcap
+
+PIDFILE_NETCAT=/tmp/netcat.pid
+NETCAT=/bin/nc
+GSMTAP_PORT=4729
+
 TESTCASE=$1
 
+kill_rm_pidfile() {
+	if [ -e $1 ]; then
+		kill "$(cat "$1")"
+		rm $1
+	fi
+}
+
 echo "------ $TESTCASE ------"
 date
 
@@ -12,10 +24,8 @@
 	TTCN3_PCAP_PATH=/tmp
 fi
 
-if [ -e $PIDFILE ]; then
-	kill "$(cat "$PIDFILE")"
-	rm $PIDFILE
-fi
+kill_rm_pidfile $PIDFILE_NETCAT
+kill_rm_pidfile $PIDFILE_PCAP
 
 if [ "$(id -u)" = "0" ]; then
 	CMD="$TCPDUMP -U"
@@ -39,9 +49,14 @@
     fi
 fi
 
+# Create a dummy sink for GSMTAP packets
+$NETCAT -l -u -k -p $GSMTAP_PORT >/dev/null 2>$TESTCASE.netcat.stderr &
+PID=$!
+echo $PID > $PIDFILE_NETCAT
+
 $CMD -s 1500 -n -i any -w "$TTCN3_PCAP_PATH/$TESTCASE.pcap" >$TTCN3_PCAP_PATH/$TESTCASE.pcap.stdout 2>&1 &
 PID=$!
-echo $PID > $PIDFILE
+echo $PID > $PIDFILE_PCAP
 
 # Wait until packet dumper creates the pcap file and starts recording.
 # We generate some traffic until we see packet dumper catches it.
diff --git a/ttcn3-tcpdump-stop.sh b/ttcn3-tcpdump-stop.sh
index c1ab9d0..1f4da3d 100755
--- a/ttcn3-tcpdump-stop.sh
+++ b/ttcn3-tcpdump-stop.sh
@@ -1,9 +1,24 @@
 #!/bin/sh
 
-PIDFILE=/tmp/dumper.pid
+PIDFILE_PCAP=/tmp/pcap.pid
+PIDFILE_NETCAT=/tmp/netcat.pid
 TESTCASE=$1
 VERDICT="$2"
 
+kill_rm_pidfile() {
+if [ -e $1 ]; then
+        PSNAME="$(ps -q "$(cat "$1")" -o comm=)"
+	if [ "$PSNAME" != "sudo" ]; then
+		kill "$(cat "$1")"
+	else
+	# NOTE: This requires you to be root or something like
+	# "laforge ALL=NOPASSWD: /usr/sbin/tcpdump, /bin/kill" in your sudoers file
+		sudo kill "$(cat "$1")"
+	fi
+	rm $1
+fi
+}
+
 date
 
 if [ x"$VERDICT" = x"pass" ]; then
@@ -31,14 +46,5 @@
 	i=$((i+1))
 done
 
-if [ -e $PIDFILE ]; then
-        DUMPER="$(ps -q "$(cat "$PIDFILE")" -o comm=)"
-	if [ "$DUMPER" != "sudo" ]; then
-		kill "$(cat "$PIDFILE")"
-	else
-	# NOTE: This requires you to be root or something like
-	# "laforge ALL=NOPASSWD: /usr/sbin/tcpdump, /bin/kill" in your sudoers file
-		sudo kill "$(cat "$PIDFILE")"
-	fi
-	rm $PIDFILE
-fi
+kill_rm_pidfile "$PIDFILE_PCAP"
+kill_rm_pidfile "$PIDFILE_NETCAT"