blob: efbba6093ff471103453d3f0e76b2ed2e2b17df9 [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
dulalsaurab2b899532018-10-25 18:02:15 +000025from ndn.apps.ndn_ping_client import NDNPingClient
Vince Lehmancb20c542015-05-12 14:04:47 -050026
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
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -050039 nInitialPings = (self.PING_COLLECTION_TIME_BEFORE_FAILURE +
Ashlesh Gawande27b5e1b2018-08-06 17:47:15 -050040 len(args["net"].hosts) * (self.FAILURE_INTERVAL + self.RECOVERY_INTERVAL))
41 print("Scheduling with {} initial pings".format(nInitialPings))
Vince Lehman3b8bc652015-06-18 15:01:47 -050042
43 Experiment.__init__(self, args)
Ashlesh Gawande27b5e1b2018-08-06 17:47:15 -050044 self.options.nPings = nInitialPings
Vince Lehmancb20c542015-05-12 14:04:47 -050045
Vince Lehmancb20c542015-05-12 14:04:47 -050046 def run(self):
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -050047 self.startPctPings()
Vince Lehmancb20c542015-05-12 14:04:47 -050048
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
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -050059 # Stay in failure state for FAILURE_INTERVAL seconds
Vince Lehmancb20c542015-05-12 14:04:47 -050060 time.sleep(self.FAILURE_INTERVAL)
61
62 # Bring the node back up
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -050063 start_time = time.time()
Vince Lehmancb20c542015-05-12 14:04:47 -050064 self.recoverNode(host)
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -050065 recovery_time = int(time.time() - start_time)
Vince Lehmancb20c542015-05-12 14:04:47 -050066
67 # Number of pings required to reach the end of the test
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -050068 nNodesRemainingToFail -= 1
69 nPings = ((self.RECOVERY_INTERVAL - recovery_time) +
70 nNodesRemainingToFail*(self.FAILURE_INTERVAL + self.RECOVERY_INTERVAL))
Vince Lehmancb20c542015-05-12 14:04:47 -050071
Ashlesh Gawande27b5e1b2018-08-06 17:47:15 -050072 print("Scheduling with {} remaining pings".format(nPings))
Vince Lehmancb20c542015-05-12 14:04:47 -050073
74 # Restart pings
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -050075 for nodeToPing in self.pingedDict[host]:
dulalsaurab2b899532018-10-25 18:02:15 +000076 NDNPingClient.ping(host, nodeToPing, nPings)
Vince Lehmancb20c542015-05-12 14:04:47 -050077
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -050078 time.sleep(self.RECOVERY_INTERVAL - recovery_time)
Vince Lehman3b8bc652015-06-18 15:01:47 -050079
80Experiment.register("multiple-failure", MultipleFailureExperiment)