blob: 0e1ea02d5a9b0763d15af28f774cbb04338ea71f [file] [log] [blame]
Junxiao Shi2feae5b2014-06-19 02:40:22 -06001#!/usr/bin/python2
2
3import os
4import time
5import unittest
6import process_manager
7
8class 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 Newberry6fc88222015-06-19 10:43:24 -070023 self.startProcess("pingserver", ["./pingserver.sh", key, strategy], "-> Starting ping server on B")
Junxiao Shi2feae5b2014-06-19 02:40:22 -060024 time.sleep(1)
Eric Newberry6fc88222015-06-19 10:43:24 -070025 self.startProcess("ping", ["./ping.sh", key, strategy], "-> Starting ping client on A")
Junxiao Shi2feae5b2014-06-19 02:40:22 -060026
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)