Ashlesh Gawande | 6c86e30 | 2019-09-17 22:27:05 -0500 | [diff] [blame] | 1 | # -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | # |
Saurab Dulal | 576a419 | 2020-08-25 00:55:22 -0500 | [diff] [blame] | 3 | # Copyright (C) 2015-2020, 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 | import sys |
| 26 | from itertools import cycle |
| 27 | |
| 28 | from mininet.log import info |
| 29 | |
| 30 | from minindn.helpers.nfdc import Nfdc |
| 31 | from minindn.helpers.ndnpingclient import NDNPingClient |
| 32 | |
| 33 | class Experiment(object): |
| 34 | @staticmethod |
| 35 | def checkConvergence(ndn, hosts, convergenceTime, quit=False): |
| 36 | # Wait for convergence time period |
| 37 | info('Waiting {} seconds for convergence...\n'.format(convergenceTime)) |
| 38 | time.sleep(convergenceTime) |
| 39 | info('...done\n') |
| 40 | |
| 41 | # To check whether all the nodes of NLSR have converged |
| 42 | didNlsrConverge = True |
| 43 | |
| 44 | # Checking for convergence |
| 45 | for host in hosts: |
| 46 | statusRouter = host.cmd('nfdc fib list | grep site/%C1.Router/cs/') |
| 47 | statusPrefix = host.cmd('nfdc fib list | grep ndn | grep site | grep -v Router') |
| 48 | didNodeConverge = True |
| 49 | for node in hosts: |
| 50 | # Node has its own router name in the fib list, but not name prefix |
| 51 | if (('/ndn/{}-site/%C1.Router/cs/{}'.format(node.name, node.name)) not in statusRouter or |
| 52 | host.name != node.name and ('/ndn/{}-site/{}'.format(node.name, node.name)) not in statusPrefix): |
| 53 | didNodeConverge = False |
| 54 | didNlsrConverge = False |
| 55 | |
| 56 | host.cmd('echo {} > convergence-result &'.format(didNodeConverge)) |
| 57 | |
| 58 | if not didNlsrConverge: |
| 59 | info('NLSR has not converged. Exiting...\n') |
| 60 | if quit: |
| 61 | ndn.stop() |
| 62 | sys.exit(1) |
| 63 | else: |
| 64 | info('NLSR has converged successfully.\n') |
| 65 | |
| 66 | return didNlsrConverge |
| 67 | |
| 68 | @staticmethod |
| 69 | def setupPing(hosts, strategy): |
| 70 | for host in hosts: |
| 71 | host.cmd('mkdir -p ping-data') |
| 72 | Nfdc.setStrategy(host, '/ndn/', strategy) |
| 73 | host.cmd('ndnpingserver /ndn/{}-site/{} > ping-server &'.format(host.name, host.name)) |
| 74 | |
| 75 | @staticmethod |
| 76 | def startPctPings(net, nPings, pctTraffic=1.0): |
| 77 | nNodesToPing = int(round(len(net.hosts) * pctTraffic)) |
| 78 | info('Each node will ping {} node(s)\n'.format(nNodesToPing)) |
| 79 | # Temporarily store all the nodes being pinged by a particular node |
| 80 | nodesPingedList = [] |
| 81 | pingedDict = {} |
| 82 | |
| 83 | for host in net.hosts: |
| 84 | # Create a circular list |
| 85 | pool = cycle(net.hosts) |
| 86 | |
| 87 | # Move iterator to current node |
| 88 | next(x for x in pool if host.name == x.name) |
| 89 | |
| 90 | # Track number of nodes to ping scheduled for this node |
| 91 | nNodesScheduled = 0 |
| 92 | |
| 93 | while nNodesScheduled < nNodesToPing: |
| 94 | other = next(pool) |
| 95 | |
| 96 | # Do not ping self |
| 97 | if host.name != other.name: |
| 98 | NDNPingClient.ping(host, other, nPings) |
| 99 | nodesPingedList.append(other) |
| 100 | |
| 101 | # Always increment because in 100% case a node should not ping itself |
| 102 | nNodesScheduled = nNodesScheduled + 1 |
| 103 | |
| 104 | pingedDict[host] = nodesPingedList |
| 105 | nodesPingedList = [] |
| 106 | |
| 107 | return pingedDict |