blob: 950dc05d38dda9d30e655561244b6b32083416ef [file] [log] [blame]
Vince Lehmanb8b18062015-07-14 13:07:22 -05001# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2#
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -05003# Copyright (C) 2015-2017, The University of Memphis,
Vince Lehman5d5a5662015-12-02 12:33:12 -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/>.
23#
24# This file incorporates work covered by the following copyright and
25# permission notice:
26#
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -050027# Mininet 2.3.0d1 License
Vince Lehmanb8b18062015-07-14 13:07:22 -050028#
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -050029# Copyright (c) 2013-2016 Open Networking Laboratory
Vince Lehmanb8b18062015-07-14 13:07:22 -050030# Copyright (c) 2009-2012 Bob Lantz and The Board of Trustees of
31# The Leland Stanford Junior University
32#
33# Original authors: Bob Lantz and Brandon Heller
34#
35# We are making Mininet available for public use and benefit with the
36# expectation that others will use, modify and enhance the Software and
37# contribute those enhancements back to the community. However, since we
38# would like to make the Software available for broadest use, with as few
39# restrictions as possible permission is hereby granted, free of charge, to
40# any person obtaining a copy of this Software to deal in the Software
41# under the copyrights without restriction, including without limitation
42# the rights to use, copy, modify, merge, publish, distribute, sublicense,
43# and/or sell copies of the Software, and to permit persons to whom the
44# Software is furnished to do so, subject to the following conditions:
45#
46# The above copyright notice and this permission notice shall be included
47# in all copies or substantial portions of the Software.
48#
49# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
50# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
51# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
52# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
53# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
54# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
55# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
56#
57# The name and trademarks of copyright holder(s) may NOT be used in
58# advertising or publicity pertaining to the Software or any derivatives
59# without specific, written prior permission.
ashuef3490b2015-02-17 11:01:04 -060060
61from mininet.topo import Topo
62from mininet.net import Mininet
63from mininet.log import setLogLevel, output, info
64from mininet.cli import CLI
65from mininet.link import TCLink
ashu2ad32e22015-05-29 13:37:40 -050066from mininet.util import ipStr, ipParse
ashuef3490b2015-02-17 11:01:04 -060067
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -050068from mininet.examples.cluster import MininetCluster, RoundRobinPlacer, ClusterCleanup
69from mininet.examples.clustercli import ClusterCLI
Vince Lehman3b8bc652015-06-18 15:01:47 -050070
71from ndn import ExperimentManager
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -050072from ndn.ndn_host import NdnHost, CpuLimitedNdnHost, RemoteNdnHost
Vince Lehmanfbd47c92015-10-14 16:00:06 -050073from ndn.conf_parser import parse_hosts, parse_switches, parse_links
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -050074from ndn.remote_ndn_link import RemoteNdnLink, RemoteGRENdnLink
75from ndn.placer import GuidedPlacer, PopulatePlacement
76from ndn.util import ssh, scp
ashuef3490b2015-02-17 11:01:04 -060077
78import os.path, time
Yucheng Zhang14aa5962016-04-05 17:10:15 -050079import shutil
Ashlesh Gawande044611d2016-12-21 14:24:49 -060080import argparse
ashuef3490b2015-02-17 11:01:04 -060081import datetime
ashu01b62f72015-03-12 15:16:11 -050082from os.path import expanduser
Vince Lehman3b8bc652015-06-18 15:01:47 -050083import sys
Ashlesh Gawande3807c1b2016-08-05 16:27:02 -050084import signal
Yucheng Zhang14aa5962016-04-05 17:10:15 -050085from subprocess import call
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -050086import glob
87from functools import partial
88import re
ashuef3490b2015-02-17 11:01:04 -060089
90from ndn.nlsr import Nlsr, NlsrConfigGenerator
ashu34c3ee02015-03-25 14:41:14 -050091from ndn.nfd import Nfd
ashuef3490b2015-02-17 11:01:04 -060092
Ashlesh Gawande0cccdb82016-08-15 12:58:06 -050093VERSION_NUMBER = "0.2.0"
Ashlesh Gawande044611d2016-12-21 14:24:49 -060094INSTALL_DIR='/usr/local/etc/mini-ndn/'
Vince Lehmane9f116d2015-07-15 10:40:21 -050095
Ashlesh Gawande044611d2016-12-21 14:24:49 -060096class PrintExperimentNames(argparse.Action):
97 def __init__(self, option_strings, dest, nargs=0, help=None):
98 super(PrintExperimentNames, self).__init__(option_strings=option_strings, dest=dest, nargs=nargs, help=help)
Vince Lehman3b8bc652015-06-18 15:01:47 -050099
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600100 def __call__(self, parser, namespace, values, option_string=None):
101 experimentNames = ExperimentManager.getExperimentNames()
Vince Lehman3b8bc652015-06-18 15:01:47 -0500102
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600103 print("Mini-NDN experiments:")
104 for experiment in experimentNames:
105 print(" %s" % experiment)
Vince Lehman194be242015-10-15 18:01:42 -0500106
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600107 sys.exit(0)
Vince Lehmane9f116d2015-07-15 10:40:21 -0500108
Vince Lehman194be242015-10-15 18:01:42 -0500109class ProgramOptions:
110 def __init__(self):
111 self.ctime = 60
112 self.experimentName = None
113 self.nFaces = 3
114 self.templateFile = "minindn.conf"
115 self.hr = False
116 self.isCliEnabled = True
Vince Lehman5d5a5662015-12-02 12:33:12 -0600117 self.nlsrSecurity = False
Vince Lehman194be242015-10-15 18:01:42 -0500118 self.nPings = 300
119 self.testbed = False
Ashlesh Gawande1b663692015-10-14 16:38:10 -0500120 self.workDir = "/tmp"
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500121 self.resultDir = None
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -0500122 self.pctTraffic = 1.0
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500123 self.cluster = None
124 self.servers = None
125 self.guided = None
126 self.placer = None
127 self.tunnelType = None
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500128
129def createResultsDir(resultDir, faces, hr):
130 if faces == 0:
131 faces = "all"
132
133 if hr:
134 routingType = "/hr/"
135 else:
136 routingType = "/ls/"
137
138 resultDir = "%s/%s/faces-%s" % (str(resultDir), routingType, str(faces))
139 resultDir = os.path.abspath(resultDir)
140
141 if not os.path.isdir(resultDir):
142 os.makedirs(resultDir)
143 else:
144 print("Results directory (%s) already exists!" % resultDir)
145 sys.exit(1);
146
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600147 print("Results will be stored at: %s" % resultDir)
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500148 return resultDir
Vince Lehman194be242015-10-15 18:01:42 -0500149
ashuef3490b2015-02-17 11:01:04 -0600150def parse_args():
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600151 parser = argparse.ArgumentParser(prog='minindn')
ashuef3490b2015-02-17 11:01:04 -0600152
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600153 # nargs='?' required here since optional argument
154 parser.add_argument('tempfile', nargs='?', default=INSTALL_DIR + 'default-topology.conf',
155 help="If no template_file is given, ndn_utils/default-topology.conf (given sample file) will be used.")
ashuef3490b2015-02-17 11:01:04 -0600156
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600157 parser.add_argument("--ctime", type=int, default=60,
158 help="Specify convergence time for the topology (Default: 60 seconds)")
ashuef3490b2015-02-17 11:01:04 -0600159
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600160 parser.add_argument("--experiment",
161 help="Runs the specified experiment")
Vince Lehman3b8bc652015-06-18 15:01:47 -0500162
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600163 parser.add_argument("--faces", type=int, default=3,
164 help="Specify number of faces 0-60")
ashuef3490b2015-02-17 11:01:04 -0600165
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600166 # store_true stores default value of False
167 parser.add_argument("--hr", action="store_true",
168 help="--hr is used to turn on hyperbolic routing")
Vince Lehman194be242015-10-15 18:01:42 -0500169
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600170 parser.add_argument("--list-experiments", action=PrintExperimentNames,
171 help="Lists the names of all available experiments")
Vince Lehman194be242015-10-15 18:01:42 -0500172
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600173 parser.add_argument("--no-cli", action="store_false", dest="isCliEnabled",
174 help="Run experiments and exit without showing the command line interface")
Vince Lehman194be242015-10-15 18:01:42 -0500175
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600176 parser.add_argument("--nPings", type=int, default=300,
177 help="Number of pings to perform between each node in the experiment")
Vince Lehman194be242015-10-15 18:01:42 -0500178
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600179 parser.add_argument("--nlsr-security", action="store_true", dest="nlsrSecurity",
180 help="Enables NLSR security")
Vince Lehman5d5a5662015-12-02 12:33:12 -0600181
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600182 parser.add_argument("-t", "--testbed", action="store_true", dest="testbed",
183 help="Instantiates a snapshot of the NDN Testbed irrespective of the tempfile provided")
ashuef3490b2015-02-17 11:01:04 -0600184
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600185 parser.add_argument("--work-dir", action="store", dest="workDir", default="/tmp",
186 help="Specify the working directory; default is /tmp")
Ashlesh Gawande1b663692015-10-14 16:38:10 -0500187
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600188 parser.add_argument("--result-dir", action="store", dest="resultDir", default=None,
189 help="Specify the full path destination folder where experiment results will be moved")
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500190
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600191 parser.add_argument("--pct-traffic", dest="pctTraffic", type=float, default=1.0,
192 help="Specify the percentage of nodes each node should ping")
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -0500193
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600194 parser.add_argument('--version', '-V', action='version', version='%(prog)s ' + VERSION_NUMBER,
195 help='Displays version information')
Vince Lehmane9f116d2015-07-15 10:40:21 -0500196
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500197 parser.add_argument("--cluster", metavar='localhost,server2,...',
198 help="Run cluster edition")
199
200 parser.add_argument("--placement", default='guided',
201 choices=['roundRobin', 'guided'])
202
203 parser.add_argument("--place-list", dest="placeList",
204 help="""Provide corresponding number of nodes (comma separated) to put on
205 each node respectively of --cluster when guided placement is used""")
206
207 parser.add_argument("--tunnel-type", dest="tunnelType", default='ssh',
208 choices=['ssh', 'gre'])
209
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600210 args = parser.parse_args()
ashuef3490b2015-02-17 11:01:04 -0600211
Vince Lehman194be242015-10-15 18:01:42 -0500212 options = ProgramOptions()
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600213 options.templateFile = args.tempfile
Vince Lehman194be242015-10-15 18:01:42 -0500214 options.ctime = args.ctime
215 options.experimentName = args.experiment
216 options.nFaces = args.faces
217 options.hr = args.hr
218 options.isCliEnabled = args.isCliEnabled
Vince Lehman5d5a5662015-12-02 12:33:12 -0600219 options.nlsrSecurity = args.nlsrSecurity
Vince Lehman194be242015-10-15 18:01:42 -0500220 options.nPings = args.nPings
Vince Lehman5d5a5662015-12-02 12:33:12 -0600221
Vince Lehman194be242015-10-15 18:01:42 -0500222 options.testbed = args.testbed
Ashlesh Gawande1b663692015-10-14 16:38:10 -0500223 options.workDir = args.workDir
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500224 options.resultDir = args.resultDir
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -0500225 options.pctTraffic = args.pctTraffic
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500226 options.cluster = args.cluster
227 options.placement = args.placement
228 options.tunnelType = args.tunnelType
229 options.placeList = args.placeList
ashuef3490b2015-02-17 11:01:04 -0600230
Vince Lehman194be242015-10-15 18:01:42 -0500231 if options.experimentName is not None and options.experimentName not in ExperimentManager.getExperimentNames():
232 print("No experiment named %s" % options.experimentName)
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600233 sys.exit(1)
Vince Lehman3b8bc652015-06-18 15:01:47 -0500234
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500235 if options.experimentName is not None and options.resultDir is None:
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600236 print("No results folder specified; experiment results will remain in the working directory")
ashuef3490b2015-02-17 11:01:04 -0600237
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500238 if options.cluster is not None:
239 servers = options.cluster.split(',')
240 for server in servers:
241 ClusterCleanup.add(server)
242 options.servers = servers
243
244 if options.placement == "roundRobin":
245 options.placement = RoundRobinPlacer
246 elif options.placement == "guided":
247 if options.placeList is None or not re.match("^[0-9,]+$", options.placeList):
248 print("Please specify correctly how many nodes you want to place on each node!")
249 sys.exit(1)
250 else:
251 try:
252 options.placeList = map(int, options.placeList.split(","))
253 except ValueError:
254 print("Please specify the nodes correctly, no comma at the beginning/end!")
255 sys.exit(1)
256
257 PopulatePlacement(options.placeList)
258 options.placement = GuidedPlacer
259
260 if options.tunnelType == "ssh":
261 options.tunnelType = RemoteNdnLink
262 else:
263 options.tunnelType = RemoteGRENdnLink
264
Vince Lehman194be242015-10-15 18:01:42 -0500265 return options
ashuef3490b2015-02-17 11:01:04 -0600266
267class NdnTopo(Topo):
Ashlesh Gawande1b663692015-10-14 16:38:10 -0500268 def __init__(self, conf_arq, workDir, **opts):
ashuef3490b2015-02-17 11:01:04 -0600269 Topo.__init__(self, **opts)
270
271 global hosts_conf
272 global links_conf
273 hosts_conf = parse_hosts(conf_arq)
Vince Lehmanfbd47c92015-10-14 16:00:06 -0500274 switches_conf = parse_switches(conf_arq)
ashuef3490b2015-02-17 11:01:04 -0600275 links_conf = parse_links(conf_arq)
276
277 self.isTCLink = False
278 self.isLimited = False
279
280 for host in hosts_conf:
281 if host.cpu != None and self.isLimited != True:
282 self.isLimited = True
Ashlesh Gawande1b663692015-10-14 16:38:10 -0500283 self.addHost(host.name, app=host.app, params=host.uri_tuples, cpu=host.cpu,cores=host.cores,cache=host.cache, workdir=workDir)
ashuef3490b2015-02-17 11:01:04 -0600284
Vince Lehmanfbd47c92015-10-14 16:00:06 -0500285 for switch in switches_conf:
286 self.addSwitch(switch.name)
287
ashuef3490b2015-02-17 11:01:04 -0600288 for link in links_conf:
289 if len(link.linkDict) == 0:
290 self.addLink(link.h1, link.h2)
291 else:
292 self.addLink(link.h1, link.h2, **link.linkDict)
293 self.isTCLink = True
294
295 info('Parse of ' + conf_arq + ' done.\n')
296
Vince Lehman194be242015-10-15 18:01:42 -0500297def execute(options):
ashuef3490b2015-02-17 11:01:04 -0600298 "Create a network based on template_file"
299
Vince Lehman194be242015-10-15 18:01:42 -0500300 if options.testbed:
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600301 options.templateFile = INSTALL_DIR + 'minindn.testbed.conf'
ashuef3490b2015-02-17 11:01:04 -0600302
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600303 if os.path.exists(options.templateFile) == False:
304 info('Template file cannot be found. Exiting...\n')
305 sys.exit(1)
Ashlesh Gawande20f70762015-06-17 15:18:19 -0500306
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500307 if options.cluster is not None and options.placement == GuidedPlacer:
308 num_nodes = 0
309 with open(options.templateFile, 'r') as topo:
310 for line in topo:
311 if ': _' in line:
312 num_nodes += 1
313
314 if sum(options.placeList) != num_nodes:
315 print("Placement list sum is not equal to number of nodes!")
316 sys.exit(1)
317
Yucheng Zhang14aa5962016-04-05 17:10:15 -0500318 # Use nfd.conf as default configuration for NFD, else use the sample
319
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600320 nfdConfFile = "%s/nfd.conf" % INSTALL_DIR
Yucheng Zhang14aa5962016-04-05 17:10:15 -0500321 if os.path.isfile("/usr/local/etc/ndn/nfd.conf") == True:
322 shutil.copy2("/usr/local/etc/ndn/nfd.conf", nfdConfFile)
323 elif os.path.isfile("/usr/local/etc/ndn/nfd.conf.sample") == True:
324 shutil.copy2("/usr/local/etc/ndn/nfd.conf.sample", nfdConfFile)
325 else:
326 sys.exit("nfd.conf or nfd.conf.sample cannot be found in the expected directory. Exit.")
327
328 call(["sudo", "sed", "-i", 's|default_level [A-Z]*$|default_level $LOG_LEVEL|g', nfdConfFile])
Vince Lehman498625b2015-10-21 14:25:24 -0500329
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500330 # Copy nfd.conf to remote hosts - this assumes that NDN versions across
331 # the cluster are at least compatible if not the same
332 if options.cluster is not None:
333 for server in options.servers:
334 if server != "localhost":
335 login = "mininet@%s" % server
336 src = nfdConfFile
337 dst = "%s:/tmp/nfd.conf" % (login)
338 scp(src, dst)
339 ssh(login, "sudo cp /tmp/nfd.conf %s" % src)
340
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500341 if options.resultDir is not None:
342 options.resultDir = createResultsDir(options.resultDir, options.nFaces, options.hr)
343
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600344 topo = NdnTopo(options.templateFile, options.workDir)
ashuef3490b2015-02-17 11:01:04 -0600345
346 t = datetime.datetime.now()
347
348 if topo.isTCLink == True and topo.isLimited == True:
349 net = Mininet(topo,host=CpuLimitedNdnHost,link=TCLink)
350 elif topo.isTCLink == True and topo.isLimited == False:
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500351 if options.cluster is not None:
352 mn = partial(MininetCluster, servers=options.servers, placement=options.placement)
353 net = mn(topo=topo, host=RemoteNdnHost, link=options.tunnelType)
354 else:
355 net = Mininet(topo, host=NdnHost, link=TCLink)
ashuef3490b2015-02-17 11:01:04 -0600356 elif topo.isTCLink == False and topo.isLimited == True:
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500357 net = Mininet(topo, host=CpuLimitedNdnHost)
ashuef3490b2015-02-17 11:01:04 -0600358 else:
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500359 net = Mininet(topo, host=NdnHost)
ashuef3490b2015-02-17 11:01:04 -0600360
361 t2 = datetime.datetime.now()
362
363 delta = t2 - t
364
365 info('Setup time: ' + str(delta.seconds) + '\n')
366
367 net.start()
368
ashu2ad32e22015-05-29 13:37:40 -0500369 # Giving proper IPs to intf so neighbor nodes can communicate
370 # This is one way of giving connectivity, another way could be
371 # to insert a switch between each pair of neighbors
372 ndnNetBase = "1.0.0.0"
373 interfaces = []
374 for host in net.hosts:
375 for intf in host.intfList():
376 link = intf.link
377 node1, node2 = link.intf1.node, link.intf2.node
Vince Lehmanfbd47c92015-10-14 16:00:06 -0500378
379 if node1 in net.switches or node2 in net.switches:
Vince Lehmanfbd47c92015-10-14 16:00:06 -0500380 continue
381
ashu2ad32e22015-05-29 13:37:40 -0500382 if link.intf1 not in interfaces and link.intf2 not in interfaces:
383 interfaces.append(link.intf1)
384 interfaces.append(link.intf2)
385 node1.setIP(ipStr(ipParse(ndnNetBase) + 1) + '/30', intf=link.intf1)
386 node2.setIP(ipStr(ipParse(ndnNetBase) + 2) + '/30', intf=link.intf2)
387 ndnNetBase = ipStr(ipParse(ndnNetBase) + 4)
388
ashuef3490b2015-02-17 11:01:04 -0600389 nodes = "" # Used later to check prefix name in checkFIB
390
Vince Lehman5d5a5662015-12-02 12:33:12 -0600391 # NLSR Security
392 if options.nlsrSecurity is True:
393 Nlsr.createKeysAndCertificates(net, options.workDir)
394
ashuef3490b2015-02-17 11:01:04 -0600395 # NLSR initialization
396 for host in net.hosts:
397 nodes += str(host.name) + ","
398
399 conf = next(x for x in hosts_conf if x.name == host.name)
400 host.nlsrParameters = conf.nlsrParameters
401
Vince Lehman194be242015-10-15 18:01:42 -0500402 if options.nFaces is not None:
403 host.nlsrParameters["max-faces-per-prefix"] = options.nFaces
ashuef3490b2015-02-17 11:01:04 -0600404
Vince Lehman194be242015-10-15 18:01:42 -0500405 if options.hr is True:
ashuef3490b2015-02-17 11:01:04 -0600406 host.nlsrParameters["hyperbolic-state"] = "on"
407
408 # Generate NLSR configuration file
Vince Lehman5d5a5662015-12-02 12:33:12 -0600409 configGenerator = NlsrConfigGenerator(host, options.nlsrSecurity)
ashuef3490b2015-02-17 11:01:04 -0600410 configGenerator.createConfigFile()
411
412 # Start NLSR
ashu34c3ee02015-03-25 14:41:14 -0500413 host.nlsr = Nlsr(host)
414 host.nlsr.start()
ashuef3490b2015-02-17 11:01:04 -0600415
416 nodes = nodes[0:-1]
417
ashuef3490b2015-02-17 11:01:04 -0600418 for host in net.hosts:
419 if 'app' in host.params:
Ashlesh Gawande557cb842015-07-01 15:39:44 -0500420 if host.params['app'] != '':
421 app = host.params['app']
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600422 print("Starting " + app + " on node " + host.name)
Ashlesh Gawande557cb842015-07-01 15:39:44 -0500423 print(host.cmd(app))
ashuef3490b2015-02-17 11:01:04 -0600424
Vince Lehman3b8bc652015-06-18 15:01:47 -0500425 # Load experiment
Vince Lehman194be242015-10-15 18:01:42 -0500426 experimentName = options.experimentName
427
Vince Lehman3b8bc652015-06-18 15:01:47 -0500428 if experimentName is not None:
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600429 print("Loading experiment: %s" % experimentName)
Vince Lehman3b8bc652015-06-18 15:01:47 -0500430
431 experimentArgs = {
432 "net": net,
433 "nodes": nodes,
Vince Lehman194be242015-10-15 18:01:42 -0500434 "ctime": options.ctime,
435 "nPings": options.nPings,
Ashlesh Gawandeb07ada82016-08-05 14:29:17 -0500436 "strategy": Nfd.STRATEGY_BEST_ROUTE,
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -0500437 "pctTraffic": options.pctTraffic
Vince Lehman3b8bc652015-06-18 15:01:47 -0500438 }
439
440 experiment = ExperimentManager.create(experimentName, experimentArgs)
441
442 if experiment is not None:
443 experiment.start()
444 else:
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600445 print("ERROR: Experiment '%s' does not exist" % experimentName)
Vince Lehman3b8bc652015-06-18 15:01:47 -0500446 return
447
Vince Lehman194be242015-10-15 18:01:42 -0500448 if options.isCliEnabled is True:
ashuef3490b2015-02-17 11:01:04 -0600449 CLI(net)
450
451 net.stop()
452
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500453 if options.resultDir is not None:
454 print("Moving results to %s" % options.resultDir)
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500455 for file in glob.glob('%s/*' % options.workDir):
456 shutil.move(file, options.resultDir)
457 if options.cluster is not None:
458 for server in options.servers:
459 if server != "localhost":
460 login = "mininet@%s" % server
461 src = "%s:%s/*" % (login, options.workDir)
462 dst = options.resultDir
463 scp(src, dst)
464 print("Please clean work directories of other machines before running the cluster again")
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500465
Ashlesh Gawande3807c1b2016-08-05 16:27:02 -0500466def signal_handler(signal, frame):
467 print('Cleaning up...')
468 call(["nfd-stop"])
469 call(["sudo", "mn", "--clean"])
470 sys.exit(1)
471
ashuef3490b2015-02-17 11:01:04 -0600472if __name__ == '__main__':
Vince Lehman3b8bc652015-06-18 15:01:47 -0500473
ashuef3490b2015-02-17 11:01:04 -0600474 hosts_conf = []
475 links_conf = []
Vince Lehman194be242015-10-15 18:01:42 -0500476
Ashlesh Gawande3807c1b2016-08-05 16:27:02 -0500477 signal.signal(signal.SIGINT, signal_handler)
478
Vince Lehman194be242015-10-15 18:01:42 -0500479 options = parse_args()
ashuef3490b2015-02-17 11:01:04 -0600480
481 setLogLevel('info')
Vince Lehman194be242015-10-15 18:01:42 -0500482 execute(options)