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.
10 from mininet.net import Mininet
11 from mininet.node import Controller
12 from mininet.log import setLogLevel, info, warn
14 def validatePort( switch, intf ):
15 "Validate intf's OF port number"
16 ofport = int( switch.cmd( 'ovs-vsctl get Interface', intf,
18 if ofport != switch.ports[ intf ]:
19 warn( 'WARNING: ofport for', intf, 'is actually', ofport, '\n' )
24 def testPortNumbering():
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."""
31 net = Mininet( controller=Controller )
33 info( '*** Adding controller\n' )
34 net.addController( 'c0' )
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' )
43 info( '*** Adding switch\n' )
44 s1 = net.addSwitch( 's1' )
46 info( '*** Creating links\n' )
47 # host 1-4 connect to ports 1-4 on the switch
52 # specify a different port to connect host 5 to on the switch.
53 net.addLink( h5, s1, port1=1, port2= 9)
55 info( '*** Starting network\n' )
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],
65 info( 'Validating that', intfs,
66 'is actually on port', s1.ports[intfs], '... ' )
67 if validatePort( s1, intfs ):
68 info( 'Validated.\n' )
71 # test the network with pingall
75 info( '*** Stopping network\n' )
78 if __name__ == '__main__':