Statistics
| Branch: | Tag: | Revision:

mininet / examples / cpu.py @ e0bf8ece

History | View | Annotate | Download (2.03 KB)

1
#!/usr/bin/python
2

    
3
"""
4
cpu.py: test iperf bandwidth for varying cpu limits
5
"""
6

    
7
from mininet.net import Mininet
8
from mininet.node import CPULimitedHost
9
from mininet.topolib import TreeTopo
10
from mininet.util import custom, waitListening
11
from mininet.log import setLogLevel, info
12

    
13

    
14
def bwtest( cpuLimits, period_us=100000, seconds=5 ):
15
    """Example/test of link and CPU bandwidth limits
16
       cpu: cpu limit as fraction of overall CPU time"""
17

    
18
    topo = TreeTopo( depth=1, fanout=2 )
19

    
20
    results = {}
21

    
22
    for sched in 'rt', 'cfs':
23
        print '*** Testing with', sched, 'bandwidth limiting'
24
        for cpu in cpuLimits:
25
            host = custom( CPULimitedHost, sched=sched,
26
                           period_us=period_us,
27
                           cpu=cpu )
28
            try:
29
                net = Mininet( topo=topo, host=host )
30
            except:
31
                info( '*** Skipping host %s\n' % sched )
32
                break
33
            net.start()
34
            net.pingAll()
35
            hosts = [ net.getNodeByName( h ) for h in topo.hosts() ]
36
            client, server = hosts[ 0 ], hosts[ -1 ]
37
            server.cmd( 'iperf -s -p 5001 &' )
38
            waitListening( client, server, 5001 )
39
            result = client.cmd( 'iperf -yc -t %s -c %s' % (
40
                seconds, server.IP() ) ).split( ',' )
41
            bps = float( result[ -1 ] )
42
            server.cmdPrint( 'kill %iperf' )
43
            net.stop()
44
            updated = results.get( sched, [] )
45
            updated += [ ( cpu, bps ) ]
46
            results[ sched ] = updated
47

    
48
    return results
49

    
50

    
51
def dump( results ):
52
    "Dump results"
53

    
54
    fmt = '%s\t%s\t%s'
55

    
56
    print
57
    print fmt % ( 'sched', 'cpu', 'client MB/s' )
58
    print
59

    
60
    for sched in sorted( results.keys() ):
61
        entries = results[ sched ]
62
        for cpu, bps in entries:
63
            pct = '%.2f%%' % ( cpu * 100 )
64
            mbps = bps / 1e6
65
            print fmt % ( sched, pct, mbps )
66

    
67

    
68
if __name__ == '__main__':
69
    setLogLevel( 'info' )
70
    limits = [ .45, .4, .3, .2, .1 ]
71
    out = bwtest( limits )
72
    dump( out )