[PATCH net-next 06/11] selftests: drv-net: tc_flower_police: Test police parameters

From: Mohsin Bashir

Date: Thu Dec 03 2026 - 19:06:16 EST


From: Mohsin Bashir <hmohsin@xxxxxxxx>

act_police supports more than a rate and a burst, and drivers usually
offload only a subset of it. Add police_params to cover the pipe exceed
action, peak rate, overhead and packet rate, and verify that traffic
shows the effect of each option the device accepts. If the device
rejects an option, the test checks that a plain police rule still works
and skips. A rejected rule must not be left behind.

Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx>
Signed-off-by: Mohsin Bashir <hmohsin@xxxxxxxx>
---
.../drivers/net/hw/tc_flower_police.py | 56 +++++++++++++++++--
1 file changed, 52 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
index cdff5cb6b6a3..66d32f6e13f7 100755
--- a/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
+++ b/tools/testing/selftests/drivers/net/hw/tc_flower_police.py
@@ -9,6 +9,7 @@ import tempfile
import time
from lib.py import ksft_run, ksft_exit, ksft_pr
from lib.py import ksft_eq, ksft_ge
+from lib.py import ksft_variants, KsftNamedVariant
from lib.py import CmdExitFailure, KsftSkipEx, KsftXfailEx, KsftFailEx
from lib.py import Iperf3Runner, NetDrvEpEnv
from lib.py import set_ethtool_feat
@@ -68,9 +69,9 @@ def _add_secondary_addr(cfg, want=None):
return addr


-def _police(rate_mbit):
+def _police(rate_mbit, extra="", exceed="drop"):
return (f"action police rate {rate_mbit}mbit burst 1m "
- "conform-exceed drop/ok")
+ f"conform-exceed {exceed}/ok {extra}")


def _try_filter(cfg, rule, action, pref):
@@ -82,10 +83,16 @@ def _try_filter(cfg, rule, action, pref):
return res.ret == 0, res.stderr.strip()


-def _add_filter(cfg, rule, action, pref):
+def _add_filter(cfg, rule, action, pref, dst=None):
added, err = _try_filter(cfg, rule, action, pref)
if not added:
raise KsftSkipEx(f"Rule not offloaded: {err}")
+ if dst is None:
+ return
+ got = _iperf3(cfg, dst, OFFERED_MBIT)
+ if not _check_rate(got, RATE_MBIT, f"rule at pref {pref}"):
+ raise KsftFailEx(f"Police rule at pref {pref} not at the "
+ "expected rate")


def _filter_info(cfg, pref):
@@ -330,6 +337,46 @@ def police_dst_prefix(cfg):
ksft_pr("LOCAL_PREFIX_V6 is a /120, shorter masks not checked")


+@ksft_variants([
+ KsftNamedVariant("exceed_pipe",
+ f"{_police(RATE_MBIT, exceed='pipe')} "
+ f"{_police(RATE_MBIT // 2)}",
+ RATE_MBIT + RATE_MBIT // 2),
+ KsftNamedVariant("peakrate",
+ _police(OFFERED_MBIT * 2,
+ extra=f"peakrate {RATE_MBIT}mbit mtu 65535"),
+ RATE_MBIT),
+ KsftNamedVariant("overhead",
+ _police(RATE_MBIT, extra=f"overhead {UDP_PAYLOAD}"),
+ RATE_MBIT * IP6_PKT_LEN / (IP6_PKT_LEN + UDP_PAYLOAD)),
+ KsftNamedVariant("pkts_rate",
+ "action police pkts_rate 1000 pkts_burst 100 "
+ "conform-exceed drop/ok", 1000 * IP6_PKT_LEN * 8 / 1e6),
+])
+def police_params(cfg, action, expect):
+ """
+ Check police parameters beyond the rate and burst. A device that
+ offloads the rule must limit the traffic as configured. A device may
+ reject it, and a plain police rule must then still limit the traffic,
+ after which the case is skipped.
+ """
+ _setup_clsact(cfg)
+ rule, dst = _dst_ip_rule(cfg)
+
+ _check_baseline_rate(cfg)
+ added, err = _try_filter(cfg, rule, action, pref=10)
+ if added:
+ got = _iperf3(cfg, dst, OFFERED_MBIT)
+ _check_rate(got, expect, "policed flow")
+ return
+
+ if _filter_info(cfg, 10) is not None:
+ raise KsftFailEx(f"Rejected filter left behind: {err}")
+ _add_filter(cfg, rule, _police(RATE_MBIT), pref=10, dst=dst)
+ reason = err.partition("\n")[0]
+ raise KsftSkipEx(f"Not offloaded: {reason}")
+
+
def main() -> None:
"""Ksft boilerplate main."""
with NetDrvEpEnv(__file__, nsim_test=False) as cfg:
@@ -339,7 +386,8 @@ def main() -> None:
link_baseline,
police_rate,
police_isolation,
- police_dst_prefix],
+ police_dst_prefix,
+ police_params],
args=(cfg,))
ksft_exit()

--
2.53.1-Meta