4 limit.py: example of using link and CPU limits
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
15 def testLinkLimit( net, bw ):
16 "Run bandwidth limit test"
17 info( '*** Testing network %.2f Mbps bandwidth limit\n' % bw )
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' )
29 release = quietRun( 'uname -r' ).strip('\r\n')
30 output = quietRun( 'grep CONFIG_RT_GROUP_SCHED /boot/config-%s'
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' )
36 host = custom( CPULimitedHost, sched=sched, cpu=cpu )
37 net = Mininet( topo=myTopo, intf=intf, host=host )
39 testLinkLimit( net, bw=bw )
40 net.runCpuLimitTest( cpu=cpu )
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' )
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() )
58 if __name__ == '__main__':