blob: c454ff4e8d49b7ab705ba3e04a7d3fb88f99d1bf [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
26from itertools import cycle
27
28from mininet.log import info
29
30from minindn.helpers.nfdc import Nfdc
dulalsaurab0ed77722020-09-24 22:32:58 +000031from minindn.helpers.ndnping import NDNPing
32from minindn.util import getSafeName
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050033
34class Experiment(object):
35 @staticmethod
dhensley6691edd777f2022-12-06 14:24:19 -060036 def checkConvergence(ndn, hosts, convergenceTime, quit=False, returnConvergenceInfo=False):
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050037 # Wait for convergence time period
38 info('Waiting {} seconds for convergence...\n'.format(convergenceTime))
39 time.sleep(convergenceTime)
40 info('...done\n')
41
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050042 didNlsrConverge = True
dhensley6691edd777f2022-12-06 14:24:19 -060043 convergeInfo = {}
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050044
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050045 for host in hosts:
dhensley6691edd777f2022-12-06 14:24:19 -060046 convergeInfo[host.name] = {}
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050047 statusRouter = host.cmd('nfdc fib list | grep site/%C1.Router/cs/')
48 statusPrefix = host.cmd('nfdc fib list | grep ndn | grep site | grep -v Router')
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050049 for node in hosts:
50 # Node has its own router name in the fib list, but not name prefix
dhensley6691edd777f2022-12-06 14:24:19 -060051 routerPrefix = ('/ndn/{}-site/%C1.Router/cs/{}'.format(node.name, node.name))
52 namePrefix = ('/ndn/{}-site/{}'.format(node.name, node.name))
53
54 statusRouterCheck = routerPrefix not in statusRouter
55 statusPrefixCheck = host.name != node.name and namePrefix not in statusPrefix
56
57 if statusRouterCheck or statusPrefixCheck:
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050058 didNlsrConverge = False
dhensley6691edd777f2022-12-06 14:24:19 -060059 host.cmd('echo {} > convergence-result &'.format(False))
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050060
dhensley6691edd777f2022-12-06 14:24:19 -060061 if returnConvergenceInfo:
62 convergeInfo[host.name][node.name] = []
63 if statusRouterCheck:
64 convergeInfo[host.name][node.name].append(routerPrefix)
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050065
dhensley6691edd777f2022-12-06 14:24:19 -060066 if statusPrefixCheck:
67 convergeInfo[host.name][node.name].append(namePrefix)
68 else:
69 host.cmd('echo {} > convergence-result &'.format(True))
70
71 if didNlsrConverge:
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050072 if quit:
dhensley6691edd777f2022-12-06 14:24:19 -060073 info('NLSR has converged successfully. Exiting...\n')
74 ndn.stop()
75 sys.exit(0)
76 else:
77 info('NLSR has converged successfully.\n')
78 else:
79 if quit:
80 info('NLSR has not converged. Exiting...\n')
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050081 ndn.stop()
82 sys.exit(1)
dhensley6691edd777f2022-12-06 14:24:19 -060083 else:
84 info('NLSR has not converged.\n')
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050085
dhensley6691edd777f2022-12-06 14:24:19 -060086 if returnConvergenceInfo:
87 return didNlsrConverge, convergeInfo
88 else:
89 return didNlsrConverge
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050090
91 @staticmethod
92 def setupPing(hosts, strategy):
93 for host in hosts:
94 host.cmd('mkdir -p ping-data')
95 Nfdc.setStrategy(host, '/ndn/', strategy)
dulalsaurab0ed77722020-09-24 22:32:58 +000096 prefix = getSafeName('/ndn/{}-site/{}'.format(host.name, host.name))
97 NDNPing.startPingServer(host, prefix)
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050098
99 @staticmethod
100 def startPctPings(net, nPings, pctTraffic=1.0):
101 nNodesToPing = int(round(len(net.hosts) * pctTraffic))
102 info('Each node will ping {} node(s)\n'.format(nNodesToPing))
103 # Temporarily store all the nodes being pinged by a particular node
104 nodesPingedList = []
105 pingedDict = {}
106
107 for host in net.hosts:
108 # Create a circular list
109 pool = cycle(net.hosts)
110
111 # Move iterator to current node
112 next(x for x in pool if host.name == x.name)
113
114 # Track number of nodes to ping scheduled for this node
115 nNodesScheduled = 0
116
117 while nNodesScheduled < nNodesToPing:
118 other = next(pool)
119
120 # Do not ping self
121 if host.name != other.name:
dulalsaurab0ed77722020-09-24 22:32:58 +0000122 destPrefix = getSafeName('/ndn/{}-site/{}'.format(other.name, other.name))
123 NDNPing.ping(host, destPrefix, other.name, nPings)
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500124 nodesPingedList.append(other)
125
126 # Always increment because in 100% case a node should not ping itself
127 nNodesScheduled = nNodesScheduled + 1
128
129 pingedDict[host] = nodesPingedList
130 nodesPingedList = []
131
132 return pingedDict