blob: d1b4482f69cff608803c47fcaa80add57fcae3ac [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_interest_aggregation(unittest.TestCase, process_manager.ProcessManager):
"""Test case for testing interest aggregation"""
def setUp(self):
print "\nTesting Interest Aggregation"
print "****************************"
self.logFolder = "test_interest_aggregation/logs/"
if not os.path.exists(self.logFolder):
os.system("mkdir " + self.logFolder)
def tearDown(self):
self.killNfd()
self.killProcess("ndn-traffic-server-1")
self.killProcess("ndn-tlv-peek-1")
self.killProcess("ndn-tlv-peek-2")
self.killProcess("ndn-traffic-server-2")
self.killProcess("ndn-tlv-peek-3")
self.killProcess("ndn-tlv-peek-4")
self.killProcess("ndn-traffic-server-3")
self.killProcess("ndn-tlv-peek-5")
self.killProcess("ndn-tlv-peek-6")
self.cleanupProcesses()
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 checkServerReceiveCount(self, processKey, processName, expectedCount):
serverOutput = self.getProcessOutput(processKey).splitlines()
isTestSuccessful = False
receivedCount = 0
for logLine in serverOutput:
if "Total Interests Received" in logLine:
for value in logLine.split():
if value.isdigit():
receivedCount = int(value)
break
if receivedCount == expectedCount:
isTestSuccessful = True
break
if not isTestSuccessful:
self.fail(">> TEST FAILED - " + processName +
" expected to receive only " + str(expectedCount) +
" interest(s) but received " + str(receivedCount) + " interest(s)" )
else:
print "-> " + processName + " received " + str(receivedCount) + " interest(s)"
def test_aggregation(self):
#Start NFD
self.startNfd()
time.sleep(1)
#Start ndn-traffic-server to serve ndn:/test-agg, with content delay set to 2000ms
serverConfigurationFile = os.path.abspath(
"test_interest_aggregation/test-traffic-server.conf")
self.startProcess("ndn-traffic-server-1",
["ndn-traffic-server", serverConfigurationFile],
"-> Starting Traffic Server 1 (Prefix=ndn:/test-agg, ContentDelay=2000ms)")
time.sleep(1)
#Start two instances of ndn-tlv-peek to request ndn:/test-agg/A. Wait until they
#terminate. Fail if either is unanswered.
peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-1.txt")
self.startProcess("ndn-tlv-peek-1",
["ndn-tlv-peek", "ndn:/test-agg/A"],
"-> Starting Peek Client 1 (Prefix=ndn:/test-agg/A)",
outputFile=peekOutputFile)
peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-2.txt")
self.startProcess("ndn-tlv-peek-2",
["ndn-tlv-peek", "ndn:/test-agg/A"],
"-> Starting Peek Client 2 (Prefix=ndn:/test-agg/A)",
outputFile=peekOutputFile)
self.waitForProcessCompletion("ndn-tlv-peek-1", 10)
self.waitForProcessCompletion("ndn-tlv-peek-2", 10)
#Stop ndn-traffic-server. Fail if total served Interest does not equal 1.
self.killProcess("ndn-traffic-server-1")
time.sleep(1)
print "-> Stopping Traffic Server 1"
self.checkAndReportFailure("ndn-tlv-peek-1", "Peek Client 1")
self.checkAndReportFailure("ndn-tlv-peek-2", "Peek Client 2")
self.checkServerReceiveCount("ndn-traffic-server-1", "Traffic Server 1", 1)
#Start ndn-traffic-server to serve ndn:/test-agg, with content delay set to 2000ms
self.startProcess("ndn-traffic-server-2",
["ndn-traffic-server", serverConfigurationFile],
"-> Starting Traffic Server 2 (Prefix=ndn:/test-agg, ContentDelay=2000ms)")
time.sleep(1)
#Start ndn-tlv-peek to request ndn:/test-agg/B ChildSelector=leftmost, and another
#instance to request ndn:/test-agg/B ChildSelector=rightmost. Wait until they terminate.
#Fail if either is unanswered.
peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-3.txt")
self.startProcess("ndn-tlv-peek-3",
["ndn-tlv-peek", "ndn:/test-agg/B"],
"-> Starting Peek Client 3 (Prefix=ndn:/test-agg/B, ChildSelector=leftmost)",
outputFile=peekOutputFile)
peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-4.txt")
self.startProcess("ndn-tlv-peek-4",
["ndn-tlv-peek", "-r", "ndn:/test-agg/B"],
"-> Starting Peek Client 4 (Prefix=ndn:/test-agg/B, ChildSelector=rightmost)",
outputFile=peekOutputFile)
self.waitForProcessCompletion("ndn-tlv-peek-3", 10)
self.waitForProcessCompletion("ndn-tlv-peek-4", 10)
#Stop ndn-traffic-server. Fail if total served Interest does not equal 2.
self.killProcess("ndn-traffic-server-2")
time.sleep(1)
print "-> Stopping Traffic Server 2"
self.checkAndReportFailure("ndn-tlv-peek-3", "Peek Client 3")
self.checkAndReportFailure("ndn-tlv-peek-4", "Peek Client 4")
self.checkServerReceiveCount("ndn-traffic-server-2", "Traffic Server 2", 2)
#Start ndn-traffic-server to serve ndn:/test-agg, with content delay set to 2000ms
self.startProcess("ndn-traffic-server-3",
["ndn-traffic-server", serverConfigurationFile],
"-> Starting Traffic Server 3 (Prefix=ndn:/test-agg, ContentDelay=2000ms)")
time.sleep(1)
#Start ndn-tlv-peek to request ndn:/test-agg/C InterestLifetime=6000ms, and another
#instance to request ndn:/test-agg/C. InterestLifetime=8000ms. Wait until they terminate.
#Fail if either is unanswered.
peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-5.txt")
self.startProcess("ndn-tlv-peek-5",
["ndn-tlv-peek", "-l 6000", "ndn:/test-agg/C"],
"-> Starting Peek Client 5 (Prefix=ndn:/test-agg/C, InterestLifetime=6000ms)",
outputFile=peekOutputFile)
peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-6.txt")
self.startProcess("ndn-tlv-peek-6",
["ndn-tlv-peek", "-l 8000", "ndn:/test-agg/C"],
"-> Starting Peek Client 6 (Prefix=ndn:/test-agg/C, InterestLifetime=8000ms)",
outputFile=peekOutputFile)
self.waitForProcessCompletion("ndn-tlv-peek-5", 10)
self.waitForProcessCompletion("ndn-tlv-peek-6", 10)
#Stop ndn-traffic-server. Fail if total served Interest does not equal 1.
self.killProcess("ndn-traffic-server-3")
time.sleep(1)
print "-> Stopping Traffic Server 3"
self.checkAndReportFailure("ndn-tlv-peek-5", "Peek Client 5")
self.checkAndReportFailure("ndn-tlv-peek-6", "Peek Client 6")
self.checkServerReceiveCount("ndn-traffic-server-3", "Traffic Server 3", 1)
print ">> TEST SUCCESSFUL"