Vince Lehman | b8b1806 | 2015-07-14 13:07:22 -0500 | [diff] [blame] | 1 | # -*- 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/>. |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 23 | |
| 24 | from ndn.experiments.experiment import Experiment |
| 25 | from ndn.nlsr import Nlsr |
| 26 | |
| 27 | import time |
| 28 | |
| 29 | class FailureExperiment(Experiment): |
| 30 | |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 31 | def __init__(self, args): |
| 32 | args["nPings"] = 300 |
| 33 | Experiment.__init__(self, args) |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 34 | |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 35 | self.PING_COLLECTION_TIME_BEFORE_FAILURE = 60 |
Ashlesh Gawande | 1cebdfc | 2015-10-14 14:58:33 -0500 | [diff] [blame] | 36 | self.PING_COLLECTION_TIME_AFTER_RECOVERY = 120 |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 37 | |
| 38 | def run(self): |
| 39 | self.startPings() |
| 40 | |
| 41 | # After the pings are scheduled, collect pings for 1 minute |
| 42 | time.sleep(self.PING_COLLECTION_TIME_BEFORE_FAILURE) |
| 43 | |
| 44 | # Bring down CSU |
| 45 | for host in self.net.hosts: |
| 46 | if host.name == "csu": |
Vince Lehman | d96eed3 | 2015-10-22 13:57:27 -0500 | [diff] [blame] | 47 | self.failNode(host) |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 48 | break |
| 49 | |
| 50 | # CSU is down for 2 minutes |
| 51 | time.sleep(120) |
| 52 | |
| 53 | # Bring CSU back up |
| 54 | for host in self.net.hosts: |
| 55 | if host.name == "csu": |
Vince Lehman | d96eed3 | 2015-10-22 13:57:27 -0500 | [diff] [blame] | 56 | self.recoverNode(host) |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 57 | |
Ashlesh Gawande | 1cebdfc | 2015-10-14 14:58:33 -0500 | [diff] [blame] | 58 | for other in self.net.hosts: |
| 59 | if host.name != other.name: |
| 60 | self.ping(host, other, self.PING_COLLECTION_TIME_AFTER_RECOVERY) |
| 61 | |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 62 | # Collect pings for more seconds after CSU is up |
| 63 | time.sleep(self.PING_COLLECTION_TIME_AFTER_RECOVERY) |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 64 | |
| 65 | Experiment.register("failure", FailureExperiment) |