Vince Lehman | b8b1806 | 2015-07-14 13:07:22 -0500 | [diff] [blame] | 1 | # -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | # |
Ashlesh Gawande | da475f0 | 2017-03-01 17:20:58 -0600 | [diff] [blame] | 3 | # Copyright (C) 2015-2017, The University of Memphis, |
| 4 | # Arizona Board of Regents, |
| 5 | # Regents of the University of California. |
Vince Lehman | b8b1806 | 2015-07-14 13:07:22 -0500 | [diff] [blame] | 6 | # |
| 7 | # This file is part of Mini-NDN. |
| 8 | # See AUTHORS.md for a complete list of Mini-NDN authors and contributors. |
| 9 | # |
| 10 | # Mini-NDN is free software: you can redistribute it and/or modify |
| 11 | # it under the terms of the GNU General Public License as published by |
| 12 | # the Free Software Foundation, either version 3 of the License, or |
| 13 | # (at your option) any later version. |
| 14 | # |
| 15 | # Mini-NDN is distributed in the hope that it will be useful, |
| 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | # GNU General Public License for more details. |
| 19 | # |
| 20 | # You should have received a copy of the GNU General Public License |
| 21 | # along with Mini-NDN, e.g., in COPYING.md file. |
| 22 | # If not, see <http://www.gnu.org/licenses/>. |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame] | 23 | |
| 24 | from ndn.experiments.experiment import Experiment |
| 25 | from ndn.nlsr import Nlsr |
| 26 | |
| 27 | import time |
| 28 | |
| 29 | class MultipleFailureExperiment(Experiment): |
| 30 | |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 31 | def __init__(self, args): |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame] | 32 | |
| 33 | self.PING_COLLECTION_TIME_BEFORE_FAILURE = 60 |
| 34 | |
| 35 | self.FAILURE_INTERVAL = 60 |
| 36 | self.RECOVERY_INTERVAL = 60 |
| 37 | |
| 38 | # This is the number of pings required to make it through the full experiment |
Ashlesh Gawande | d9c9e52 | 2015-10-15 16:40:12 -0500 | [diff] [blame] | 39 | nInitialPings = (self.PING_COLLECTION_TIME_BEFORE_FAILURE + |
| 40 | len(args["net"].hosts)*(self.FAILURE_INTERVAL + self.RECOVERY_INTERVAL)) |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame] | 41 | print("Scheduling with %s initial pings" % nInitialPings) |
| 42 | |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 43 | args["nPings"] = nInitialPings |
| 44 | |
| 45 | Experiment.__init__(self, args) |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame] | 46 | |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame] | 47 | def run(self): |
Ashlesh Gawande | d9c9e52 | 2015-10-15 16:40:12 -0500 | [diff] [blame] | 48 | self.startPctPings() |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame] | 49 | |
| 50 | # After the pings are scheduled, collect pings for 1 minute |
| 51 | time.sleep(self.PING_COLLECTION_TIME_BEFORE_FAILURE) |
| 52 | |
| 53 | nNodesRemainingToFail = len(self.net.hosts) |
| 54 | |
| 55 | # Fail and recover each node |
| 56 | for host in self.net.hosts: |
| 57 | # Fail the node |
| 58 | self.failNode(host) |
| 59 | |
Ashlesh Gawande | d9c9e52 | 2015-10-15 16:40:12 -0500 | [diff] [blame] | 60 | # Stay in failure state for FAILURE_INTERVAL seconds |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame] | 61 | time.sleep(self.FAILURE_INTERVAL) |
| 62 | |
| 63 | # Bring the node back up |
Ashlesh Gawande | d9c9e52 | 2015-10-15 16:40:12 -0500 | [diff] [blame] | 64 | start_time = time.time() |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame] | 65 | self.recoverNode(host) |
Ashlesh Gawande | d9c9e52 | 2015-10-15 16:40:12 -0500 | [diff] [blame] | 66 | recovery_time = int(time.time() - start_time) |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame] | 67 | |
| 68 | # Number of pings required to reach the end of the test |
Ashlesh Gawande | d9c9e52 | 2015-10-15 16:40:12 -0500 | [diff] [blame] | 69 | nNodesRemainingToFail -= 1 |
| 70 | nPings = ((self.RECOVERY_INTERVAL - recovery_time) + |
| 71 | nNodesRemainingToFail*(self.FAILURE_INTERVAL + self.RECOVERY_INTERVAL)) |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame] | 72 | |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame] | 73 | print("Scheduling with %s remaining pings" % nPings) |
| 74 | |
| 75 | # Restart pings |
Ashlesh Gawande | d9c9e52 | 2015-10-15 16:40:12 -0500 | [diff] [blame] | 76 | for nodeToPing in self.pingedDict[host]: |
| 77 | self.ping(host, nodeToPing, nPings) |
Vince Lehman | cb20c54 | 2015-05-12 14:04:47 -0500 | [diff] [blame] | 78 | |
Ashlesh Gawande | d9c9e52 | 2015-10-15 16:40:12 -0500 | [diff] [blame] | 79 | time.sleep(self.RECOVERY_INTERVAL - recovery_time) |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 80 | |
| 81 | Experiment.register("multiple-failure", MultipleFailureExperiment) |