blob: 6eeef0e577195d7a545e1672e46fa8e874948969 [file] [log] [blame]
carlosmscabralf40ecd12013-02-01 18:15:58 -02001#!/usr/bin/python
2
3"""
4This example creates a multi-controller network from
5semi-scratch; note a topo object could also be used and
6would be passed into the Mininet() constructor.
7"""
8
9from mininet.net import Mininet
10from mininet.node import Controller, OVSKernelSwitch
11from mininet.cli import CLI
12from mininet.log import setLogLevel
13
14Switch = OVSKernelSwitch
15
16def addHost( net, N ):
17 "Create host hN and add to net."
18 name = 'h%d' % N
19 ip = '10.0.0.%d' % N
20 return net.addHost( name, ip=ip )
21
22def multiControllerNet():
23 "Create a network with multiple controllers."
24
25 net = Mininet( controller=Controller, switch=Switch)
26
27 print "*** Creating controllers"
28 c1 = net.addController( 'c1', port=6633 )
29 c2 = net.addController( 'c2', port=6634 )
30
31 print "*** Creating switches"
32 s1 = net.addSwitch( 's1' )
33 s2 = net.addSwitch( 's2' )
34
35 print "*** Creating hosts"
36 hosts1 = [ addHost( net, n ) for n in 3, 4 ]
37 hosts2 = [ addHost( net, n ) for n in 5, 6 ]
38
39 print "*** Creating links"
40 for h in hosts1:
41 s1.linkTo( h )
42 for h in hosts2:
43 s2.linkTo( h )
44 s1.linkTo( s2 )
45
46 print "*** Starting network"
47 net.build()
48 c1.start()
49 c2.start()
50 s1.start( [ c1 ] )
51 s2.start( [ c2 ] )
52
53 print "*** Testing network"
54 net.pingAll()
55
56 print "*** Running CLI"
57 CLI( net )
58
59 print "*** Stopping network"
60 net.stop()
61
62if __name__ == '__main__':
63 setLogLevel( 'info' ) # for CLI output
64 multiControllerNet()