blob: 0b23ca1de1eb67f2555d4e23fc993aa6189b8631 [file] [log] [blame]
carlosmscabralf40ecd12013-02-01 18:15:58 -02001#!/usr/bin/python
2
3"""
4limit.py: example of using link and CPU limits
5"""
6
7from mininet.net import Mininet
8from mininet.link import TCIntf
9from mininet.node import CPULimitedHost
10from mininet.topolib import TreeTopo
11from mininet.util import custom
12from mininet.log import setLogLevel
13
14
15def testLinkLimit( net, bw ):
16 "Run bandwidth limit test"
17 print '*** Testing network %.2f Mbps bandwidth limit' % bw
18 net.iperf( )
19
20
21def 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
36def 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
51if __name__ == '__main__':
52 setLogLevel( 'info' )
53 limit()