nrd-test: Add test case for NRD
Refs: #1381
Change-Id: I1a195552ce93ea43f59831c39d708e6c22455ca8
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"