Statistics
| Branch: | Tag: | Revision:

mininet / examples / limit.py @ 58324bdc

History | View | Annotate | Download (1.93 KB)

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' % release )
31
            if output == '# CONFIG_RT_GROUP_SCHED is not set\n':
32
                info( '*** RT Scheduler is not enabled in your kernel. Skipping this test\n' )
33
                continue
34
        host = custom( CPULimitedHost, sched=sched, cpu=cpu )
35
        net = Mininet( topo=myTopo, intf=intf, host=host )
36
        net.start()
37
        testLinkLimit( net, bw=bw )
38
        net.runCpuLimitTest( cpu=cpu )
39
        net.stop()
40

    
41
def verySimpleLimit( bw=150 ):
42
    "Absurdly simple limiting test"
43
    intf = custom( TCIntf, bw=bw )
44
    net = Mininet( intf=intf )
45
    h1, h2 = net.addHost( 'h1' ), net.addHost( 'h2' )
46
    net.addLink( h1, h2 )
47
    net.start()
48
    net.pingAll()
49
    net.iperf()
50
    h1.cmdPrint( 'tc -s qdisc ls dev', h1.defaultIntf() )
51
    h2.cmdPrint( 'tc -d class show dev', h2.defaultIntf() )
52
    h1.cmdPrint( 'tc -s qdisc ls dev', h1.defaultIntf() )
53
    h2.cmdPrint( 'tc -d class show dev', h2.defaultIntf() )
54
    net.stop()
55

    
56
if __name__ == '__main__':
57
    setLogLevel( 'info' )
58
    limit()