jeraldabraham | ae8de47 | 2014-04-19 00:34:59 -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_fib_matching(unittest.TestCase, process_manager.ProcessManager): |
| 15 | """Test case for testing fib matching""" |
| 16 | |
| 17 | def setUp(self): |
| 18 | print "\nTesting FIB Matching" |
| 19 | print "********************" |
| 20 | |
| 21 | def tearDown(self): |
| 22 | self.killNfd() |
| 23 | try: |
| 24 | self.killProcess("ndn-traffic-server-1") |
| 25 | self.killProcess("ndn-traffic-server-2") |
| 26 | self.killProcess("ndn-traffic-server-3") |
| 27 | self.killProcess("ndn-traffic-server-4") |
| 28 | self.killProcess("ndn-traffic-client-1") |
| 29 | self.killProcess("ndn-traffic-client-2") |
| 30 | self.killProcess("ndn-traffic-client-3") |
| 31 | self.killProcess("ndn-traffic-client-4") |
| 32 | self.killProcess("ndn-traffic-client-5") |
| 33 | self.killProcess("ndn-traffic-client-6") |
| 34 | self.killProcess("ndn-traffic-client-7") |
| 35 | self.killProcess("ndn-traffic-client-8") |
| 36 | self.killProcess("ndn-traffic-client-9") |
| 37 | self.killProcess("ndn-traffic-client-10") |
| 38 | self.cleanupProcesses() |
| 39 | except IOError as e: |
| 40 | self.cleanupProcesses() |
| 41 | pass |
| 42 | |
| 43 | def checkAndReportFailure(self, processKey, processName): |
| 44 | if self.hasProcessCompleted(processKey): |
| 45 | if self.getProcessReturnCode(processKey) != 0: |
| 46 | print self.getProcessOutput(processKey) |
| 47 | print self.getProcessError(processKey) |
| 48 | self.fail(">> TEST FAILED - received non-zero return code from " + processName) |
| 49 | else: |
| 50 | self.fail(">> TEST FAILED - " + processName + " failed to complete") |
| 51 | |
| 52 | def test_matching(self): |
| 53 | |
| 54 | #Start NFD |
| 55 | self.startNfd() |
| 56 | time.sleep(1) |
jeraldabraham | ae8de47 | 2014-04-19 00:34:59 -0700 | [diff] [blame] | 57 | |
| 58 | #Start ndn-traffic-server to serve ndn:/ with Content "Z", FreshnessPeriod=10ms |
| 59 | #Prefix registration using NFD FibMgmt |
| 60 | serverConfigurationFile = os.path.abspath( |
| 61 | "test_fib_matching/test-traffic-server-1.conf") |
| 62 | self.startProcess("ndn-traffic-server-1", |
| 63 | ["ndn-traffic-server", serverConfigurationFile], |
| 64 | "-> Starting Traffic Server 1 (Prefix=ndn:/, FreshnessPeriod=10ms, Data=Z)") |
| 65 | time.sleep(0.1) |
| 66 | |
| 67 | #Start ndn-traffic-server to serve ndn:/A with Content "A", FreshnessPeriod=10ms |
| 68 | #Prefix registration using NFD FibMgmt |
| 69 | serverConfigurationFile = os.path.abspath( |
| 70 | "test_fib_matching/test-traffic-server-2.conf") |
| 71 | self.startProcess("ndn-traffic-server-2", |
| 72 | ["ndn-traffic-server", serverConfigurationFile], |
| 73 | "-> Starting Traffic Server 2 (Prefix=ndn:/A, FreshnessPeriod=10ms, Data=A)") |
| 74 | time.sleep(0.1) |
| 75 | |
| 76 | #Start ndn-traffic-server to serve ndn:/A/B/C with Content "C", FreshnessPeriod=10ms |
| 77 | #Prefix registration using NFD FibMgmt |
| 78 | serverConfigurationFile = os.path.abspath( |
| 79 | "test_fib_matching/test-traffic-server-3.conf") |
| 80 | self.startProcess("ndn-traffic-server-3", |
| 81 | ["ndn-traffic-server", serverConfigurationFile], |
| 82 | "-> Starting Traffic Server 3 (Prefix=ndn:/A/B/C, FreshnessPeriod=10ms, Data=C)") |
| 83 | time.sleep(0.1) |
| 84 | |
| 85 | #Start ndn-traffic-server to serve ndn:/D/E with Content "E", FreshnessPeriod=10ms |
| 86 | #Prefix registration using NFD FibMgmt |
| 87 | serverConfigurationFile = os.path.abspath( |
| 88 | "test_fib_matching/test-traffic-server-4.conf") |
| 89 | self.startProcess("ndn-traffic-server-4", |
| 90 | ["ndn-traffic-server", serverConfigurationFile], |
| 91 | "-> Starting Traffic Server 4 (Prefix=ndn:/D/E, FreshnessPeriod=10ms, Data=E)") |
| 92 | time.sleep(0.1) |
| 93 | |
| 94 | #Invoke ndn-traffic to request ndn:/ MustBeFresh=yes |
| 95 | #Fail if unanswered. Fail if Content is not "Z". |
| 96 | clientConfigurationFile = os.path.abspath( |
| 97 | "test_fib_matching/test-traffic-client-1.conf") |
| 98 | self.startProcess("ndn-traffic-client-1", |
| 99 | ["ndn-traffic", "-c 1", clientConfigurationFile], |
| 100 | ("-> Starting Traffic Client 1 (Prefix=ndn:/, MustBeFresh=Yes," |
| 101 | " ExpectedContent=Z, MaxSuffixComponents=2)")) |
| 102 | self.waitForProcessCompletion("ndn-traffic-client-1", 10) |
| 103 | self.checkAndReportFailure("ndn-traffic-client-1", "Traffic Client 1") |
| 104 | print "-> Traffic Client 1 received data with Content=Z" |
| 105 | |
| 106 | #Wait 100ms |
| 107 | time.sleep(0.1) |
| 108 | |
| 109 | #Invoke ndn-traffic to request ndn:/F MustBeFresh=yes |
| 110 | #Fail if unanswered. Fail if Content is not "Z". |
| 111 | clientConfigurationFile = os.path.abspath( |
| 112 | "test_fib_matching/test-traffic-client-2.conf") |
| 113 | self.startProcess("ndn-traffic-client-2", |
| 114 | ["ndn-traffic", "-c 1", clientConfigurationFile], |
| 115 | "-> Starting Traffic Client 2 (Prefix=ndn:/F, MustBeFresh=Yes, ExpectedContent=Z)") |
| 116 | self.waitForProcessCompletion("ndn-traffic-client-2", 10) |
| 117 | self.checkAndReportFailure("ndn-traffic-client-2", "Traffic Client 2") |
| 118 | print "-> Traffic Client 2 received data with Content=Z" |
| 119 | |
| 120 | #Wait 100ms |
| 121 | time.sleep(0.1) |
| 122 | |
| 123 | #Invoke ndn-traffic to request ndn:/A MustBeFresh=yes |
| 124 | #Fail if unanswered. Fail if Content is not "A". |
| 125 | clientConfigurationFile = os.path.abspath( |
| 126 | "test_fib_matching/test-traffic-client-3.conf") |
| 127 | self.startProcess("ndn-traffic-client-3", |
| 128 | ["ndn-traffic", "-c 1", clientConfigurationFile], |
| 129 | "-> Starting Traffic Client 3 (Prefix=ndn:/A, MustBeFresh=Yes, ExpectedContent=A)") |
| 130 | self.waitForProcessCompletion("ndn-traffic-client-3", 10) |
| 131 | self.checkAndReportFailure("ndn-traffic-client-3", "Traffic Client 3") |
| 132 | print "-> Traffic Client 3 received data with Content=A" |
| 133 | |
| 134 | #Wait 100ms |
| 135 | time.sleep(0.1) |
| 136 | |
| 137 | #Invoke ndn-traffic to request ndn:/a MustBeFresh=yes |
| 138 | #Fail if unanswered. Fail if Content is not "Z". |
| 139 | clientConfigurationFile = os.path.abspath( |
| 140 | "test_fib_matching/test-traffic-client-4.conf") |
| 141 | self.startProcess("ndn-traffic-client-4", |
| 142 | ["ndn-traffic", "-c 1", clientConfigurationFile], |
| 143 | "-> Starting Traffic Client 4 (Prefix=ndn:/a, MustBeFresh=Yes, ExpectedContent=Z)") |
| 144 | self.waitForProcessCompletion("ndn-traffic-client-4", 10) |
| 145 | self.checkAndReportFailure("ndn-traffic-client-4", "Traffic Client 4") |
| 146 | print "-> Traffic Client 4 received data with Content=Z" |
| 147 | |
| 148 | #Wait 100ms |
| 149 | time.sleep(0.1) |
| 150 | |
| 151 | #Invoke ndn-traffic to request ndn:/A/B MustBeFresh=yes |
| 152 | #Fail if unanswered. Fail if Content is not "A". |
| 153 | clientConfigurationFile = os.path.abspath( |
| 154 | "test_fib_matching/test-traffic-client-5.conf") |
| 155 | self.startProcess("ndn-traffic-client-5", |
| 156 | ["ndn-traffic", "-c 1", clientConfigurationFile], |
| 157 | "-> Starting Traffic Client 5 (Prefix=ndn:/A/B, MustBeFresh=Yes, ExpectedContent=A)") |
| 158 | self.waitForProcessCompletion("ndn-traffic-client-5", 10) |
| 159 | self.checkAndReportFailure("ndn-traffic-client-5", "Traffic Client 5") |
| 160 | print "-> Traffic Client 5 received data with Content=A" |
| 161 | |
| 162 | #Wait 100ms |
| 163 | time.sleep(0.1) |
| 164 | |
| 165 | #Invoke ndn-traffic to request ndn:/A/B/G MustBeFresh=yes |
| 166 | #Fail if unanswered. Fail if Content is not "A". |
| 167 | clientConfigurationFile = os.path.abspath( |
| 168 | "test_fib_matching/test-traffic-client-6.conf") |
| 169 | self.startProcess("ndn-traffic-client-6", |
| 170 | ["ndn-traffic", "-c 1", clientConfigurationFile], |
| 171 | "-> Starting Traffic Client 6 (Prefix=ndn:/A/B/G, MustBeFresh=Yes, ExpectedContent=A)") |
| 172 | self.waitForProcessCompletion("ndn-traffic-client-6", 10) |
| 173 | self.checkAndReportFailure("ndn-traffic-client-6", "Traffic Client 6") |
| 174 | print "-> Traffic Client 6 received data with Content=A" |
| 175 | |
| 176 | #Wait 100ms |
| 177 | time.sleep(0.1) |
| 178 | |
| 179 | #Invoke ndn-traffic to request ndn:/A/B/C MustBeFresh=yes |
| 180 | #Fail if unanswered. Fail if Content is not "C". |
| 181 | clientConfigurationFile = os.path.abspath( |
| 182 | "test_fib_matching/test-traffic-client-7.conf") |
| 183 | self.startProcess("ndn-traffic-client-7", |
| 184 | ["ndn-traffic", "-c 1", clientConfigurationFile], |
| 185 | "-> Starting Traffic Client 7 (Prefix=ndn:/A/B/C, MustBeFresh=Yes, ExpectedContent=C)") |
| 186 | self.waitForProcessCompletion("ndn-traffic-client-7", 10) |
| 187 | self.checkAndReportFailure("ndn-traffic-client-7", "Traffic Client 7") |
| 188 | print "-> Traffic Client 7 received data with Content=C" |
| 189 | |
| 190 | #Wait 100ms |
| 191 | time.sleep(0.1) |
| 192 | |
| 193 | #Invoke ndn-traffic to request ndn:/A/B/C/P/Q/R/S/T/U/V/W/X/Y/Z MustBeFresh=yes |
| 194 | #Fail if unanswered. Fail if Content is not "C". |
| 195 | clientConfigurationFile = os.path.abspath( |
| 196 | "test_fib_matching/test-traffic-client-8.conf") |
| 197 | self.startProcess("ndn-traffic-client-8", |
| 198 | ["ndn-traffic", "-c 1", clientConfigurationFile], |
| 199 | ("-> Starting Traffic Client 8 (Prefix=ndn:/A/B/C/P/Q/R/S/T/U/V/W/X/Y/Z," |
| 200 | " MustBeFresh=Yes, ExpectedContent=C)")) |
| 201 | self.waitForProcessCompletion("ndn-traffic-client-8", 10) |
| 202 | self.checkAndReportFailure("ndn-traffic-client-8", "Traffic Client 8") |
| 203 | print "-> Traffic Client 8 received data with Content=C" |
| 204 | |
| 205 | #Wait 100ms |
| 206 | time.sleep(0.1) |
| 207 | |
Eric Newberry | 97a62b3 | 2016-08-01 18:13:39 -0700 | [diff] [blame] | 208 | #Invoke ndn-traffic to request ndn:/D MustBeFresh=yes Exclude=[...,D] |
jeraldabraham | ae8de47 | 2014-04-19 00:34:59 -0700 | [diff] [blame] | 209 | #Fail if unanswered. Fail if Content is not "Z". |
| 210 | clientConfigurationFile = os.path.abspath( |
| 211 | "test_fib_matching/test-traffic-client-9.conf") |
| 212 | self.startProcess("ndn-traffic-client-9", |
| 213 | ["ndn-traffic", "-c 1", clientConfigurationFile], |
| 214 | ("-> Starting Traffic Client 9 (Prefix=ndn:/D, MustBeFresh=Yes," |
Eric Newberry | 97a62b3 | 2016-08-01 18:13:39 -0700 | [diff] [blame] | 215 | " ExcludeRange=...,D, ExpectedContent=Z)")) |
jeraldabraham | ae8de47 | 2014-04-19 00:34:59 -0700 | [diff] [blame] | 216 | self.waitForProcessCompletion("ndn-traffic-client-9", 10) |
| 217 | self.checkAndReportFailure("ndn-traffic-client-9", "Traffic Client 9") |
| 218 | print "-> Traffic Client 9 received data with Content=Z" |
| 219 | |
| 220 | #Wait 100ms |
| 221 | time.sleep(0.1) |
| 222 | |
Eric Newberry | 97a62b3 | 2016-08-01 18:13:39 -0700 | [diff] [blame] | 223 | #Invoke ndn-traffic to request ndn:/D MustBeFresh=yes Exclude=[...,E] |
jeraldabraham | ae8de47 | 2014-04-19 00:34:59 -0700 | [diff] [blame] | 224 | #Fail if unanswered. Fail if Content is not "Z". |
| 225 | clientConfigurationFile = os.path.abspath( |
| 226 | "test_fib_matching/test-traffic-client-10.conf") |
| 227 | self.startProcess("ndn-traffic-client-10", |
| 228 | ["ndn-traffic", "-c 1", clientConfigurationFile], |
| 229 | ("-> Starting Traffic Client 10 (Prefix=ndn:/E, MustBeFresh=Yes," |
Eric Newberry | 97a62b3 | 2016-08-01 18:13:39 -0700 | [diff] [blame] | 230 | " ExcludeRange=...,E, ExpectedContent=Z)")) |
jeraldabraham | ae8de47 | 2014-04-19 00:34:59 -0700 | [diff] [blame] | 231 | self.waitForProcessCompletion("ndn-traffic-client-10", 10) |
| 232 | self.checkAndReportFailure("ndn-traffic-client-10", "Traffic Client 10") |
| 233 | print "-> Traffic Client 10 received data with Content=Z" |
| 234 | |
| 235 | #Stop all four traffic servers |
| 236 | self.killProcess("ndn-traffic-server-1") |
| 237 | self.killProcess("ndn-traffic-server-2") |
| 238 | self.killProcess("ndn-traffic-server-3") |
| 239 | self.killProcess("ndn-traffic-server-4") |
| 240 | print ">> TEST SUCCESSFUL" |