blob: b2c8db6d46162476e02a4f30b3d120c21eb899aa [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 Gawandeda475f02017-03-01 17:20:58 -060092VERSION_NUMBER = "0.3.0"
Ashlesh Gawande044611d2016-12-21 14:24:49 -060093INSTALL_DIR='/usr/local/etc/mini-ndn/'
Vince Lehmane9f116d2015-07-15 10:40:21 -050094
Ashlesh Gawande044611d2016-12-21 14:24:49 -060095class PrintExperimentNames(argparse.Action):
96 def __init__(self, option_strings, dest, nargs=0, help=None):
97 super(PrintExperimentNames, self).__init__(option_strings=option_strings, dest=dest, nargs=nargs, help=help)
Vince Lehman3b8bc652015-06-18 15:01:47 -050098
Ashlesh Gawande044611d2016-12-21 14:24:49 -060099 def __call__(self, parser, namespace, values, option_string=None):
100 experimentNames = ExperimentManager.getExperimentNames()
Vince Lehman3b8bc652015-06-18 15:01:47 -0500101
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600102 print("Mini-NDN experiments:")
103 for experiment in experimentNames:
104 print(" %s" % experiment)
Vince Lehman194be242015-10-15 18:01:42 -0500105
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600106 sys.exit(0)
Vince Lehmane9f116d2015-07-15 10:40:21 -0500107
Vince Lehman194be242015-10-15 18:01:42 -0500108class ProgramOptions:
109 def __init__(self):
110 self.ctime = 60
111 self.experimentName = None
112 self.nFaces = 3
113 self.templateFile = "minindn.conf"
dmcoomes7adc7f72017-10-06 12:01:28 -0500114 self.routingType = "link-state"
dmcoomesecf9c5a2017-10-11 10:17:46 -0500115 self.isNlsrEnabled = True
Vince Lehman194be242015-10-15 18:01:42 -0500116 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 Gawande708fcca2017-06-23 14:04:12 -0500128 self.faceType = "udp"
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500129
dmcoomes7adc7f72017-10-06 12:01:28 -0500130def createResultsDir(resultDir, faces, rType):
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500131 if faces == 0:
132 faces = "all"
133
dmcoomes7adc7f72017-10-06 12:01:28 -0500134 routingChoice = "/{}/".format(rType)
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500135
dmcoomes7adc7f72017-10-06 12:01:28 -0500136 resultDir = "{}/{}/faces-{}".format(resultDir, routingChoice, faces)
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500137 resultDir = os.path.abspath(resultDir)
138
139 if not os.path.isdir(resultDir):
140 os.makedirs(resultDir)
141 else:
142 print("Results directory (%s) already exists!" % resultDir)
143 sys.exit(1);
144
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600145 print("Results will be stored at: %s" % resultDir)
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500146 return resultDir
Vince Lehman194be242015-10-15 18:01:42 -0500147
ashuef3490b2015-02-17 11:01:04 -0600148def parse_args():
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600149 parser = argparse.ArgumentParser(prog='minindn')
ashuef3490b2015-02-17 11:01:04 -0600150
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600151 # nargs='?' required here since optional argument
152 parser.add_argument('tempfile', nargs='?', default=INSTALL_DIR + 'default-topology.conf',
153 help="If no template_file is given, ndn_utils/default-topology.conf (given sample file) will be used.")
ashuef3490b2015-02-17 11:01:04 -0600154
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600155 parser.add_argument("--ctime", type=int, default=60,
156 help="Specify convergence time for the topology (Default: 60 seconds)")
ashuef3490b2015-02-17 11:01:04 -0600157
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600158 parser.add_argument("--experiment",
159 help="Runs the specified experiment")
Vince Lehman3b8bc652015-06-18 15:01:47 -0500160
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600161 parser.add_argument("--faces", type=int, default=3,
162 help="Specify number of faces 0-60")
ashuef3490b2015-02-17 11:01:04 -0600163
dmcoomes7adc7f72017-10-06 12:01:28 -0500164 parser.add_argument("--routing", dest="routingType", default='link-state', choices=['link-state', 'hr', 'dry'],
165 help="""choices for routing are 'link-state' for link state, 'hr' for hyperbolic, and 'dry'
166 to test hyperbolic routing and compare with link state. Default is link-state.""")
Vince Lehman194be242015-10-15 18:01:42 -0500167
dmcoomesecf9c5a2017-10-11 10:17:46 -0500168 parser.add_argument("--no-nlsr", action="store_false", dest="isNlsrEnabled",
169 help="Run mini-ndn without NLSR routing")
170
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600171 parser.add_argument("--list-experiments", action=PrintExperimentNames,
172 help="Lists the names of all available experiments")
Vince Lehman194be242015-10-15 18:01:42 -0500173
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600174 parser.add_argument("--no-cli", action="store_false", dest="isCliEnabled",
175 help="Run experiments and exit without showing the command line interface")
Vince Lehman194be242015-10-15 18:01:42 -0500176
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600177 parser.add_argument("--nPings", type=int, default=300,
178 help="Number of pings to perform between each node in the experiment")
Vince Lehman194be242015-10-15 18:01:42 -0500179
dmcoomes7adc7f72017-10-06 12:01:28 -0500180 # store_true stores default value of False
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600181 parser.add_argument("--nlsr-security", action="store_true", dest="nlsrSecurity",
182 help="Enables NLSR security")
Vince Lehman5d5a5662015-12-02 12:33:12 -0600183
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600184 parser.add_argument("-t", "--testbed", action="store_true", dest="testbed",
185 help="Instantiates a snapshot of the NDN Testbed irrespective of the tempfile provided")
ashuef3490b2015-02-17 11:01:04 -0600186
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600187 parser.add_argument("--work-dir", action="store", dest="workDir", default="/tmp",
188 help="Specify the working directory; default is /tmp")
Ashlesh Gawande1b663692015-10-14 16:38:10 -0500189
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600190 parser.add_argument("--result-dir", action="store", dest="resultDir", default=None,
191 help="Specify the full path destination folder where experiment results will be moved")
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500192
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600193 parser.add_argument("--pct-traffic", dest="pctTraffic", type=float, default=1.0,
194 help="Specify the percentage of nodes each node should ping")
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -0500195
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600196 parser.add_argument('--version', '-V', action='version', version='%(prog)s ' + VERSION_NUMBER,
197 help='Displays version information')
Vince Lehmane9f116d2015-07-15 10:40:21 -0500198
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500199 parser.add_argument("--cluster", metavar='localhost,server2,...',
200 help="Run cluster edition")
201
202 parser.add_argument("--placement", default='guided',
203 choices=['roundRobin', 'guided'])
204
205 parser.add_argument("--place-list", dest="placeList",
206 help="""Provide corresponding number of nodes (comma separated) to put on
207 each node respectively of --cluster when guided placement is used""")
208
209 parser.add_argument("--tunnel-type", dest="tunnelType", default='ssh',
210 choices=['ssh', 'gre'])
211
Ashlesh Gawande708fcca2017-06-23 14:04:12 -0500212 parser.add_argument("--face-type", dest='faceType', default='udp', choices=['udp', 'tcp'])
213
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600214 args = parser.parse_args()
ashuef3490b2015-02-17 11:01:04 -0600215
Vince Lehman194be242015-10-15 18:01:42 -0500216 options = ProgramOptions()
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600217 options.templateFile = args.tempfile
Vince Lehman194be242015-10-15 18:01:42 -0500218 options.ctime = args.ctime
219 options.experimentName = args.experiment
220 options.nFaces = args.faces
dmcoomes7adc7f72017-10-06 12:01:28 -0500221 options.routingType = args.routingType
dmcoomesecf9c5a2017-10-11 10:17:46 -0500222 options.isNlsrEnabled = args.isNlsrEnabled
Vince Lehman194be242015-10-15 18:01:42 -0500223 options.isCliEnabled = args.isCliEnabled
Vince Lehman5d5a5662015-12-02 12:33:12 -0600224 options.nlsrSecurity = args.nlsrSecurity
Vince Lehman194be242015-10-15 18:01:42 -0500225 options.nPings = args.nPings
Vince Lehman5d5a5662015-12-02 12:33:12 -0600226
Vince Lehman194be242015-10-15 18:01:42 -0500227 options.testbed = args.testbed
Ashlesh Gawande1b663692015-10-14 16:38:10 -0500228 options.workDir = args.workDir
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500229 options.resultDir = args.resultDir
Ashlesh Gawanded9c9e522015-10-15 16:40:12 -0500230 options.pctTraffic = args.pctTraffic
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500231 options.cluster = args.cluster
232 options.placement = args.placement
233 options.tunnelType = args.tunnelType
234 options.placeList = args.placeList
Ashlesh Gawande708fcca2017-06-23 14:04:12 -0500235 options.faceType = args.faceType
ashuef3490b2015-02-17 11:01:04 -0600236
Vince Lehman194be242015-10-15 18:01:42 -0500237 if options.experimentName is not None and options.experimentName not in ExperimentManager.getExperimentNames():
238 print("No experiment named %s" % options.experimentName)
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600239 sys.exit(1)
Vince Lehman3b8bc652015-06-18 15:01:47 -0500240
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500241 if options.experimentName is not None and options.resultDir is None:
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600242 print("No results folder specified; experiment results will remain in the working directory")
ashuef3490b2015-02-17 11:01:04 -0600243
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500244 if options.cluster is not None:
245 servers = options.cluster.split(',')
246 for server in servers:
247 ClusterCleanup.add(server)
248 options.servers = servers
249
250 if options.placement == "roundRobin":
251 options.placement = RoundRobinPlacer
252 elif options.placement == "guided":
253 if options.placeList is None or not re.match("^[0-9,]+$", options.placeList):
254 print("Please specify correctly how many nodes you want to place on each node!")
255 sys.exit(1)
256 else:
257 try:
258 options.placeList = map(int, options.placeList.split(","))
259 except ValueError:
260 print("Please specify the nodes correctly, no comma at the beginning/end!")
261 sys.exit(1)
262
263 PopulatePlacement(options.placeList)
264 options.placement = GuidedPlacer
265
266 if options.tunnelType == "ssh":
267 options.tunnelType = RemoteNdnLink
268 else:
269 options.tunnelType = RemoteGRENdnLink
270
Vince Lehman194be242015-10-15 18:01:42 -0500271 return options
ashuef3490b2015-02-17 11:01:04 -0600272
273class NdnTopo(Topo):
Ashlesh Gawande1b663692015-10-14 16:38:10 -0500274 def __init__(self, conf_arq, workDir, **opts):
ashuef3490b2015-02-17 11:01:04 -0600275 Topo.__init__(self, **opts)
276
277 global hosts_conf
278 global links_conf
279 hosts_conf = parse_hosts(conf_arq)
Vince Lehmanfbd47c92015-10-14 16:00:06 -0500280 switches_conf = parse_switches(conf_arq)
ashuef3490b2015-02-17 11:01:04 -0600281 links_conf = parse_links(conf_arq)
282
283 self.isTCLink = False
284 self.isLimited = False
285
286 for host in hosts_conf:
287 if host.cpu != None and self.isLimited != True:
288 self.isLimited = True
Ashlesh Gawande1b663692015-10-14 16:38:10 -0500289 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 -0600290
Vince Lehmanfbd47c92015-10-14 16:00:06 -0500291 for switch in switches_conf:
292 self.addSwitch(switch.name)
293
ashuef3490b2015-02-17 11:01:04 -0600294 for link in links_conf:
295 if len(link.linkDict) == 0:
296 self.addLink(link.h1, link.h2)
297 else:
298 self.addLink(link.h1, link.h2, **link.linkDict)
299 self.isTCLink = True
300
301 info('Parse of ' + conf_arq + ' done.\n')
302
Vince Lehman194be242015-10-15 18:01:42 -0500303def execute(options):
ashuef3490b2015-02-17 11:01:04 -0600304 "Create a network based on template_file"
305
Vince Lehman194be242015-10-15 18:01:42 -0500306 if options.testbed:
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600307 options.templateFile = INSTALL_DIR + 'minindn.testbed.conf'
ashuef3490b2015-02-17 11:01:04 -0600308
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600309 if os.path.exists(options.templateFile) == False:
310 info('Template file cannot be found. Exiting...\n')
311 sys.exit(1)
Ashlesh Gawande20f70762015-06-17 15:18:19 -0500312
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500313 if options.cluster is not None and options.placement == GuidedPlacer:
314 num_nodes = 0
315 with open(options.templateFile, 'r') as topo:
316 for line in topo:
317 if ': _' in line:
318 num_nodes += 1
319
320 if sum(options.placeList) != num_nodes:
321 print("Placement list sum is not equal to number of nodes!")
322 sys.exit(1)
323
Yucheng Zhang14aa5962016-04-05 17:10:15 -0500324 # Use nfd.conf as default configuration for NFD, else use the sample
325
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600326 nfdConfFile = "%s/nfd.conf" % INSTALL_DIR
Yucheng Zhang14aa5962016-04-05 17:10:15 -0500327 if os.path.isfile("/usr/local/etc/ndn/nfd.conf") == True:
328 shutil.copy2("/usr/local/etc/ndn/nfd.conf", nfdConfFile)
329 elif os.path.isfile("/usr/local/etc/ndn/nfd.conf.sample") == True:
330 shutil.copy2("/usr/local/etc/ndn/nfd.conf.sample", nfdConfFile)
331 else:
332 sys.exit("nfd.conf or nfd.conf.sample cannot be found in the expected directory. Exit.")
333
334 call(["sudo", "sed", "-i", 's|default_level [A-Z]*$|default_level $LOG_LEVEL|g', nfdConfFile])
Vince Lehman498625b2015-10-21 14:25:24 -0500335
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500336 # Copy nfd.conf to remote hosts - this assumes that NDN versions across
337 # the cluster are at least compatible if not the same
338 if options.cluster is not None:
339 for server in options.servers:
340 if server != "localhost":
341 login = "mininet@%s" % server
342 src = nfdConfFile
343 dst = "%s:/tmp/nfd.conf" % (login)
344 scp(src, dst)
345 ssh(login, "sudo cp /tmp/nfd.conf %s" % src)
346
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500347 if options.resultDir is not None:
dmcoomes7adc7f72017-10-06 12:01:28 -0500348 options.resultDir = createResultsDir(options.resultDir, options.nFaces, options.routingType)
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500349
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600350 topo = NdnTopo(options.templateFile, options.workDir)
ashuef3490b2015-02-17 11:01:04 -0600351
352 t = datetime.datetime.now()
353
354 if topo.isTCLink == True and topo.isLimited == True:
355 net = Mininet(topo,host=CpuLimitedNdnHost,link=TCLink)
356 elif topo.isTCLink == True and topo.isLimited == False:
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500357 if options.cluster is not None:
358 mn = partial(MininetCluster, servers=options.servers, placement=options.placement)
359 net = mn(topo=topo, host=RemoteNdnHost, link=options.tunnelType)
360 else:
361 net = Mininet(topo, host=NdnHost, link=TCLink)
ashuef3490b2015-02-17 11:01:04 -0600362 elif topo.isTCLink == False and topo.isLimited == True:
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500363 net = Mininet(topo, host=CpuLimitedNdnHost)
ashuef3490b2015-02-17 11:01:04 -0600364 else:
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500365 net = Mininet(topo, host=NdnHost)
ashuef3490b2015-02-17 11:01:04 -0600366
367 t2 = datetime.datetime.now()
368
369 delta = t2 - t
370
371 info('Setup time: ' + str(delta.seconds) + '\n')
372
373 net.start()
374
ashu2ad32e22015-05-29 13:37:40 -0500375 # Giving proper IPs to intf so neighbor nodes can communicate
376 # This is one way of giving connectivity, another way could be
377 # to insert a switch between each pair of neighbors
378 ndnNetBase = "1.0.0.0"
379 interfaces = []
380 for host in net.hosts:
381 for intf in host.intfList():
382 link = intf.link
383 node1, node2 = link.intf1.node, link.intf2.node
Vince Lehmanfbd47c92015-10-14 16:00:06 -0500384
385 if node1 in net.switches or node2 in net.switches:
Vince Lehmanfbd47c92015-10-14 16:00:06 -0500386 continue
387
ashu2ad32e22015-05-29 13:37:40 -0500388 if link.intf1 not in interfaces and link.intf2 not in interfaces:
389 interfaces.append(link.intf1)
390 interfaces.append(link.intf2)
391 node1.setIP(ipStr(ipParse(ndnNetBase) + 1) + '/30', intf=link.intf1)
392 node2.setIP(ipStr(ipParse(ndnNetBase) + 2) + '/30', intf=link.intf2)
393 ndnNetBase = ipStr(ipParse(ndnNetBase) + 4)
394
dmcoomesecf9c5a2017-10-11 10:17:46 -0500395 if options.isNlsrEnabled is True:
Vince Lehman5d5a5662015-12-02 12:33:12 -0600396
dmcoomesecf9c5a2017-10-11 10:17:46 -0500397 # NLSR Security
398 if options.nlsrSecurity is True:
399 Nlsr.createKeysAndCertificates(net, options.workDir)
ashuef3490b2015-02-17 11:01:04 -0600400
dmcoomesecf9c5a2017-10-11 10:17:46 -0500401 # NLSR initialization
402 for host in net.hosts:
403 conf = next(x for x in hosts_conf if x.name == host.name)
404 host.nlsrParameters = conf.nlsrParameters
405
406 if options.nFaces is not None:
407 host.nlsrParameters["max-faces-per-prefix"] = options.nFaces
ashuef3490b2015-02-17 11:01:04 -0600408
dmcoomes7adc7f72017-10-06 12:01:28 -0500409 if options.routingType == 'dry':
410 host.nlsrParameters["hyperbolic-state"] = "dry-run"
411
412 elif options.routingType == 'hr':
ashuef3490b2015-02-17 11:01:04 -0600413 host.nlsrParameters["hyperbolic-state"] = "on"
414
dmcoomesecf9c5a2017-10-11 10:17:46 -0500415 # Generate NLSR configuration file
416 configGenerator = NlsrConfigGenerator(host, options.nlsrSecurity, options.faceType)
417 configGenerator.createConfigFile()
ashuef3490b2015-02-17 11:01:04 -0600418
dmcoomesecf9c5a2017-10-11 10:17:46 -0500419 # Start NLSR
420 host.nlsr = Nlsr(host, configGenerator.neighborIPs, options.faceType)
421 host.nlsr.start()
ashuef3490b2015-02-17 11:01:04 -0600422
ashuef3490b2015-02-17 11:01:04 -0600423 for host in net.hosts:
424 if 'app' in host.params:
Ashlesh Gawande557cb842015-07-01 15:39:44 -0500425 if host.params['app'] != '':
426 app = host.params['app']
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600427 print("Starting " + app + " on node " + host.name)
Ashlesh Gawande557cb842015-07-01 15:39:44 -0500428 print(host.cmd(app))
ashuef3490b2015-02-17 11:01:04 -0600429
Vince Lehman3b8bc652015-06-18 15:01:47 -0500430 # Load experiment
Vince Lehman194be242015-10-15 18:01:42 -0500431 experimentName = options.experimentName
432
Vince Lehman3b8bc652015-06-18 15:01:47 -0500433 if experimentName is not None:
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600434 print("Loading experiment: %s" % experimentName)
Vince Lehman3b8bc652015-06-18 15:01:47 -0500435
436 experimentArgs = {
437 "net": net,
Vince Lehman194be242015-10-15 18:01:42 -0500438 "ctime": options.ctime,
439 "nPings": options.nPings,
Ashlesh Gawandeb07ada82016-08-05 14:29:17 -0500440 "strategy": Nfd.STRATEGY_BEST_ROUTE,
Ashlesh Gawande6a075c22017-08-03 15:15:49 -0500441 "pctTraffic": options.pctTraffic,
442 "nlsrSecurity": options.nlsrSecurity
Vince Lehman3b8bc652015-06-18 15:01:47 -0500443 }
444
445 experiment = ExperimentManager.create(experimentName, experimentArgs)
446
447 if experiment is not None:
448 experiment.start()
449 else:
Ashlesh Gawande044611d2016-12-21 14:24:49 -0600450 print("ERROR: Experiment '%s' does not exist" % experimentName)
Vince Lehman3b8bc652015-06-18 15:01:47 -0500451 return
452
Vince Lehman194be242015-10-15 18:01:42 -0500453 if options.isCliEnabled is True:
Ashlesh Gawande95789cc2017-02-27 12:38:04 -0600454 MiniNDNCLI(net)
ashuef3490b2015-02-17 11:01:04 -0600455
456 net.stop()
457
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500458 if options.resultDir is not None:
459 print("Moving results to %s" % options.resultDir)
Ashlesh Gawandef5f304b2016-06-16 16:42:41 -0500460 for file in glob.glob('%s/*' % options.workDir):
461 shutil.move(file, options.resultDir)
462 if options.cluster is not None:
463 for server in options.servers:
464 if server != "localhost":
465 login = "mininet@%s" % server
466 src = "%s:%s/*" % (login, options.workDir)
467 dst = options.resultDir
468 scp(src, dst)
469 print("Please clean work directories of other machines before running the cluster again")
Ashlesh Gawanded829bfc2015-10-14 16:38:10 -0500470
Ashlesh Gawande3807c1b2016-08-05 16:27:02 -0500471def signal_handler(signal, frame):
472 print('Cleaning up...')
473 call(["nfd-stop"])
474 call(["sudo", "mn", "--clean"])
475 sys.exit(1)
476
ashuef3490b2015-02-17 11:01:04 -0600477if __name__ == '__main__':
Vince Lehman3b8bc652015-06-18 15:01:47 -0500478
ashuef3490b2015-02-17 11:01:04 -0600479 hosts_conf = []
480 links_conf = []
Vince Lehman194be242015-10-15 18:01:42 -0500481
Ashlesh Gawande3807c1b2016-08-05 16:27:02 -0500482 signal.signal(signal.SIGINT, signal_handler)
483
Vince Lehman194be242015-10-15 18:01:42 -0500484 options = parse_args()
ashuef3490b2015-02-17 11:01:04 -0600485
486 setLogLevel('info')
Vince Lehman194be242015-10-15 18:01:42 -0500487 execute(options)