Example #1
0
def pairNet( pairs=1, useSwitches=False, bw=None, cpu=-1, **kwargs ):
    "Convenience function for creating pair networks"
    clients, servers = [], []
    # This is a bit ugly - a lot of work to avoid flushing
    # routes; I think we should rethink how that works.
    class MyHost( CPULimitedHost ):
        "Put clients in root namespace and DON'T flush routes"
        def __init__( self, name, **kwargs ):
            # First N (=pairs) hosts are clients, in root NS
            kwargs.pop('inNamespace', True)
            isServer = int( name[ 1: ] ) > pairs
            CPULimitedHost.__init__( self, name, inNamespace=isServer, **kwargs )
        def setDefaultRoute( self, intf ):
            "Hack of sorts: don't set or flush route"
            pass

    cpu = custom( MyHost, cpu=cpu )
    link = custom( TCLink, bw=bw )
    topo = PairTopo( pairs, useSwitches )
    net = Mininet( topo, host=MyHost, **kwargs )
    net.hosts = sorted( net.hosts, key=lambda h: natural( h.name ) )
    clients, servers = net.hosts[ :pairs ], net.hosts[ pairs: ]
    info( "*** Configuring host routes\n" )
    for client, server in zip( clients, servers ):
        client.setHostRoute( server.IP(), client.defaultIntf() )
        server.setHostRoute( client.IP(), server.defaultIntf() )
    return net, clients, servers
Example #2
0
info( '* Starting Control Network\n')
cnet.build()
cnet.start()
dataControllers = cnet.hosts[ : -1 ]  # ignore 'root' node

info( '* Creating Data Network\n' )
topo = TreeTopo( depth=2, fanout=2 )
# UserSwitch so we can easily test failover
net = Mininet( topo=topo, switch=UserSwitch, build=False )
info( '* Adding Controllers to Data Network\n' )
net.controllers = dataControllers
net.build()
info( '* Starting Data Network\n')
net.start()

CLI2( net, cnet=cnet )

info( '* Stopping Data Network\n' )
net.stop()

info( '* Stopping Control Network\n' )
# dataControllers have already been stopped
cnet.hosts = list( set( cnet.hosts ) - set( dataControllers ) )
cnet.stop()






Example #3
0
info('* Creating Control Network\n')
ctopo = ControlNetwork(n=4, dataController=DataController)
cnet = Mininet(topo=ctopo, ipBase='192.168.123.0/24', build=False)
info('* Adding Control Network Controller\n')
cnet.addController('cc0')
info('* Starting Control Network\n')
cnet.build()
cnet.start()
dataControllers = cnet.hosts[:-1]  # ignore 'root' node

info('* Creating Data Network\n')
topo = TreeTopo(depth=2, fanout=2)
# UserSwitch so we can easily test failover
net = Mininet(topo=topo, switch=UserSwitch, build=False)
info('* Adding Controllers to Data Network\n')
net.controllers = dataControllers
net.build()
info('* Starting Data Network\n')
net.start()

CLI2(net, cnet=cnet)

info('* Stopping Data Network\n')
net.stop()

info('* Stopping Control Network\n')
# dataControllers have already been stopped
cnet.hosts = list(set(cnet.hosts) - set(dataControllers))
cnet.stop()