blob: 55c4788de388d074f1f617d2ed44a40360c3ef6a [file] [log] [blame]
#!/usr/bin/python2
# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
#
# Copyright (C) 2014 University of Arizona
# Author: Jerald Paul Abraham <jeraldabraham@email.arizona.edu>
# See COPYING for copyright and distribution information.
#
import os
import time
import unittest
import process_manager
class test_fib_matching(unittest.TestCase, process_manager.ProcessManager):
"""Test case for testing fib matching"""
def setUp(self):
print "\nTesting FIB Matching"
print "********************"
def tearDown(self):
self.killNfd()
try:
self.killProcess("ndn-traffic-server-1")
self.killProcess("ndn-traffic-server-2")
self.killProcess("ndn-traffic-server-3")
self.killProcess("ndn-traffic-server-4")
self.killProcess("ndn-traffic-client-1")
self.killProcess("ndn-traffic-client-2")
self.killProcess("ndn-traffic-client-3")
self.killProcess("ndn-traffic-client-4")
self.killProcess("ndn-traffic-client-5")
self.killProcess("ndn-traffic-client-6")
self.killProcess("ndn-traffic-client-7")
self.killProcess("ndn-traffic-client-8")
self.killProcess("ndn-traffic-client-9")
self.killProcess("ndn-traffic-client-10")
self.cleanupProcesses()
except IOError as e:
self.cleanupProcesses()
pass
def checkAndReportFailure(self, processKey, processName):
if self.hasProcessCompleted(processKey):
if self.getProcessReturnCode(processKey) != 0:
print self.getProcessOutput(processKey)
print self.getProcessError(processKey)
self.fail(">> TEST FAILED - received non-zero return code from " + processName)
else:
self.fail(">> TEST FAILED - " + processName + " failed to complete")
def test_matching(self):
#Start NFD
self.startNfd()
time.sleep(1)
#Start ndn-traffic-server to serve ndn:/ with Content "Z", FreshnessPeriod=10ms
#Prefix registration using NFD FibMgmt
serverConfigurationFile = os.path.abspath(
"test_fib_matching/test-traffic-server-1.conf")
self.startProcess("ndn-traffic-server-1",
["ndn-traffic-server", serverConfigurationFile],
"-> Starting Traffic Server 1 (Prefix=ndn:/, FreshnessPeriod=10ms, Data=Z)")
time.sleep(0.1)
#Start ndn-traffic-server to serve ndn:/A with Content "A", FreshnessPeriod=10ms
#Prefix registration using NFD FibMgmt
serverConfigurationFile = os.path.abspath(
"test_fib_matching/test-traffic-server-2.conf")
self.startProcess("ndn-traffic-server-2",
["ndn-traffic-server", serverConfigurationFile],
"-> Starting Traffic Server 2 (Prefix=ndn:/A, FreshnessPeriod=10ms, Data=A)")
time.sleep(0.1)
#Start ndn-traffic-server to serve ndn:/A/B/C with Content "C", FreshnessPeriod=10ms
#Prefix registration using NFD FibMgmt
serverConfigurationFile = os.path.abspath(
"test_fib_matching/test-traffic-server-3.conf")
self.startProcess("ndn-traffic-server-3",
["ndn-traffic-server", serverConfigurationFile],
"-> Starting Traffic Server 3 (Prefix=ndn:/A/B/C, FreshnessPeriod=10ms, Data=C)")
time.sleep(0.1)
#Start ndn-traffic-server to serve ndn:/D/E with Content "E", FreshnessPeriod=10ms
#Prefix registration using NFD FibMgmt
serverConfigurationFile = os.path.abspath(
"test_fib_matching/test-traffic-server-4.conf")
self.startProcess("ndn-traffic-server-4",
["ndn-traffic-server", serverConfigurationFile],
"-> Starting Traffic Server 4 (Prefix=ndn:/D/E, FreshnessPeriod=10ms, Data=E)")
time.sleep(0.1)
#Invoke ndn-traffic to request ndn:/ MustBeFresh=yes
#Fail if unanswered. Fail if Content is not "Z".
clientConfigurationFile = os.path.abspath(
"test_fib_matching/test-traffic-client-1.conf")
self.startProcess("ndn-traffic-client-1",
["ndn-traffic", "-c 1", clientConfigurationFile],
("-> Starting Traffic Client 1 (Prefix=ndn:/, MustBeFresh=Yes,"
" ExpectedContent=Z, MaxSuffixComponents=2)"))
self.waitForProcessCompletion("ndn-traffic-client-1", 10)
self.checkAndReportFailure("ndn-traffic-client-1", "Traffic Client 1")
print "-> Traffic Client 1 received data with Content=Z"
#Wait 100ms
time.sleep(0.1)
#Invoke ndn-traffic to request ndn:/F MustBeFresh=yes
#Fail if unanswered. Fail if Content is not "Z".
clientConfigurationFile = os.path.abspath(
"test_fib_matching/test-traffic-client-2.conf")
self.startProcess("ndn-traffic-client-2",
["ndn-traffic", "-c 1", clientConfigurationFile],
"-> Starting Traffic Client 2 (Prefix=ndn:/F, MustBeFresh=Yes, ExpectedContent=Z)")
self.waitForProcessCompletion("ndn-traffic-client-2", 10)
self.checkAndReportFailure("ndn-traffic-client-2", "Traffic Client 2")
print "-> Traffic Client 2 received data with Content=Z"
#Wait 100ms
time.sleep(0.1)
#Invoke ndn-traffic to request ndn:/A MustBeFresh=yes
#Fail if unanswered. Fail if Content is not "A".
clientConfigurationFile = os.path.abspath(
"test_fib_matching/test-traffic-client-3.conf")
self.startProcess("ndn-traffic-client-3",
["ndn-traffic", "-c 1", clientConfigurationFile],
"-> Starting Traffic Client 3 (Prefix=ndn:/A, MustBeFresh=Yes, ExpectedContent=A)")
self.waitForProcessCompletion("ndn-traffic-client-3", 10)
self.checkAndReportFailure("ndn-traffic-client-3", "Traffic Client 3")
print "-> Traffic Client 3 received data with Content=A"
#Wait 100ms
time.sleep(0.1)
#Invoke ndn-traffic to request ndn:/a MustBeFresh=yes
#Fail if unanswered. Fail if Content is not "Z".
clientConfigurationFile = os.path.abspath(
"test_fib_matching/test-traffic-client-4.conf")
self.startProcess("ndn-traffic-client-4",
["ndn-traffic", "-c 1", clientConfigurationFile],
"-> Starting Traffic Client 4 (Prefix=ndn:/a, MustBeFresh=Yes, ExpectedContent=Z)")
self.waitForProcessCompletion("ndn-traffic-client-4", 10)
self.checkAndReportFailure("ndn-traffic-client-4", "Traffic Client 4")
print "-> Traffic Client 4 received data with Content=Z"
#Wait 100ms
time.sleep(0.1)
#Invoke ndn-traffic to request ndn:/A/B MustBeFresh=yes
#Fail if unanswered. Fail if Content is not "A".
clientConfigurationFile = os.path.abspath(
"test_fib_matching/test-traffic-client-5.conf")
self.startProcess("ndn-traffic-client-5",
["ndn-traffic", "-c 1", clientConfigurationFile],
"-> Starting Traffic Client 5 (Prefix=ndn:/A/B, MustBeFresh=Yes, ExpectedContent=A)")
self.waitForProcessCompletion("ndn-traffic-client-5", 10)
self.checkAndReportFailure("ndn-traffic-client-5", "Traffic Client 5")
print "-> Traffic Client 5 received data with Content=A"
#Wait 100ms
time.sleep(0.1)
#Invoke ndn-traffic to request ndn:/A/B/G MustBeFresh=yes
#Fail if unanswered. Fail if Content is not "A".
clientConfigurationFile = os.path.abspath(
"test_fib_matching/test-traffic-client-6.conf")
self.startProcess("ndn-traffic-client-6",
["ndn-traffic", "-c 1", clientConfigurationFile],
"-> Starting Traffic Client 6 (Prefix=ndn:/A/B/G, MustBeFresh=Yes, ExpectedContent=A)")
self.waitForProcessCompletion("ndn-traffic-client-6", 10)
self.checkAndReportFailure("ndn-traffic-client-6", "Traffic Client 6")
print "-> Traffic Client 6 received data with Content=A"
#Wait 100ms
time.sleep(0.1)
#Invoke ndn-traffic to request ndn:/A/B/C MustBeFresh=yes
#Fail if unanswered. Fail if Content is not "C".
clientConfigurationFile = os.path.abspath(
"test_fib_matching/test-traffic-client-7.conf")
self.startProcess("ndn-traffic-client-7",
["ndn-traffic", "-c 1", clientConfigurationFile],
"-> Starting Traffic Client 7 (Prefix=ndn:/A/B/C, MustBeFresh=Yes, ExpectedContent=C)")
self.waitForProcessCompletion("ndn-traffic-client-7", 10)
self.checkAndReportFailure("ndn-traffic-client-7", "Traffic Client 7")
print "-> Traffic Client 7 received data with Content=C"
#Wait 100ms
time.sleep(0.1)
#Invoke ndn-traffic to request ndn:/A/B/C/P/Q/R/S/T/U/V/W/X/Y/Z MustBeFresh=yes
#Fail if unanswered. Fail if Content is not "C".
clientConfigurationFile = os.path.abspath(
"test_fib_matching/test-traffic-client-8.conf")
self.startProcess("ndn-traffic-client-8",
["ndn-traffic", "-c 1", clientConfigurationFile],
("-> Starting Traffic Client 8 (Prefix=ndn:/A/B/C/P/Q/R/S/T/U/V/W/X/Y/Z,"
" MustBeFresh=Yes, ExpectedContent=C)"))
self.waitForProcessCompletion("ndn-traffic-client-8", 10)
self.checkAndReportFailure("ndn-traffic-client-8", "Traffic Client 8")
print "-> Traffic Client 8 received data with Content=C"
#Wait 100ms
time.sleep(0.1)
#Invoke ndn-traffic to request ndn:/D MustBeFresh=yes Exclude=[...,D]
#Fail if unanswered. Fail if Content is not "Z".
clientConfigurationFile = os.path.abspath(
"test_fib_matching/test-traffic-client-9.conf")
self.startProcess("ndn-traffic-client-9",
["ndn-traffic", "-c 1", clientConfigurationFile],
("-> Starting Traffic Client 9 (Prefix=ndn:/D, MustBeFresh=Yes,"
" ExcludeRange=...,D, ExpectedContent=Z)"))
self.waitForProcessCompletion("ndn-traffic-client-9", 10)
self.checkAndReportFailure("ndn-traffic-client-9", "Traffic Client 9")
print "-> Traffic Client 9 received data with Content=Z"
#Wait 100ms
time.sleep(0.1)
#Invoke ndn-traffic to request ndn:/D MustBeFresh=yes Exclude=[...,E]
#Fail if unanswered. Fail if Content is not "Z".
clientConfigurationFile = os.path.abspath(
"test_fib_matching/test-traffic-client-10.conf")
self.startProcess("ndn-traffic-client-10",
["ndn-traffic", "-c 1", clientConfigurationFile],
("-> Starting Traffic Client 10 (Prefix=ndn:/E, MustBeFresh=Yes,"
" ExcludeRange=...,E, ExpectedContent=Z)"))
self.waitForProcessCompletion("ndn-traffic-client-10", 10)
self.checkAndReportFailure("ndn-traffic-client-10", "Traffic Client 10")
print "-> Traffic Client 10 received data with Content=Z"
#Stop all four traffic servers
self.killProcess("ndn-traffic-server-1")
self.killProcess("ndn-traffic-server-2")
self.killProcess("ndn-traffic-server-3")
self.killProcess("ndn-traffic-server-4")
print ">> TEST SUCCESSFUL"