def testLinkLoss( self ): "Verify that we see packet drops with a high configured loss rate." LOSS_PERCENT = 99 REPS = 1 lopts = { 'loss': LOSS_PERCENT, 'use_htb': True } mn = Mininet( topo=SingleSwitchOptionsTopo( n=N, lopts=lopts ), host=CPULimitedHost, link=TCLink, switch=self.switchClass, waitConnected=True ) # Drops are probabilistic, but the chance of no dropped packets is # 1 in 100 million with 4 hops for a link w/99% loss. dropped_total = 0 mn.start() for _ in range(REPS): dropped_total += mn.ping(timeout='1') mn.stop() loptsStr = ', '.join( '%s: %s' % ( opt, value ) for opt, value in lopts.items() ) msg = ( '\nTesting packet loss with %d%% loss rate\n' 'number of dropped pings during mininet.ping(): %s\n' 'expected number of dropped packets: 1\n' 'Topo = SingleSwitchTopo, %s hosts\n' 'Link = TCLink\n' 'lopts = %s\n' 'host = default\n' 'switch = %s\n' % ( LOSS_PERCENT, dropped_total, N, loptsStr, self.switchClass ) ) self.assertGreater( dropped_total, 0, msg )
def intfOptions(): "run various traffic control commands on a single interface" net = Mininet( autoStaticArp=True ) net.addController( 'c0' ) h1 = net.addHost( 'h1' ) h2 = net.addHost( 'h2' ) s1 = net.addSwitch( 's1' ) link1 = net.addLink( h1, s1, cls=TCLink ) net.addLink( h2, s1 ) net.start() # flush out latency from reactive forwarding delay net.pingAll() info( '\n*** Configuring one intf with bandwidth of 5 Mb\n' ) link1.intf1.config( bw=5 ) info( '\n*** Running iperf to test\n' ) net.iperf() info( '\n*** Configuring one intf with loss of 50%\n' ) link1.intf1.config( loss=50 ) info( '\n' ) net.iperf( ( h1, h2 ), l4Type='UDP' ) info( '\n*** Configuring one intf with delay of 15ms\n' ) link1.intf1.config( delay='15ms' ) info( '\n*** Run a ping to confirm delay\n' ) net.pingPairFull() info( '\n*** Done testing\n' ) net.stop()
def cs461net(): stophttp() "Create a simple network for cs461" r = get_ip_setting() if r == -1: exit("Couldn't load config file for ip addresses, check whether %s exists" % IPCONFIG_FILE) else: info( '*** Successfully loaded ip settings for hosts\n %s\n' % IP_SETTING) topo = CS461Topo() info( '*** Creating network\n' ) net = Mininet( topo=topo, controller=RemoteController, ipBase=IPBASE ) net.start() server1, server2, client, router = net.get( 'server1', 'server2', 'client', 'sw0') s1intf = server1.defaultIntf() s1intf.setIP('%s/8' % IP_SETTING['server1']) s2intf = server2.defaultIntf() s2intf.setIP('%s/8' % IP_SETTING['server2']) clintf = client.defaultIntf() clintf.setIP('%s/8' % IP_SETTING['client']) for host in server1, server2, client: set_default_route(host) starthttp( server1 ) starthttp( server2 ) CLI( net ) stophttp() net.stop()
def testCPULimits( self ): "Verify topology creation with CPU limits set for both schedulers." CPU_FRACTION = 0.1 CPU_TOLERANCE = 0.8 # CPU fraction below which test should fail hopts = { 'cpu': CPU_FRACTION } #self.runOptionsTopoTest( N, hopts=hopts ) mn = Mininet( SingleSwitchOptionsTopo( n=N, hopts=hopts ), host=CPULimitedHost, switch=self.switchClass, waitConnected=True ) mn.start() results = mn.runCpuLimitTest( cpu=CPU_FRACTION ) mn.stop() hostUsage = '\n'.join( 'h%s: %s' % ( n + 1, results[ (n - 1) * 5 : (n * 5) - 1 ] ) for n in range( N ) ) hoptsStr = ', '.join( '%s: %s' % ( opt, value ) for opt, value in hopts.items() ) msg = ( '\nTesting cpu limited to %d%% of cpu per host\n' 'cpu usage percent per host:\n%s\n' 'Topo = SingleSwitchTopo, %s hosts\n' 'hopts = %s\n' 'host = CPULimitedHost\n' 'Switch = %s\n' % ( CPU_FRACTION * 100, hostUsage, N, hoptsStr, self.switchClass ) ) for pct in results: #divide cpu by 100 to convert from percentage to fraction self.assertWithinTolerance( pct/100, CPU_FRACTION, CPU_TOLERANCE, msg )
def setup(): cos = [] for d in CTLS.keys(): co = CO(d) ctls = CTLS[d] for i in range(len(ctls)): co.addController('c%s%s' % (d, i), controller=RemoteController, ip=ctls[i]) co.build() cos.append(co) # make/setup Mininet object net = Mininet() for co in cos: co.injectInto(net) #co.dumpCfg('co%d.json' % co.getId()) vls = VLANS.get(co.getId()) lf1_ifs = LF1_INFS.get(co.getId()) lf2_ifs = LF2_INFS.get(co.getId()) co.bootstrap(net, vls, lf1_ifs, lf2_ifs) # start everything, let it run its course net.build() for co in cos: # remove IP from trunk interface of EE host (assigned by Mininet) ee = net.get('h%d11' % co.getId()) ee.defaultIntf().ifconfig('inet', '0') co.start() CLI(net) net.stop()
def output(partIdx): """Uses the student code to compute the output for test cases.""" outputString = "" if partIdx == 0: # This is agPA2 "Set up link parameters" print "a. Setting link parameters" "--- core to aggregation switches" linkopts1 = {"bw": 50, "delay": "5ms"} "--- aggregation to edge switches" linkopts2 = {"bw": 30, "delay": "10ms"} "--- edge switches to hosts" linkopts3 = {"bw": 10, "delay": "15ms"} "Creating network and run simple performance test" print "b. Creating Custom Topology" topo = CustomTopo(linkopts1, linkopts2, linkopts3, fanout=3) print "c. Firing up Mininet" net = Mininet(topo=topo, link=TCLink) net.start() h1 = net.get("h1") h27 = net.get("h27") print "d. Starting Test" # Start pings outputString = h1.cmd("ping", "-c6", h27.IP()) print "e. Stopping Mininet" net.stop() return outputString.strip()
def main(): start = time() try: topo = NetworkTopo(switch_bw=args.bw_net, host_bw=args.bw_host, switch_delay='%sms' %(args.delay, ), queue_size=23593) net = Mininet(topo=topo, host=CPULimitedHost, link=TCLink) net.start() dumpNodeConnections(net.hosts) net.pingAll() if args.http: 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")
def setupNetwork(): "Create network" topo = MyTopo() network = Mininet(topo=topo, autoSetMacs=True, controller=None) network.start() CLI( network ) network.stop()
def topology(): "Create a network." net = Mininet( controller=Controller, link=TCLink, switch=OVSKernelSwitch ) print "*** Creating nodes" sta1 = net.addStation( 'sta1', mac='00:00:00:00:00:02', ip='10.0.0.2/8' ) ap1 = net.addBaseStation( 'ap1', ssid= 'new-ssid', mode= 'g', channel= '1', position='50,50,0' ) c1 = net.addController( 'c1', controller=Controller ) print "*** adding Link" net.addLink(sta1, ap1) print "*** Starting network" net.build() c1.start() ap1.start( [c1] ) """uncomment to plot graph""" net.plotGraph(max_x=100, max_y=100) getTrace(sta1, 'examples/replaying/replayingBandwidth/throughputData.dat') replayingBandwidth() print "*** Running CLI" CLI( net ) print "*** Stopping network" net.stop()
def multiSwitchTest(): topo = MultiSwitchTopo(depth=2, fanout=4) #net = Mininet(topo, controller=OVSController) net = Mininet(topo, controller=lambda name: RemoteController(name, ip='192.168.56.1')) net.start() print "Dumping host connections" dumpNodeConnections(net.hosts) print "Testing network connectivity" net.pingAll() receivers = ["00:11:22:33:44:00", "00:11:22:33:44:04", "00:11:22:33:44:08", "00:11:22:33:44:0c"] for host in net.hosts: if host.defaultIntf().MAC() in receivers: startLogReceiver(host) else: startLogSender(host) for host in net.hosts: if not (host.defaultIntf().MAC() in receivers): runGenerator(host) for host in net.hosts: if host.defaultIntf().MAC() in receivers: stopLogReceiver(host) else: stopLogSender(host) net.stop()
def main(): "Create and run experiment" start = time() topo = ParkingLotTopo(n=args.n) host = custom(CPULimitedHost, cpu=.15) # 15% of system bandwidth link = custom(TCLink, bw=args.bw, delay='1ms', max_queue_size=200) net = Mininet(topo=topo, host=host, link=link) net.start() cprint("*** Dumping network connections:", "green") dumpNetConnections(net) cprint("*** Testing connectivity", "blue") net.pingAll() if args.cli: # Run CLI instead of experiment CLI(net) else: cprint("*** Running experiment", "magenta") run_parkinglot_expt(net, n=args.n) net.stop() end = time() os.system("killall -9 bwm-ng") cprint("Experiment took %.3f seconds" % (end - start), "yellow")
def simpleTest(): "Create and test a simple network" topo = DiamondTopo(k=4) net = Mininet(topo=topo,link=TCLink,controller=RemoteController) if args.sim!=1: print "Adding real interfaces" s1 = net.getNodeByName('s1') s3 = net.getNodeByName('s3') addRealIntf(net,args.intf1,s1) addRealIntf(net,args.intf2,s3) opts = '-D -o UseDNS=no -u0' rootnode=sshd(net, opts=opts) h2 = net.getNodeByName('h2') h2.cmd('iperf -s -p 5001 -i 1 > iperf-recv_TCP.txt &') h2.cmd('iperf -s -p 5003 -u -i 1 > iperf-recv_UDP.txt &') else: net.start() CLI(net) os.system('killall -9 iperf' ) if args.sim!=1: net.hosts[0].cmd('killall -9 dhcpd') for host in net.hosts: host.cmd('kill %'+ '/usr/sbin/sshd') stopNAT(rootnode) net.stop()
def run(): "Create control and data networks, and invoke the CLI" info( '* Creating Control Network\n' ) ctopo = ControlNetwork( n=4, dataController=DataController ) cnet = Mininet( topo=ctopo, ipBase='192.168.123.0/24', controller=None ) info( '* Adding Control Network Controller\n') cnet.addController( 'cc0', controller=Controller ) info( '* Starting Control Network\n') cnet.start() info( '* Creating Data Network\n' ) topo = TreeTopo( depth=2, fanout=2 ) # UserSwitch so we can easily test failover sw = partial( UserSwitch, opts='--inactivity-probe=1 --max-backoff=1' ) net = Mininet( topo=topo, switch=sw, controller=None ) info( '* Adding Controllers to Data Network\n' ) for host in cnet.hosts: if isinstance(host, Controller): net.addController( host ) info( '* Starting Data Network\n') net.start() mn = MininetFacade( net, cnet=cnet ) CLI( mn ) info( '* Stopping Data Network\n' ) net.stop() info( '* Stopping Control Network\n' ) cnet.stop()
def sdnnet(opt): topo = SDNTopo() info( '*** Creating network\n' ) net = Mininet( topo=topo, controller=MyController, link=TCLink) host = [] for i in range (8): host.append(net.get( 'host%d' % i )) net.start() core_sw = [] for i in range (2): name_suffix = '%s' % NWID + '0c' + '%02d' % i net.get('sw' + name_suffix).attach('tap%s0' % NWID) for i in range (8): host[i].defaultIntf().setIP('192.168.10.10%d/24' % i) root = [] for i in range (8): root.append(net.get( 'root%d' % i )) for i in range (8): host[i].intf('host%d-eth1' % i).setIP('1.1.%d.1/24' % i) root[i].intf('root%d-eth0' % i).setIP('1.1.%d.2/24' % i) stopsshd () startsshds ( host ) if opt=="cli": CLI(net) stopsshd() net.stop()
def sdnTopo(interface_name): CONTROLLER_IP='10.0.0.200' net = Mininet( topo=None, build=False) # Create nodes h1 = net.addHost( 'h1', ip='10.0.0.1/8' ) h2 = net.addHost( 'h2', ip='10.0.0.2/8' ) # Create switches s1 = net.addSwitch( 's1') net.addLink(h1, s1, ) net.addLink(h2, s1, ) # Add Controllers odl_ctrl = net.addController( 'c0', controller=RemoteController, ip=CONTROLLER_IP) info( "*** Creation de l'architecture réseau\n" ) net.build() # Connect each switch to a different controller s1.start( [odl_ctrl] ) info( "*** Ajout de l'interface",interface_name,"au switch" ) _intf = Intf( interface_name, node=s1) net.start() CLI( net ) net.stop()
def emptyNet(): "Create an empty network and add nodes to it." net = Mininet( controller=lambda a: RemoteController(a, ip='128.208.125.60' )) info( '*** Adding controller\n' ) net.addController( 'c0' ) info( '*** Adding hosts\n' ) h1 = net.addHost( 'h1', ip='10.0.0.1' ) h2 = net.addHost( 'h2', ip='10.0.0.2' ) info( '*** Adding switch\n' ) s3 = net.addSwitch( 's3' ) s4 = net.addSwitch( 's4' ) s5 = net.addSwitch( 's5' ) info( '*** Creating links\n' ) net.addLink( h1, s3 ) net.addLink( h2, s5 ) net.addLink( s3 , s4 ) net.addLink( s4 , s5 ) info( '*** Starting network\n') net.start() info( '*** Running CLI\n' ) CLI( net ) info( '*** Stopping network' ) net.stop()
def topology(): "Create a network." net = Mininet( controller=Controller, link=TCLink, switch=OVSKernelSwitch ) print "*** Creating nodes" sta1 = net.addStation( 'sta1', mac='00:00:00:00:00:02', ip='10.0.0.2/8', position='10,20,0' ) sta2 = net.addStation( 'sta2', mac='00:00:00:00:00:03', ip='10.0.0.3/8', position='10,30,0' ) ap1 = net.addBaseStation( 'ap1', ssid= 'new-ssid', mode= 'g', channel= '1', position='15,30,0' ) c1 = net.addController( 'c1', controller=Controller ) """uncomment to plot graph""" #net.plotGraph(max_x=60, max_y=60) print "*** Creating links" net.addLink(ap1, sta1) net.addLink(ap1, sta2) print "*** Starting network" net.build() c1.start() ap1.start( [c1] ) print "*** Running CLI" CLI( net ) print "*** Stopping network" net.stop()
def runMultiLink(): "Create and run multiple link network" topo = simpleMultiLinkTopo( n=2 ) net = Mininet( topo=topo ) net.start() CLI( net ) net.stop()
def run( n ): topo = OpticalTopo( n ) net = Mininet( topo=topo, controller=RemoteController, autoSetMacs=True ) net.start() #installStaticFlows( net ) CLI( net ) net.stop()
def test(): topo = DssTopo() net = Mininet(topo, link=TCLink) net.start() pidList(net) global NPAUSE global NRESUME NPAUSE = 'sudo /home/kd/VirtualTimeKernel/test_virtual_time/freeze_all_procs -f -p %s'%pIDS NRESUME ='sudo /home/kd/VirtualTimeKernel/test_virtual_time/freeze_all_procs -u -p %s'%pIDS #block print(net.get('h1').cmd('ping -c 1 10.0.0.2')) net.get('h1').cmd('ping -c 40 10.0.0.2 > %sbl.test'% FileOut) #dont block net.get('h1').cmd('/home/kd/VirtualTimeKernel/iputils/ping -c 40 -D 10.0.0.2 > %svt.test &'% FileOut) time.sleep(5) for x in range(0,int(sys.argv[3])): print 'pausing' pause() time.sleep(stime) print 'resumed' time.sleep(30) net.stop()
def topology(): "Create a network." net = Mininet( controller=Controller, link=TCLink, switch=OVSKernelSwitch ) #wirelessRadios = Number of STAs + APs print "*** Creating nodes" ap1 = net.addBaseStation( 'ap1', ssid="simplewifi", mode="g", channel="5" ) sta1 = net.addStation( 'sta1', ip='192.168.0.1/24' ) sta2 = net.addStation( 'sta2', ip='192.168.0.2/24' ) h3 = net.addHost( 'h3', ip='192.168.0.3/24' ) h4 = net.addHost( 'h4', ip='192.168.0.4/24' ) c0 = net.addController('c0', controller=Controller, ip='127.0.0.1', port=6633 ) print "*** Adding Link" net.addLink(sta1, ap1) net.addLink(sta2, ap1) net.addLink(h3, ap1) net.addLink(h4, ap1) print "*** Starting network" net.build() c0.start() ap1.start( [c0] ) print "*** Running CLI" CLI( net ) print "*** Stopping network" net.stop()
def main(): # All b/w are in megabits max_bw = 1000 # B/w of queue 1 and queue 2 values = [3,1,4] topo = MyTopo(max_bw) net = Mininet(topo, link = TCLink, controller = partial(RemoteController, ip = '127.0.0.1', port = 6633)) net.start() # Queue set in between h1 and s1 cmd = 'ovs-vsctl -- set Port s2-eth4 qos=@newqos -- \ --id=@newqos create QoS type=linux-htb other-config:max-rate=1000000000 queues=0=@q0,1=@q1,2=@q2,3=@q3 -- \ --id=@q0 create Queue other-config:min-rate=%d other-config:max-rate=%d -- \ --id=@q1 create Queue other-config:min-rate=%d other-config:max-rate=%d -- \ --id=@q2 create Queue other-config:min-rate=%d other-config:max-rate=%d -- \ --id=@q3 create Queue other-config:min-rate=%d other-config:max-rate=%d' % \ (max_bw * 10**6, max_bw * 10**6, \ values[0] * 10**6, values[0] * 10**6, \ values[1] * 10**6, values[1] * 10**6, \ values[2] * 10**6, values[2] * 10**6) sp.call(cmd, shell = True) CLI(net) net.stop()
def emptyNet(): "Create an empty network and add nodes to it." net = Mininet( topo=None, build=False) net.addController( 'c0', controller=RemoteController, ip='0.0.0.0' ) h1 = net.addHost( 'h1', ip='10.0.0.1' ) h2 = net.addHost( 'h2', ip='10.0.0.2' ) h3 = net.addHost( 'h3', ip='10.0.0.3' ) s1 = net.addSwitch( 's1', cls=OVSSwitch ) net.addLink( h1, s1 ) net.addLink( h2, s1 ) net.addLink( h3, s1 ) net.start() s1.cmd('ifconfig s1 inet 10.0.0.10') CLI( net ) net.stop()
def perfTest(): topo = crazy_switches() net = Mininet(topo=topo, controller=lambda name: RemoteController( 'c0', '127.0.0.1' ), host=CPULimitedHost, link=TCLink) net.start() CLI(net) net.stop()
def test(): topo = DssTopo() net = Mininet(topo, link=TCLink) net.start() with open("pause.test","a") as myfile: for x in range(0,2000): st1 = net.pingPairFull() #print 'pausing' time.sleep(0.01) pause() myfile.write( repr(st1[0][2][3])) myfile.write('\n') with open("noPause.test","a") as myffile: for x in range(0,2000): st1 = net.pingPairFull() #print 'pausing' time.sleep(0.01) #pause() myffile.write( repr(st1[0][2][3])) myffile.write('\n') net.stop()
def run_cellsim_topology(): print_welcome_message() os.system( "killall -q controller" ) os.system( "killall -q cellsim" ) os.system( "killall -q mysender" ) os.system( "killall -q myreceiver" ) topo = ProtoTester() net = Mininet(topo=topo, host=Host, link=Link) net.start() sender = net.getNodeByName('sender') LTE = net.getNodeByName('LTE') receiver = net.getNodeByName('receiver') set_all_IP(net, sender, LTE, receiver) #Dump connections #dumpNodeConnections(net.hosts) #display_routes(net, sender, LTE, receiver) #run_cellsim(LTE) run_datagrump(sender, receiver) run_cellsim(LTE) # CLI(net) net.stop()
def myNet(): MultiSwitch13 = partial( MultiSwitch, protocols='OpenFlow13' ) #tree_topo = TreeTopo(depth=3,fanout=2) tree_topo = SingleSwitchTopo(n=14) net = Mininet(controller=RemoteController, topo=tree_topo, switch=MultiSwitch13, build=False, autoSetMacs=True) info( '*** Adding controllers\n') #c1 = net.addController('c1', controller=RemoteController, ip="127.0.0.1", port=6633) c1 = net.addController('c1', controller=RemoteController, ip="192.168.1.1", port=6633) c2 = net.addController('c2', controller=RemoteController, ip="192.168.1.2", port=6633) c3 = net.addController('c3', controller=RemoteController, ip="192.168.1.3", port=6633) # info( '*** Add hosts\n') # h1 = net.addHost( 'h1', ip='10.0.0.1' ) # h2 = net.addHost( 'h2', ip='10.0.0.2' ) # h3 = net.addHost( 'h3', ip='10.0.0.3' ) # h4 = net.addHost( 'h4', ip='10.0.0.4' ) # info( '*** Add switches\n') # s1 = net.addSwitch( 's1', cls=OVSKernelSwitch, protocols='OpenFlow13' ) # s2 = net.addSwitch( 's2', cls=OVSKernelSwitch, protocols='OpenFlow13' ) # s3 = net.addSwitch( 's3', cls=OVSKernelSwitch, protocols='OpenFlow13' ) # s4 = net.addSwitch( 's4', cls=OVSKernelSwitch, protocols='OpenFlow13' ) # info( '*** Add links\n') # s1.linkTo( h1 ) # s1.linkTo( s2 ) # s2.linkTo( h2 ) # s2.linkTo( s3 ) # s3.linkTo( h3 ) # s3.linkTo( s4 ) # s4.linkTo( h4 ) info( '*** Starting network\n') net.build() info( '*** Starting controllers\n') c1.start() c2.start() c3.start() # info( '*** Starting switches\n') # s1.start([c1,c2,c3]) # s2.start([c1,c2,c3]) # s3.start([c1,c2,c3]) # s4.start([c1,c2,c3]) net.start() net.staticArp() # i = 0; # while i < 10: # h1, h2 = random.choice(net.hosts), random.choice(net.hosts) # print h1.IP(), "-->", h2.IP() # sent, received, rttmin, rttavg, rttmax, rttdev = ping(h1, h2) # print received,"/",sent # i = i + 1 # sleep(1) CLI( net ) net.stop()
def myNet(): #OpenDayLight controller CONTROLLER1_IP='127.0.0.1' #Floodlight controller net = Mininet( topo=None, build=False) # Create nodes h1 = net.addHost( 'h1', mac='01:00:00:00:01:00', ip='192.168.0.1/24' ) # Create switches s1 = net.addSwitch( 's1', listenPort=6634, mac='00:00:00:00:00:01' ) print "*** Creating links" net.addLink(h1, s1 ) # Add Controllers c0 = net.addController( 'c0', controller=RemoteController, ip=CONTROLLER1_IP, port=6633) net.build() # Connect each switch to a different controller s1.start([c0]) s1.cmdPrint('ovs-vsctl show') CLI( net ) net.stop()
def bufferbloat(**kwargs): # Linux uses CUBIC-TCP by default that doesn't have the usual sawtooth # behaviour. For those who are curious, replace reno with cubic # see what happens... # sysctl -a | grep cong should list some interesting parameters. os.system("sysctl -w net.ipv4.tcp_congestion_control=reno") # create the topology and network topo = BBTopo(int(kwargs['queue_size']), int(kwargs['ping_RTT'])) net = Mininet(topo=topo, host=CPULimitedHost, link=TCLink, controller= OVSController) net.start() # This dumps the topology and how nodes are interconnected through # links. dumpNodeConnections(net.hosts) # This performs a basic all pairs ping test. net.pingAll() # Start all the monitoring processes start_tcpprobe("cwnd.txt") # TODO: Start monitoring the queue sizes. Since the switch I # created is "s0", I monitor one of the interfaces. Which # interface? The interface numbering starts with 1 and increases. # Depending on the order you add links to your network, this # number may be 1 or 2. Ensure you use the correct number. # qmon = start_qmon(...) qmon = start_qmon(iface='s0-eth2', outfile='%s/q.txt' % ".") # TODO: Start iperf, pings, and the webserver. # start_iperf(net), ... start_iperf(net, kwargs['congestion_window']) start_webserver(net) start_ping(net) # TODO: measure the time it takes to complete webpage transfer # from h1 to h2 (say) 4-5 times. Hint: check what the following # command does: curl -o /dev/null -s -w %{time_total} google.com # Now use the curl command to fetch webpage from the webserver you # spawned on host h1 (not from google!) print "starting timing tester" timing_results = timing_tester(net) # TODO: compute average (and standard deviation) of the fetch # times. You don't need to plot them. Just print them # here and explain your observations in the Questions part # in Part 2, where you analyze your measurements. print timing_results[0] print "Ave fetching time: %.4f" % numpy.average(numpy.array(timing_results).astype(numpy.float)) print "std dev. of fetching times: %.4f" % numpy.std(numpy.array(timing_results).astype(numpy.float)) # Stop probing stop_tcpprobe() qmon.terminate() net.stop() # Ensure that all processes you create within Mininet are killed. # Sometimes they require manual killing. Popen("pgrep -f webserver.py | xargs kill -9", shell=True).wait()
def myNet(): #OpenDayLight controller 1 ODL_CONTROLLER1_IP='192.168.1.10' #OpenDaylight controller 2 ODL_CONTROLLER2_IP='192.168.1.11' #OpenDaylight controller 3 ODL_CONTROLLER3_IP='192.168.1.12' net = Mininet(topo=None, build=False) # Create nodes h1 = net.addHost( 'h1',ip='10.0.0.1') h2 = net.addHost( 'h2',ip='10.0.0.2') h3 = net.addHost( 'h3',ip='10.0.0.3') h4 = net.addHost( 'h4',ip='10.0.0.4') h5 = net.addHost( 'h5',ip='10.0.0.5') h6 = net.addHost( 'h6',ip='10.0.0.6') h7 = net.addHost( 'h7',ip='10.0.0.7') h8 = net.addHost( 'h8',ip='10.0.0.8') h01 = net.addHost( 'h01',ip='10.0.0.11') h02 = net.addHost( 'h02',ip='10.0.0.12') h03 = net.addHost( 'h03',ip='10.0.0.13') h04 = net.addHost( 'h04',ip='10.0.0.14') h05 = net.addHost( 'h05',ip='10.0.0.15') # Create switches s6 = net.addSwitch( 's6') s7 = net.addSwitch( 's7') s8 = net.addSwitch( 's8') s9 = net.addSwitch( 's9') 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') s20 = net.addSwitch( 's20') s21 = net.addSwitch( 's21') s22 = net.addSwitch( 's22') s23 = net.addSwitch( 's23') s24 = net.addSwitch( 's24') s25 = net.addSwitch( 's25') print "*** Creating links" #external net.addLink(s1,h01,) net.addLink(s2,h02,) net.addLink(s3,h03,) net.addLink(s4,h04,) net.addLink(s5,h05,) net.addLink(s3,s10,) net.addLink(s3,s4,) net.addLink(s3,s1,) net.addLink(s1,s2,) net.addLink(s2,s5,) net.addLink(s4,s5,) net.addLink(s5,s17,) #internal net.addLink(s18,h1,) net.addLink(s19,h2,) net.addLink(s20,h3,) net.addLink(s21,h4,) net.addLink(s22,h5,) net.addLink(s23,h6,) net.addLink(s24,h7,) net.addLink(s25,h8,) net.addLink(s10, s18,) net.addLink(s10, s19,) net.addLink(s11, s18,) net.addLink(s11, s19,) net.addLink(s12, s20,) net.addLink(s12, s21,) net.addLink(s13, s20,) net.addLink(s13, s21,) net.addLink(s14, s22,) net.addLink(s14, s23,) net.addLink(s15, s22,) net.addLink(s15, s23,) net.addLink(s16, s24,) net.addLink(s16, s25,) net.addLink(s17, s24,) net.addLink(s17, s25,) net.addLink(s6, s10,) net.addLink(s6, s12,) net.addLink(s6, s14,) net.addLink(s6, s16,) net.addLink(s7, s10,) net.addLink(s7, s12,) net.addLink(s7, s14,) net.addLink(s7, s16,) net.addLink(s8, s11,) net.addLink(s8, s13,) net.addLink(s8, s15,) net.addLink(s8, s17,) net.addLink(s9, s11,) net.addLink(s9, s13,) net.addLink(s9, s15,) net.addLink(s9, s17,) # Add Controllers odl_ctrl1 = net.addController( 'c0', controller=RemoteController, ip=ODL_CONTROLLER1_IP, port=6633) net.build() #odl_ctrl.start() #fl_ctrl.start() # Connect each switch to a different controller s6.start([odl_ctrl1]) s7.start([odl_ctrl1]) s8.start([odl_ctrl1]) s9.start([odl_ctrl1]) s10.start([odl_ctrl1]) s11.start([odl_ctrl1]) s12.start([odl_ctrl1]) s13.start([odl_ctrl1]) s14.start([odl_ctrl1]) s15.start([odl_ctrl1]) s16.start([odl_ctrl1]) s17.start([odl_ctrl1]) s18.start([odl_ctrl1]) s19.start([odl_ctrl1]) s20.start([odl_ctrl1]) s21.start([odl_ctrl1]) s22.start([odl_ctrl1]) s23.start([odl_ctrl1]) s24.start([odl_ctrl1]) s25.start([odl_ctrl1]) #s6.cmdPrint('ovs-vsctl show') CLI( net ) net.stop()
def WifiNet(inputFile): input = open(inputFile, "r") """ Node names """ max_outgoing = [] hosts = [] switches = [] # satellite and dummy satellite links = [] queueConfig = open("FDMQueueConfig.sh", "w") flowTableConfig = open("FDMFlowTableConfig.sh", "w") queueConfig.write("#!/bin/bash\n\n") flowTableConfig.write("#!/bin/bash\n\n") queue_num = 1 num_host = 0 num_ship = 0 num_sat = 0 # Read src-des pair for testing src_hosts = [] des_hosts = [] des_ip = [] line = input.readline() while line.strip() != "End": src, des, ip = line.strip().split() src_hosts.append(src) des_hosts.append(des) des_ip.append(ip) line = input.readline() # Add nodes # Mirror ships are switches line = input.readline() while line.strip() != "End": action, type_node, target = line.strip().split() if type_node == "host:": hosts.append(target) num_host += 1 else: if type_node == "ship:": num_ship += 1 max_outgoing.append(0) elif type_node == "sat:": num_sat += 1 switches.append(target) line = input.readline() num_sat = num_sat / 2 # Add links line = input.readline() while line.strip() != "End": action, type_node, end1, end2, bw, delay = line.strip().split() if end1[0] == "s" and int(end1[1:]) <= num_ship and end2[0] == "s": max_outgoing[int(end1[1:]) - 1] += 1 links.append([end1, end2, bw, delay]) line = input.readline() print(max_outgoing) # Routing table of hosts line = input.readline() udphost = set() while line.strip() != "End": host, st, num_ip, protocol = line.strip().split() print(num_ip) print(protocol) if protocol == "UDP": udphost.add(host) file = open(host + ".sh", "w") file.write("#!/bin/bash\n\n") for i in range(0, int(num_ip)): ipaddr = input.readline().strip() intf = host + "-eth" + str(i) file.write("ifconfig " + intf + " " + ipaddr + " netmask 255.255.255.255\n") file.write("ip rule add from " + ipaddr + " table " + str(i + 1) + "\n") file.write("ip route add " + ipaddr + "/32 dev " + intf + " scope link table " + str(i + 1) + "\n") file.write("ip route add default via " + ipaddr + " dev " + intf + " table " + str(i + 1) + "\n") if i == 0: file.write("ip route add default scope global nexthop via " + ipaddr + " dev " + intf + "\n") file.close() call(["sudo", "chmod", "777", host + ".sh"]) line = input.readline() # Flow table and queue queue_num = 1 bwReq = [] line = input.readline() while line: # print(line) end1, end2, num_flow = line.strip().split() num_flow = num_flow.strip().split(":")[1] # Routing tables have been configured if "host" in end1: flow = 0 for i in range(0, int(num_flow)): line = input.readline() flow += float(line.strip().split()[1]) bwReq.append(flow) else: switch, intf = end1.split("-") index_switch = int(switch[1:]) index_intf = intf[3:] if index_switch <= num_ship and "host" != end2[0:4]: # uplink to ship, need to configure both flowtable and queue # put the queues for one port on one line in definition commandQueue = "sudo ifconfig " + end1 + " txqueuelen 10" queueConfig.write(commandQueue + "\n") commandQueue = "sudo ovs-vsctl -- set Port " + end1 + " qos=@newqos -- --id=@newqos create QoS type=linux-htb other-config:max-rate=100000000 " queue_nums = [] rates = [] ipaddrs = [] for i in range(0, int(num_flow) - 1): ipaddr, rate = input.readline().strip().split() rates.append(rate) ipaddrs.append(ipaddr) queue_nums.append(queue_num) commandQueue += "queues:" + str(queue_num) + "=@q" + str( queue_num) + " " queue_num += 1 ipaddr, rate = input.readline().strip().split() rates.append(rate) ipaddrs.append(ipaddr) queue_nums.append(queue_num) commandQueue += "queues:" + str(queue_num) + "=@q" + str( queue_num) + " -- " queue_num += 1 for i in range(0, int(num_flow) - 1): commandQueue += " --id=@q" + str( queue_nums[i] ) + " create Queue other-config:min-rate=" + str( int(float(rates[i]) * 1000000)) + " other-config:max-rate=" + str( int(float(rates[i]) * 1000000)) + " -- " commandQueue += " --id=@q" + str( queue_nums[len(queue_nums) - 1] ) + " create Queue other-config:min-rate=" + str( int(float(rates[len(queue_nums) - 1]) * 1000000)) + " other-config:max-rate=" + str( int(float(rates[len(queue_nums) - 1]) * 1000000)) queueConfig.write(commandQueue + "\n") for i in range(0, int(num_flow)): commandFlowTable = "sudo ovs-ofctl add-flow " + switch + " ip,nw_src=" + ipaddrs[ i] + "/32,actions=set_queue:" + str( queue_nums[i]) + ",output:" + index_intf flowTableConfig.write(commandFlowTable + "\n") commandFlowTable = "sudo ovs-ofctl add-flow " + switch + " in_port=" + index_intf + ",actions=normal" flowTableConfig.write(commandFlowTable + "\n") else: # sat-dummy_sat # port forwarding for i in range(0, int(num_flow)): input.readline() for i in range(1, int(index_intf)): commandFlowTable = "sudo ovs-ofctl add-flow " + switch + " in_port=" + str( i) + ",actions=output:" + index_intf flowTableConfig.write(commandFlowTable + "\n") commandFlowTable = "sudo ovs-ofctl add-flow " + switch + " in_port=" + index_intf + ",actions=normal" flowTableConfig.write(commandFlowTable + "\n") line = input.readline() for i in range(0, num_ship): queueConfig.write("sudo ovs-ofctl -O Openflow13 queue-stats s" + str(i + 1) + "\n") for i in range(0, num_ship + 2 * num_sat + 1): flowTableConfig.write("sudo ovs-ofctl add-flow s" + str(i + 1) + " priority=100,actions=normal\n") flowTableConfig.close() queueConfig.close() call(["sudo", "chmod", "777", "FDMQueueConfig.sh"]) call(["sudo", "chmod", "777", "FDMFlowTableConfig.sh"]) net = Mininet(link=TCLink, controller=None, autoSetMacs=True) nodes = {} """ Initialize Ships """ for host in hosts: node = net.addHost(host) nodes[host] = node """ Initialize SATCOMs """ for switch in switches: node = net.addSwitch(switch) nodes[switch] = node """ Add links """ for link in links: name1, name2, b, d = link[0], link[1], link[2], link[3] node1, node2 = nodes[name1], nodes[name2] if (d != '0'): net.addLink(node1, node2, delay=d + 'ms') else: net.addLink(node1, node2) """ Start the simulation """ info('*** Starting network ***\n') net.start() # set all ships for i in range(0, num_host): src = nodes[hosts[i]] info("--configing routing table of " + hosts[i]) if os.path.isfile(hosts[i] + '.sh'): src.cmdPrint('./' + hosts[i] + '.sh') time.sleep(3) info('*** set queues ***\n') call(["sudo", "bash", "FDMQueueConfig.sh"]) time.sleep(3) info('*** set flow tables ***\n') call(["sudo", "bash", "FDMFlowTableConfig.sh"]) # start D-ITG Servers for i in [num_host - 1]: # last host is receiver srv = nodes[hosts[i]] info("starting D-ITG servers...\n") srv.cmdPrint("cd ~/D-ITG-2.8.1-r1023/bin") srv.cmdPrint("./ITGRecv &") time.sleep(1) print("This is UDP set") for item in udphost: print(item) # start D-ITG application # set simulation time sTime = 60000 # default 120,000ms for i in range(0, num_host - 1): sender = i receiver = num_host - 1 host = "host" + str(sender) if host in udphost: ITGUDPGeneration(sender, receiver, hosts, nodes, bwReq[i] * 125, sTime) else: ITGTCPGeneration(sender, receiver, hosts, nodes, bwReq[i] * 125, sTime) time.sleep(0.2) info("running simulaiton...\n") info("please wait...\n") time.sleep(sTime / 1000) # You need to change the path here os.system("python analysis-9.py") # CLI(net) net.stop() info('*** net.stop()\n')
def myNetwork(): net = Mininet( topo=None, build=False, ipBase='10.0.0.0/8') info( '*** Adding controller\n' ) info( '*** Add switches\n') r6 = net.addHost('r6', cls=Node, ip='0.0.0.0') r6.cmd('sysctl -w net.ipv4.ip_forward=1') r10 = net.addHost('r10', cls=Node, ip='0.0.0.0') r10.cmd('sysctl -w net.ipv4.ip_forward=1') r4 = net.addHost('r4', cls=Node, ip='0.0.0.0') r4.cmd('sysctl -w net.ipv4.ip_forward=1') r5 = net.addHost('r5', cls=Node, ip='0.0.0.0') r5.cmd('sysctl -w net.ipv4.ip_forward=1') r11 = net.addHost('r11', cls=Node, ip='0.0.0.0') r11.cmd('sysctl -w net.ipv4.ip_forward=1') s12 = net.addSwitch('s12', cls=OVSKernelSwitch, failMode='standalone') r8 = net.addHost('r8', cls=Node, ip='0.0.0.0') r8.cmd('sysctl -w net.ipv4.ip_forward=1') r2 = net.addHost('r2', cls=Node, ip='0.0.0.0') r2.cmd('sysctl -w net.ipv4.ip_forward=1') r1 = net.addHost('r1', cls=Node, ip='0.0.0.0') r1.cmd('sysctl -w net.ipv4.ip_forward=1') r9 = net.addHost('r9', cls=Node, ip='0.0.0.0') r9.cmd('sysctl -w net.ipv4.ip_forward=1') r3 = net.addHost('r3', cls=Node, ip='0.0.0.0') r3.cmd('sysctl -w net.ipv4.ip_forward=1') r7 = net.addHost('r7', cls=Node, ip='0.0.0.0') r7.cmd('sysctl -w net.ipv4.ip_forward=1') info( '*** Add hosts\n') info( '*** Add links\n') net.addLink(r1, r2) net.addLink(r2, r3) net.addLink(r3, r4) net.addLink(r4, r5) net.addLink(r5, r6) net.addLink(r6, r7) net.addLink(r7, r8) net.addLink(r8, r9) net.addLink(r9, r10) net.addLink(r10, r11) net.addLink(r11, r1) net.addLink(s12, r4) net.addLink(s12, r5) net.addLink(s12, r6) net.addLink(s12, r7) net.addLink(s12, r8) info( '*** Starting network\n') net.build() info( '*** Starting controllers\n') for controller in net.controllers: controller.start() info( '*** Starting switches\n') net.get('s12').start([]) info( '*** Post configure switches and hosts\n') CLI(net) net.stop()
def sdn1net(): topo = SDNTopo() info('*** Creating network\n') # global net net = Mininet(topo=topo, controller=RemoteController) spk1, spk2, spk3, spk4, p64514, p64515, p64516, p64517, p64518, p64519, p64520 = \ net.get( 'spk1', 'spk2', 'spk3', 'spk4', 'p64514', 'p64515', 'p64516', 'p64517', 'p64518', 'p64519', 'p64520' ) # Adding addresses to speakers' interface connected to sw24 # for BGP peering spk1.setMAC('00:00:00:00:00:01', 'spk1-eth0') spk1.cmd('ip addr add 10.0.4.101/24 dev spk1-eth0') spk1.cmd('ip addr add 10.0.5.101/24 dev spk1-eth0') spk1.cmd('ip addr add 10.0.6.101/24 dev spk1-eth0') spk1.defaultIntf().setIP('10.0.4.101/24') spk1.defaultIntf().setMAC('00:00:00:00:00:01') spk2.setMAC('00:00:00:00:00:02', 'spk2-eth0') spk2.cmd('ip addr add 10.0.14.101/24 dev spk2-eth0') spk2.cmd('ip addr add 10.0.15.101/24 dev spk2-eth0') spk2.cmd('ip addr add 10.0.16.101/24 dev spk2-eth0') spk2.defaultIntf().setIP('10.0.14.101/24') spk2.defaultIntf().setMAC('00:00:00:00:00:02') spk3.setMAC('00:00:00:00:00:03', 'spk3-eth0.10') spk3.cmd('ip addr add 10.0.9.101/24 dev spk3-eth0.10') spk3.cmd('ip addr add 10.0.20.101/24 dev spk3-eth0.10') spk3.defaultIntf().setIP('10.1.9.101/24') spk3.defaultIntf().setMAC('00:00:00:00:00:03') spk4.setMAC('00:00:00:00:00:04', 'spk4-eth0.20') spk4.cmd('ip addr add 10.0.7.101/24 dev spk4-eth0.20') spk4.cmd('ip addr add 10.0.8.101/24 dev spk4-eth0.20') spk4.defaultIntf().setIP('10.1.7.101/24') spk4.defaultIntf().setMAC('00:00:00:00:00:04') p64517.config(vlan=20, intfName="p64517-eth1", ip="7.0.0.254") p64518.config(vlan=20, intfName="p64518-eth1", ip="8.0.0.254") p64519.config(vlan=10, intfName="p64519-eth1", ip="9.0.0.254") p64520.config(vlan=10, intfName="p64520-eth1", ip="20.0.0.254") # Net has to be start after adding the above link net.start() # setup configuration on the interface connected to switch p64514.cmd("ifconfig p64514-eth0 10.0.4.1 up") p64514.cmd("ip addr add 10.0.14.1/24 dev p64514-eth0") p64514.setMAC('00:00:00:00:00:14', 'p64514-eth0') # do not repeat spk4's MAC addr p64515.cmd("ifconfig p64515-eth0 10.0.5.1 up") p64515.cmd("ip addr add 10.0.15.1/24 dev p64515-eth0") p64515.setMAC('00:00:00:00:00:05', 'p64515-eth0') p64516.cmd("ifconfig p64516-eth0 10.0.6.1 up") p64516.cmd("ip addr add 10.0.16.1/24 dev p64516-eth0") p64516.setMAC('00:00:00:00:00:06', 'p64516-eth0') p64517.cmd("ifconfig p64517-eth0.20 10.0.7.1 up") p64517.setMAC('00:00:00:00:00:07', 'p64517-eth0.20') p64518.cmd("ifconfig p64518-eth0.20 10.0.8.1 up") p64518.setMAC('00:00:00:00:00:08', 'p64518-eth0.20') p64519.cmd("ifconfig p64519-eth0.10 10.0.9.1 up") p64519.setMAC('00:00:00:00:00:09', 'p64519-eth0.10') p64520.cmd("ifconfig p64520-eth0.10 10.0.20.1 up") p64520.setMAC('00:00:00:00:00:20', 'p64520-eth0.10') # setup configuration on the interface connected to hosts p64514.setIP("4.0.0.254", 8, "p64514-eth1") p64514.setMAC('00:00:00:00:00:44', 'p64514-eth1') p64515.setIP("5.0.0.254", 8, "p64515-eth1") p64515.setMAC('00:00:00:00:00:55', 'p64515-eth1') p64516.setIP("6.0.0.254", 8, "p64516-eth1") p64516.setMAC('00:00:00:00:00:66', 'p64516-eth1') p64517.setIP("7.0.0.254", 8, "p64517-eth1.20") p64517.setMAC('00:00:00:00:00:77', 'p64517-eth1.20') p64518.setIP("8.0.0.254", 8, "p64518-eth1.20") p64518.setMAC('00:00:00:00:00:88', 'p64518-eth1.20') p64519.setIP("9.0.0.254", 8, "p64519-eth1.10") p64519.setMAC('00:00:00:00:00:99', 'p64519-eth1.10') p64520.setIP("20.0.0.254", 8, "p64520-eth1.10") p64520.setMAC('00:00:00:00:00:20', 'p64520-eth1.10') # enable forwarding on BGP peer hosts p64514.cmd('sysctl net.ipv4.conf.all.forwarding=1') p64515.cmd('sysctl net.ipv4.conf.all.forwarding=1') p64516.cmd('sysctl net.ipv4.conf.all.forwarding=1') p64517.cmd('sysctl net.ipv4.conf.all.forwarding=1') p64518.cmd('sysctl net.ipv4.conf.all.forwarding=1') p64519.cmd('sysctl net.ipv4.conf.all.forwarding=1') p64520.cmd('sysctl net.ipv4.conf.all.forwarding=1') # config interface for control plane connectivity p64514.setIP("192.168.0.4", 24, "p64514-eth2") p64515.setIP("192.168.0.5", 24, "p64515-eth2") p64516.setIP("192.168.0.6", 24, "p64516-eth2") p64517.setIP("192.168.0.7", 24, "p64517-eth2") p64518.setIP("192.168.0.8", 24, "p64518-eth2") p64519.setIP("192.168.0.9", 24, "p64519-eth2") p64520.setIP("192.168.0.20", 24, "p64520-eth2") # Setup hosts in each non-SDN AS h64514, h64515, h64516, h64517, h64518, h64519, h64520 = \ net.get( 'h64514', 'h64515', 'h64516', 'h64517', 'h64518', 'h64519', 'h64520' ) h64514.cmd('ifconfig h64514-eth0 4.0.0.1 up') h64514.cmd('ip route add default via 4.0.0.254') h64514.setIP('192.168.0.44', 24, 'h64514-eth1') # for control plane h64515.cmd('ifconfig h64515-eth0 5.0.0.1 up') h64515.cmd('ip route add default via 5.0.0.254') h64516.cmd('ifconfig h64516-eth0 6.0.0.1 up') h64516.cmd('ip route add default via 6.0.0.254') h64517.cmd('ifconfig h64517-eth0.20 7.0.0.1 up') h64517.cmd('ip route add default via 7.0.0.254') h64517.setIP('192.168.0.77', 24, 'h64517-eth1') # for control plane h64518.cmd('ifconfig h64518-eth0.20 8.0.0.1 up') h64518.cmd('ip route add default via 8.0.0.254') h64519.cmd('ifconfig h64519-eth0.10 9.0.0.1 up') h64519.cmd('ip route add default via 9.0.0.254') h64519.setIP('192.168.0.99', 24, 'h64519-eth1') # for control plane h64520.cmd('ifconfig h64520-eth0.10 20.0.0.1 up') h64520.cmd('ip route add default via 20.0.0.254') # set up swCtl100 as a learning swCtl100 = net.get('swCtl100') swCtl100.cmd('ovs-vsctl set-controller swCtl100 none') swCtl100.cmd('ovs-vsctl set-fail-mode swCtl100 standalone') # connect all switches to controller """ onos1IP = "10.128.4.52" onos2IP = "10.128.4.53" onos3IP = "10.128.4.54" for i in range ( 1, numSw + 1 ): swX = net.get( 'sw%s' % ( i ) ) swX.cmd( 'ovs-vsctl set-controller sw%s tcp:%s:6653 tcp:%s:6653 tcp:%s:6653' % ( i, onos1IP, onos2IP, onos3IP ) ) """ # Start Quagga on border routers startquagga(p64514, 64514, 'quagga64514.conf') startquagga(p64515, 64515, 'quagga64515.conf') startquagga(p64516, 64516, 'quagga64516.conf') startquagga(p64517, 64517, 'quagga64517.conf') startquagga(p64518, 64518, 'quagga64518.conf') startquagga(p64519, 64519, 'quagga64519.conf') startquagga(p64520, 64520, 'quagga64520.conf') # start Quagga in SDN network startquagga(spk1, 64513, 'quagga-sdn.conf') startquagga(spk2, 64512, 'quagga-sdn-speaker2.conf') startquagga(spk3, 64511, 'quagga-sdn3.conf') startquagga(spk4, 64510, 'quagga-sdn4.conf') root = net.get('root') root.intf('root-eth0').setIP('1.1.1.2/24') root.cmd('ip addr add 192.168.0.100/24 dev root-eth0') root.intf('root-eth1').setIP('1.1.1.4/24') root.cmd('ip addr add 192.168.0.101/24 dev root-eth1') root.intf('root-eth2').setIP('1.1.1.6/24') root.cmd('ip addr add 192.168.0.102/24 dev root-eth2') spk1.intf('spk1-eth1').setIP('1.1.1.1/24') spk2.intf('spk2-eth1').setIP('1.1.1.3/24') spk3.intf('spk3-eth1').setIP('1.1.1.5/24') spk4.intf('spk4-eth1').setIP('1.1.1.7/24') stopsshd() hosts = [ p64514, p64515, p64516, p64517, p64518, p64519, p64520, h64514, h64517, h64519 ] startsshds(hosts) """ forwarding1 = '%s:2000:%s:2000' % ( '1.1.1.2', onos1IP ) root.cmd( 'ssh -nNT -o "PasswordAuthentication no" \ -o "StrictHostKeyChecking no" -l sdn -L %s %s & ' % ( forwarding1, onos1IP ) ) forwarding2 = '%s:2000:%s:2000' % ( '1.1.1.4', onos2IP ) root.cmd( 'ssh -nNT -o "PasswordAuthentication no" \ -o "StrictHostKeyChecking no" -l sdn -L %s %s & ' % ( forwarding2, onos2IP ) ) forwarding3 = '%s:2000:%s:2000' % ( '1.1.1.6', onos3IP ) root.cmd( 'ssh -nNT -o "PasswordAuthentication no" \ -o "StrictHostKeyChecking no" -l sdn -L %s %s & ' % ( forwarding3, onos3IP ) ) """ CLI(net) stopsshd() stopquagga() net.stop()
class Minindn(object): """ This class provides the following features to the user: 1) Wrapper around Mininet object with option to pass topology directly 1.1) Users can pass custom argument parser to extend the default on here 2) Parses the topology file given via command line if user does not pass a topology object 3) Provides way to stop Mini-NDN via stop 3.1) Applications register their clean up function with this class 4) Sets IPs on neighbors for connectivity required in a switch-less topology 5) Some other utility functions """ ndnSecurityDisabled = False workDir = '/tmp/minindn' resultDir = None def __init__(self, parser=argparse.ArgumentParser(), topo=None, topoFile=None, noTopo=False, link=TCLink, **mininetParams): """ Create MiniNDN object :param parser: Parent parser of Mini-NDN parser :param topo: Mininet topo object (optional) :param topoFile: Mininet topology file location (optional) :param noTopo: Allows specification of topology after network object is initialized (optional) :param link: Allows specification of default Mininet link type for connections between nodes (optional) :param mininetParams: Any params to pass to Mininet """ self.parser = Minindn.parseArgs(parser) self.args = self.parser.parse_args() Minindn.workDir = os.path.abspath(self.args.workDir) Minindn.resultDir = self.args.resultDir if not topoFile: # Args has default topology if none specified self.topoFile = self.args.topoFile else: self.topoFile = topoFile if topo is None and not noTopo: try: info('Using topology file {}\n'.format(self.topoFile)) self.topo = self.processTopo(self.topoFile) except configparser.NoSectionError as e: info('Error reading config file: {}\n'.format(e)) sys.exit(1) else: self.topo = topo if not noTopo: self.net = Mininet(topo=self.topo, link=link, **mininetParams) else: self.net = Mininet(link=link, **mininetParams) self.initParams(self.net.hosts) self.cleanups = [] if not self.net.switches: self.ethernetPairConnectivity() try: process = Popen(['ndnsec-get-default', '-k'], stdout=PIPE, stderr=PIPE) output, error = process.communicate() if process.returncode == 0: Minindn.ndnSecurityDisabled = '/dummy/KEY/-%9C%28r%B8%AA%3B%60' in output info('Dummy key chain patch is installed in ndn-cxx. Security will be disabled.\n') else: debug(error) except: pass @staticmethod def parseArgs(parent): parser = argparse.ArgumentParser(prog='minindn', parents=[parent], add_help=False) # nargs='?' required here since optional argument parser.add_argument('topoFile', nargs='?', default='/usr/local/etc/mini-ndn/default-topology.conf', help='If no template_file is given, topologies/default-topology.conf will be used.') parser.add_argument('--work-dir', action='store', dest='workDir', default='/tmp/minindn', help='Specify the working directory; default is /tmp/minindn') parser.add_argument('--result-dir', action='store', dest='resultDir', default=None, help='Specify the full path destination folder where experiment results will be moved') return parser def ethernetPairConnectivity(self): ndnNetBase = '10.0.0.0' interfaces = [] for host in self.net.hosts: for intf in host.intfList(): link = intf.link node1, node2 = link.intf1.node, link.intf2.node if isinstance(node1, Switch) or isinstance(node2, Switch): 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) @staticmethod def processTopo(topoFile): config = configparser.ConfigParser(delimiters=' ', allow_no_value=True) config.read(topoFile) topo = Topo() items = config.items('nodes') coordinates = [] for item in items: name = item[0].split(':')[0] params = {} if item[1]: if all (x in item[1] for x in ['radius', 'angle']) and item[1] in coordinates: error("FATAL: Duplicate Coordinate, \'{}\' used by multiple nodes\n" \ .format(item[1])) sys.exit(1) coordinates.append(item[1]) for param in item[1].split(' '): if param == '_': continue params[param.split('=')[0]] = param.split('=')[1] topo.addHost(name, params=params) try: items = config.items('switches') for item in items: name = item[0].split(':')[0] topo.addSwitch(name) except configparser.NoSectionError: # Switches are optional pass items = config.items('links') for item in items: link = item[0].split(':') params = {} for param in item[1].split(' '): key = param.split('=')[0] value = param.split('=')[1] if key in ['bw', 'jitter', 'max_queue_size']: value = int(value) if key == 'loss': value = float(value) params[key] = value topo.addLink(link[0], link[1], **params) return topo def start(self): self.net.start() time.sleep(3) def stop(self): for cleanup in self.cleanups: cleanup() self.net.stop() if Minindn.resultDir is not None: info("Moving results to \'{}\'\n".format(Minindn.resultDir)) os.system("mkdir -p {}".format(Minindn.resultDir)) for file in glob.glob('{}/*'.format(Minindn.workDir)): shutil.move(file, Minindn.resultDir) @staticmethod def cleanUp(): devnull = open(os.devnull, 'w') call('nfd-stop', stdout=devnull, stderr=devnull) call('mn --clean'.split(), stdout=devnull, stderr=devnull) @staticmethod def verifyDependencies(): """Prevent MiniNDN from running without necessary dependencies""" dependencies = ['nfd', 'nlsr', 'infoedit', 'ndnping', 'ndnpingserver'] devnull = open(os.devnull, 'w') # Checks that each program is in the system path for program in dependencies: if call(['which', program], stdout=devnull): error('{} is missing from the system path! Exiting...\n'.format(program)) sys.exit(1) devnull.close() @staticmethod def sleep(seconds): # sleep is not required if ndn-cxx is using in-memory keychain if not Minindn.ndnSecurityDisabled: time.sleep(seconds) @staticmethod def handleException(): """Utility method to perform cleanup steps and exit after catching exception""" Minindn.cleanUp() info(format_exc()) exit(1) def initParams(self, nodes): """Initialize Mini-NDN parameters for array of nodes""" for host in nodes: if 'params' not in host.params: host.params['params'] = {} host.params['params']['workDir'] = Minindn.workDir homeDir = '{}/{}'.format(Minindn.workDir, host.name) host.params['params']['homeDir'] = homeDir host.cmd('mkdir -p {}'.format(homeDir)) host.cmd('export HOME={} && cd ~'.format(homeDir))
def MyTopo(): switch = partial(OVSSwitch, protocols='OpenFlow13') net = Mininet(topo=None, build=False, ipBase='10.0.0.0/24', switch=switch) info('*** Adding controller\n') c1 = net.addController(name='c1', controller=RemoteController, ip='127.0.0.1', protocol='tcp', port=6633) info('*** Add switches\n') s1 = net.addSwitch('s1', cls=OVSKernelSwitch, protocols='OpenFlow13', dpid='1') s2 = net.addSwitch('s2', cls=OVSKernelSwitch, protocols='OpenFlow13', dpid='2') s3 = net.addSwitch('s3', cls=OVSKernelSwitch, protocols='OpenFlow13', dpid='3') s4 = net.addSwitch('s4', cls=OVSKernelSwitch, protocols='OpenFlow13', dpid='4') s5 = net.addSwitch('s5', cls=OVSKernelSwitch, protocols='OpenFlow13', dpid='5') s6 = net.addSwitch('s6', cls=OVSKernelSwitch, protocols='OpenFlow13', dpid='6') info('*** Add hosts\n') cdn = net.addHost('h1', cls=Host, ip='10.0.0.1/24', mac='00:00:00:00:00:01', defaultRoute=None) user1 = net.addHost('h2', cls=Host, ip='10.0.0.2/24', mac='00:00:00:00:00:02', defaultRoute=None) user2 = net.addHost('h3', cls=Host, ip='10.0.0.3/24', mac='00:00:00:00:00:03', defaultRoute=None) info('*** Add links\n') # Switch 1 net.addLink(s1, s2, port1=1, port2=1) net.addLink(s1, s3, port1=2, port2=1) # Switch 2 net.addLink(s2, s3, port1=2, port2=2) net.addLink(s2, cdn, port1=3) # Switch 3 net.addLink(s3, s4, port1=3, port2=1) # Switch 4 net.addLink(s4, s5, port1=2, port2=1) net.addLink(s4, s6, port1=3, port2=1) # Switch 5 net.addLink(s5, s6, port1=2, port2=2) net.addLink(s5, user2, port1=3) # Switch 6 net.addLink(s6, user1, port1=3) info('*** Starting network\n') net.build() info('*** Starting controllers\n') for controller in net.controllers: controller.start() info('*** Starting switches\n') net.get('s1').start([c1]) net.get('s3').start([c1]) net.get('s2').start([c1]) net.get('s4').start([c1]) net.get('s5').start([c1]) net.get('s6').start([c1]) info('*** Post configure switches and hosts\n') CLI(net) net.stop()
def emptyNet(dl, baw, ls, qs): #Conditioning parameters to be as per user or default values if user provided minimum/maximum values if dl == 0: dl = None else: dl = str(dl) + 'ms' if baw == 1000: baw = None if ls == 0: ls = None if qs == 1000: qs = None ####################################### # Run mininet ####################################### net = Mininet( topo=None, build=False,host=CPULimitedHost,link=TCLink ) info( '*** Adding controller\n' ) net.addController('c0', controller=RemoteController,ip="127.0.0.1",port=6633) #A dummy host to attach with controller and then connect that host with a switch h0 = net.addHost('h0', ip='127.0.0.1') info( '*** Adding hosts\n' ) host = [] switch = [] for i in range(10): host.append(net.addHost('h' + str(i+1))) for i in range(10): switch.append(net.addSwitch('s' + str(i+1), cls=OVSSwitch)) info( '*** Creating links\n' ) ## controller - switch (s1) net.addLink( h0, switch[0] ) ## host - switch for i in range(10): net.addLink(host[i], switch[i], delay=dl, loss=ls, max_queue_size=qs,bw=baw) ## switche links for index in range (0, len(switch)-1): net.addLink(switch[index], switch[index+1],bw = baw,delay=dl,loss=ls,max_queue_size=qs) net.addLink(switch[0], switch[9],bw=baw,loss=ls,delay=dl,max_queue_size=qs) info( '*** Starting network\n') net.start() #Set ip address to switch for i in range (10): switch[i].cmd('ifconfig s' + str(i+1) + ' 10.0.1.' + str(i+1)) info('*** Enable spanning tree\n') for i in range(10): switch[i].cmd('ovs-vsctl set bridge s' + str(i+1) + 'stp-enable=true') info( '*** Running CLI\n' ) CLI( net ) info( '*** Stopping network' ) net.stop()
def emptyNet(): switch = partial(OVSSwitch, protocols='OpenFlow13') link = partial(TCLink, bw=100) topo = SpineLeaf(leaves=3) net = Mininet(controller=RemoteController, switch=switch, link=link, topo=topo, build=False, autoSetMacs=True) controllers = [] controllers.append( net.addController('c1', controller=RemoteController, ip="172.17.0.5", port=6633)) controllers.append( net.addController('c2', controller=RemoteController, ip="172.17.0.6", port=6633)) controllers.append( net.addController('c3', controller=RemoteController, ip="172.17.0.7", port=6633)) net.build() net.start() # trigger() # time.sleep(5) h1 = net.getNodeByName("h1") h3 = net.getNodeByName("h3") # log_output = "iperf_log_" # log_index = 1 # log_dir = "capturas/" # log_path = log_dir+log_output+str(log_index) # while os.path.exists(log_path): # log_index += 1 # log_path = log_dir+log_output+str(log_index) # if not os.path.exists(log_dir): # os.mkdir(log_dir) # h3.cmdPrint("iperf -s -p 3434 &") # h3.cmdPrint("iperf --udp -s -p 3434 &") # h1.cmdPrint("iperf -c 10.0.0.3 -p 3434 -t 60 -b 100000000") # h1.cmdPrint("iperf -c 10.0.0.3 --udp -p 3434 -t 50 -b 100000000 >> %s &" % (log_path)) # capture("falha-controlador-s3-eth2","s3-eth2",timeout=40) # capture("falha-controlador-s3-eth1","s3-eth1",timeout=40) # time.sleep(15) # os.system("docker container stop onos-3") # checkStart() # time.sleep(15) CLI(net) net.stop()
class SclNet(object): def __init__(self, topo='fattree_outband', app='shortest', ch='udp'): self.switches = [] self.hosts = [] self.topo = topo # NOTE: hard code now, use config file instead self.ctrls = [1, 13] k = 6 setLogLevel(LOG_LEVEL) # set up topology skeleton if self.topo == 'fattree_inband': self.skeleton = FatTree(k, self.switches, self.hosts) elif self.topo == 'fattree_outband': self.skeleton = FatTreeOutBand(k, self.switches, self.hosts, self.ctrls) # autoStaticArp doesnt works well, because we will move the IP in # the host interface to the internal port of the switch self.net = Mininet(topo=self.skeleton, controller=None, link=TCLink) # write topology to file self.file_name = os.path.abspath('../conf') + '/' + topo + '.json' topo2file(self.file_name, self.net, self.switches, self.hosts, self.ctrls) self.net.getNodeByName( "s000").cmdPrint("bash RunMe.sh Flows_NORMAL_RUNNING.txt " + str(int(k * k * 1.25)) + " &") self.write_conf_to_file() if app == 'clean': return self.set_static_arps() # set up ovs in each switch namespace if topo == 'fattree_inband': self.start_switch() self.start_inband_connection() self.config_ctrl_routing('inband') self.start_controller(app) self.start_scl_proxy(ch) self.start_scl_agent(ch) if topo == 'fattree_outband': self.start_dp_switch() self.start_ctrl_switch() self.config_ctrl_routing('outband') self.start_outband_connection() self.start_controller(app) self.start_scl_proxy(ch) self.start_scl_agent(ch) def write_conf_to_file(self): agent_list = [] proxy_list = [] for sw_name in self.switches: sw = self.net.getNodeByName(sw_name) agent_list.append(sw.IP()) for ctrl in self.ctrls: host = self.net.getNodeByName(self.hosts[ctrl]) proxy_list.append(host.IP()) config = ConfigParser.ConfigParser() config.add_section('interfaces') config.set('interfaces', 'agent_list', json.dumps(agent_list)) config.set('interfaces', 'proxy_list', json.dumps(proxy_list)) with open(CONF_FILE, 'wb') as configfile: config.write(configfile) def set_static_arps(self): ctrls = [self.hosts[ctrl] for ctrl in self.ctrls] hosts = [host for host in self.hosts if host not in ctrls] arps = [] for host_name in hosts: host = self.net.getNodeByName(host_name) arps.append((host.IP(), host.MAC())) for host_name in hosts: host = self.net.getNodeByName(host_name) for arp in arps: if arp[0] == host.IP(): continue host.cmdPrint('arp -s %s %s' % (arp[0], arp[1])) def start_scl_agent(self, ch): sw_id = 0 for sw_name in self.switches: sw = self.net.getNodeByName(sw_name) sw.cmd( 'cd .. && python ./scl_agent.py %d %s --debug > ./log/scl_agent_%d.log 2>&1 &' % (sw_id, ch, sw_id)) sw_id = sw_id + 1 def start_scl_proxy(self, ch): ctrl_id = 0 ctrls_num = len(self.ctrls) for ctrl in self.ctrls: host = self.net.getNodeByName(self.hosts[ctrl]) host.cmdPrint( 'cd .. && python ./scl_proxy.py %d %s --debug > ./log/scl_proxy_%d.log 2>&1 &' % (ctrl_id, ch, ctrl_id)) ctrl_id = ctrl_id + 1 def start_controller(self, app): ctrl_id = 0 pox_format = '"%(asctime)s - %(name)s - %(levelname)s - %(message)s"' pox_datefmt = '"%Y%m%d %H:%M:%S"' for ctrl in self.ctrls: host = self.net.getNodeByName(self.hosts[ctrl]) # NOTE: hard code #host.cmd('python pox/pox.py log.level --DEBUG log --file=log/ctrl_%d.log,w --format=%s --datefmt=%s scl_routing --name=%s &' % (ctrl_id, pox_format, pox_datefmt, self.file_name)) if app == 'shortest': # host.cmdPrint('tshark -i any -s 7000 -w FirstResult_' + str(ctrl_id) + '.pcap -a duration:45 &') host.cmdPrint( 'cd ../floodlight && java -jar target/floodlight.jar ' + '> /home/saimsalman/Desktop/scl/log/ctrl_' + str(ctrl_id) + '.log &') # host.cmd('cd .. && python pox/pox.py log.level --DEBUG log --format=%s --datefmt=%s scl_routing --name=%s > log/ctrl_%d.log 2>&1 &' % (pox_format, pox_datefmt, self.file_name, ctrl_id)) elif app == 'te': host.cmd( 'cd .. && python pox/pox.py log.level --DEBUG log --format=%s --datefmt=%s scl_te --name=%s > log/ctrl_%d.log 2>&1 &' % (pox_format, pox_datefmt, self.file_name, ctrl_id)) ctrl_id = ctrl_id + 1 def start_switch(self): for sw_name in self.switches: sw = self.net.getNodeByName(sw_name) sw.cmdPrint('%s/start_ovs.sh %s' % (DIR, sw_name)) sw.cmdPrint('%s/create_br.sh %s' % (DIR, sw_name)) def start_dp_switch(self): for sw_name in self.switches: sw = self.net.getNodeByName(sw_name) sw.cmdPrint('%s/start_ovs.sh %s' % (DIR, sw_name)) sw.cmdPrint('%s/create_dp_br.sh %s' % (DIR, sw_name)) def start_ctrl_switch(self): for sw_name in self.switches: sw_name = 'c' + sw_name[1:] sw = self.net.getNodeByName(sw_name) sw.cmdPrint('%s/start_ovs.sh %s' % (DIR, sw_name)) sw.cmdPrint('%s/create_ctrl_br.sh %s' % (DIR, sw_name)) def config_ctrl_routing(self, topo): for ctrl in self.ctrls: host = self.net.getNodeByName(self.hosts[ctrl]) ip = host.IP() # config ip to control plane interface # add default route to send broadcast msg if topo == 'outband': host.cmdPrint('ifconfig %s-eth0 0' % self.hosts[ctrl]) host.cmdPrint('ifconfig %s-eth1 %s/8' % (self.hosts[ctrl], ip)) host.cmdPrint('route add default gw %s' % ip) elif topo == 'inband': host.cmdPrint('route add -host 255.255.255.255 dev %s-eth0' % self.hosts[ctrl]) def config_ctrl_vlan(self): # set vlan to some sw ports which connect to controller hosts for ctrl in self.ctrls: host = self.net.getNodeByName(self.hosts[ctrl]) host_intf = host.intfList()[0] sw_intf = host_intf.link.intf1\ if host_intf.link.intf1 is not host_intf\ else host_intf.link.intf2 sw_name = sw_intf.name.split('-')[0] sw = self.net.getNodeByName(sw_name) # sw.ports index starts from 0, ovs index starts from 1 sw_port = sw.ports[sw_intf] + 1 port_list = [1, 2, 3, 4, 5, 6, 7, 8, 9] port_list.remove(sw_port) self.net.getNodeByName(sw_name).cmdPrint( '%s/config_ctrl_vlan.sh %s %s %d %d %d %d' % (DIR, sw_name, sw_intf.name, sw_port, port_list[0], port_list[1], port_list[2])) def start_inband_connection(self): sw = self.net.getNodeByName(self.switches[3]) #sw.cmdPrint('tcpdump -i lo -enn -w s003.pcap &') for sw_name in self.switches: sw = self.net.getNodeByName(sw_name) sw.cmdPrint('%s/start_inband_connection.sh %s' % (DIR, sw_name)) self.config_ctrl_vlan() def start_outband_connection(self): sw = self.net.getNodeByName(self.switches[3]) #sw.cmdPrint('tcpdump -i lo -enn -w s003.pcap &') for sw_name in self.switches: sw = self.net.getNodeByName(sw_name) sw_intf = sw.intfList()[-1] ctrl_intf = sw_intf.link.intf1\ if sw_intf.link.intf1 is not sw_intf\ else sw_intf.link.intf2 ctrl_name = ctrl_intf.name.split('-')[0] assert ctrl_name[0] == 'c' output = sw.ports[sw_intf] + 1 sw.cmdPrint('%s/start_outband_connection.sh %s %d' % (DIR, sw_name, output)) def run(self): CLI(self.net) def clearSwitches(self): sw = self.net.getNodeByName(self.switches[0]) sw.cmdPrint('%s/stop_scl.sh' % DIR) sw.cmdPrint('ps -ef | grep scl') sw.cmdPrint('ps -ef | grep pox') for sw_name in self.switches: sw = self.net.getNodeByName(sw_name) sw.cmdPrint('%s/clear_all.sh %s' % (DIR, sw_name)) if self.topo == 'fattree_outband': for sw_name in self.switches: sw_name = 'c' + sw_name[1:] sw = self.net.getNodeByName(sw_name) sw.cmdPrint('%s/clear_all.sh %s' % (DIR, sw_name)) def stop(self): self.clearSwitches() self.net.stop()
def myNetwork(): net = Mininet(topo=None, build=False, ipBase='10.0.0.0/8') info('*** Adding controller\n') c0 = net.addController(name='c0', controller=Controller, protocol='tcp', port=6653, ip='192.168.122.1') info('*** Add switches\n') s1 = net.addSwitch('s1', cls=OVSKernelSwitch) s2 = net.addSwitch('s2', cls=OVSKernelSwitch) s7 = net.addSwitch('s7', cls=OVSKernelSwitch) s6 = net.addSwitch('s6', cls=OVSKernelSwitch) s8 = net.addSwitch('s8', cls=OVSKernelSwitch) s5 = net.addSwitch('s5', cls=OVSKernelSwitch) s3 = net.addSwitch('s3', cls=OVSKernelSwitch) s4 = net.addSwitch('s4', cls=OVSKernelSwitch) info('*** Add hosts\n') h11 = net.addHost('h11', cls=Host, ip='10.0.0.11', defaultRoute=None) h13 = net.addHost('h13', cls=Host, ip='10.0.0.13', defaultRoute=None) h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None) h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None) h19 = net.addHost('h19', cls=Host, ip='10.0.0.19', defaultRoute=None) h29 = net.addHost('h29', cls=Host, ip='10.0.0.29', defaultRoute=None) h17 = net.addHost('h17', cls=Host, ip='10.0.0.17', defaultRoute=None) h14 = net.addHost('h14', cls=Host, ip='10.0.0.14', defaultRoute=None) h25 = net.addHost('h25', cls=Host, ip='10.0.0.25', defaultRoute=None) h27 = net.addHost('h27', cls=Host, ip='10.0.0.27', defaultRoute=None) h24 = net.addHost('h24', cls=Host, ip='10.0.0.24', defaultRoute=None) h12 = net.addHost('h12', cls=Host, ip='10.0.0.12', defaultRoute=None) h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None) h34 = net.addHost('h34', cls=Host, ip='10.0.0.34', defaultRoute=None) h22 = net.addHost('h22', cls=Host, ip='10.0.0.22', defaultRoute=None) h10 = net.addHost('h10', cls=Host, ip='10.0.0.10', defaultRoute=None) h30 = net.addHost('h30', cls=Host, ip='10.0.0.30', defaultRoute=None) h32 = net.addHost('h32', cls=Host, ip='10.0.0.32', defaultRoute=None) h8 = net.addHost('h8', cls=Host, ip='10.0.0.8', defaultRoute=None) h7 = net.addHost('h7', cls=Host, ip='10.0.0.7', defaultRoute=None) h9 = net.addHost('h9', cls=Host, ip='10.0.0.9', defaultRoute=None) h20 = net.addHost('h20', cls=Host, ip='10.0.0.20', defaultRoute=None) h15 = net.addHost('h15', cls=Host, ip='10.0.0.15', defaultRoute=None) h33 = net.addHost('h33', cls=Host, ip='10.0.0.33', defaultRoute=None) h16 = net.addHost('h16', cls=Host, ip='10.0.0.16', defaultRoute=None) h18 = net.addHost('h18', cls=Host, ip='10.0.0.18', defaultRoute=None) h31 = net.addHost('h31', cls=Host, ip='10.0.0.31', defaultRoute=None) h23 = net.addHost('h23', cls=Host, ip='10.0.0.23', defaultRoute=None) h6 = net.addHost('h6', cls=Host, ip='10.0.0.6', defaultRoute=None) h26 = net.addHost('h26', cls=Host, ip='10.0.0.26', defaultRoute=None) h21 = net.addHost('h21', cls=Host, ip='10.0.0.21', defaultRoute=None) h4 = net.addHost('h4', cls=Host, ip='10.0.0.4', defaultRoute=None) h5 = net.addHost('h5', cls=Host, ip='10.0.0.5', defaultRoute=None) h28 = net.addHost('h28', cls=Host, ip='10.0.0.28', defaultRoute=None) info('*** Add links\n') net.addLink(h24, s1) net.addLink(h28, s1) net.addLink(h29, s1) net.addLink(h25, s1) net.addLink(h26, s1) net.addLink(h27, s1) net.addLink(s1, s7) net.addLink(s8, s3) net.addLink(s8, s4) net.addLink(s6, s7) net.addLink(s5, h11) net.addLink(s5, h7) net.addLink(s5, h8) net.addLink(s5, h10) net.addLink(s5, h9) net.addLink(s4, h12) net.addLink(s4, h13) net.addLink(s4, h14) net.addLink(s4, h15) net.addLink(s4, h16) net.addLink(s3, h17) net.addLink(s3, h18) net.addLink(s3, h19) net.addLink(s3, h20) net.addLink(s3, h21) net.addLink(s3, h23) net.addLink(s3, h22) net.addLink(s2, h34) net.addLink(s2, h33) net.addLink(s2, h30) net.addLink(s2, h31) net.addLink(s2, h32) net.addLink(s6, h5) net.addLink(s6, h1) net.addLink(s6, h2) net.addLink(s6, h3) net.addLink(s6, h4) net.addLink(s6, h6) net.addLink(s7, s2) net.addLink(s8, s2) net.addLink(s5, s8) net.addLink(s7, s5) info('*** Starting network\n') net.build() info('*** Starting controllers\n') for controller in net.controllers: controller.start() info('*** Starting switches\n') net.get('s1').start([c0]) net.get('s2').start([c0]) net.get('s7').start([c0]) net.get('s6').start([c0]) net.get('s8').start([c0]) net.get('s5').start([c0]) net.get('s3').start([c0]) net.get('s4').start([c0]) info('*** Post configure switches and hosts\n') CLI(net) net.stop()
def createNetwork(): #send rate at each link in Mbps bwg = 1 #in Mbps bwbn = 1 #in Mbps loss = 8 #in % mqs = 100 #max queue size of interfaces dly = '2.5ms' #create empty network net = Mininet(intf=TCIntf) info('\n*** Adding controller\n') net.addController('c0') #is it ok ? #add host to topology ht = net.addHost('ht', ip='10.10.0.1/24') hu = net.addHost('hu', ip='10.10.0.2/24') it = net.addHost('it', ip='10.20.0.1/24') iu = net.addHost('iu', ip='10.20.0.2/24') rh = net.addHost('rh', ip='10.10.0.10/24') ri = net.addHost('ri', ip='10.20.0.20/24') info('\n** Adding Switches\n') # Adding 2 switches to the network sw1 = net.addSwitch('sw1') sw2 = net.addSwitch('sw2') info('\n** Creating Links \n') #create link beetween the network link_ht_sw1 = net.addLink(ht, sw1) link_hu_sw1 = net.addLink(hu, sw1) link_rh_sw1 = net.addLink(rh, sw1, intfName1='rh-eth0') link_it_sw2 = net.addLink(it, sw2) link_iu_sw2 = net.addLink(iu, sw2) link_ri_sw2 = net.addLink(ri, sw2, intfName1='ri-eth0') link_rh_ri = net.addLink(rh, ri, intfName1='rh-eth1', intfName2='ri-eth1') #set bandwith link_ht_sw1.intf1.config(bw=bwbn, max_queue_size=mqs) link_hu_sw1.intf1.config(bw=bwbn, max_queue_size=mqs) link_rh_sw1.intf1.config( bw=bwbn, max_queue_size=mqs ) #max_queue_size is hardcoded low to prevent bufferbloat, too high queuing delays link_it_sw2.intf1.config(bw=bwg, max_queue_size=mqs) link_iu_sw2.intf1.config(bw=bwg, max_queue_size=mqs) link_ri_sw2.intf1.config(bw=bwg, max_queue_size=mqs, delay=dly) #delay is set at ri on both interfaces link_rh_ri.intf1.config( bw=bwg, max_queue_size=mqs, loss=loss) #loss is set at rh on its interface to ri only link_ht_sw1.intf2.config(bw=bwbn, max_queue_size=mqs) link_hu_sw1.intf2.config(bw=bwbn, max_queue_size=mqs) link_rh_sw1.intf2.config(bw=bwbn, max_queue_size=mqs) link_it_sw2.intf2.config(bw=bwg, max_queue_size=mqs) link_iu_sw2.intf2.config(bw=bwg, max_queue_size=mqs) link_ri_sw2.intf2.config(bw=bwg, max_queue_size=mqs) link_rh_ri.intf2.config(bw=bwg, max_queue_size=mqs, delay=dly) #delay is set at ri on both interfaces net.start() info('\n*** Configuring hosts\n') rh.cmd( 'ifconfig rh-eth1 10.12.0.10 netmask 255.255.255.0' ) #reconfiguring mutiples intefaces host to prevent mininet strange initialisation behaviors rh.cmd('ifconfig rh-eth0 10.10.0.10 netmask 255.255.255.0') rh.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward' ) #enable forwarding at routers ri.cmd( 'ifconfig ri-eth1 10.12.0.20 netmask 255.255.255.0' ) #reconfiguring mutiples intefaces host to prvent mininet strange initialisation behaviors ri.cmd('ifconfig ri-eth0 10.20.0.20 netmask 255.255.255.0') ri.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward' ) #enable forwarding at routers #configure host default gateways ht.cmd('ip route add default via 10.10.0.10') hu.cmd('ip route add default via 10.10.0.10') it.cmd('ip route add default via 10.20.0.20') iu.cmd('ip route add default via 10.20.0.20') #configure router routing tables rh.cmd('ip route add default via 10.12.0.20') ri.cmd('ip route add default via 10.12.0.10') # weiyu: iu.cmd('touch server.pcap') hu.cmd('touch client.pcap') rh.cmd('tc qdisc del dev rh-eth1 root') start_nodes(rh, ri, iu, hu, mqs) #experiment actions it.cmd( 'ethtool -K it-eth0 tx off sg off tso off' ) #disable TSO on TCP on defaul TCP sender need to be done on other host if sending large TCP file from other nodes time.sleep(1) # Enable the mininet> prompt if uncommented info('\n*** Running CLI\n') CLI(net) # stops the simulation net.stop()
class ONOSCluster(Controller): "ONOS Cluster" # Offset for port forwarding portOffset = 0 def __init__(self, *args, **kwargs): """name: (first parameter) *args: topology class parameters ipBase: IP range for ONOS nodes forward: default port forwarding list portOffset: offset to port base (optional) topo: topology class or instance nodeOpts: ONOSNode options debug: enabling debug mode or not **kwargs: additional topology parameters By default, multiple ONOSClusters will increment the portOffset automatically; alternately, it can be specified explicitly. """ args = list(args) name = args.pop(0) topo = kwargs.pop('topo', None) self.nat = kwargs.pop('nat', 'nat0') nodeOpts = kwargs.pop('nodeOpts', {}) self.portOffset = kwargs.pop('portOffset', ONOSCluster.portOffset) # Pass in kwargs to the ONOSNodes instead of the cluster "alertAction: exception|ignore|warn|exit (exception)" alertAction = kwargs.pop('alertAction', None) if alertAction: nodeOpts['alertAction'] = alertAction # Default: single switch with 1 ONOS node if not topo: topo = SingleSwitchTopo if not args: args = (1, ) if not isinstance(topo, Topo): topo = RenamedTopo(topo, *args, hnew='onos', **kwargs) self.ipBase = kwargs.pop('ipBase', '192.168.123.0/24') self.forward = kwargs.pop('forward', [KarafPort, GUIPort, OpenFlowPort]) self.debug = kwargs.pop('debug', 'False') == 'True' super(ONOSCluster, self).__init__(name, inNamespace=False) fixIPTables() self.env = initONOSEnv() self.net = Mininet(topo=topo, ipBase=self.ipBase, host=partial(ONOSNode, **nodeOpts), switch=LinuxBridge, controller=None) if self.nat: self.net.addNAT(self.nat).configDefault() updateNodeIPs(self.env, self.nodes()) self._remoteControllers = [] # Update port offset for more ONOS clusters ONOSCluster.portOffset += len(self.nodes()) def start(self): "Start up ONOS cluster" info('*** ONOS_APPS = %s\n' % ONOS_APPS) self.net.start() for node in self.nodes(): node.start(self.env, self.nodes(), self.debug) info('\n') self.configPortForwarding(ports=self.forward, action='A') self.waitStarted() return def waitStarted(self): "Wait until all nodes have started" startTime = time.time() for node in self.nodes(): info(node) node.waitStarted() info('*** Waited %.2f seconds for ONOS startup' % (time.time() - startTime)) def stop(self): "Shut down ONOS cluster" self.configPortForwarding(ports=self.forward, action='D') for node in self.nodes(): node.stop() self.net.stop() def nodes(self): "Return list of ONOS nodes" return [h for h in self.net.hosts if isONOSNode(h)] def configPortForwarding(self, ports=[], action='A'): """Start or stop port forwarding (any intf) for all nodes ports: list of ports to forward action: A=add/start, D=delete/stop (default: A)""" self.cmd('iptables -' + action, 'FORWARD -d', self.ipBase, '-j ACCEPT') for port in ports: for index, node in enumerate(self.nodes()): ip, inport = node.IP(), port + self.portOffset + index # Configure a destination NAT rule self.cmd('iptables -t nat -' + action, 'PREROUTING -t nat -p tcp --dport', inport, '-j DNAT --to-destination %s:%s' % (ip, port)) def getONOSNode(self, instance): """Return ONOS node which name is 'instance' instance: ONOS instance name""" try: onos = self.net.getNodeByName(instance) if isONOSNode(onos): return onos else: info('instance %s is not ONOS.\n' % instance) except KeyError: info('No such ONOS instance %s.\n' % instance)
def run(): # Creating the network according to Fig1. of PDF info( 'Creating the network' ) net = Mininet( controller=RemoteController, switch=OVSSwitch ) # Controller info( '*** Adding controller\n' ) # Without any additional parameters, by default Mininet will look into 127.0.0.1:6633 for the controller # This is consistent with RYU controller's default settings c0 = RemoteController('c0') net.addController(c0) info( '*** Adding hosts, switches and host-switch links\n' ) switches = [] for h in range(4): n = h + 1 # We assign distinguishable dpid (datapath ID) to each switch for easy management switch = net.addSwitch('SW%s' % n, dpid='0%s0%s1ca21ab40%s0%s' % (n, n, n, n), protocols='OpenFlow13', datapath='user' ) switches.append(switch) messg = 'Adding switch %s\n' % switches[h] info(messg) # We assigned distinguishable mac-addresses to each host if n % 2 == 0: host = net.addHost( 'h%s' % n, ip='10.10.1.%s/24' % (n-1), mac='1c:a2:1a:b4:00:0%s' % n ) messg = 'Adding host %s\n' % host.name info(messg) net.addLink(switch, host) else: host = net.addHost( 'h%s' % n, ip='10.10.1.%s/24' % n, mac='1c:a2:1a:b4:01:0%s' % n ) messg = 'Adding host %s\n' % host.name info(messg) net.addLink(switch, host) continue info( '*** Adding additional switches\n' ) for h in range(5, 9): # We assigned distinguishable dpid (datapath ID) to each switch for easy management mac='%s0:%s1:1c:a2:1a:b4' switch = net.addSwitch('SW%s' % h, dpid='0%s0%s1ca21ab40%s0%s' % (h, h, h, h), protocols='OpenFlow13', datapath='user' ) switches.append(switch) messg = 'Adding switch %s\n' % switches[h-1] info(messg) info( '*** Creating Additional Links\n' ) # We match Fig. 1 of PDF # Connections on SW1 net.addLink( switches[0], switches[4]) net.addLink( switches[0], switches[6]) # Connections on SW3 net.addLink( switches[2], switches[7]) net.addLink( switches[2], switches[5]) # Connections on SW2 net.addLink( switches[1], switches[4]) net.addLink( switches[1], switches[5]) # Connections on SW4 net.addLink( switches[3], switches[7]) net.addLink( switches[3], switches[6]) # Creating the Core mesh net.addLink( switches[4], switches[6]) #SW5, SW7 net.addLink( switches[5], switches[7]) #SW6, SW8 net.addLink( switches[4], switches[5]) #SW5, SW6 net.addLink( switches[6], switches[7]) #SW7, SW8 net.addLink( switches[4], switches[7]) #SW5, SW8 net.addLink( switches[5], switches[6]) #SW6, SW7 info( '*** Starting network\n') net.start() info( '*** Running CLI\n' ) CLI( net ) info( '*** Stopping network' ) net.stop()
def myNetwork(): net = Mininet(topo=None, build=False, ipBase='10.0.0.0/8') info('*** Adding controller\n') c0 = net.addController(name='c0', controller=Controller, protocol='tcp', port=6633) info('*** Add switches\n') s1 = net.addSwitch('s1', cls=OVSKernelSwitch) s2 = net.addSwitch('s2', cls=OVSKernelSwitch) s4 = net.addSwitch('s4', cls=OVSKernelSwitch) s3 = net.addSwitch('s3', cls=OVSKernelSwitch) s10 = net.addSwitch('s10', cls=OVSKernelSwitch) s7 = net.addSwitch('s7', cls=OVSKernelSwitch) s9 = net.addSwitch('s9', cls=OVSKernelSwitch) s8 = net.addSwitch('s8', cls=OVSKernelSwitch) info('*** Add hosts\n') server = net.addHost('server', cls=Host, ip='10.0.0.1', defaultRoute=None) client = net.addHost('client', cls=Host, ip='10.0.0.2', defaultRoute=None) info('*** Add links\n') servers1 = {'bw': 1000} net.addLink(server, s1, cls=TCLink, **servers1) s1s2 = {'bw': 1000} net.addLink(s1, s2, cls=TCLink, **s1s2) s2s3 = {'bw': 1000} net.addLink(s2, s3, cls=TCLink, **s2s3) s3s4 = {'bw': 1000} net.addLink(s3, s4, cls=TCLink, **s3s4) s7s8 = {'bw': 1000} net.addLink(s7, s8, cls=TCLink, **s7s8) s8s9 = {'bw': 1000} net.addLink(s8, s9, cls=TCLink, **s8s9) s9s10 = {'bw': 1000} net.addLink(s9, s10, cls=TCLink, **s9s10) s10client = {'bw': 1000} net.addLink(s10, client, cls=TCLink, **s10client) s4s7 = {'bw': 1000} net.addLink(s4, s7, cls=TCLink, **s4s7) info('*** Starting network\n') net.build() info('*** Starting controllers\n') for controller in net.controllers: controller.start() info('*** Starting switches\n') net.get('s1').start([c0]) net.get('s2').start([c0]) net.get('s4').start([c0]) net.get('s3').start([c0]) net.get('s10').start([c0]) net.get('s7').start([c0]) net.get('s9').start([c0]) net.get('s8').start([c0]) info('*** Post configure switches and hosts\n') CLI(net) net.stop()
def main(): topo = MyTopo() mn = Mininet(topo=topo, controller=RemoteController) mn.start() CLI(mn) mn.stop()
def myNetwork(): net = Mininet(topo=None, build=False, ipBase='10.0.0.0/8') info('*** Adding controller\n') c0 = net.addController(name='c0', controller=RemoteController, ip='127.0.0.1', protocol='tcp', port=6633) # Add physical interface info('Defining physical interface\n') intfName = 'enp0s9' info('*** Add switches\n') s1 = net.addSwitch('s1', cls=OVSKernelSwitch) info('*** Add hosts\n') h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute='via 10.0.0.254') h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute='via 10.0.0.254') h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute='via 10.0.0.254') r1 = net.addHost('r1', cls=Node, ip='10.0.0.254') info('*** Add links\n') net.addLink(s1, r1) net.addLink(s1, h1) net.addLink(s1, h2) net.addLink(s1, h3) info('Adding hardware interface', intfName, 'to router', r1.name, '\n') _intf = Intf(intfName, node=r1, ip='192.168.56.254/24') info('*** Starting network\n') net.build() info('*** Starting controllers\n') for controller in net.controllers: controller.start() info('*** Starting switches\n') net.get('s1').start([c0]) info('*** Post configure switches and hosts\n') r1.cmd('sysctl -w net.ipv4.ip_forward=1') h1.cmdPrint('/usr/sbin/sshd') h2.cmdPrint('/usr/sbin/sshd') h3.cmdPrint('/usr/sbin/sshd') net.startTerms() CLI(net) net.stop()
def main(): ''' 1. Radomly selcect hosts and servers. 2. Repeat throughput test use fixed hosts. :return: ''' # 1. declare and parse arguments top_dir = os.path.join("result") if not os.path.exists(top_dir): os.makedirs(top_dir) subflow_num_start = 1 subflow_num_end = 9 test_name = 'test1' test_type = 'mptcp' # 0: random-based ecmp; 1:mptcp-awared load-balance #datacollection_step_time = 1 connection_interval_time = 5 connection_during_time = 30 # 2. createTopo k_value = readFatTreeK() topo = FatTreeTopo(k=k_value) # link = custom(TCLink, bw=10) # , delay=args.delay) c0 = RemoteController(name='c0', ip='10.103.89.185', port=6633) #c0 = RemoteController(name='c0', ip='10.103.90.184', port=6633) net = Mininet(controller=c0, topo=topo, link=TCLink, switch=OVSKernelSwitch) # c0 = net.addController('c0', ip='10.103.89.185', port=6633) net.start() countDown('Pepareing for test, remain time:%d....', 10) # net.pingAll() hosts = list(net.hosts) host_0 = hosts[0] for host in hosts: net.ping([host_0, host]) host_count = len(hosts) client_hosts, server_hosts = selectHostsPairs(hosts) # random.shuffle(client_hosts) # c_hosts = client_hosts[0:host_count / 2] c_hosts = client_hosts # s_hosts = client_hosts[host_count / 2: host_count] s_hosts = server_hosts # 3. start evaluation while True: test_flag = readTestFlag() if test_flag == False: break test_name = readTestName() test_dir = os.path.join(top_dir, test_name) test_type = readTestType() subflow_num_start = readStartSubflowNum() subflow_num_end = readEndSubflowNum() connection_interval_time = readConnectionInterval() connection_during_time = readConnectionDuringTime() test_info = "Test info,Test type:%s, Subflow num:%d--%d, Connection interval: %d, Connection during: %d" % ( test_type, subflow_num_start, subflow_num_end, connection_interval_time, connection_during_time) print test_info test_time = (len(net.hosts) - 1) * connection_interval_time + connection_during_time print('Test time: %d' % test_time) os.popen("sudo touch README.md") os.popen("sudo echo %s >> README.md" % test_info) print 'Start test ...' for subflow_num in range(subflow_num_start, subflow_num_start + 1): print 'Sub-test start,subflow num: %d.....' % subflow_num cmd_set_subflw = "echo '" + str( subflow_num ) + "' > /sys/module/mptcp_fullmesh/parameters/num_subflows" os.popen(cmd_set_subflw) throughput_test(net, test_dir, subflow_num, test_type, 1, connection_interval_time, connection_during_time, c_hosts, s_hosts) CLI(net) net.stop()
def MininetTopo(): ''' Prepare Your Topology ''' net = Mininet(topo=None, link=TCLink, build=False) c0 = net.addController(name='c0', controller=RemoteController, ip=REMOTE_CONTROLLER_IP, port=6633) info("Create Host node\n") 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') 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') info("Create Switch node\n") s1 = net.addSwitch('s1', protocols='OpenFlow13') s2 = net.addSwitch('s2', protocols='OpenFlow13') s3 = net.addSwitch('s3', protocols='OpenFlow13') s4 = net.addSwitch('s4', protocols='OpenFlow13') info("Link switch to host\n") # net.addLink(s1, h1, 4, bw=BW) # net.addLink(s1, h2, 5, bw=BW) # net.addLink(s1, h3, 6, bw=BW) # net.addLink(s3, h4, 4, bw=BW) # net.addLink(s3, h5, 5, bw=BW) # net.addLink(s3, h6, 6, bw=BW) # net.addLink(s1, s2, 1, 1, bw=BW) # net.addLink(s2, s3, 2, 1, bw=BW) # net.addLink(s3, s4, 2, 2, bw=BW) # net.addLink(s4, s1, 1, 2, bw=BW) # net.addLink(s1, s3, 3, 3, bw=BW) # net.addLink(s2, s4, 3, 3, bw=BW) # net.addLink(s1, h1, 4, bw=BW) # net.addLink(s1, h2, 5, bw=BW) # net.addLink(s1, h3, 6, bw=BW) # net.addLink(s3, h4, 4, bw=BW) # net.addLink(s3, h5, 5, bw=BW) # net.addLink(s3, h6, 6, bw=BW) net.addLink(s1, h1, 4) net.addLink(s1, h2, 5) net.addLink(s1, h3, 6) net.addLink(s3, h4, 4) net.addLink(s3, h5, 5) net.addLink(s3, h6, 6) net.addLink(s1, s2, 1, 1) net.addLink(s2, s3, 2, 1) net.addLink(s3, s4, 2, 2) net.addLink(s4, s1, 1, 2) net.addLink(s1, s3, 3, 3) net.addLink(s2, s4, 3, 3) ''' Working your topology ''' info("Start network\n") net.build() c0.start() s1.start([c0]) s2.start([c0]) s3.start([c0]) s4.start([c0]) # info("Start xterm\n") # net.terms.append(makeTerm(c0)) info("Dumping host connections\n") dumpNodeConnections(net.hosts) h1.cmd("ping -c 1 10.0.0.6") h2.cmd("ping -c 1 10.0.0.4") h3.cmd("ping -c 1 10.0.0.5") h6.cmd("ping -c 1 10.0.0.1") h5.cmd("ping -c 1 10.0.0.3") h4.cmd("ping -c 1 10.0.0.2") h1.cmd("ping -c 1 10.0.0.6") sleep(2) print "Testing network connectivity" net.pingAll() sleep(3) print "Testing iperf" h1.cmd("echo 1 > /proc/sys/net/ipv4/tcp_ecn") h2.cmd("echo 1 > /proc/sys/net/ipv4/tcp_ecn") h3.cmd("echo 1 > /proc/sys/net/ipv4/tcp_ecn") h4.cmd("echo 1 > /proc/sys/net/ipv4/tcp_ecn") h5.cmd("echo 1 > /proc/sys/net/ipv4/tcp_ecn") h6.cmd("echo 1 > /proc/sys/net/ipv4/tcp_ecn") h4.cmd("iperf3 -s -p 5001 -i 1 > 'h4_tcp_p5001.txt' &") h4.cmd("iperf3 -s -p 5002 -i 1 > 'h4_tcp_p5002.txt' &") h4.cmd("iperf3 -s -p 5003 -i 1 > 'h4_tcp_p5003.txt' &") h4.cmd("iperf3 -s -p 5004 -i 1 > 'h4_tcp_p5004.txt' &") h4.cmd("iperf3 -s -u -p 5001 -i 1 > 'h4_udp.txt' &") h5.cmd("iperf3 -s -p 5001 -i 1 > 'h5_tcp_p5001.txt' &") h5.cmd("iperf3 -s -p 5002 -i 1 > 'h5_tcp_p5002.txt' &") h5.cmd("iperf3 -s -p 5003 -i 1 > 'h5_tcp_p5003.txt' &") h5.cmd("iperf3 -s -p 5004 -i 1 > 'h5_tcp_p5004.txt' &") h5.cmd("iperf3 -s -u -p 5001 -i 1 > 'h5_udp.txt' &") h6.cmd("iperf3 -s -p 5001 -i 1 > 'h6_tcp_p5001.txt' &") h6.cmd("iperf3 -s -p 5002 -i 1 > 'h6_tcp_p5002.txt' &") h6.cmd("iperf3 -s -p 5003 -i 1 > 'h6_tcp_p5003.txt' &") h6.cmd("iperf3 -s -p 5004 -i 1 > 'h6_tcp_p5004.txt' &") h6.cmd("iperf3 -s -u -p 5001 -i 1 > 'h6_udp.txt' &") print "iperf from h1 to h4 via port 5001" h1.cmd("sh tcp_25M_ip_port.sh 10.0.0.4 5001 &") sleep(10) print "iperf from h2 to h5 via port 5001" h2.cmd("sh tcp_25M_ip_port.sh 10.0.0.5 5001 &") sleep(10) print "iperf from h3 to h6 via port 5001" h3.cmd("sh tcp_25M_ip_port.sh 10.0.0.6 5001 &") sleep(10) print "iperf from h1 to h4 via port 5002" h1.cmd("sh tcp_25M_ip_port.sh 10.0.0.4 5002 &") sleep(10) print "iperf from h2 to h5 via port 5002" h2.cmd("sh tcp_25M_ip_port.sh 10.0.0.5 5002 &") sleep(10) print "iperf from h3 to h6 via port 5002" h3.cmd("sh tcp_25M_ip_port.sh 10.0.0.6 5002 &") sleep(10) print "iperf from h1 to h4 via port 5003" h1.cmd("sh tcp_25M_ip_port.sh 10.0.0.4 5003 &") sleep(10) print "iperf from h2 to h5 via port 5003" h2.cmd("sh tcp_25M_ip_port.sh 10.0.0.5 5003 &") sleep(10) print "iperf from h3 to h6 via port 5003" h3.cmd("sh tcp_25M_ip_port.sh 10.0.0.6 5003 &") sleep(10) print "iperf from h1 to h4 via port 5004" h1.cmd("sh tcp_25M_ip_port.sh 10.0.0.4 5004 &") sleep(10) print "iperf from h2 to h5 via port 5004" h2.cmd("sh tcp_25M_ip_port.sh 10.0.0.5 5004 &") sleep(10) print "iperf from h3 to h6 via port 5004" h3.cmd("sh tcp_25M_ip_port.sh 10.0.0.6 5004 &") # print "iperf from h1 to h4" # h1.cmd("iperf -c 10.0.0.4 -t 3600 -i 5 -p 5001 &") # sleep(10) # print "iperf from h2 to h5" # h2.cmd("iperf -c 10.0.0.5 -t 3600 -i 5 -p 5001 &") # sleep(10) # print "iperf from h3 to h6" # h3.cmd("iperf -c 10.0.0.6 -t 3600 -i 5 -p 5001 &") # sleep(10) # print "iperf udp from h1 to h4" # h1.cmd("sh udp_to_6.sh &") # sleep(10) # print "iperf udp from h2 to h5" # h2.cmd("sh udp_to_4.sh &") # sleep(10) # print "iperf udp from h3 to h6" # h3.cmd("sh udp_to_5.sh &") CLI(net) ''' Clean mininet ''' net.stop()
def FinalProject(): net = Mininet(topo=None, build=False, ipBase='10.0.0.0/8') info('*** Adding Controller\n') c0 = net.addController(name='c0', controller=RemoteController, ip='127.0.0.1', protocol='tcp', port=6633) info('*** Adding Switches\n') s6 = net.addSwitch('s6', cls=OVSKernelSwitch) s1 = net.addSwitch('s1', cls=OVSKernelSwitch) s13 = net.addSwitch('s13', cls=OVSKernelSwitch) s4 = net.addSwitch('s4', cls=OVSKernelSwitch) s12 = net.addSwitch('s12', cls=OVSKernelSwitch) s10 = net.addSwitch('s10', cls=OVSKernelSwitch) s3 = net.addSwitch('s3', cls=OVSKernelSwitch) s14 = net.addSwitch('s14', cls=OVSKernelSwitch) s8 = net.addSwitch('s8', cls=OVSKernelSwitch) s11 = net.addSwitch('s11', cls=OVSKernelSwitch) s9 = net.addSwitch('s9', cls=OVSKernelSwitch) s5 = net.addSwitch('s5', cls=OVSKernelSwitch) s2 = net.addSwitch('s2', cls=OVSKernelSwitch) s7 = net.addSwitch('s7', cls=OVSKernelSwitch) info('*** Adding Hosts\n') h2 = net.addHost('h2', cls=Host, ip='10.0.0.2', defaultRoute=None) h3 = net.addHost('h3', cls=Host, ip='10.0.0.3', defaultRoute=None) h4 = net.addHost('h4', cls=Host, ip='10.0.0.4', defaultRoute=None) h1 = net.addHost('h1', cls=Host, ip='10.0.0.1', defaultRoute=None) info('*** Adding links\n') net.addLink(h1, s13) net.addLink(s13, s10) net.addLink(s12, s11) net.addLink(s11, s10) net.addLink(s12, s14) net.addLink(s14, h2) net.addLink(s11, s1) net.addLink(s1, s2) net.addLink(s2, s4) net.addLink(s4, s3) net.addLink(s4, s7) net.addLink(s7, s5) net.addLink(s6, s7) net.addLink(s5, s8) net.addLink(s6, s9) net.addLink(s9, h4) net.addLink(s8, h3) info('*** Building Network\n') net.build() info('*** Starting Controller\n') for controller in net.controllers: controller.start() info('*** Starting Switches\n') net.get('s6').start([c0]) net.get('s1').start([c0]) net.get('s13').start([c0]) net.get('s4').start([c0]) net.get('s12').start([c0]) net.get('s10').start([c0]) net.get('s3').start([c0]) net.get('s14').start([c0]) net.get('s8').start([c0]) net.get('s11').start([c0]) net.get('s9').start([c0]) net.get('s5').start([c0]) net.get('s2').start([c0]) net.get('s7').start([c0]) info('*** Post configurtion of switches and hosts ***\n') info('************************************************\n') info('*********** NET4901 Official Topology **********\n') info('* Created By: Carlos | Logan | Jiteng | Nissan *\n') info('************************************************\n') CLI(net) net.stop()
def myNetwork(): net = Mininet(topo=None, build=False, ipBase='10.0.0.0/8', link=TCLink) info('*** Adding controller\n') c1 = net.addController(name='c1', controller=RemoteController, ip='192.168.56.102', protocol='tcp', port=6633) c2 = net.addController(name='c2', controller=RemoteController, ip='192.168.56.106', protocol='tcp', port=6633) c3 = net.addController(name='c3', controller=RemoteController, ip='192.168.56.107', protocol='tcp', port=6633) c4 = net.addController(name='c4', controller=RemoteController, ip='192.168.56.108', protocol='tcp', port=6633) c5 = net.addController(name='c5', controller=RemoteController, ip='192.168.56.109', protocol='tcp', port=6633) c6 = net.addController(name='c6', controller=RemoteController, ip='192.168.56.117', protocol='tcp', port=6633) c7 = net.addController(name='c7', controller=RemoteController, ip='192.168.56.121', protocol='tcp', port=6633) c8 = net.addController(name='c8', controller=RemoteController, ip='192.168.56.119', protocol='tcp', port=6633) info('*** Add switches\n') s1 = net.addSwitch('s1', cls=OVSKernelSwitch) s2 = net.addSwitch('s2', cls=OVSKernelSwitch) s3 = net.addSwitch('s3', cls=OVSKernelSwitch) s4 = net.addSwitch('s4', cls=OVSKernelSwitch) s5 = net.addSwitch('s5', cls=OVSKernelSwitch) s6 = net.addSwitch('s6', cls=OVSKernelSwitch) s7 = net.addSwitch('s7', cls=OVSKernelSwitch) s8 = net.addSwitch('s8', cls=OVSKernelSwitch) info('*** Add hosts\n') h1 = net.addHost('h1', ip='192.168.0.200', mac='00:00:00:00:00:01') h2 = net.addHost('h2', ip='192.168.0.201', mac='00:00:00:00:00:02') h3 = net.addHost('h3', ip='192.168.0.202', mac='00:00:00:00:00:03') h4 = net.addHost('h4', ip='192.168.0.203', mac='00:00:00:00:00:04') h5 = net.addHost('h5', ip='192.168.0.204', mac='00:00:00:00:00:05') h6 = net.addHost('h6', ip='192.168.0.205', mac='00:00:00:00:00:06') for x in range(7, 53): if x >= 10: exec( "h%s = net.addHost('h%s', ip='192.168.0.%s', mac='00:00:00:00:00:%s')" % (x, x, x, x)) else: exec( "h%s = net.addHost('h%s', ip='192.168.0.%s', mac='00:00:00:00:00:0%s')" % (x, x, x, x)) exec("h%s.cmd('sysctl -w net.ipv4.ip_forward=1')" % x) info('*** Add links\in') # h1 sera ligado no s2 para fazer o nat com h2 que tera a app funcionando do outro lado (s1) Link(h1, s2, intfName1='h1-eth0') exec("net.addLink(s3, h1, bw=1000, delay='1ms', loss=0, use_htb=True)") h1.cmd('ifconfig h1-eth1 0.0.0.0 netmask 0.0.0.0.0') h1.cmd( 'iptables -t nat -A PREROUTING -d 192.168.0.200 -j DNAT --to-destination 10.0.0.5' ) h1.cmd( 'iptables -t nat -A POSTROUTING -o h1-eth1 -j SNAT --to-source 10.0.0.82' ) h1.cmd('sysctl -w net.ipv4.ip_forward=1') Link(h2, s4, intfName1='h2-eth0') exec("net.addLink(s3, h2, bw=1000, delay='1ms', loss=0, use_htb=True)") h2.cmd('ifconfig h2-eth1 0.0.0.0 netmask 0.0.0.0') h2.cmd( 'iptables -t nat -A PREROUTING -d 192.168.0.201 -j DNAT --to-destination 10.0.0.5' ) h2.cmd( 'iptables -t nat -A POSTROUTING -o h2-eth1 -j SNAT --to-source 10.0.0.83' ) h2.cmd('sysctl -w net.ipv4.ip_forward=1') Link(h3, s5, intfName1='h3-eth0') exec("net.addLink(s3, h3, bw=1000, delay='1ms', loss=0, use_htb=True)") h3.cmd('ifconfig h3-eth1 0.0.0.0 netmask 0.0.0.0') h3.cmd( 'iptables -t nat -A PREROUTING -d 192.168.0.202 -j DNAT --to-destination 10.0.0.5' ) h3.cmd( 'iptables -t nat -A POSTROUTING -o h3-eth1 -j SNAT --to-source 10.0.0.84' ) h3.cmd('sysctl -w net.ipv4.ip_forward=1') Link(h4, s6, intfName1='h4-eth0') exec("net.addLink(s3, h4, bw=1000, delay='1ms', loss=0, use_htb=True)") h4.cmd('ifconfig h4-eth1 0.0.0.0 netmask 0.0.0.0') h4.cmd( 'iptables -t nat -A PREROUTING -d 192.168.0.203 -j DNAT --to-destination 10.0.0.5' ) h4.cmd( 'iptables -t nat -A POSTROUTING -o h4-eth1 -j SNAT --to-source 10.0.0.85' ) h4.cmd('sysctl -w net.ipv4.ip_forward=1') Link(h5, s7, intfName1='h5-eth0') exec("net.addLink(s3, h5, bw=1000, delay='1ms', loss=0, use_htb=True)") h5.cmd('ifconfig h5-eth1 0.0.0.0 netmask 0.0.0.0') h5.cmd( 'iptables -t nat -A PREROUTING -d 192.168.0.204 -j DNAT --to-destination 10.0.0.5' ) h5.cmd( 'iptables -t nat -A POSTROUTING -o h5-eth1 -j SNAT --to-source 10.0.0.86' ) h5.cmd('sysctl -w net.ipv4.ip_forward=1') Link(h6, s8, intfName1='h6-eth0') exec("net.addLink(s3, h6, bw=1000, delay='1ms', loss=0, use_htb=True)") h6.cmd('ifconfig h6-eth1 0.0.0.0 netmask 0.0.0.0') h6.cmd( 'iptables -t nat -A PREROUTING -d 192.168.0.205 -j DNAT --to-destination 10.0.0.5' ) h6.cmd( 'iptables -t nat -A POSTROUTING -o h6-eth1 -j SNAT --to-source 10.0.0.87' ) h6.cmd('sysctl -w net.ipv4.ip_forward=1') net.addLink(s1, s2) net.addLink(s1, s3) net.addLink(s1, s4) net.addLink(s1, s5) net.addLink(s1, s6) net.addLink(s1, s7) net.addLink(s1, s8) for x in range(7, 53): exec("net.addLink(s1, h%s, bw=1000, delay='1ms', loss=0, use_htb=True)" % x) info('*** Starting network\n') net.build() info('*** Starting controllers\n') for controller in net.controllers: controller.start() info('*** Starting switches\n') net.get('s1').start([c1]) net.get('s2').start([c2]) net.get('s3').start([c3]) net.get('s4').start([c4]) net.get('s5').start([c5]) net.get('s6').start([c6]) net.get('s7').start([c7]) net.get('s8').start([c8]) info('*** Post configure switches and hosts\n') os.popen('ovs-vsctl add-port s3 enp0s3') exec("h1.cmdPrint('dhclient h1-eth1')") exec("h2.cmdPrint('dhclient h2-eth1')") exec("h3.cmdPrint('dhclient h3-eth1')") exec("h4.cmdPrint('dhclient h4-eth1')") exec("h5.cmdPrint('dhclient h5-eth1')") exec("h6.cmdPrint('dhclient h6-eth1')") h1.cmd("ifconfig h1-eth1 10.0.0.82") h2.cmd("ifconfig h2-eth1 10.0.0.83") h3.cmd("ifconfig h3-eth1 10.0.0.84") h4.cmd("ifconfig h4-eth1 10.0.0.85") h5.cmd("ifconfig h5-eth1 10.0.0.86") h6.cmd("ifconfig h6-eth1 10.0.0.87") os.popen('ovs-vsctl add-port s1 enp0s9') for x in range(7, 53): exec("h%s.cmdPrint('dhclient '+h%s.defaultIntf().name)" % (x, x)) exec("h%s.cmd('sysctl -w net.ipv4.ip_forward=1')" % x) s1.cmd( 'ovs-ofctl add-flow s1 ip,priority=65000,nw_src=192.168.0.68/32,actions=NORMAL' ) s1.cmd( 'ovs-ofctl add-flow s1 ip,priority=65000,nw_dst=192.168.0.68/32,actions=NORMAL' ) #Esses fluxos permissivos sao para simular a internet. O cliente chega no h1 mas s2 que dira se passa ou nao. s1.cmd( 'ovs-ofctl add-flow s1 ip,priority=65000,nw_dst=192.168.0.200/32,actions=NORMAL' ) s1.cmd( 'ovs-ofctl add-flow s1 ip,priority=65000,nw_src=192.168.0.200/32,actions=NORMAL' ) s1.cmd( 'ovs-ofctl add-flow s1 ip,priority=65000,nw_src=192.168.0.201/32,actions=NORMAL' ) s1.cmd( 'ovs-ofctl add-flow s1 ip,priority=65000,nw_dst=192.168.0.201/32,actions=NORMAL' ) s1.cmd( 'ovs-ofctl add-flow s1 ip,priority=65000,nw_src=192.168.0.202/32,actions=NORMAL' ) s1.cmd( 'ovs-ofctl add-flow s1 ip,priority=65000,nw_dst=192.168.0.202/32,actions=NORMAL' ) s1.cmd( 'ovs-ofctl add-flow s1 ip,priority=65000,nw_dst=192.168.0.203/32,actions=NORMAL' ) s1.cmd( 'ovs-ofctl add-flow s1 ip,priority=65000,nw_src=192.168.0.203/32,actions=NORMAL' ) s1.cmd( 'ovs-ofctl add-flow s1 ip,priority=65000,nw_src=192.168.0.204/32,actions=NORMAL' ) s1.cmd( 'ovs-ofctl add-flow s1 ip,priority=65000,nw_dst=192.168.0.204/32,actions=NORMAL' ) s1.cmd( 'ovs-ofctl add-flow s1 ip,priority=65000,nw_src=192.168.0.205/32,actions=NORMAL' ) s1.cmd( 'ovs-ofctl add-flow s1 ip,priority=65000,nw_dst=192.168.0.205/32,actions=NORMAL' ) # Fluxo entre app e banco s1.cmd( 'ovs-ofctl add-flow s1 ip,priority=65000,nw_src=192.168.0.70/32,nw_dst=192.168.0.6/32,actions=NORMAL' ) s1.cmd( 'ovs-ofctl add-flow s1 ip,priority=65000,nw_src=192.168.0.6/32,nw_dst=192.168.0.70/32,actions=NORMAL' ) #Fluxo para resposta da Aplicacao web s1.cmd( 'ovs-ofctl add-flow s1 ip,priority=65000,nw_src=192.168.0.70/32,actions=NORMAL' ) s1.cmd('ovs-ofctl add-flow s1 arp,priority=1000,actions=NORMAL') s1.cmd('ovs-ofctl add-flow s1 ip,priority=100,actions=DROP') ### S2 s2.cmd('ovs-ofctl add-flow s2 arp,priority=1000,actions=NORMAL') s2.cmd( 'ovs-ofctl add-flow s2 ip,priority=65000,nw_src=192.168.0.58/32,actions=NORMAL' ) s2.cmd( 'ovs-ofctl add-flow s2 ip,priority=65000,nw_dst=192.168.0.58/32,actions=NORMAL' ) s2.cmd( 'ovs-ofctl add-flow s2 ip,priority=65000,nw_src=192.168.0.200/32,actions=NORMAL' ) s2.cmd('ovs-ofctl add-flow s2 ip,priority=100,actions=DROP') ###S3 s3.cmd( 'ovs-ofctl add-flow s3 ip,priority=65000,nw_src=10.0.0.0/24,nw_dst=10.0.0.0/24,actions=NORMAL' ) s3.cmd('ovs-ofctl add-flow s3 arp,priority=1000,actions=NORMAL') s3.cmd('ovs-ofctl add-flow s3 ip,priority=100,actions=DROP') ####S4 s4.cmd( 'ovs-ofctl add-flow s4 ip,priority=65000,nw_src=192.168.0.58/32,actions=NORMAL' ) s4.cmd( 'ovs-ofctl add-flow s4 ip,priority=65000,nw_dst=192.168.0.58/32,actions=NORMAL' ) s4.cmd( 'ovs-ofctl add-flow s4 ip,priority=65000,nw_src=192.168.0.201/32,actions=NORMAL' ) s4.cmd('ovs-ofctl add-flow s4 arp,priority=1000,actions=NORMAL') s4.cmd('ovs-ofctl add-flow s4 ip,priority=100,actions=DROP') ###S5 s5.cmd( 'ovs-ofctl add-flow s5 ip,priority=65000,nw_src=192.168.0.58/32,actions=NORMAL' ) s5.cmd( 'ovs-ofctl add-flow s5 ip,priority=65000,nw_dst=192.168.0.58/32,actions=NORMAL' ) s5.cmd( 'ovs-ofctl add-flow s5 ip,priority=65000,nw_src=192.168.0.202/32,actions=NORMAL' ) s5.cmd('ovs-ofctl add-flow s5 arp,priority=1000,actions=NORMAL') s5.cmd('ovs-ofctl add-flow s5 ip,priority=100,actions=DROP') ###S6 s6.cmd( 'ovs-ofctl add-flow s6 ip,priority=65000,nw_src=192.168.0.58/32,actions=NORMAL' ) s6.cmd( 'ovs-ofctl add-flow s6 ip,priority=65000,nw_dst=192.168.0.58/32,actions=NORMAL' ) s6.cmd( 'ovs-ofctl add-flow s6 ip,priority=65000,nw_src=192.168.0.203/32,actions=NORMAL' ) s6.cmd('ovs-ofctl add-flow s6 arp,priority=1000,actions=NORMAL') s6.cmd('ovs-ofctl add-flow s6 ip,priority=100,actions=DROP') ###S7 s7.cmd( 'ovs-ofctl add-flow s7 ip,priority=65000,nw_src=192.168.0.58/32,actions=NORMAL' ) s7.cmd( 'ovs-ofctl add-flow s7 ip,priority=65000,nw_dst=192.168.0.58/32,actions=NORMAL' ) s7.cmd( 'ovs-ofctl add-flow s7 ip,priority=65000,nw_src=192.168.0.204/32,actions=NORMAL' ) s7.cmd('ovs-ofctl add-flow s7 arp,priority=1000,actions=NORMAL') s7.cmd('ovs-ofctl add-flow s7 ip,priority=100,actions=DROP') ###S8 s8.cmd( 'ovs-ofctl add-flow s8 ip,priority=65000,nw_src=192.168.0.58/32,actions=NORMAL' ) s8.cmd( 'ovs-ofctl add-flow s8 ip,priority=65000,nw_dst=192.168.0.58/32,actions=NORMAL' ) s8.cmd( 'ovs-ofctl add-flow s8 ip,priority=65000,nw_src=192.168.0.205/32,actions=NORMAL' ) s8.cmd('ovs-ofctl add-flow s8 arp,priority=1000,actions=NORMAL') s8.cmd('ovs-ofctl add-flow s8 ip,priority=100,actions=DROP') CLI(net) net.stop()
def topology(): net = Mininet(controller=RemoteController, link=TCLink, accessPoint=OVSKernelAP, switch=OVSKernelSwitch, useWmediumd=True) print "Creating nodes" h1 = net.addHost('h1', mac='00:00:00:00:00:01', ip='10.0.0.1/24') h2 = net.addHost('h2', mac='00:00:00:00:00:02', ip='10.0.0.2/24') sw10 = net.addSwitch('sw10') sw20 = net.addSwitch('sw20') sw30 = net.addSwitch('sw30') sw40 = net.addSwitch('sw40') ap1 = net.addAccessPoint('ap1', ssid='AP1', mode='g', channel='1', position='40,60,0', range='30') ap2 = net.addAccessPoint('ap2', ssid='AP2', mode='g', channel='6', position='60,60,0', range='30') ap3 = net.addAccessPoint('ap3', ssid='AP3', mode='g', channel='11', position='40,40,0', range='30') ap4 = net.addAccessPoint('ap4', ssid='AP4', mode='g', channel='1', position='60,40,0', range='30') sta1 = net.addStation('sta1', mac='00:00:00:00:00:10', ip='10.0.0.10/24', position='0,0,0') c0 = net.addController('c0', controller=RemoteController, ip='127.0.0.1', port=6653) net.configureWifiNodes() print "Associating and creating links" net.addLink(sw10, sw20) net.addLink(sw20, sw30) net.addLink(sw10, sw40) net.addLink(sw10, h1) net.addLink(sw20, h2) net.addLink(sw10, ap1) net.addLink(sw20, ap2) net.addLink(sw30, ap3) net.addLink(sw40, ap4) print "Starting network" net.build() c0.start() sw10.start([c0]) sw20.start([c0]) sw30.start([c0]) sw40.start([c0]) ap1.start([c0]) ap2.start([c0]) ap3.start([c0]) ap4.start([c0]) net.plotGraph(max_x=100, max_y=100) # start = 2 # net.startMobility(startTime=start) # net.mobility(sta1, 'start', time=start, position='0.0,0.0,0.0') # net.mobility(sta1, 'stop', time=start+10, position='20.0,20.0,0.0') # net.stopMobility(stopTime=start+11) thread.start_new_thread(MySocket().start, (net, )) print "Running CLI" CLI(net) print "Stopping network" net.stop()
def simulate(host_type): net = None try: net = Mininet(topo=None, build=False, host=host_type, ipBase='10.0.0.0/8', xterms=True, waitConnected=True) h1 = net.addHost('h1', ip='10.0.0.1', defaultRoute=None) h2 = net.addHost('h2', ip='10.0.0.2', defaultRoute=None) h3 = net.addHost('h3', ip='10.0.0.3', defaultRoute=None) h4 = net.addHost('h4', ip='10.0.0.4', defaultRoute=None) verifier = net.addHost('verifier', ip='10.0.1.0', defaultRoute=None) s1 = net.addSwitch('s1', cls=OVSKernelSwitch, failMode='standalone') s2 = net.addSwitch('s2', cls=OVSKernelSwitch, failMode='standalone') net.addLink(s1, h1) net.addLink(s1, h2) net.addLink(s1, h3) net.addLink(s1, h4) net.addLink(s1, verifier) net.addLink(s2, s1) net.build() net.start() for node in net.hosts: node.start('/tmp/') sleep(2) # Wait for nodes to be started completely. generators = [h1, h2, h3, h4] for node in generators: register_peers(node, verifier) target_amounts = {h1: 12, h2: 20, h3: 35, h4: 45} for h, a in target_amounts.iteritems(): h.call('block/generate/loop/start') print("Waiting for block generations for initial target amounts.") generated = [] while len(generated) != len(target_amounts): sleep(5) print('***** AMOUNT CONTROL *****') for h, a in target_amounts.iteritems(): if h.name in generated: continue host_amount = verifier_check_amount(h, verifier) print(h.name + ' has ' + str(host_amount) + ' coin currently, target is: ' + str(a)) if (host_amount >= a): print(h.name + ' has enough coin, stopping generation for it') h.call('block/generate/loop/stop') generated.append(h.name) # 6/11/10 open_mininet_cli(net) h5 = add_host_helper('h5', '10.0.0.5', s2, net) register_peers(h2, h5) register_peers(h3, h5) raw_input('Input something to start transactions in 6/11/10: ') send_transaction(h2, h5, 20) send_transaction(h3, h5, 35) wait_and_forge_transactions(verifier, 2) #8/11/10 Phase1 open_mininet_cli(net) h6 = add_host_helper('h6', '10.0.0.6', s2, net) h7 = add_host_helper('h7', '10.0.0.7', s2, net) h8 = add_host_helper('h8', '10.0.0.8', s1, net) register_peers(h4, h7) register_peers(h4, h8) register_peers(h5, h7) register_peers(h6, h7) register_peers(h5, h6) register_peers(h1, h6) raw_input('Input something to send transactions in 8/11/10 Phase1: ') send_transaction(h1, h6, 12) send_transaction(h4, h7, 30) send_transaction(h4, h8, 15) wait_and_forge_transactions(verifier, 3) #8/11/10 between entity raw_input( 'Input something to send mid-transactions(between entity) in 8/11/10' ) send_transaction(h6, h5, 5) send_transaction(h7, h5, 30) wait_and_forge_transactions(verifier, 2) #8/11/10 Phase2 open_mininet_cli(net) h9 = add_host_helper('h9', '10.0.0.9', s1, net) h10 = add_host_helper('h10', '10.0.0.10', s1, net) register_peers(h6, h9) register_peers(h5, h10) raw_input('Input something to send transactions in 8/11/10 Phase2: ') send_transaction(h6, h9, 7) send_transaction(h5, h10, 90) wait_and_forge_transactions(verifier, 2) #8/11/10 Phase3 raw_input('Input something to send transactions in 8/11/10 Phase3: ') send_transaction(h10, verifier, 90) wait_and_forge_transactions(verifier, 1) #15/06/2011 open_mininet_cli(net) h11 = add_host_helper('h11', '10.0.0.11', s1, net) register_peers(h8, h11) raw_input('Input something to send transactions in 15/06/2011: ') send_transaction(h8, h11, 15) wait_and_forge_transactions(verifier, 1) #17/06/2011: Phase1 open_mininet_cli(net) h12 = add_host_helper('h12', '10.0.0.12', s1, net) register_peers(h11, h12) raw_input( 'Input something to send transactions in 17/06/2011: Phase1: ') target_amount = 12 transaction_count = 8 print("Sending " + str(transaction_count) + " number of transactions from h11 to h12") for i in range(1, transaction_count + 1): send_transaction(h11, h12, target_amount / float(transaction_count), True) wait_and_forge_transactions(verifier, 1) sleep(0.5) #17/06/2011: Phase2 raw_input( 'Input something to send transactions in 17/06/2011 Phase2: ') send_transaction(h12, verifier, 12) wait_and_forge_transactions(verifier, 1) finally: result = CLI(net) net.stop()
def createNetwork(): #send rate at each link in Mbps bwg = 1 #in Mbps bwbn = 1 #in Mbps mqs = 100 #max queue size of interfaces dly = '2.5ms' apps = 4 #number of other UDP applications = number of DRR classes - 1 [MAXIMUM = 9(!)] qlim = int(mqs/(apps+1)) #limit of queue in DRR is mqs divided by the number of apps + 1 qlim = 5 #TODO delete (just a tryout) appquantum = 1500 #quantum for UDP traffic quicquantum = 55 # quantum for QUIC traffic #create empty network net = Mininet(intf=TCIntf) info( '\n*** Adding controller\n' ) net.addController( 'c0' ) #is it ok ? #add host to topology ht = net.addHost( 'ht', ip='10.10.0.1/24' ) hu = net.addHost( 'hu', ip='10.10.0.2/24' ) it = net.addHost( 'it', ip='10.20.0.1/24' ) iu = net.addHost( 'iu', ip='10.20.0.2/24' ) rh = net.addHost('rh', ip='10.10.0.10/24') ri = net.addHost('ri', ip='10.20.0.20/24') info('\n** Adding Switches\n') # Adding 2 switches to the network sw1 = net.addSwitch('sw1') sw2 = net.addSwitch('sw2') info('\n** Creating Links \n') #create link beetween the network link_ht_sw1 = net.addLink( ht, sw1) link_hu_sw1 = net.addLink( hu, sw1, intfName1='hu-eth0') link_rh_sw1 = net.addLink( rh, sw1, intfName1='rh-eth0') link_it_sw2 = net.addLink( it, sw2) link_iu_sw2 = net.addLink( iu, sw2) link_ri_sw2 = net.addLink( ri, sw2, intfName1='ri-eth0') link_rh_ri = net.addLink( rh, ri, intfName1='rh-eth1', intfName2='ri-eth1') #set bandwith link_ht_sw1.intf1.config( bw = bwbn, max_queue_size = mqs) link_hu_sw1.intf1.config( bw = bwbn, max_queue_size = mqs) link_rh_sw1.intf1.config( bw = bwbn, max_queue_size = mqs) #max_queue_size is hardcoded low to prevent bufferbloat, too high queuing delays link_it_sw2.intf1.config( bw = bwg, max_queue_size = mqs) link_iu_sw2.intf1.config( bw = bwg, max_queue_size = mqs) link_ri_sw2.intf1.config( bw = bwg, max_queue_size = mqs, delay=dly) #delay is set at ri on both interfaces link_rh_ri.intf1.config( bw = bwg, max_queue_size = mqs) #loss is set at rh on its interface to ri only link_ht_sw1.intf2.config( bw = bwbn, max_queue_size = mqs) link_hu_sw1.intf2.config( bw = bwbn, max_queue_size = mqs) link_rh_sw1.intf2.config( bw = bwbn, max_queue_size = mqs) link_it_sw2.intf2.config( bw = bwg, max_queue_size = mqs) link_iu_sw2.intf2.config( bw = bwg, max_queue_size = mqs) link_ri_sw2.intf2.config( bw = bwg, max_queue_size = mqs) link_rh_ri.intf2.config( bw = bwg, max_queue_size = mqs, delay=dly) #delay is set at ri on both interfaces net.start() info( '\n*** Configuring hosts\n' ) rh.cmd('ifconfig rh-eth1 10.12.0.10 netmask 255.255.255.0') #reconfiguring mutiples intefaces host to prevent mininet strange initialisation behaviors rh.cmd('ifconfig rh-eth0 10.10.0.10 netmask 255.255.255.0') rh.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward') #enable forwarding at routers ri.cmd('ifconfig ri-eth1 10.12.0.20 netmask 255.255.255.0') #reconfiguring mutiples intefaces host to prvent mininet strange initialisation behaviors ri.cmd('ifconfig ri-eth0 10.20.0.20 netmask 255.255.255.0') ri.cmd('echo 1 > /proc/sys/net/ipv4/ip_forward') #enable forwarding at routers #configure host default gateways ht.cmd('ip route add default via 10.10.0.10') hu.cmd('ip route add default via 10.10.0.10') it.cmd('ip route add default via 10.20.0.20') iu.cmd('ip route add default via 10.20.0.20') #configure router routing tables rh.cmd('ip route add default via 10.12.0.20') ri.cmd('ip route add default via 10.12.0.10') # weiyu: iu.cmd('touch server.pcap') hu.cmd('touch client.pcap') rh.cmd('tc qdisc del dev rh-eth1 root') start_nodes(rh, ri, iu, hu, mqs, it, ht, apps, appquantum, quicquantum, qlim) #experiment actions it.cmd('ethtool -K it-eth0 tx off sg off tso off') #disable TSO on TCP on defaul TCP sender need to be done on other host if sending large TCP file from other nodes time.sleep(5) hu.cmd('sudo tc -s -g qdisc show dev hu-eth0 >> tc.log') hu.cmd('sudo tc -s -g class show dev hu-eth0 >> tc.log') hu.cmd('echo "class show done (running).\n" >> tc.log') # Enable the mininet> prompt if uncommented info('\n*** Running CLI\n') CLI(net) hu.cmd('sudo tc -s -g class show dev hu-eth0 >> tc.log') hu.cmd('echo "class show done (end).\n" >> tc.log') # stops the simulation net.stop()
def WifiNet(inputFile): # enable mptcp call(["sudo", "sysctl", "-w", "net.mptcp.mptcp_enabled=1"]) input = open(inputFile, "r") """ Node names """ max_outgoing = [] hosts = [] switches = [] # satellite and dummy satellite links = [] queueConfig = open("FDMQueueConfig.sh", "w") flowTableConfig = open("FDMFlowTableConfig.sh", "w") queueConfig.write("#!/bin/bash\n\n") flowTableConfig.write("#!/bin/bash\n\n") queue_num = 1 num_host = 0 num_ship = 0 num_sat = 0 # Read src-des pair for testing src_hosts = [] des_hosts = [] des_ip = [] line = input.readline() while line.strip() != "End": src, des, ip = line.strip().split() src_hosts.append(src) des_hosts.append(des) des_ip.append(ip) line = input.readline() # Add nodes # Mirror ships are switches line = input.readline() while line.strip() != "End": action, type_node, target = line.strip().split() if type_node == "host:": hosts.append(target) num_host += 1 else: if type_node == "ship:": num_ship += 1 max_outgoing.append(0) elif type_node == "hub:": num_sat += 1 switches.append(target) line = input.readline() # Add links line = input.readline() while line.strip() != "End": action, type_node, end1, end2, bw, delay = line.strip().split() if end1[0] == "s" and int(end1[1:]) <= num_ship and end2[0] == "s": max_outgoing[int(end1[1:]) - 1] += 1 links.append([end1, end2, bw, delay]) line = input.readline() print(max_outgoing) # Routing table of hosts line = input.readline() while line.strip() != "End": host, st, num_ip = line.strip().split() file = open(host + ".sh", "w") file.write("#!/bin/bash\n\n") for i in range(0, int(num_ip)): ipaddr = input.readline().strip() intf = host + "-eth" + str(i) file.write("ifconfig " + intf + " " + ipaddr + " netmask 255.255.255.255\n") file.write("ip rule add from " + ipaddr + " table " + str(i + 1) + "\n") file.write("ip route add " + ipaddr + "/32 dev " + intf + " scope link table " + str(i + 1) + "\n") file.write("ip route add default via " + ipaddr + " dev " + intf + " table " + str(i + 1) + "\n") if i == 0: file.write("ip route add default scope global nexthop via " + ipaddr + " dev " + intf + "\n") file.close() call(["sudo", "chmod", "777", host + ".sh"]) line = input.readline() # Flow table and queue queue_num = 1 line = input.readline() while line: # print(line) end1, end2, num_flow = line.strip().split() num_flow = num_flow.strip().split(":")[1] # Routing tables have been configured if "host" in end1: for i in range(0, int(num_flow)): line = input.readline() else: switch, intf = end1.split("-") index_switch = int(switch[1:]) index_intf = intf[3:] if index_switch <= num_ship and "host" != end2[0:4]: # uplink to ship, need to configure both flowtable and queue # Set queue size to one to enable packet drop commandQueue = "sudo ifconfig " + end1 + " txqueuelen 100" queueConfig.write(commandQueue + "\n") # put the queues for one port on one line in definition commandQueue = "sudo ovs-vsctl -- set Port " + end1 + " qos=@newqos -- --id=@newqos create QoS type=linux-htb other-config:max-rate=100000000 " queue_nums = [] rates = [] ipaddrs = [] for i in range(0, int(num_flow) - 1): ipaddr, rate = input.readline().strip().split() rates.append(rate) ipaddrs.append(ipaddr) queue_nums.append(queue_num) commandQueue += "queues:" + str(queue_num) + "=@q" + str( queue_num) + " " queue_num += 1 ipaddr, rate = input.readline().strip().split() rates.append(rate) ipaddrs.append(ipaddr) queue_nums.append(queue_num) commandQueue += "queues:" + str(queue_num) + "=@q" + str( queue_num) + " -- " queue_num += 1 for i in range(0, int(num_flow) - 1): commandQueue += " --id=@q" + str( queue_nums[i] ) + " create Queue other-config:min-rate=" + str( int(float(rates[i]) * 1000000)) + " other-config:max-rate=" + str( int(float(rates[i]) * 1000000)) + " -- " commandQueue += " --id=@q" + str( queue_nums[len(queue_nums) - 1] ) + " create Queue other-config:min-rate=" + str( int(float(rates[len(queue_nums) - 1]) * 1000000)) + " other-config:max-rate=" + str( int(float(rates[len(queue_nums) - 1]) * 1000000)) queueConfig.write(commandQueue + "\n") for i in range(0, int(num_flow)): commandFlowTable = "sudo ovs-ofctl add-flow " + switch + " ip,nw_src=" + ipaddrs[ i] + "/32,actions=set_queue:" + str( queue_nums[i]) + ",output:" + index_intf flowTableConfig.write(commandFlowTable + "\n") commandFlowTable = "sudo ovs-ofctl add-flow " + switch + " in_port=" + index_intf + ",actions=normal" flowTableConfig.write(commandFlowTable + "\n") elif index_switch <= num_ship: # ship to host downlink # port forwarding for i in range(0, int(num_flow)): input.readline() for i in range(0, int(max_outgoing[index_switch - 1])): # ipaddr, rate = input.readline().strip().split() commandFlowTable = "sudo ovs-ofctl add-flow " + switch + " in_port=" + str( int(index_intf) - i - 1) + ",actions=output:" + index_intf flowTableConfig.write(commandFlowTable + "\n") commandFlowTable = "sudo ovs-ofctl add-flow " + switch + " in_port=" + index_intf + ",actions=normal" flowTableConfig.write(commandFlowTable + "\n") elif index_switch <= num_ship + num_sat * 2: # sat-hub-dummy_sat # port forwarding for i in range(0, int(num_flow)): input.readline() for i in range(1, int(index_intf)): commandFlowTable = "sudo ovs-ofctl add-flow " + switch + " in_port=" + str( i) + ",actions=output:" + index_intf flowTableConfig.write(commandFlowTable + "\n") commandFlowTable = "sudo ovs-ofctl add-flow " + switch + " in_port=" + index_intf + ",actions=normal" flowTableConfig.write(commandFlowTable + "\n") elif index_switch <= num_ship + num_sat * 3: # dummy to mirror ship, ip forwarding for i in range(0, int(num_flow)): ipaddr, rate = input.readline().strip().split() commandFlowTable = "sudo ovs-ofctl add-flow " + switch + " ip,nw_src=" + ipaddr + "/32,actions=output:" + index_intf flowTableConfig.write(commandFlowTable + "\n") commandFlowTable = "sudo ovs-ofctl add-flow " + switch + " in_port=" + index_intf + ",actions=normal" flowTableConfig.write(commandFlowTable + "\n") else: # mirror ship to host, port forwarding for i in range(0, int(num_flow)): input.readline() for i in range(1, int(index_intf)): commandFlowTable = "sudo ovs-ofctl add-flow " + switch + " in_port=" + str( i) + ",actions=output:" + index_intf flowTableConfig.write(commandFlowTable + "\n") commandFlowTable = "sudo ovs-ofctl add-flow " + switch + " in_port=" + index_intf + ",actions=normal" flowTableConfig.write(commandFlowTable + "\n") line = input.readline() for i in range(0, num_ship): queueConfig.write("sudo ovs-ofctl -O Openflow13 queue-stats s" + str(i + 1) + "\n") for i in range(0, num_ship + 3 * num_sat): flowTableConfig.write("sudo ovs-ofctl add-flow s" + str(i + 1) + " priority=100,actions=normal\n") flowTableConfig.close() queueConfig.close() call(["sudo", "chmod", "777", "FDMQueueConfig.sh"]) call(["sudo", "chmod", "777", "FDMFlowTableConfig.sh"]) net = Mininet(link=TCLink, controller=None, autoSetMacs=True) nodes = {} """ Initialize Ships """ for host in hosts: node = net.addHost(host) nodes[host] = node """ Initialize SATCOMs """ for switch in switches: node = net.addSwitch(switch) nodes[switch] = node """ Add links """ for link in links: name1, name2, b, d = link[0], link[1], link[2], link[3] node1, node2 = nodes[name1], nodes[name2] if (d != '0'): net.addLink(node1, node2, delay=d + 'ms') else: net.addLink(node1, node2) """ Start the simulation """ info('*** Starting network ***\n') net.start() # set all ships for i in range(0, num_host): src = nodes[hosts[i]] info("--configing routing table of " + hosts[i]) if os.path.isfile(hosts[i] + '.sh'): src.cmdPrint('./' + hosts[i] + '.sh') time.sleep(3) info('*** set queues ***\n') call(["sudo", "bash", "FDMQueueConfig.sh"]) time.sleep(3) info('*** set flow tables ***\n') call(["sudo", "bash", "FDMFlowTableConfig.sh"]) # info('*** start test ping and iperf***\n') # # myServer = [] # des_open = [] # for i in range(0,len(src_hosts)): # src = nodes[src_hosts[i]] # des = nodes[des_hosts[i]] # myServer.append("") # des_open.append(False) # if des.waiting == False: # info("Setting up server " + des_hosts[i] + " for iperf",'\n') # myServer[i] = ServerSetup(des, des_hosts[i]) # myServer[i].setDaemon(True) # myServer[i].start() # des_open[i] = True # time.sleep(1) # # for i in range(0,len(src_hosts)): # src = nodes[src_hosts[i]] # des = nodes[des_hosts[i]] # info("testing",src_hosts[i],"<->",des_hosts[i],'\n') # src.cmdPrint('ping -c 2 ' + des_ip[i]) # time.sleep(0.2) # src.cmdPrint('iperf -c ' + des_ip[i] + ' -t 3 -i 1') # time.sleep(0.2) # # time.sleep(10) # for i in range(0,len(src_hosts)): # if des_open[i] == True: # print("Closing iperf session " + des_hosts[i]) # myServer[i].close(i) # # time.sleep(5) # start D-ITG Servers # start D-ITG application # set simulation time for i in range(0, 5): for i in [2, 5, 8, 11, 14]: srv = nodes[hosts[i]] info("starting D-ITG servers...\n") srv.cmdPrint("cd ~/D-ITG-2.8.1-r1023/bin") srv.cmdPrint("./ITGRecv &") srv.cmdPrint("PID=$!") time.sleep(1) sTime = 10000 # default 120,000ms for i in range(0, 10): # normal requirement senderList = [0, 1, 3, 4, 6, 7, 9, 10, 12, 13] recvList = [11, 14, 2, 8, 5, 11, 5, 8, 2, 11] #bwReq = [6,4,7,3,4,4,3,3,3,3] # large requirement bwReq = [2, 12, 3, 3, 5, 5, 12, 2, 12, 2] ITGTest(senderList[i], recvList[i], hosts, nodes, bwReq[i] * 125, sTime) time.sleep(0.2) info("running simulaiton...\n") info("please wait...\n") time.sleep(sTime / 1000 + 10) for i in [2, 5, 8, 11, 14]: srv = nodes[hosts[i]] info("killing D-ITG servers...\n") srv.cmdPrint("kill $PID") # You need to change the path here call(["sudo", "python", "analysis.py"]) # CLI(net) net.stop() info('*** net.stop()\n')
def myNetWork(): net = Mininet(topo=None, build=False, ipBase='10.0.0.0/8') info('*** Adding controller \n') c0 = net.addController('c0', controller=RemoteController, ip="192.168.17.128", protocol='tcp', port=6633) info('*** Adding switches \n') s1 = net.addSwitch('s1', cls=OVSKernelSwitch) s2 = net.addSwitch('s2', cls=OVSKernelSwitch) s3 = net.addSwitch('s3', cls=OVSKernelSwitch) s4 = net.addSwitch('s4', cls=OVSKernelSwitch) s5 = net.addSwitch('s5', cls=OVSKernelSwitch) s6 = net.addSwitch('s6', cls=OVSKernelSwitch) s7 = net.addSwitch('s7', cls=OVSKernelSwitch) s8 = net.addSwitch('s8', cls=OVSKernelSwitch) s9 = net.addSwitch('s9', cls=OVSKernelSwitch) s10 = net.addSwitch('s10', cls=OVSKernelSwitch) s11 = net.addSwitch('s11', cls=OVSKernelSwitch) s12 = net.addSwitch('s12', cls=OVSKernelSwitch) s13 = net.addSwitch('s13', cls=OVSKernelSwitch) s14 = net.addSwitch('s14', cls=OVSKernelSwitch) s15 = net.addSwitch('s15', cls=OVSKernelSwitch) s16 = net.addSwitch('s16', cls=OVSKernelSwitch) s17 = net.addSwitch('s17', cls=OVSKernelSwitch) s18 = net.addSwitch('s18', cls=OVSKernelSwitch) s19 = net.addSwitch('s19', cls=OVSKernelSwitch) s20 = net.addSwitch('s20', cls=OVSKernelSwitch) info('*** Adding hosts \n') h1 = net.addHost('h1', cls=Host, ip='10.0.0.2', defaultRoute=None) h2 = net.addHost('h2', cls=Host, ip='10.0.0.3', defaultRoute=None) h3 = net.addHost('h3', cls=Host, ip='10.0.1.2', defaultRoute=None) h4 = net.addHost('h4', cls=Host, ip='10.0.1.3', defaultRoute=None) h5 = net.addHost('h5', cls=Host, ip='10.1.0.2', defaultRoute=None) h6 = net.addHost('h6', cls=Host, ip='10.1.0.3', defaultRoute=None) h7 = net.addHost('h7', cls=Host, ip='10.1.1.2', defaultRoute=None) h8 = net.addHost('h8', cls=Host, ip='10.1.1.3', defaultRoute=None) h9 = net.addHost('h9', cls=Host, ip='10.2.0.2', defaultRoute=None) h10 = net.addHost('h10', cls=Host, ip='10.2.0.3', defaultRoute=None) h11 = net.addHost('h11', cls=Host, ip='10.2.1.2', defaultRoute=None) h12 = net.addHost('h12', cls=Host, ip='10.2.1.3', defaultRoute=None) h13 = net.addHost('h13', cls=Host, ip='10.3.0.2', defaultRoute=None) h14 = net.addHost('h14', cls=Host, ip='10.3.0.3', defaultRoute=None) h15 = net.addHost('h15', cls=Host, ip='10.3.1.2', defaultRoute=None) h16 = net.addHost('h16', cls=Host, ip='10.3.1.3', defaultRoute=None) info('*** Adding links \n') net.addLink(s1, h1) net.addLink(s1, h2) net.addLink(s2, h3) net.addLink(s2, h4) net.addLink(s3, h5) net.addLink(s3, h6) net.addLink(s4, h7) net.addLink(s4, h8) net.addLink(s5, h9) net.addLink(s5, h10) net.addLink(s6, h11) net.addLink(s6, h12) net.addLink(s7, h13) net.addLink(s7, h14) net.addLink(s8, h15) net.addLink(s8, h16) net.addLink(s9, s1) net.addLink(s9, s2) net.addLink(s10, s1) net.addLink(s10, s2) net.addLink(s11, s3) net.addLink(s11, s4) net.addLink(s12, s3) net.addLink(s12, s4) net.addLink(s13, s5) net.addLink(s13, s6) net.addLink(s14, s5) net.addLink(s14, s6) net.addLink(s15, s7) net.addLink(s15, s8) net.addLink(s16, s7) net.addLink(s16, s8) net.addLink(s17, s9) net.addLink(s17, s11) net.addLink(s17, s13) net.addLink(s17, s15) net.addLink(s18, s9) net.addLink(s18, s11) net.addLink(s18, s13) net.addLink(s18, s15) net.addLink(s19, s10) net.addLink(s19, s12) net.addLink(s19, s14) net.addLink(s19, s16) net.addLink(s20, s10) net.addLink(s20, s12) net.addLink(s20, s14) net.addLink(s20, s16) info('*** starting network \n') net.build() info('*** starting controllers \n') for controller in net.controllers: controller.start() info('*** starting switches \n') net.get('s1').start([c0]) net.get('s2').start([c0]) net.get('s3').start([c0]) net.get('s4').start([c0]) net.get('s5').start([c0]) net.get('s6').start([c0]) net.get('s7').start([c0]) net.get('s8').start([c0]) net.get('s9').start([c0]) net.get('s10').start([c0]) net.get('s11').start([c0]) net.get('s12').start([c0]) net.get('s13').start([c0]) net.get('s14').start([c0]) net.get('s15').start([c0]) net.get('s16').start([c0]) net.get('s17').start([c0]) net.get('s18').start([c0]) net.get('s19').start([c0]) net.get('s20').start([c0]) info('*** Enable the fat Tree \n') CLI(net) net.stop()
def topology(): "Create a network." net = Mininet(controller=Controller, link=TCLink, switch=OVSKernelSwitch) print "*** Creating nodes" h1 = net.addHost('h1', mac='00:00:00:00:00:01', ip='10.0.0.1/8') sta1 = net.addStation('sta1', wlans=2, ip='10.0.0.2/8') ap1 = net.addBaseStation('ap1', ssid='ssid_ap1', mode='g', channel='6', position='70,25,0') ap2 = net.addBaseStation('ap2', ssid='ssid_ap2', mode='g', channel='1', position='30,25,0') ap3 = net.addBaseStation('ap3', ssid='ssid_ap3', mode='g', channel='11', position='110,25,0') s4 = net.addSwitch('s4', mac='00:00:00:00:00:10') c1 = net.addController('c1', controller=Controller) print "*** Associating and Creating links" net.addLink(ap1, s4) net.addLink(ap2, s4) net.addLink(ap3, s4) net.addLink(s4, h1) sta1.cmd('modprobe bonding mode=3') sta1.cmd('ip link add bond0 type bond') sta1.cmd('ip link set bond0 address 02:01:02:03:04:08') sta1.cmd('ip link set sta1-wlan0 down') sta1.cmd('ip link set sta1-wlan0 address 00:00:00:00:00:11') sta1.cmd('ip link set sta1-wlan0 master bond0') sta1.cmd('ip link set sta1-wlan1 down') sta1.cmd('ip link set sta1-wlan1 address 00:00:00:00:00:12') sta1.cmd('ip link set sta1-wlan1 master bond0') sta1.cmd('ip addr add 10.0.0.10/8 dev bond0') sta1.cmd('ip link set bond0 up') print "*** Starting network" net.build() c1.start() s4.start([c1]) ap1.start([c1]) ap2.start([c1]) ap3.start([c1]) sta1.cmd('ip addr del 10.0.0.2/8 dev sta1-wlan0') os.system('ovs-ofctl add-flow s4 actions=normal') """seed""" net.seed(12) """uncomment to plot graph""" net.plotGraph(max_x=140, max_y=140) "*** Available models: RandomWalk, TruncatedLevyWalk, RandomDirection, RandomWaypoint, GaussMarkov ***" net.startMobility(startTime=0, model='RandomDirection', max_x=120, max_y=50, min_v=0.4, max_v=0.6) print "*** Running CLI" CLI(net) print "*** Stopping network" net.stop()
from mininet.net import Mininet from mininet.util import createLink net = Mininet() #creating nodes in a network c0 = net.addController() h0 = net.addHost('h0') s0 = net.addSwitch('s0') h1 = net.addHost('h1') #creating links between nodes in anetowrk(2-ways) net.addLink(h0,s0) net.addLink(h1,s1) #setip h0.setIP('192.168.1.1',24) h1.setIP('192.168.1.2',24) net.start() net.pingAll() net.stop()
def myNetwork(): net = Mininet(topo=None, build=False, link=TCLink) info('*** Adding controller\n') c0 = net.addController(name='c0', controller=RemoteController, protocol='tcp', ip='127.0.0.1', port=6633) info('*** Adding switches\n') s1 = net.addSwitch('s1', cls=OVSKernelSwitch, protocols='OpenFlow13') s2 = net.addSwitch('s2', cls=OVSKernelSwitch, protocols='OpenFlow13') s3 = net.addSwitch('s3', cls=OVSKernelSwitch, protocols='OpenFlow13') s4 = net.addSwitch('s4', cls=OVSKernelSwitch, protocols='OpenFlow13') s5 = net.addSwitch('s5', cls=OVSKernelSwitch, protocols='OpenFlow13') s6 = net.addSwitch('s6', cls=OVSKernelSwitch, protocols='OpenFlow13') s7 = net.addSwitch('s7', cls=OVSKernelSwitch, protocols='OpenFlow13') s8 = net.addSwitch('s8', cls=OVSKernelSwitch, protocols='OpenFlow13') s9 = net.addSwitch('s9', cls=OVSKernelSwitch, protocols='OpenFlow13') s10 = net.addSwitch('s10', cls=OVSKernelSwitch, protocols='OpenFlow13') s11 = net.addSwitch('s11', cls=OVSKernelSwitch, protocols='OpenFlow13') s12 = net.addSwitch('s12', cls=OVSKernelSwitch, protocols='OpenFlow13') s13 = net.addSwitch('s13', cls=OVSKernelSwitch, protocols='OpenFlow13') s14 = net.addSwitch('s14', cls=OVSKernelSwitch, protocols='OpenFlow13') s15 = net.addSwitch('s15', cls=OVSKernelSwitch, protocols='OpenFlow13') s16 = net.addSwitch('s16', cls=OVSKernelSwitch, protocols='OpenFlow13') s17 = net.addSwitch('s17', cls=OVSKernelSwitch, protocols='OpenFlow13') s18 = net.addSwitch('s18', cls=OVSKernelSwitch, protocols='OpenFlow13') s19 = net.addSwitch('s19', cls=OVSKernelSwitch, protocols='OpenFlow13') s20 = net.addSwitch('s20', cls=OVSKernelSwitch, protocols='OpenFlow13') info('*** Adding links between switches.\n') net.addLink(s1, s5, bw=10) net.addLink(s1, s7, bw=10) net.addLink(s1, s9, bw=10) net.addLink(s1, s11, bw=10) net.addLink(s2, s5, bw=10) net.addLink(s2, s7, bw=10) net.addLink(s2, s9, bw=10) net.addLink(s2, s11, bw=10) net.addLink(s3, s6, bw=10) net.addLink(s3, s8, bw=10) net.addLink(s3, s10, bw=10) net.addLink(s3, s12, bw=10) net.addLink(s4, s6, bw=10) net.addLink(s4, s8, bw=10) net.addLink(s4, s10, bw=10) net.addLink(s4, s12, bw=10) net.addLink(s5, s13, bw=10) net.addLink(s5, s14, bw=10) net.addLink(s6, s13, bw=10) net.addLink(s6, s14, bw=10) net.addLink(s7, s15, bw=10) net.addLink(s7, s16, bw=10) net.addLink(s8, s15, bw=10) net.addLink(s8, s16, bw=10) net.addLink(s9, s17, bw=10) net.addLink(s9, s18, bw=10) net.addLink(s10, s17, bw=10) net.addLink(s10, s18, bw=10) net.addLink(s11, s19, bw=10) net.addLink(s11, s20, bw=10) net.addLink(s12, s19, bw=10) net.addLink(s12, s20, bw=10) info('*** Adding end devices.\n') h1 = net.addHost('h1', ip='10.0.0.1') TCLink(h1, s13, intfName='h1-eth0') TCLink(h1, s14, intfName='h1-eth1') h1.setIP('10.0.0.1', intf='h1-eth0') h1.setIP('10.0.0.2', intf='h1-eth1') h1.setMAC('00:00:00:00:00:01', intf='h1-eth0') h1.setMAC('00:00:00:00:00:02', intf='h1-eth1') h1.cmd('ip rule add from 10.0.0.1 table 1') h1.cmd('ip rule add from 10.0.0.2 table 2') h1.cmd('ip route add 10.0.0.0/24 dev h1-eth0 scope link table 1') h1.cmd('ip route add 10.0.0.0/24 dev h1-eth1 scope link table 2') h1.cmd('sysctl -w net.ipv4.conf.all.arp_filter=1') h1.cmd('/home/mato/ryu/scripts/h1_arp.sh') h2 = net.addHost('h2', ip='10.0.0.3') TCLink(h2, s19, intfName='h2-eth0') TCLink(h2, s20, intfName='h2-eth1') h2.setIP('10.0.0.3', intf='h2-eth0') h2.setIP('10.0.0.4', intf='h2-eth1') h2.setMAC('00:00:00:00:00:03', intf='h2-eth0') h2.setMAC('00:00:00:00:00:04', intf='h2-eth1') h2.cmd('ip rule add from 10.0.0.3 table 1') h2.cmd('ip rule add from 10.0.0.4 table 2') h2.cmd('ip route add 10.0.0.0/24 dev h2-eth0 scope link table 1') h2.cmd('ip route add 10.0.0.0/24 dev h2-eth1 scope link table 2') h2.cmd('sysctl -w net.ipv4.conf.all.arp_filter=1') h2.cmd('/home/mato/ryu/scripts/h2_arp.sh') net.build() info('*** Starting controller\n') for controller in net.controllers: controller.start() info('*** Starting switches\n') net.get('s1').start([c0]) net.get('s2').start([c0]) net.get('s3').start([c0]) net.get('s4').start([c0]) net.get('s5').start([c0]) net.get('s6').start([c0]) net.get('s7').start([c0]) net.get('s8').start([c0]) net.get('s9').start([c0]) net.get('s10').start([c0]) net.get('s11').start([c0]) net.get('s12').start([c0]) net.get('s13').start([c0]) net.get('s14').start([c0]) net.get('s15').start([c0]) net.get('s16').start([c0]) net.get('s17').start([c0]) net.get('s18').start([c0]) net.get('s19').start([c0]) net.get('s20').start([c0]) info('*** Starting iperf server on host #2') h2.cmd('iperf -s &') info('*** Done.\n') CLI(net) net.stop()
def topoTest(): topo = Topo2() net = Mininet( topo=topo, controller=lambda name: RemoteController(name, ip='192.168.42.1'), link=TCLink, switch=OVSSwitch) serverList = [] c = net.getNodeByName('c0') for i in range(1, 17): serverName = 'hs' + str(i) serverList.append(net.getNodeByName(serverName)) clientList = [] for i in range(1, 65): clientName = 'hc' + str(i) clientList.append(net.getNodeByName(clientName)) it1List = [] it2List = [] cIpList = [] sIpList = [] for i in range(16): server = serverList[i] link = server.linkTo(c) i1 = link.intf1 i2 = link.intf2 sIp = '123.123.123.' + str(i) cIp = '125.125.125.' + str(i) #msk = '255.255.255.255' sIpList.append(sIp) cIpList.append(cIp) it1List.append(i1) it2List.append(i2) server.setIP(sIp, 8, i1) c.setIP(cIp, 8, i2) server.cmd('route add -net ' + cIp + ' netmask 255.255.255.255' + ' dev' + str(i1)) #c.cmd('route add -net ' + sIp + ' dev' + str(i2)) net.start() for i in range(16): server = serverList[i] sIp = sIpList[i] cIp = cIpList[i] it1 = it1List[i] it2 = it2List[i] #print str(server) + "," + str(ip) + "," + str(it) server.cmd('route del -net ' + '123.0.0.0' + ' netmask 255.0.0.0 dev ' + str(it1)) server.cmd('route add -net ' + cIp + ' netmask 255.255.255.255 dev ' + str(it1)) c.cmd('route del -net ' + '125.0.0.0' ' netmask 255.0.0.0 dev ' + str(it2)) c.cmd('route add -net ' + sIp + ' netmask 255.255.255.255 dev ' + str(it2)) server.cmd('cd ~/proj/host/mongoose') server.cmd('./mongoose ' + str(i + 1) + ' 125.125.125.' + str(i) + ' &') #Test Cases for i in range(64): client = clientList[i] client.cmd('cd ~/proj/host') client.cmd('./test.sh &') time.sleep(2) CLI(net) net.stop()
def perfTest(): "Create network and run simple performance test" global flag topo = MyTopo() net = Mininet(topo=topo, host=CPULimitedHost, link=TCLink, controller=partial(RemoteController, ip='127.0.0.1', port=6633)) net.start() print "Dumping host connections" dumpNodeConnections(net.hosts) h1, h2, h3, h4, h5, h6, h7, h8, h9, h10 = net.get('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'h7', 'h8', 'h9', 'h10') h21, h22, h23, h24, h25, h26, h27, h28, h29, h30 = net.get( 'h21', 'h22', 'h23', 'h24', 'h25', 'h26', 'h27', 'h28', 'h29', 'h30') h11, h12, h13, h14, h15, h16, h17, h18, h19, h20 = net.get( 'h11', 'h12', 'h13', 'h14', 'h15', 'h16', 'h17', 'h18', 'h19', 'h20') h31, h32, h33, h34, h35, h36, h37, h38, h39, h40 = net.get( 'h31', 'h32', 'h33', 'h34', 'h35', 'h36', 'h37', 'h38', 'h39', 'h40') h1.setMAC("0:0:0:0:0:1") h2.setMAC("0:0:0:0:0:2") h3.setMAC("0:0:0:0:0:3") h4.setMAC("0:0:0:0:0:4") h5.setMAC("0:0:0:0:0:5") h6.setMAC("0:0:0:0:0:6") h7.setMAC("0:0:0:0:0:7") h8.setMAC("0:0:0:0:0:8") h9.setMAC("0:0:0:0:0:9") h10.setMAC("0:0:0:0:0:10") h11.setMAC("0:0:0:0:0:11") h12.setMAC("0:0:0:0:0:12") h13.setMAC("0:0:0:0:0:13") h14.setMAC("0:0:0:0:0:14") h15.setMAC("0:0:0:0:0:15") h16.setMAC("0:0:0:0:0:16") h17.setMAC("0:0:0:0:0:17") h18.setMAC("0:0:0:0:0:18") h19.setMAC("0:0:0:0:0:19") h20.setMAC("0:0:0:0:0:20") h21.setMAC("0:0:0:0:0:21") h22.setMAC("0:0:0:0:0:22") h23.setMAC("0:0:0:0:0:23") h24.setMAC("0:0:0:0:0:24") h25.setMAC("0:0:0:0:0:25") h26.setMAC("0:0:0:0:0:26") h27.setMAC("0:0:0:0:0:27") h28.setMAC("0:0:0:0:0:28") h29.setMAC("0:0:0:0:0:29") h30.setMAC("0:0:0:0:0:30") h31.setMAC("0:0:0:0:0:31") h32.setMAC("0:0:0:0:0:32") h33.setMAC("0:0:0:0:0:33") h34.setMAC("0:0:0:0:0:34") h35.setMAC("0:0:0:0:0:35") h36.setMAC("0:0:0:0:0:36") h37.setMAC("0:0:0:0:0:37") h38.setMAC("0:0:0:0:0:38") h39.setMAC("0:0:0:0:0:39") h40.setMAC("0:0:0:0:0:40") time.sleep(150) #iperf Server h21.popen('iperf -s ', shell=True) #iperf Server h22.popen('iperf -s ', shell=True) h23.popen('iperf -s ', shell=True) h24.popen('iperf -s ', shell=True) h25.popen('iperf -s ', shell=True) h26.popen('iperf -s ', shell=True) h27.popen('iperf -s ', shell=True) h28.popen('iperf -s ', shell=True) h29.popen('iperf -s ', shell=True) h30.popen('iperf -s ', shell=True) h31.popen('iperf -s ', shell=True) # iperf Server h32.popen('iperf -s ', shell=True) h33.popen('iperf -s ', shell=True) h34.popen('iperf -s ', shell=True) h35.popen('iperf -s ', shell=True) h36.popen('iperf -s ', shell=True) h37.popen('iperf -s ', shell=True) h38.popen('iperf -s ', shell=True) h39.popen('iperf -s ', shell=True) h40.popen('iperf -s ', shell=True) h = [ h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11, h12, h13, h14, h15, h16, h17, h18, h19, h20, h21, h22, h23, h24, h25, h26, h27, h28, h29, h30, h31, h32, h33, h34, h35, h36, h37, h38, h39, h40 ] num_list = [ 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 ] def loop(n): if n == 19: print 'lf10:' h20.cmdPrint('iperf -c ' + h40.IP() + ' -l 7240000 -n 1 ') elif n == 18: h19.cmdPrint('iperf -c ' + h39.IP() + ' -l 7240000 -n 1 ') elif n == 17: h18.cmdPrint('iperf -c ' + h38.IP() + ' -l 7240000 -n 1 ') elif n == 16: h17.cmdPrint('iperf -c ' + h37.IP() + ' -l 7240000 -n 1 ') else: h[n].cmdPrint('iperf -c ' + h[n + 20].IP() + ' -l 579200 -n 1 ') pool = threadpool.ThreadPool(20) requests = threadpool.makeRequests(loop, num_list) [pool.putRequest(req) for req in requests] pool.wait() CLI(net) net.stop()
def main(): net = Mininet(controller=None) # add hosts h1 = net.addHost("h1", ip="172.16.10.1/24") h2 = net.addHost("h2", ip="172.16.10.2/24") # add switch 1 sw1 = net.addSwitch("sw1", target_name="p4dockerswitch", cls=P4DockerSwitch, sai_port=25000, pcap_dump=True) # add switch 2 sw2 = net.addSwitch("sw2", target_name="p4dockerswitch", cls=P4DockerSwitch, sai_port=25001, pcap_dump=True) # add links if StrictVersion(VERSION) <= StrictVersion("2.2.0"): net.addLink(sw1, h1, port1=1) net.addLink(sw1, sw2, port1=2, port2=2) net.addLink(sw2, h2, port1=1) else: net.addLink(sw1, h1, port1=1, fast=False) net.addLink(sw1, sw2, port1=2, port2=2, fast=False) net.addLink(sw2, h2, port1=1, fast=False) net.start() print "Waiting 10 seconds for switches to intialize..." time.sleep(10) cfg_switch1() cfg_switch2() CLI(net) net.stop()