Vince Lehman | b8b1806 | 2015-07-14 13:07:22 -0500 | [diff] [blame] | 1 | # -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | # |
Vince Lehman | 5d5a566 | 2015-12-02 12:33:12 -0600 | [diff] [blame^] | 3 | # Copyright (C) 2015-2016, The University of Memphis, |
| 4 | # Arizona Board of Regents, |
| 5 | # Regents of the University of California. |
Vince Lehman | b8b1806 | 2015-07-14 13:07:22 -0500 | [diff] [blame] | 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 | # |
| 24 | # This file incorporates work covered by the following copyright and |
| 25 | # permission notice: |
| 26 | # |
| 27 | # Mininet 2.2.1 License |
| 28 | # |
| 29 | # Copyright (c) 2013-2015 Open Networking Laboratory |
| 30 | # 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. |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 60 | |
| 61 | from mininet.topo import Topo |
| 62 | from mininet.net import Mininet |
| 63 | from mininet.log import setLogLevel, output, info |
| 64 | from mininet.cli import CLI |
| 65 | from mininet.link import TCLink |
ashu | 2ad32e2 | 2015-05-29 13:37:40 -0500 | [diff] [blame] | 66 | from mininet.util import ipStr, ipParse |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 67 | |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 68 | |
| 69 | from ndn import ExperimentManager |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 70 | from ndn.ndn_host import NdnHost, CpuLimitedNdnHost |
Vince Lehman | fbd47c9 | 2015-10-14 16:00:06 -0500 | [diff] [blame] | 71 | from ndn.conf_parser import parse_hosts, parse_switches, parse_links |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 72 | |
| 73 | import os.path, time |
Yucheng Zhang | 14aa596 | 2016-04-05 17:10:15 -0500 | [diff] [blame] | 74 | import shutil |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 75 | import optparse |
| 76 | import datetime |
ashu | 01b62f7 | 2015-03-12 15:16:11 -0500 | [diff] [blame] | 77 | from os.path import expanduser |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 78 | import sys |
Yucheng Zhang | 14aa596 | 2016-04-05 17:10:15 -0500 | [diff] [blame] | 79 | from subprocess import call |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 80 | |
| 81 | from ndn.nlsr import Nlsr, NlsrConfigGenerator |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 82 | from ndn.nfd import Nfd |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 83 | |
Vince Lehman | 68b0815 | 2015-10-23 10:15:36 -0500 | [diff] [blame] | 84 | VERSION_NUMBER = "0.1.1" |
Vince Lehman | e9f116d | 2015-07-15 10:40:21 -0500 | [diff] [blame] | 85 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 86 | def printExperimentNames(option, opt, value, parser): |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 87 | experimentNames = ExperimentManager.getExperimentNames() |
| 88 | |
| 89 | print "Mini-NDN experiments:" |
| 90 | for experiment in experimentNames: |
| 91 | print " %s" % experiment |
| 92 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 93 | sys.exit() |
| 94 | |
Vince Lehman | e9f116d | 2015-07-15 10:40:21 -0500 | [diff] [blame] | 95 | def printVersion(option, opt, value, parser): |
| 96 | print "Mini-NDN v%s" % VERSION_NUMBER |
| 97 | sys.exit() |
| 98 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 99 | class ProgramOptions: |
| 100 | def __init__(self): |
| 101 | self.ctime = 60 |
| 102 | self.experimentName = None |
| 103 | self.nFaces = 3 |
| 104 | self.templateFile = "minindn.conf" |
| 105 | self.hr = False |
| 106 | self.isCliEnabled = True |
Vince Lehman | 5d5a566 | 2015-12-02 12:33:12 -0600 | [diff] [blame^] | 107 | self.nlsrSecurity = False |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 108 | self.nPings = 300 |
| 109 | self.testbed = False |
Ashlesh Gawande | 1b66369 | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 110 | self.workDir = "/tmp" |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 111 | self.resultDir = None |
Ashlesh Gawande | d9c9e52 | 2015-10-15 16:40:12 -0500 | [diff] [blame] | 112 | self.pctTraffic = 1.0 |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 113 | |
| 114 | def createResultsDir(resultDir, faces, hr): |
| 115 | if faces == 0: |
| 116 | faces = "all" |
| 117 | |
| 118 | if hr: |
| 119 | routingType = "/hr/" |
| 120 | else: |
| 121 | routingType = "/ls/" |
| 122 | |
| 123 | resultDir = "%s/%s/faces-%s" % (str(resultDir), routingType, str(faces)) |
| 124 | resultDir = os.path.abspath(resultDir) |
| 125 | |
| 126 | if not os.path.isdir(resultDir): |
| 127 | os.makedirs(resultDir) |
| 128 | else: |
| 129 | print("Results directory (%s) already exists!" % resultDir) |
| 130 | sys.exit(1); |
| 131 | |
| 132 | print "Results will be stored at: %s" % resultDir |
| 133 | return resultDir |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 134 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 135 | def parse_args(): |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 136 | usage = """Usage: minindn [template_file] [ -t | --testbed ] |
Ashlesh Gawande | 20f7076 | 2015-06-17 15:18:19 -0500 | [diff] [blame] | 137 | If no template_file is given, ndn_utils/default-topology.conf (given sample file) |
| 138 | will be used. |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 139 | If --testbed is used, minindn will run the NDN Project Testbed. |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 140 | """ |
| 141 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 142 | parser = optparse.OptionParser(usage) |
| 143 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 144 | parser.add_option("--ctime", action="store", dest="ctime", type="int", default=60, |
| 145 | help="Specify convergence time for the topology (Default: 60 seconds)") |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 146 | |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 147 | parser.add_option("--experiment", action="store", dest="experiment", |
| 148 | help="Runs the specified experiment") |
| 149 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 150 | parser.add_option("--faces", action="store", dest="faces", type="int", default=3, |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 151 | help="Specify number of faces 0-60") |
| 152 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 153 | parser.add_option("--hr", action="store_true", dest="hr", default=False, |
| 154 | help="--hr is used to turn on hyperbolic routing") |
| 155 | |
| 156 | parser.add_option("--list-experiments", action="callback", callback=printExperimentNames, |
| 157 | help="Lists the names of all available experiments") |
| 158 | |
| 159 | parser.add_option("--no-cli", action="store_false", dest="isCliEnabled", default=True, |
| 160 | help="Run experiments and exit without showing the command line interface") |
| 161 | |
| 162 | parser.add_option("--nPings", action="store", dest="nPings", type="int", default=300, |
| 163 | help="Number of pings to perform between each node in the experiment") |
| 164 | |
Vince Lehman | 5d5a566 | 2015-12-02 12:33:12 -0600 | [diff] [blame^] | 165 | parser.add_option("--nlsr-security", action="store_true", dest="nlsrSecurity", default=False, |
| 166 | help="Enables NLSR security") |
| 167 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 168 | parser.add_option("-t", "--testbed", action="store_true", dest="testbed", default=False, |
| 169 | help="instantiates NDN Testbed") |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 170 | |
Ashlesh Gawande | 1b66369 | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 171 | parser.add_option("--work-dir", action="store", dest="workDir", default="/tmp", |
| 172 | help="Specify the working directory; default is /tmp") |
| 173 | |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 174 | parser.add_option("--result-dir", action="store", dest="resultDir", default=None, |
| 175 | help="Specify the full path destination folder where experiment results will be moved") |
| 176 | |
Ashlesh Gawande | d9c9e52 | 2015-10-15 16:40:12 -0500 | [diff] [blame] | 177 | parser.add_option("--pct-traffic", action="store", dest="pctTraffic", type="float", default=1.0, |
| 178 | help="Specify the percentage of nodes each node should ping") |
| 179 | |
Vince Lehman | e9f116d | 2015-07-15 10:40:21 -0500 | [diff] [blame] | 180 | parser.add_option('--version', '-V', action='callback', callback=printVersion, |
| 181 | help='Displays version information') |
| 182 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 183 | (args, arg) = parser.parse_args() |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 184 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 185 | options = ProgramOptions() |
| 186 | options.ctime = args.ctime |
| 187 | options.experimentName = args.experiment |
| 188 | options.nFaces = args.faces |
| 189 | options.hr = args.hr |
| 190 | options.isCliEnabled = args.isCliEnabled |
Vince Lehman | 5d5a566 | 2015-12-02 12:33:12 -0600 | [diff] [blame^] | 191 | options.nlsrSecurity = args.nlsrSecurity |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 192 | options.nPings = args.nPings |
Vince Lehman | 5d5a566 | 2015-12-02 12:33:12 -0600 | [diff] [blame^] | 193 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 194 | options.testbed = args.testbed |
Ashlesh Gawande | 1b66369 | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 195 | options.workDir = args.workDir |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 196 | options.resultDir = args.resultDir |
Ashlesh Gawande | d9c9e52 | 2015-10-15 16:40:12 -0500 | [diff] [blame] | 197 | options.pctTraffic = args.pctTraffic |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 198 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 199 | if options.experimentName is not None and options.experimentName not in ExperimentManager.getExperimentNames(): |
| 200 | print("No experiment named %s" % options.experimentName) |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 201 | sys.exit() |
| 202 | |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 203 | if options.experimentName is not None and options.resultDir is None: |
| 204 | print "No results folder specified; experiment results will remain in the working directory" |
| 205 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 206 | if len(arg) == 0 or len(arg) > 2: |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 207 | options.templateFile = '' |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 208 | else: |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 209 | options.templateFile = arg[0] |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 210 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 211 | return options |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 212 | |
| 213 | class NdnTopo(Topo): |
Ashlesh Gawande | 1b66369 | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 214 | def __init__(self, conf_arq, workDir, **opts): |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 215 | Topo.__init__(self, **opts) |
| 216 | |
| 217 | global hosts_conf |
| 218 | global links_conf |
| 219 | hosts_conf = parse_hosts(conf_arq) |
Vince Lehman | fbd47c9 | 2015-10-14 16:00:06 -0500 | [diff] [blame] | 220 | switches_conf = parse_switches(conf_arq) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 221 | links_conf = parse_links(conf_arq) |
| 222 | |
| 223 | self.isTCLink = False |
| 224 | self.isLimited = False |
| 225 | |
| 226 | for host in hosts_conf: |
| 227 | if host.cpu != None and self.isLimited != True: |
| 228 | self.isLimited = True |
Ashlesh Gawande | 1b66369 | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 229 | self.addHost(host.name, app=host.app, params=host.uri_tuples, cpu=host.cpu,cores=host.cores,cache=host.cache, workdir=workDir) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 230 | |
Vince Lehman | fbd47c9 | 2015-10-14 16:00:06 -0500 | [diff] [blame] | 231 | for switch in switches_conf: |
| 232 | self.addSwitch(switch.name) |
| 233 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 234 | for link in links_conf: |
| 235 | if len(link.linkDict) == 0: |
| 236 | self.addLink(link.h1, link.h2) |
| 237 | else: |
| 238 | self.addLink(link.h1, link.h2, **link.linkDict) |
| 239 | self.isTCLink = True |
| 240 | |
| 241 | info('Parse of ' + conf_arq + ' done.\n') |
| 242 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 243 | def execute(options): |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 244 | "Create a network based on template_file" |
| 245 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 246 | template_file = options.templateFile |
Ashlesh Gawande | 20f7076 | 2015-06-17 15:18:19 -0500 | [diff] [blame] | 247 | install_dir='/usr/local/etc/mini-ndn/' |
| 248 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 249 | if template_file == '': |
Ashlesh Gawande | 20f7076 | 2015-06-17 15:18:19 -0500 | [diff] [blame] | 250 | template_file = install_dir + 'default-topology.conf' |
| 251 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 252 | if options.testbed: |
Ashlesh Gawande | 20f7076 | 2015-06-17 15:18:19 -0500 | [diff] [blame] | 253 | template_file = install_dir + 'minindn.testbed.conf' |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 254 | |
| 255 | if os.path.exists(template_file) == False: |
Ashlesh Gawande | 20f7076 | 2015-06-17 15:18:19 -0500 | [diff] [blame] | 256 | info('No template file given and default template file cannot be found. Exiting...\n') |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 257 | quit() |
Ashlesh Gawande | 20f7076 | 2015-06-17 15:18:19 -0500 | [diff] [blame] | 258 | |
Yucheng Zhang | 14aa596 | 2016-04-05 17:10:15 -0500 | [diff] [blame] | 259 | # Use nfd.conf as default configuration for NFD, else use the sample |
| 260 | |
Vince Lehman | 498625b | 2015-10-21 14:25:24 -0500 | [diff] [blame] | 261 | nfdConfFile = "%s/nfd.conf" % install_dir |
Yucheng Zhang | 14aa596 | 2016-04-05 17:10:15 -0500 | [diff] [blame] | 262 | if os.path.isfile("/usr/local/etc/ndn/nfd.conf") == True: |
| 263 | shutil.copy2("/usr/local/etc/ndn/nfd.conf", nfdConfFile) |
| 264 | elif os.path.isfile("/usr/local/etc/ndn/nfd.conf.sample") == True: |
| 265 | shutil.copy2("/usr/local/etc/ndn/nfd.conf.sample", nfdConfFile) |
| 266 | else: |
| 267 | sys.exit("nfd.conf or nfd.conf.sample cannot be found in the expected directory. Exit.") |
| 268 | |
| 269 | call(["sudo", "sed", "-i", 's|default_level [A-Z]*$|default_level $LOG_LEVEL|g', nfdConfFile]) |
Vince Lehman | 498625b | 2015-10-21 14:25:24 -0500 | [diff] [blame] | 270 | |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 271 | if options.resultDir is not None: |
| 272 | options.resultDir = createResultsDir(options.resultDir, options.nFaces, options.hr) |
| 273 | |
Ashlesh Gawande | 1b66369 | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 274 | topo = NdnTopo(template_file, options.workDir) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 275 | |
| 276 | t = datetime.datetime.now() |
| 277 | |
| 278 | if topo.isTCLink == True and topo.isLimited == True: |
| 279 | net = Mininet(topo,host=CpuLimitedNdnHost,link=TCLink) |
| 280 | elif topo.isTCLink == True and topo.isLimited == False: |
| 281 | net = Mininet(topo,host=NdnHost,link=TCLink) |
| 282 | elif topo.isTCLink == False and topo.isLimited == True: |
| 283 | net = Mininet(topo,host=CpuLimitedNdnHost) |
| 284 | else: |
| 285 | net = Mininet(topo,host=NdnHost) |
| 286 | |
| 287 | t2 = datetime.datetime.now() |
| 288 | |
| 289 | delta = t2 - t |
| 290 | |
| 291 | info('Setup time: ' + str(delta.seconds) + '\n') |
| 292 | |
| 293 | net.start() |
| 294 | |
ashu | 2ad32e2 | 2015-05-29 13:37:40 -0500 | [diff] [blame] | 295 | # Giving proper IPs to intf so neighbor nodes can communicate |
| 296 | # This is one way of giving connectivity, another way could be |
| 297 | # to insert a switch between each pair of neighbors |
| 298 | ndnNetBase = "1.0.0.0" |
| 299 | interfaces = [] |
| 300 | for host in net.hosts: |
| 301 | for intf in host.intfList(): |
| 302 | link = intf.link |
| 303 | node1, node2 = link.intf1.node, link.intf2.node |
Vince Lehman | fbd47c9 | 2015-10-14 16:00:06 -0500 | [diff] [blame] | 304 | |
| 305 | if node1 in net.switches or node2 in net.switches: |
Vince Lehman | fbd47c9 | 2015-10-14 16:00:06 -0500 | [diff] [blame] | 306 | continue |
| 307 | |
ashu | 2ad32e2 | 2015-05-29 13:37:40 -0500 | [diff] [blame] | 308 | if link.intf1 not in interfaces and link.intf2 not in interfaces: |
| 309 | interfaces.append(link.intf1) |
| 310 | interfaces.append(link.intf2) |
| 311 | node1.setIP(ipStr(ipParse(ndnNetBase) + 1) + '/30', intf=link.intf1) |
| 312 | node2.setIP(ipStr(ipParse(ndnNetBase) + 2) + '/30', intf=link.intf2) |
| 313 | ndnNetBase = ipStr(ipParse(ndnNetBase) + 4) |
| 314 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 315 | nodes = "" # Used later to check prefix name in checkFIB |
| 316 | |
Vince Lehman | 5d5a566 | 2015-12-02 12:33:12 -0600 | [diff] [blame^] | 317 | # NLSR Security |
| 318 | if options.nlsrSecurity is True: |
| 319 | Nlsr.createKeysAndCertificates(net, options.workDir) |
| 320 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 321 | # NLSR initialization |
| 322 | for host in net.hosts: |
| 323 | nodes += str(host.name) + "," |
| 324 | |
| 325 | conf = next(x for x in hosts_conf if x.name == host.name) |
| 326 | host.nlsrParameters = conf.nlsrParameters |
| 327 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 328 | if options.nFaces is not None: |
| 329 | host.nlsrParameters["max-faces-per-prefix"] = options.nFaces |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 330 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 331 | if options.hr is True: |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 332 | host.nlsrParameters["hyperbolic-state"] = "on" |
| 333 | |
| 334 | # Generate NLSR configuration file |
Vince Lehman | 5d5a566 | 2015-12-02 12:33:12 -0600 | [diff] [blame^] | 335 | configGenerator = NlsrConfigGenerator(host, options.nlsrSecurity) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 336 | configGenerator.createConfigFile() |
| 337 | |
| 338 | # Start NLSR |
ashu | 34c3ee0 | 2015-03-25 14:41:14 -0500 | [diff] [blame] | 339 | host.nlsr = Nlsr(host) |
| 340 | host.nlsr.start() |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 341 | |
| 342 | nodes = nodes[0:-1] |
| 343 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 344 | for host in net.hosts: |
| 345 | if 'app' in host.params: |
Ashlesh Gawande | 557cb84 | 2015-07-01 15:39:44 -0500 | [diff] [blame] | 346 | if host.params['app'] != '': |
| 347 | app = host.params['app'] |
| 348 | print "Starting " + app + " on node " + host.name |
| 349 | print(host.cmd(app)) |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 350 | |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 351 | # Load experiment |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 352 | experimentName = options.experimentName |
| 353 | |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 354 | if experimentName is not None: |
| 355 | print "Loading experiment: %s" % experimentName |
| 356 | |
| 357 | experimentArgs = { |
| 358 | "net": net, |
| 359 | "nodes": nodes, |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 360 | "ctime": options.ctime, |
| 361 | "nPings": options.nPings, |
Ashlesh Gawande | d9c9e52 | 2015-10-15 16:40:12 -0500 | [diff] [blame] | 362 | "strategy": Nfd.STRATEGY_BEST_ROUTE_V3, |
| 363 | "pctTraffic": options.pctTraffic |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | experiment = ExperimentManager.create(experimentName, experimentArgs) |
| 367 | |
| 368 | if experiment is not None: |
| 369 | experiment.start() |
| 370 | else: |
| 371 | print "ERROR: Experiment '%s' does not exist" % experimentName |
| 372 | return |
| 373 | |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 374 | if options.isCliEnabled is True: |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 375 | CLI(net) |
| 376 | |
| 377 | net.stop() |
| 378 | |
Ashlesh Gawande | d829bfc | 2015-10-14 16:38:10 -0500 | [diff] [blame] | 379 | if options.resultDir is not None: |
| 380 | print("Moving results to %s" % options.resultDir) |
| 381 | os.system("sudo mv /%s/* %s" % (options.workDir, options.resultDir)) |
| 382 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 383 | if __name__ == '__main__': |
Vince Lehman | 3b8bc65 | 2015-06-18 15:01:47 -0500 | [diff] [blame] | 384 | |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 385 | hosts_conf = [] |
| 386 | links_conf = [] |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 387 | |
| 388 | options = parse_args() |
ashu | ef3490b | 2015-02-17 11:01:04 -0600 | [diff] [blame] | 389 | |
| 390 | setLogLevel('info') |
Vince Lehman | 194be24 | 2015-10-15 18:01:42 -0500 | [diff] [blame] | 391 | execute(options) |