blob: 1736f9ab51fa38dc6f2d168bdfc380c09a3f89b9 [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
46 def failNode(self, host):
47 print("Bringing %s down" % host.name)
48 host.nfd.stop()
49
50 def recoverNode(self, host):
51 print("Bringing %s up" % host.name)
52 host.nfd.start()
53 host.nlsr.start()
54 host.nfd.setStrategy("/ndn/edu", self.strategy)
55 host.cmd("ndnpingserver /ndn/edu/" + str(host) + " > ping-server &")
56
57 def run(self):
58 self.startPings()
59
60 # After the pings are scheduled, collect pings for 1 minute
61 time.sleep(self.PING_COLLECTION_TIME_BEFORE_FAILURE)
62
63 nNodesRemainingToFail = len(self.net.hosts)
64
65 # Fail and recover each node
66 for host in self.net.hosts:
67 # Fail the node
68 self.failNode(host)
69
70 # Stay in failure state for FAILURE_INTERVAL
71 time.sleep(self.FAILURE_INTERVAL)
72
73 # Bring the node back up
74 self.recoverNode(host)
75
76 # Number of pings required to reach the end of the test
77 nPings = self.RECOVERY_INTERVAL + nNodesRemainingToFail*(self.FAILURE_INTERVAL + self.RECOVERY_INTERVAL)
78 nNodesRemainingToFail = nNodesRemainingToFail - 1
79
80 # Wait for NFD and NLSR to fully recover
81 time.sleep(1)
82 print("Scheduling with %s remaining pings" % nPings)
83
84 # Restart pings
85 for other in self.net.hosts:
86 # Do not ping self
87 if host.name != other.name:
88 self.ping(host, other, nPings)
89
90 time.sleep(self.RECOVERY_INTERVAL)
Vince Lehman3b8bc652015-06-18 15:01:47 -050091
92Experiment.register("multiple-failure", MultipleFailureExperiment)