Update and rename MantenerFIFO to MantenerFIFO.md
[vsorcdistro/.git] / mininet / examples / numberedports.py
1 #!/usr/bin/python
2
3 """
4 Create a network with 5 hosts, numbered 1-4 and 9.
5 Validate that the port numbers match to the interface name,
6 and that the ovs ports match the mininet ports.
7 """
8
9
10 from mininet.net import Mininet
11 from mininet.node import Controller
12 from mininet.log import setLogLevel, info, warn
13
14 def validatePort( switch, intf ):
15     "Validate intf's OF port number"
16     ofport = int( switch.cmd( 'ovs-vsctl get Interface', intf,
17                               'ofport' ) )
18     if ofport != switch.ports[ intf ]:
19         warn( 'WARNING: ofport for', intf, 'is actually', ofport, '\n' )
20         return 0
21     else:
22         return 1
23
24 def testPortNumbering():
25
26     """Test port numbering:
27        Create a network with 5 hosts (using Mininet's
28        mid-level API) and check that implicit and
29        explicit port numbering works as expected."""
30
31     net = Mininet( controller=Controller )
32
33     info( '*** Adding controller\n' )
34     net.addController( 'c0' )
35
36     info( '*** Adding hosts\n' )
37     h1 = net.addHost( 'h1', ip='10.0.0.1' )
38     h2 = net.addHost( 'h2', ip='10.0.0.2' )
39     h3 = net.addHost( 'h3', ip='10.0.0.3' )
40     h4 = net.addHost( 'h4', ip='10.0.0.4' )
41     h5 = net.addHost( 'h5', ip='10.0.0.5' )
42
43     info( '*** Adding switch\n' )
44     s1 = net.addSwitch( 's1' )
45
46     info( '*** Creating links\n' )
47     # host 1-4 connect to ports 1-4 on the switch
48     net.addLink( h1, s1 )
49     net.addLink( h2, s1 )
50     net.addLink( h3, s1 )
51     net.addLink( h4, s1 )
52     # specify a different port to connect host 5 to on the switch.
53     net.addLink( h5, s1, port1=1, port2= 9)
54
55     info( '*** Starting network\n' )
56     net.start()
57
58     # print the interfaces and their port numbers
59     info( '\n*** printing and validating the ports '
60           'running on each interface\n' )
61     for intfs in s1.intfList():
62         if not intfs.name == "lo":
63             info( intfs, ': ', s1.ports[intfs],
64                   '\n' )
65             info( 'Validating that', intfs,
66                    'is actually on port', s1.ports[intfs], '... ' )
67             if validatePort( s1, intfs ):
68                 info( 'Validated.\n' )
69     info( '\n' )
70
71     # test the network with pingall
72     net.pingAll()
73     info( '\n' )
74
75     info( '*** Stopping network\n' )
76     net.stop()
77
78 if __name__ == '__main__':
79     setLogLevel( 'info' )
80     testPortNumbering()