def runMPI(): # Create network topo = TestTopo() net = Mininet(topo=topo, controller=lambda name: RemoteController(name, ip='127.0.0.1'), link=TCLink) # net = Mininet(topo=topo, controller=OVSController, link=TCLink) net.start() for host in net.hosts: host.cmd('../../tiny-lldpd/tlldpd -d -i 1') sleep(5) # Launch sshd on each hosts and output host IPs to machinefile pids = [] f = open('./machines', 'w') for h in net.hosts: h.cmd('/usr/sbin/sshd -D -o UseDNS=no -u0 &') pid = int(h.cmd('echo $!')) pids.append(pid) f.write('%s\n' % h.IP()) f.close() # Launch MPI application print "Starting MPI application:" print "----------------------------------------" net.hosts[0].cmdPrint('mpirun --machinefile ./machines --mca coll_tuned_priority 100 --mca coll_tuned_allreduce_algorithm 3 --mca coll_tuned_use_dynamic_rules 1 --mca coll_base_verbose 1 ./mpitest'); print "----------------------------------------" print "MPI application finished." for pid in pids: h.cmd('kill -9 %s' % pid) net.hosts[0].cmd('killall -9 tlldpd') net.stop() cleanup()
def perfTest(): topo = TestTopo() net = Mininet(topo=topo, controller=lambda name: RemoteController(name, ip='127.0.0.1'), link=TCLink) net.start() print "Dumping connections" dumpNodeConnections(net.hosts) print "Launching LLDP daemons" for host in net.hosts: host.cmd('../../tiny-lldpd/tlldpd -d -i 1') sleep(3) net.pingAll() net.get('h3').cmd('iperf -sD') net.get('h4').cmd('iperf -sD') net.get('h1').cmd('iperf -c %s > /tmp/h1.txt &' % net.get('h3').IP()) net.get('h2').cmd('sleep 1; iperf -c %s > /tmp/h2.txt &' % net.get('h4').IP()) net.get('h1').cmd('wait $!') net.get('h2').cmd('wait $!') net.get('h1').cmdPrint("awk 'NR == 7 {print $7 $8}' /tmp/h1.txt") net.get('h2').cmdPrint("awk 'NR == 7 {print $7 $8}' /tmp/h2.txt") net.hosts[0].cmd('killall -9 tlldpd') net.hosts[0].cmd('killall -9 iperf') net.stop() cleanup()
def launch_network(k=4, bw=10, ip_alias=True, fair_queues=False, cli=False): signal.signal(signal.SIGTERM, signal_term_handler) # Cleanup the network cleanup() sh("killall ospfd zebra getLoads.py nc") # Remove tmp files and old namespaces subprocess.call(['rm', '/tmp/*.log', '/tmp/*.pid', '/tmp/mice*']) subprocess.call(['rm', '/var/run/netns/*']) # Flush root namespace mangle table subprocess.call(["iptables", "-t", "mangle" ,"-F"]) subprocess.call(["iptables", "-t", "mangle" ,"-X"]) # Topology topo = FatTree(k=k, sflow=False, ovs_switches=False) # Interfaces if fair_queues: print("*** Using FairQueues at the network interfaces") intf = custom(DCTCIntf, bw=bw) else: print("*** Using normal pFIFO queues at the network interfaces") intf = custom(PrioFifoIntf, bw=bw) # Network net = IPNet(topo=topo, debug=_lib.DEBUG_FLAG, intf=intf) # Save the TopoDB object TopologyDB(net=net).save(cfg.DB_path) # Start the network net.start() # Setup hash seeds setupHashSeeds(topo) # Start intreface collectors startCounterCollectors(topo, interval=1) if ip_alias: setupSecondaryIps(net) if cli: # Start the Fibbing CLI FibbingCLI(net) else: print("*** Looping forever. Press CTRL+C to quit") while True: try: time.sleep(2) except KeyboardInterrupt: print("*** KeyboardInterrupt catched! Shutting down") break net.stop() stopCounterCollectors(topo)
def runTests( testDir, verbosity=1 ): "discover and run all tests in testDir" # ensure root and cleanup before starting tests cleanup() # discover all tests in testDir testSuite = defaultTestLoader.discover( testDir ) # run tests TextTestRunner( verbosity=verbosity ).run( testSuite )
def stop_mininet(self): if self.mininet_client is not None: self.mininet_client.stop() if self.topology: self.topology = [] self.delay = None cleanup() sleep(20)
def runTests( testDir, verbosity=1 ): "discover and run all tests in testDir" # cleanup before starting tests cleanup() # discover all tests in testDir testSuite = unittest.defaultTestLoader.discover( testDir ) # run tests MininetTestRunner( verbosity=verbosity ).run( testSuite )
def mininet_cleanup(): global net logger.info("*** Clean Topology") if net is not None: logger.info("--> calling mininet.stop()") net.stop() net = None cleanup() return {'status': 'ok'}
def tearDown(): cleanup() # make sure that all pending docker containers are killed with open(os.devnull, 'w') as devnull: subprocess.call( "sudo docker rm -f $(sudo docker ps --filter 'label=com.containernet' -a -q)", stdout=devnull, stderr=devnull, shell=True)
def tearDown(): cleanup() # make sure that all pending docker containers are killed with open(os.devnull, 'w') as devnull: subprocess.call( "docker rm -f $(docker ps --filter 'label=com.containernet' -a -q)", stdout=devnull, stderr=devnull, shell=True)
def runTests(testDir, verbosity=1): "discover and run all tests in testDir" # ensure root and cleanup before starting tests ensureRoot() cleanup() # discover all tests in testDir testSuite = defaultTestLoader.discover(testDir) # run tests success = TextTestRunner(verbosity=verbosity).run(testSuite).wasSuccessful() sys.exit(0 if success else 1)
def runTests( testDir, verbosity=1 ): "discover and run all tests in testDir" # ensure root and cleanup before starting tests ensureRoot() cleanup() # discover all tests in testDir testSuite = unittest.defaultTestLoader.discover( testDir ) # run tests success = MininetTestRunner( verbosity=verbosity ).run( testSuite ).wasSuccessful() sys.exit( 0 if success else 1 )
def __init__(self, topo=None): cleanUpScreens() cleanup() if topo is None: topo = LinearTopo(N) self.net = Mininet(controller=partial(RemoteController, ip='101.6.30.40', port=6653), topo=topo, #host=CPULimitedHost, #link=TCLink )
def destroy_mininet(self): """shut down mininet instance""" if self.net: for popen in self.x11popens: popen.terminate() popen.communicate() popen.wait() self.net.stop() # remove mininet instance and running docker container cleanup() self.logger.info("mininet instance terminated") self.net = None
def init(pred_error, seed = None): cleanup() config = ConfigParser.ConfigParser() config.read('./config') ip = config.get('main','Ip') link_type = config.get('main','Distribution') nm_sw_sf = int(config.get('main','MainSwitches')) nm_ho_sf = 0 datac = int(config.get('main','Datacenters')) err_int = int(config.get('main', 'ErrorInterval')) if seed == None or 'None' in seed: seed = random.randint(1, 10000) print ' Seed = %s' % seed topo = random_scalefree.RandomScaleFree(seed, link_type, datac, nm_sw_sf, nm_ho_sf) if datac > 0: namespace = [nm_sw_sf+3*datac, nm_ho_sf+3*datac] else: namespace = [nm_sw_sf, nm_ho_sf] trim(topo) ex_net = config.sections() if (len(ex_net)>1): extra_topos = {} n_networks = len(ex_net)-1 config2 = ConfigParser.ConfigParser() config2.read('./repo_subnets') topo_counter = 0 for i in range(n_networks): nm_networks = int(config.get(ex_net[i+1], 'Number')) for n in range(nm_networks): nm_sw = int(config2.get(ex_net[i+1],'Switches')) nm_ho = int(config2.get(ex_net[i+1],'Hosts')) extra_topos["topo{}".format(topo_counter)] = random_scalefree.RandomScaleFree(seed, link_type, 0, nm_sw, nm_ho, namespace) namespace[0] += nm_sw namespace[1] += nm_ho topo_counter += 1 print "Building network..." join = join_networks(topo, extra_topos, namespace[0], link_type) topo = join[0] namespace[0] = join[1] run(topo, ip, config, config2, pred_error, err_int) return
def __init__(self, controller=RemoteController, monitor=False, enable_learning = True, # in case of RemoteController (Ryu), learning switch behavior can be turned off/on dc_emulation_max_cpu=1.0, # fraction of overall CPU time for emulation dc_emulation_max_mem=512, # emulation max mem in MB **kwargs): """ Create an extended version of a Containernet network :param dc_emulation_max_cpu: max. CPU time used by containers in data centers :param kwargs: path through for Mininet parameters :return: """ # members self.dcs = {} self.ryu_process = None # always cleanup environment before we start the emulator self.killRyu() cleanup() # call original Docker.__init__ and setup default controller Containernet.__init__( self, switch=OVSKernelSwitch, controller=controller, **kwargs) # Ryu management if controller == RemoteController: # start Ryu controller self.startRyu(learning_switch=enable_learning) # add the specified controller self.addController('c0', controller=controller) # graph of the complete DC network self.DCNetwork_graph = nx.MultiDiGraph() # initialize pool of vlan tags to setup the SDN paths self.vlans = range(4096)[::-1] # link to Ryu REST_API ryu_ip = 'localhost' ryu_port = '8080' self.ryu_REST_api = 'http://{0}:{1}'.format(ryu_ip, ryu_port) self.RyuSession = requests.Session() # monitoring agent if monitor: self.monitor_agent = DCNetworkMonitor(self) else: self.monitor_agent = None # initialize resource model registrar self.rm_registrar = ResourceModelRegistrar( dc_emulation_max_cpu, dc_emulation_max_mem)
def httpTest( N=2 ): "Run pings and monitor multiple hosts using pmonitor" ## SET LOGGING AND CLEANUP PREVIOUS MININET STATE, IF ANY lg.setLogLevel('info') cleanup() ## INSTEAD OF RUNNING PYRETIC HUB, UNCOMMENT LINE ## TO SEE THAT THIS WORKS FINE WHEN RUNNING REFERENCE CONTROLLER # call('controller ptcp: &', shell=True) ## SET UP TOPOLOGY topo = LinearTopo( N ) ## (tcp parse) warning TCP data offset too long or too short # topo = SingleSwitchTopo( N ) ## SILENT STALL ## SET UP MININET INSTANCE AND START net = Mininet( topo, switch=OVSKernelSwitch, host=Host, controller=RemoteController ) net.start() print "Starting test..." ## GET THE HOST AND SERVER NAMES hosts = net.hosts client = hosts[ 0 ] server = hosts[ 1 ] ## DICTS FOR USE W/ PMONITOR spopens = {} cpopens = {} ## WARMUP SERVER spopens[server] = server.popen('python', '-m', 'SimpleHTTPServer', '80') sleep(1) ## CLIENT REQUEST cpopens[client] = client.popen('wget', '-O', '-', server.IP(), stdout=PIPE, stderr=STDOUT) ## MONITOR OUTPUT for h, line in pmonitor( cpopens, timeoutms=5000 ): if h and line: print '%s: %s' % ( h.name, line ), ## TO USE THE COMMAND LINE INTERFACE, BEFORE FINISHING, UNCOMMENT # CLI( net ) ## SHUTDOWN SERVER spopens[server].send_signal( SIGINT ) ## SHUTDOWN MININET net.stop()
def runTests(testDir, verbosity=1, dockeronly=False): "discover and run all tests in testDir" # ensure root and cleanup before starting tests ensureRoot() cleanup() # discover all tests in testDir testSuite = defaultTestLoader.discover(testDir) if dockeronly: testSuiteFiltered = [s for s in testSuite if "Docker" in str(s)] testSuite = TestSuite() testSuite.addTests(testSuiteFiltered) # run tests TextTestRunner(verbosity=verbosity).run(testSuite)
def runMininet(protocols, controller, topo, topo_arg, ovs_switch, pattern): # If no arguments passed, set the default values if protocols == None: protocols = "OpenFlow13" if controller == None: controller = ["127.0.0.1"] if topo == None: topo = "SwitchTopo" if topo_arg == None: topo_arg = [1] if ovs_switch == None: ovs_switch = "OVSSwitch" if pattern == None: pattern = "xscxx" # Create topology cur_topo = getattr(topology, topo)(*topo_arg) # Get switch type cur_switch = partial(getattr(switch, ovs_switch), protocols=protocols) # Prepare mininet net = None # Execute pattern delay = "" for c in pattern: if c == 's': # Create mininet object net = Mininet(switch=cur_switch, controller=None) net.buildFromTopo(cur_topo) # Create and add controllers for i, address in enumerate(controller): net.addController( RemoteController('c{0}'.format(i), address, 6653)) # Start connections to controllers net.start() elif c == 'c': if net != None: CLI(net) elif c == 'x': if net != None: net.stop() net = None else: cleanup() elif c.isdigit(): delay += c elif c == 'd': if delay == "": delay = "1" print("*** Waiting " + delay + " seconds") sleep(float(delay)) delay = ""
def reset(params): global net global is_running net.stop() is_running = False cleanup() # reinitialize mininet net = Mininet(topo=None, build=False, switch=OVSSwitch, controller=RemoteController, link=Link, host=Host) return format_results([{"msg": "Mininet was been reset"}])
def bwtest(cpuLimits, period_us=100000, seconds=10): """Example/test of link and CPU bandwidth limits cpu: cpu limit as fraction of overall CPU time""" topo = TreeTopo(depth=1, fanout=2) results = {} for sched in 'rt', 'cfs': info('*** Testing with', sched, 'bandwidth limiting\n') for cpu in cpuLimits: # cpu is the cpu fraction for all hosts, so we divide # it across two hosts host = custom(CPULimitedHost, sched=sched, period_us=period_us, cpu=.5 * cpu) try: net = Mininet(topo=topo, host=host, waitConnected=True) # pylint: disable=bare-except except: info('*** Skipping scheduler %s and cleaning up\n' % sched) cleanup() break net.start() net.pingAll() hosts = [net.getNodeByName(h) for h in topo.hosts()] client, server = hosts[0], hosts[-1] info('*** Starting iperf with %d%% of CPU allocated to hosts\n' % (100.0 * cpu)) # We measure at the server because it doesn't include # the client's buffer fill rate popen = server.popen('iperf -yc -s -p 5001') waitListening(client, server, 5001) # ignore empty result from waitListening/telnet popen.stdout.readline() client.cmd('iperf -yc -t %s -c %s' % (seconds, server.IP())) result = decode(popen.stdout.readline()).split(',') bps = float(result[-1]) popen.terminate() net.stop() updated = results.get(sched, []) updated += [(cpu, bps)] results[sched] = updated return results
def perfTest(): topo = TestTopo() net = Mininet(topo=topo, controller=lambda name: RemoteController(name, ip='127.0.0.1'), link=TCLink) net.start() print "Dumping connections" dumpNodeConnections(net.hosts) for host in net.hosts: host.cmdPrint('../../tiny-lldpd/tlldpd -d -i 1') CLI(net) for host in net.hosts: host.cmdPrint('killall tlldpd') net.stop() cleanup()
def bwtest( cpuLimits, period_us=100000, seconds=10 ): """Example/test of link and CPU bandwidth limits cpu: cpu limit as fraction of overall CPU time""" topo = TreeTopo( depth=1, fanout=2 ) results = {} for sched in 'rt', 'cfs': info( '*** Testing with', sched, 'bandwidth limiting\n' ) for cpu in cpuLimits: # cpu is the cpu fraction for all hosts, so we divide # it across two hosts host = custom( CPULimitedHost, sched=sched, period_us=period_us, cpu=.5*cpu ) try: net = Mininet( topo=topo, host=host ) # pylint: disable=bare-except except: info( '*** Skipping scheduler %s and cleaning up\n' % sched ) cleanup() break net.start() net.pingAll() hosts = [ net.getNodeByName( h ) for h in topo.hosts() ] client, server = hosts[ 0 ], hosts[ -1 ] info( '*** Starting iperf with %d%% of CPU allocated to hosts\n' % ( 100.0 * cpu ) ) # We measure at the server because it doesn't include # the client's buffer fill rate popen = server.popen( 'iperf -yc -s -p 5001' ) waitListening( client, server, 5001 ) # ignore empty result from waitListening/telnet popen.stdout.readline() client.cmd( 'iperf -yc -t %s -c %s' % ( seconds, server.IP() ) ) result = decode( popen.stdout.readline() ).split( ',' ) bps = float( result[ -1 ] ) popen.terminate() net.stop() updated = results.get( sched, [] ) updated += [ ( cpu, bps ) ] results[ sched ] = updated return results
def tearDown(self): print('->>>>>>> tear everything down ->>>>>>>>>>>>>>>') self.stopApi() # stop all flask threads self.stopNet() # stop some mininet and containernet stuff cleanup() # make sure that all pending docker containers are killed with open(os.devnull, 'w') as devnull: # kill a possibly running docker process that blocks the open ports subprocess.call("kill $(netstat -npl | grep '5000' | grep -o -e'[0-9]\+/docker' | grep -o -e '[0-9]\+')", stdout=devnull, stderr=devnull, shell=True) with open(os.devnull, 'w') as devnull: subprocess.call( "sudo docker rm -f $(sudo docker ps --filter 'label=com.containernet' -a -q)", stdout=devnull, stderr=devnull, shell=True)
def multiPath(): net = fatTree() info('*** Starting network\n') net.start() #info('*** Performing basic tests\n') #perfTest(net) #info("*** Configuring Flows") #flClient = StaticFlowPusher("127.0.0.1") info('*** Running CLI\n') CLI(net) info('*** Stopping network') net.stop() cleanup()
def cleanup(level='info'): """Cleanup all possible junk that we may have started.""" log.setLogLevel(level) # Standard mininet cleanup mnclean.cleanup() # Cleanup any leftover daemon patterns = [] for d in daemons.__all__: obj = getattr(daemons, d) killp = getattr(obj, 'KILL_PATTERNS', None) if not killp: continue if not is_container(killp): killp = [killp] patterns.extend(killp) log.info('*** Cleaning up daemons:\n') for pattern in patterns: mnclean.killprocs('"%s"' % pattern) log.info('\n')
def cleanup(): """Cleanup all possible junk that we may have started.""" log.setLogLevel('info') # Standard mininet cleanup mnclean.cleanup() # Cleanup any leftover daemon patterns = [] for d in daemons.__all__: obj = getattr(daemons, d) killp = getattr(obj, 'KILL_PATTERNS', None) if not killp: continue if not is_container(killp): killp = [killp] patterns.extend(killp) log.info('*** Cleaning up daemons:\n') for pattern in patterns: mnclean.killprocs('"%s"' % pattern) log.info('\n')
def cleanup(level: str = 'info'): """Cleanup all possible junk that we may have started.""" log.setLogLevel(level) # Standard mininet cleanup mnclean.cleanup() # Cleanup any leftover daemon patterns = [] # type: List[str] for package in [router_daemons, host_daemons]: for d in package.__all__: obj = getattr(package, d, None) killp = getattr(obj, 'KILL_PATTERNS', None) if not killp: continue if not is_container(killp): killp = [killp] patterns.extend(killp) log.info('*** Cleaning up daemons:\n') killprocs(['"^%s"' % p for p in patterns]) log.info('\n')
def main(): lg.setLogLevel('debug') context = Context() if not get_cmd_line_args(context): return print 'Starting with [%s] switches' % context.switch_number # Create the topology with the context args taken from the cmd-line myTopo = create_topology(context) # The network myNet = Mininet(myTopo, switch=MultiSwitch) # The SDN-remote_controller connection mySDNController = myNet.addController( context.remote_controller_name, customClass({'remote': RemoteController}, context.remote_controller_args)) myLocalController = myNet.addController('c1', controller=OVSController) # myLocalController.start() dump_hosts(myNet) # This will output the nodes port connections to MININET_NET_FILE dumpNodeConnections(myNet.values()) # This will output the nodes port connections to MININET_DUMP_FILE dumpNodes(myNet.values()) # start_gateways(myNet) #start_switches(context, myNet, mySDNController, myLocalController) myNet.start() # Insert ovs-ofctl rules print 'Inserting flows into the switches...' init_flows(context) # Start the command line CLI(myNet) cleanup()
def setup(bandwidth=100, delay=100): # Clean up existing mininet print "Cleaning up mininet..." cleanup() # Set congestion control to cubic (It is default congestion control algorithm) os.system("sysctl -w net.ipv4.tcp_congestion_control=cubic > /dev/null") # Timeout modifiers, throw it all away os.system("sysctl -w net.ipv4.tcp_retries1=100 > /dev/null") os.system("sysctl -w net.ipv4.tcp_retries2=100 > /dev/null") os.system("sysctl -w net.ipv4.tcp_frto=100 > /dev/null") os.system("sysctl -w net.ipv4.tcp_frto_response=100 > /dev/null") # Setup network topology print "Starting network..." topo = MininetTolpology(bandwidth=bandwidth, delay=delay / 4.0) net = Mininet(topo=topo, host=CPULimitedHost, link=TCLink) net.start() return net
def setup(bandwidth=100, rtt=100): # Clean up existing mininet print "Cleaning up mininet..." cleanup() # Set congestion control to cubic (should be default) os.system("sysctl -w net.ipv4.tcp_congestion_control=cubic > /dev/null") # Timeout modifiers os.system("sysctl -w net.ipv4.tcp_retries1=100 > /dev/null") os.system("sysctl -w net.ipv4.tcp_retries2=100 > /dev/null") os.system("sysctl -w net.ipv4.tcp_frto=100 > /dev/null") os.system("sysctl -w net.ipv4.tcp_frto_response=100 > /dev/null") # Setup network topology print "Starting network..." topo = SimpleDCTopo(bandwidth=bandwidth, delay=rtt / 4.0) net = Mininet(topo=topo, host=CPULimitedHost, link=TCLink) net.start() return net
def main(): lg.setLogLevel('info') context = Context() if not get_cmd_line_args(context): return print 'Starting with [%s] switches' % context.switch_number # Create the topology with the context args taken from the cmd-line myTopo = create_topology(context) # The network myNet = Mininet(myTopo) # The SDN-remote_controller connection mySDNController = myNet.addController( context.remote_controller_name, customConstructor({'remote': RemoteController}, context.remote_controller_args)) myLocalController = myNet.addController('c1', controller=OVSController) myLocalController.start() dump_hosts(myNet) # This will output the nodes port connections to MININET_NET_FILE dumpNodeConnections(myNet.values()) # This will output the nodes port connections to MININET_DUMP_FILE dumpNodes(myNet.values()) # start_gateways(myNet) start_switches(context, myNet, mySDNController, myLocalController) # Insert ovs-ofctl rules print 'Inserting flows into the switches...' init_flows(context) # Start the command line CLI(myNet) cleanup()
def runTest(file_name, controller, tdf, size, set_cpu, set_bw, set_delay="50us"): lg.setLogLevel('info') """in fact, Controller and Remotecontroller have no difference all we need to do is start or not start POX in another shell""" if controller == "POX": controller = partial(RemoteController, ip='127.0.0.1', port=6633) else: controller = DefaultController link = partial(TCLink, bw=set_bw, delay=set_delay) """config host's cpu share and time dilation factor""" host = custom(CPULimitedHost, sched='cfs', period_us=100000, cpu=set_cpu, tdf=tdf) """with w option, it automatically overwrite everytime""" data_file = open('%s.log' % file_name, 'w') print "Results are written to %s.log file" % file_name data_file.write("********* Server String Topowith TDF = %d *********\n" % tdf) if tdf == 1: data_file.write("RTT\tSwitchCount\tAvg\tStd\tTime\n") else: data_file.write("SwitchCount\tAvg\tStd\tTime\n") data_file.flush() print "********* Running stringBandwidthTest *********", size avg, std = stringBandwidthTest(host, controller, link, size, tdf, data_file) cleanup() return avg, std
def runMPI(): # Create network topo = TestTopo() net = Mininet( topo=topo, controller=lambda name: RemoteController(name, ip='127.0.0.1'), link=TCLink) # net = Mininet(topo=topo, controller=OVSController, link=TCLink) net.start() for host in net.hosts: host.cmd('../../tiny-lldpd/tlldpd -d -i 1') sleep(5) # Launch sshd on each hosts and output host IPs to machinefile pids = [] f = open('./machines', 'w') for h in net.hosts: h.cmd('/usr/sbin/sshd -D -o UseDNS=no -u0 &') pid = int(h.cmd('echo $!')) pids.append(pid) f.write('%s\n' % h.IP()) f.close() # Launch MPI application print "Starting MPI application:" print "----------------------------------------" net.hosts[0].cmdPrint( 'mpirun --machinefile ./machines --mca coll_tuned_priority 100 --mca coll_tuned_allreduce_algorithm 3 --mca coll_tuned_use_dynamic_rules 1 --mca coll_base_verbose 1 ./mpitest' ) print "----------------------------------------" print "MPI application finished." for pid in pids: h.cmd('kill -9 %s' % pid) net.hosts[0].cmd('killall -9 tlldpd') net.stop() cleanup()
def example(): setLogLevel('debug') cleanup() net = Containernet(controller=Controller) net.addController('c0') ftp = net.addDocker('ftp', cls=Vsftpd, ip='10.10.10.1/24') h1 = net.addHost('h1', ip='10.10.10.2/24') s1 = net.addSwitch('s1') net.addLink(h1, s1) net.addLink(ftp, s1) net.start() # Add test:test to users add_user(ftp, "test", "test") CLI(net) net.stop()
def tearDown(self): time.sleep(2) print('->>>>>>> tear everything down ->>>>>>>>>>>>>>>') self.stopApi() # stop all flask threads self.stopNet() # stop some mininet and containernet stuff cleanup() # make sure that all pending docker containers are killed # kill a possibly running docker process that blocks the open ports with open(os.devnull, 'w') as devnull: subprocess.call( "kill $(netstat -npl | grep '15000' | grep -o -e'[0-9]\+/docker' | grep -o -e '[0-9]\+')", stdout=devnull, stderr=devnull, shell=True) with open(os.devnull, 'w') as devnull: subprocess.call( "sudo docker rm -f $(sudo docker ps --filter 'label=com.containernet' -a -q)", stdout=devnull, stderr=devnull, shell=True) time.sleep(2)
def runMPI(): # Create network topo = TestTopo() net = Mininet( topo=topo, controller=lambda name: RemoteController(name, ip='127.0.0.1'), link=TCLink) # net = Mininet(topo=topo, controller=OVSController, link=TCLink) net.start() print "Dumping host connections" dumpNodeConnections(net.hosts) for host in net.hosts: host.cmdPrint('../../tiny-lldpd/tlldpd -d -i 1') sleep(5) print "Testing network connectivity" net.pingAll() # Launch sshd on each hosts and output host IPs to machinefile f = open('./machines', 'w') for h in net.hosts: h.cmd('/usr/sbin/sshd -o UseDNS=no -u0') f.write('%s\n' % h.IP()) f.close() # Launch MPI application print "Starting MPI application:" print "----------------------------------------" net.hosts[0].cmdPrint('mpirun --machinefile ./machines ./mpitest') print "----------------------------------------" print "MPI application finished." net.hosts[0].cmdPrint('sudo killall -9 tlldpd') net.stop() cleanup()
def __init__(self, seed=None): cleanup() config = ConfigParser.ConfigParser() config2 = ConfigParser.ConfigParser() config.read(['./config']) config2.read(['./repo_subnets']) self.config = config self.config2 = config2 self.namespace = [0, 0] ip = self.config.get('main', 'Ip') if seed == None or 'None' in seed: self.seed = random.randint(1, 10000) else: self.seed = seed print ' Seed = %s' % self.seed self.create_topo() controller = RemoteController('c1', ip=ip, port=6633) self.net = Mininet(topo=self.topo, link=TCLink, controller=controller)
def main(): cleanup() topo = ExampleTopo() intf = custom(TCIntf, bw=100) net = Mininet(topo=topo, intf=intf, controller=None) info("*** Starting topology\n") net.start() info("*** Starting minigenerator\n") minigen = Minigenerator(net=net) minigen.start() MiniGeneratorCLI(minigenerator=minigen, mininet=net) #CLI(mininet=net) info("*** Stoping minigen and network\n") minigen.stop() net.stop()
def example(): from mininet.log import setLogLevel from mininet.clean import cleanup from mininet.net import Containernet from mininet.cli import CLI setLogLevel('debug') cleanup() net = Containernet(controller=None) base = net.addDocker('base', cls=Base) h1 = net.addHost('h1', ip='10.10.10.2/24') s1 = net.addSwitch('s1') net.addLink(h1, s1) net.addLink(base, s1) net.start() CLI(net) net.stop()
def main(): # Parse command-line arguments. parse() # Validate xaxis and yaxis input values. if args.xmin < -1 or args.xmax < -1 or args.ymin < -1 or args.ymax < -1: print "Invalid values entered for axis limits. View help using -h." return xlimits = (args.xmin, args.xmax) ylimits = (args.ymin, args.ymax) ch = ConfigHandler(args.input, args.output) # If there is an exception in config parsing, ch.config will be None. if not ch.config: print "Error while reading config; exiting...\n" return # Simulate network. # We simulate the network only to access the required configurations such as nodes, links, and paths from underlying Mininet object. # However, we don't start the network or run tests on it. network = NetworkSimulator(ch) # Obtain details on flows, links, and RTT. (C, F, flowInfo) = getG2Inputs(ch, network) # Process iperf output and generate results. rg = ResultGenerator(ch, C, F, flowInfo) iperfResults = rg.parseIperfOutput() # Generate throughput plots using specified axis range. # Plot throughput of unique flows with custom axis range. numPlots = args.num_unique_plots rg.plotUniqueInstances(iperfResults, numPlots, xlimits, ylimits) # Plot average throughput of unique flows with custom axis range. rg.plotAvgFlows(iperfResults, xlimits, ylimits) # Clean Mininet. cleanup()
def runMPI(): # Create network topo = TestTopo() net = Mininet(topo=topo, controller=lambda name: RemoteController(name, ip='127.0.0.1'), link=TCLink) # net = Mininet(topo=topo, controller=OVSController, link=TCLink) net.start() print "Dumping host connections" dumpNodeConnections(net.hosts) for host in net.hosts: host.cmdPrint('../../tiny-lldpd/tlldpd -d -i 1') sleep(5) print "Testing network connectivity" net.pingAll() # Launch sshd on each hosts and output host IPs to machinefile f = open('./machines', 'w') for h in net.hosts: h.cmd('/usr/sbin/sshd -o UseDNS=no -u0') f.write('%s\n' % h.IP()) f.close() # Launch MPI application print "Starting MPI application:" print "----------------------------------------" net.hosts[0].cmdPrint('mpirun --machinefile ./machines ./mpitest'); print "----------------------------------------" print "MPI application finished." net.hosts[0].cmdPrint('sudo killall -9 tlldpd') net.stop() cleanup()
def start(self): cleanup() self.net = Mininet(topo=self.topo, switch=self.switchClass, controller=self.controllers[0]) # if there are multiple controllers, let's append the rest of the controllers itercrtls = iter(self.controllers) next(itercrtls) for ctrl in itercrtls: self.net.addController(ctrl) if 'interface' not in self.props or self.props['interface'] is None: self.props['interface'] = [] for interface in self.props['interface']: name = interface['name'] print "adding interface {} to switch".format( name, interface['switch']) self.interfaces[name] = Intf( name, node=self.net.nameToNode[interface['switch']]) self.net.start()
def stop(self): "Stop the controller(s), switches and hosts" info('*** Stopping %i controllers\n' % len(self.controllers)) for controller in self.controllers: info(controller.name + ' ') controller.stop() info('\n') if self.terms: info('*** Stopping %i terms\n' % len(self.terms)) self.stopXterms() info('*** Stopping %i links\n' % len(self.links)) for link in self.links: info('.') link.stop() info('\n') info('*** Stopping %i switches\n' % len(self.switches)) stopped = {} for swclass, switches in groupby(sorted(self.switches, key=type), type): switches = tuple(switches) if hasattr(swclass, 'batchShutdown'): success = swclass.batchShutdown(switches) stopped.update({s: s for s in success}) for switch in self.switches: info(switch.name + ' ') if switch not in stopped: switch.stop() switch.terminate() info('\n') info('*** Stopping %i hosts\n' % len(self.hosts)) for host in self.hosts: info(host.name + ' ') host.terminate() info('*** Clean all interfaces\n') cleanup() info('\n*** Done\n')
def perfTest(): topo = TestTopo() net = Mininet( topo=topo, controller=lambda name: RemoteController(name, ip='127.0.0.1'), link=TCLink) net.start() print "Dumping connections" dumpNodeConnections(net.hosts) print "Launching LLDP daemons" for host in net.hosts: host.cmd('../../tiny-lldpd/tlldpd -d -i 1') sleep(3) net.pingAll() net.get('h3').cmd('iperf -sD') net.get('h4').cmd('iperf -sD') net.get('h1').cmd('iperf -c %s > /tmp/h1.txt &' % net.get('h3').IP()) net.get('h2').cmd('sleep 1; iperf -c %s > /tmp/h2.txt &' % net.get('h4').IP()) net.get('h1').cmd('wait $!') net.get('h2').cmd('wait $!') net.get('h1').cmdPrint("awk 'NR == 7 {print $7 $8}' /tmp/h1.txt") net.get('h2').cmdPrint("awk 'NR == 7 {print $7 $8}' /tmp/h2.txt") net.hosts[0].cmd('killall -9 tlldpd') net.hosts[0].cmd('killall -9 iperf') net.stop() cleanup()
def simulation(): # Cleanup any leftovers from previous mininet runs cleanup() topo = OneSwitchTopo() net = Mininet(topo=topo, host=CPULimitedHost, link=TCLink) net.start() net.pingAll() # Start bitcoind for every host start_btc_server(net) time.sleep(1) # Connect all nodes btc_server_add_node(net) time.sleep(1) CLI(net) # Stop bitcoind for every host stop_btc_server(net) net.stop()
def run(): ''' Method used to configure network ''' # Create network net = Mininet(topo=SimpleTopology(4), controller=FloodlightController(name='floodlight', ip=get_ip()), autoSetMacs=True) # Add NAT connectivity net.addNAT().configDefault() # Start Network net.start() nat = net.get('nat0') print "*** NAT with mac address %s and ip address %s." % (nat.MAC(), nat.IP()) # Deploy interactive client CLI(net) # Shutdown network net.stop() # Cleanup cleanup()
def runTest(file_name, controller, tdf, size, set_cpu, set_bw, set_delay="10us"): lg.setLogLevel( 'info' ) if controller == "POX": controller = partial( RemoteController, ip = '127.0.0.1', port=6633 ) else: controller = DefaultController link = partial( TCLink, bw=set_bw, delay=set_delay ) """config host's cpu share and time dilation factor""" host = custom(CPULimitedHost, inNamespace=True, sched='cfs', period_us=100000, cpu=set_cpu) """with w option, it automatically overwrite everytime""" data_file = open('%s.log' % file_name, 'w') print "Results are written to %s.log file" % file_name data_file.write("********* Running stringBandwidthTest *********\n") data_file.flush() # seems mininet cannot handle more than 640 switches print "******* Running with %d switches, TDF = %d *******" % (size, tdf) client_avg, client_stdev = stringBandwidthTest(host, controller, link, size, tdf, data_file) cleanup() return client_avg, client_stdev
switches = [self.addSwitch('s%d' % (n + 1) ) for n in range(2)] for i in range(4): self.addLink(hosts[i],switches[0]) self.addLink(hosts[4],switches[1]) self.addLink(switches[0],switches[1]) class Simulator: def __init__(self): global server,port topo = Topology() self.mn = Mininet( topo=topo, controller=partial(RemoteController, ip=server, port=port) ) def cli(self): CLI(self.mn) def start(self): self.mn.start() def stop(self): self.mn.stop() if __name__ == '__main__': setLogLevel('info') cleanup() simulator = Simulator() simulator.start() simulator.cli() simulator.stop()
from mininet.clean import cleanup from mininet.link import TCLink from mininet.node import UserSwitch, OVSKernelSwitch, OVSSwitch, IVSSwitch json_data = read_json('result.json') hosts = parse_hosts(json_data) switches = parse_switches(json_data) links = parse_links(json_data) class MultiCastTopology(Topo): def __init__(self): Topo.__init__(self) def build(self): for host in hosts: h = self.addHost(host.id, ip=host.ip, mac=host.mac) for switch in switches: s = self.addSwitch(switch.id, dpid=str(switch.dpid)) for link in links: l = self.addLink(link.node1, link.node2, port1=link.port1, port2=link.port2) topo = MultiCastTopology() net = Mininet( topo=topo, controller=lambda name: RemoteController(name, ip='127.0.0.1', protocol='tcp', port = 6633), link=TCLink ) net.start() CLI(net) cleanup()
def mininet_cleanup(): del controllers[:] switches.clear() links.clear() cleanup() return {'status': 'ok'}
def tearDown( self ): "Clean up if necessary" # satisfy pylint assert self if sys.exc_info != ( None, None, None ): cleanup()
def begin( self ): "Create and run mininet." if self.options.clean: cleanup() exit() start = time.time() #navy #topo = buildTopo( TOPOS, self.options.topo ) topo = MyTopo() switch = customConstructor( SWITCHES, self.options.switch ) host = customConstructor( HOSTS, self.options.host ) controller = lambda name: RemoteController( name,ip='10.211.55.2',port=int('6633') ) link = customConstructor( LINKS, self.options.link ) if self.validate: self.validate( self.options ) inNamespace = self.options.innamespace #navy #Net = MininetWithControlNet if inNamespace else Mininet Net = mininet.services.wrpMininet ipBase = self.options.ipbase xterms = self.options.xterms mac = self.options.mac arp = self.options.arp pin = self.options.pin listenPort = None if not self.options.nolistenport: listenPort = self.options.listenport intfName = 'eth1' info( '*** Checking', intfName, '\n' ) checkIntf( intfName ) mn = Net( topo=topo, switch=switch, host=host, controller=controller, link=link, ipBase=ipBase, inNamespace=inNamespace, xterms=xterms, autoSetMacs=mac, autoStaticArp=arp, autoPinCpus=pin, #navy # listenPort=listenPort ) listenPort=listenPort, services = True ) for sw in mn.switches: if sw.name in sw_ext_intf: info( '*** Adding hardware interface', intfName, 'to switch', sw.name, '\n' ) _intf = Intf( intfName, node=sw ) info( '*** Note: you may need to reconfigure the interfaces for ' 'the Mininet hosts:\n', mn.hosts, '\n' ) #navy #Add services here #----------------- if self.options.pre: CLI( mn, script=self.options.pre ) test = self.options.test test = ALTSPELLING.get( test, test ) mn.start() if test == 'none': pass elif test == 'all': mn.start() mn.ping() mn.iperf() elif test == 'cli': CLI( mn ) elif test != 'build': getattr( mn, test )() if self.options.post: CLI( mn, script=self.options.post ) mn.stop() elapsed = float( time.time() - start ) info( 'completed in %0.3f seconds\n' % elapsed )
def stringBandwidthTest(host_class, controller_class, link_class, size, tdf, data_file): "Check bandwidth at various lengths along a switch chain." topo_class = StringTestTopo(size) net = Mininet(topo=topo_class, host=host_class, switch=OVSKernelSwitch, controller=controller_class, waitConnected=False, link=link_class) net.start() if tdf != 1: net.dilateEmulation(tdf) print "*** testing basic connectivity\n" src, dst = net.hosts num_pings = 3 for i in irange(1, num_pings): ping_result = list(net.pingFull( [ src, dst ] )) # ping_result=[(host1), (host2)] # host = (src, dst, data) # data = (#sent, #received, rttmin, rttavg, rttmax, rttdev) print "Ping avg rtt = %s\n" % ping_result[0][2][3] rttavg = ping_result[0][2][3] data_file.write( "RTT Avg = %s ms\n" % rttavg) print "*** testing bandwidth\n" num_rounds = 2 client_history = [] time = 10 for i in irange(1, num_rounds): net.showDilation() bandwidth = net.iperf( [src, dst], l4Type = 'TCP', fmt = 'm', seconds=time, clifile=data_file, serfile=data_file ) # bandwidth = net.iperf( [src, dst], l4Type = 'UDP', # fmt = 'm', seconds=time, # clifile=data_file, serfile=data_file ) flush() net.showDilation() serout = bandwidth[0] cliout = bandwidth[1] if len(serout) > 0 and len(cliout) > 0: serDataStr, unit = serout.split(" ") serData = float(serDataStr) cliDataStr, unit = cliout.split(" ") cliData = float(cliDataStr) client_history.append(cliData) data_file.write("%s\t%f\t%s\t%s\n" % (size, tdf, serData, cliData)) client_mean = numpy.mean(client_history) client_stdev = numpy.std(client_history) data_file.write( "Avg Throughtput = %f\n" % client_mean ) data_file.write( "STD Throughput = %f\n" % client_stdev ) print "AVG = %f " % client_mean print "STD = %f " % client_stdev data_file.write('\n\n') # CLI(net) net.stop() cleanup() return client_mean, client_stdev
def tearDown( self ): # kill the ssh process sh( "ps aux | grep 'ssh.*Banner' | awk '{ print $2 }' | xargs kill" ) cleanup() # remove public key pair sh( 'rm -rf /tmp/ssh' )
def addFailure( self, test, err ): super( MininetTestResult, self ).addFailure( test, err ) cleanup()
def tearDown(): "Clean up if necessary" if sys.exc_info != ( None, None, None ): cleanup()
def __init__(self, controller=RemoteController, monitor=False, enable_learning=False, # learning switch behavior of the default ovs switches icw Ryu controller can be turned off/on, needed for E-LAN functionality dc_emulation_max_cpu=1.0, # fraction of overall CPU time for emulation dc_emulation_max_mem=512, # emulation max mem in MB **kwargs): """ Create an extended version of a Containernet network :param dc_emulation_max_cpu: max. CPU time used by containers in data centers :param kwargs: path through for Mininet parameters :return: """ # members self.dcs = {} self.ryu_process = None #list of deployed nsds.E_Lines and E_LANs (uploaded from the dummy gatekeeper) self.deployed_nsds = [] self.deployed_elines = [] self.deployed_elans = [] self.vlan_dict = {} # flag to indicate if the topology has been stopped (e.g. by api call) self.exit = False # always cleanup environment before we start the emulator self.killRyu() cleanup() # call original Docker.__init__ and setup default controller Containernet.__init__( self, switch=OVSKernelSwitch, controller=controller, **kwargs) # default switch configuration enable_ryu_learning = False if enable_learning : self.failMode = 'standalone' enable_ryu_learning = True else: self.failMode = 'secure' # Ryu management if controller == RemoteController: # start Ryu controller self.startRyu(learning_switch=enable_ryu_learning) # add the specified controller self.addController('c0', controller=controller) # graph of the complete DC network self.DCNetwork_graph = nx.MultiDiGraph() # initialize pool of vlan tags to setup the SDN paths self.vlans = range(1, 4095)[::-1] # link to Ryu REST_API ryu_ip = 'localhost' ryu_port = '8080' self.ryu_REST_api = 'http://{0}:{1}'.format(ryu_ip, ryu_port) self.RyuSession = requests.Session() # monitoring agent if monitor: self.monitor_agent = DCNetworkMonitor(self) else: self.monitor_agent = None # initialize resource model registrar self.rm_registrar = ResourceModelRegistrar( dc_emulation_max_cpu, dc_emulation_max_mem) self.cpu_period = CPU_PERIOD
def addError( self,test, err ): super( MininetTestResult, self ).addError( test, err ) cleanup()