# Where the tc binary lives
TC = "/sbin/tc"
+# Where the ebtables binary lives
+EBTABLES = "/sbin/ebtables"
+
# Default interface
dev = "eth0"
def get_xid(slice):
"""
- Get slice xid ("princeton_mlh") from slice name ("500" or "princeton_mlh")
+ Get slice xid ("500") from slice name ("princeton_mlh")
"""
if slice == "root":
return run(TC + " " + cmd)
+def ebtables(cmd):
+ """
+ Shortcut for running a ebtables command
+ """
+
+ return run(EBTABLES + " " + cmd)
+
def stop(dev = dev):
'''
"""
# Load the module used to manage exempt classes
- run("/sbin/modprobe ip_set_iphash")
+ #run("/sbin/modprobe ip_set_iphash")
+ # Test the new module included in kernel 3 series
+ run("/sbin/modprobe ip_set_hash_ip")
# Save current settings
paramslist = get(None, dev)
tc("class replace dev %s parent 1:20 classid 1:%x htb rate %dbit ceil %dbit quantum %d" % \
(dev, exempt_minor | xid, minexemptrate, maxexemptrate, share * quantum))
-
+
# Attach a FIFO to each subclass, which helps to throttle back
# processes that are sending faster than the token buckets can
# support.
tc("qdisc replace dev %s parent 1:%x handle %x pfifo" % \
(dev, exempt_minor | xid, exempt_minor | xid))
+ # Setup a filter rule to the root class so each packet originated by a
+ # container interface is classified to it corresponding class
+ # The handle number is a mark created by ebtables with the xid
+ tc("filter replace dev %s parent 1:1 protocol ip prio 1 handle %d fw flowid 1:%x" % \
+ (dev, default_minor | xid, default_minor | xid))
+
+ # Create the ebtables rule to mark the packets going out from the virtual
+ # interface to the actual device so the filter canmatch against the mark
+ # We remove and readd the rule because this method is called each time the
+ # bandwidth limit is changed
+ ebtables("-D INPUT -i veth%d -j mark --set-mark %d" % \
+ (xid, default_minor | xid))
+ ebtables("-A INPUT -i veth%d -j mark --set-mark %d" % \
+ (xid, default_minor | xid))
+
def set(xid, share = None, minrate = None, maxrate = None, minexemptrate = None, maxexemptrate = None, dev = dev ):
on(xid = xid, dev = dev, share = share,
import libvirt
import sys
from string import Template
+import bwlimit
import sliver_libvirt as lv
def create(name, rec=None):
logger.verbose ('sliver_lxc: %s create'%(name))
conn = lv.getConnection(Sliver_LXC.TYPE)
-
- # Template for libvirt sliver configuration
- try:
- with open(Sliver_LXC.REF_IMG_BASE_DIR + '/config_template.xml') as f:
- template = Template(f.read())
- xml = template.substitute(name=name)
- except IOError:
- logger.log('Cannot find XML template file')
- return
-
+
''' Create dirs, copy fs image, lxc_create '''
# Get the type of image from vref myplc tags specified as:
# pldistro = lxc
command = ['cp', '/home/%s/.ssh/id_rsa.pub'%name, '%s/root/.ssh/authorized_keys'%containerDir]
logger.log_call(command, timeout=15*60)
+ # Lookup for xid and create template after the user is created so we
+ # can get the correct xid based on the name of the slice
+ xid = bwlimit.get_xid(name)
+
+ # Template for libvirt sliver configuration
+ try:
+ with open(Sliver_LXC.REF_IMG_BASE_DIR + '/config_template.xml') as f:
+ template = Template(f.read())
+ xml = template.substitute(name=name, xid=xid)
+ except IOError:
+ logger.log('Cannot find XML template file')
+ return
+
# Lookup for the sliver before actually
# defining it, just in case it was already defined.
try: