Statistics
| Branch: | Tag: | Revision:

mininet / examples / limit.py @ c5da46f1

History | View | Annotate | Download (1.56 KB)

1 4ac1148e Bob Lantz
#!/usr/bin/python
2
3
"""
4
limit.py: example of using link and CPU limits
5
"""
6
7
from mininet.net import Mininet
8 216a4b7c Bob Lantz
from mininet.link import TCIntf
9 4ac1148e Bob Lantz
from mininet.node import CPULimitedHost
10
from mininet.topolib import TreeTopo
11 fcd01592 Brandon Heller
from mininet.util import custom
12 4ac1148e Bob Lantz
from mininet.log import setLogLevel
13 fcd01592 Brandon Heller
14 4ac1148e Bob Lantz
15 216a4b7c Bob Lantz
def testLinkLimit( net, bw ):
16 14ff3ad3 Bob Lantz
    "Run bandwidth limit test"
17 216a4b7c Bob Lantz
    print '*** Testing network %.2f Mbps bandwidth limit' % bw
18
    net.iperf( )
19 4ac1148e Bob Lantz
20
21 fcd01592 Brandon Heller
def limit( bw=10, cpu=.1 ):
22 216a4b7c Bob Lantz
    """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 ba8d4f9b Bob Lantz
    intf = custom( TCIntf, bw=bw )
26 4ac1148e Bob Lantz
    myTopo = TreeTopo( depth=1, fanout=2 )
27 216a4b7c Bob Lantz
    for sched in 'rt', 'cfs':
28
        print '*** Testing with', sched, 'bandwidth limiting'
29 f89d9a4d Bob Lantz
        host = custom( CPULimitedHost, sched=sched, cpu=cpu )
30 216a4b7c Bob Lantz
        net = Mininet( topo=myTopo, intf=intf, host=host )
31
        net.start()
32
        testLinkLimit( net, bw=bw )
33 fcd01592 Brandon Heller
        net.runCpuLimitTest( cpu=cpu )
34 216a4b7c Bob Lantz
        net.stop()
35 4ac1148e Bob Lantz
36 ba8d4f9b Bob Lantz
def verySimpleLimit( bw=150 ):
37 612b21cb Bob Lantz
    "Absurdly simple limiting test"
38 ba8d4f9b Bob Lantz
    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 612b21cb Bob Lantz
51 4ac1148e Bob Lantz
if __name__ == '__main__':
52
    setLogLevel( 'info' )
53 00d9b780 Bob Lantz
    limit()