On Wed, Aug 09, 2023 at 12:19:21AM +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 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 a new egress Qos type called 'kpkts-policer'.
> the policer police the kilo-packet per second at which the token bucket
> be updated by 'kpkts_rate'. and the policer's burst size is defined by
> 'kpkts_burst'.
>
> Examples:
> $ovs-vsctl set port vhost-user0 qos=@newqos --
> --id=@newqos create qos type=kpkts-policer \
> 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]>
...
> diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
...
> +static int
> +kpkts_policer_run_single_packet(struct token_bucket *tb, struct rte_mbuf
> **pkts,
> + int pkt_cnt, bool should_steal)
> +{
> + struct rte_mbuf *batch[NETDEV_MAX_BURST] = {0};
> + long long int now = time_msec();
> + struct rte_mbuf *pkt = NULL;
> + int i = 0, n = 0;
> + int cnt = 0;
> +
> + for (i = 0; i < pkt_cnt; i++) {
> + pkt = pkts[i];
> + /* Handle current packet. */
> + if (token_bucket_withdraw(tb, 1, now)) {
> + /* Count passed packets. */
> + if (cnt != i) {
> + pkts[cnt] = pkt;
> + }
> + cnt++;
> + } else {
> + /* Count dropped packets. */
> + batch[n++] = pkt;
> + }
> + }
> +
> + if (should_steal && n) {
> + rte_pktmbuf_free_bulk(batch, n);
> + }
> +
> + return cnt;
> +}
Hi Lin Huang,
The function above is largely the same as srtcm_policer_run_single_packet()
and the comments I made in the previous patch regarding that function
apply here too. Could these functions be consolidated somehow - f.e.
by providing a callback for, in this case, the call to
token_bucket_withdraw()?
...
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev