blob: cd448ccebfe8bd3b8566ae37f62e2fd9a320426e [file] [log] [blame]
Ashlesh Gawande5fee7762015-10-28 16:01:55 -05001# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2#
Alexander Lane9944cf52018-05-17 12:16:50 -05003# Copyright (C) 2015-2018, The University of Memphis,
Ashlesh Gawandeda475f02017-03-01 17:20:58 -06004# Arizona Board of Regents,
5# Regents of the University of California.
Ashlesh Gawande5fee7762015-10-28 16:01:55 -05006#
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
24from ndn.experiments.experiment import Experiment
dulalsaurab2b899532018-10-25 18:02:15 +000025from ndn.apps.ndn_ping_client import NDNPingClient
Ashlesh Gawande5fee7762015-10-28 16:01:55 -050026
27import time
28
Ashlesh Gawande5f470202017-02-25 12:02:53 -060029class MCNFailureExperiment(Experiment):
Ashlesh Gawande5fee7762015-10-28 16:01:55 -050030
31 def __init__(self, args):
Ashlesh Gawande5fee7762015-10-28 16:01:55 -050032 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 Gawande27b5e1b2018-08-06 17:47:15 -050039 print "The most connected node is: {}".format(mcn.name)
Ashlesh Gawande5fee7762015-10-28 16:01:55 -050040 return mcn
41
Ashlesh Gawande27b5e1b2018-08-06 17:47:15 -050042 def setup(self):
43 if self.options.nPings != 0:
44 Experiment.setup(self)
45
Ashlesh Gawande5fee7762015-10-28 16:01:55 -050046 def run(self):
47 mostConnectedNode = self.getMostConnectedNode()
48
Ashlesh Gawande27b5e1b2018-08-06 17:47:15 -050049 if self.options.nPings != 0:
50 self.startPctPings()
Ashlesh Gawande5fee7762015-10-28 16:01:55 -050051
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 Gawande27b5e1b2018-08-06 17:47:15 -050059 time.sleep(int(self.options.arguments.waitTime))
Ashlesh Gawande5fee7762015-10-28 16:01:55 -050060
61 # Bring MCN back up
62 self.recoverNode(mostConnectedNode)
63
64 # Restart pings
Ashlesh Gawande27b5e1b2018-08-06 17:47:15 -050065 if self.options.nPings != 0:
66 for nodeToPing in self.pingedDict[mostConnectedNode]:
67 NDNPingClient.ping(mostConnectedNode, nodeToPing, self.PING_COLLECTION_TIME_AFTER_RECOVERY)
Ashlesh Gawande5fee7762015-10-28 16:01:55 -050068
Ashlesh Gawande27b5e1b2018-08-06 17:47:15 -050069 # Collect pings for more seconds after MCN is up
70 time.sleep(self.PING_COLLECTION_TIME_AFTER_RECOVERY)
71 else:
72 self.checkConvergence()
Ashlesh Gawande5fee7762015-10-28 16:01:55 -050073
Ashlesh Gawande27b5e1b2018-08-06 17:47:15 -050074 @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
79Experiment.register("mcn-failure", MCNFailureExperiment)