Ashlesh Gawande | 5fee776 | 2015-10-28 16:01:55 -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. |
Ashlesh Gawande | 5fee776 | 2015-10-28 16:01:55 -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/>. |
| 23 | |
| 24 | from ndn.experiments.experiment import Experiment |
Ashlesh Gawande | 5fee776 | 2015-10-28 16:01:55 -0500 | [diff] [blame] | 25 | |
| 26 | import time |
| 27 | |
Ashlesh Gawande | 5f47020 | 2017-02-25 12:02:53 -0600 | [diff] [blame] | 28 | class MCNFailureExperiment(Experiment): |
Ashlesh Gawande | 5fee776 | 2015-10-28 16:01:55 -0500 | [diff] [blame] | 29 | |
| 30 | def __init__(self, args): |
| 31 | args["nPings"] = 300 |
| 32 | Experiment.__init__(self, args) |
| 33 | |
| 34 | self.PING_COLLECTION_TIME_BEFORE_FAILURE = 60 |
| 35 | self.PING_COLLECTION_TIME_AFTER_RECOVERY = 120 |
| 36 | |
| 37 | def getMostConnectedNode(self): |
| 38 | mcn = max(self.net.hosts, key=lambda host: len(host.intfNames())) |
| 39 | print "The most connected node is: %s" % mcn.name |
| 40 | return mcn |
| 41 | |
| 42 | def run(self): |
| 43 | mostConnectedNode = self.getMostConnectedNode() |
| 44 | |
| 45 | self.startPctPings() |
| 46 | |
| 47 | # After the pings are scheduled, collect pings for 1 minute |
| 48 | time.sleep(self.PING_COLLECTION_TIME_BEFORE_FAILURE) |
| 49 | |
| 50 | # Bring down MCN |
| 51 | self.failNode(mostConnectedNode) |
| 52 | |
| 53 | # MCN is down for 2 minutes |
| 54 | time.sleep(120) |
| 55 | |
| 56 | # Bring MCN back up |
| 57 | self.recoverNode(mostConnectedNode) |
| 58 | |
| 59 | # Restart pings |
| 60 | for nodeToPing in self.pingedDict[mostConnectedNode]: |
| 61 | self.ping(mostConnectedNode, nodeToPing, self.PING_COLLECTION_TIME_AFTER_RECOVERY) |
| 62 | |
| 63 | # Collect pings for more seconds after MCN is up |
| 64 | time.sleep(self.PING_COLLECTION_TIME_AFTER_RECOVERY) |
| 65 | |
Ashlesh Gawande | 5f47020 | 2017-02-25 12:02:53 -0600 | [diff] [blame] | 66 | Experiment.register("failure-mcn", MCNFailureExperiment) |