def build(): global net, hosts1, hosts2 net = Mininet(controller=RemoteController, switch=KildaSwitch, build=False) gateway = get_gateway() info("*** Creating (Remote) controllers\n") c0 = net.addController('c0', ip=gateway, port=6653) info("*** Creating switches\n") s1 = net.addSwitch('s1') s2 = net.addSwitch('s2') info("*** Creating hosts\n") hosts1 = [net.addHost('h%ds1' % n) for n in (1, 2)] hosts2 = [net.addHost('h%ds2' % n) for n in (1, 2)] info("*** Creating links\n") for h in hosts1: net.addLink(h, s1) for h in hosts2: net.addLink(h, s2) net.addLink(s1, s2) info("*** Starting network\n") net.configHosts() net.start() add_rules()
def new_topology(): global net logger.info("*** Creating Topology") validate(request.json, topology_schema) net = Mininet(controller=RemoteController, switch=KildaSwitch, build=False) logger.info("") logger.info("*** Creating (Remote) controllers") for controller in request.json['controllers']: name = controller['name'] host = controller['host'] port = controller['port'] logger.info("===> adding controller name={}, host={}, port={}".format( name, host, port)) ip = socket.gethostbyname(host) net.addController(name, ip=ip, port=port) logger.info("") logger.info("*** Creating switches") for switch in request.json['switches']: name = switch['name'] dpid = switch['dpid'] if type(dpid) is unicode: dpid = dpid.encode('ascii', 'ignore') logger.info("===> adding switch name={}, dpid={}".format(name, dpid)) net.addSwitch(name=name, dpid=dpid) logger.info("") logger.info("*** Creating Switch:Switch links") for link in request.json['links']: node1 = link['node1'] node2 = link['node2'] logger.info("===> adding link {} -> {}".format(node1, node2)) net.addLink(node1, node2) logger.info("") logger.info("*** Creating hosts\n") for switch in net.switches: # add single host per switch .. sufficient for our strategy of testing flows h = net.addHost('h%s' % switch.name) net.addLink(h, switch) logger.info("") logger.info("*** Starting network") net.configHosts() net.start() response.content_type = 'application/json' result = json.dumps({ 'controllers': [controller_info(x) for x in net.controllers], 'switches': [switch_info(x) for x in net.switches], 'links': [link_info(x) for x in net.links] }) logger.info("") logger.info("*** returning {}".format(result)) logger.info("") return result
def dtvLCSTest(): "Create and test the simple LCS topology" topos = {} ## net = Mininet(topo) net = Mininet(controller=lambda a: RemoteController(a, ip='10.0.2.2'), topo=None) net.addController('c0') # Receiver rcv = net.addHost('rcv', ip='10.1.3.3') # The core core = net.addSwitch('core', dpid=int2dpid(5)) # Connect the receiver to the coreh net.addLink(rcv, core) cp = net.addSwitch('cp', dpid=int2dpid(1)) cb = net.addSwitch('cb', dpid=int2dpid(2)) net.addLink(cp, core) net.addLink(cb, core) net.addLink(cp, cb) # Primary and backup routers lp = net.addSwitch('lp', dpid=int2dpid(3)) lb = net.addSwitch('lb', dpid=int2dpid(4)) net.addLink(lp, cp) net.addLink(lb, cb) # Now create all the hosts n = 4 for e in range(n): ipaddr = '10.1.1.' + str(e + 1) print "IP: " + ipaddr enc = net.addHost('e' + str(e + 1), ip=ipaddr) # Add the primary and backup links net.addLink(enc, lp) net.addLink(enc, lb) net.configHosts() net.start() print "Dumping host connections" dumpNodeConnections(net.hosts) print "Testing network connectivity" CLI(net) net.stop()
def topo_init(): myTopo = TreeTopo( depth=3, fanout=3 ) global net net = Mininet( topo=myTopo, switch=OVSSwitch, build=False ) "Creating Controller" c0 = net.addController( 'c0', controller=InbandController, ip='10.0.0.100' ) net.start() "Adding a host for changing to controller" server = net.addHost( 'server', ip='10.0.0.100') s1 = net.get('s1') link = net.addLink( server, s1 ) s1.attach( link.intf2 ) net.configHosts() "Hosts list and the total # of hosts" global hosts_list hosts_list = net.hosts global num_hosts num_hosts = len( hosts_list ) "Assigning IP addresses to switches in the network" switch_list = net.switches n = len(switch_list) ip = hosts_list[-2].IP() for i in range(1,n+1): ip2int = lambda ipstr: struct.unpack( '!I', socket.inet_aton(ipstr))[0] int_ip = ip2int(ip) int_ip+=1 int2ip = lambda n: socket.inet_ntoa(struct.pack('!I', n)) ip = int2ip(int_ip) s = net.get('s%d' % i) s.cmd( 'ifconfig s%d %s ' % (i, ip) ) "Start the controller in 'server' host" global controller_host controller_host = hosts_list[-1] "Fetch the listener host in the network" global server_host server_host = hosts_list[-2] "Start the listener script in the listener host" #info( server_host.cmd( './listener.sh &' ) ) #server_host.cmd( 'while true; do nc -l -p 2222; done > /home/mininet/mininet/custom/dump.txt &' ) "Start the sender script in the remaining hosts"
def failover_test(): """Example/test of fast failover""" myTopo = Diamond() net = Mininet( topo=myTopo, autoStaticArp=True, \ switch=UserSwitch, \ controller=RemoteController ) #controller=PatheticController ) net.configHosts() net.start() #net.controllers[0].real_start() print "* Sleep a few seconds while pathetic installs rules" sleep(10) #CLI(net) testFailover( net ) net.stop()
def configHosts(self): "Configure the networks hosts." # Let Mininet handle the baseline initialization Mininet.configHosts(self) info('*** Starting host services\n') for host in self.hosts: returnCodes = host.autoStartServices() if returnCodes: # print detailed information on the started services statusStr = "%s: " % (host) for service, returnCode in returnCodes.items(): if returnCode['ret'] == 0: result = 'OK' else: result = 'FAIL' statusStr += "%s (%s) " % (service, result) info(statusStr + '\n')
def configHosts(self): "Configure the networks hosts." # Let Mininet handle the baseline initialization Mininet.configHosts(self) info('*** Starting host services\n') for host in self.hosts: returnCodes = host.autoStartServices() if returnCodes: # print detailed information on the started services statusStr = "%s: " % (host) for service, returnCode in returnCodes.iteritems(): if returnCode['ret'] == 0: result = 'OK' else: result = 'FAIL' statusStr += "%s (%s) " % (service, result) info(statusStr + '\n')
def limit( traffic, numEdgeSwitches=20, bw=100 ): """Example/test of link and CPU bandwidth limits traffic: traffic matrix (src,dst,load) bw: interface bandwidth limit in Mbps cpu: cpu limit as fraction of overall CPU time""" # intf = custom( TCIntf, bw=bw, use_tbf=True ) # host = custom( Host, intf=intf ) myTopo = FattreeTopology( numEdgeSwitches=numEdgeSwitches ) net = Mininet( topo=myTopo.mininet_topo(), autoStaticArp=True, \ switch=UserSwitch, \ controller=RemoteController ) switch = net.switches[ 0 ] routes = [ '10.0.0.0/8' ] # host networks to route to net.configHosts() # connectToRootNS( net, switch, routes ) net.start() start_sshd( net ) CLI(net) testThroughput( net, traffic ) stop_sshd( net ) net.stop()
s1 = net.addSwitch( 's1' ) s2 = net.addSwitch( 's2' ) info( "*** Creating hosts\n" ) hosts1 = [ net.addHost( 'h%ds1' % n ) for n in ( 1, 2 ) ] hosts2 = [ net.addHost( 'h%ds2' % n ) for n in ( 1, 2 ) ] info( "*** Creating links\n" ) for h in hosts1: net.addLink( h, s1 ) for h in hosts2: net.addLink( h, s2 ) net.addLink( s1, s2 ) info( "*** Starting network\n" ) net.configHosts() # c0.start() # s1.start( [c0] ) # s2.start( [c0] ) net.start() p = subprocess.Popen(["ovs-ofctl","-O","OpenFlow13","add-flow","s1", "idle_timeout=0,priority=1000,in_port=1,actions=output:2"], stdout=subprocess.PIPE) p = subprocess.Popen(["ovs-ofctl","-O","OpenFlow13","add-flow","s1", "idle_timeout=0,priority=1000,in_port=2,actions=output:1"], stdout=subprocess.PIPE) p.wait()