Create a network from semi-scratch with multiple controllers.
()
| 18 | from mininet.log import setLogLevel, info |
| 19 | |
| 20 | def multiControllerNet(): |
| 21 | "Create a network from semi-scratch with multiple controllers." |
| 22 | |
| 23 | net = Mininet( controller=Controller, switch=OVSSwitch, |
| 24 | waitConnected=True ) |
| 25 | |
| 26 | info( "*** Creating (reference) controllers\n" ) |
| 27 | c1 = net.addController( 'c1', port=6633 ) |
| 28 | c2 = net.addController( 'c2', port=6634 ) |
| 29 | |
| 30 | info( "*** Creating switches\n" ) |
| 31 | s1 = net.addSwitch( 's1' ) |
| 32 | s2 = net.addSwitch( 's2' ) |
| 33 | |
| 34 | info( "*** Creating hosts\n" ) |
| 35 | hosts1 = [ net.addHost( 'h%d' % n ) for n in ( 3, 4 ) ] |
| 36 | hosts2 = [ net.addHost( 'h%d' % n ) for n in ( 5, 6 ) ] |
| 37 | |
| 38 | info( "*** Creating links\n" ) |
| 39 | for h in hosts1: |
| 40 | net.addLink( s1, h ) |
| 41 | for h in hosts2: |
| 42 | net.addLink( s2, h ) |
| 43 | net.addLink( s1, s2 ) |
| 44 | |
| 45 | info( "*** Starting network\n" ) |
| 46 | net.build() |
| 47 | c1.start() |
| 48 | c2.start() |
| 49 | s1.start( [ c1 ] ) |
| 50 | s2.start( [ c2 ] ) |
| 51 | |
| 52 | info( "*** Testing network\n" ) |
| 53 | net.pingAll() |
| 54 | |
| 55 | info( "*** Running CLI\n" ) |
| 56 | CLI( net ) |
| 57 | |
| 58 | info( "*** Stopping network\n" ) |
| 59 | net.stop() |
| 60 | |
| 61 | |
| 62 | if __name__ == '__main__': |