bitkeeper revision 1.1236.1.46 (4225fdb2Fsz5LfXWKyVON4u_POTHkQ)

Credit-based rate limiting in net backend. From Ross Mcilroy.
Signed-off-by: Keir Fraser <keir.fraser@cl.cam.ac.uk>
This commit is contained in:
kaf24@scramble.cl.cam.ac.uk committed 2005-03-02 17:53:54 +00:00
1 parent d9edb54d67
commit 047fb79307
13 files changed
+181 -30

No files matched your search

+13
View File
@@ -698,6 +698,13 @@ static PyObject *xu_message_get_payload(PyObject *self, PyObject *args)
C2P(netif_be_destroy_t, netif_handle, Int, Long);
C2P(netif_be_destroy_t, status, Int, Long);
return dict;
case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_CREDITLIMIT):
C2P(netif_be_creditlimit_t, domid, Int, Long);
C2P(netif_be_creditlimit_t, netif_handle, Int, Long);
C2P(netif_be_creditlimit_t, credit_bytes, Int, Long);
C2P(netif_be_creditlimit_t, period_usec, Int, Long);
C2P(netif_be_creditlimit_t, status, Int, Long);
return dict;
case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_CONNECT):
C2P(netif_be_connect_t, domid, Int, Long);
C2P(netif_be_connect_t, netif_handle, Int, Long);
@@ -916,6 +923,12 @@ static PyObject *xu_message_new(PyObject *self, PyObject *args)
P2C(netif_be_destroy_t, domid, u32);
P2C(netif_be_destroy_t, netif_handle, u32);
break;
case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_CREDITLIMIT):
P2C(netif_be_creditlimit_t, domid, u32);
P2C(netif_be_creditlimit_t, netif_handle, u32);
P2C(netif_be_creditlimit_t, credit_bytes, u32);
P2C(netif_be_creditlimit_t, period_usec, u32);
break;
case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_CONNECT):
P2C(netif_be_connect_t, domid, u32);
P2C(netif_be_connect_t, netif_handle, u32);
+7
View File
@@ -278,6 +278,13 @@ class Xend:
{ 'op' : 'maxmem_set',
'memory' : memory })
def xend_domain_vif_limit(self, id, vif, credit, period):
return self.xendPost(self.domainurl(id),
{ 'op' : 'vif_credit_limit',
'vif' : vif,
'credit' : credit,
'period' : period })
def xend_domain_vifs(self, id):
return self.xendGet(self.domainurl(id),
{ 'op' : 'vifs' })
+9
View File
@@ -723,6 +723,15 @@ class XendDomain:
dominfo = self.domain_lookup(id)
return dominfo.get_device_by_index(type, idx)
def domain_vif_credit_limit(self, id, vif, credit, period):
"""Limit the vif's transmission rate
"""
dominfo = self.domain_lookup(id)
try:
return dominfo.limit_vif(vif, credit, period)
except Exception, ex:
raise XendError(str(ex))
def domain_vif_ls(self, id):
"""Get list of virtual network interface (vif) indexes for a domain.
+12
View File
@@ -614,6 +614,18 @@ class XendDomainInfo:
def get_device_recreate(self, type, index):
return self.get_device_savedinfo(type, index) or self.recreate
def limit_vif(self, vif, credit, period):
"""Limit the rate of a virtual interface
@param vif: vif
@param credit: vif credit in bytes
@param period: vif period in uSec
@return: 0 on success
"""
ctrl = xend.netif_create(self.dom, recreate=self.recreate)
d = ctrl.limitDevice(vif, credit, period)
return d
def add_config(self, val):
"""Add configuration data to a virtual machine.
@@ -164,6 +164,15 @@ class SrvDomain(SrvDir):
d = fn(req.args, {'dom': self.dom.id})
return d
def op_vif_credit_limit(self, op, req):
fn = FormFn(self.xd.domain_vif_credit_limit,
[['dom', 'str'],
['vif', 'int'],
['credit', 'int'],
['period', 'int']])
val = fn(req.args, {'dom': self.dom.id})
return val
def op_vifs(self, op, req):
devs = self.xd.domain_vif_ls(self.dom.id)
return [ dev.sxpr() for dev in devs ]
+4
View File
@@ -150,6 +150,7 @@ CMSG_NETIF_BE_CREATE = 0
CMSG_NETIF_BE_DESTROY = 1
CMSG_NETIF_BE_CONNECT = 2
CMSG_NETIF_BE_DISCONNECT = 3
CMSG_NETIF_BE_CREDITLIMIT = 4
CMSG_NETIF_BE_DRIVER_STATUS = 32
NETIF_INTERFACE_STATUS_CLOSED = 0 #/* Interface doesn't exist. */
@@ -173,6 +174,9 @@ netif_formats = {
'netif_be_destroy_t':
(CMSG_NETIF_BE, CMSG_NETIF_BE_DESTROY),
'netif_be_creditlimit_t':
(CMSG_NETIF_BE, CMSG_NETIF_BE_CREDITLIMIT),
'netif_be_driver_status_t':
(CMSG_NETIF_BE, CMSG_NETIF_BE_DRIVER_STATUS),
+24 -1
View File
@@ -346,7 +346,21 @@ class NetDev(controller.SplitDev):
vif = val['netif_handle']
self.status = NETIF_INTERFACE_STATUS_CONNECTED
self.reportStatus()
def send_be_creditlimit(self, credit, period):
msg = packMsg('netif_be_creditlimit_t',
{ 'domid' : self.controller.dom,
'netif_handle' : self.vif,
'credit_bytes' : credit,
'period_usec' : period })
d = defer.Deferred()
d.addCallback(self.respond_be_creditlimit)
self.getBackendInterface().writeRequest(msg, response=d)
def respond_be_creditlimit(self, msg):
val = unpackMsg('netif_be_creditlimit_t', msg)
return self
def reportStatus(self, resp=0):
msg = packMsg('netif_fe_interface_status_t',
{ 'handle' : self.vif,
@@ -430,6 +444,15 @@ class NetifController(controller.SplitController):
d = dev.attach()
return d
def limitDevice(self, vif, credit, period):
if vif not in self.devices:
raise XendError('device does not exist for credit limit: vif'
+ str(self.dom) + '.' + str(vif))
dev = self.devices[vif]
d = dev.send_be_creditlimit(credit, period)
return d
def recv_fe_driver_status(self, msg, req):
if not req: return
print
+17
View File
@@ -717,6 +717,23 @@ class ProgLog(Prog):
xm.prog(ProgLog)
class ProgVifCreditLimit(Prog):
group = 'vif'
name= "vif-limit"
info = """Limit the transmission rate of a virtual network interface."""
def help(self, args):
print args[0], "DOMAIN VIF CREDIT_IN_BYTES PERIOD_IN_USECS"
print "\nSet the credit limit of a virtual network interface."
def main(self, args):
if len(args) != 5: self.err("%s: Invalid argument(s)" % args[0])
dom = args[1]
v = map(int, args[2:5])
server.xend_domain_vif_limit(dom, *v)
xm.prog(ProgVifCreditLimit)
class ProgVifList(Prog):
group = 'vif'
name = 'vif-list'
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.