From e0e69bbeec118e8ccd43f2ce9b6f6fed0c5903f5 Mon Sep 17 00:00:00 2001 From: Bob Lantz Date: Wed, 1 Sep 2010 19:53:09 -0700 Subject: [PATCH] Added new example of multiple controllers. --- examples/controllers.py | 60 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 examples/controllers.py diff --git a/examples/controllers.py b/examples/controllers.py new file mode 100755 index 0000000..340089d --- /dev/null +++ b/examples/controllers.py @@ -0,0 +1,60 @@ +#!/usr/bin/python + +""" +This example creates a multi-controller network from +semi-scratch; note a topo object could also be used and +would be passed into the Mininet() constructor. +""" + +from mininet.net import Mininet +from mininet.node import Controller, OVSKernelSwitch +from mininet.cli import CLI +from mininet.log import setLogLevel + +Switch = OVSKernelSwitch + +def addHost( net, N ): + "Create host hN and add to net." + name = 'h%d' % N + ip = '10.0.0.%d' % N + return net.addHost( name, ip=ip ) + +def multiControllerNet(): + + net = Mininet( controller=Controller, switch=Switch) + + print "*** Creating 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 = [ addHost( net, n ) for n in 3, 4 ] + hosts2 = [ addHost( net, n ) for n in 5, 6 ] + + print "*** Creating links" + [ s1.linkTo( h ) for h in hosts1 ] + [ s2.linkTo( h ) for h in hosts2 ] + s1.linkTo( s2 ) + + print "*** Starting network" + net.build() + [ controller.start() for controller in c1, c2 ] + s1.start( [ c1 ] ) + s2.start( [ c2 ] ) + + print "*** Testing network" + net.pingAll() + + print "*** Running CLI" + CLI( net ) + + print "*** Stopping network" + net.stop() + +if __name__ == '__main__': + setLogLevel( 'info' ) # for CLI output + multiControllerNet()