blob: 2061c73b176ba456db6fd0886e03f113e2fcebe4 [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
ashuef3490b2015-02-17 11:01:04 -060064from mininet.link import TCLink
ashu2ad32e22015-05-29 13:37:40 -050065from mininet.util import ipStr, ipParse
ashuef3490b2015-02-17 11:01:04 -060066
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -050067from mininet.examples.cluster import MininetCluster, RoundRobinPlacer, ClusterCleanup
68from mininet.examples.clustercli import ClusterCLI
Vince Lehman3b8bc652015-06-18 15:01:47 -050069
70from ndn import ExperimentManager
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -050071from ndn.ndn_host import NdnHost, CpuLimitedNdnHost, RemoteNdnHost
Vince Lehmanfbd47c92015-10-14 16:00:06 -050072from ndn.conf_parser import parse_hosts, parse_switches, parse_links
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -050073from ndn.remote_ndn_link import RemoteNdnLink, RemoteGRENdnLink
74from ndn.placer import GuidedPlacer, PopulatePlacement
Ashlesh Gawande95789cc2017-02-27 12:38:04 -060075from ndn.util import ssh, scp, MiniNDNCLI
ashuef3490b2015-02-17 11:01:04 -060076
77import os.path, time
Yucheng Zhang14aa5962016-04-05 17:10:15 -050078import shutil
Ashlesh Gawande044611d2016-12-21 14:24:49 -060079import argparse
ashuef3490b2015-02-17 11:01:04 -060080import datetime
ashu01b62f72015-03-12 15:16:11 -050081from os.path import expanduser
Vince Lehman3b8bc652015-06-18 15:01:47 -050082import sys
Ashlesh Gawande3807c1b2016-08-05 16:27:02 -050083import signal
Yucheng Zhang14aa5962016-04-05 17:10:15 -050084from subprocess import call
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -050085import glob
86from functools import partial
87import re
ashuef3490b2015-02-17 11:01:04 -060088
89from ndn.nlsr import Nlsr, NlsrConfigGenerator
ashu34c3ee02015-03-25 14:41:14 -050090from ndn.nfd import Nfd
ashuef3490b2015-02-17 11:01:04 -060091
Ashlesh Gawande212cb822017-02-07 10:42:13 -060092try:
93 import argcomplete
94except ImportError:
95 pass
96
Ashlesh Gawandeda475f02017-03-01 17:20:58 -060097VERSION_NUMBER = "0.3.0"
Ashlesh Gawande044611d2016-12-21 14:24:49 -060098INSTALL_DIR='/usr/local/etc/mini-ndn/'
Vince Lehmane9f116d2015-07-15 10:40:21 -050099
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600100class PrintExperimentNames(argparse.Action):
101 def __init__(self, option_strings, dest, nargs=0, help=None):
102 super(PrintExperimentNames, self).__init__(option_strings=option_strings, dest=dest, nargs=nargs, help=help)
Vince Lehman3b8bc652015-06-18 15:01:47 -0500103
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600104 def __call__(self, parser, namespace, values, option_string=None):
105 experimentNames = ExperimentManager.getExperimentNames()
Ashlesh Gawande501d4d62017-10-25 13:12:11 -0500106 experimentArgs = ExperimentManager.getExperimentArgs()
Vince Lehman3b8bc652015-06-18 15:01:47 -0500107
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600108 print("Mini-NDN experiments:")
109 for experiment in experimentNames:
Ashlesh Gawande501d4d62017-10-25 13:12:11 -0500110 print(" {}".format(experiment))
111 if experiment in experimentArgs:
112 print(" ({})".format(experimentArgs[experiment]))
Vince Lehman194be242015-10-15 18:01:42 -0500113
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600114 sys.exit(0)
Vince Lehmane9f116d2015-07-15 10:40:21 -0500115
Vince Lehman194be242015-10-15 18:01:42 -0500116class ProgramOptions:
117 def __init__(self):
118 self.ctime = 60
119 self.experimentName = None
120 self.nFaces = 3
121 self.templateFile = "minindn.conf"
dmcoomes7adc7f72017-10-06 12:01:28 -0500122 self.routingType = "link-state"
dmcoomesecf9c5a2017-10-11 10:17:46 -0500123 self.isNlsrEnabled = True
Vince Lehman194be242015-10-15 18:01:42 -0500124 self.isCliEnabled = True
Vince Lehman5d5a5662015-12-02 12:33:12 -0600125 self.nlsrSecurity = False
Vince Lehman194be242015-10-15 18:01:42 -0500126 self.nPings = 300
127 self.testbed = False
dmcoomes80eeea12017-10-27 12:49:10 -0500128 self.workDir = "/tmp/minindn"
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500129 self.resultDir = None
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -0500130 self.pctTraffic = 1.0
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500131 self.cluster = None
132 self.servers = None
133 self.guided = None
134 self.placer = None
135 self.tunnelType = None
Ashlesh Gawande708fcca2017-06-23 14:04:12 -0500136 self.faceType = "udp"
Ashlesh Gawande501d4d62017-10-25 13:12:11 -0500137 self.arbArgs = {}
Ashlesh Gawande532302b2018-02-15 18:58:20 -0600138 self.csSize = 65536
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500139
dmcoomes7adc7f72017-10-06 12:01:28 -0500140def createResultsDir(resultDir, faces, rType):
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500141 if faces == 0:
142 faces = "all"
143
dmcoomes7adc7f72017-10-06 12:01:28 -0500144 routingChoice = "/{}/".format(rType)
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500145
dmcoomes7adc7f72017-10-06 12:01:28 -0500146 resultDir = "{}/{}/faces-{}".format(resultDir, routingChoice, faces)
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500147 resultDir = os.path.abspath(resultDir)
148
149 if not os.path.isdir(resultDir):
150 os.makedirs(resultDir)
151 else:
152 print("Results directory (%s) already exists!" % resultDir)
Ashlesh Gawande212cb822017-02-07 10:42:13 -0600153 sys.exit(1)
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500154
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600155 print("Results will be stored at: %s" % resultDir)
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500156 return resultDir
Vince Lehman194be242015-10-15 18:01:42 -0500157
ashuef3490b2015-02-17 11:01:04 -0600158def parse_args():
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600159 parser = argparse.ArgumentParser(prog='minindn')
ashuef3490b2015-02-17 11:01:04 -0600160
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600161 # nargs='?' required here since optional argument
162 parser.add_argument('tempfile', nargs='?', default=INSTALL_DIR + 'default-topology.conf',
Ashlesh Gawande532302b2018-02-15 18:58:20 -0600163 help="If no template_file is given, topologies/default-topology.conf (given sample file) will be used.")
ashuef3490b2015-02-17 11:01:04 -0600164
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600165 parser.add_argument("--ctime", type=int, default=60,
166 help="Specify convergence time for the topology (Default: 60 seconds)")
ashuef3490b2015-02-17 11:01:04 -0600167
Ashlesh Gawande212cb822017-02-07 10:42:13 -0600168 parser.add_argument("--experiment", choices=[experiment for experiment in ExperimentManager.getExperimentNames()],
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600169 help="Runs the specified experiment")
Vince Lehman3b8bc652015-06-18 15:01:47 -0500170
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600171 parser.add_argument("--faces", type=int, default=3,
Ashlesh Gawande212cb822017-02-07 10:42:13 -0600172 help="Specify number of max faces per prefix for NLSR 0-60")
ashuef3490b2015-02-17 11:01:04 -0600173
dmcoomes7adc7f72017-10-06 12:01:28 -0500174 parser.add_argument("--routing", dest="routingType", default='link-state', choices=['link-state', 'hr', 'dry'],
175 help="""choices for routing are 'link-state' for link state, 'hr' for hyperbolic, and 'dry'
176 to test hyperbolic routing and compare with link state. Default is link-state.""")
Vince Lehman194be242015-10-15 18:01:42 -0500177
dmcoomesecf9c5a2017-10-11 10:17:46 -0500178 parser.add_argument("--no-nlsr", action="store_false", dest="isNlsrEnabled",
179 help="Run mini-ndn without NLSR routing")
180
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600181 parser.add_argument("--list-experiments", action=PrintExperimentNames,
182 help="Lists the names of all available experiments")
Vince Lehman194be242015-10-15 18:01:42 -0500183
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600184 parser.add_argument("--no-cli", action="store_false", dest="isCliEnabled",
185 help="Run experiments and exit without showing the command line interface")
Vince Lehman194be242015-10-15 18:01:42 -0500186
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600187 parser.add_argument("--nPings", type=int, default=300,
188 help="Number of pings to perform between each node in the experiment")
Vince Lehman194be242015-10-15 18:01:42 -0500189
dmcoomes7adc7f72017-10-06 12:01:28 -0500190 # store_true stores default value of False
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600191 parser.add_argument("--nlsr-security", action="store_true", dest="nlsrSecurity",
192 help="Enables NLSR security")
Vince Lehman5d5a5662015-12-02 12:33:12 -0600193
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600194 parser.add_argument("-t", "--testbed", action="store_true", dest="testbed",
195 help="Instantiates a snapshot of the NDN Testbed irrespective of the tempfile provided")
ashuef3490b2015-02-17 11:01:04 -0600196
dmcoomes80eeea12017-10-27 12:49:10 -0500197 parser.add_argument("--work-dir", action="store", dest="workDir", default="/tmp/minindn",
198 help="Specify the working directory; default is /tmp/minindn")
Ashlesh Gawande1b663692015-10-14 16:38:10 -0500199
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600200 parser.add_argument("--result-dir", action="store", dest="resultDir", default=None,
201 help="Specify the full path destination folder where experiment results will be moved")
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500202
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600203 parser.add_argument("--pct-traffic", dest="pctTraffic", type=float, default=1.0,
204 help="Specify the percentage of nodes each node should ping")
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -0500205
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600206 parser.add_argument('--version', '-V', action='version', version='%(prog)s ' + VERSION_NUMBER,
207 help='Displays version information')
Vince Lehmane9f116d2015-07-15 10:40:21 -0500208
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500209 parser.add_argument("--cluster", metavar='localhost,server2,...',
210 help="Run cluster edition")
211
212 parser.add_argument("--placement", default='guided',
213 choices=['roundRobin', 'guided'])
214
215 parser.add_argument("--place-list", dest="placeList",
216 help="""Provide corresponding number of nodes (comma separated) to put on
217 each node respectively of --cluster when guided placement is used""")
218
219 parser.add_argument("--tunnel-type", dest="tunnelType", default='ssh',
220 choices=['ssh', 'gre'])
221
Ashlesh Gawande708fcca2017-06-23 14:04:12 -0500222 parser.add_argument("--face-type", dest='faceType', default='udp', choices=['udp', 'tcp'])
223
Ashlesh Gawande532302b2018-02-15 18:58:20 -0600224 parser.add_argument("--cs-size", dest='csSize', type=int, default=65536,
225 help="Set CS size in NFD's conf file")
226
Ashlesh Gawande212cb822017-02-07 10:42:13 -0600227 if "argcomplete" in sys.modules:
228 argcomplete.autocomplete(parser)
229
Ashlesh Gawande501d4d62017-10-25 13:12:11 -0500230 args, unknownArgs = parser.parse_known_args()
231
232 unknownArgsList = []
233 for arg in unknownArgs:
234 if arg.startswith(("--")):
235 parser.add_argument(arg)
236 unknownArgsList.append(arg.split("--")[1])
237
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600238 args = parser.parse_args()
ashuef3490b2015-02-17 11:01:04 -0600239
Vince Lehman194be242015-10-15 18:01:42 -0500240 options = ProgramOptions()
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600241 options.templateFile = args.tempfile
Vince Lehman194be242015-10-15 18:01:42 -0500242 options.ctime = args.ctime
243 options.experimentName = args.experiment
244 options.nFaces = args.faces
dmcoomes7adc7f72017-10-06 12:01:28 -0500245 options.routingType = args.routingType
dmcoomesecf9c5a2017-10-11 10:17:46 -0500246 options.isNlsrEnabled = args.isNlsrEnabled
Vince Lehman194be242015-10-15 18:01:42 -0500247 options.isCliEnabled = args.isCliEnabled
Vince Lehman5d5a5662015-12-02 12:33:12 -0600248 options.nlsrSecurity = args.nlsrSecurity
Vince Lehman194be242015-10-15 18:01:42 -0500249 options.nPings = args.nPings
Vince Lehman5d5a5662015-12-02 12:33:12 -0600250
Vince Lehman194be242015-10-15 18:01:42 -0500251 options.testbed = args.testbed
Ashlesh Gawande1b663692015-10-14 16:38:10 -0500252 options.workDir = args.workDir
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500253 options.resultDir = args.resultDir
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -0500254 options.pctTraffic = args.pctTraffic
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500255 options.cluster = args.cluster
256 options.placement = args.placement
257 options.tunnelType = args.tunnelType
258 options.placeList = args.placeList
Ashlesh Gawande708fcca2017-06-23 14:04:12 -0500259 options.faceType = args.faceType
Ashlesh Gawande532302b2018-02-15 18:58:20 -0600260 options.csSize = args.csSize
ashuef3490b2015-02-17 11:01:04 -0600261
Ashlesh Gawande501d4d62017-10-25 13:12:11 -0500262 for k in args.__dict__:
263 if k in unknownArgsList:
264 options.arbArgs[k] = args.__dict__[k]
265
Vince Lehman194be242015-10-15 18:01:42 -0500266 if options.experimentName is not None and options.experimentName not in ExperimentManager.getExperimentNames():
267 print("No experiment named %s" % options.experimentName)
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600268 sys.exit(1)
Vince Lehman3b8bc652015-06-18 15:01:47 -0500269
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500270 if options.experimentName is not None and options.resultDir is None:
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600271 print("No results folder specified; experiment results will remain in the working directory")
ashuef3490b2015-02-17 11:01:04 -0600272
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500273 if options.cluster is not None:
274 servers = options.cluster.split(',')
275 for server in servers:
276 ClusterCleanup.add(server)
277 options.servers = servers
278
279 if options.placement == "roundRobin":
280 options.placement = RoundRobinPlacer
281 elif options.placement == "guided":
282 if options.placeList is None or not re.match("^[0-9,]+$", options.placeList):
283 print("Please specify correctly how many nodes you want to place on each node!")
284 sys.exit(1)
285 else:
286 try:
287 options.placeList = map(int, options.placeList.split(","))
288 except ValueError:
289 print("Please specify the nodes correctly, no comma at the beginning/end!")
290 sys.exit(1)
291
292 PopulatePlacement(options.placeList)
293 options.placement = GuidedPlacer
294
295 if options.tunnelType == "ssh":
296 options.tunnelType = RemoteNdnLink
297 else:
298 options.tunnelType = RemoteGRENdnLink
299
Vince Lehman194be242015-10-15 18:01:42 -0500300 return options
ashuef3490b2015-02-17 11:01:04 -0600301
302class NdnTopo(Topo):
Ashlesh Gawande1b663692015-10-14 16:38:10 -0500303 def __init__(self, conf_arq, workDir, **opts):
ashuef3490b2015-02-17 11:01:04 -0600304 Topo.__init__(self, **opts)
305
306 global hosts_conf
307 global links_conf
308 hosts_conf = parse_hosts(conf_arq)
Vince Lehmanfbd47c92015-10-14 16:00:06 -0500309 switches_conf = parse_switches(conf_arq)
ashuef3490b2015-02-17 11:01:04 -0600310 links_conf = parse_links(conf_arq)
311
312 self.isTCLink = False
313 self.isLimited = False
314
315 for host in hosts_conf:
316 if host.cpu != None and self.isLimited != True:
317 self.isLimited = True
dmcoomes74da84c2017-11-07 16:09:23 -0600318 self.addHost(host.name, app=host.app, params=host.uri_tuples, cpu=host.cpu,
319 cores=host.cores,cache=host.cache, workdir=workDir)
320 if (options.routingType != 'link-state' and (host.params.get('radius') is None
321 or host.params.get('angle') is None)):
322 info('Hyperbolic coordinates in topology file are either missing or misconfigured.\n' \
323 'Check that each node has one radius value and one or two angle value(s).\n')
324 sys.exit(1)
ashuef3490b2015-02-17 11:01:04 -0600325
Vince Lehmanfbd47c92015-10-14 16:00:06 -0500326 for switch in switches_conf:
327 self.addSwitch(switch.name)
328
ashuef3490b2015-02-17 11:01:04 -0600329 for link in links_conf:
330 if len(link.linkDict) == 0:
331 self.addLink(link.h1, link.h2)
332 else:
333 self.addLink(link.h1, link.h2, **link.linkDict)
334 self.isTCLink = True
335
336 info('Parse of ' + conf_arq + ' done.\n')
337
Vince Lehman194be242015-10-15 18:01:42 -0500338def execute(options):
ashuef3490b2015-02-17 11:01:04 -0600339 "Create a network based on template_file"
340
Vince Lehman194be242015-10-15 18:01:42 -0500341 if options.testbed:
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600342 options.templateFile = INSTALL_DIR + 'minindn.testbed.conf'
ashuef3490b2015-02-17 11:01:04 -0600343
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600344 if os.path.exists(options.templateFile) == False:
345 info('Template file cannot be found. Exiting...\n')
346 sys.exit(1)
Ashlesh Gawande20f70762015-06-17 15:18:19 -0500347
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500348 if options.cluster is not None and options.placement == GuidedPlacer:
349 num_nodes = 0
350 with open(options.templateFile, 'r') as topo:
351 for line in topo:
352 if ': _' in line:
353 num_nodes += 1
354
355 if sum(options.placeList) != num_nodes:
356 print("Placement list sum is not equal to number of nodes!")
357 sys.exit(1)
358
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500359 # Copy nfd.conf to remote hosts - this assumes that NDN versions across
360 # the cluster are at least compatible if not the same
361 if options.cluster is not None:
362 for server in options.servers:
363 if server != "localhost":
364 login = "mininet@%s" % server
365 src = nfdConfFile
366 dst = "%s:/tmp/nfd.conf" % (login)
367 scp(src, dst)
368 ssh(login, "sudo cp /tmp/nfd.conf %s" % src)
369
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500370 if options.resultDir is not None:
dmcoomes7adc7f72017-10-06 12:01:28 -0500371 options.resultDir = createResultsDir(options.resultDir, options.nFaces, options.routingType)
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500372
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600373 topo = NdnTopo(options.templateFile, options.workDir)
ashuef3490b2015-02-17 11:01:04 -0600374
375 t = datetime.datetime.now()
376
377 if topo.isTCLink == True and topo.isLimited == True:
378 net = Mininet(topo,host=CpuLimitedNdnHost,link=TCLink)
379 elif topo.isTCLink == True and topo.isLimited == False:
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500380 if options.cluster is not None:
381 mn = partial(MininetCluster, servers=options.servers, placement=options.placement)
382 net = mn(topo=topo, host=RemoteNdnHost, link=options.tunnelType)
383 else:
384 net = Mininet(topo, host=NdnHost, link=TCLink)
ashuef3490b2015-02-17 11:01:04 -0600385 elif topo.isTCLink == False and topo.isLimited == True:
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500386 net = Mininet(topo, host=CpuLimitedNdnHost)
ashuef3490b2015-02-17 11:01:04 -0600387 else:
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500388 net = Mininet(topo, host=NdnHost)
ashuef3490b2015-02-17 11:01:04 -0600389
390 t2 = datetime.datetime.now()
391
392 delta = t2 - t
393
394 info('Setup time: ' + str(delta.seconds) + '\n')
395
396 net.start()
397
ashu2ad32e22015-05-29 13:37:40 -0500398 # Giving proper IPs to intf so neighbor nodes can communicate
399 # This is one way of giving connectivity, another way could be
400 # to insert a switch between each pair of neighbors
401 ndnNetBase = "1.0.0.0"
402 interfaces = []
403 for host in net.hosts:
404 for intf in host.intfList():
405 link = intf.link
406 node1, node2 = link.intf1.node, link.intf2.node
Vince Lehmanfbd47c92015-10-14 16:00:06 -0500407
408 if node1 in net.switches or node2 in net.switches:
Vince Lehmanfbd47c92015-10-14 16:00:06 -0500409 continue
410
ashu2ad32e22015-05-29 13:37:40 -0500411 if link.intf1 not in interfaces and link.intf2 not in interfaces:
412 interfaces.append(link.intf1)
413 interfaces.append(link.intf2)
414 node1.setIP(ipStr(ipParse(ndnNetBase) + 1) + '/30', intf=link.intf1)
415 node2.setIP(ipStr(ipParse(ndnNetBase) + 2) + '/30', intf=link.intf2)
416 ndnNetBase = ipStr(ipParse(ndnNetBase) + 4)
417
Ashlesh Gawande532302b2018-02-15 18:58:20 -0600418 time.sleep(2)
419 info('Starting NFD on nodes\n')
420 for host in net.hosts:
421 host.nfd = Nfd(host, options.csSize)
422 host.nfd.start()
423
dmcoomesecf9c5a2017-10-11 10:17:46 -0500424 if options.isNlsrEnabled is True:
Vince Lehman5d5a5662015-12-02 12:33:12 -0600425
dmcoomesecf9c5a2017-10-11 10:17:46 -0500426 # NLSR Security
427 if options.nlsrSecurity is True:
428 Nlsr.createKeysAndCertificates(net, options.workDir)
ashuef3490b2015-02-17 11:01:04 -0600429
dmcoomesecf9c5a2017-10-11 10:17:46 -0500430 # NLSR initialization
Ashlesh Gawande532302b2018-02-15 18:58:20 -0600431 info('Starting NLSR on nodes\n')
dmcoomesecf9c5a2017-10-11 10:17:46 -0500432 for host in net.hosts:
433 conf = next(x for x in hosts_conf if x.name == host.name)
434 host.nlsrParameters = conf.nlsrParameters
435
436 if options.nFaces is not None:
437 host.nlsrParameters["max-faces-per-prefix"] = options.nFaces
ashuef3490b2015-02-17 11:01:04 -0600438
dmcoomes2ef39c02017-10-20 14:06:26 -0500439 if options.routingType == 'dry':
440 host.nlsrParameters["hyperbolic-state"] = "dry-run"
dmcoomes7adc7f72017-10-06 12:01:28 -0500441
dmcoomes2ef39c02017-10-20 14:06:26 -0500442 elif options.routingType == 'hr':
443 host.nlsrParameters["hyperbolic-state"] = "on"
ashuef3490b2015-02-17 11:01:04 -0600444
dmcoomesecf9c5a2017-10-11 10:17:46 -0500445 # Generate NLSR configuration file
446 configGenerator = NlsrConfigGenerator(host, options.nlsrSecurity, options.faceType)
447 configGenerator.createConfigFile()
ashuef3490b2015-02-17 11:01:04 -0600448
dmcoomesecf9c5a2017-10-11 10:17:46 -0500449 # Start NLSR
450 host.nlsr = Nlsr(host, configGenerator.neighborIPs, options.faceType)
451 host.nlsr.start()
ashuef3490b2015-02-17 11:01:04 -0600452
ashuef3490b2015-02-17 11:01:04 -0600453 for host in net.hosts:
454 if 'app' in host.params:
Ashlesh Gawande557cb842015-07-01 15:39:44 -0500455 if host.params['app'] != '':
456 app = host.params['app']
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600457 print("Starting " + app + " on node " + host.name)
Ashlesh Gawande557cb842015-07-01 15:39:44 -0500458 print(host.cmd(app))
ashuef3490b2015-02-17 11:01:04 -0600459
Vince Lehman3b8bc652015-06-18 15:01:47 -0500460 # Load experiment
Vince Lehman194be242015-10-15 18:01:42 -0500461 experimentName = options.experimentName
462
Vince Lehman3b8bc652015-06-18 15:01:47 -0500463 if experimentName is not None:
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600464 print("Loading experiment: %s" % experimentName)
Vince Lehman3b8bc652015-06-18 15:01:47 -0500465
466 experimentArgs = {
467 "net": net,
Vince Lehman194be242015-10-15 18:01:42 -0500468 "ctime": options.ctime,
469 "nPings": options.nPings,
Ashlesh Gawandeb07ada82016-08-05 14:29:17 -0500470 "strategy": Nfd.STRATEGY_BEST_ROUTE,
Ashlesh Gawande6a075c22017-08-03 15:15:49 -0500471 "pctTraffic": options.pctTraffic,
Ashlesh Gawande501d4d62017-10-25 13:12:11 -0500472 "nlsrSecurity": options.nlsrSecurity,
473 "workDir": options.workDir,
474 "arbArgs" : options.arbArgs
Vince Lehman3b8bc652015-06-18 15:01:47 -0500475 }
476
477 experiment = ExperimentManager.create(experimentName, experimentArgs)
478
479 if experiment is not None:
480 experiment.start()
481 else:
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600482 print("ERROR: Experiment '%s' does not exist" % experimentName)
Vince Lehman3b8bc652015-06-18 15:01:47 -0500483 return
484
Vince Lehman194be242015-10-15 18:01:42 -0500485 if options.isCliEnabled is True:
Ashlesh Gawande95789cc2017-02-27 12:38:04 -0600486 MiniNDNCLI(net)
ashuef3490b2015-02-17 11:01:04 -0600487
488 net.stop()
489
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500490 if options.resultDir is not None:
491 print("Moving results to %s" % options.resultDir)
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500492 for file in glob.glob('%s/*' % options.workDir):
493 shutil.move(file, options.resultDir)
494 if options.cluster is not None:
495 for server in options.servers:
496 if server != "localhost":
497 login = "mininet@%s" % server
498 src = "%s:%s/*" % (login, options.workDir)
499 dst = options.resultDir
500 scp(src, dst)
501 print("Please clean work directories of other machines before running the cluster again")
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500502
Ashlesh Gawande3807c1b2016-08-05 16:27:02 -0500503def signal_handler(signal, frame):
504 print('Cleaning up...')
505 call(["nfd-stop"])
506 call(["sudo", "mn", "--clean"])
507 sys.exit(1)
508
ashuef3490b2015-02-17 11:01:04 -0600509if __name__ == '__main__':
Vince Lehman3b8bc652015-06-18 15:01:47 -0500510
ashuef3490b2015-02-17 11:01:04 -0600511 hosts_conf = []
512 links_conf = []
Vince Lehman194be242015-10-15 18:01:42 -0500513
Ashlesh Gawande2763f192017-10-25 15:48:39 -0500514 signal.signal(signal.SIGQUIT, signal_handler)
Ashlesh Gawande3807c1b2016-08-05 16:27:02 -0500515
Vince Lehman194be242015-10-15 18:01:42 -0500516 options = parse_args()
ashuef3490b2015-02-17 11:01:04 -0600517
518 setLogLevel('info')
Alexander Lanee842cc22018-05-14 11:37:43 -0500519
520 # No exceptions are raised in ndn presently, and Mininet relies
521 # on generic Exception. If this situation changes this may well
522 # need to be altered.
523 try:
524 execute(options)
525 except Exception as e:
526 print("Mininet Error: {}".format(e))
527 call(["nfd-stop"])
528 call(["sudo", "mn", "--clean"])
529 sys.exit(1)