Update and rename MantenerFIFO to MantenerFIFO.md
[vsorcdistro/.git] / mininet / examples / simpleperf.py
1 #!/usr/bin/python
2
3 """
4 Simple example of setting network and CPU parameters
5
6 NOTE: link params limit BW, add latency, and loss.
7 There is a high chance that pings WILL fail and that
8 iperf will hang indefinitely if the TCP handshake fails
9 to complete.
10 """
11
12
13 from mininet.topo import Topo
14 from mininet.net import Mininet
15 from mininet.node import CPULimitedHost
16 from mininet.link import TCLink
17 from mininet.util import dumpNodeConnections
18 from mininet.log import setLogLevel, info
19
20 from sys import argv
21
22 # It would be nice if we didn't have to do this:
23 # pylint: disable=arguments-differ
24
25 class SingleSwitchTopo( Topo ):
26     "Single switch connected to n hosts."
27     def build( self, n=2, lossy=True ):
28         switch = self.addSwitch('s1')
29         for h in range(n):
30             # Each host gets 50%/n of system CPU
31             host = self.addHost('h%s' % (h + 1),
32                                 cpu=.5 / n)
33             if lossy:
34                 # 10 Mbps, 5ms delay, 10% packet loss
35                 self.addLink(host, switch,
36                              bw=10, delay='5ms', loss=10, use_htb=True)
37             else:
38                 # 10 Mbps, 5ms delay, no packet loss
39                 self.addLink(host, switch,
40                              bw=10, delay='5ms', loss=0, use_htb=True)
41
42
43 def perfTest( lossy=True ):
44     "Create network and run simple performance test"
45     topo = SingleSwitchTopo( n=4, lossy=lossy )
46     net = Mininet( topo=topo,
47                    host=CPULimitedHost, link=TCLink,
48                    autoStaticArp=True )
49     net.start()
50     info( "Dumping host connections\n" )
51     dumpNodeConnections(net.hosts)
52     info( "Testing bandwidth between h1 and h4\n" )
53     h1, h4 = net.getNodeByName('h1', 'h4')
54     net.iperf( ( h1, h4 ), l4Type='UDP' )
55     net.stop()
56
57 if __name__ == '__main__':
58     setLogLevel( 'info' )
59     # Prevent test_simpleperf from failing due to packet loss
60     perfTest( lossy=( 'testmode' not in argv ) )