multicast-test: multicast scenario
Refs: #1390
Change-Id: I28c713e1511618c3b708342227e858cfb0dfc08e
diff --git a/test_multicast/NDNTrafficServerB.conf b/test_multicast/NDNTrafficServerB.conf
new file mode 100644
index 0000000..508d509
--- /dev/null
+++ b/test_multicast/NDNTrafficServerB.conf
@@ -0,0 +1,7 @@
+##########
+Name=ndn:/test-mcast/B
+Content=BBBBBBBB
+##########
+Name=ndn:/test-mcast/Z
+Content=ZZZZZZZB
+##########
diff --git a/test_multicast/NDNTrafficServerC.conf b/test_multicast/NDNTrafficServerC.conf
new file mode 100644
index 0000000..cf94a2a
--- /dev/null
+++ b/test_multicast/NDNTrafficServerC.conf
@@ -0,0 +1,7 @@
+##########
+Name=ndn:/test-mcast/C
+Content=CCCCCCCC
+##########
+Name=ndn:/test-mcast/Z
+Content=ZZZZZZZC
+##########
diff --git a/test_multicast/README.md b/test_multicast/README.md
new file mode 100644
index 0000000..833d56a
--- /dev/null
+++ b/test_multicast/README.md
@@ -0,0 +1,17 @@
+# Multicast test scenario
+
+Test UDP and Ethernet multicast faces.
+
+1. Start NFD on A, B, and C.
+2. On host A, insert FIB entry `ndn:/test-mcast` to either UDP or Ethernet multicast face on experiment NIC.
+3. On host B, start traffic generator producer to serve `ndn:/test-mcast/B`, `ndn:/test-mcast/Z`.
+4. On host C, start traffic generator producer to serve `ndn:/test-mcast/C`, `ndn:/test-mcast/Z`.
+5. On host A, invoke `ndn-tlv-peek ndn:/test-mcast/B/1`.
+ Fail the test if this Interest is unanswered.
+6. On host A, invoke `ndn-tlv-peek ndn:/test-mcast/C/1`.
+ Fail the test if this Interest is unanswered.
+7. On host A, invoke `ndn-tlv-peek ndn:/test-mcast/Z/1`.
+ Fail the test if this Interest is unanswered.
+8. On host B, kill the producer.
+9. On host A, invoke `ndn-tlv-peek ndn:/test-mcast/Z/2`.
+ Fail the test if this Interest is unanswered.
diff --git a/test_multicast/__init__.py b/test_multicast/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test_multicast/__init__.py
diff --git a/test_multicast/multicast-test.sh b/test_multicast/multicast-test.sh
new file mode 100755
index 0000000..b5a349f
--- /dev/null
+++ b/test_multicast/multicast-test.sh
@@ -0,0 +1,71 @@
+#!/bin/bash
+source ../multi-host.conf
+if [[ $1 = "udp" ]]
+then
+ a_ipaddr=$IP4_A1
+else
+ a_ipaddr=$(ip addr show to $IP4_A1 | head -1 | cut -d: -f2 | cut -d' ' -f2)
+fi
+mkdir -p logs
+workdir=$(pwd)
+
+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)
+}
+
+# start nfd and ndn-traffic-server on B and C
+ssh $CTRL_B "mkdir -p $workdir/logs;\
+ sudo nfd &> $workdir/logs/nfd.log &\
+ sleep 3;\
+ ndn-traffic-server $workdir/NDNTrafficServerB.conf &> $workdir/logs/server.log &"
+ssh $CTRL_C "mkdir -p $workdir/logs;\
+ sudo nfd &> $workdir/logs/nfd.log &\
+ sleep 3;\
+ ndn-traffic-server $workdir/NDNTrafficServerC.conf &> $workdir/logs/server.log &"
+
+# start nfd and add nexthop of ndn:/test-mcast to UDP multicast face
+sudo nfd &> $workdir/logs/nfd.log &
+sleep 3
+faceid=$(nfd-status -f | grep $a_ipaddr | grep -Po 'faceid=.*? ' | sed 's/faceid=//' | sed 's/ //')
+nfdc add-nexthop ndn:/test-mcast $faceid
+
+# use ndn-tlv-peek to test multicast feature
+response=$(ndn-tlv-peek -p ndn:/test-mcast/B/1)
+if [[ $response != 'BBBBBBBB' ]]
+then
+ echo "FAIL: Expected data for ndn:/test-mcast/B/1 is: 'BBBBBBBB', Actual: '$response'"
+ clean_up
+ exit 1
+fi
+response=$(ndn-tlv-peek -p ndn:/test-mcast/C/1)
+if [[ $response != 'CCCCCCCC' ]]
+then
+ echo "FAIL: Expected data for ndn:/test-mcast/C/1 is: 'CCCCCCCC', Actual: '$response'"
+ clean_up
+ exit 2
+fi
+response=$(ndn-tlv-peek -p ndn:/test-mcast/Z/1)
+if [[ ( $response != 'ZZZZZZZB' ) && ( $response != 'ZZZZZZZC' ) ]]
+then
+ echo "FAIL: Expected data for ndn:/test-mcast/Z/1 is: 'ZZZZZZZB' or 'ZZZZZZZC', Actual: '$response'"
+ clean_up
+ exit 3
+fi
+
+# kill ndn-traffic-server on host B
+ssh $CTRL_B "sudo killall ndn-traffic-server"
+
+# use ndn-tlv-peek to request ndn:/testmcast/Z/2
+response=$(ndn-tlv-peek -p ndn:/test-mcast/Z/2)
+if [[ $response != 'ZZZZZZZC' ]]
+then
+ echo "FAIL: Expected data for ndn:/test-mcast/Z/2 is: 'ZZZZZZZC', Actual: '$response'"
+ clean_up
+ exit 4
+fi
+
+# clean up
+clean_up
+echo "Multicast Test PASSED"
diff --git a/test_multicast/test_multicast.py b/test_multicast/test_multicast.py
new file mode 100644
index 0000000..2b87789
--- /dev/null
+++ b/test_multicast/test_multicast.py
@@ -0,0 +1,44 @@
+#!/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_multicast(unittest.TestCase):
+ """Test case for multicast scenario"""
+
+ errormsg = {
+ 1 : "Interest ndn:/test-mcast/B/1 is unanswered.",
+ 2 : "Interest ndn:/test-mcast/C/1 is unanswered.",
+ 3 : "Interest ndn:/test-mcast/Z/1 is unanswered.",
+ 4 : "Interest ndn:/test-mcast/Z/2 is unanswered.",
+ }
+
+ def setUp(self):
+ print "\nTesting Multicast"
+ print "*****************"
+ os.chdir("test_multicast")
+
+ def tearDown(self):
+ print "*****************"
+ os.chdir("..")
+
+ def test_udp_multicast(self):
+ print ">>> Test UDP multicast <<<"
+ ret = subprocess.call(["./multicast-test.sh udp"], shell=True)
+ print "Test script return value:", ret
+ if ret != 0:
+ self.fail(self.errormsg[ret])
+
+ def test_eth_multicast(self):
+ print ">>> Test Ethernet multicast <<<"
+ ret = subprocess.call(["./multicast-test.sh eth"], shell=True)
+ print "Test script return value:", ret
+ if ret != 0:
+ self.fail(self.errormsg[ret])