Statistics
| Branch: | Tag: | Revision:

mininet / examples / controllers.py @ e0e69bbe

History | View | Annotate | Download (1.43 KB)

1
#!/usr/bin/python
2

    
3
"""
4
This example creates a multi-controller network from
5
semi-scratch; note a topo object could also be used and
6
would be passed into the Mininet() constructor.
7
"""
8

    
9
from mininet.net import Mininet
10
from mininet.node import Controller, OVSKernelSwitch
11
from mininet.cli import CLI
12
from mininet.log import setLogLevel
13

    
14
Switch = OVSKernelSwitch
15

    
16
def 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

    
22
def multiControllerNet():
23

    
24
    net = Mininet( controller=Controller, switch=Switch)
25

    
26
    print "*** Creating controllers"
27
    c1 = net.addController( 'c1', port=6633 )
28
    c2 = net.addController( 'c2', port=6634 )
29

    
30
    print "*** Creating switches"
31
    s1 = net.addSwitch( 's1' )
32
    s2 = net.addSwitch( 's2' )
33

    
34
    print "*** Creating hosts"
35
    hosts1 = [ addHost( net, n ) for n in 3, 4 ]
36
    hosts2 = [ addHost( net, n ) for n in 5, 6 ]
37

    
38
    print "*** Creating links"
39
    [ s1.linkTo( h ) for h in hosts1 ]
40
    [ s2.linkTo( h ) for h in hosts2 ]
41
    s1.linkTo( s2 )
42

    
43
    print "*** Starting network"
44
    net.build()
45
    [ controller.start() for controller in c1, c2 ]
46
    s1.start( [ c1 ] )
47
    s2.start( [ c2 ] )
48

    
49
    print "*** Testing network"
50
    net.pingAll()
51

    
52
    print "*** Running CLI"
53
    CLI( net )
54

    
55
    print "*** Stopping network"
56
    net.stop()
57

    
58
if __name__ == '__main__':
59
    setLogLevel( 'info' )  # for CLI output
60
    multiControllerNet()