tcp-udp-tunnel-test: Add test case to test TCP/UDP tunnel.
Refs: #1362
Change-Id: I78f558f61ddd0cf0a363e56081e2e4c735d8156e
diff --git a/test_tcp_udp_tunnel/tcp-udp-tunnel-test.sh b/test_tcp_udp_tunnel/tcp-udp-tunnel-test.sh
new file mode 100755
index 0000000..c9e7710
--- /dev/null
+++ b/test_tcp_udp_tunnel/tcp-udp-tunnel-test.sh
@@ -0,0 +1,70 @@
+#!/usr/bin/env bash
+usage=$'Usage: tcp-udp-tunnel-test.sh [tcp|udp][4|6]'
+if [ $# != 1 ]
+then
+ echo "$usage"
+ exit
+fi
+source ../multi-host.conf
+if [[ ($1 = "tcp4") || ($1 = "udp4") ]]
+then
+ ipaddr="$IP4_D1"
+else
+ ipaddr="[$IP6_D1]"
+fi
+echo "host D IP address $ipaddr"
+
+mkdir -p logs
+
+clean_up() {
+ r=$(ssh $CTRL_D "sudo killall ndn-traffic-server;\
+ sleep 1;\
+ sudo killall nfd" 2>&1)
+ r=$(sudo killall nfd 2>&1)
+}
+
+# start nfd on host A
+sudo nfd > logs/nfd.log 2>&1 &
+
+# start nfd and ndn-traffic-server on host D
+echo "starting nfd and ndn-traffic-server on host D..."
+workdir=$(pwd)
+ssh $CTRL_D "mkdir -p $workdir/logs;\
+ sudo nfd &> $workdir/logs/nfd.log &\
+ sleep 3;\
+ ndn-traffic-server $workdir/NDNTrafficServer.conf > $workdir/logs/server.log 2>&1 &"
+sleep 5
+
+# open a tunnel from host A to host D and set nexthop of ndn:/tunnel-test to D
+echo "preparing tunnel..."
+faceid=$(nfdc create $1://$ipaddr | grep -Po 'FaceId: .*?,' | sed 's/FaceId: //' | sed 's/,//')
+if [[ -z $faceid ]]
+then
+ echo "Fail to create face"
+ clean_up
+ exit 1
+fi
+nfdc add-nexthop ndn:/tunnel-test $faceid
+
+# run ndn-traffic client
+echo "running ndn-traffic client..."
+ndn-traffic -c 100 -i 100 NDNTrafficClient.conf > logs/client.log 2>&1
+
+# stop nfd on hostA
+echo "stopping nfd on host A..."
+sudo killall nfd
+
+# stop ndn-traffic-server and nfd on hostB
+echo "stopping ndn-traffic-server and nfd on host B..."
+clean_up
+
+# examine client log
+echo "analyzing results..."
+output=$(grep "Total Interest Loss" $workdir/logs/client.log | head -1 | cut -d= -f2 | cut -d' ' -f2 | cut -d% -f1)
+if [ $output != '0' ]
+then
+ echo "Expected no Interest Loss. Actual: $output%"
+ echo "For more information, please examine the log at \"$(pwd)/logs\""
+ exit 2
+fi
+echo "Tunnel Test PASSED"