Support for CFS bandwidth limiting.
Also trying to fix NOX cmdline opt, but broken at the moment.
This commit is contained in:
+21
-22
@@ -5,19 +5,20 @@ limit.py: example of using link and CPU limits
|
||||
"""
|
||||
|
||||
from mininet.net import Mininet
|
||||
from mininet.link import TCIntf, Link
|
||||
from mininet.link import TCIntf
|
||||
from mininet.node import CPULimitedHost
|
||||
from mininet.topolib import TreeTopo
|
||||
from mininet.util import custom, quietRun
|
||||
from mininet.log import setLogLevel
|
||||
from time import sleep
|
||||
|
||||
def testLinkLimit( net ):
|
||||
print '*** Testing network bandwidth limit'
|
||||
net.iperf()
|
||||
def testLinkLimit( net, bw ):
|
||||
print '*** Testing network %.2f Mbps bandwidth limit' % bw
|
||||
net.iperf( )
|
||||
|
||||
def testCpuLimit( net ):
|
||||
print '*** Testing CPU bandwidth limit'
|
||||
def testCpuLimit( net, cpu ):
|
||||
pct = cpu * 100
|
||||
print '*** Testing CPU %.0f%% bandwidth limit' % pct
|
||||
h1, h2 = net.hosts
|
||||
h1.cmd( 'while true; do a=1; done &' )
|
||||
h2.cmd( 'while true; do a=1; done &' )
|
||||
@@ -26,26 +27,24 @@ def testCpuLimit( net ):
|
||||
cmd = 'ps -p %s,%s -o pid,%%cpu,args' % ( pid1, pid2 )
|
||||
for i in range( 0, 5):
|
||||
sleep( 1 )
|
||||
print quietRun( cmd )
|
||||
print quietRun( cmd ).strip()
|
||||
h1.cmd( 'kill %1')
|
||||
h2.cmd( 'kill %1')
|
||||
|
||||
def limit():
|
||||
"Example/test of link and CPU bandwidth limits"
|
||||
# 1 Mbps interfaces limited using tc
|
||||
intf1Mbps = custom( TCIntf, bw=1 )
|
||||
# Links consisting of two 10 Mbps interfaces
|
||||
link1Mbps = custom( Link, intf=intf1Mbps, cls2=TCIntf )
|
||||
# Hosts with 30% of system bandwidth
|
||||
host30pct = custom( CPULimitedHost, cpu=.3 )
|
||||
def limit( bw=1, cpu=.3 ):
|
||||
"""Example/test of link and CPU bandwidth limits
|
||||
bw: interface bandwidth limit in Mbps
|
||||
cpu: cpu limit as fraction of overall CPU time"""
|
||||
intf = custom( TCIntf, bw=1 )
|
||||
myTopo = TreeTopo( depth=1, fanout=2 )
|
||||
net = Mininet( topo=myTopo,
|
||||
link=link1Mbps,
|
||||
host=host30pct )
|
||||
net.start()
|
||||
testLinkLimit( net )
|
||||
testCpuLimit( net )
|
||||
net.stop()
|
||||
for sched in 'rt', 'cfs':
|
||||
print '*** Testing with', sched, 'bandwidth limiting'
|
||||
host = custom( CPULimitedHost, sched=sched, cpu=cpu )
|
||||
net = Mininet( topo=myTopo, intf=intf, host=host )
|
||||
net.start()
|
||||
testLinkLimit( net, bw=bw )
|
||||
testCpuLimit( net, cpu=cpu )
|
||||
net.stop()
|
||||
|
||||
if __name__ == '__main__':
|
||||
setLogLevel( 'info' )
|
||||
|
||||
Reference in New Issue
Block a user