Add hub discovery test scenario
Change-Id: I6b99fab75cbd2d615f0a72560ee8fae0ea1a378e
refs: #1444
diff --git a/install_helpers/install_dependencies.py b/install_helpers/install_dependencies.py
index 6daa1e7..3d433a6 100644
--- a/install_helpers/install_dependencies.py
+++ b/install_helpers/install_dependencies.py
@@ -6,4 +6,4 @@
print "\nINSTALLING DEPENDENCIES"
print "***********************"
os.system("sudo apt-get -qq update")
- os.system("sudo apt-get -qq install libboost1.48-all-dev libcrypto++-dev pkg-config libsqlite3-dev socat")
+ os.system("sudo apt-get -qq install libboost1.48-all-dev libcrypto++-dev pkg-config libsqlite3-dev socat bind9")
\ No newline at end of file
diff --git a/test_hub_discovery/README.md b/test_hub_discovery/README.md
new file mode 100644
index 0000000..0514bbd
--- /dev/null
+++ b/test_hub_discovery/README.md
@@ -0,0 +1,69 @@
+Test Case - Hub discovery test scenario
+=====================
+
+## Topology
+B---A---R---D
+
+A,B,D are NDN hosts.
+R is an IP router and is not NDN host; R does not forward multicast packets.
+
+Script is invoked on host A. It can control other hosts via ssh
+
+multi-host.conf defines: IP4_A1, IP4_B1, IP4_D1
+
+
+## Description
+The script test hub discovery procedure.
+In case of a failure, the detailed log can be found under:
+test_hub_discovery/log/hub_discovery.log
+
+#### Initialize ndn-autoconfig-server and dns records on host A:
+1. start NFD.
+2. start ndn-autoconfig-server, set FaceUri to udp4://10.63.18.1
+3. start bind to serve these records
+ * _ndn._udp.autoconfig-test.named-data.net => 10.63.18.2
+ * _ndn._udp.autoconfig-test.tmp._homehub._autoconf.named-data.net => 10.63.18.3
+
+### Test stage 1: multicast discovery
+On host B:
+
+1. invoke ndnsec-keygen /tmp/autoconfig-test | ndnsec-install-cert -
+2. in /etc/resolv.conf, set DNS Server to A's IP address on A-B link,
+3. set DNS search domain to autoconfig-test-none.named-data.net
+4. start NFD.
+5. invoke ndn-autoconfig
+6. execute nfd-status -f,
+ * search output for 10.63.18.1, fail if not found.
+ * search output for 10.63.18.2, fail if found.
+ * search output for 10.63.18.3, fail if found.
+7. stop NFD.
+
+### Test stage 2: DNS query with default suffix
+On host D:
+
+1. invoke ndnsec-keygen /tmp/autoconfig-test | ndnsec-install-cert -
+2. in /etc/resolv.conf, set DNS Server to A's IP address on A-R link,
+3. set DNS search domain to autoconfig-test.named-data.net
+4. start NFD
+5. invoke ndn-autoconfig
+6. execute nfd-status -f,
+ * search output for 10.63.18.1, fail if found.
+ * search output for 10.63.18.2, fail if not found.
+ * search output for 10.63.18.3, fail if found.
+7. stop NFD.
+
+### Test stage 3: find home router
+On host D:
+
+1. in /etc/resolv.conf, set DNS Server to A's IP address on A-R link,
+2. set DNS search domain to autoconfig-test-none.named-data.net
+3. start NFD
+4. invoke ndn-autoconfig
+5. execute nfd-status -f,
+ * search output for 10.63.18.1, fail if found.
+ * search output for 10.63.18.2, fail if found.
+ * search output for 10.63.18.3, fail if not found.
+6. stop NFD.
+
+## Return value
+PASS of all stages finished successfully.
\ No newline at end of file
diff --git a/test_hub_discovery/__init__.py b/test_hub_discovery/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test_hub_discovery/__init__.py
diff --git a/test_hub_discovery/autoconfig-test.named-data.net.db b/test_hub_discovery/autoconfig-test.named-data.net.db
new file mode 100644
index 0000000..ae0a69d
--- /dev/null
+++ b/test_hub_discovery/autoconfig-test.named-data.net.db
@@ -0,0 +1,15 @@
+$ORIGIN .
+$TTL 20
+autoconfig-test.named-data.net IN SOA ns.autoconfig-test.named-data.net. root.autoconfig-test.named-data.net. (
+ 1 ; Serial
+ 604800 ; Refresh
+ 86400 ; Retry
+ 2419200 ; Expire
+ 604800 ) ; Negative Cache TTL
+;
+autoconfig-test.named-data.net. IN NS ns.autoconfig-test.named-data.net.
+
+_ndn._udp.autoconfig-test.named-data.net. SRV 0 0 6363 ns.autoconfig-test.named-data.net.
+$ORIGIN autoconfig-test.named-data.net.
+
+ns A 10.63.18.2
diff --git a/test_hub_discovery/hub-discovery-test.sh b/test_hub_discovery/hub-discovery-test.sh
new file mode 100755
index 0000000..5d50070
--- /dev/null
+++ b/test_hub_discovery/hub-discovery-test.sh
@@ -0,0 +1,60 @@
+#!/usr/bin/env bash
+source ../multi-host.conf
+workdir=$(pwd)
+mkdir -p $workdir/logs
+testCase=$1
+testLog=$workdir/logs/hub_discovery.log
+
+# clean up - kill nfd
+clean_up() {
+ r=$(sudo killall nfd 2>&1)
+ sleep 2
+
+}
+
+echo "TEST STARTED" > $testLog
+
+# start nfd on localhost
+sudo nfd &> $workdir/logs/nfd.log &
+sleep 2
+
+# start nrd on localhost
+nrd &> $workdir/logs/nrd.log &
+sleep 2
+
+ndn-autoconfig-server udp4://10.63.18.1 &
+
+# set record for _ndn._udp.autoconfig-test.named-data.net => 10.63.18.2
+# set record for _ndn._udp.autoconfig-test.tmp._homehub._autoconf.named-data.net => 10.63.18.3
+sudo cp autoconfig-test.named-data.net.db /etc/bind/
+sudo cp named-data.net.db /etc/bind
+
+# configure local dns server
+sudo cp named.conf.local /etc/bind
+sudo service bind9 restart
+
+sleep 2
+
+ssh $IP4_B1 "$workdir/test-B-stage1.sh $workdir"
+if [[ $? -ne 0 ]]; then
+ echo "Stage 1: multicast discovery failed on node B" >> $testLog
+ clean_up
+ exit 1
+fi
+
+ssh $IP4_D1 "$workdir/test-D-stage2.sh $workdir"
+if [[ $? -ne 0 ]]; then
+ echo "Stage 2: DNS query with default suffix failed on node D" >> $testLog
+ clean_up
+exit 1
+fi
+
+ssh $IP4_D1 "$workdir/test-D-stage3.sh $workdir"
+if [[ $? -ne 0 ]]; then
+ echo "Stage 3: find home router failed on node D" >> $testLog
+ clean_up
+exit 1
+fi
+
+clean_up
+exit 0
diff --git a/test_hub_discovery/named-data.net.db b/test_hub_discovery/named-data.net.db
new file mode 100644
index 0000000..e5fdaa3
--- /dev/null
+++ b/test_hub_discovery/named-data.net.db
@@ -0,0 +1,11 @@
+$TTL 20
+@ IN SOA ns1 root (
+ 4 ; Serial
+ 604800 ; Refresh
+ 86400 ; Retry
+ 2419200 ; Expire
+ 604800 ) ; Negative Cache TTL
+;
+@ IN NS ns1
+_ndn._udp.autoconfig-test.tmp._homehub._autoconf SRV 0 0 6363 ns1
+ns1 A 10.63.18.3
diff --git a/test_hub_discovery/named.conf.local b/test_hub_discovery/named.conf.local
new file mode 100644
index 0000000..f6a7b37
--- /dev/null
+++ b/test_hub_discovery/named.conf.local
@@ -0,0 +1,19 @@
+//
+// Do any local configuration here
+//
+
+// Consider adding the 1918 zones here, if they are not used in your
+// organization
+//include "/etc/bind/zones.rfc1918";
+
+zone "named-data.net" IN {
+type master;
+file "/etc/bind/named-data.net.db";
+};
+
+zone "autoconfig-test.named-data.net" IN {
+type master;
+file "/etc/bind/autoconfig-test.named-data.net.db";
+};
+
+
diff --git a/test_hub_discovery/test-B-stage1.sh b/test_hub_discovery/test-B-stage1.sh
new file mode 100755
index 0000000..e88d216
--- /dev/null
+++ b/test_hub_discovery/test-B-stage1.sh
@@ -0,0 +1,51 @@
+#!/usr/bin/env bash
+workdir=$1
+source $workdir/../multi-host.conf
+testLog=$workdir/logs/hub_discovery.log
+
+clean_up_nodeB() {
+ r=$(sudo killall nfd 2>&1)
+ sudo mv resolv.conf.bak /etc/resolv.conf
+ sleep 2
+}
+
+mkdir -p $workdir/logs;
+sudo nfd &> $workdir/logs/nfd.log &
+sleep 2
+
+nrd &> $workdir/logs/nrd.log &
+sleep 2
+
+ndnsec-keygen /tmp/autoconfig-test | ndnsec-install-cert -
+sudo cp /etc/resolv.conf resolv.conf.bak
+echo "nameserver $IP4_A1" > resolv.conf
+echo "search autoconfig-test.named-data.net" >> resolv.conf
+sudo mv resolv.conf /etc/resolv.conf
+
+sudo cat /etc/resolv.conf >> $testLog
+
+ndn-autoconfig
+
+# search output for 10.63.18.1, fail if not found
+face=$(nfd-status -f | grep -F remote=udp4://10.63.18.1)
+if [[ -z "$face" ]]; then
+ clean_up_nodeB
+ exit 1
+fi
+
+# search output for 10.63.18.2, fail if found.
+face=$(nfd-status -f | grep -F remote=udp4://10.63.18.2)
+if [[ -n "$face" ]]; then
+ clean_up_nodeB
+ exit 1
+fi
+
+#search output for 10.63.18.3, fail if found.
+face=$(nfd-status -f | grep -F remote=udp4://10.63.18.3)
+if [[ -n "$face" ]]; then
+ clean_up_nodeB
+ exit 1
+fi
+
+clean_up_nodeB
+exit 0
diff --git a/test_hub_discovery/test-D-stage2.sh b/test_hub_discovery/test-D-stage2.sh
new file mode 100755
index 0000000..2305cfc
--- /dev/null
+++ b/test_hub_discovery/test-D-stage2.sh
@@ -0,0 +1,59 @@
+#!/usr/bin/env bash
+workdir=$1
+source $workdir/../multi-host.conf
+testLog=$workdir/logs/hub_discovery.log
+
+clean_up_nodeC() {
+ r=$(sudo killall nfd 2>&1)
+ sudo mv resolv.conf.bak /etc/resolv.conf
+ sleep 2
+}
+
+mkdir -p $workdir/logs;
+sudo nfd &> $workdir/logs/nfd.log &
+sleep 2
+
+nrd &> $workdir/logs/nrd.log &
+sleep 2
+
+####### TEST STAGE 2 #######
+
+ndnsec-keygen /tmp/autoconfig-test | ndnsec-install-cert -
+sudo cp /etc/resolv.conf resolv.conf.bak
+echo "nameserver $IP4_A2" > resolv.conf
+echo "search autoconfig-test.named-data.net" >> resolv.conf
+sudo mv resolv.conf /etc/resolv.conf
+
+sudo cat /etc/resolv.conf >> $testLog
+echo "host ns.autoconfig-test.named-data.net." >> $testLog
+host ns.autoconfig-test.named-data.net. >> $testLog
+
+echo "ping -c 4 ns.autoconfig-test.named-data.net." >> $testLog
+ping -c 4 ns.autoconfig-test.named-data.net. >> $testLog
+
+ndn-autoconfig
+sleep 3
+
+# search output for 10.63.18.1, fail if found
+face=$(nfd-status -f | grep -F remote=udp4://10.63.18.1)
+if [[ -n "$face" ]]; then
+ clean_up_nodeC
+ exit 1
+fi
+
+# search output for 10.63.18.2, fail if not found.
+face=$(nfd-status -f | grep -F remote=udp4://10.63.18.2)
+if [[ -z "$face" ]]; then
+ clean_up_nodeC
+ exit 1
+fi
+
+#search output for 10.63.18.3, fail if found.
+face=$(nfd-status -f | grep -F remote=udp4://10.63.18.3)
+if [[ -n "$face" ]]; then
+ clean_up_nodeC
+ exit 1
+fi
+
+clean_up_nodeC
+exit 0
diff --git a/test_hub_discovery/test-D-stage3.sh b/test_hub_discovery/test-D-stage3.sh
new file mode 100755
index 0000000..dceb171
--- /dev/null
+++ b/test_hub_discovery/test-D-stage3.sh
@@ -0,0 +1,59 @@
+#!/usr/bin/env bash
+workdir=$1
+source $workdir/../multi-host.conf
+testLog=$workdir/logs/hub_discovery.log
+
+clean_up_nodeC() {
+ r=$(sudo killall nfd 2>&1)
+ sudo mv resolv.conf.bak /etc/resolv.conf
+ sleep 2
+}
+
+mkdir -p $workdir/logs;
+sudo nfd &> $workdir/logs/nfd.log &
+sleep 2
+
+nrd &> $workdir/logs/nrd.log &
+sleep 2
+
+####### TEST STAGE 3 #######
+
+ndnsec-keygen /tmp/autoconfig-test | ndnsec-install-cert -
+sudo cp /etc/resolv.conf resolv.conf.bak
+echo "nameserver $IP4_A2" > resolv.conf
+echo "search autoconfig-test-none.named-data.net" >> resolv.conf
+sudo mv resolv.conf /etc/resolv.conf
+
+sudo cat /etc/resolv.conf >> $testLog
+echo "host ns1.autoconfig-test.tmp._homehub._autoconf.named-data.net." >> $testLog
+host ns1.autoconfig-test.tmp._homehub._autoconf.named-data.net. >> $testLog
+
+echo "ping -c 4 ns1.autoconfig-test.tmp._homehub._autoconf.named-data.net." >> $testLog
+ping -c 4 ns1.autoconfig-test.tmp._homehub._autoconf.named-data.net. >> $testLog
+
+ndn-autoconfig
+
+sleep 3
+# search output for 10.63.18.1, fail if found
+face=$(nfd-status -f | grep -F remote=udp4://10.63.18.1)
+if [[ -n "$face" ]]; then
+ clean_up_nodeC
+ exit 1
+fi
+
+# search output for 10.63.18.2, fail if found.
+face=$(nfd-status -f | grep -F remote=udp4://10.63.18.2)
+if [[ -n "$face" ]]; then
+ clean_up_nodeC
+ exit 1
+fi
+
+#search output for 10.63.18.3, fail if not found.
+face=$(nfd-status -f | grep -F remote=udp4://10.63.18.3)
+if [[ -z "$face" ]]; then
+ clean_up_nodeC
+ exit 1
+fi
+
+clean_up_nodeC
+exit 0
diff --git a/test_hub_discovery/test_hub_discovery.py b/test_hub_discovery/test_hub_discovery.py
new file mode 100644
index 0000000..3d5edf7
--- /dev/null
+++ b/test_hub_discovery/test_hub_discovery.py
@@ -0,0 +1,32 @@
+#!/usr/bin/python2
+# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+#
+# Copyright (C) 2014 Washington University in St. Louis
+# Author: Hila Ben Abraham <hila@wustl.edu>
+# See COPYING for copyright and distribution information.
+#
+
+import os
+import unittest
+import subprocess
+
+class test_hub_discovery(unittest.TestCase):
+ """Test case for testing NDN Hub Discovery NDN hub discovery procedure"""
+
+ def setUp(self):
+ print "\nTesting NDN hub discovery procedure"
+ print "*****************************"
+ os.chdir("test_hub_discovery")
+ os.system("mkdir -p logs")
+
+ def tearDown(self):
+ print "********************************"
+ os.chdir("..")
+
+ def test_hub_discovery(self):
+ print ">>> test hub discovery procedure <<<"
+ ret = subprocess.call(["./hub-discovery-test.sh"], shell=True)
+ if (ret != 0):
+ self.fail(" >> TEST HUB DISCOVEY PROCEDURE FAILED")
+ else:
+ print ">> TEST HUB DISCOVEY PROCEDURE PASSED SUCCESSFULLY"
\ No newline at end of file