Update and rename MantenerFIFO to MantenerFIFO.md
[vsorcdistro/.git] / mininet / examples / limit.py
1 #!/usr/bin/python
2
3 """
4 limit.py: example of using link and CPU limits
5 """
6
7 from mininet.net import Mininet
8 from mininet.link import TCIntf
9 from mininet.node import CPULimitedHost
10 from mininet.topolib import TreeTopo
11 from mininet.util import custom, quietRun
12 from mininet.log import setLogLevel, info
13
14
15 def testLinkLimit( net, bw ):
16     "Run bandwidth limit test"
17     info( '*** Testing network %.2f Mbps bandwidth limit\n' % bw )
18     net.iperf()
19
20 def limit( bw=10, cpu=.1 ):
21     """Example/test of link and CPU bandwidth limits
22        bw: interface bandwidth limit in Mbps
23        cpu: cpu limit as fraction of overall CPU time"""
24     intf = custom( TCIntf, bw=bw )
25     myTopo = TreeTopo( depth=1, fanout=2 )
26     for sched in 'rt', 'cfs':
27         info( '*** Testing with', sched, 'bandwidth limiting\n' )
28         if sched == 'rt':
29             release = quietRun( 'uname -r' ).strip('\r\n')
30             output = quietRun( 'grep CONFIG_RT_GROUP_SCHED /boot/config-%s'
31                                % release )
32             if output == '# CONFIG_RT_GROUP_SCHED is not set\n':
33                 info( '*** RT Scheduler is not enabled in your kernel. '
34                       'Skipping this test\n' )
35                 continue
36         host = custom( CPULimitedHost, sched=sched, cpu=cpu )
37         net = Mininet( topo=myTopo, intf=intf, host=host )
38         net.start()
39         testLinkLimit( net, bw=bw )
40         net.runCpuLimitTest( cpu=cpu )
41         net.stop()
42
43 def verySimpleLimit( bw=150 ):
44     "Absurdly simple limiting test"
45     intf = custom( TCIntf, bw=bw )
46     net = Mininet( intf=intf )
47     h1, h2 = net.addHost( 'h1' ), net.addHost( 'h2' )
48     net.addLink( h1, h2 )
49     net.start()
50     net.pingAll()
51     net.iperf()
52     h1.cmdPrint( 'tc -s qdisc ls dev', h1.defaultIntf() )
53     h2.cmdPrint( 'tc -d class show dev', h2.defaultIntf() )
54     h1.cmdPrint( 'tc -s qdisc ls dev', h1.defaultIntf() )
55     h2.cmdPrint( 'tc -d class show dev', h2.defaultIntf() )
56     net.stop()
57
58 if __name__ == '__main__':
59     setLogLevel( 'info' )
60     limit()