From: Bobby Eshleman <[email protected]>
Extend the netkit devmem selftest with a TX test case. The TX path uses
the primary RX redirect BPF program to redirect traffic from the primary
netkit ingress to the physical NIC via bpf_redirect_neigh().
The actual TX path looks like the following:
TX Path
-------
Netkit Guest (netns) Netkit Host Physical NIC Remote
| | | |
|--- TCP send --------->| | |
|--- BPF redirect --->| |
|---- transmit ----->|
dmabuf
Signed-off-by: Bobby Eshleman <[email protected]>
---
.../testing/selftests/drivers/net/hw/nk_devmem.py | 23 ++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/drivers/net/hw/nk_devmem.py
b/tools/testing/selftests/drivers/net/hw/nk_devmem.py
index 0a66ff85db9d..0e3c5aab6423 100755
--- a/tools/testing/selftests/drivers/net/hw/nk_devmem.py
+++ b/tools/testing/selftests/drivers/net/hw/nk_devmem.py
@@ -89,14 +89,33 @@ def test_devmem(cfg) -> None:
ksft_eq(ncdevmem_rx.ret, 0)
+def test_devmem_tx(cfg) -> None:
+ """Test devmem TX: send from netkit guest, receive on remote."""
+ configure_nic(cfg)
+
+ socat = f"socat -U - TCP6-LISTEN:{cfg.port},reuseaddr"
+ tx_cmd = (f"ip netns exec {cfg.netns.name} bash -c"
+ f" 'echo test_devmem_tx | {cfg.bin_local}"
+ f" -f {cfg._nk_guest_ifname} -s {cfg.remote_addr_v['6']}"
+ f" -p {cfg.port} -t 0 -q 1 -n'")
+
+ with bkg(socat, host=cfg.remote, exit_wait=True) as receiver:
+ wait_port_listen(cfg.port, proto="tcp", host=cfg.remote)
+ cmd(tx_cmd, shell=True)
+
+ ksft_eq(receiver.ret, 0)
+ ksft_eq(receiver.stdout.strip(), "test_devmem_tx")
+
+
def main() -> None:
"""Run netkit devmem tests."""
- with NetDrvContEnv(__file__, rxqueues=2) as cfg:
+ with NetDrvContEnv(__file__, rxqueues=2,
+ primary_rx_redirect=True) as cfg:
cfg.bin_local = path.abspath(
path.dirname(__file__) + "/ncdevmem"
)
cfg.port = rand_port()
- ksft_run([test_devmem], args=(cfg,))
+ ksft_run([test_devmem, test_devmem_tx], args=(cfg,))
ksft_exit()
--
2.52.0