On 5/16/23 17:20, [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 doesn't
> support for ingress and egress packet-per-second policing now.
> 
> So, this patch add support for userspace egress pps policing by using
> native ovs token bucket library. Token bucket is accumulated by 'rate'
> tokens per millisecond and store maximum 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 add new configuration option 'kpkts_rate' and 'kpkts_burst'
> for egress-policer QoS type which now supports setting packet-per-second
> limits in addition to the previously configurable byte rate settings.
> 
> Examples:
> $ovs-vsctl set port vhost-user0 qos=@newqos --
>            --id=@newqos create qos type=egress-policer \
>            other-config:cir=123000 other-config:cbs=123000
>            other-config:kpkts_rate=123 other-config:kpkts_burst=123
> 
> Add some unit tests for egress packet-per-second policing.
> 
> Signed-off-by: Lin Huang <[email protected]>
> ---
>  Documentation/topics/dpdk/qos.rst |  15 ++-
>  NEWS                              |   3 +
>  lib/netdev-dpdk.c                 | 130 ++++++++++++++++----
>  tests/system-dpdk.at              | 194 +++++++++++++++++++++++++++++-
>  vswitchd/vswitch.xml              |  10 ++
>  5 files changed, 325 insertions(+), 27 deletions(-)

<snip>

>  static int
>  egress_policer_run(struct qos_conf *conf, struct rte_mbuf **pkts, int 
> pkt_cnt,
>                     bool should_steal)
>  {
> -    int cnt = 0;
>      struct egress_policer *policer =
>          CONTAINER_OF(conf, struct egress_policer, qos_conf);
>  
> -    cnt = srtcm_policer_run_single_packet(&policer->egress_meter,
> -                                          &policer->egress_prof, pkts,
> -                                          pkt_cnt, should_steal);
> +    if (policer->type & POLICER_BPS) {
> +        pkt_cnt = srtcm_policer_run_single_packet(&policer->egress_meter,
> +                                                  &policer->egress_prof, 
> pkts,
> +                                                  pkt_cnt, should_steal);
> +    }
> +
> +    if (policer->type & POLICER_PKTPS) {
> +        pkt_cnt = pkts_policer_run_single_packet(&policer->egress_tb, pkts,
> +                                                 pkt_cnt, should_steal);
> +    }

Hrm.  This is actually not correct, sorry.  The semantics should be that
both policers should work at the same time.  Meaning that even if the
first policer decides to drop the packet, that packet should still be
accounted in the budget of the second policer.

So, we should either pass packets through the srtcm_policer and the
token bucket one by one and decide if we're going to drop it.
Or we execute the first policer other the whole batch only remembering the
result, but nor dropping any packets, then the second over the whole batch.
Then get the maximum from the number of dropped packets, and drop that
amount of packets from the end of a batch.  Note that since we're not
taking current time per packet for the srtcm_policer, it should drop all
the packets after the first one that doesn't fit into the rate limit.
The code might need re-work to reflect that.

Same applies to the ingress policer.

Best regards, Ilya Maximets.

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

Reply via email to