localhop-scenario-test: Add test case for localhop scenario
Refs: #1386
Change-Id: I3fdf47350abfeca9a39bb35abb78587f8d2fc902
diff --git a/test_localhop/NDNTrafficServer.conf b/test_localhop/NDNTrafficServer.conf
new file mode 100644
index 0000000..4d046f7
--- /dev/null
+++ b/test_localhop/NDNTrafficServer.conf
@@ -0,0 +1,7 @@
+##########
+Name=ndn:/localhop/test-localhop/A
+Content=AAAAAAAA
+##########
+Name=ndn:/localhop/test-localhop/B
+Content=BBBBBBBB
+##########
diff --git a/test_localhop/README.md b/test_localhop/README.md
new file mode 100644
index 0000000..7328c4a
--- /dev/null
+++ b/test_localhop/README.md
@@ -0,0 +1,13 @@
+Topology: A-B-C. All are NDN nodes.
+
+Steps:
+
+1. Start NFD on A, B, and C. Setup routing entries:
+ * On host A, `ndn:/localhop` goes to host B.
+ * On host B, `ndn:/localhop` goes to host C.
+2. On host C, start a producer that serves `ndn:/localhop/test-localhop`. The producer should print a message whenever an Interest is served.
+3. On host A, invoke a consumer to send an Interest `ndn:/localhop/test-localhop/1`.
+4. Fail the test if producer on host C receives the Interest.
+
+Script is invoked on host A.
+Script can assume integrated test suite is cloned to all hosts, necessary programs are installed and accessible in $PATH, current user can ssh to other hosts and has sudo privilege.
\ No newline at end of file
diff --git a/test_localhop/__init__.py b/test_localhop/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test_localhop/__init__.py
diff --git a/test_localhop/hostB.sh b/test_localhop/hostB.sh
new file mode 100755
index 0000000..03710e8
--- /dev/null
+++ b/test_localhop/hostB.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+workdir=$1
+c_ipaddr=$2
+sudo nfd > $workdir/logs/nfd.log 2>&1 &
+sleep 3
+faceid=$(nfdc create udp4://$c_ipaddr | grep -Po 'FaceId: .*?,' | sed 's/FaceId: //' | sed 's/,//')
+nfdc add-nexthop ndn:/localhop $faceid
diff --git a/test_localhop/localhop-test.sh b/test_localhop/localhop-test.sh
new file mode 100755
index 0000000..15bcbd3
--- /dev/null
+++ b/test_localhop/localhop-test.sh
@@ -0,0 +1,89 @@
+#!/bin/bash
+source ../multi-host.conf
+b_ipaddr=$IP4_B1
+c_ipaddr=$IP4_C1
+echo "host B IP address $b_ipaddr"
+echo "host C IP address $c_ipaddr"
+
+clean_up() {
+ r=$(ssh $CTRL_B "sudo killall nfd" 2>&1)
+ r=$(ssh $CTRL_C "sudo killall nfd" 2>&1)
+ r=$(sudo killall nfd 2>&1)
+}
+
+mkdir -p logs
+
+# start nfd and ndn-traffic-server on host C
+workdir=$(pwd)
+echo "starting nfd and ndn-traffic-server on host C..."
+ssh $CTRL_C "mkdir -p $workdir/logs;\
+ sudo nfd > $workdir/logs/nfd.log 2>&1 &\
+ sleep 3;\
+ ndn-traffic-server $workdir/NDNTrafficServer.conf > $workdir/logs/server.log 2>&1 &"
+
+# start nfd and add nexthop of ndn:/localhop to C on host B
+echo "starting nfd and adding nexthop of ndn:/localhop to C on host B..."
+ssh $CTRL_B "mkdir -p $workdir/logs;\
+ $workdir/hostB.sh $workdir $c_ipaddr"
+
+# start nfd and add nexthop of ndn:/localhop to B on host A
+echo "starting nfd and adding nexthop of ndn:/localhop to B on host A..."
+sudo nfd > logs/nfd.log 2>&1 &
+sleep 3
+faceid=$(nfdc create udp4://$b_ipaddr | grep -Po 'FaceId: .*?,' | sed 's/FaceId: //' | sed 's/,//')
+nfdc add-nexthop ndn:/localhop $faceid
+if [[ $? -ne 0 ]]
+then
+ echo "Fail to add nexthop of ndn:/localhop"
+ clean_up
+ exit 2
+fi
+
+# From A, send interest ndn:/localhop/test-localhop/A/1
+echo "From A, sending interest ndn:/localhop/test-localhop/A/1..."
+output=$(ndn-tlv-peek -p ndn:/localhop/test-localhop/A/1)
+if [[ ! -z $output ]]
+then
+ echo "ndn:/localhop/test-localhop/A/1 is answered."
+ clean_up
+ exit 4
+fi
+
+# From B, send interest ndn:/localhop/test-localhop/B/1
+echo "From B, sending interest ndn:/localhop/test-localhop/B/1..."
+output=$(ssh $CTRL_B "ndn-tlv-peek -p ndn:/localhop/test-localhop/B/1")
+if [[ $output != BBBBBBBB ]]
+then
+ echo "ndn:/localhop/test-localhop/B/1 is not correctly answered. Content: $output"
+ clean_up
+ exit 5
+fi
+
+# stop ndn-traffic-server and nfd on host C
+echo "stopping ndn-traffic-server and nfd on host C..."
+ssh $CTRL_C "sudo killall ndn-traffic-server; sudo killall nfd"
+
+# stop nfd on host B
+echo "stopping nfd on host B..."
+ssh $CTRL_B "sudo killall nfd"
+
+# stop nfd on host A
+echo "stopping nfd on host A..."
+sudo killall nfd
+
+# copy back the server log
+echo "copying back ndn-traffic-server log..."
+scp $CTRL_C:$workdir/logs/server.log $workdir/logs/
+
+# analyze server log
+echo "analyzing server log..."
+output=$(grep "Total Interests Received" $workdir/logs/server.log | head -2 | tail -1 | cut -d= -f2 | cut -d' ' -f2)
+if [ $output != '0' ]
+then
+ echo "Expected no interests with name ndn:/localhop/test-localhop/A/1 received on host C. Actual: $output"
+ echo "For more information, please examine the log at \"$(pwd)/logs\""
+ clean_up
+ exit 3
+fi
+clean_up
+echo "Localhop Test PASSED"
diff --git a/test_localhop/test_localhop.py b/test_localhop/test_localhop.py
new file mode 100644
index 0000000..f4d56f5
--- /dev/null
+++ b/test_localhop/test_localhop.py
@@ -0,0 +1,36 @@
+#!/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_localhop(unittest.TestCase):
+ """Test case for testing /localhop"""
+
+ def setUp(self):
+ print "\nTesting /localhop"
+ print "*****************"
+ os.chdir("test_localhop")
+
+ def tearDown(self):
+ print "*****************"
+ os.chdir("..")
+
+ def test_localhost_scope(self):
+ ret = subprocess.call(["./localhop-test.sh"], shell=True)
+ print "Test script return value:", ret
+ errormsg = {
+ 1 : "Invalid command line arguments",
+ 2 : "Fail to add nexthop of ndn:/localhop",
+ 3 : "Interest with name ndn:/localhop/test-localhop/A/1 was received on host C",
+ 4 : "ndn:/localhop/test-localhop/A/1 is answered.",
+ 5 : "ndn:/localhop/test-localhop/B/1 is not correctly answered.",
+ }
+ if (ret != 0):
+ self.fail(errormsg[ret])