Example/test of link and CPU bandwidth limits cpu: cpu limit as fraction of overall CPU time
( cpuLimits, period_us=100000, seconds=10 )
| 36 | from mininet.clean import cleanup |
| 37 | |
| 38 | def bwtest( cpuLimits, period_us=100000, seconds=10 ): |
| 39 | """Example/test of link and CPU bandwidth limits |
| 40 | cpu: cpu limit as fraction of overall CPU time""" |
| 41 | |
| 42 | topo = TreeTopo( depth=1, fanout=2 ) |
| 43 | |
| 44 | results = {} |
| 45 | |
| 46 | for sched in 'rt', 'cfs': |
| 47 | info( '*** Testing with', sched, 'bandwidth limiting\n' ) |
| 48 | for cpu in cpuLimits: |
| 49 | # cpu is the cpu fraction for all hosts, so we divide |
| 50 | # it across two hosts |
| 51 | host = custom( CPULimitedHost, sched=sched, |
| 52 | period_us=period_us, |
| 53 | cpu=.5*cpu ) |
| 54 | try: |
| 55 | net = Mininet( topo=topo, host=host, waitConnected=True ) |
| 56 | # pylint: disable=bare-except |
| 57 | except: # noqa |
| 58 | info( '*** Skipping scheduler %s and cleaning up\n' % sched ) |
| 59 | cleanup() |
| 60 | break |
| 61 | net.start() |
| 62 | net.pingAll() |
| 63 | hosts = [ net.getNodeByName( h ) for h in topo.hosts() ] |
| 64 | client, server = hosts[ 0 ], hosts[ -1 ] |
| 65 | info( '*** Starting iperf with %d%% of CPU allocated to hosts\n' % |
| 66 | ( 100.0 * cpu ) ) |
| 67 | # We measure at the server because it doesn't include |
| 68 | # the client's buffer fill rate |
| 69 | popen = server.popen( 'iperf -yc -s -p 5001' ) |
| 70 | waitListening( client, server, 5001 ) |
| 71 | client.cmd( 'iperf -yc -t %s -c %s' % ( seconds, server.IP() ) ) |
| 72 | # ignore empty result from waitListening/telnet for old iperf |
| 73 | svals = {} |
| 74 | while not svals or int( svals[ 'rate' ] ) == 0: |
| 75 | line = decode( popen.stdout.readline() ) |
| 76 | # Probably shouldn't depend on an internal method, but |
| 77 | # this is the easiest way |
| 78 | svals = Mininet._iperfVals( # pylint: disable=protected-access |
| 79 | line, server.IP() ) |
| 80 | bps = float( svals[ 'rate' ] ) |
| 81 | popen.terminate() |
| 82 | net.stop() |
| 83 | updated = results.get( sched, [] ) |
| 84 | updated += [ ( cpu, bps ) ] |
| 85 | results[ sched ] = updated |
| 86 | |
| 87 | return results |
| 88 | |
| 89 | |
| 90 | def dump( results ): |
no test coverage detected