blob: b6c2b028944cd11d84797c09bd66edd063a72a8a [file] [log] [blame]
Ashlesh Gawande6c86e302019-09-17 22:27:05 -05001# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2#
Saurab Dulal576a4192020-08-25 00:55:22 -05003# Copyright (C) 2015-2020, The University of Memphis,
Ashlesh Gawande6c86e302019-09-17 22:27:05 -05004# 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
24import time
25import sys
awlane595cbda2024-11-06 15:16:26 -060026import argparse
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050027from itertools import cycle
28
29from mininet.log import info
30
31from minindn.helpers.nfdc import Nfdc
dulalsaurab0ed77722020-09-24 22:32:58 +000032from minindn.helpers.ndnping import NDNPing
33from minindn.util import getSafeName
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050034
35class Experiment(object):
36 @staticmethod
dhensley6691edd777f2022-12-06 14:24:19 -060037 def checkConvergence(ndn, hosts, convergenceTime, quit=False, returnConvergenceInfo=False):
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050038 # Wait for convergence time period
39 info('Waiting {} seconds for convergence...\n'.format(convergenceTime))
40 time.sleep(convergenceTime)
41 info('...done\n')
42
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050043 didNlsrConverge = True
dhensley6691edd777f2022-12-06 14:24:19 -060044 convergeInfo = {}
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050045
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050046 for host in hosts:
dhensley6691edd777f2022-12-06 14:24:19 -060047 convergeInfo[host.name] = {}
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050048 statusRouter = host.cmd('nfdc fib list | grep site/%C1.Router/cs/')
49 statusPrefix = host.cmd('nfdc fib list | grep ndn | grep site | grep -v Router')
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050050 for node in hosts:
51 # Node has its own router name in the fib list, but not name prefix
dhensley6691edd777f2022-12-06 14:24:19 -060052 routerPrefix = ('/ndn/{}-site/%C1.Router/cs/{}'.format(node.name, node.name))
53 namePrefix = ('/ndn/{}-site/{}'.format(node.name, node.name))
54
55 statusRouterCheck = routerPrefix not in statusRouter
56 statusPrefixCheck = host.name != node.name and namePrefix not in statusPrefix
57
58 if statusRouterCheck or statusPrefixCheck:
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050059 didNlsrConverge = False
dhensley6691edd777f2022-12-06 14:24:19 -060060 host.cmd('echo {} > convergence-result &'.format(False))
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050061
dhensley6691edd777f2022-12-06 14:24:19 -060062 if returnConvergenceInfo:
63 convergeInfo[host.name][node.name] = []
64 if statusRouterCheck:
65 convergeInfo[host.name][node.name].append(routerPrefix)
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050066
dhensley6691edd777f2022-12-06 14:24:19 -060067 if statusPrefixCheck:
68 convergeInfo[host.name][node.name].append(namePrefix)
69 else:
70 host.cmd('echo {} > convergence-result &'.format(True))
71
72 if didNlsrConverge:
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050073 if quit:
dhensley6691edd777f2022-12-06 14:24:19 -060074 info('NLSR has converged successfully. Exiting...\n')
75 ndn.stop()
76 sys.exit(0)
77 else:
78 info('NLSR has converged successfully.\n')
79 else:
80 if quit:
81 info('NLSR has not converged. Exiting...\n')
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050082 ndn.stop()
83 sys.exit(1)
dhensley6691edd777f2022-12-06 14:24:19 -060084 else:
85 info('NLSR has not converged.\n')
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050086
dhensley6691edd777f2022-12-06 14:24:19 -060087 if returnConvergenceInfo:
88 return didNlsrConverge, convergeInfo
89 else:
90 return didNlsrConverge
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050091
92 @staticmethod
93 def setupPing(hosts, strategy):
94 for host in hosts:
95 host.cmd('mkdir -p ping-data')
96 Nfdc.setStrategy(host, '/ndn/', strategy)
dulalsaurab0ed77722020-09-24 22:32:58 +000097 prefix = getSafeName('/ndn/{}-site/{}'.format(host.name, host.name))
98 NDNPing.startPingServer(host, prefix)
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050099
100 @staticmethod
101 def startPctPings(net, nPings, pctTraffic=1.0):
102 nNodesToPing = int(round(len(net.hosts) * pctTraffic))
103 info('Each node will ping {} node(s)\n'.format(nNodesToPing))
104 # Temporarily store all the nodes being pinged by a particular node
105 nodesPingedList = []
106 pingedDict = {}
107
108 for host in net.hosts:
109 # Create a circular list
110 pool = cycle(net.hosts)
111
112 # Move iterator to current node
113 next(x for x in pool if host.name == x.name)
114
115 # Track number of nodes to ping scheduled for this node
116 nNodesScheduled = 0
117
118 while nNodesScheduled < nNodesToPing:
119 other = next(pool)
120
121 # Do not ping self
122 if host.name != other.name:
dulalsaurab0ed77722020-09-24 22:32:58 +0000123 destPrefix = getSafeName('/ndn/{}-site/{}'.format(other.name, other.name))
124 NDNPing.ping(host, destPrefix, other.name, nPings)
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500125 nodesPingedList.append(other)
126
127 # Always increment because in 100% case a node should not ping itself
128 nNodesScheduled = nNodesScheduled + 1
129
130 pingedDict[host] = nodesPingedList
131 nodesPingedList = []
132
133 return pingedDict
awlane595cbda2024-11-06 15:16:26 -0600134
135 import argparse
136
137 @staticmethod
138 def getWifiExperimentParser(parent=argparse.ArgumentParser()):
139 parser = argparse.ArgumentParser(prog='minindn-wifi', parents=[parent], add_help=False)
140
141 parser.add_argument('--mobility',action='store_true',dest='mobility',default=False,
142 help='Enable custom mobility for topology (defined in script)')
143 parser.add_argument('--model-mob',action='store_true',dest='modelMob',default=False,
144 help='Enable model mobility for topology (defined in script; see adhoc experiment for how to specify in topology file)')
145 return parser