blob: bea9a7823928bba702e77629c544d459f8dde037 [file] [log] [blame]
Vince Lehmanb8b18062015-07-14 13:07:22 -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/>.
Vince Lehmancb20c542015-05-12 14:04:47 -050023
24from ndn.experiments.experiment import Experiment
25from ndn.nlsr import Nlsr
26
27import time
28
29class MultipleFailureExperiment(Experiment):
30
Vince Lehman3b8bc652015-06-18 15:01:47 -050031 def __init__(self, args):
Vince Lehmancb20c542015-05-12 14:04:47 -050032
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
Vince Lehman3b8bc652015-06-18 15:01:47 -050039 nInitialPings = self.PING_COLLECTION_TIME_BEFORE_FAILURE + len(args["net"].hosts)*(self.FAILURE_INTERVAL + self.RECOVERY_INTERVAL)
Vince Lehmancb20c542015-05-12 14:04:47 -050040 print("Scheduling with %s initial pings" % nInitialPings)
41
Vince Lehman3b8bc652015-06-18 15:01:47 -050042 args["nPings"] = nInitialPings
43
44 Experiment.__init__(self, args)
Vince Lehmancb20c542015-05-12 14:04:47 -050045
Vince Lehmancb20c542015-05-12 14:04:47 -050046 def run(self):
47 self.startPings()
48
49 # After the pings are scheduled, collect pings for 1 minute
50 time.sleep(self.PING_COLLECTION_TIME_BEFORE_FAILURE)
51
52 nNodesRemainingToFail = len(self.net.hosts)
53
54 # Fail and recover each node
55 for host in self.net.hosts:
56 # Fail the node
57 self.failNode(host)
58
59 # Stay in failure state for FAILURE_INTERVAL
60 time.sleep(self.FAILURE_INTERVAL)
61
62 # Bring the node back up
63 self.recoverNode(host)
64
65 # Number of pings required to reach the end of the test
66 nPings = self.RECOVERY_INTERVAL + nNodesRemainingToFail*(self.FAILURE_INTERVAL + self.RECOVERY_INTERVAL)
67 nNodesRemainingToFail = nNodesRemainingToFail - 1
68
69 # Wait for NFD and NLSR to fully recover
70 time.sleep(1)
71 print("Scheduling with %s remaining pings" % nPings)
72
73 # Restart pings
74 for other in self.net.hosts:
75 # Do not ping self
76 if host.name != other.name:
77 self.ping(host, other, nPings)
78
79 time.sleep(self.RECOVERY_INTERVAL)
Vince Lehman3b8bc652015-06-18 15:01:47 -050080
81Experiment.register("multiple-failure", MultipleFailureExperiment)