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") |
| 27 | self.killProcess("ndn-tlv-peek-1") |
| 28 | self.killProcess("ndn-tlv-peek-2") |
| 29 | self.killProcess("ndn-traffic-server-2") |
| 30 | self.killProcess("ndn-tlv-peek-3") |
| 31 | self.killProcess("ndn-tlv-peek-4") |
| 32 | self.killProcess("ndn-traffic-server-3") |
| 33 | self.killProcess("ndn-tlv-peek-5") |
| 34 | self.killProcess("ndn-tlv-peek-6") |
| 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) |
Yi Huang | 53fa871 | 2014-06-10 20:14:26 -0700 | [diff] [blame] | 72 | self.startNrd() |
| 73 | time.sleep(1) |
jeraldabraham | b2a2655 | 2014-04-16 21:08:09 -0700 | [diff] [blame] | 74 | |
| 75 | #Start ndn-traffic-server to serve ndn:/test-agg, with content delay set to 2000ms |
| 76 | serverConfigurationFile = os.path.abspath( |
| 77 | "test_interest_aggregation/test-traffic-server.conf") |
| 78 | self.startProcess("ndn-traffic-server-1", |
| 79 | ["ndn-traffic-server", serverConfigurationFile], |
| 80 | "-> Starting Traffic Server 1 (Prefix=ndn:/test-agg, ContentDelay=2000ms)") |
| 81 | time.sleep(1) |
| 82 | |
| 83 | #Start two instances of ndn-tlv-peek to request ndn:/test-agg/A. Wait until they |
| 84 | #terminate. Fail if either is unanswered. |
| 85 | peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-1.txt") |
| 86 | self.startProcess("ndn-tlv-peek-1", |
| 87 | ["ndn-tlv-peek", "ndn:/test-agg/A"], |
| 88 | "-> Starting Peek Client 1 (Prefix=ndn:/test-agg/A)", |
| 89 | outputFile=peekOutputFile) |
| 90 | peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-2.txt") |
| 91 | self.startProcess("ndn-tlv-peek-2", |
| 92 | ["ndn-tlv-peek", "ndn:/test-agg/A"], |
| 93 | "-> Starting Peek Client 2 (Prefix=ndn:/test-agg/A)", |
| 94 | outputFile=peekOutputFile) |
| 95 | self.waitForProcessCompletion("ndn-tlv-peek-1", 10) |
| 96 | self.waitForProcessCompletion("ndn-tlv-peek-2", 10) |
| 97 | |
| 98 | #Stop ndn-traffic-server. Fail if total served Interest does not equal 1. |
| 99 | self.killProcess("ndn-traffic-server-1") |
| 100 | time.sleep(1) |
| 101 | print "-> Stopping Traffic Server 1" |
| 102 | self.checkAndReportFailure("ndn-tlv-peek-1", "Peek Client 1") |
| 103 | self.checkAndReportFailure("ndn-tlv-peek-2", "Peek Client 2") |
| 104 | self.checkServerReceiveCount("ndn-traffic-server-1", "Traffic Server 1", 1) |
| 105 | |
| 106 | #Start ndn-traffic-server to serve ndn:/test-agg, with content delay set to 2000ms |
| 107 | self.startProcess("ndn-traffic-server-2", |
| 108 | ["ndn-traffic-server", serverConfigurationFile], |
| 109 | "-> Starting Traffic Server 2 (Prefix=ndn:/test-agg, ContentDelay=2000ms)") |
| 110 | time.sleep(1) |
| 111 | |
| 112 | #Start ndn-tlv-peek to request ndn:/test-agg/B ChildSelector=leftmost, and another |
| 113 | #instance to request ndn:/test-agg/B ChildSelector=rightmost. Wait until they terminate. |
| 114 | #Fail if either is unanswered. |
| 115 | peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-3.txt") |
| 116 | self.startProcess("ndn-tlv-peek-3", |
| 117 | ["ndn-tlv-peek", "ndn:/test-agg/B"], |
| 118 | "-> Starting Peek Client 3 (Prefix=ndn:/test-agg/B, ChildSelector=leftmost)", |
| 119 | outputFile=peekOutputFile) |
| 120 | peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-4.txt") |
| 121 | self.startProcess("ndn-tlv-peek-4", |
| 122 | ["ndn-tlv-peek", "-r", "ndn:/test-agg/B"], |
| 123 | "-> Starting Peek Client 4 (Prefix=ndn:/test-agg/B, ChildSelector=rightmost)", |
| 124 | outputFile=peekOutputFile) |
| 125 | self.waitForProcessCompletion("ndn-tlv-peek-3", 10) |
| 126 | self.waitForProcessCompletion("ndn-tlv-peek-4", 10) |
| 127 | |
| 128 | #Stop ndn-traffic-server. Fail if total served Interest does not equal 2. |
| 129 | self.killProcess("ndn-traffic-server-2") |
| 130 | time.sleep(1) |
| 131 | print "-> Stopping Traffic Server 2" |
| 132 | self.checkAndReportFailure("ndn-tlv-peek-3", "Peek Client 3") |
| 133 | self.checkAndReportFailure("ndn-tlv-peek-4", "Peek Client 4") |
| 134 | self.checkServerReceiveCount("ndn-traffic-server-2", "Traffic Server 2", 2) |
| 135 | |
| 136 | #Start ndn-traffic-server to serve ndn:/test-agg, with content delay set to 2000ms |
| 137 | self.startProcess("ndn-traffic-server-3", |
| 138 | ["ndn-traffic-server", serverConfigurationFile], |
| 139 | "-> Starting Traffic Server 3 (Prefix=ndn:/test-agg, ContentDelay=2000ms)") |
| 140 | time.sleep(1) |
| 141 | |
| 142 | #Start ndn-tlv-peek to request ndn:/test-agg/C InterestLifetime=6000ms, and another |
| 143 | #instance to request ndn:/test-agg/C. InterestLifetime=8000ms. Wait until they terminate. |
| 144 | #Fail if either is unanswered. |
| 145 | peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-5.txt") |
| 146 | self.startProcess("ndn-tlv-peek-5", |
| 147 | ["ndn-tlv-peek", "-l 6000", "ndn:/test-agg/C"], |
| 148 | "-> Starting Peek Client 5 (Prefix=ndn:/test-agg/C, InterestLifetime=6000ms)", |
| 149 | outputFile=peekOutputFile) |
| 150 | peekOutputFile = os.path.abspath(self.logFolder + "test-peek-output-6.txt") |
| 151 | self.startProcess("ndn-tlv-peek-6", |
| 152 | ["ndn-tlv-peek", "-l 8000", "ndn:/test-agg/C"], |
| 153 | "-> Starting Peek Client 6 (Prefix=ndn:/test-agg/C, InterestLifetime=8000ms)", |
| 154 | outputFile=peekOutputFile) |
| 155 | self.waitForProcessCompletion("ndn-tlv-peek-5", 10) |
| 156 | self.waitForProcessCompletion("ndn-tlv-peek-6", 10) |
| 157 | |
| 158 | #Stop ndn-traffic-server. Fail if total served Interest does not equal 1. |
| 159 | self.killProcess("ndn-traffic-server-3") |
| 160 | time.sleep(1) |
| 161 | print "-> Stopping Traffic Server 3" |
| 162 | self.checkAndReportFailure("ndn-tlv-peek-5", "Peek Client 5") |
| 163 | self.checkAndReportFailure("ndn-tlv-peek-6", "Peek Client 6") |
| 164 | self.checkServerReceiveCount("ndn-traffic-server-3", "Traffic Server 3", 1) |
| 165 | print ">> TEST SUCCESSFUL" |