def emptyNet(): net = Mininet(topo=None, build=False) c0 = Controller('c0', inNamespace=False) h1 = Host('h1') h2 = Host('h2') #intf1 = Intf("h1-eth1") #intf2 = Intf("h2-eth1") s1 = OVSSwitch('br0', inNamespace=False) Link(h1, s1) Link(h2, s1) c0.start() s1.start([c0]) net.start() #s1.cmd('ovs-vsctl set bridge br0 protocols=OpenFlow13') CLI(net) net.stop() h1.stop() h2.stop() s1.stop() c0.stop()
def create(self, func, prefix, numberOfDevices, routed): devices = list() for i in range(0, numberOfDevices): if (routed == True): devices.append (func(prefix + str(i + 1), ip='10.0.0.' + str(i + 1))) else: name = prefix + str(i + 1) switch = OVSSwitch(name, failMode='standalone', stp=True) devices.append(func(prefix + str(i + 1))) return devices
#!/usr/bin/python from mininet.node import Host, OVSSwitch, Controller from mininet.link import Link h1 = Host('h1') h2 = Host('h2') h3 = Host('h3') h4 = Host('h4') s1 = OVSSwitch('s1', inNamespace=False) s2 = OVSSwitch('s2', inNamespace=False) c0 = Controller('c0', inNamespace=False) Link(h1, s1) Link(h2, s1) Link(h3, s2) Link(h4, s2) Link(s1, s2) h1.setIP('10.0.0.1/24') h2.setIP('10.0.0.2/24') h3.setIP('10.0.0.3/24') h4.setIP('10.0.0.4/24') c0.start() s1.start([c0]) s2.start([c0]) print h1.IP print h2.IP print h3.IP print h4.IP print 'Pinging ...' print h1.cmd('ping -c3 ', h2.IP()) print h1.cmd('ping -c3 ', h3.IP())
def topology(): total_switches = 1 total_clients = 1 total_servers = 3 switches = [] clients = [] servers = [] servers_running = [] net = Mininet_wifi( controller=lambda name: RemoteController( name, ip='10.0.2.15', port=6633), switch=lambda name, **kwargs: OVSSwitch( name, protocols="OpenFlow13", **kwargs), waitConnected=True ) # net = Mininet_wifi() c0 = net.addController( 'c0', controller=RemoteController, ip='127.0.0.1', port=6633) # s0, s1 #switch IP start at 10.0.2.0 / switch MAC start at 00:00:00:00:00:20 / switch DPID start at 1 for i in range(total_switches): print("Creating switch s" + str(i)) thisip = '10.0.2.' thisip += str(i+1) thisip += '/8' thismac = '00:00:00:00:00:2' thismac += str(i+1) thisdpid = '000000000000000' # START FROM 1 HEXADECIMAL thisdpid += str(i+1) switches.append(net.addSwitch( 's' + str(i), ip=thisip, mac=thismac, dpid=thisdpid)) # h0, h1 h2 #hostsudo ps IP start at 10.0.0.0 / hosts MAC start at 00:00:00:00:00:00 for i in range(1, 1 + total_clients): print("Creating client h" + str(i)) thisip = '10.0.0.' thisip += str(i) thisip += '/8' thismac = '00:00:00:00:00:0' thismac += str(i) clients.append(net.addHost('h' + str(i), ip=thisip, mac=thismac)) # s0 ... s5 #stations IP start at 10.0.1.0 / stations MAC start at 00:00:00:00:01:00 for i in range(1 + total_clients, 1 + total_clients + total_servers): print("Creating server h" + str(i)) thisip = '10.0.1.' thisip += str(i) thisip += '/8' thismac = '00:00:00:00:00:1' thismac += str(i) servers.append(net.addHost('h' + str(i), ip=thisip, mac=thismac)) # info("*** Configuring wifi nodes\n") net.configureWifiNodes() for c in clients: net.addLink(c, switches[0]) for srv in servers: net.addLink(srv, switches[0]) # turn server online for i in range(0, total_servers): initServer(servers[i], i+2) startServer(servers[i], i+2) servers_running.append(True) info("*** Starting network\n") net.build() c0.start() for s in switches: s.start([c0]) # menu: # 1. start server 2 (10.0.1.2) # 2. start server 3 (10.0.1.3) # 3. start server 4 (10.0.1.4) # 4. stop server 2 (10.0.1.2) # 5. stop server 3 (10.0.1.3) # 6. stop server 4 (10.0.1.4) # 7. curl to server 2 (10.0.1.2) # 8. curl to server 3 (10.0.1.3) # 9. curl to server 4 (10.0.1.4) # 10. curl cluster (10.0.1.5) while True: print("+-----------------------------------+") print("| menu: |") if not servers_running[0]: print("| 1. start server 2 (10.0.1.2) |") if not servers_running[1]: print("| 2. start server 3 (10.0.1.3) |") if not servers_running[2]: print("| 3. start server 4 (10.0.1.4) |") if servers_running[0]: print("| 4. stop server 2 (10.0.1.2) |") if servers_running[1]: print("| 5. stop server 3 (10.0.1.3) |") if servers_running[2]: print("| 6. stop server 4 (10.0.1.4) |") print("| 7. curl to server 2 (10.0.1.2) |") print("| 8. curl to server 3 (10.0.1.3) |") print("| 9. curl to server 4 (10.0.1.4) |") print("| 10. curl cluster (10.0.1.1) |") print("+-----------------------------------+") line = raw_input("INPUT ('c' for CLI):") tokens = line.split(" ") x = tokens[0] if x == 'e' or x == "exit": break if x == 'c': CLI(net) if x == "1": print("1) start server 2 (10.0.1.2)\n") startServer(servers[0], 2) servers_running[0] = True if x == "2": print("2) start server 3 (10.0.1.3)\n") startServer(servers[1], 3) servers_running[1] = True if x == "3": print("3) start server 4 (10.0.1.4)\n") startServer(servers[2], 4) servers_running[2] = True if x == "4": print("4) stop server 2 (10.0.1.2)\n") stopServer(servers[0], 2) servers_running[0] = False if x == "5": print("5) stop server 3 (10.0.1.3)\n") stopServer(servers[1], 3) servers_running[1] = False if x == "6": print("6) stop server 4 (10.0.1.4)\n") stopServer(servers[2], 4) servers_running[2] = False if x == "7": print("7) curl to server 2 (10.0.1.2)\n") curlServer(clients[0], servers[0]) if x == "8": print("8) curl to server 3 (10.0.1.3)\n") curlServer(clients[0], servers[1]) if x == "9": print("9) curl to server 4 (10.0.1.4) \n") curlServer(clients[0], servers[2]) if x == "10" or x == "0": print("10) curl cluster (10.0.1.1) \n") curlCluster(clients[0]) net.stop()
def topology(): if "--help" in sys.argv: # HELP print("\n[I] Help:\n\n --test : Opens a menu with network tests\n" ) # CHECK NO FW | return total_switches = 2 total_access_points = 1 total_hosts = 5 total_stations = 5 switches = [] accesspoints = [] hosts = [] stations = [] businessHosts = [] # all hosts connected to switch 090 clients = [] # all nodes except host4 server = [] internet = [] net = Mininet_wifi(controller=lambda name: RemoteController( name, ip='10.0.2.15', port=6633), switch=lambda name, **kwargs: OVSSwitch( name, protocols="OpenFlow13", **kwargs), waitConnected=True) # net = Mininet_wifi() c0 = net.addController('c0', controller=RemoteController, ip='127.0.0.1', port=6633) info("*** Creating nodes\n") #### DISCLAIMER all node names are 0based but IPs and DPID are 1based ##### for i in range( total_switches ): # s0, s1 #switch IP start at 10.0.2.0 / switch MAC start at 00:00:00:00:00:20 / switch DPID start at 1 print("Creating switch s" + str(i)) thisip = '10.0.2.' thisip += str(i + 1) thisip += '/8' thismac = '00:00:00:00:00:2' thismac += str(i + 1) thisdpid = '000000000000000' ##START FROM 1 HEXADECIMAL thisdpid += str(i + 1) switches.append( net.addSwitch('s' + str(i), ip=thisip, mac=thismac, dpid=thisdpid)) for i in range( total_hosts ): # h0, h1 h2 #hostsudo ps IP start at 10.0.0.0 / hosts MAC start at 00:00:00:00:00:00 print("Creating host h" + str(i)) thisip = '10.0.0.' thisip += str(i + 1) thisip += '/8' thismac = '00:00:00:00:00:0' thismac += str(i + 1) hosts.append(net.addHost('h' + str(i), ip=thisip, mac=thismac)) for i in range( total_stations ): # s0 ... s5 #stations IP start at 10.0.1.0 / stations MAC start at 00:00:00:00:01:00 print("Creating host sta" + str(i)) thisip = '10.0.1.' thisip += str(i + 1) thisip += '/8' thismac = '00:00:00:00:00:1' thismac += str(i + 1) stations.append(net.addStation('sta' + str(i), ip=thisip, mac=thismac)) for i in range( total_access_points ): # ap0 #Access points IP start at 10.0.3.0 / Access points MAC start at 00:00:00:00:03:00 / Access points DPID starts at 101 print("Creating access point ap" + str(i)) thisip = '10.0.3.' thisip += str(i + 1) thisip += '/8' thismac = '00:00:00:00:00:3' thismac += str(i + 1) thisdpid = '000000000000006' ##START FROM 101 HEXADECIMAL thisdpid += str(i + 5) accesspoints.append( net.addAccessPoint(('ap' + str(i)), ssid="ssid_" + str(i), mode="g", channel="5", client_isolation=True, ip=thisip, mac=thismac, dpid=thisdpid)) # info("*** Configuring wifi nodes\n") net.configureWifiNodes() for sta in stations: net.addLink(sta, accesspoints[0]) clients.append(sta) for i in range(1): server.append(hosts[3]) for i in range(1): internet.append(hosts[4]) for i in range(3): net.addLink(hosts[i], switches[0]) businessHosts.append(hosts[i]) clients.append(hosts[i]) net.addLink(switches[0], switches[1]) net.addLink(switches[1], accesspoints[0]) net.addLink(hosts[3], switches[1]) net.addLink(hosts[4], switches[1]) clients.append(hosts[i]) info("*** Starting network\n") net.build() c0.start() for ap in accesspoints: ap.start([c0]) for s in switches: s.start([c0]) # if '-v' not in sys.argv: # ap1.cmd('ovs-ofctl add-flow ap1 "priority=0,arp,in_port=1,' # 'actions=output:in_port,normal"') # ap1.cmd('ovs-ofctl add-flow ap1 "priority=0,icmp,in_port=1,' # 'actions=output:in_port,normal"') # ap1.cmd('ovs-ofctl add-flow ap1 "priority=0,udp,in_port=1,' # 'actions=output:in_port,normal"') # ap1.cmd('ovs-ofctl add-flow ap1 "priority=0,tcp,in_port=1,' # 'actions=output:in_port,normal"') ### MENU ######### if "--test" in sys.argv: while True: filee = open(filename1, "r") print(filee.read()) line = raw_input("INPUT ('c' for CLI):") tokens = line.split(" ") x = tokens[0] if x == 'e' or x == "exit": break if x == "c": CLI(net) if x == "1": #1 #ICMP BUSINESS<->BUSINESS print("1) Test with ICMP Connection between Business\n") testICMP(businessHosts) if x == "2": #2 #ICMP CUSTOMERS<->CUSTOMERS print("2) Test with ICMP Connection between Customers\n") testICMP(stations) if x == "3": #3 #ICMP BUSINESS<->CUSTOMERS print( "3) Test with ICMP Connection between Business and Customers\n" ) testICMP(businessHosts, stations) if x == "4": #4 #ICMP BUSINESS<->SERVER print( "4) Test with ICMP Connection between Business and Server\n" ) testICMP(businessHosts, server) if x == "5": #5 #ICMP CUSTOMERS<->SERVER print( "5) Test with ICMP Connection between Customers and Server\n" ) testICMP(stations, server) if x == "6": #6 #HTTP BUSINESS<->INTERNET print( "6) Test with HTTP Connection between Business and Internet (host4)\n" ) testHTTP(businessHosts, internet) if x == "7": #7 #HTTP CUSTOMERS<->INTERNET print( "7) Test with HTTP Connection between Customers and Internet (host4)\n" ) testHTTP(stations, internet) if x == "8": #8 #HTTP SERVER<->INTERNET print( "8) Test with HTTP Connection between Server and Internet (host4)\n" ) testHTTP(server, internet) if x == "9": #9 #TCP BUSINESS<->BUSINESS print("9) Test with TCP Connection between Business \n") testTCP(businessHosts) if x == "10": #10 #TCP CUSTOMERS<->CUSTOMERS print("10) Test with TCP Connection between Customers \n") testTCP(stations) if x == "11": #11 #TCP BUSINESS<->CUSTOMERS print( "11) Test with TCP Connection between Business and Customers \n" ) testTCP(businessHosts, stations) if x == "12": #12 #TCP BUSINESS<->SERVER print( "12) Test with TCP Connection between Business and Server \n" ) testTCP(businessHosts, server) if x == "13": #13 #TCP CUSTOMERS<->SERVER print( "13) Test with TCP Connection between Customers and Server \n" ) testTCP(stations, server) if x == "14": #14 #UDP BUSINESS<->BUSINESS print("14) Test with UDP Connection between Business \n") testUDP(businessHosts) if x == "15": #15 #UDP CUSTOMERS<->CUSTOMERS print("15) Test with UDP Connection between Customers \n") testUDP(stations) if x == "16": #16 #UDP BUSINESS<->CUSTOMERS print( "16) Test with UDP Connection between Business and Customers \n" ) testUDP(businessHosts, stations) if x == "17": #17 #UDP BUSINESS<->SERVER print( "17) Test with UDP Connection between Business and Server \n" ) testUDP(businessHosts, server) if x == "18": #18 #UDP CUSTOMERS<->SERVER print( "18) Test with UDP Connection between Customers and Server \n" ) testUDP(stations, server) if x == "19": #19 #ICMP BUSINESS<->INTERNET print( "19) Test with ICMP Connection between Business and Internet \n" ) testICMP(businessHosts, internet) if x == "20": #20 #TCP BUSINESS<->INTERNET print( "20) Test with TCP Connection between Business and Internet \n" ) testTCP(businessHosts, internet) if x == "21": #21 #TCP CUSTOMERS<->INTERNET print( "21) Test with TCP Connection between Customers and Internet \n" ) testTCP(stations, internet) if x == "22": #22 #TCP SERVER<->INTERNET print( "22) Test with TCP Connection between Server and Internet \n" ) testTCP(server, internet) if x == "23": #23 # CUSTOMERS<->SERVER print( "23) Test all Connections between Customers and Server \n" ) testICMP(stations, server) testTCP(stations, server) testUDP(stations, server) testHTTP(stations, server) if x == "24": #24 # BUSINESS<->BUSINESS print("24) Test all Connections between Business hosts \n") testICMP(businessHosts) testTCP(businessHosts) testUDP(businessHosts) testHTTP(businessHosts) ### MENU ######### info("*** Running CLI\n") CLI(net) info("*** Stopping network\n") net.stop()
#!/usr/bin/python import sys from mininet.node import Host, OVSSwitch, Controller from mininet.link import Link n = sys.argv[1] c1 = Controller( 'c1', inNamespace=False ) i = 1 while( i <= n ): a1 = OVSSwitch( 'a%d', inNamespace=False) % (i) Link( c1, ai ) i = i + 1 i = 1 count = 1 while( i <= n ** 2): e1 = OVSSwitch( 'e%d', inNamespace=False ) % (i) Link( acount, ei ) if i == n: count = count + 1 i = i + 1 i = 1 count = 1 while( i <= n ** 3) : h1 = Host( 'h%d' ) % (i) Link( ecount, hi ) hi.setIP( '10.0.0.1/24' ) if i == n: count = count + 1
#!/usr/bin/python from mininet.node import Host, OVSSwitch, Controller from mininet.link import Link h1 = Host('h1') h2 = Host('h2') h3 = Host('h3') h4 = Host('h4') h5 = Host('h5') h6 = Host('h6') h7 = Host('h7') h8 = Host('h8') e1 = OVSSwitch('e1', inNamespace=False) e2 = OVSSwitch('e2', inNamespace=False) e3 = OVSSwitch('e3', inNamespace=False) e4 = OVSSwitch('e4', inNamespace=False) a1 = OVSSwitch('a1', inNamespace=False) a2 = OVSSwitch('a2', inNamespace=False) c1 = Controller('c1', inNamespace=False) Link(h1, e1) Link(h2, e1) Link(h3, e2) Link(h4, e2) Link(h5, e3) Link(h6, e3) Link(h7, e4) Link(h8, e4) h1.setIP('10.0.0.1/24') h2.setIP('10.0.0.2/24') h3.setIP('10.0.0.3/24')