broadcast-test: BroadcastStrategy test scenario
Change-Id: Ie43803f2acadf777bc0832e26f5265094722dbb7
Refs: #1389
diff --git a/test_broadcast/NDNTrafficClient.conf b/test_broadcast/NDNTrafficClient.conf
new file mode 100644
index 0000000..79b6a94
--- /dev/null
+++ b/test_broadcast/NDNTrafficClient.conf
@@ -0,0 +1,6 @@
+##########
+TrafficPercentage=100
+Name=ndn:/test-bcast/A
+ExpectedContent=AAAAAAAA
+NameAppendBytes=8
+##########
diff --git a/test_broadcast/NDNTrafficServer.conf b/test_broadcast/NDNTrafficServer.conf
new file mode 100644
index 0000000..499a882
--- /dev/null
+++ b/test_broadcast/NDNTrafficServer.conf
@@ -0,0 +1,4 @@
+##########
+Name=ndn:/test-bcast
+Content=AAAAAAAA
+##########
diff --git a/test_broadcast/README.md b/test_broadcast/README.md
new file mode 100644
index 0000000..2b2068a
--- /dev/null
+++ b/test_broadcast/README.md
@@ -0,0 +1,17 @@
+# BroadcastStrategy test scenario
+
+Test Broadcast Strategy
+
+Steps:
+
+1. Start NFD on A,B,C,D.
+2. On host B,C, start ndn-traffic-server to serve `ndn:/test-bcast`.
+3. On host A, invoke nfdc to set BroadcastStrategy at `ndn:/test-bcast`.
+4. On host A, invoke nfdc to create UDP tunnel to B, and add nexthop for `ndn:/test-bcast` to this face with cost 10.
+5. On host A, invoke nfdc to create UDP tunnel to C, and add nexthop for `ndn:/test-bcast` to this face with cost 20.
+6. On host D, invoke nfdc to create UDP tunnel to A, and add nexthop for `ndn:/test-bcast` to this face.
+7. On host D, execute ndn-traffic-client to send 100 Interest to `ndn:/test-bcast/A/<random>`.
+8. On host B,C, stop ndn-traffic-server.
+ Fail if total served Interests on either host is less than 80.
+9. On host D, invoke nfd-status to observe counters on the face created in step 6.
+ Fail if total received Datas on this face is greater than 120 (because A should not forward the second copy of Data to D after PIT entry is satisfied).
diff --git a/test_broadcast/broadcast-test.sh b/test_broadcast/broadcast-test.sh
new file mode 100755
index 0000000..9cbc763
--- /dev/null
+++ b/test_broadcast/broadcast-test.sh
@@ -0,0 +1,91 @@
+#!/usr/bin/env bash
+source ../multi-host.conf
+mkdir -p logs
+workdir=$(pwd)
+
+clean_up() {
+ echo "cleaning up..."
+ r=$(sudo killall nfd 2>&1)
+ r=$(ssh $CTRL_B "sudo killall ndn-traffic-server 2>&1; sudo killall nfd 2>&1" 2>&1)
+ r=$(ssh $CTRL_C "sudo killall ndn-traffic-server 2>&1; sudo killall nfd 2>&1" 2>&1)
+ r=$(ssh $CTRL_D "sudo killall nfd 2>&1" 2>&1)
+}
+
+# start nfd on all hosts
+echo "starting nfd on all hosts..."
+ssh $CTRL_B "mkdir -p $workdir/logs;\
+ sudo nfd &> $workdir/logs/nfd.log &"
+ssh $CTRL_C "mkdir -p $workdir/logs;\
+ sudo nfd &> $workdir/logs/nfd.log &"
+ssh $CTRL_D "mkdir -p $workdir/logs;\
+ sudo nfd &> $workdir/logs/nfd.log &"
+sudo nfd &> $workdir/logs/nfd.log &
+sleep 5
+
+# start ndn-traffic-server on B and C
+echo "starting ndn-traffic-server on B and C"
+ssh $CTRL_B "ndn-traffic-server $workdir/NDNTrafficServer.conf &> $workdir/logs/serverB.log &"
+ssh $CTRL_C "ndn-traffic-server $workdir/NDNTrafficServer.conf &> $workdir/logs/serverC.log &"
+
+# set up forwarding on A
+echo "setting up forwarding on A..."
+nfdc set-strategy ndn:/test-bcast ndn:/localhost/nfd/strategy/broadcast
+faceid=$(nfdc create udp4://$IP4_B1 | grep -Po 'FaceId: .*?,' | sed 's/FaceId: //' | sed 's/,//')
+nfdc add-nexthop -c 10 ndn:/test-bcast $faceid
+faceid=$(nfdc create udp4://$IP4_C1 | grep -Po 'FaceId: .*?,' | sed 's/FaceId: //' | sed 's/,//')
+nfdc add-nexthop -c 20 ndn:/test-bcast $faceid
+
+# set up forwarding on D
+echo "setting up forwarding on D..."
+faceid=$(ssh $CTRL_D "nfdc create udp4://$IP4_A2" | grep -Po 'FaceId: .*?,' | sed 's/FaceId: //' | sed 's/,//')
+ssh $CTRL_D "nfdc add-nexthop ndn:/test-bcast $faceid"
+
+# run ndn-traffic client on D
+echo "running ndn-traffic client on D..."
+ssh $CTRL_D "ndn-traffic -c 100 -i 200 $workdir/NDNTrafficClient.conf > $workdir/logs/client.log 2>&1"
+
+# kill ndn-traffic-server on B and C
+echo "killing ndn-traffic-server on B and C..."
+ssh $CTRL_B "sudo killall ndn-traffic-server; sudo killall nfd"
+ssh $CTRL_C "sudo killall ndn-traffic-server; sudo killall nfd"
+
+# collect data from B, C and D
+echo "collecting data from B, C and D..."
+scp $CTRL_B:$workdir/logs/serverB.log $workdir/logs/serverB.log
+scp $CTRL_C:$workdir/logs/serverC.log $workdir/logs/serverC.log
+ssh $CTRL_D "nfd-status -f > $workdir/logs/nfd-status-D.log"
+scp $CTRL_D:$workdir/logs/nfd-status-D.log $workdir/logs/nfd-status-D.log
+scp $CTRL_D:$workdir/logs/client.log $workdir/logs/client.log
+nfd-status > $workdir/logs/nfd-status-A.log
+
+# analyze result
+echo "analyzing result"
+b_received=$(grep "Total Interests Received" $workdir/logs/serverB.log | head -1 | cut -d= -f2 | cut -d' ' -f2)
+if [[ $b_received -lt 80 ]]
+then
+ echo "FAIL: B did not receive at least 80 interests."
+ clean_up
+ exit 1
+fi
+c_received=$(grep "Total Interests Received" $workdir/logs/serverC.log | head -1 | cut -d= -f2 | cut -d' ' -f2)
+if [[ $c_received -lt 80 ]]
+then
+ echo "FAIL: C did not receive at least 80 interests."
+ clean_up
+ exit 2
+fi
+cat $workdir/logs/nfd-status-D.log | grep udp4 | while read line
+do
+ ind=$(echo $line | grep -Po "i .*?d} out" | sed 's/i //g' | sed 's/d} out//g')
+ if [[ $ind -gt 120 ]]
+ then
+ echo "FAIL: incoming data packet in D exceeded 120."
+ echo $line
+ clean_up
+ exit 3
+ fi
+done
+
+# clean up
+clean_up
+echo "Breadcast Test PASSED"
diff --git a/test_broadcast/test_broadcast.py b/test_broadcast/test_broadcast.py
new file mode 100644
index 0000000..da34c29
--- /dev/null
+++ b/test_broadcast/test_broadcast.py
@@ -0,0 +1,34 @@
+#!/usr/bin/python2
+# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+#
+# Copyright (C) 2014 University of Arizona
+# Author: Yi Huang <ltr120@email.arizona.edu>
+# See COPYING for copyright and distribution information.
+#
+
+import os
+import unittest
+import subprocess
+
+class test_broadcast(unittest.TestCase):
+ """Test case for broadcast scenario"""
+
+ def setUp(self):
+ print "\nTesting Broadcast scenario"
+ print "**************************"
+ os.chdir("test_broadcast")
+
+ def tearDown(self):
+ print "**************************"
+ os.chdir("..")
+
+ def test_unixface(self):
+ ret = subprocess.call(["./broadcast-test.sh"], shell=True)
+ print "Test script return value:", ret
+ errormsg = {
+ 1 : "B did not receive at least 80 Interests.",
+ 2 : "C did not receive at least 80 Interests.",
+ 3 : "Incoming Data packets in D exceeded 120.",
+ }
+ if ret != 0:
+ self.fail(errormsg[ret])