blob: 27c372a4ed6acf38e3b6dafc93b113d0349f4281 [file] [log] [blame]
Vince Lehmancb20c542015-05-12 14:04:47 -05001#!/usr/bin/python
2
3from ndn.experiments.experiment import Experiment
4from ndn.nlsr import Nlsr
5
6import time
7
8class MultipleFailureExperiment(Experiment):
9
Vince Lehman3b8bc652015-06-18 15:01:47 -050010 def __init__(self, args):
Vince Lehmancb20c542015-05-12 14:04:47 -050011
12 self.PING_COLLECTION_TIME_BEFORE_FAILURE = 60
13
14 self.FAILURE_INTERVAL = 60
15 self.RECOVERY_INTERVAL = 60
16
17 # This is the number of pings required to make it through the full experiment
Vince Lehman3b8bc652015-06-18 15:01:47 -050018 nInitialPings = self.PING_COLLECTION_TIME_BEFORE_FAILURE + len(args["net"].hosts)*(self.FAILURE_INTERVAL + self.RECOVERY_INTERVAL)
Vince Lehmancb20c542015-05-12 14:04:47 -050019 print("Scheduling with %s initial pings" % nInitialPings)
20
Vince Lehman3b8bc652015-06-18 15:01:47 -050021 args["nPings"] = nInitialPings
22
23 Experiment.__init__(self, args)
Vince Lehmancb20c542015-05-12 14:04:47 -050024
25 def failNode(self, host):
26 print("Bringing %s down" % host.name)
27 host.nfd.stop()
28
29 def recoverNode(self, host):
30 print("Bringing %s up" % host.name)
31 host.nfd.start()
32 host.nlsr.start()
33 host.nfd.setStrategy("/ndn/edu", self.strategy)
34 host.cmd("ndnpingserver /ndn/edu/" + str(host) + " > ping-server &")
35
36 def run(self):
37 self.startPings()
38
39 # After the pings are scheduled, collect pings for 1 minute
40 time.sleep(self.PING_COLLECTION_TIME_BEFORE_FAILURE)
41
42 nNodesRemainingToFail = len(self.net.hosts)
43
44 # Fail and recover each node
45 for host in self.net.hosts:
46 # Fail the node
47 self.failNode(host)
48
49 # Stay in failure state for FAILURE_INTERVAL
50 time.sleep(self.FAILURE_INTERVAL)
51
52 # Bring the node back up
53 self.recoverNode(host)
54
55 # Number of pings required to reach the end of the test
56 nPings = self.RECOVERY_INTERVAL + nNodesRemainingToFail*(self.FAILURE_INTERVAL + self.RECOVERY_INTERVAL)
57 nNodesRemainingToFail = nNodesRemainingToFail - 1
58
59 # Wait for NFD and NLSR to fully recover
60 time.sleep(1)
61 print("Scheduling with %s remaining pings" % nPings)
62
63 # Restart pings
64 for other in self.net.hosts:
65 # Do not ping self
66 if host.name != other.name:
67 self.ping(host, other, nPings)
68
69 time.sleep(self.RECOVERY_INTERVAL)
Vince Lehman3b8bc652015-06-18 15:01:47 -050070
71Experiment.register("multiple-failure", MultipleFailureExperiment)