Exemple #1
0
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()
Exemple #2
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()
Exemple #3
0
def emptyNet():

    "Create an empty network and add nodes to it."

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

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

    info('*** Creating links\n')
    net.addLink(h1, s3)
    net.addLink(h2, s3)

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

    info('*** Running CLI\n')
    CLI(net)

    info('*** Stopping network')
    net.stop()
Exemple #4
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()
Exemple #5
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()
Exemple #6
0
 def addController( self, *args, **kwargs ):
     "Patch to update IP address to global IP address"
     controller = Mininet.addController( self, *args, **kwargs )
     # Update IP address for controller that may not be local
     if ( isinstance( controller, Controller)
          and controller.IP() == '127.0.0.1'
          and ' eth0:' in controller.cmd( 'ip link show' ) ):
         Intf( 'eth0', node=controller ).updateIP()
     return controller
Exemple #7
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()
Exemple #8
0
from src.mininet.topolib import TreeTopo
from src.mininet.log import setLogLevel
from src.mininet.cli import CLI

setLogLevel('info')

# Two local and one "external" controller (which is actually c0)
# Ignore the warning message that the remote isn't (yet) running
c0 = Controller('c0', port=6633)
c1 = Controller('c1', port=6634)
c2 = RemoteController('c2', ip='127.0.0.1', port=6633)

cmap = {'s1': c0, 's2': c1, 's3': c2}


class MultiSwitch(OVSSwitch):
    "Custom Switch() subclass that connects to different controllers"

    def start(self, controllers):
        return OVSSwitch.start(self, [cmap[self.name]])


topo = TreeTopo(depth=2, fanout=2)
net = Mininet(topo=topo, switch=MultiSwitch, build=False)
for c in [c0, c1]:
    net.addController(c)
net.build()
net.start()
CLI(net)
net.stop()