carlosmscabral | f40ecd1 | 2013-02-01 18:15:58 -0200 | [diff] [blame] | 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 |
| 12 | from mininet.log import setLogLevel |
| 13 | |
| 14 | |
| 15 | def testLinkLimit( net, bw ): |
| 16 | "Run bandwidth limit test" |
| 17 | print '*** Testing network %.2f Mbps bandwidth limit' % bw |
| 18 | net.iperf( ) |
| 19 | |
| 20 | |
| 21 | def limit( bw=10, cpu=.1 ): |
| 22 | """Example/test of link and CPU bandwidth limits |
| 23 | bw: interface bandwidth limit in Mbps |
| 24 | cpu: cpu limit as fraction of overall CPU time""" |
| 25 | intf = custom( TCIntf, bw=bw ) |
| 26 | myTopo = TreeTopo( depth=1, fanout=2 ) |
| 27 | for sched in 'rt', 'cfs': |
| 28 | print '*** Testing with', sched, 'bandwidth limiting' |
| 29 | host = custom( CPULimitedHost, sched=sched, cpu=cpu ) |
| 30 | net = Mininet( topo=myTopo, intf=intf, host=host ) |
| 31 | net.start() |
| 32 | testLinkLimit( net, bw=bw ) |
| 33 | net.runCpuLimitTest( cpu=cpu ) |
| 34 | net.stop() |
| 35 | |
| 36 | def verySimpleLimit( bw=150 ): |
| 37 | "Absurdly simple limiting test" |
| 38 | intf = custom( TCIntf, bw=bw ) |
| 39 | net = Mininet( intf=intf ) |
| 40 | h1, h2 = net.addHost( 'h1' ), net.addHost( 'h2' ) |
| 41 | net.addLink( h1, h2 ) |
| 42 | net.start() |
| 43 | net.pingAll() |
| 44 | net.iperf() |
| 45 | h1.cmdPrint( 'tc -s qdisc ls dev', h1.defaultIntf() ) |
| 46 | h2.cmdPrint( 'tc -d class show dev', h2.defaultIntf() ) |
| 47 | h1.cmdPrint( 'tc -s qdisc ls dev', h1.defaultIntf() ) |
| 48 | h2.cmdPrint( 'tc -d class show dev', h2.defaultIntf() ) |
| 49 | net.stop() |
| 50 | |
| 51 | if __name__ == '__main__': |
| 52 | setLogLevel( 'info' ) |
| 53 | limit() |