Exemplo n.º 1
0
def mobilityTest():
    "A simple test of mobility"
    print '* Simple mobility test'
    net = Mininet(topo=LinearTopo(3), switch=MobilitySwitch)
    print '* Starting network:'
    net.start()
    printConnections(net.switches)
    print '* Testing network'
    net.pingAll()
    print '* Identifying switch interface for h1'
    h1, old = net.get('h1', 's1')
    for s in 2, 3, 1:
        new = net['s%d' % s]
        port = randint(10, 20)
        print '* Moving', h1, 'from', old, 'to', new, 'port', port
        hintf, sintf = moveHost(h1, old, new, newPort=port)
        print '*', hintf, 'is now connected to', sintf
        print '* Clearing out old flows'
        for sw in net.switches:
            sw.dpctl('del-flows')
        print '* New network:'
        printConnections(net.switches)
        print '* Testing connectivity:'
        net.pingAll()
        old = new
    net.stop()
Exemplo n.º 2
0
def testRemoteNet( remote='ubuntu2' ):
    "Test remote Node classes"
    print '*** Remote Node Test'
    net = Mininet( host=RemoteHost, switch=RemoteOVSSwitch,
                   link=RemoteLink )
    c0 = net.addController( 'c0' )
    # Make sure controller knows its non-loopback address
    Intf( 'eth0', node=c0 ).updateIP()
    print "*** Creating local h1"
    h1 = net.addHost( 'h1' )
    print "*** Creating remote h2"
    h2 = net.addHost( 'h2', server=remote )
    print "*** Creating local s1"
    s1 = net.addSwitch( 's1' )
    print "*** Creating remote s2"
    s2 = net.addSwitch( 's2', server=remote )
    print "*** Adding links"
    net.addLink( h1, s1 )
    net.addLink( s1, s2 )
    net.addLink( h2, s2 )
    net.start()
    print 'Mininet is running on', quietRun( 'hostname' ).strip()
    for node in c0, h1, h2, s1, s2:
        print 'Node', node, 'is running on', node.cmd( 'hostname' ).strip()
    net.pingAll()
    CLI( net )
    net.stop()
Exemplo n.º 3
0
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()
Exemplo n.º 4
0
def testRemoteTopo():
    "Test remote Node classes using Mininet()/Topo() API"
    topo = LinearTopo( 2 )
    net = Mininet( topo=topo, host=HostPlacer, switch=SwitchPlacer,
                   link=RemoteLink, controller=ClusterController )
    net.start()
    net.pingAll()
    net.stop()
Exemplo n.º 5
0
def testNsTunnels():
    "Test tunnels between nodes in namespaces"
    net = Mininet( host=RemoteHost, link=RemoteLink )
    h1 = net.addHost( 'h1' )
    h2 = net.addHost( 'h2', server='ubuntu2' )
    net.addLink( h1, h2 )
    net.start()
    net.pingAll()
    net.stop()
Exemplo n.º 6
0
def testPortNumbering():
    """Test port numbering:
       Create a network with 5 hosts (using Mininet's
       mid-level API) and check that implicit and
       explicit port numbering works as expected."""

    net = Mininet(controller=Controller)

    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')
    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')

    info('*** Adding switch\n')
    s1 = net.addSwitch('s1')

    info('*** Creating links\n')
    # host 1-4 connect to ports 1-4 on the switch
    net.addLink(h1, s1)
    net.addLink(h2, s1)
    net.addLink(h3, s1)
    net.addLink(h4, s1)
    # specify a different port to connect host 5 to on the switch.
    net.addLink(h5, s1, port1=1, port2=9)

    info('*** Starting network\n')
    net.start()

    # print the interfaces and their port numbers
    info('\n*** printing and validating the ports '
         'running on each interface\n')
    for intfs in s1.intfList():
        if not intfs.name == "lo":
            info(intfs, ': ', s1.ports[intfs], '\n')
            info('Validating that', intfs, 'is actually on port',
                 s1.ports[intfs], '... ')
            if validatePort(s1, intfs):
                info('Validated.\n')
    print '\n'

    # test the network with pingall
    net.pingAll()
    print '\n'

    info('*** Stopping network')
    net.stop()
Exemplo n.º 7
0
def verySimpleLimit(bw=150):
    "Absurdly simple limiting test"
    intf = custom(TCIntf, bw=bw)
    net = Mininet(intf=intf)
    h1, h2 = net.addHost('h1'), net.addHost('h2')
    net.addLink(h1, h2)
    net.start()
    net.pingAll()
    net.iperf()
    h1.cmdPrint('tc -s qdisc ls dev', h1.defaultIntf())
    h2.cmdPrint('tc -d class show dev', h2.defaultIntf())
    h1.cmdPrint('tc -s qdisc ls dev', h1.defaultIntf())
    h2.cmdPrint('tc -d class show dev', h2.defaultIntf())
    net.stop()
Exemplo n.º 8
0
def multiControllerNet():
    "Create a network from semi-scratch with multiple controllers."

    net = Mininet(controller=Controller, switch=OVSSwitch)

    print "*** Creating (reference) controllers"
    c1 = net.addController('c1', port=6633)
    c2 = net.addController('c2', port=6634)

    print "*** Creating switches"
    s1 = net.addSwitch('s1')
    s2 = net.addSwitch('s2')

    print "*** Creating hosts"
    hosts1 = [net.addHost('h%d' % n) for n in 3, 4]
    hosts2 = [net.addHost('h%d' % n) for n in 5, 6]

    print "*** Creating links"
    for h in hosts1:
        net.addLink(s1, h)
    for h in hosts2:
        net.addLink(s2, h)
    net.addLink(s1, s2)

    print "*** Starting network"
    net.build()
    c1.start()
    c2.start()
    s1.start([c1])
    s2.start([c2])

    print "*** Testing network"
    net.pingAll()

    print "*** Running CLI"
    CLI(net)

    print "*** Stopping network"
    net.stop()
Exemplo n.º 9
0
def bwtest(cpuLimits, period_us=100000, seconds=5):
    """Example/test of link and CPU bandwidth limits
       cpu: cpu limit as fraction of overall CPU time"""

    topo = TreeTopo(depth=1, fanout=2)

    results = {}

    for sched in 'rt', 'cfs':
        print '*** Testing with', sched, 'bandwidth limiting'
        for cpu in cpuLimits:
            host = custom(CPULimitedHost,
                          sched=sched,
                          period_us=period_us,
                          cpu=cpu)
            try:
                net = Mininet(topo=topo, host=host)
            # pylint: disable=bare-except
            except:
                info('*** Skipping host %s\n' % sched)
                break
            net.start()
            net.pingAll()
            hosts = [net.getNodeByName(h) for h in topo.hosts()]
            client, server = hosts[0], hosts[-1]
            server.cmd('iperf -s -p 5001 &')
            waitListening(client, server, 5001)
            result = client.cmd('iperf -yc -t %s -c %s' %
                                (seconds, server.IP())).split(',')
            bps = float(result[-1])
            server.cmdPrint('kill %iperf')
            net.stop()
            updated = results.get(sched, [])
            updated += [(cpu, bps)]
            results[sched] = updated

    return results
Exemplo n.º 10
0
from src.mininet.cli import CLI
from src.mininet.log import lg, info
from src.mininet.net import Mininet
from src.mininet.node import OVSKernelSwitch
from src.mininet.topolib import TreeTopo


def ifconfigTest(net):
    "Run ifconfig on all hosts in net."
    hosts = net.hosts
    for host in hosts:
        info(host.cmd('ifconfig'))


if __name__ == '__main__':
    lg.setLogLevel('info')
    info("*** Initializing Mininet and kernel modules\n")
    OVSKernelSwitch.setup()
    info("*** Creating network\n")
    network = Mininet(TreeTopo(depth=2, fanout=2), switch=OVSKernelSwitch)
    info("*** Starting network\n")
    network.start()
    info("*** Running ping test\n")
    network.pingAll()
    info("*** Running ifconfig test\n")
    ifconfigTest(network)
    info("*** Starting CLI (type 'exit' to exit)\n")
    CLI(network)
    info("*** Stopping network\n")
    network.stop()