Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | from ndn.experiments.experiment import Experiment |
| 4 | from ndn.nlsr import Nlsr |
| 5 | |
| 6 | import time |
| 7 | |
| 8 | class MultipleFailureExperiment(Experiment): |
| 9 | |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame^] | 10 | def __init__(self, args): |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame] | 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 |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame^] | 18 | nInitialPings = self.PING_COLLECTION_TIME_BEFORE_FAILURE + len(args["net"].hosts)*(self.FAILURE_INTERVAL + self.RECOVERY_INTERVAL) |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame] | 19 | print("Scheduling with %s initial pings" % nInitialPings) |
| 20 | |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame^] | 21 | args["nPings"] = nInitialPings |
| 22 | |
| 23 | Experiment.__init__(self, args) |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame] | 24 | |
| 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 Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame^] | 70 | |
| 71 | Experiment.register("multiple-failure", MultipleFailureExperiment) |