Update and rename MantenerFIFO to MantenerFIFO.md
[vsorcdistro/.git] / mininet / examples / controllers2.py
1 #!/usr/bin/python
2
3 """
4 This example creates a multi-controller network from semi-scratch by
5 using the net.add*() API and manually starting the switches and controllers.
6
7 This is the "mid-level" API, which is an alternative to the "high-level"
8 Topo() API which supports parametrized topology classes.
9
10 Note that one could also create a custom switch class and pass it into
11 the Mininet() constructor.
12 """
13
14
15 from mininet.net import Mininet
16 from mininet.node import Controller, OVSSwitch
17 from mininet.cli import CLI
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
25     info( "*** Creating (reference) controllers\n" )
26     c1 = net.addController( 'c1', port=6633 )
27     c2 = net.addController( 'c2', port=6634 )
28
29     info( "*** Creating switches\n" )
30     s1 = net.addSwitch( 's1' )
31     s2 = net.addSwitch( 's2' )
32
33     info( "*** Creating hosts\n" )
34     hosts1 = [ net.addHost( 'h%d' % n ) for n in ( 3, 4 ) ]
35     hosts2 = [ net.addHost( 'h%d' % n ) for n in ( 5, 6 ) ]
36
37     info( "*** Creating links\n" )
38     for h in hosts1:
39         net.addLink( s1, h )
40     for h in hosts2:
41         net.addLink( s2, h )
42     net.addLink( s1, s2 )
43
44     info( "*** Starting network\n" )
45     net.build()
46     c1.start()
47     c2.start()
48     s1.start( [ c1 ] )
49     s2.start( [ c2 ] )
50
51     info( "*** Testing network\n" )
52     net.pingAll()
53
54     info( "*** Running CLI\n" )
55     CLI( net )
56
57     info( "*** Stopping network\n" )
58     net.stop()
59
60 if __name__ == '__main__':
61     setLogLevel( 'info' )  # for CLI output
62     multiControllerNet()