blob: db7d53645c39dcaaa2fa25bf5c0ed29853056908 [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
10 def __init__(self, net, nodes, convergenceTime, strategy):
11
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
18 nInitialPings = self.PING_COLLECTION_TIME_BEFORE_FAILURE + len(net.hosts)*(self.FAILURE_INTERVAL + self.RECOVERY_INTERVAL)
19 print("Scheduling with %s initial pings" % nInitialPings)
20
21 Experiment.__init__(self, net, nodes, convergenceTime, nInitialPings, strategy)
22
23 def failNode(self, host):
24 print("Bringing %s down" % host.name)
25 host.nfd.stop()
26
27 def recoverNode(self, host):
28 print("Bringing %s up" % host.name)
29 host.nfd.start()
30 host.nlsr.start()
31 host.nfd.setStrategy("/ndn/edu", self.strategy)
32 host.cmd("ndnpingserver /ndn/edu/" + str(host) + " > ping-server &")
33
34 def run(self):
35 self.startPings()
36
37 # After the pings are scheduled, collect pings for 1 minute
38 time.sleep(self.PING_COLLECTION_TIME_BEFORE_FAILURE)
39
40 nNodesRemainingToFail = len(self.net.hosts)
41
42 # Fail and recover each node
43 for host in self.net.hosts:
44 # Fail the node
45 self.failNode(host)
46
47 # Stay in failure state for FAILURE_INTERVAL
48 time.sleep(self.FAILURE_INTERVAL)
49
50 # Bring the node back up
51 self.recoverNode(host)
52
53 # Number of pings required to reach the end of the test
54 nPings = self.RECOVERY_INTERVAL + nNodesRemainingToFail*(self.FAILURE_INTERVAL + self.RECOVERY_INTERVAL)
55 nNodesRemainingToFail = nNodesRemainingToFail - 1
56
57 # Wait for NFD and NLSR to fully recover
58 time.sleep(1)
59 print("Scheduling with %s remaining pings" % nPings)
60
61 # Restart pings
62 for other in self.net.hosts:
63 # Do not ping self
64 if host.name != other.name:
65 self.ping(host, other, nPings)
66
67 time.sleep(self.RECOVERY_INTERVAL)