| #!/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("ndnpeek-1") |
| self.killProcess("ndnpeek-2") |
| self.killProcess("ndn-traffic-server-2") |
| self.killProcess("ndnpeek-3") |
| self.killProcess("ndnpeek-4") |
| self.killProcess("ndn-traffic-server-3") |
| self.killProcess("ndnpeek-5") |
| self.killProcess("ndnpeek-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 ndnpeek 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("ndnpeek-1", |
| ["ndnpeek", "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("ndnpeek-2", |
| ["ndnpeek", "ndn:/test-agg/A"], |
| "-> Starting Peek Client 2 (Prefix=ndn:/test-agg/A)", |
| outputFile=peekOutputFile) |
| self.waitForProcessCompletion("ndnpeek-1", 10) |
| self.waitForProcessCompletion("ndnpeek-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("ndnpeek-1", "Peek Client 1") |
| self.checkAndReportFailure("ndnpeek-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 ndnpeek 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("ndnpeek-3", |
| ["ndnpeek", "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("ndnpeek-4", |
| ["ndnpeek", "-r", "ndn:/test-agg/B"], |
| "-> Starting Peek Client 4 (Prefix=ndn:/test-agg/B, ChildSelector=rightmost)", |
| outputFile=peekOutputFile) |
| self.waitForProcessCompletion("ndnpeek-3", 10) |
| self.waitForProcessCompletion("ndnpeek-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("ndnpeek-3", "Peek Client 3") |
| self.checkAndReportFailure("ndnpeek-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 ndnpeek 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("ndnpeek-5", |
| ["ndnpeek", "-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("ndnpeek-6", |
| ["ndnpeek", "-l 8000", "ndn:/test-agg/C"], |
| "-> Starting Peek Client 6 (Prefix=ndn:/test-agg/C, InterestLifetime=8000ms)", |
| outputFile=peekOutputFile) |
| self.waitForProcessCompletion("ndnpeek-5", 10) |
| self.waitForProcessCompletion("ndnpeek-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("ndnpeek-5", "Peek Client 5") |
| self.checkAndReportFailure("ndnpeek-6", "Peek Client 6") |
| self.checkServerReceiveCount("ndn-traffic-server-3", "Traffic Server 3", 1) |
| print ">> TEST SUCCESSFUL" |