Statistics
| Branch: | Tag: | Revision:

## mininet / examples / limit.py @ c5da46f1

1 2 3 4ac1148e Bob Lantz ```#!/usr/bin/python ``` ```""" ``` ```limit.py: example of using link and CPU limits ``` ```""" ``` ```from mininet.net import Mininet ``` 216a4b7c Bob Lantz ```from mininet.link import TCIntf ``` 4ac1148e Bob Lantz ```from mininet.node import CPULimitedHost ``` ```from mininet.topolib import TreeTopo ``` fcd01592 Brandon Heller ```from mininet.util import custom ``` 4ac1148e Bob Lantz ```from mininet.log import setLogLevel ``` fcd01592 Brandon Heller 4ac1148e Bob Lantz 216a4b7c Bob Lantz ```def testLinkLimit( net, bw ): ``` 14ff3ad3 Bob Lantz ``` "Run bandwidth limit test" ``` 216a4b7c Bob Lantz ``` print '*** Testing network %.2f Mbps bandwidth limit' % bw ``` ``` net.iperf( ) ``` 4ac1148e Bob Lantz fcd01592 Brandon Heller ```def limit( bw=10, cpu=.1 ): ``` 216a4b7c Bob Lantz ``` """Example/test of link and CPU bandwidth limits ``` ``` bw: interface bandwidth limit in Mbps ``` ``` cpu: cpu limit as fraction of overall CPU time""" ``` ba8d4f9b Bob Lantz ``` intf = custom( TCIntf, bw=bw ) ``` 4ac1148e Bob Lantz ``` myTopo = TreeTopo( depth=1, fanout=2 ) ``` 216a4b7c Bob Lantz ``` for sched in 'rt', 'cfs': ``` ``` print '*** Testing with', sched, 'bandwidth limiting' ``` f89d9a4d Bob Lantz ``` host = custom( CPULimitedHost, sched=sched, cpu=cpu ) ``` 216a4b7c Bob Lantz ``` net = Mininet( topo=myTopo, intf=intf, host=host ) ``` ``` net.start() ``` ``` testLinkLimit( net, bw=bw ) ``` fcd01592 Brandon Heller ``` net.runCpuLimitTest( cpu=cpu ) ``` 216a4b7c Bob Lantz ``` net.stop() ``` 4ac1148e Bob Lantz ba8d4f9b Bob Lantz ```def verySimpleLimit( bw=150 ): ``` 612b21cb Bob Lantz ``` "Absurdly simple limiting test" ``` ba8d4f9b Bob Lantz ``` intf = custom( TCIntf, bw=bw ) ``` ``` net = Mininet( intf=intf ) ``` ``` h1, h2 = net.addHost( 'h1' ), net.addHost( 'h2' ) ``` ``` net.addLink( h1, h2 ) ``` ``` net.start() ``` ``` net.pingAll() ``` ``` net.iperf() ``` ``` h1.cmdPrint( 'tc -s qdisc ls dev', h1.defaultIntf() ) ``` ``` h2.cmdPrint( 'tc -d class show dev', h2.defaultIntf() ) ``` ``` h1.cmdPrint( 'tc -s qdisc ls dev', h1.defaultIntf() ) ``` ``` h2.cmdPrint( 'tc -d class show dev', h2.defaultIntf() ) ``` ``` net.stop() ``` 612b21cb Bob Lantz 4ac1148e Bob Lantz ```if __name__ == '__main__': ``` ``` setLogLevel( 'info' ) ``` 00d9b780 Bob Lantz ` limit()`