Skip to contentSkip to conversation

Add selftests for ntuple (NFC) rules

PATCH Applied Dimitri Daskalakis 3 participants 6 messages Apr 7 – Apr 10

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Add selftests for ntuple (NFC) rules

From: Dimitri Daskalakis <[email protected]>

Thoroughly testing a device's NFC implementation can be tedious. The more features a device supports, the more combinations to validate.

This series aims to ease that burden, validating the most common NFC rule combinations.

Dimitri Daskalakis (2):
selftests: drv-net: Add ntuple (NFC) flow steering test
selftests: drv-net: ntuple: Add dst-ip, src-port, dst-port fields

 .../testing/selftests/drivers/net/hw/Makefile |   1 +
 .../selftests/drivers/net/hw/ntuple.py        | 162 ++++++++++++++++++
 2 files changed, 163 insertions(+)
 create mode 100755 tools/testing/selftests/drivers/net/hw/ntuple.py
Signature · 1 line
2.52.0
#1 lore raw

PATCH 1/2 selftests: drv-net: Add ntuple (NFC) flow steering test

From: Dimitri Daskalakis <[email protected]>

Add a test for ethtool NFC (ntuple) flow steering rules. The test creates an ntuple rule matching on various flow fields and verifies that traffic is steered to the correct queue.

The test forces all traffic to queue 0 via the indirection table, then installs an ntuple rule to steer select traffic to a specific queue. The test then verifies the expected number of packets is received on the queue.

This test has variants for TCP/UDP over IPv4/IPv6, with rules matching the source IP. Additional match fields will be added in the next commit.

TAP version 13
1..4
ok 1 ntuple.queue.tcp4.src_ip
ok 2 ntuple.queue.udp4.src_ip
ok 3 ntuple.queue.tcp6.src_ip
ok 4 ntuple.queue.udp6.src_ip
# Totals: pass:4 fail:0 xfail:0 xpass:0 skip:0 error:0

---
 .../testing/selftests/drivers/net/hw/Makefile |   1 +
 .../selftests/drivers/net/hw/ntuple.py        | 145 ++++++++++++++++++
 2 files changed, 146 insertions(+)
 create mode 100755 tools/testing/selftests/drivers/net/hw/ntuple.py
tools/testing/selftests/drivers/net/hw/Makefile +1 -0
index deeca3f8d080..1f4ebe70c34c 100644
@@ -35,6 +35,7 @@ TEST_PROGS = \
 	loopback.sh \
 	nic_timestamp.py \
 	nk_netns.py \
+	ntuple.py \
 	pp_alloc_fail.py \
 	rss_api.py \
 	rss_ctx.py \
tools/testing/selftests/drivers/net/hw/ntuple.py new file +145 -0

145 lines not on this page · raw message

Signature · 1 line
2.52.0
maintainer
#2 lore raw

Re: [PATCH net-next 1/2] selftests: drv-net: Add ntuple (NFC) flow steering test

Quoted 3 lines · On Tue, 7 Apr 2026 09:49:53 -0700 Dimitri Daskalakis wrote:

Add a test for ethtool NFC (ntuple) flow steering rules. The test creates an ntuple rule matching on various flow fields and verifies that traffic is steered to the correct queue.

Hi Michael, how accurate is the stats refresh timer in bnxt? This test is seeing ~10% of flakiness on bnxt, fewer packets got counted than we sent. Could be something else but I suspect the stats just didn't get refreshed. We give it 25% margin right now.

Dimitiri, this skips for some drivers because they don't auto-enable ntuple filters. Looks like other selftests have the same check and also skip in netdev CI. So probably a separate / follow up task but I think we need to add code to enable the filters if they were disabled.

#3 lore raw

Re: [PATCH net-next 1/2] selftests: drv-net: Add ntuple (NFC) flow steering test

Quoted 10 lines · Jakub Kicinski
Quoted 3 lines · On Tue, 7 Apr 2026 09:49:53 -0700 Dimitri Daskalakis wrote:

Add a test for ethtool NFC (ntuple) flow steering rules. The test creates an ntuple rule matching on various flow fields and verifies that traffic is steered to the correct queue.

Hi Michael, how accurate is the stats refresh timer in bnxt? This test is seeing ~10% of flakiness on bnxt, fewer packets got counted than we sent. Could be something else but I suspect the stats just didn't get refreshed. We give it 25% margin right now.

Quoted 4 lines

Dimitiri, this skips for some drivers because they don't auto-enable ntuple filters. Looks like other selftests have the same check and also skip in netdev CI. So probably a separate / follow up task but I think we need to add code to enable the filters if they were disabled.

Sounds good, I will follow up with enabling ntuple filters across the selftests.

#4 lore raw

PATCH 2/2 selftests: drv-net: ntuple: Add dst-ip, src-port, dst-port fields

In reply to Dimitri Daskalakis

From: Dimitri Daskalakis <[email protected]>

Extend the ntuple flow steering test to cover dst-ip, src-port, and dst-port fields. The test supports arbitrary combinations of the fields, for now we test src_ip/dst_ip, and src_ip/dst_ip/src_port/dst_port.

The tests currently match full fields, but we can consider adding support for masked fields in the future.

TAP version 13
1..24
ok 1 ntuple.queue.tcp4.src_ip
ok 2 ntuple.queue.tcp4.dst_ip
ok 3 ntuple.queue.tcp4.src_port
ok 4 ntuple.queue.tcp4.dst_port
ok 5 ntuple.queue.tcp4.src_ip.dst_ip
ok 6 ntuple.queue.tcp4.src_ip.dst_ip.src_port.dst_port ok 7 ntuple.queue.udp4.src_ip
ok 8 ntuple.queue.udp4.dst_ip
ok 9 ntuple.queue.udp4.src_port
ok 10 ntuple.queue.udp4.dst_port
ok 11 ntuple.queue.udp4.src_ip.dst_ip
ok 12 ntuple.queue.udp4.src_ip.dst_ip.src_port.dst_port ok 13 ntuple.queue.tcp6.src_ip
ok 14 ntuple.queue.tcp6.dst_ip
ok 15 ntuple.queue.tcp6.src_port
ok 16 ntuple.queue.tcp6.dst_port
ok 17 ntuple.queue.tcp6.src_ip.dst_ip
ok 18 ntuple.queue.tcp6.src_ip.dst_ip.src_port.dst_port ok 19 ntuple.queue.udp6.src_ip
ok 20 ntuple.queue.udp6.dst_ip
ok 21 ntuple.queue.udp6.src_port
ok 22 ntuple.queue.udp6.dst_port
ok 23 ntuple.queue.udp6.src_ip.dst_ip
ok 24 ntuple.queue.udp6.src_ip.dst_ip.src_port.dst_port # Totals: pass:24 fail:0 xfail:0 xpass:0 skip:0 error:0

---
 .../selftests/drivers/net/hw/ntuple.py        | 29 +++++++++++++++----
 1 file changed, 23 insertions(+), 6 deletions(-)
tools/testing/selftests/drivers/net/hw/ntuple.py +23 -6
index c50b76198fba..12f0d395f825 100755
@@ -9,11 +9,14 @@ from lib.py import ksft_eq, ksft_ge
 from lib.py import ksft_variants, KsftNamedVariant
 from lib.py import EthtoolFamily, NetDrvEpEnv, NetdevFamily
 from lib.py import KsftSkipEx
-from lib.py import cmd, ethtool, defer, rand_port, bkg, wait_port_listen
+from lib.py import cmd, ethtool, defer, rand_ports, bkg, wait_port_listen
 
 
 class NtupleField(Enum):
     SRC_IP = auto()
+    DST_IP = auto()
+    SRC_PORT = auto()
+    DST_PORT = auto()
 
 
 def _require_ntuple(cfg):
@@ -69,7 +72,7 @@ def _setup_isolated_queue(cfg):
     return random.randint(1, desired_queues - 1)
 
 
-def _send_traffic(cfg, ipver, proto, dst_port, pkt_cnt=40):
+def _send_traffic(cfg, ipver, proto, dst_port, src_port, pkt_cnt=40):
     """Generate traffic with the desired flow signature."""
 
     cfg.require_cmd("socat", remote=True)
@@ -86,28 +89,42 @@ def _send_traffic(cfg, ipver, proto, dst_port, pkt_cnt=40):
         send_cmd = f"""
         bash -c 'for i in $(seq {pkt_cnt}); do echo msg; sleep 0.02; done' |
         socat -{ipver} -u - \
-            {socat_proto}:{dst_addr}:{dst_port},reuseaddr{extra_opts}
+            {socat_proto}:{dst_addr}:{dst_port},sourceport={src_port},reuseaddr{extra_opts}
         """
         cmd(send_cmd, shell=True, host=cfg.remote)
 
 
 def _add_ntuple_rule_and_send_traffic(cfg, ipver, proto, fields, test_queue):
-    dst_port = rand_port()
+    ports = rand_ports(2)
+    src_port = ports[0]
+    dst_port = ports[1]
     flow_parts = [f"flow-type {proto}{ipver}"]
 
     for field in fields:
         if field == NtupleField.SRC_IP:
             flow_parts.append(f"src-ip {cfg.remote_addr_v[ipver]}")
+        elif field == NtupleField.DST_IP:
+            flow_parts.append(f"dst-ip {cfg.addr_v[ipver]}")
+        elif field == NtupleField.SRC_PORT:
+            flow_parts.append(f"src-port {src_port}")
+        elif field == NtupleField.DST_PORT:
+            flow_parts.append(f"dst-port {dst_port}")
 
     flow_parts.append(f"action {test_queue}")
     _ntuple_rule_add(cfg, " ".join(flow_parts))
-    _send_traffic(cfg, ipver, proto, dst_port=dst_port)
+    _send_traffic(cfg, ipver, proto, dst_port=dst_port, src_port=src_port)
 
 
 def _ntuple_variants():
     for ipver in ["4", "6"]:
         for proto in ["tcp", "udp"]:
-            for fields in [[NtupleField.SRC_IP]]:
+            for fields in [[NtupleField.SRC_IP],
+                           [NtupleField.DST_IP],
+                           [NtupleField.SRC_PORT],
+                           [NtupleField.DST_PORT],
+                           [NtupleField.SRC_IP, NtupleField.DST_IP],
+                           [NtupleField.SRC_IP, NtupleField.DST_IP,
+                            NtupleField.SRC_PORT, NtupleField.DST_PORT]]:
                 name = ".".join(f.name.lower() for f in fields)
                 yield KsftNamedVariant(f"{proto}{ipver}.{name}",
                                       ipver, proto, fields)
Signature · 1 line
2.52.0
#5 lore raw
In reply to Dimitri Daskalakis
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Tue, 7 Apr 2026 09:49:52 -0700 you wrote:

From: Dimitri Daskalakis <[email protected]>

Thoroughly testing a device's NFC implementation can be tedious. The more features a device supports, the more combinations to validate.

This series aims to ease that burden, validating the most common NFC rule combinations.

[...]

Here is the summary with links:
- [net-next,1/2] selftests: drv-net: Add ntuple (NFC) flow steering test

    https://git.kernel.org/netdev/net-next/c/18589df9344c
  - [net-next,2/2] selftests: drv-net: ntuple: Add dst-ip, src-port, dst-port fields
    https://git.kernel.org/netdev/net-next/c/a66374a3eb02

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html