blob: cc3fa09a0efc018de3916aac696b5aeb406b3b95 [file] [log] [blame]
Ashlesh Gawande5fee7762015-10-28 16:01:55 -05001# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2#
3# Copyright (C) 2015 The University of Memphis,
4# Arizona Board of Regents,
5# Regents of the University of California.
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
24from ndn.experiments.experiment import Experiment
25from ndn.nlsr import Nlsr
26
27import time
28
29class FailureExperiment(Experiment):
30
31 def __init__(self, args):
32 args["nPings"] = 300
33 Experiment.__init__(self, args)
34
35 self.PING_COLLECTION_TIME_BEFORE_FAILURE = 60
36 self.PING_COLLECTION_TIME_AFTER_RECOVERY = 120
37
38 def getMostConnectedNode(self):
39 mcn = max(self.net.hosts, key=lambda host: len(host.intfNames()))
40 print "The most connected node is: %s" % mcn.name
41 return mcn
42
43 def run(self):
44 mostConnectedNode = self.getMostConnectedNode()
45
46 self.startPctPings()
47
48 # After the pings are scheduled, collect pings for 1 minute
49 time.sleep(self.PING_COLLECTION_TIME_BEFORE_FAILURE)
50
51 # Bring down MCN
52 self.failNode(mostConnectedNode)
53
54 # MCN is down for 2 minutes
55 time.sleep(120)
56
57 # Bring MCN back up
58 self.recoverNode(mostConnectedNode)
59
60 # Restart pings
61 for nodeToPing in self.pingedDict[mostConnectedNode]:
62 self.ping(mostConnectedNode, nodeToPing, self.PING_COLLECTION_TIME_AFTER_RECOVERY)
63
64 # Collect pings for more seconds after MCN is up
65 time.sleep(self.PING_COLLECTION_TIME_AFTER_RECOVERY)
66
67Experiment.register("failure-mcn", FailureExperiment)