blob: 910b239b21ce8b88676f8878cc6194dfaadfd49d [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
36 def checkConvergence(ndn, hosts, convergenceTime, quit=False):
37 # Wait for convergence time period
38 info('Waiting {} seconds for convergence...\n'.format(convergenceTime))
39 time.sleep(convergenceTime)
40 info('...done\n')
41
42 # To check whether all the nodes of NLSR have converged
43 didNlsrConverge = True
44
45 # Checking for convergence
46 for host in hosts:
47 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')
49 didNodeConverge = True
50 for node in hosts:
51 # Node has its own router name in the fib list, but not name prefix
52 if (('/ndn/{}-site/%C1.Router/cs/{}'.format(node.name, node.name)) not in statusRouter or
53 host.name != node.name and ('/ndn/{}-site/{}'.format(node.name, node.name)) not in statusPrefix):
54 didNodeConverge = False
55 didNlsrConverge = False
56
57 host.cmd('echo {} > convergence-result &'.format(didNodeConverge))
58
59 if not didNlsrConverge:
60 info('NLSR has not converged. Exiting...\n')
61 if quit:
62 ndn.stop()
63 sys.exit(1)
64 else:
65 info('NLSR has converged successfully.\n')
66
67 return didNlsrConverge
68
69 @staticmethod
70 def setupPing(hosts, strategy):
71 for host in hosts:
72 host.cmd('mkdir -p ping-data')
73 Nfdc.setStrategy(host, '/ndn/', strategy)
dulalsaurab0ed77722020-09-24 22:32:58 +000074 prefix = getSafeName('/ndn/{}-site/{}'.format(host.name, host.name))
75 NDNPing.startPingServer(host, prefix)
Ashlesh Gawande6c86e302019-09-17 22:27:05 -050076
77 @staticmethod
78 def startPctPings(net, nPings, pctTraffic=1.0):
79 nNodesToPing = int(round(len(net.hosts) * pctTraffic))
80 info('Each node will ping {} node(s)\n'.format(nNodesToPing))
81 # Temporarily store all the nodes being pinged by a particular node
82 nodesPingedList = []
83 pingedDict = {}
84
85 for host in net.hosts:
86 # Create a circular list
87 pool = cycle(net.hosts)
88
89 # Move iterator to current node
90 next(x for x in pool if host.name == x.name)
91
92 # Track number of nodes to ping scheduled for this node
93 nNodesScheduled = 0
94
95 while nNodesScheduled < nNodesToPing:
96 other = next(pool)
97
98 # Do not ping self
99 if host.name != other.name:
dulalsaurab0ed77722020-09-24 22:32:58 +0000100 destPrefix = getSafeName('/ndn/{}-site/{}'.format(other.name, other.name))
101 NDNPing.ping(host, destPrefix, other.name, nPings)
Ashlesh Gawande6c86e302019-09-17 22:27:05 -0500102 nodesPingedList.append(other)
103
104 # Always increment because in 100% case a node should not ping itself
105 nNodesScheduled = nNodesScheduled + 1
106
107 pingedDict[host] = nodesPingedList
108 nodesPingedList = []
109
110 return pingedDict