Ashlesh Gawande | 6c86e30 | 2019-09-17 22:27:05 -0500 | [diff] [blame] | 1 | # -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | # |
dulalsaurab | 578f2ec | 2021-06-10 20:55:26 +0000 | [diff] [blame] | 3 | # Copyright (C) 2015-2021, The University of Memphis, |
Ashlesh Gawande | 6c86e30 | 2019-09-17 22:27:05 -0500 | [diff] [blame] | 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/>. |
| 23 | |
| 24 | import time |
| 25 | |
| 26 | from mininet.log import setLogLevel, info |
| 27 | |
| 28 | from minindn.minindn import Minindn |
| 29 | from minindn.util import MiniNDNCLI |
| 30 | from minindn.apps.app_manager import AppManager |
| 31 | from minindn.apps.nfd import Nfd |
| 32 | from minindn.apps.nlsr import Nlsr |
| 33 | from minindn.helpers.experiment import Experiment |
| 34 | from minindn.helpers.nfdc import Nfdc |
dulalsaurab | 578f2ec | 2021-06-10 20:55:26 +0000 | [diff] [blame] | 35 | from minindn.helpers.ndnping import NDNPing |
Ashlesh Gawande | 6c86e30 | 2019-09-17 22:27:05 -0500 | [diff] [blame] | 36 | |
| 37 | from nlsr_common import getParser |
| 38 | |
| 39 | def multipleFailure(ndn, nfds, nlsrs, args): |
| 40 | |
| 41 | Experiment.checkConvergence(ndn, ndn.net.hosts, args.ctime, quit=True) |
| 42 | Experiment.setupPing(ndn.net.hosts, Nfdc.STRATEGY_BEST_ROUTE) |
| 43 | |
| 44 | PING_COLLECTION_TIME_BEFORE_FAILURE = 60 |
| 45 | FAILURE_INTERVAL = 60 |
| 46 | RECOVERY_INTERVAL = 60 |
| 47 | |
dulalsaurab | 578f2ec | 2021-06-10 20:55:26 +0000 | [diff] [blame] | 48 | # Number of pings required to make it through the full experiment |
Ashlesh Gawande | 6c86e30 | 2019-09-17 22:27:05 -0500 | [diff] [blame] | 49 | nInitialPings = (PING_COLLECTION_TIME_BEFORE_FAILURE + |
| 50 | len(ndn.net.hosts) * (FAILURE_INTERVAL + RECOVERY_INTERVAL)) |
| 51 | print('Scheduling with {} initial pings'.format(nInitialPings)) |
| 52 | |
| 53 | pingedDict = Experiment.startPctPings(ndn.net, nInitialPings, args.pctTraffic) |
| 54 | time.sleep(PING_COLLECTION_TIME_BEFORE_FAILURE) |
| 55 | |
| 56 | nNodesRemainingToFail = len(ndn.net.hosts) |
| 57 | |
| 58 | for host in ndn.net.hosts: |
| 59 | # Fail the node |
| 60 | info('Bringing down node {}\n'.format(host.name)) |
| 61 | nlsrs[host.name].stop() |
| 62 | nfds[host.name].stop() |
| 63 | |
| 64 | # Stay in failure state for FAILURE_INTERVAL seconds |
| 65 | time.sleep(FAILURE_INTERVAL) |
| 66 | |
| 67 | # Bring the node back up |
| 68 | start_time = time.time() |
| 69 | info('Bringing up node {}\n'.format(host.name)) |
| 70 | nfds[host.name].start() |
| 71 | nlsrs[host.name].start() |
| 72 | Experiment.setupPing([host], Nfdc.STRATEGY_BEST_ROUTE) |
| 73 | |
| 74 | recovery_time = int(time.time() - start_time) |
| 75 | |
| 76 | # Number of pings required to reach the end of the test |
| 77 | nNodesRemainingToFail -= 1 |
| 78 | nPings = ((RECOVERY_INTERVAL - recovery_time) + |
| 79 | nNodesRemainingToFail * (FAILURE_INTERVAL + RECOVERY_INTERVAL)) |
| 80 | |
| 81 | info('Scheduling with {} remaining pings\n'.format(nPings)) |
| 82 | |
| 83 | # Restart pings |
| 84 | for nodeToPing in pingedDict[host]: |
dulalsaurab | 578f2ec | 2021-06-10 20:55:26 +0000 | [diff] [blame] | 85 | NDNPing.ping(host, nodeToPing, nPings=nPings) |
Ashlesh Gawande | 6c86e30 | 2019-09-17 22:27:05 -0500 | [diff] [blame] | 86 | |
| 87 | time.sleep(RECOVERY_INTERVAL - recovery_time) |
| 88 | |
dulalsaurab | 578f2ec | 2021-06-10 20:55:26 +0000 | [diff] [blame] | 89 | Experiment.checkConvergence(ndn, ndn.net.hosts, args.ctime, quit=True) |
Ashlesh Gawande | 6c86e30 | 2019-09-17 22:27:05 -0500 | [diff] [blame] | 90 | |
| 91 | if __name__ == '__main__': |
| 92 | setLogLevel('info') |
| 93 | |
| 94 | ndn = Minindn(parser=getParser()) |
| 95 | args = ndn.args |
| 96 | |
| 97 | ndn.start() |
| 98 | |
| 99 | nfds = AppManager(ndn, ndn.net.hosts, Nfd) |
| 100 | nlsrs = AppManager(ndn, ndn.net.hosts, Nlsr, sync=args.sync, |
| 101 | security=args.security, faceType=args.faceType, |
| 102 | nFaces=args.faces, routingType=args.routingType) |
| 103 | |
| 104 | multipleFailure(ndn, nfds, nlsrs, args) |
| 105 | |
| 106 | if args.isCliEnabled: |
| 107 | MiniNDNCLI(ndn.net) |
| 108 | |
| 109 | ndn.stop() |