[ovs-discuss] 回复: 回复: ovs-ofctl add-meter command limit rate can work ?

爬山虎 cxasm at qq.com
Mon Jun 19 08:58:09 UTC 2017

1)We think one meter with one  bond is just good way , one meter with multiple band can not be work (can not be test in real project).  So sorry we never to realize multiple band that wrong in theory.

2) This days we are realizing the meter function with netlink style . We just put the meter actions to kernel,  and when packets pass the flow we do our limit work . Code like this :

static int execute_meter_rate_limit(struct datapath *dp, struct sk_buff *skb, uint32_t meter_id)
	int ret = -1;
	long long int long_delta_t;
	uint32_t delta_t; /* msec */
	uint32_t bucket, skb_bits;

	struct meter_info *meter = dp->meter_tb.addr[meter_id];
    if (!meter) {
		printk("meter null\n");
        goto out;

	dp_meter_lock(&dp->meter_tb, meter_id);
	long_delta_t = (jiffies - meter->used); /* msec */ 
	/* Update meter stats. */

	skb_bits = skb->len * 8;

	bucket = meter->max_delta_t * meter->rate;
	if (skb_bits + meter->pre_bits > bucket) {
		ret = -1;
	}else {
		meter->pre_bits += skb_bits;
		ret = 0;

        /*every HZ/4 loop one*/
	if (long_delta_t >= meter->max_delta_t) {
		meter->pre_bits = 0;
		meter->used = jiffies;
		packets = 0;
	dp_meter_unlock(&dp->meter_tb, meter_id);	
	return ret;

This just a protomodel, and code just copy opensource 's  dp_netdev_run_meter function. We test in udp and tcp tow ways. The result in tcp is inaccurate. Did you  meet this problem , any ideas for kernel implementation ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openvswitch.org/pipermail/ovs-discuss/attachments/20170619/5774aa40/attachment-0001.html>

More information about the discuss mailing list