Пример #1
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()
Пример #2
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()