interest-loop-scenario: Add test cast for Interest loop scenario.
Change-Id: Ic83735a24488614236eb6fbb7c7c79260434e457
Refs: #1409
diff --git a/.gitignore b/.gitignore
index 5cf7948..d1ba9e9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
*.pyc
*/logs
+test_interest_loop/keys
diff --git a/test_interest_loop/NDNTrafficClient.conf b/test_interest_loop/NDNTrafficClient.conf
new file mode 100644
index 0000000..439a96f
--- /dev/null
+++ b/test_interest_loop/NDNTrafficClient.conf
@@ -0,0 +1,6 @@
+##########
+TrafficPercentage=100
+Name=ndn:/test-loop/A
+ExpectedContent=AAAAAAAA
+NameAppendBytes=8
+##########
diff --git a/test_interest_loop/README.md b/test_interest_loop/README.md
new file mode 100644
index 0000000..87d8941
--- /dev/null
+++ b/test_interest_loop/README.md
@@ -0,0 +1,10 @@
+Steps:
+
+1. Start NFD on A,B,C.
+2. On host A, create UDP face to host B, and add nexthop for `ndn:/test-loop` toward this face.
+ On host B, create UDP face to host C, and add nexthop for `ndn:/test-loop` toward this face.
+ On host C, create UDP face to host A, and add nexthop for `ndn:/test-loop` toward this face.
+3. On every host, set strategy of `ndn:/test-loop` to *strategy under test*.
+4. On host A, execute ndn-traffic-client to send 100 Interests to `ndn:/test-loop/A/<random>`.
+5. On every host, execute nfd-status to see face counters.
+ Fail if NInInterests or NOutInterests counter of a UDP face is greater than 200.
diff --git a/test_interest_loop/__init__.py b/test_interest_loop/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test_interest_loop/__init__.py
diff --git a/test_interest_loop/add-nexthop.sh b/test_interest_loop/add-nexthop.sh
new file mode 100755
index 0000000..c7bab48
--- /dev/null
+++ b/test_interest_loop/add-nexthop.sh
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+ipaddr=$1
+strategy=$2
+faceid=$(nfdc create udp4://$ipaddr | grep -Po 'FaceId: .*?,' | sed 's/FaceId: //' | sed 's/,//')
+nfdc add-nexthop ndn:/test-loop $faceid
+nfdc set-strategy ndn:/test-loop $strategy
diff --git a/test_interest_loop/interest-loop-test.sh b/test_interest_loop/interest-loop-test.sh
new file mode 100755
index 0000000..0cc616e
--- /dev/null
+++ b/test_interest_loop/interest-loop-test.sh
@@ -0,0 +1,80 @@
+#!/usr/bin/env bash
+source ../multi-host.conf
+a_ipaddr=$IP4_A1
+b_ipaddr=$IP4_B1
+c_ipaddr=$IP4_C1
+strategy=$1
+echo "host A IP address $a_ipaddr"
+echo "host B IP address $b_ipaddr"
+echo "host C IP address $c_ipaddr"
+echo "Strategy: $strategy"
+mkdir -p logs
+workdir=$(pwd)
+
+clean_up() {
+ echo "cleaning up..."
+ r=$(sudo killall nfd 2>&1)
+ r=$(ssh $b_ipaddr "sudo killall nfd 2>&1" 2>&1)
+ r=$(ssh $c_ipaddr "sudo killall nfd 2>&1" 2>&1)
+}
+
+# get keys
+echo "getting keys..."
+cp -r /usr/local/etc/ndn/keys $workdir/
+ssh $CTRL_B "cp -r /usr/local/etc/ndn/keys $workdir/"
+ssh $CTRL_C "cp -r /usr/local/etc/ndn/keys $workdir/"
+
+# start NFD on three nodes and set nexthop to create loop
+echo "start NFD on three nodes and set nexthop to create loop..."
+ssh $CTRL_B "mkdir -p $workdir/logs;\
+ sudo nfd --config $workdir/nfd.conf > $workdir/logs/nfd.log 2>&1 &"
+ssh $CTRL_C "mkdir -p $workdir/logs;\
+ sudo nfd --config $workdir/nfd.conf > $workdir/logs/nfd.log 2>&1 &"
+sudo nfd --config $workdir/nfd.conf > $workdir/logs/nfd.log 2>&1 &
+sleep 5
+ssh $CTRL_B "$workdir/add-nexthop.sh $c_ipaddr $strategy"
+ssh $CTRL_C "$workdir/add-nexthop.sh $a_ipaddr $strategy"
+$workdir/add-nexthop.sh $b_ipaddr $strategy
+
+# use ndn-traffic client to send 100 interests
+echo "using ndn-traffic client to send 100 interests..."
+ndn-traffic -c 100 -i 200 NDNTrafficClient.conf > $workdir/logs/client.log 2>&1
+
+# collect nfd-status from B and C
+echo "collecting nfd-status from B and C..."
+ssh $CTRL_B "nfd-status -f > $workdir/logs/nfd-status-B.log 2>&1"
+scp $CTRL_B:$workdir/logs/nfd-status-B.log $workdir/logs/nfd-status-B.log
+ssh $CTRL_C "nfd-status -f > $workdir/logs/nfd-status-C.log 2>&1"
+scp $CTRL_C:$workdir/logs/nfd-status-C.log $workdir/logs/nfd-status-C.log
+nfd-status -f > $workdir/logs/nfd-status-A.log 2>&1
+
+# analyze results
+echo "analyzing results..."
+for host in {A..C}
+do
+ echo "Host $host:"
+ cat $workdir/logs/nfd-status-$host.log | grep udp4 | while read line
+ do
+ ini=$(echo "$line" | grep -Po "in={.*?i" | sed 's/in={//g' | sed 's/i//g')
+ outi=$(echo "$line" | grep -Po "out={.*?i" | sed 's/out={//g' | sed 's/i//g')
+ echo " $ini in, $outi out"
+ if [[ $ini -gt 200 ]]
+ then
+ echo "FAIL: counter for incoming interest on host $host is greater than 200"
+ echo "$line"
+ clean_up
+ exit 1
+ fi
+ if [[ $outi -gt 200 ]]
+ then
+ echo "FAIL: counter for outgoing interest on host $host is greater than 200"
+ echo "$line"
+ clean_up
+ exit 2
+ fi
+ done
+done
+
+# clean up
+clean_up
+echo "Interest Loop Test PASSED"
diff --git a/test_interest_loop/nfd.conf b/test_interest_loop/nfd.conf
new file mode 100644
index 0000000..7c16261
--- /dev/null
+++ b/test_interest_loop/nfd.conf
@@ -0,0 +1,46 @@
+log
+{
+}
+
+face_system
+{
+ unix
+ {
+ listen yes
+ path /var/run/nfd.sock
+ }
+
+ tcp
+ {
+ listen yes
+ port 6363
+ }
+
+ udp
+ {
+ port 6363
+ idle_timeout 600
+ keep_alive_interval 25
+
+ mcast no ; Turn off UDP multicast.
+ }
+
+ ether
+ {
+ mcast no ; Turn off Ethernet multicast.
+ }
+}
+
+authorizations
+{
+ authorize
+ {
+ certfile keys/default.ndncert
+ privileges
+ {
+ faces
+ fib
+ strategy-choice
+ }
+ }
+}
diff --git a/test_interest_loop/test_interest_loop.py b/test_interest_loop/test_interest_loop.py
new file mode 100644
index 0000000..595d037
--- /dev/null
+++ b/test_interest_loop/test_interest_loop.py
@@ -0,0 +1,56 @@
+#!/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_interest_loop(unittest.TestCase):
+ """Test case for Interest loop scenario"""
+
+ errormsg = {
+ 1 : "Counter for incoming interest is greater than 200.",
+ 2 : "Counter for outgoing interest is greater than 200.",
+ }
+
+ def setUp(self):
+ print "\nTesting Interest loop scenario"
+ print "******************************"
+ os.chdir("test_interest_loop")
+
+ def tearDown(self):
+ print "******************************"
+ os.chdir("..")
+
+ def test_broadcast(self):
+ print ">>> Testing with Broadcast Strategy <<<"
+ ret = subprocess.call(["./interest-loop-test.sh ndn:/localhost/nfd/strategy/broadcast"], shell=True)
+ print "Test script return value:", ret
+ if ret != 0:
+ self.fail(self.errormsg[ret])
+
+ def test_best_route(self):
+ print ">>> Testing with Best-route Strategy <<<"
+ ret = subprocess.call(["./interest-loop-test.sh ndn:/localhost/nfd/strategy/best-route"], shell=True)
+ print "Test script return value:", ret
+ if ret != 0:
+ self.fail(self.errormsg[ret])
+
+ def test_client_control(self):
+ print ">>> Testing with Client Control Strategy <<<"
+ ret = subprocess.call(["./interest-loop-test.sh ndn:/localhost/nfd/strategy/client-control"], shell=True)
+ print "Test script return value:", ret
+ if ret != 0:
+ self.fail(self.errormsg[ret])
+
+ def test_ncc(self):
+ print ">>> Testing with NCC Strategy <<<"
+ ret = subprocess.call(["./interest-loop-test.sh ndn:/localhost/nfd/strategy/ncc"], shell=True)
+ print "Test script return value:", ret
+ if ret != 0:
+ self.fail(self.errormsg[ret])