On Sun, Apr 09, 2023 at 07:15:09PM +0800, [email protected] wrote:
> From: Lin Huang <[email protected]>
> 
> OvS has supported packet-per-second policer which can be set at ingress and 
> egress
> side in kernel datapath. But the userspace datapath dosen't support for 
> ingress and
> egress packet-per-second policing now.
> 
> So, this patch add support for userspace ingress pps policing by using native 
> ovs
> token bucket library. Token bucket is accumulated by 'rate' tokens per 
> millisecond
> and store maxiumim tokens at 'burst' bucket size. One token in the bucket 
> means
> one packet (1 kpkts * millisecond) which will drop or pass by policer.
> 
> This patch reuse 'ingress_policing_kpkts_rate' and 
> 'ingress_policing_kpkts_burst'
> options at interface table. Now userspace ingress policer supports setting
> packet-per-second limits in addition to the previously configurable byte rate
> settings.
> 
> Examples:
> $ ovs-vsctl set interface dpdk0 ingress_policing_rate=12300
> $ ovs-vsctl set interface dpdk0 ingress_policing_burst=12300
> $ ovs-vsctl set interface dpdk0 ingress_policing_kpkts_rate=123
> $ ovs-vsctl set interface dpdk0 ingress_policing_kpkts_burst=123
> 
> Add some unit tests for ingress packet-per-second policing.
> 
> Signed-off-by: Lin Huang <[email protected]>

Hi Lin Huang,

thanks for your patch.

...

> @@ -3546,23 +3560,43 @@ netdev_dpdk_policer_construct(uint32_t rate, uint32_t 
> burst)
>      policer = xmalloc(sizeof *policer);
>      rte_spinlock_init(&policer->policer_lock);
>  
> -    /* rte_meter requires bytes so convert kbits rate and burst to bytes. */
> -    rate_bytes = rate * 1000ULL / 8;
> -    burst_bytes = burst * 1000ULL / 8;
> +    if (rate) {
> +        /* rte_meter requires bytes so convert kbits rate and burst to 
> bytes. */
> +        rate_bytes = rate * 1000ULL / 8;
> +        burst_bytes = burst * 1000ULL / 8;
>  
> -    policer->app_srtcm_params.cir = rate_bytes;
> -    policer->app_srtcm_params.cbs = burst_bytes;
> -    policer->app_srtcm_params.ebs = 0;
> -    err = rte_meter_srtcm_profile_config(&policer->in_prof,
> -                                         &policer->app_srtcm_params);
> -    if (!err) {
> -        err = rte_meter_srtcm_config(&policer->in_policer,
> -                                     &policer->in_prof);
> +        policer->app_srtcm_params.cir = rate_bytes;
> +        policer->app_srtcm_params.cbs = burst_bytes;
> +        policer->app_srtcm_params.ebs = 0;
> +        err = rte_meter_srtcm_profile_config(&policer->in_prof,
> +                                             &policer->app_srtcm_params);
> +        if (!err) {
> +            err = rte_meter_srtcm_config(&policer->in_policer,
> +                                         &policer->in_prof);
> +        }
> +        if (err) {
> +            VLOG_ERR("Could not create rte meter for ingress policer");

If this is an error, then probably the function should
clean up and return an error.

If it's not an error then VLOG_ERR seems inappropriate.


> +        } else {
> +            policer->type |= POLICER_BPS;
> +        }
>      }
> -    if (err) {
> -        VLOG_ERR("Could not create rte meter for ingress policer");
> +
> +    if (kpkts_rate) {
> +        /*
> +        * By default token is added per millisecond.
> +        * Rate in kilo-packets/second, bucket 1000 packets.
> +        * msec * kilo-packets/sec = 1 packets.
> +        */
> +        kpkts_burst *= 1000;
> +
> +        token_bucket_init(&policer->tb, kpkts_rate, kpkts_burst);
> +        policer->type |= POLICER_PKTPS;
> +    }
> +
> +    if (!policer->type) {
> +        /* Neither kbps nor kpkts policer is configured. */
>          free(policer);
> -        return NULL;
> +        policer = NULL;
>      }
>  
>      return policer;

...
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to