blob: 6b4ce6b35dab6e380666ee7c3c8fb7ab7ab06a52 [file] [log] [blame]
Vince Lehmanb8b18062015-07-14 13:07:22 -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.
Vince Lehmanb8b18062015-07-14 13:07:22 -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/>.
Vince Lehmancb20c542015-05-12 14:04:47 -050023
24from ndn.experiments.experiment import Experiment
25from ndn.nlsr import Nlsr
dulalsaurab2b899532018-10-25 18:02:15 +000026from ndn.apps.ndn_ping_client import NDNPingClient
Vince Lehmancb20c542015-05-12 14:04:47 -050027
28import time
29
30class MultipleFailureExperiment(Experiment):
31
Vince Lehman3b8bc652015-06-18 15:01:47 -050032 def __init__(self, args):
Vince Lehmancb20c542015-05-12 14:04:47 -050033
34 self.PING_COLLECTION_TIME_BEFORE_FAILURE = 60
35
36 self.FAILURE_INTERVAL = 60
37 self.RECOVERY_INTERVAL = 60
38
39 # This is the number of pings required to make it through the full experiment
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -050040 nInitialPings = (self.PING_COLLECTION_TIME_BEFORE_FAILURE +
41 len(args["net"].hosts)*(self.FAILURE_INTERVAL + self.RECOVERY_INTERVAL))
Vince Lehmancb20c542015-05-12 14:04:47 -050042 print("Scheduling with %s initial pings" % nInitialPings)
43
Vince Lehman3b8bc652015-06-18 15:01:47 -050044 args["nPings"] = nInitialPings
45
46 Experiment.__init__(self, args)
Vince Lehmancb20c542015-05-12 14:04:47 -050047
Vince Lehmancb20c542015-05-12 14:04:47 -050048 def run(self):
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -050049 self.startPctPings()
Vince Lehmancb20c542015-05-12 14:04:47 -050050
51 # After the pings are scheduled, collect pings for 1 minute
52 time.sleep(self.PING_COLLECTION_TIME_BEFORE_FAILURE)
53
54 nNodesRemainingToFail = len(self.net.hosts)
55
56 # Fail and recover each node
57 for host in self.net.hosts:
58 # Fail the node
59 self.failNode(host)
60
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -050061 # Stay in failure state for FAILURE_INTERVAL seconds
Vince Lehmancb20c542015-05-12 14:04:47 -050062 time.sleep(self.FAILURE_INTERVAL)
63
64 # Bring the node back up
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -050065 start_time = time.time()
Vince Lehmancb20c542015-05-12 14:04:47 -050066 self.recoverNode(host)
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -050067 recovery_time = int(time.time() - start_time)
Vince Lehmancb20c542015-05-12 14:04:47 -050068
69 # Number of pings required to reach the end of the test
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -050070 nNodesRemainingToFail -= 1
71 nPings = ((self.RECOVERY_INTERVAL - recovery_time) +
72 nNodesRemainingToFail*(self.FAILURE_INTERVAL + self.RECOVERY_INTERVAL))
Vince Lehmancb20c542015-05-12 14:04:47 -050073
Vince Lehmancb20c542015-05-12 14:04:47 -050074 print("Scheduling with %s remaining pings" % nPings)
75
76 # Restart pings
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -050077 for nodeToPing in self.pingedDict[host]:
dulalsaurab2b899532018-10-25 18:02:15 +000078 NDNPingClient.ping(host, nodeToPing, nPings)
Vince Lehmancb20c542015-05-12 14:04:47 -050079
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -050080 time.sleep(self.RECOVERY_INTERVAL - recovery_time)
Vince Lehman3b8bc652015-06-18 15:01:47 -050081
82Experiment.register("multiple-failure", MultipleFailureExperiment)