blob: fa76370bd1315af454084e06c46a0b7e46e08209 [file] [log] [blame]
Vince Lehmanb8b18062015-07-14 13:07:22 -05001# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2#
Alexander Lane9944cf52018-05-17 12:16:50 -05003# Copyright (C) 2015-2018, The University of Memphis,
Ashlesh Gawandeda475f02017-03-01 17:20:58 -06004# Arizona Board of Regents,
5# Regents of the University of California.
Vince Lehmanb8b18062015-07-14 13:07:22 -05006#
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/>.
ashu34c3ee02015-03-25 14:41:14 -050023
24import time
25import sys
Alexander Lane9944cf52018-05-17 12:16:50 -050026from ndn.apps.ndn_ping_client import NDNPingClient
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -050027from itertools import cycle
ashu34c3ee02015-03-25 14:41:14 -050028
Vince Lehman3b8bc652015-06-18 15:01:47 -050029from ndn import ExperimentManager
30
ashu34c3ee02015-03-25 14:41:14 -050031class Experiment:
32
Vince Lehman3b8bc652015-06-18 15:01:47 -050033 def __init__(self, args):
34 self.net = args["net"]
Vince Lehman3b8bc652015-06-18 15:01:47 -050035 self.convergenceTime = args["ctime"]
36 self.nPings = args["nPings"]
37 self.strategy = args["strategy"]
Ashlesh Gawande044611d2016-12-21 14:24:49 -060038 self.pctTraffic = args["pctTraffic"]
Ashlesh Gawande6a075c22017-08-03 15:15:49 -050039 self.nlsrSecurity = args["nlsrSecurity"]
Alexander Lane1bc9b472018-05-16 15:07:16 -050040 self.arguments = args["arguments"]
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -050041
42 # Used to restart pings on the recovered node if any
43 self.pingedDict = {}
44
ashu34c3ee02015-03-25 14:41:14 -050045 def start(self):
46 self.setup()
47 self.run()
48
49 def setup(self):
50 for host in self.net.hosts:
51 # Set strategy
Ashlesh Gawandee144ceb2016-11-14 13:56:24 -060052 host.nfd.setStrategy("/ndn/", self.strategy)
ashu34c3ee02015-03-25 14:41:14 -050053
54 # Start ping server
Ashlesh Gawandee144ceb2016-11-14 13:56:24 -060055 host.cmd("ndnpingserver /ndn/" + str(host) + "-site/" + str(host) + " > ping-server &")
ashu34c3ee02015-03-25 14:41:14 -050056
57 # Create folder to store ping data
58 host.cmd("mkdir ping-data")
59
Ashlesh Gawande5f470202017-02-25 12:02:53 -060060 self.checkConvergence()
61
62 def checkConvergence(self, convergenceTime = None):
63 if convergenceTime is None:
64 convergenceTime = self.convergenceTime
65
ashu34c3ee02015-03-25 14:41:14 -050066 # Wait for convergence time period
Ashlesh Gawande5f470202017-02-25 12:02:53 -060067 print "Waiting " + str(convergenceTime) + " seconds for convergence..."
68 time.sleep(convergenceTime)
ashu34c3ee02015-03-25 14:41:14 -050069 print "...done"
70
71 # To check whether all the nodes of NLSR have converged
72 didNlsrConverge = True
73
74 # Checking for convergence
75 for host in self.net.hosts:
Ashlesh Gawandef932a182016-12-19 23:45:26 -060076 statusRouter = host.cmd("nfdc fib list | grep site/%C1.Router/cs/")
77 statusPrefix = host.cmd("nfdc fib list | grep ndn | grep site | grep -v Router")
ashu34c3ee02015-03-25 14:41:14 -050078 didNodeConverge = True
Ashlesh Gawandef6a610b2017-02-21 14:48:08 -060079 for node in self.net.hosts:
80 # Node has its own router name in the fib list, but not name prefix
81 if ( ("/ndn/" + node.name + "-site/%C1.Router/cs/" + node.name) not in statusRouter or
82 host.name != node.name and ("/ndn/" + node.name + "-site/" + node.name) not in statusPrefix ):
Ashlesh Gawandee144ceb2016-11-14 13:56:24 -060083 didNodeConverge = False
84 didNlsrConverge = False
ashu34c3ee02015-03-25 14:41:14 -050085
86 host.cmd("echo " + str(didNodeConverge) + " > convergence-result &")
87
88 if didNlsrConverge:
89 print("NLSR has successfully converged.")
90 else:
91 print("NLSR has not converged. Exiting...")
Ashlesh Gawande3807c1b2016-08-05 16:27:02 -050092 self.net.stop()
ashu34c3ee02015-03-25 14:41:14 -050093 sys.exit(1)
94
95 def startPings(self):
96 for host in self.net.hosts:
97 for other in self.net.hosts:
98 # Do not ping self
99 if host.name != other.name:
Alexander Lane9944cf52018-05-17 12:16:50 -0500100 NDNPingClient.ping(host, other, self.nPings)
ashu34c3ee02015-03-25 14:41:14 -0500101
Vince Lehmand96eed32015-10-22 13:57:27 -0500102 def failNode(self, host):
103 print("Bringing %s down" % host.name)
104 host.nfd.stop()
105
106 def recoverNode(self, host):
107 print("Bringing %s up" % host.name)
108 host.nfd.start()
Ashlesh Gawande708fcca2017-06-23 14:04:12 -0500109 host.nlsr.createFaces()
Vince Lehmand96eed32015-10-22 13:57:27 -0500110 host.nlsr.start()
Ashlesh Gawandee144ceb2016-11-14 13:56:24 -0600111 host.nfd.setStrategy("/ndn/", self.strategy)
112 host.cmd("ndnpingserver /ndn/" + str(host) + "-site/" + str(host) + " > ping-server &")
Vince Lehmand96eed32015-10-22 13:57:27 -0500113
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -0500114 def startPctPings(self):
115 nNodesToPing = int(round(len(self.net.hosts)*self.pctTraffic))
116 print "Each node will ping %d node(s)" % nNodesToPing
117 # Temporarily store all the nodes being pinged by a particular node
118 nodesPingedList = []
119
120 for host in self.net.hosts:
121 # Create a circular list
122 pool = cycle(self.net.hosts)
123
124 # Move iterator to current node
125 next(x for x in pool if host.name == x.name)
126
127 # Track number of nodes to ping scheduled for this node
128 nNodesScheduled = 0
129
130 while nNodesScheduled < nNodesToPing:
131 other = pool.next()
132
133 # Do not ping self
134 if host.name != other.name:
Alexander Lane9944cf52018-05-17 12:16:50 -0500135 NDNPingClient.ping(host, other, self.nPings)
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -0500136 nodesPingedList.append(other)
137
138 # Always increment because in 100% case a node should not ping itself
139 nNodesScheduled = nNodesScheduled + 1
140
141 self.pingedDict[host] = nodesPingedList
142 nodesPingedList = []
143
Vince Lehman3b8bc652015-06-18 15:01:47 -0500144 @staticmethod
145 def register(name, experimentClass):
Alexander Lane1bc9b472018-05-16 15:07:16 -0500146 ExperimentManager.register(name, experimentClass)