Junxiao Shi | 2feae5b | 2014-06-19 02:40:22 -0600 | [diff] [blame] | 1 | #!/usr/bin/python2 |
| 2 | |
| 3 | import os |
| 4 | import time |
| 5 | import unittest |
| 6 | import process_manager |
| 7 | |
| 8 | class test_linkfail(unittest.TestCase, process_manager.ProcessManager): |
| 9 | """Strategy link failure test scenario""" |
| 10 | |
| 11 | def setUp(self): |
| 12 | os.chdir("test_linkfail") |
| 13 | |
| 14 | def tearDown(self): |
| 15 | self.startProcess("stop", ["./stop.sh"], "-> Stopping NFD") |
| 16 | self.waitForProcessCompletion("stop", None) |
| 17 | os.chdir("..") |
| 18 | |
| 19 | def run_strategy_test(self, key, strategy, expectLoss=False): |
| 20 | print "[linkfail] testing", key |
| 21 | self.startProcess("start", ["./start.sh", key, strategy], "-> Starting NFD and creating faces") |
| 22 | self.waitForProcessCompletion("start", None) |
Eric Newberry | 6fc8822 | 2015-06-19 10:43:24 -0700 | [diff] [blame] | 23 | self.startProcess("pingserver", ["./pingserver.sh", key, strategy], "-> Starting ping server on B") |
Junxiao Shi | 2feae5b | 2014-06-19 02:40:22 -0600 | [diff] [blame] | 24 | time.sleep(1) |
Eric Newberry | 6fc8822 | 2015-06-19 10:43:24 -0700 | [diff] [blame] | 25 | self.startProcess("ping", ["./ping.sh", key, strategy], "-> Starting ping client on A") |
Junxiao Shi | 2feae5b | 2014-06-19 02:40:22 -0600 | [diff] [blame] | 26 | |
| 27 | time.sleep(5) |
| 28 | self.startProcess("ABfail", ["./linkfail.sh", "fail", "A1", "B1"], "-> Failing link A-B") |
| 29 | self.waitForProcessCompletion("ABfail", None) |
| 30 | time.sleep(5) |
| 31 | self.startProcess("ABrecover", ["./linkfail.sh", "recover", "A1", "B1"], "-> Recovering link A-B") |
| 32 | self.waitForProcessCompletion("ABrecover", None) |
| 33 | time.sleep(5) |
| 34 | self.startProcess("ACfail", ["./linkfail.sh", "fail", "A1", "C1"], "-> Failing link A-C") |
| 35 | self.waitForProcessCompletion("ACfail", None) |
| 36 | time.sleep(5) |
| 37 | self.startProcess("ACrecover", ["./linkfail.sh", "recover", "A1", "C1"], "-> Recovering link A-C") |
| 38 | self.waitForProcessCompletion("ACrecover", None) |
| 39 | self.waitForProcessCompletion("ping", None) |
| 40 | self.killProcess("pingserver") |
| 41 | |
| 42 | if expectLoss: |
| 43 | if self.getProcessReturnCode("ping") == 0: |
| 44 | self.fail("EXPECTED loss or delay; ACTUAL no loss or delay") |
| 45 | else: |
| 46 | if self.getProcessReturnCode("ping") <> 0: |
| 47 | self.fail("ping loss or delay") |
| 48 | |
| 49 | def test_broadcast(self): |
| 50 | self.run_strategy_test("broadcast", "ndn:/localhost/nfd/strategy/broadcast") |
| 51 | |
| 52 | def test_ncc(self): |
| 53 | self.run_strategy_test("ncc", "ndn:/localhost/nfd/strategy/ncc") |
| 54 | |
| 55 | def test_bestroute(self): |
| 56 | self.run_strategy_test("bestroute", "ndn:/localhost/nfd/strategy/best-route", True) |