nrd-test: Add test case for NRD
Refs: #1381
Change-Id: I1a195552ce93ea43f59831c39d708e6c22455ca8
diff --git a/test_nrd/NDNTrafficServer.conf b/test_nrd/NDNTrafficServer.conf
new file mode 100644
index 0000000..8e8c2c9
--- /dev/null
+++ b/test_nrd/NDNTrafficServer.conf
@@ -0,0 +1,7 @@
+##########
+Name=ndn:/test-nrd/A
+Content=AAAAAAAA
+##########
+Name=ndn:/test-nrd/B
+Content=BBBBBBBB
+##########
diff --git a/test_nrd/README.md b/test_nrd/README.md
new file mode 100644
index 0000000..231c1b1
--- /dev/null
+++ b/test_nrd/README.md
@@ -0,0 +1,9 @@
+Test correctness of NRD prefix registration and FIB updates (without ForwardingFlags processing).
+
+1. Modify $HOME/.ndn/client.conf to choose "protocol=nrd-0.1".
+2. Start NFD and NRD.
+3. Run nfd-status to obtain FIB.
+4. Start ndn-traffic-server; configuration has one or more non-overlapping prefixes.
+5. Run nfd-status to obtain FIB. Compare new FIB to the FIB from step 3, and determine whether FIB entry is inserted
+6. Stop ndn-traffic-server.
+7. Run nfd-status to obtain FIB. Compare new FIB to the FIB from step 5, and determine whether FIB entry is deleted
diff --git a/test_nrd/__init__.py b/test_nrd/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test_nrd/__init__.py
diff --git a/test_nrd/client.conf b/test_nrd/client.conf
new file mode 100644
index 0000000..e9be4a1
--- /dev/null
+++ b/test_nrd/client.conf
@@ -0,0 +1,10 @@
+; "unix_socket" specifies the location of the NFD unix socket
+unix_socket=/var/run/nfd.sock
+
+; "protocol" determines the protocol for prefix registration
+; it has a value of:
+; nfd-0.1
+; nrd-0.1
+; ndnd-tlv-0.7
+; ndnx-0.7
+protocol=nrd-0.1
diff --git a/test_nrd/nrd-test.sh b/test_nrd/nrd-test.sh
new file mode 100755
index 0000000..7b72005
--- /dev/null
+++ b/test_nrd/nrd-test.sh
@@ -0,0 +1,83 @@
+#!/usr/bin/env bash
+clean_up() {
+ r=$(sudo killall nfd 2>&1)
+ r=$(mv ~/.ndn/client.conf.bk ~/.ndn/client.conf 2>&1)
+}
+mkdir -p logs
+
+# backup client.conf
+echo "backup client.conf"
+cp ~/.ndn/client.conf ~/.ndn/client.conf.bk
+sed -i 's/^protocol=.*$/protocol=nrd-0.1/g' ~/.ndn/client.conf
+
+# start nfd and nrd
+echo "starting nfd and nrd..."
+sudo nfd > logs/nfd.log 2>&1 &
+sleep 3
+nrd &> logs/nrd.log &
+sleep 10
+
+# check fib before server starts
+echo "checking fib before server starts..."
+fib=$(nfd-status -b)
+res=$(echo $fib | grep '/test-nrd/A' | wc -l)
+if [[ $res -ne 0 ]]
+then
+ echo "the name '/test-nrd/A' already exists"
+ clean_up
+ exit 1
+fi
+res=$(echo $fib | grep '/test-nrd/B' | wc -l)
+if [[ $res -ne 0 ]]
+then
+ echo "the name '/test-nrd/B' already exists"
+ exit 2
+fi
+
+# start server
+echo "starting server..."
+ndn-traffic-server NDNTrafficServer.conf > logs/server.log 2>&1 &
+sleep 3
+
+# check fib after server starts
+echo "checking fib after server starts..."
+fib=$(nfd-status -b)
+res=$(echo $fib | grep '/test-nrd/A' | wc -l)
+if [[ $res -ne 1 ]]
+then
+ echo "the name '/test-nrd/A' does not exists after ndn-traffic-server starts"
+ clean_up
+ exit 3
+fi
+res=$(echo $fib | grep '/test-nrd/B' | wc -l)
+if [[ $res -ne 1 ]]
+then
+ echo "the name '/test-nrd/B' does not exists after ndn-traffic-server starts"
+ clean_up
+ exit 4
+fi
+
+# stop ndn-traffic-server
+echo "stopping ndn-traffic-server..."
+sudo killall ndn-traffic-server
+sleep 3
+
+# check fib after server stops
+echo "checking fib after server stops..."
+fib=$(nfd-status -b)
+res=$(echo $fib | grep '/test-nrd/A' | wc -l)
+if [[ $res -ne 0 ]]
+then
+ echo "the name '/test-nrd/A' still exists after ndn-traffic-server exit"
+ clean_up
+ exit 5
+fi
+res=$(echo $fib | grep '/test-nrd/B' | wc -l)
+if [[ $res -ne 0 ]]
+then
+ echo "the name '/test-nrd/B' still exists after ndn-traffic-server exit"
+ clean_up
+ exit 6
+fi
+clean_up
+echo "nrd test PASSED"
diff --git a/test_nrd/test_nrd.py b/test_nrd/test_nrd.py
new file mode 100644
index 0000000..b64909b
--- /dev/null
+++ b/test_nrd/test_nrd.py
@@ -0,0 +1,37 @@
+#!/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_nrd(unittest.TestCase):
+ """Test case for NRD"""
+
+ def setUp(self):
+ print "\nTesting NRD"
+ print "***********"
+ os.chdir("test_nrd")
+
+ def tearDown(self):
+ print "***********"
+ os.chdir("..")
+
+ def test_nrd(self):
+ ret = subprocess.call(["./nrd-test.sh"], shell=True)
+ print "Test script return value:", ret
+ errormsg = {
+ 1 : "the name '/test-nrd/A' already exists before ndn-traffic-server starts",
+ 2 : "the name '/test-nrd/B' already exists before ndn-traffic-server starts",
+ 3 : "the name '/test-nrd/A' does not exists after ndn-traffic-server starts",
+ 4 : "the name '/test-nrd/B' does not exists after ndn-traffic-server starts",
+ 5 : "the name '/test-nrd/A' still exists after ndn-traffic-server exit",
+ 6 : "the name '/test-nrd/B' still exists after ndn-traffic-server exit",
+ }
+ if (ret != 0):
+ self.fail(errormsg[ret])