jeraldabraham | b2a2655 | 2014-04-16 21:08:09 -0700 | [diff] [blame] | 1 | #!/usr/bin/python2 |
| 2 | # -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 3 | # |
| 4 | # Copyright (C) 2014 University of Arizona |
| 5 | # Author: Jerald Paul Abraham <jeraldabraham@email.arizona.edu> |
| 6 | # See COPYING for copyright and distribution information. |
| 7 | # |
| 8 | |
| 9 | import os |
| 10 | import time |
| 11 | import unittest |
| 12 | import process_manager |
| 13 | |
| 14 | class test_interest_aggregation(unittest.TestCase, process_manager.ProcessManager): |
| 15 | """Test case for testing interest aggregation""" |
| 16 | |
| 17 | def setUp(self): |
| 18 | print "\nTesting Interest Aggregation" |
| 19 | print "****************************" |
| 20 | self.logFolder = "test_interest_aggregation/logs/" |
| 21 | if not os.path.exists(self.logFolder): |
| 22 | os.system("mkdir " + self.logFolder) |
| 23 | |
| 24 | def tearDown(self): |
| 25 | self.killNfd() |
| 26 | self.killProcess("ndn-traffic-server-1") |
Eric Newberry | d4ed622 | 2015-06-10 14:12:42 -0700 | [diff] [blame] | 27 | self.killProcess("ndnpeek-1") |
| 28 | self.killProcess("ndnpeek-2") |
jeraldabraham | b2a2655 | 2014-04-16 21:08:09 -0700 | [diff] [blame] | 29 | self.killProcess("ndn-traffic-server-2") |
Eric Newberry | d4ed622 | 2015-06-10 14:12:42 -0700 | [diff] [blame] | 30 | self.killProcess("ndnpeek-3") |
| 31 | self.killProcess("ndnpeek-4") |
jeraldabraham | b2a2655 | 2014-04-16 21:08:09 -0700 | [diff] [blame] | 32 | self.killProcess("ndn-traffic-server-3") |
Eric Newberry | d4ed622 | 2015-06-10 14:12:42 -0700 | [diff] [blame] | 33 | self.killProcess("ndnpeek-5") |
| 34 | self.killProcess("ndnpeek-6") |
jeraldabraham | b2a2655 | 2014-04-16 21:08:09 -0700 | [diff] [blame] | 35 | self.cleanupProcesses() |
| 36 | |
| 37 | def checkAndReportFailure(self, processKey, processName): |
| 38 | if self.hasProcessCompleted(processKey): |
| 39 | if self.getProcessReturnCode(processKey) != 0: |
| 40 | print self.getProcessOutput(processKey) |
| 41 | print self.getProcessError(processKey) |
| 42 | self.fail(">> TEST FAILED - received non-zero return code from " + processName) |
| 43 | else: |
| 44 | self.fail(">> TEST FAILED - " + processName + " failed to complete") |
| 45 | |
| 46 | |
| 47 | def checkServerReceiveCount(self, processKey, processName, expectedCount): |
| 48 | serverOutput = self.getProcessOutput(processKey).splitlines() |
| 49 | isTestSuccessful = False |
| 50 | receivedCount = 0 |
| 51 | for logLine in serverOutput: |
| 52 | if "Total Interests Received" in logLine: |
| 53 | for value in logLine.split(): |
| 54 | if value.isdigit(): |
| 55 | receivedCount = int(value) |
| 56 | break |
| 57 | if receivedCount == expectedCount: |
| 58 | isTestSuccessful = True |
| 59 | break |
| 60 | if not isTestSuccessful: |
| 61 | self.fail(">> TEST FAILED - " + processName + |
| 62 | " expected to receive only " + str(expectedCount) + |
| 63 | " interest(s) but received " + str(receivedCount) + " interest(s)" ) |
| 64 | else: |
| 65 | print "-> " + processName + " received " + str(receivedCount) + " interest(s)" |
| 66 | |
| 67 | def test_aggregation(self): |
| 68 | |
| 69 | #Start NFD |
| 70 | self.startNfd() |
| 71 | time.sleep(1) |
jeraldabraham | b2a2655 | 2014-04-16 21:08:09 -0700 | [diff] [blame] | 72 | |
| 73 | #Start ndn-traffic-server to serve ndn:/test-agg, with content delay set to 2000ms |
| 74 | serverConfigurationFile = os.path.abspath( |
| 75 | "test_interest_aggregation/test-traffic-server.conf") |
| 76 | self.startProcess("ndn-traffic-server-1", |
| 77 | ["ndn-traffic-server", serverConfigurationFile], |
| 78 | "-> Starting Traffic Server 1 (Prefix=ndn:/test-agg, ContentDelay=2000ms)") |
| 79 | time.sleep(1) |
| 80 | |
Eric Newberry | d4ed622 | 2015-06-10 14:12:42 -0700 | [diff] [blame] | 81 | #Start two instances of ndnpeek to request ndn:/test-agg/A. Wait until they |
jeraldabraham | b2a2655 | 2014-04-16 21:08:09 -0700 | [diff] [blame] | 82 | #terminate. Fail if either is unanswered. |
| 83 | peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-1.txt") |
Eric Newberry | d4ed622 | 2015-06-10 14:12:42 -0700 | [diff] [blame] | 84 | self.startProcess("ndnpeek-1", |
| 85 | ["ndnpeek", "ndn:/test-agg/A"], |
jeraldabraham | b2a2655 | 2014-04-16 21:08:09 -0700 | [diff] [blame] | 86 | "-> Starting Peek Client 1 (Prefix=ndn:/test-agg/A)", |
| 87 | outputFile=peekOutputFile) |
| 88 | peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-2.txt") |
Eric Newberry | d4ed622 | 2015-06-10 14:12:42 -0700 | [diff] [blame] | 89 | self.startProcess("ndnpeek-2", |
| 90 | ["ndnpeek", "ndn:/test-agg/A"], |
jeraldabraham | b2a2655 | 2014-04-16 21:08:09 -0700 | [diff] [blame] | 91 | "-> Starting Peek Client 2 (Prefix=ndn:/test-agg/A)", |
| 92 | outputFile=peekOutputFile) |
Eric Newberry | d4ed622 | 2015-06-10 14:12:42 -0700 | [diff] [blame] | 93 | self.waitForProcessCompletion("ndnpeek-1", 10) |
| 94 | self.waitForProcessCompletion("ndnpeek-2", 10) |
jeraldabraham | b2a2655 | 2014-04-16 21:08:09 -0700 | [diff] [blame] | 95 | |
| 96 | #Stop ndn-traffic-server. Fail if total served Interest does not equal 1. |
| 97 | self.killProcess("ndn-traffic-server-1") |
| 98 | time.sleep(1) |
| 99 | print "-> Stopping Traffic Server 1" |
Eric Newberry | d4ed622 | 2015-06-10 14:12:42 -0700 | [diff] [blame] | 100 | self.checkAndReportFailure("ndnpeek-1", "Peek Client 1") |
| 101 | self.checkAndReportFailure("ndnpeek-2", "Peek Client 2") |
jeraldabraham | b2a2655 | 2014-04-16 21:08:09 -0700 | [diff] [blame] | 102 | self.checkServerReceiveCount("ndn-traffic-server-1", "Traffic Server 1", 1) |
| 103 | |
| 104 | #Start ndn-traffic-server to serve ndn:/test-agg, with content delay set to 2000ms |
| 105 | self.startProcess("ndn-traffic-server-2", |
| 106 | ["ndn-traffic-server", serverConfigurationFile], |
| 107 | "-> Starting Traffic Server 2 (Prefix=ndn:/test-agg, ContentDelay=2000ms)") |
| 108 | time.sleep(1) |
| 109 | |
Eric Newberry | d4ed622 | 2015-06-10 14:12:42 -0700 | [diff] [blame] | 110 | #Start ndnpeek to request ndn:/test-agg/B ChildSelector=leftmost, and another |
jeraldabraham | b2a2655 | 2014-04-16 21:08:09 -0700 | [diff] [blame] | 111 | #instance to request ndn:/test-agg/B ChildSelector=rightmost. Wait until they terminate. |
| 112 | #Fail if either is unanswered. |
| 113 | peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-3.txt") |
Eric Newberry | d4ed622 | 2015-06-10 14:12:42 -0700 | [diff] [blame] | 114 | self.startProcess("ndnpeek-3", |
| 115 | ["ndnpeek", "ndn:/test-agg/B"], |
jeraldabraham | b2a2655 | 2014-04-16 21:08:09 -0700 | [diff] [blame] | 116 | "-> Starting Peek Client 3 (Prefix=ndn:/test-agg/B, ChildSelector=leftmost)", |
| 117 | outputFile=peekOutputFile) |
| 118 | peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-4.txt") |
Eric Newberry | d4ed622 | 2015-06-10 14:12:42 -0700 | [diff] [blame] | 119 | self.startProcess("ndnpeek-4", |
| 120 | ["ndnpeek", "-r", "ndn:/test-agg/B"], |
jeraldabraham | b2a2655 | 2014-04-16 21:08:09 -0700 | [diff] [blame] | 121 | "-> Starting Peek Client 4 (Prefix=ndn:/test-agg/B, ChildSelector=rightmost)", |
| 122 | outputFile=peekOutputFile) |
Eric Newberry | d4ed622 | 2015-06-10 14:12:42 -0700 | [diff] [blame] | 123 | self.waitForProcessCompletion("ndnpeek-3", 10) |
| 124 | self.waitForProcessCompletion("ndnpeek-4", 10) |
jeraldabraham | b2a2655 | 2014-04-16 21:08:09 -0700 | [diff] [blame] | 125 | |
| 126 | #Stop ndn-traffic-server. Fail if total served Interest does not equal 2. |
| 127 | self.killProcess("ndn-traffic-server-2") |
| 128 | time.sleep(1) |
| 129 | print "-> Stopping Traffic Server 2" |
Eric Newberry | d4ed622 | 2015-06-10 14:12:42 -0700 | [diff] [blame] | 130 | self.checkAndReportFailure("ndnpeek-3", "Peek Client 3") |
| 131 | self.checkAndReportFailure("ndnpeek-4", "Peek Client 4") |
jeraldabraham | b2a2655 | 2014-04-16 21:08:09 -0700 | [diff] [blame] | 132 | self.checkServerReceiveCount("ndn-traffic-server-2", "Traffic Server 2", 2) |
| 133 | |
| 134 | #Start ndn-traffic-server to serve ndn:/test-agg, with content delay set to 2000ms |
| 135 | self.startProcess("ndn-traffic-server-3", |
| 136 | ["ndn-traffic-server", serverConfigurationFile], |
| 137 | "-> Starting Traffic Server 3 (Prefix=ndn:/test-agg, ContentDelay=2000ms)") |
| 138 | time.sleep(1) |
| 139 | |
Eric Newberry | d4ed622 | 2015-06-10 14:12:42 -0700 | [diff] [blame] | 140 | #Start ndnpeek to request ndn:/test-agg/C InterestLifetime=6000ms, and another |
jeraldabraham | b2a2655 | 2014-04-16 21:08:09 -0700 | [diff] [blame] | 141 | #instance to request ndn:/test-agg/C. InterestLifetime=8000ms. Wait until they terminate. |
| 142 | #Fail if either is unanswered. |
| 143 | peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-5.txt") |
Eric Newberry | d4ed622 | 2015-06-10 14:12:42 -0700 | [diff] [blame] | 144 | self.startProcess("ndnpeek-5", |
| 145 | ["ndnpeek", "-l 6000", "ndn:/test-agg/C"], |
jeraldabraham | b2a2655 | 2014-04-16 21:08:09 -0700 | [diff] [blame] | 146 | "-> Starting Peek Client 5 (Prefix=ndn:/test-agg/C, InterestLifetime=6000ms)", |
| 147 | outputFile=peekOutputFile) |
| 148 | peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-6.txt") |
Eric Newberry | d4ed622 | 2015-06-10 14:12:42 -0700 | [diff] [blame] | 149 | self.startProcess("ndnpeek-6", |
| 150 | ["ndnpeek", "-l 8000", "ndn:/test-agg/C"], |
jeraldabraham | b2a2655 | 2014-04-16 21:08:09 -0700 | [diff] [blame] | 151 | "-> Starting Peek Client 6 (Prefix=ndn:/test-agg/C, InterestLifetime=8000ms)", |
| 152 | outputFile=peekOutputFile) |
Eric Newberry | d4ed622 | 2015-06-10 14:12:42 -0700 | [diff] [blame] | 153 | self.waitForProcessCompletion("ndnpeek-5", 10) |
| 154 | self.waitForProcessCompletion("ndnpeek-6", 10) |
jeraldabraham | b2a2655 | 2014-04-16 21:08:09 -0700 | [diff] [blame] | 155 | |
| 156 | #Stop ndn-traffic-server. Fail if total served Interest does not equal 1. |
| 157 | self.killProcess("ndn-traffic-server-3") |
| 158 | time.sleep(1) |
| 159 | print "-> Stopping Traffic Server 3" |
Eric Newberry | d4ed622 | 2015-06-10 14:12:42 -0700 | [diff] [blame] | 160 | self.checkAndReportFailure("ndnpeek-5", "Peek Client 5") |
| 161 | self.checkAndReportFailure("ndnpeek-6", "Peek Client 6") |
jeraldabraham | b2a2655 | 2014-04-16 21:08:09 -0700 | [diff] [blame] | 162 | self.checkServerReceiveCount("ndn-traffic-server-3", "Traffic Server 3", 1) |
| 163 | print ">> TEST SUCCESSFUL" |