Compare commits

...
5 changed files with 74 additions and 11 deletions

No files matched your search

+22
View File
@@ -14,12 +14,32 @@ from subprocess import Popen, PIPE
from mininet.log import info from mininet.log import info
from mininet.term import cleanUpScreens from mininet.term import cleanUpScreens
import os
def sh( cmd ): def sh( cmd ):
"Print a command and send it to the shell" "Print a command and send it to the shell"
info( cmd + '\n' ) info( cmd + '\n' )
return Popen( [ '/bin/sh', '-c', cmd ], stdout=PIPE ).communicate()[ 0 ] return Popen( [ '/bin/sh', '-c', cmd ], stdout=PIPE ).communicate()[ 0 ]
CGROUPS_LOC='/mnt/cgroups'
def kill_cgroups(cgroups = None):
"""cgroups is a list of cgroup names."""
if not cgroups:
cpudir = os.path.join(CGROUPS_LOC, 'cpu')
if not os.path.exists(cpudir):
return
else:
cgroups = os.listdir(cpudir)
info( "killing cgroups: %s" % " ".join(cgroups) )
for g in cgroups:
if 'sysdefault' in g:
continue
for resource in os.listdir(CGROUPS_LOC):
cgdir = "%s/%s/%s" % (CGROUPS_LOC, resource, g)
if os.path.exists(cgdir):
sh( "sudo rmdir %s" % cgdir )
def cleanup(): def cleanup():
"""Clean up junk which might be left over from old runs; """Clean up junk which might be left over from old runs;
do fast stuff before slow dp and link removal!""" do fast stuff before slow dp and link removal!"""
@@ -57,4 +77,6 @@ def cleanup():
if link != '': if link != '':
sh( "ip link del " + link ) sh( "ip link del " + link )
kill_cgroups()
info( "*** Cleanup complete.\n" ) info( "*** Cleanup complete.\n" )
+2 -2
View File
@@ -183,8 +183,8 @@ class TCIntf( Intf ):
cmds, parent = [], ' root ' cmds, parent = [], ' root '
if bw and ( bw < 0 or bw > 1000 ): if bw and ( bw < 0 or bw > 10000 ):
error( 'Bandwidth', bw, 'is outside range 0..1000 Mbps\n' ) warn( 'Bandwidth', bw, 'is outside range 0..10000 Mbps\n' )
elif bw is not None: elif bw is not None:
# BL: this seems a bit brittle... # BL: this seems a bit brittle...
+40 -7
View File
@@ -49,12 +49,15 @@ import re
import signal import signal
import select import select
from subprocess import Popen, PIPE, STDOUT from subprocess import Popen, PIPE, STDOUT
import time
import subprocess
from mininet.log import info, error, warn, debug from mininet.log import info, error, warn, debug
from mininet.util import ( quietRun, errRun, errFail, moveIntf, isShellBuiltin, from mininet.util import ( quietRun, errRun, errFail, moveIntf, isShellBuiltin,
numCores, retry, mountCgroups ) numCores, retry, mountCgroups, errFailTemp )
from mininet.moduledeps import moduleDeps, pathCheck, OVS_KMOD, OF_KMOD, TUN from mininet.moduledeps import moduleDeps, pathCheck, OVS_KMOD, OF_KMOD, TUN
from mininet.link import Link, Intf, TCIntf from mininet.link import Link, Intf, TCIntf
from mininet.clean import kill_cgroups
class Node( object ): class Node( object ):
"""A virtual network node is simply a shell in a network namespace. """A virtual network node is simply a shell in a network namespace.
@@ -556,10 +559,18 @@ class CPULimitedHost( Host ):
CPULimitedHost.init() CPULimitedHost.init()
# Create a cgroup and move shell into it # Create a cgroup and move shell into it
self.cgroup = 'cpu,cpuacct,cpuset:/' + self.name self.cgroup = 'cpu,cpuacct,cpuset:/' + self.name
errFail( 'cgcreate -g ' + self.cgroup ) cmd_to_run = 'cgcreate -g ' + self.cgroup
error("creating group using command: %s\n" % cmd_to_run)
errFail( cmd_to_run )
# We don't add ourselves to a cpuset because you must # We don't add ourselves to a cpuset because you must
# specify the cpu and memory placement first # specify the cpu and memory placement first
errFail( 'cgclassify -g cpu,cpuacct:/%s %s' % ( self.name, self.pid ) ) #self.pid = 12345
#error("nap time!")
time.sleep(0.1)
cmd_to_run = 'cgclassify -g cpu,cpuacct:/%s %s' % ( self.name, self.pid )
errFailTemp( cmd_to_run )
#error("nap time over.")
#exit
# BL: Setting the correct period/quota is tricky, particularly # BL: Setting the correct period/quota is tricky, particularly
# for RT. RT allows very small quotas, but the overhead # for RT. RT allows very small quotas, but the overhead
# seems to be high. CFS has a mininimum quota of 1 ms, but # seems to be high. CFS has a mininimum quota of 1 ms, but
@@ -573,7 +584,7 @@ class CPULimitedHost( Host ):
cmd = 'cgset -r %s.%s=%s /%s' % ( cmd = 'cgset -r %s.%s=%s /%s' % (
resource, param, value, self.name ) resource, param, value, self.name )
quietRun( cmd ) quietRun( cmd )
nvalue = int( self.cgroupGet( param, resource ) ) nvalue = int( self.cgroupGet2( param, resource ) )
if nvalue != value: if nvalue != value:
error( '*** error: cgroupSet: %s set to %s instead of %s\n' error( '*** error: cgroupSet: %s set to %s instead of %s\n'
% ( param, nvalue, value ) ) % ( param, nvalue, value ) )
@@ -583,13 +594,35 @@ class CPULimitedHost( Host ):
"Return value of cgroup parameter" "Return value of cgroup parameter"
cmd = 'cgget -r %s.%s /%s' % ( cmd = 'cgget -r %s.%s /%s' % (
resource, param, self.name ) resource, param, self.name )
return int( quietRun( cmd ).split()[ -1 ] ) cmd_output = quietRun( cmd )
return int( cmd_output.split()[ -1 ] )
def cgroupGet2( self, param, resource='cpu' ):
"Return value of cgroup parameter"
# TEMP: cgget not in 10.04 cgroup-bin. Oops!
# Can get same stuff by reading files.
filename = resource + '.' + param
filepath = os.path.join("/mnt/cgroups/", resource, self.name, filename)
#cmd = 'cgget -r %s.%s /%s' % (
# resource, param, self.name )
if not os.path.exists(filepath):
raise Exception("%s not found." % filename)
# TEMP below
f = open(filepath)
cmd_output = f.readlines()[0]
f.close()
#cmd_output = subprocess.check_output(cmd, shell=True)
#quietRun( cmd )
return int( cmd_output.split()[ -1 ] )
def cgroupDel( self ): def cgroupDel( self ):
"Clean up our cgroup" "Clean up our cgroup"
# info( '*** deleting cgroup', self.cgroup, '\n' ) # info( '*** deleting cgroup', self.cgroup, '\n' )
_out, _err, exitcode = errRun( 'cgdelete -r ' + self.cgroup ) # TEMP out
return exitcode != 0 kill_cgroups([self.name])
#_out, _err, exitcode = errRun( 'cgdelete -r ' + self.cgroup )
#return exitcode != 0
return True
def popen( self, *args, **kwargs ): def popen( self, *args, **kwargs ):
"""Return a Popen() object in node's namespace """Return a Popen() object in node's namespace
+9 -1
View File
@@ -9,6 +9,7 @@ from subprocess import call, check_call, Popen, PIPE, STDOUT
import re import re
from fcntl import fcntl, F_GETFL, F_SETFL from fcntl import fcntl, F_GETFL, F_SETFL
from os import O_NONBLOCK from os import O_NONBLOCK
import os
# Command execution support # Command execution support
@@ -111,6 +112,10 @@ def errFail( *cmd, **kwargs ):
% ( cmd, ret, err ) ) % ( cmd, ret, err ) )
return out, err, ret return out, err, ret
def errFailTemp( *cmd, **kwargs ):
import os
os.system(" ".join(cmd))
def quietRun( cmd, **kwargs ): def quietRun( cmd, **kwargs ):
"Run a command and return merged stdout and stderr" "Run a command and return merged stdout and stderr"
return errRun( cmd, stderr=STDOUT, **kwargs )[ 0 ] return errRun( cmd, stderr=STDOUT, **kwargs )[ 0 ]
@@ -357,9 +362,12 @@ def fixLimits():
setrlimit( RLIMIT_NOFILE, ( 16384, 16384 ) ) setrlimit( RLIMIT_NOFILE, ( 16384, 16384 ) )
def mountCgroups(): def mountCgroups():
return
"Make sure cgroups file system is mounted" "Make sure cgroups file system is mounted"
mounts = quietRun( 'mount' ) mounts = quietRun( 'mount' )
cgdir = '/sys/fs/cgroup' #cgdir = '/sys/fs/cgroup'
# BDH temp for 10.04
cgdir = '/mnt/cgroups'
csdir = cgdir + '/cpuset' csdir = cgdir + '/cpuset'
if 'cgroups on %s' % cgdir not in mounts: if 'cgroups on %s' % cgdir not in mounts:
raise Exception( "cgroups not mounted on " + cgdir ) raise Exception( "cgroups not mounted on " + cgdir )
+1 -1
View File
@@ -284,7 +284,7 @@ function ovs {
sudo apt-get -y --force-yes -t lenny-backports install autoconf sudo apt-get -y --force-yes -t lenny-backports install autoconf
fi fi
else else
$install git $install git-core
fi fi
# Install OVS from release # Install OVS from release