def execute(options): "Create a network based on template_file" template_file = options.templateFile install_dir='/usr/local/etc/mini-ndn/' if template_file == '': template_file = install_dir + 'default-topology.conf' if options.testbed: template_file = install_dir + 'minindn.testbed.conf' if os.path.exists(template_file) == False: info('No template file given and default template file cannot be found. Exiting...\n') quit() # Update nfd.conf file used by Mini-NDN to match the currently installed version of NFD nfdConfFile = "%s/nfd.conf" % install_dir os.system("sudo cp /usr/local/etc/ndn/nfd.conf.sample %s" % nfdConfFile) os.system("sudo sed -i \'s|default_level [A-Z]*$|default_level $LOG_LEVEL|g\' %s" % nfdConfFile) topo = NdnTopo(template_file, options.workDir) t = datetime.datetime.now() if topo.isTCLink == True and topo.isLimited == True: net = Mininet(topo,host=CpuLimitedNdnHost,link=TCLink) elif topo.isTCLink == True and topo.isLimited == False: net = Mininet(topo,host=NdnHost,link=TCLink) elif topo.isTCLink == False and topo.isLimited == True: net = Mininet(topo,host=CpuLimitedNdnHost) else: net = Mininet(topo,host=NdnHost,controller=RemoteController) # [PZ] probable alternative is to have net=Mininet(...,build=False) and add something like # net.addController(name='c0', controller=RemoteController, ip='127.0.0.1') # ..and then have net.build() t2 = datetime.datetime.now() delta = t2 - t info('Setup time: ' + str(delta.seconds) + '\n') net.start() # Giving proper IPs to intf so neighbor nodes can communicate # This is one way of giving connectivity, another way could be # to insert a switch between each pair of neighbors ndnNetBase = "1.0.0.0" sdnNetBase = "2.0.0.0" sdnHostCount = 0 interfaces = [] for host in net.hosts: for intf in host.intfList(): link = intf.link node1, node2 = link.intf1.node, link.intf2.node # if node1 in net.switches or node2 in net.switches: # print "%s or %s is a switch" % (node1.name, node2.name) # continue if node1 in net.hosts and node2 in net.switches: sdnHostCount += 1 if sdnHostCount > 254: print "too many sdn hosts" exit() node1.setIP(ipStr(ipParse(sdnNetBase) + sdnHostCount) + '/24', intf=link.intf1) continue if node2 in net.hosts and node1 in net.switches: sdnHostCount += 1 if sdnHostCount > 254: print "too many sdn hosts" exit() node2.setIP(ipStr(ipParse(sdnNetBase) + sdnHostCount) + '/24', intf=link.intf2) continue if link.intf1 not in interfaces and link.intf2 not in interfaces: interfaces.append(link.intf1) interfaces.append(link.intf2) node1.setIP(ipStr(ipParse(ndnNetBase) + 1) + '/30', intf=link.intf1) node2.setIP(ipStr(ipParse(ndnNetBase) + 2) + '/30', intf=link.intf2) ndnNetBase = ipStr(ipParse(ndnNetBase) + 4) nodes = "" # Used later to check prefix name in checkFIB # NLSR initialization for host in net.hosts: nodes += str(host.name) + "," conf = next(x for x in hosts_conf if x.name == host.name) host.nlsrParameters = conf.nlsrParameters if options.nFaces is not None: host.nlsrParameters["max-faces-per-prefix"] = options.nFaces if options.hr is True: host.nlsrParameters["hyperbolic-state"] = "on" # Generate NLSR configuration file configGenerator = NlsrConfigGenerator(host) configGenerator.createConfigFile() # Start NLSR host.nlsr = Nlsr(host) host.nlsr.start() nodes = nodes[0:-1] for host in net.hosts: if 'app' in host.params: if host.params['app'] != '': app = host.params['app'] print "Starting " + app + " on node " + host.name print(host.cmd(app)) # Load experiment experimentName = options.experimentName if experimentName is not None: print "Loading experiment: %s" % experimentName experimentArgs = { "net": net, "nodes": nodes, "ctime": options.ctime, "nPings": options.nPings, "strategy": Nfd.STRATEGY_BEST_ROUTE_V3 } experiment = ExperimentManager.create(experimentName, experimentArgs) if experiment is not None: experiment.start() else: print "ERROR: Experiment '%s' does not exist" % experimentName return if options.isCliEnabled is True: CLI(net) net.stop()