def initialize_settings(): # Tell mininet to print useful information lg.setLogLevel('info') # cleanup mininet settings ramained uncleaned from previous runs os.system('sudo mn -c > /dev/null 2>&1') # cleanup transferred files from previous runs os.system('sudo rm -f /home/mininet/*.rcv > /dev/null 2>&1')
def main(): lg.setLogLevel('info') net = Mininet(SingleSwitchTopo(k=2)) net.start() h1 = net.get('h1') print "The ip address of client is " + str(h1.IP()) client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) client_socket.sendto("hello world", (options.ip, options.port)) server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) print "Server IP address is " + str(h1.IP()) server_socket.bind((h1.IP(), 12345)) f = open('foo.txt', 'w') while True: data, addr = server_socket.recvfrom(512) f.write("%s: %s\n" % (addr, data)) f.flush() p1 = h1.popen('python my_server.py -i %s &' % h1.IP()) h2 = net.get('h2') h2.cmd('python my_client.py -i %s -m "hello world"' % h1.IP()) #CLI( net ) p1.terminate() net.stop()
def main(): args = initParser() import json topo = json.load(args.topo) lg.setLogLevel(args.verbosity) net = interopNet(topo) net.start() for h in net.hosts: if not h.name.endswith('-c'): h.setDefaultRoute(h.params.get('defaultRoute')) if args.cli: CLI(net) if not args.notest: interopTest(net) for sw in net.switches: sw.printTableEntries() for sw in net.switches: # Assume everyone assigns the control-plane thread to a 'controller' attr sw_ctrl = getattr(sw, 'controller', None) if sw_ctrl is not None: sw_ctrl_join = getattr(sw_ctrl, 'join', None) if sw_ctrl_join is not None: lg.info('*** Stopping control-plane of %s\n' % sw.name) sw_ctrl_join() lg.info('*** Control-plane of %s stopped\n' % sw.name)
def runTest(file_name, controller, tdf, size, set_cpu, set_bw, set_delay="10us"): 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("********* 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
def main(): lg.setLogLevel('info') net = Mininet(SingleSwitchTopo(k=3)) net.start() h1 = net.get('h1') #server h2 = net.get('h2') #controller h3 = net.get('h3') #renderer h1.setIP('10.0.0.1') h2.setIP('10.0.0.2') h3.setIP('10.0.0.3') #p1 = h1.popen('python server.py &') # server opens up and works in background #p3 = h3.popen('python renderer.py &') # renderer opens up and works in background ### WARNING ### # order matters. Don't switch p1 and p3 CLI(net) #p1.terminate() #p3.terminate() net.stop()
def main(): lg.setLogLevel('info') #Setup network ctl = RemoteController("c1", ip='10.0.1.1', port=6633) network = Mininet(topo=TreeTopo(2, 2), controller=ctl, switch=OVSKernelSwitch, host=TestHost) network.start() #Topology detection delay sleep(30) for h in network.hosts: h.start1() for h in network.hosts: h.start2(network.hosts) sleep(300) network.pingAll() #Stop network for h in network.hosts: h.stop1() network.stop()
def __init__(self): self.options = None self.args = None self.parseArgs() lg.setLogLevel('info') self.runDemo()
def main(): lg.setLogLevel('info') net = Mininet(SingleSwitchTopo(k=5)) net.start() h1 = net.get('h1') h2 = net.get('h2') h3 = net.get('h3') p1 = h1.popen('python fun_probe.py --host %s --port %s' % (h1.IP(), '9030')) p2 = h2.popen('python fun_probe.py --host %s --port %s' % (h2.IP(), '9031')) p3 = h3.popen('python fun_collector.py --host %s --devicehosts %s ' % (h3.IP(), [h1.IP(), h2.IP()])) popens = {h1: p1, h2: p2, h3: p3} for h, line in popens: print h + " " + line for h, line in pmonitor(popens): print "Monitoring output..." if h: print '%s: %s' % (h.name, line) CLI(net)
def main(): # Set Log Level lg.setLogLevel('info') #lg.setLogLevel( 'error' ) #Read and parse configuration conf = get_config() if conf is None: send_output(None) return ctlip = list() ctlport = list() for i in range(0, len(conf['controllers'])): ctlip.append(conf['controllers'][i][0]) ctlport.append(conf['controllers'][i][1]) #Setup Network ts = time.time() topo = FixedTree(depth=1, fanout=2) network = Mininet(topo=topo, controller=None, switch=OVSKernelSwitch) for i in range(0, len(ctlip)): network.addController('c' + str(i + 1), controller=RemoteController, ip=ctlip[i], port=ctlport[i]) network.start() if ENABLE_STAT: lg.output('[timer] Setup network: %f sec.\n' % (time.time() - ts)) #Start Switch Monitor monitor_id = procmon.start(pname=SWITCH_PNAME, lg=lg) #Tests ts = time.time() hc = HostController(network, lg, conf) results = hc.do_test() if results == None: results = [False] if ENABLE_STAT: lg.output('[timer] Tests: %f sec.\n' % (time.time() - ts)) #Dump process monitor output stat_dict = procmon.stop(monitor_id, lg) # Pull Rules raw = [] for s in network.switches: raw.append(s.name + "," + s.dpctl("dump-flows")) #Write Output d = {"results": results, "rules": raw, "stat": stat_dict} send_output(d) lg.output(str(d) + "\n") # Cleanup Network ts = time.time() network.stop() if ENABLE_STAT: lg.output('[timer] Stop network: %f sec.\n' % (time.time() - ts))
def main(): "Parse argument" args = parse_args() if not os.path.exists(args.dir): os.makedirs(args.dir) "Create network topology, running experiments" lg.setLogLevel('info') start = time() cprint("*** Creating network topology:", "yellow") topo = MMwaveTestTopo(mmwavebw=args.bw) host = custom(CPULimitedHost, cpu=0.2) # 20% of system bandwidth (why?) link = custom(TCLink) net = Mininet(topo=topo, host=host, link=link) net.start() cprint("*** Dumping network connections:", "green") dumpNetConnections(net) cprint("*** Configure MPTCP", "red") configMPTCP(net, args) cprint("*** Testing connectivity", "blue") net.pingAll() cprint("*** Running experiment", "magenta") #CLI(net) run(net, args) end = time() cprint("*** Finishing experiment, took %.3f seconds" % (end - start), "yellow") net.stop()
def main(): lg.setLogLevel('info') supervisord = os.getenv("SUPERVISORD") assert supervisord topology = configparser.ConfigParser(interpolation=None) topology.read_file(open(NETWORKS_CONF), source=NETWORKS_CONF) topo = ScionTopo(topology) net = Mininet(topo=topo, controller=RemoteController, link=ScionTCLink) for host in net.hosts: host.cmd('export DISPATCHER_ID=%s' % host.name) host.cmd('ip route add 169.254.0.0/16 dev %s-0' % host.name) net.start() os.system('ip link add name mininet type dummy') os.system('ip addr add 169.254.0.1/16 dev mininet') os.system('ip addr add 169.254.0.2/16 dev mininet') os.system('ip addr add 169.254.0.3/16 dev mininet') for switch in net.switches: for k, v in topo.switch_map.items(): if v == switch.name: os.system('ip link set dev %s up' % switch.name) os.system('ip route add %s dev %s src 169.254.0.1' % (k, switch.name)) for host in net.hosts: elem_name = host.name.replace("_", "-") print("Starting supervisord on %s" % elem_name) host.cmd("%s -c gen/mininet/%s.conf" % (supervisord, elem_name)) CLI(net) net.stop() os.system('ip link delete mininet')
def _setup_logfile(self): os.makedirs(self.simulation_dir, exist_ok=True) if self.logfile: lg.addHandler(logging.FileHandler(self.logfile)) lg.setLogLevel(self.log_level) info('***** Logfile: {}\n'.format(self.logfile))
def start(ip="127.0.0.1", port=6633): ctrlr = lambda n: RemoteController(n, ip=ip, port=port, inNamespace=False) net = Mininet(switch=OVSSwitch, controller=ctrlr, autoStaticArp=False) c1 = net.addController('c1') topo_agraph = pgv.AGraph("topology.dot") for node in topo_agraph.nodes(): if node.startswith("s"): net.addSwitch(node, dpid=str(node.attr['dpid'])) else: net.addHost(node, mac=node.attr['mac'], ip=node.attr['ip'], defaultRoute="dev " + node + "-eth0 via " + node.attr['gateway']) for link in topo_agraph.edges(): (src_node, dst_node) = link net.addLink(src_node, dst_node, int(link.attr['src_port']), int(link.attr['dport'])) # Set up logging etc. lg.setLogLevel('info') lg.setLogLevel('output') # Start the network net.start() # Enter CLI mode output("Network ready\n") output("Press Ctrl-d or type exit to quit\n") CLI(net)
def start(ip="127.0.0.1",port=6633): ctrlr = lambda n: RemoteController(n, ip=ip, port=port, inNamespace=False) net = Mininet(switch=OVSSwitch, controller=ctrlr, autoStaticArp=False) c1 = net.addController('c1') topo = SingleSwitchTopo(2) net.buildFromTopo( topo ) # Set up logging etc. lg.setLogLevel('info') lg.setLogLevel('output') # Start the network net.start() # Fork off Frenetic process frenetic_proc = Popen(['/home/vagrant/src/frenetic/frenetic.native', 'http-controller']) # And fork off application app_proc = Popen(['/usr/bin/python2.7/python','/home/vagrant/manual/programmers_guide/code/quick_start/repeater.py']) output("Pingall returned "+str(net.pingAll())) frenetic_proc.kill() app_proc.kill()
def start(ip="127.0.0.1",port=6633): #def start(ip="127.0.0.1",port=6653): ctrlr = lambda n: RemoteController(n, ip=ip, port=port, inNamespace=False) net = Mininet(switch=OVSSwitch, controller=ctrlr, autoStaticArp=False) c1 = net.addController('c1') gates_agraph = pgv.AGraph("simplified_gates_topology.dot") for sw in gates_agraph.nodes(): net.addSwitch(sw, dpid = hex( int(sw.attr['dpid']) )[2:]) for link in gates_agraph.edges(): (src_switch, dst_switch) = link net.addLink(src_switch, dst_switch, int(link.attr['src_port']), int(link.attr['dport']) ) # Only one host and an Internet Router disguised as a host for now (because it's not part of the OF network) h0 = net.addHost('h0', cls=VLANHost, mac='d4:c9:ef:b2:1b:80', ip='128.253.154.1', vlan=1356) net.addLink("s_bdf", h0, 1, 0) # To test DHCP functionality, ucnomment this line and comment out the fixed IP line. Then when mininet # starts you issue: # mininet> h1 dhclient -v -d -1 h1-eth0.1356 # and make sure it gets its IP by going through all protocol steps. #h1 = net.addHost('h1', cls=VLANHost, mac='00:00:01:00:00:11', ip='0.0.0.0', vlan=1356) h1 = net.addHost('h1', cls=VLANHost, mac='00:00:01:00:00:11', ip='128.253.154.100', vlan=1356) net.addLink("s_f3a", h1, 32, 0) # h4{a,b,c} are wireless nodes supposedly hooked up to a dumb AP. You can't just hook them up # to the same mininet port. Y h4a = net.addHost('h4a', cls=VLANHost, mac='00:00:01:00:00:14', ip='128.253.154.104', vlan=1356) net.addLink("s_f3a", h4a, 33, 0) #net.addHost('h4b', cls=VLANHost, mac='00:00:01:00:00:14', ip='128.253.154.104', vlan=1356) #net.addHost('h4c', cls=VLANHost, mac='00:00:01:00:00:14', ip='128.253.154.104', vlan=1356) # h2 is a syslab PC h2 = net.addHost('h2', cls=VLANHost, mac='00:00:01:00:00:13', ip='128.253.154.102', vlan=1356) net.addLink("s_lab_r6", h2, 1, 0) # MAC spoofing attempt of h2 h3 = net.addHost('h3', cls=VLANHost, mac='00:00:01:00:00:13', ip='128.253.154.102', vlan=1356) net.addLink("s_lab_r6", h3, 2, 0) ###### Start of static Mininet epilogue ###### # Set up logging etc. lg.setLogLevel('info') lg.setLogLevel('output') # Start the network net.start() # Start the DHCP server on Internet Router. This will actually be a DHCP proxy in the real setup. #startDHCPserver( h0, gw='128.253.154.1', dns='8.8.8.8') # Enter CLI mode output("Network ready\n") output("Press Ctrl-d or type exit to quit\n") CLI(net)
def main(): lg.setLogLevel('info') topo = SingleSwitchTopo(6) #creating single switch topo with 6 nodes net = Mininet(topo=topo) # creating network with this topo net.start() h1 = net.get('h1') h2 = net.get('h2') h3 = net.get('h3') h4 = net.get('h4') h5 = net.get('h5') h6 = net.get('h6') popens = {} p1 = h1.popen('python3 ../tcp_thread/tcp_server.py %s & ' % h1.IP()) # popens[h1] = p1 # Running all the process in background to ensure that all the clients can request the server at the same time print( h2.cmd( 'python3 ../tcp_thread/tcp_client_non_persistent.py 1 %s |& tee -a output.log &' % h1.IP())) print( h3.cmd( 'python3 ../tcp_thread/tcp_client_non_persistent.py 2 %s |& tee -a output.log &' % h1.IP())) print( h4.cmd( 'python3 ../tcp_thread/tcp_client_non_persistent.py 3 %s |& tee -a output.log &' % h1.IP())) print( h5.cmd( 'python3 ../tcp_thread/tcp_client_non_persistent.py 4 %s |& tee -a output.log &' % h1.IP())) print( h6.cmd( 'python3 ../tcp_thread/tcp_client_non_persistent.py 5 %s |& tee -a output.log &' % h1.IP())) # for host, line in pmonitor( popens ): # if(host): # info( "<%s>: %s" % ( host.name, line ) ) sleep(5) p1.terminate() # To read the output of a process in the background h6.cmd('chmod 777 output.log') with open('output.log', 'r') as fin: print(fin.read()) # Removing the log file after showing it on stdout h6.cmd('sudo rm output.log') net.stop()
def __init__(self, tableIP, verbose=False): Mininet.__init__(self, build=False) self.tableIP = tableIP self.vsfs = [] self.rootnodes = [] self.verbose = verbose lg.setLogLevel('info') self.name_to_root_nodes = {} self.node_to_pw_data = defaultdict(list)
def start(loss): lg.setLogLevel('info') topo = NetTopo(loss=loss) net = Mininet(topo=topo, link=TCLink) conf(net) sshd(net) CLI(net) net.stop()
def setup( self ): "Setup and validate environment." # set logging verbosity if LEVELS[self.options.verbosity] > LEVELS['output']: print ( '*** WARNING: selected verbosity level (%s) will hide CLI ' 'output!\n' 'Please restart Mininet with -v [debug, info, output].' % self.options.verbosity ) lg.setLogLevel( self.options.verbosity )
def start(loss): lg.setLogLevel('info') topo = NetTopo(loss=loss) net = Mininet(topo = topo, controller = OVSController) conf(net) sshd(net) CLI(net) net.stop()
def start(controllers=[{'ip': '127.0.0.1', 'port': 6633}]): # Set up logging lg.setLogLevel('info') lg.setLogLevel('output') net = Mininet(switch=OVSSwitch, controller=None, autoStaticArp=True, listenPort=6634) for indx, ctl in enumerate(controllers): print("Adding controller", (1 + indx)) net.addController(('c%d' % indx), controller=RemoteController, ip=ctl['ip'], port=ctl['port']) # Add hosts h1 = net.addHost('h1') h2 = net.addHost('h2') #physical_intf = 'eth1' #Add switch that accepts only OpenFlow 1.0 s1 = net.addSwitch('s1', dpid='00:00:00:00:00:00:00:01', protocols='OpenFlow10') #Will accept both OpenFlow 1.0 and 1.3 #s2 = net.addSwitch('s2', dpid='00:00:00:00:00:00:00:02', protocols='OpenFlow10,OpenFlow13') #Will accept all protocols support by openvswitch #s3 = net.addSwitch('s2', dpid='00:00:00:00:00:00:00:02') # Connect physical interface #print "Adding physical hosts to mininet network..." #_intf1 = Intf( physical_intf, node=s1, port=1 ) net.addLink(h1, s1) net.addLink(h2, s1) # Start the network and prime other ARP caches net.start() net.staticArp() # Enter CLI mode output("Network ready\n") output("Getting results...") time.sleep(60) process_results() #output("Press Ctrl-d or type exit to quit\n") net.stop()
def run(graph_topo): # Run the Mininet CLI with a given topology lg.setLogLevel('info') mininet.clean.cleanup() net = make_mininet_instance(graph_topo) info('*** Starting network ***\n') net.start() info('*** Running CLI ***\n') CLI(net) info('*** Stopping network ***\n') net.stop()
def main(): args = parse_args() #setup args from parser setup(args) exp = importlib.import_module("."+args.open,package="experiment") lg.setLogLevel('info') topo = khalili2hosts() run_MPTCP(args,topo,exp,end) #launch Test
def pingall_test(folder, exe, topo=SingleSwitchTopo(4), custom_topo=None, custom_test=None, expect_pct=0): ip="127.0.0.1" port=6633 if not VERBOSE: lg.setLogLevel('critical') ctrlr = lambda n: RemoteController(n, ip=ip, port=port, inNamespace=False) net = Mininet(switch=OVSSwitch, controller=ctrlr, autoStaticArp=False,cleanup=True) c1 = net.addController('c1') if custom_topo: custom_topo.build(net) else: net.buildFromTopo(topo) # Start the network net.start() # Fork off Frenetic process devnull = None if VERBOSE else open(os.devnull, 'w') frenetic_proc = Popen( ['/home/vagrant/src/frenetic/frenetic.native', 'http-controller','--verbosity','debug'], stdout=devnull, stderr=devnull ) # Wait a few seconds for frenetic to initialize, otherwise time.sleep(5) # And fork off application app_proc = Popen( ['/usr/bin/python2.7',exe], stdout=devnull, stderr=devnull, cwd=CODE_ROOT+folder ) if custom_test: got_pct = int(custom_test(net)) else: got_pct = int(net.pingAll()) expected_msg = " expected "+str(expect_pct)+"% dropped got "+str(got_pct)+"% dropped" print exe + ("...ok" if expect_pct==got_pct else expected_msg) frenetic_proc.kill() app_proc.kill() # Ocassionally shutting down the network throws an error, which is superfluous because # the net is already shut down. So ignore. try: net.stop() except OSError: pass
def main(): lg.setLogLevel( 'info') topo = TreeCustomTopo() # Creating the given custom topology net = Mininet(topo=topo) net.start() #uncomment the required hosts S = net.get('S') S1 = net.get('S1') S2 = net.get('S2') H = net.get('H') I = net.get('I') J = net.get('J') K = net.get('K') # L = net.get('L') # M = net.get('M') # N = net.get('N') # O = net.get('O') # popens = {} p1 = S.popen('python3 ../tcp_thread/tcp_server.py %s & ' %S.IP()) p2 = S1.popen('python3 ../tcp_thread/tcp_server.py %s & ' %S1.IP()) p3 = S2.popen('python3 ../tcp_thread/tcp_server.py %s & ' %S2.IP()) # popens[S] = p1 # popens[S1] = p2 # popens[S2] = p3 # Ucomment the required command (H.cmd('python3 ../tcp_thread/tcp_client_non_persistent.py 1 %s |& tee -a output.log &' %S.IP())) (I.cmd('python3 ../tcp_thread/tcp_client_non_persistent.py 2 %s |& tee -a output.log &' %S.IP())) (J.cmd('python3 ../tcp_thread/tcp_client_non_persistent.py 3 %s |& tee -a output.log &' %S1.IP())) (K.cmd('python3 ../tcp_thread/tcp_client_non_persistent.py 4 %s |& tee -a output.log &' %S2.IP())) # (L.cmd('python3 ../tcp_thread/tcp_client_non_persistent.py 2 %s |& tee -a output.log &' %S.IP())) # (M.cmd('python3 ../tcp_thread/tcp_client_non_persistent.py 3 %s |& tee -a output.log &' %S1.IP())) # (N.cmd('python3 ../tcp_thread/tcp_client_non_persistent.py 4 %s |& tee -a output.log &' %S2.IP())) #(O.cmd('python3 ../tcp_thread/tcp_client_non_persistent.py 4 %s |& tee -a output.log &' %S.IP())) # for host, line in pmonitor( popens ): # if(host): # info( "<%s>: %s" % ( host.name, line ) ) sleep(5) S.cmd('chmod 777 output.log') with open('output.log', 'r') as fin: print(fin.read()) S.cmd('sudo rm output.log') p1.terminate() p2.terminate() p3.terminate() net.stop()
def start(ip="127.0.0.1", port=6633): ctrlr = lambda n: RemoteController( n, defaultIP=ip, port=port, inNamespace=False) net = Mininet(switch=UserSwitch, controller=ctrlr, intf=VLANIntf, autoStaticArp=True) c1 = net.addController('c1') ####### End of static Mininet prologue ###### eth1 = '00:00:00:00:00:01' eth2 = '00:00:00:00:00:02' ip1 = '10.0.0.1' ip2 = '10.0.0.2' # -- s2 -- # / \ # h1 - s1 s3 - h2 # \ / # -- s4 -- # Ports to host are numbered 1, then clockwise h1 = net.addHost('h1', mac=eth1, ip=ip1) h2 = net.addHost('h2', mac=eth2, ip=ip2) s1 = net.addSwitch('s1') s2 = net.addSwitch('s2') s3 = net.addSwitch('s3') s4 = net.addSwitch('s4') net.addLink(h1, s1, 0, 1) net.addLink(h2, s3, 0, 1) net.addLink(s1, s2, 2, 1) net.addLink(s2, s3, 2, 3) net.addLink(s3, s4, 2, 2) net.addLink(s4, s1, 1, 3) ###### Start of static Mininet epilogue ###### # Set up logging etc. lg.setLogLevel('info') lg.setLogLevel('output') # Start the network and prime other ARP caches net.start() h1.setDefaultRoute('h1-eth0') h2.setDefaultRoute('h2-eth0') # Enter CLI mode output("Network ready\n") output("Press Ctrl-d or type exit to quit\n") CLI(net) net.stop()
def main(argv): args = parse_args() lg.setLogLevel('info') "Create and run experiment" topo = MyTopo() net = Mininet(topo=topo, link=TCLink, controller=OVSController) net.start() Config(net, args) #dumpNodeConnections(net.hosts) net.stop()
def main(argv): args = parse_args() lg.setLogLevel('info') "Create and run experiment" topo = MyTopo() net = Mininet(topo=topo, link=TCLink, controller = OVSController) net.start() Config(net,args) #dumpNodeConnections(net.hosts) net.stop()
def main(): lg.setLogLevel('info') net = Mininet(SingleSwitchTopo(k=2)) net.start() h1 = net.get('h1') print("h1.ip: %s" % h1.IP()) h2 = net.get('h2') CLI(net) net.stop()
def start(ip="127.0.0.1",port=6633): ctrlr = lambda n: RemoteController(n, defaultIP=ip, port=port, inNamespace=False) net = Mininet(switch=UserSwitch, controller=ctrlr, intf=VLANIntf, autoStaticArp=True) c1 = net.addController('c1') ####### End of static Mininet prologue ###### eth1 = '00:00:00:00:00:01' eth2 = '00:00:00:00:00:02' ip1 = '10.0.0.1' ip2 = '10.0.0.2' # -- s2 -- # / \ # h1 - s1 s3 - h2 # \ / # -- s4 -- # Ports to host are numbered 1, then clockwise h1 = net.addHost('h1', mac=eth1, ip=ip1) h2 = net.addHost('h2', mac=eth2, ip=ip2) s1 = net.addSwitch('s1') s2 = net.addSwitch('s2') s3 = net.addSwitch('s3') s4 = net.addSwitch('s4') net.addLink(h1, s1, 0, 1) net.addLink(h2, s3, 0, 1) net.addLink(s1, s2, 2, 1) net.addLink(s2, s3, 2, 3) net.addLink(s3, s4, 2, 2) net.addLink(s4, s1, 1, 3) ###### Start of static Mininet epilogue ###### # Set up logging etc. lg.setLogLevel('info') lg.setLogLevel('output') # Start the network and prime other ARP caches net.start() h1.setDefaultRoute('h1-eth0') h2.setDefaultRoute('h2-eth0') # Enter CLI mode output("Network ready\n") output("Press Ctrl-d or type exit to quit\n") CLI(net) net.stop()
def __init__(self, verbose=False): self.checkPATHs() Mininet.__init__(self, build=False) self.cr_oshis = [] self.pe_oshis = [] self.ce_routers = [] self.ctrls = [] self.nodes_in_rn = [] self.node_to_data = defaultdict(list) self.node_to_node = {} self.node_to_default_via = {} self.coex = {} self.verbose = verbose lg.setLogLevel('info') self.vlls = [] self.node_to_pw_data = defaultdict(list) self.pws = [] self.cer_to_customer = {} self.customer_to_vtepallocator = {} self.vsfs = [] self.pe_cer_to_vsf = {} self.is_vs = False self.vss = [] self.vss_data = [] self.id_peo_to_vs = {} self.last_ipnet = IPv4Network(u'0.0.0.0/24') self.id_to_node = {} self.ip_to_mac = {} self.overall_info = {} self.mgmt = None root = Node( 'root', inNamespace=False ) root.cmd('/etc/init.d/network-manager stop') mylog("*** Stop Network Manager\n") self.cluster_to_ctrl = defaultdict(list) self.cluster_to_nodes = defaultdict(list) self.nodes_to_cluster = {}
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 __init__(self, verbose=False): self.checkPATHs() Mininet.__init__(self, build=False) self.cr_oshis = [] self.pe_oshis = [] self.ce_routers = [] self.ctrls = [] self.nodes_in_rn = [] self.node_to_data = defaultdict(list) self.node_to_node = {} self.node_to_default_via = {} self.coex = {} self.verbose = verbose lg.setLogLevel('info') self.vlls = [] self.node_to_pw_data = defaultdict(list) self.pws = [] self.cer_to_customer = {} self.customer_to_vtepallocator = {} self.vsfs = [] self.pe_cer_to_vsf = {} self.is_vs = False self.vss = [] self.vss_data = [] self.id_peo_to_vs = {} self.last_ipnet = IPv4Network(u'0.0.0.0/24') self.id_to_node = {} self.ip_to_mac = {} self.overall_info = {} self.mgmt = None root = Node('root', inNamespace=False) root.cmd('/etc/init.d/network-manager stop') mylog("*** Stop Network Manager\n") self.cluster_to_ctrl = defaultdict(list) self.cluster_to_nodes = defaultdict(list) self.nodes_to_cluster = {}
def main(): lg.setLogLevel("info") print "Setting-up a 1-switch linear topology" net = config_network() print "Starting experiment" h1 = net.get("h1") h2 = net.get("h2") print("Please wait until the experiment is complete...") CLI(net) net.stop()
def start(controllers=[{'ip':'127.0.0.1', 'port': 6633}]): # Set up logging lg.setLogLevel('info') lg.setLogLevel('output') net = Mininet(switch=OVSSwitch, controller=None, autoStaticArp=True, listenPort=6634) for indx, ctl in enumerate(controllers): print("Adding controller", (1+indx)) net.addController(('c%d' % indx), controller=RemoteController, ip=ctl['ip'], port=ctl['port']) # Add hosts h1 = net.addHost('h1') h2 = net.addHost('h2') #physical_intf = 'eth1' #Add switch that accepts only OpenFlow 1.0 s1 = net.addSwitch('s1', dpid='00:00:00:00:00:00:00:01', protocols='OpenFlow10') #Will accept both OpenFlow 1.0 and 1.3 #s2 = net.addSwitch('s2', dpid='00:00:00:00:00:00:00:02', protocols='OpenFlow10,OpenFlow13') #Will accept all protocols support by openvswitch #s3 = net.addSwitch('s2', dpid='00:00:00:00:00:00:00:02') # Connect physical interface #print "Adding physical hosts to mininet network..." #_intf1 = Intf( physical_intf, node=s1, port=1 ) net.addLink(h1, s1) net.addLink(h2, s1) # Start the network and prime other ARP caches net.start() net.staticArp() # Enter CLI mode output("Network ready\n") output("Getting results...") time.sleep(60) process_results() #output("Press Ctrl-d or type exit to quit\n") net.stop()
def test_jellyfish_hosts_reachable(self): """ Create a jellyfish network and check that all hosts can ping each other. """ lg.setLogLevel('info') # You can uncomment this to have mininet print out more debugging information jelly = jellyfish.graphs.jellyfish(16, 4, 1) mininet.clean.cleanup() net = jellyfish.mininet.make_mininet(jelly) net.start() net.waitConnected() percentage = net.pingAllFull() net.stop() self.assertEqual(percentage,0)
def main(): lg.setLogLevel('info') net = Mininet(SingleSwitchTopo(k=2)) net.start() h1 = net.get('h1') x1 = h1.popen('python testServer.py -i %s &' % h1.IP()) h2 = net.get('h2') h2.cmd('python testClient.py -i %s -m "test message"' % h1.IP()) CLI(net) x1.terminate() net.stop()
def main(): lg.setLogLevel('info') net = Mininet(SingleSwitchTopo(k=2)) net.start() h1 = net.get('h1') p1 = h1.popen('python server.py -i %s &' % h1.IP()) h2 = net.get('h2') h2.cmd('python client.py -i %s -m "hello world"' % h1.IP()) CLI(net) p1.terminate() net.stop()
def main(): lg.setLogLevel("info") print "Setting-up a 1-switch linear topology" net = config_network() print "Starting experiment" h1 = net.get("h1") #print h1.cmd( 'python3 send.py -f pcap/amostra27.pcap' ) #print ("Please wait until the experiment is complete...") CLI(net) net.stop()
def main(): lg.setLogLevel( 'info') c = lambda name: RemoteController(name, defaultIP='132.239.17.35') if 'fattree' in sys.argv: net = FatTreeNet(switch=OVSKernelSwitch, controller=c) elif 'linear' in sys.argv: net = LinearNet(switch=OVSKernelSwitch, controller=c) else: print >> sys.stderr, 'Specify either "fattree" or "linear" as the sole argument.' return net.start() CLI(net) net.stop()
def start_network(): ''' Start mininet network ''' lg.setLogLevel('info') topo = TreeTopo(1, options.hosts) net = Mininet(topo=topo, switch=OVSBridge, controller=None, waitConnected=True) switch = net['s1'] routes = ['10.0.0.0/24'] root = Node('root', inNamespace=False) interface = net.addLink(root, switch).intf1 root.setIP('10.123.123.1/32', intf=interface) net.start() for route in routes: root.cmd('route add -net {} dev {}'.format(route, interface)) return net
def go(cargs=None): global GOPTS lg.setLogLevel('output') parser = CommonParser('connectivity_test.py') parser.add_option('-p', '--num-passes', action="store",dest='passes', type='int', default=2, help="Number of passes through the network.") (options, args) = parser.parse_args(cargs) if options.remote_nox and options.nox_test: parser.error("Run reference NOX test without the -r option.") if (options.numhosts < 2 or options.numhosts > MAXHOSTS): parser.error("Need at least 2 hosts. Maximum of %s" % str(MAXHOSTS)) if not(options.remote_nox) and options.controller != '127.0.0.1:6633': parser.error("Specified a remote controller address, but -r remote NOX mode not specified.") if not(options.forwarding.lower() in validforwarding): parser.error("Please specify a valid forwarding policy for the experiment. hub | lsw | flw.") (ip,port) = check_controller(options.controller) if (ip,port) == (None,None): parser.error("Bad IP:Port specified for controller.") GOPTS = setFlags(dump_flows=options.dump_flows,nox_test=options.nox_test, remote_nox=options.remote_nox,flow_size=options.flow_size, debugp=options.debug,interrupt=options.interrupt,quiet=options.quiet, agg=options.agg,full_arp=options.arp,verify=options.verify) GOPTS['interrupt'] = options.interrupt interval = options.interval # QUIET mode trumps many options if GOPTS['quiet']: GOPTS['debug'] = False GOPTS['dump'] = False GOPTS['interrupt'] = False numpasses = 2 GOPTS['flowsize'] = 56 interval = 1 GOPTS['start'] = time.time() # Initialize and run init() retcode = start(options.numhosts, options.numswitches, options.st, ip, port, interval, options.forwarding.lower(), options.passes) return retcode
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 launch(topo = None, routing = None, mode = None): """ Args in format toponame,arg1,arg2,... """ print("mininet_stuffs") if not mode: mode = DEF_MODE # Instantiate a topo object from the passed-in file. if not topo: raise Exception("please specify topo and args on cmd line") else: t = buildTopo(topo, topos) r = getRouting(routing, t) core.registerNew(RipLController, t, r, mode) lg.setLogLevel('info') log.info("RipL-POX running with topo=%s." % topo)
def start(ip="127.0.0.1",port=6633): ctrlr = lambda n: RemoteController(n, ip=ip, port=port, inNamespace=False) net = Mininet(switch=OVSSwitch, controller=ctrlr, autoStaticArp=False) c1 = net.addController('c1') vmb = VlanMininetBuilder() vmb.build(net) # Set up logging etc. lg.setLogLevel('info') lg.setLogLevel('output') # Start the network net.start() # Enter CLI mode output("Network ready\n") output("Press Ctrl-d or type exit to quit\n") CLI(net) net.stop()
def __init__(self): # 15 Mbps bandwidth and 2 ms delay on each link #self.linkopts = dict(bw=15, delay='2ms', loss=0, use_htb=True) # disabled for testing self.linkopts = dict() self.numHostsPerSubnet = 2 self.options = None self.args = None self.subnetRootSwitch = None self.subnetRootSwitchBaseDpid = None self.subnetHostLastIP = {} self.globalHostCount = 0 self.globalPeerCount = 0 self.globalEdgeSwCount = 0 self.networksToLaunch = {} self.parseArgs() lg.setLogLevel('info') self.runDemo()
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 start(ip="127.0.0.1",port="6633",app="Netgaze"): net = Mininet(switch=ClickKernelSwitch) net.addController('c0') h1 = net.addHost('h1', ip='144.0.3.0') h2 = net.addHost('h2', ip='132.0.2.0') sw = net.addSwitch("click") sw.linkAs(h1, "h1") sw.linkAs(h2, "h2") net.start() net.staticArp() output("Network ready\n") time.sleep(3) # Enter CLI mode output("Press Ctrl-d or type exit to quit\n") lg.setLogLevel('info') CLI(net) lg.setLogLevel('output') net.stop()
def start(ip="127.0.0.1", port=6633): ctrlr = lambda n: RemoteController(n, defaultIP=ip, port=port, inNamespace=False) net = Mininet(switch=OVSSwitch, controller=ctrlr, host=VLANHost, autoStaticArp=True) c1 = net.addController("c1") ####### End of static Mininet prologue ###### h1 = net.addHost("h1", mac="00:00:00:00:00:01", ip="10.0.0.1") h2 = net.addHost("h2", mac="00:00:00:00:00:02", ip="10.0.0.2") h3 = net.addHost("h3", mac="00:00:00:00:00:03", ip="10.0.0.3") h4 = net.addHost("h4", mac="00:00:00:00:00:04", ip="10.0.0.4") s1 = net.addSwitch("s1") s10 = net.addSwitch("s10") s2 = net.addSwitch("s2") s9 = net.addSwitch("s9") net.addLink(h1, s1, 1, 1) net.addLink(h2, s1, 1, 2) net.addLink(h3, s2, 1, 1) net.addLink(h4, s2, 1, 2) net.addLink(s1, s9, 3, 1) net.addLink(s1, s10, 4, 1) net.addLink(s2, s9, 3, 2) net.addLink(s2, s10, 4, 2) ###### Start of static Mininet epilogue ###### # Set up logging etc. lg.setLogLevel("info") lg.setLogLevel("output") # Start the network and prime other ARP caches net.start() # Enter CLI mode output("Network ready\n") output("Press Ctrl-d or type exit to quit\n") CLI(net) net.stop()
def main(): lg.setLogLevel('info') if os.geteuid() != 0: lg.info("This script uses Mininet, and must be run as root.\n") sys.exit(1) topo = Wifi3GTopo(bw_wifi=args.bw_wifi, bw_3g=args.bw_3g, latency_wifi='%fms' % (args.latency_wifi,), latency_3g='%fms' % (args.latency_3g,), loss_wifi=args.loss_wifi, loss_3g=args.loss_3g, jitter_wifi='%fms' % (args.jitter_wifi,), jitter_3g='%fms' % (args.jitter_3g,)) # Compile client and server os.system('gcc server.c -o server') os.system('gcc client.c -o client') signal.signal(signal.SIGABRT, signal_cleanup) signal.signal(signal.SIGHUP, signal_cleanup) signal.signal(signal.SIGINT, signal_cleanup) signal.signal(signal.SIGTERM, signal_cleanup) types = [ 'wifi', '3g', 'mptcp', 'mptcp_noopt' ] trylimit = 3 for type in types: lg.info("Running %s\n" % type) success = False tries = 0 while not success and tries < trylimit: success = genericTest(topo, setup, run, end, type) tries += 1 if not success: lg.info("Test failed to run, retrying (%d tries remaining)\n" % (trylimit - tries,)) return 0
def start(ip="127.0.0.1",port=6633): ctrlr = lambda n: RemoteController(n, ip=ip, port=port, inNamespace=False) net = Mininet(switch=OVSSwitch, controller=ctrlr, autoStaticArp=False) c1 = net.addController('c1') topo_agraph = pgv.AGraph("topology.dot") for node in topo_agraph.nodes(): if node.startswith("s"): net.addSwitch(node, dpid=str(node.attr['dpid'])) else: net.addHost( node, mac=node.attr['mac'], ip=node.attr['ip'], defaultRoute="dev "+node+"-eth0 via "+node.attr['gateway'] ) for link in topo_agraph.edges(): (src_node, dst_node) = link net.addLink(src_node, dst_node, int(link.attr['src_port']), int(link.attr['dport']) ) # Set up logging etc. lg.setLogLevel('info') lg.setLogLevel('output') # Start the network net.start() # Enter CLI mode output("Network ready\n") output("Press Ctrl-d or type exit to quit\n") CLI(net)
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
addPrioQdisc(s1, "s1-eth2", bandwidth=bandwidth) # No delay do_fct_tests( net, flows_per_test, time_scale_factor=time_scale_factor, starter_data_function=starter_data_function, fig_file_name=fig_file_name, fct_offset=fct_offset, ) net.stop() if __name__ == "__main__": """Run prioirty queue correctness tests, and flow completion time tests.""" lg.setLogLevel("info") # Priority Queue Test - With direct host connections. # Run at 100Mbps with 2ms link delay because that appears to be stable # and reasonably fast, and use 2ms link delay for faster completion # of slow start. prioTest(100, "2ms", 1, 60) # Priority Queue Test - With switch. # Run at 100Mbps with 2ms link delay because that appears to be stable # and reasonably fast, and use 2ms link delay for faster completion # of slow start. prioSwitchTest(100, "2ms", 1, 60) # Flow Completion Time Tests rc3Test(RC3_fct_test_configs)
test_http(net) else: run_tcp_first(net, args.tcp_n) except: print "-"*80 print "Caught exception. Cleaning up..." print "-"*80 import traceback traceback.print_exc() raise finally: stop_all_iperf() net.stop() Popen("killall -9 top bwm-ng tcpdump cat mnexec; mn -c", shell=True, stderr=PIPE) Popen("pgrep -f webserver.py | xargs kill -9", shell=True).wait() stop_tcpprobe() end = time() cprint("Experiment took %s seconds\n" % (end - start), "yellow") if __name__ == '__main__': if args.debug: lg.setLogLevel('info') else: lg.setLogLevel('warning') try: main() except: pass
if not routes: routes = [ '172.16.0.0/24' ] connectToRootNS( network, switch, ip, routes ) for host in network.hosts: host.cmd( cmd + ' ' + opts + '&' ) print "*** Waiting for ssh daemons to start" for server in network.hosts: waitListening( server=server, port=22, timeout=5 ) print print "*** Hosts are running sshd at the following addresses:" print for host in network.hosts: print host.name, host.IP() print print "*** Type 'exit' or control-D to shut down network" CLI( network ) for host in network.hosts: host.cmd( 'kill %' + cmd ) network.stop() if __name__ == '__main__': lg.setLogLevel( 'debug') net = CreateNet(link=TCLink, controller=None,ipBase='172.16.0.0/24') net.addController('c0',controller=RemoteController,ip='127.0.0.1',port=6653) # get sshd args from the command line or use default args # useDNS=no -u0 to avoid reverse DNS lookup timeout argvopts = ' '.join( sys.argv[ 1: ] ) if len( sys.argv ) > 1 else ( '-D -o UseDNS=no -u0' ) sshd( net, opts=argvopts )
action='store_true', help='Run CLI for topology debugging purposes') parser.add_argument('--time', '-t', dest="time", type=int, help="Duration of the experiment.", default=60) # Expt parameters args = parser.parse_args() if not os.path.exists(args.dir): os.makedirs(args.dir) lg.setLogLevel('info') # Topology to be instantiated in Mininet class ParkingLotTopo(Topo): "Parking Lot Topology" def __init__(self, n=1, cpu=.1, bw=10, delay=None, max_queue_size=None, **params): """Parking lot topology with one receiver and n clients. n: number of clients cpu: system fraction for each host bw: link bandwidth in Mb/s delay: link delay (e.g. 10ms)""" # Initialize topo
def start(ip="192.168.137.110",port=6633): classifier1_intfName = 'eth1' classifier2_intfName = 'eth2' sff1_intfName = 'eth3' sff2_intfName = 'eth4' # Set up logging etc. lg.setLogLevel('info') lg.setLogLevel('output') ctrlr = lambda n: RemoteController(n, ip=ip, port=port, inNamespace=False) ctrlr2 = RemoteController('2', ip='192.168.137.62', port=port, inNamespace=False) net = LINCNet(switch=OVSSwitch, controller=ctrlr, autoStaticArp=True, listenPort=6634) c1 = net.addController('c1') #c2 = net.addController('c2',controller=RemoteController, ip='192.168.137.62',port=6633) c2 = net.addController(ctrlr2) # Add hosts #h1 = net.addHost('h1') #h2 = net.addHost('h2') #h101 = net.addHost('h101') #h102 = net.addHost('h102') # Add packet switches to connect hosts to the optical network s1 = net.addSwitch('s1', dpid='00:00:00:00:00:00:00:01', protocols='OpenFlow10') s2 = net.addSwitch('s2', dpid='00:00:00:00:00:00:00:02', protocols='OpenFlow10') linkopts = dict(bw=1) # Add optical switches r1 = net.addSwitch('r1', dpid='00:00:00:00:00:00:00:11', cls=LINCSwitch) r2 = net.addSwitch('r2', dpid='00:00:00:00:00:00:00:12', cls=LINCSwitch) r3 = net.addSwitch('r3', dpid='00:00:00:00:00:00:00:13', cls=LINCSwitch) r4 = net.addSwitch('r4', dpid='00:00:00:00:00:00:00:14', cls=LINCSwitch) r5 = net.addSwitch('r5', dpid='00:00:00:00:00:00:00:15', cls=LINCSwitch) r6 = net.addSwitch('r6', dpid='00:00:00:00:00:00:00:16', cls=LINCSwitch) r7 = net.addSwitch('r7', dpid='00:00:00:00:00:00:00:17', cls=LINCSwitch) r8 = net.addSwitch('r8', dpid='00:00:00:00:00:00:00:18', cls=LINCSwitch) # Connect hosts to packet switches #print "Adding physical hosts to mininet network..." _intf1 = Intf( classifier1_intfName, node=s1, port=1 ) _intf2 = Intf( sff1_intfName, node=s1, port=2 ) _intf3 = Intf( classifier2_intfName, node=s2, port=1 ) _intf4 = Intf( sff2_intfName, node=s2, port=2 ) #net.addLink(h1, s1) #net.addLink(h2, s2) #net.addLink(h101, s1) #net.addLink(h102, s2) # Connect packet switches to optical switches net.addLink(s1, r1, 3, 1, cls=LINCLink, **linkopts) net.addLink(s1, r1, 4, 2, cls=LINCLink, **linkopts) net.addLink(s2, r2, 3, 1, cls=LINCLink, **linkopts) net.addLink(s2, r2, 4, 2, cls=LINCLink, **linkopts) # Connect optical switches to each other net.addLink(r1, r3, 3, 1, cls=LINCLink) net.addLink(r1, r5, 4, 1, cls=LINCLink) net.addLink(r1, r6, 5, 1, cls=LINCLink) net.addLink(r1, r7, 6, 1, cls=LINCLink) net.addLink(r2, r4, 3, 2, cls=LINCLink) net.addLink(r2, r5, 4, 2, cls=LINCLink) net.addLink(r2, r6, 5, 2, cls=LINCLink) net.addLink(r2, r8, 6, 2, cls=LINCLink) net.addLink(r3, r4, 2, 1, cls=LINCLink) net.addLink(r7, r8, 2, 1, cls=LINCLink) # Start the network and prime other ARP caches net.start() # Uncomment below if using virtal hosts #net.staticArp() #Uncomment below if using physical hosts print "Configuring ARP entries..." utils.setStaticArp() # Enter CLI mode output("Network ready\n") output("Press Ctrl-d or type exit to quit\n") CLI(net) net.stop()
def execute(module, topology_module = None, topology=default_topology, function=default_function, args=default_args, cli=default_cli, timeout=default_timeout, nodes=default_nodes, nox_path=default_nox_path, verbose=default_verbose, experiment_mode=default_experiment_mode): nodes = int(nodes) topology_module = module + "_topo" if topology_module is None else topology_module dirs = fetch_subdirs() setup_env(module, topology_module, function, args, topology, dirs, experiment_mode, nodes) import_directories(dirs) q = Queue() listener = Listener(signal_address) wait = Process(target=receive_signal, args=(listener,q)) wait.daemon = True wait.start() # if experiment_mode: # update_application = get_function_by_name(module, function) # initial_topology = get_function_by_name(topology_module, topology) # setup = get_function_by_name("update_lib", "setup") # inst = DummyComponent(args, update_application, setup, initial_topology) # os._exit(0) if experiment_mode: # yappi.start() nox = Process(target=run_nox) nox = NOX("c0", "UpdateApp") nox.start() lg.setLogLevel('output') output("*** Application started ***\n") wait.join(timeout) msg = "" status = "" if wait.is_alive(): status = "killed" wait.terminate() else: status = "finished" msg = q.get() # yappi.stop() # stats = string.join([str(stat) for stat in yappi.get_stats(yappi.SORTTYPE_TTOTAL)],"\n") output("*** Application %s ***\n%s" % (status, msg)) # output("*** Stats %s " % (stats)) if verbose: output("\n*** Controller output: ***\n" + getControllerOutput() + "\n") nox.stop() os._exit(0) # elif nox_only: # nox_command = os.path.expanduser(nox_path) # nox_dir = os.path.dirname(nox_command) # os.chdir(nox_dir) # if verbose: # nox_command += " -v" # command = "%s -i ptcp:6633 %s" % (nox_command,"UpdateApp") # os.system(command) # wait.join() # os._exit(0) else: global mininet topo = get_function_by_name(topology_module, topology)(nodes).mininet_topo() mininet = Mininet( topo=topo, switch=UserSwitch, controller=lambda name: NOX(name, "UpdateApp"), xterms=False, autoSetMacs=True, autoStaticArp=True ) mininet.start() lg.setLogLevel('output') output("*** Mininet Up ***\n") output("*** Application started ***\n") if cli: CLI(mininet) wait.join(timeout) msg = "" status = "" if wait.is_alive(): status = "killed" listener.close() wait.terminate() else: status = "finished" msg = q.get() output("*** Application %s ***\n%s" % (status, msg)) if verbose: output("*** Controller output: ***\n" + getControllerOutput() + "\n") mininet.stop() output("*** Mininet Down ***\n") os._exit(0)
def start(ip="127.0.0.1", port=6633): ctrlr = lambda n: RemoteController(n, defaultIP=ip, port=port, inNamespace=False) net = Mininet(switch=OVSSwitch, controller=ctrlr, autoStaticArp=True) c1 = net.addController("c1") ####### End of static Mininet prologue ###### h1 = net.addHost("h1", mac="00:00:00:00:00:01", ip="10.0.0.1") h10 = net.addHost("h10", mac="00:00:00:00:00:0a", ip="10.0.0.10") h11 = net.addHost("h11", mac="00:00:00:00:00:0b", ip="10.0.0.11") h12 = net.addHost("h12", mac="00:00:00:00:00:0c", ip="10.0.0.12") h13 = net.addHost("h13", mac="00:00:00:00:00:0d", ip="10.0.0.13") h14 = net.addHost("h14", mac="00:00:00:00:00:0e", ip="10.0.0.14") h15 = net.addHost("h15", mac="00:00:00:00:00:0f", ip="10.0.0.15") h16 = net.addHost("h16", mac="00:00:00:00:00:10", ip="10.0.0.16") h2 = net.addHost("h2", mac="00:00:00:00:00:02", ip="10.0.0.2") h3 = net.addHost("h3", mac="00:00:00:00:00:03", ip="10.0.0.3") h4 = net.addHost("h4", mac="00:00:00:00:00:04", ip="10.0.0.4") h5 = net.addHost("h5", mac="00:00:00:00:00:05", ip="10.0.0.5") h6 = net.addHost("h6", mac="00:00:00:00:00:06", ip="10.0.0.6") h7 = net.addHost("h7", mac="00:00:00:00:00:07", ip="10.0.0.7") h8 = net.addHost("h8", mac="00:00:00:00:00:08", ip="10.0.0.8") h9 = net.addHost("h9", mac="00:00:00:00:00:09", ip="10.0.0.9") s1 = net.addSwitch("s1") s10 = net.addSwitch("s10") s11 = net.addSwitch("s11") s12 = net.addSwitch("s12") s13 = net.addSwitch("s13") s14 = net.addSwitch("s14") s15 = net.addSwitch("s15") s16 = net.addSwitch("s16") s17 = net.addSwitch("s17") s18 = net.addSwitch("s18") s19 = net.addSwitch("s19") s2 = net.addSwitch("s2") s20 = net.addSwitch("s20") s3 = net.addSwitch("s3") s4 = net.addSwitch("s4") s5 = net.addSwitch("s5") s6 = net.addSwitch("s6") s7 = net.addSwitch("s7") s8 = net.addSwitch("s8") s9 = net.addSwitch("s9") net.addLink(h1, s1, 1, 1) net.addLink(h10, s5, 1, 2) net.addLink(h11, s6, 1, 1) net.addLink(h12, s6, 1, 2) net.addLink(h13, s7, 1, 1) net.addLink(h14, s7, 1, 2) net.addLink(h15, s8, 1, 1) net.addLink(h16, s8, 1, 2) net.addLink(h2, s1, 1, 2) net.addLink(h3, s2, 1, 1) net.addLink(h4, s2, 1, 2) net.addLink(h5, s3, 1, 1) net.addLink(h6, s3, 1, 2) net.addLink(h7, s4, 1, 1) net.addLink(h8, s4, 1, 2) net.addLink(h9, s5, 1, 1) net.addLink(s1, s10, 4, 1) net.addLink(s1, s9, 3, 1) net.addLink(s10, s19, 3, 1) net.addLink(s10, s2, 2, 4) net.addLink(s10, s20, 4, 1) net.addLink(s11, s17, 3, 2) net.addLink(s11, s19, 4, 2) net.addLink(s11, s3, 1, 3) net.addLink(s11, s4, 2, 3) net.addLink(s12, s18, 3, 2) net.addLink(s12, s20, 4, 2) net.addLink(s12, s3, 1, 4) net.addLink(s12, s4, 2, 4) net.addLink(s13, s17, 3, 3) net.addLink(s13, s18, 4, 3) net.addLink(s13, s5, 1, 3) net.addLink(s13, s6, 2, 3) net.addLink(s14, s19, 3, 3) net.addLink(s14, s20, 4, 3) net.addLink(s14, s5, 1, 4) net.addLink(s14, s6, 2, 4) net.addLink(s15, s17, 3, 4) net.addLink(s15, s19, 4, 4) net.addLink(s15, s7, 1, 3) net.addLink(s15, s8, 2, 3) net.addLink(s16, s18, 3, 4) net.addLink(s16, s20, 4, 4) net.addLink(s16, s7, 1, 4) net.addLink(s16, s8, 2, 4) net.addLink(s17, s9, 1, 3) net.addLink(s18, s9, 1, 4) net.addLink(s2, s9, 3, 2) ###### Start of static Mininet epilogue ###### # Set up logging etc. lg.setLogLevel("info") lg.setLogLevel("output") # Start the network and prime other ARP caches net.start() # Enter CLI mode output("Network ready\n") output("Press Ctrl-d or type exit to quit\n") CLI(net) net.stop()