Ashlesh Gawande | 5fee776 | 2015-10-28 16:01:55 -0500 | [diff] [blame] | 1 | # -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | # |
Alexander Lane | 9944cf5 | 2018-05-17 12:16:50 -0500 | [diff] [blame] | 3 | # Copyright (C) 2015-2018, The University of Memphis, |
Ashlesh Gawande | da475f0 | 2017-03-01 17:20:58 -0600 | [diff] [blame] | 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 |
dulalsaurab | 2b89953 | 2018-10-25 18:02:15 +0000 | [diff] [blame] | 25 | from ndn.apps.ndn_ping_client import NDNPingClient |
Ashlesh Gawande | 5fee776 | 2015-10-28 16:01:55 -0500 | [diff] [blame] | 26 | |
| 27 | import time |
| 28 | |
Ashlesh Gawande | 5f47020 | 2017-02-25 12:02:53 -0600 | [diff] [blame] | 29 | class MCNFailureExperiment(Experiment): |
Ashlesh Gawande | 5fee776 | 2015-10-28 16:01:55 -0500 | [diff] [blame] | 30 | |
| 31 | def __init__(self, args): |
Ashlesh Gawande | 5fee776 | 2015-10-28 16:01:55 -0500 | [diff] [blame] | 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())) |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame] | 39 | print "The most connected node is: {}".format(mcn.name) |
Ashlesh Gawande | 5fee776 | 2015-10-28 16:01:55 -0500 | [diff] [blame] | 40 | return mcn |
| 41 | |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame] | 42 | def setup(self): |
| 43 | if self.options.nPings != 0: |
| 44 | Experiment.setup(self) |
| 45 | |
Ashlesh Gawande | 5fee776 | 2015-10-28 16:01:55 -0500 | [diff] [blame] | 46 | def run(self): |
| 47 | mostConnectedNode = self.getMostConnectedNode() |
| 48 | |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame] | 49 | if self.options.nPings != 0: |
| 50 | self.startPctPings() |
Ashlesh Gawande | 5fee776 | 2015-10-28 16:01:55 -0500 | [diff] [blame] | 51 | |
| 52 | # After the pings are scheduled, collect pings for 1 minute |
| 53 | time.sleep(self.PING_COLLECTION_TIME_BEFORE_FAILURE) |
| 54 | |
| 55 | # Bring down MCN |
| 56 | self.failNode(mostConnectedNode) |
| 57 | |
| 58 | # MCN is down for 2 minutes |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame] | 59 | time.sleep(int(self.options.arguments.waitTime)) |
Ashlesh Gawande | 5fee776 | 2015-10-28 16:01:55 -0500 | [diff] [blame] | 60 | |
| 61 | # Bring MCN back up |
| 62 | self.recoverNode(mostConnectedNode) |
| 63 | |
| 64 | # Restart pings |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame] | 65 | if self.options.nPings != 0: |
| 66 | for nodeToPing in self.pingedDict[mostConnectedNode]: |
| 67 | NDNPingClient.ping(mostConnectedNode, nodeToPing, self.PING_COLLECTION_TIME_AFTER_RECOVERY) |
Ashlesh Gawande | 5fee776 | 2015-10-28 16:01:55 -0500 | [diff] [blame] | 68 | |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame] | 69 | # Collect pings for more seconds after MCN is up |
| 70 | time.sleep(self.PING_COLLECTION_TIME_AFTER_RECOVERY) |
| 71 | else: |
| 72 | self.checkConvergence() |
Ashlesh Gawande | 5fee776 | 2015-10-28 16:01:55 -0500 | [diff] [blame] | 73 | |
Ashlesh Gawande | 27b5e1b | 2018-08-06 17:47:15 -0500 | [diff] [blame] | 74 | @staticmethod |
| 75 | def parseArguments(parser): |
| 76 | parser.add_argument("--wait-time", dest="waitTime", default="120", |
| 77 | help="[Experiment] Generic wait time for experiment use") |
| 78 | |
| 79 | Experiment.register("mcn-failure", MCNFailureExperiment) |