Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6ca49a78de | |||
| c703bafd9c | |||
| a2f659de57 | |||
| 4a08ccdf5a | |||
| 6525cd90bd |
@@ -14,12 +14,32 @@ from subprocess import Popen, PIPE
|
||||
|
||||
from mininet.log import info
|
||||
from mininet.term import cleanUpScreens
|
||||
import os
|
||||
|
||||
def sh( cmd ):
|
||||
"Print a command and send it to the shell"
|
||||
info( cmd + '\n' )
|
||||
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():
|
||||
"""Clean up junk which might be left over from old runs;
|
||||
do fast stuff before slow dp and link removal!"""
|
||||
@@ -57,4 +77,6 @@ def cleanup():
|
||||
if link != '':
|
||||
sh( "ip link del " + link )
|
||||
|
||||
kill_cgroups()
|
||||
|
||||
info( "*** Cleanup complete.\n" )
|
||||
|
||||
+2
-2
@@ -183,8 +183,8 @@ class TCIntf( Intf ):
|
||||
|
||||
cmds, parent = [], ' root '
|
||||
|
||||
if bw and ( bw < 0 or bw > 1000 ):
|
||||
error( 'Bandwidth', bw, 'is outside range 0..1000 Mbps\n' )
|
||||
if bw and ( bw < 0 or bw > 10000 ):
|
||||
warn( 'Bandwidth', bw, 'is outside range 0..10000 Mbps\n' )
|
||||
|
||||
elif bw is not None:
|
||||
# BL: this seems a bit brittle...
|
||||
|
||||
+40
-7
@@ -49,12 +49,15 @@ import re
|
||||
import signal
|
||||
import select
|
||||
from subprocess import Popen, PIPE, STDOUT
|
||||
import time
|
||||
import subprocess
|
||||
|
||||
from mininet.log import info, error, warn, debug
|
||||
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.link import Link, Intf, TCIntf
|
||||
from mininet.clean import kill_cgroups
|
||||
|
||||
class Node( object ):
|
||||
"""A virtual network node is simply a shell in a network namespace.
|
||||
@@ -556,10 +559,18 @@ class CPULimitedHost( Host ):
|
||||
CPULimitedHost.init()
|
||||
# Create a cgroup and move shell into it
|
||||
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
|
||||
# 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
|
||||
# for RT. RT allows very small quotas, but the overhead
|
||||
# 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' % (
|
||||
resource, param, value, self.name )
|
||||
quietRun( cmd )
|
||||
nvalue = int( self.cgroupGet( param, resource ) )
|
||||
nvalue = int( self.cgroupGet2( param, resource ) )
|
||||
if nvalue != value:
|
||||
error( '*** error: cgroupSet: %s set to %s instead of %s\n'
|
||||
% ( param, nvalue, value ) )
|
||||
@@ -583,13 +594,35 @@ class CPULimitedHost( Host ):
|
||||
"Return value of cgroup parameter"
|
||||
cmd = 'cgget -r %s.%s /%s' % (
|
||||
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 ):
|
||||
"Clean up our cgroup"
|
||||
# info( '*** deleting cgroup', self.cgroup, '\n' )
|
||||
_out, _err, exitcode = errRun( 'cgdelete -r ' + self.cgroup )
|
||||
return exitcode != 0
|
||||
# TEMP out
|
||||
kill_cgroups([self.name])
|
||||
#_out, _err, exitcode = errRun( 'cgdelete -r ' + self.cgroup )
|
||||
#return exitcode != 0
|
||||
return True
|
||||
|
||||
def popen( self, *args, **kwargs ):
|
||||
"""Return a Popen() object in node's namespace
|
||||
|
||||
+9
-1
@@ -9,6 +9,7 @@ from subprocess import call, check_call, Popen, PIPE, STDOUT
|
||||
import re
|
||||
from fcntl import fcntl, F_GETFL, F_SETFL
|
||||
from os import O_NONBLOCK
|
||||
import os
|
||||
|
||||
# Command execution support
|
||||
|
||||
@@ -111,6 +112,10 @@ def errFail( *cmd, **kwargs ):
|
||||
% ( cmd, ret, err ) )
|
||||
return out, err, ret
|
||||
|
||||
def errFailTemp( *cmd, **kwargs ):
|
||||
import os
|
||||
os.system(" ".join(cmd))
|
||||
|
||||
def quietRun( cmd, **kwargs ):
|
||||
"Run a command and return merged stdout and stderr"
|
||||
return errRun( cmd, stderr=STDOUT, **kwargs )[ 0 ]
|
||||
@@ -357,9 +362,12 @@ def fixLimits():
|
||||
setrlimit( RLIMIT_NOFILE, ( 16384, 16384 ) )
|
||||
|
||||
def mountCgroups():
|
||||
return
|
||||
"Make sure cgroups file system is mounted"
|
||||
mounts = quietRun( 'mount' )
|
||||
cgdir = '/sys/fs/cgroup'
|
||||
#cgdir = '/sys/fs/cgroup'
|
||||
# BDH temp for 10.04
|
||||
cgdir = '/mnt/cgroups'
|
||||
csdir = cgdir + '/cpuset'
|
||||
if 'cgroups on %s' % cgdir not in mounts:
|
||||
raise Exception( "cgroups not mounted on " + cgdir )
|
||||
|
||||
+1
-1
@@ -284,7 +284,7 @@ function ovs {
|
||||
sudo apt-get -y --force-yes -t lenny-backports install autoconf
|
||||
fi
|
||||
else
|
||||
$install git
|
||||
$install git-core
|
||||
fi
|
||||
|
||||
# Install OVS from release
|
||||
|
||||
Reference in New Issue
Block a user