Lines Matching +full:xdp +full:- +full:rx +full:- +full:metadata
2 # SPDX-License-Identifier: GPL-2.0
5 This file contains tests to verify native XDP support in network drivers.
7 directory, with each test focusing on a specific aspect of XDP functionality.
22 """Enum for XDP configuration options."""
30 """Enum for XDP actions."""
39 """Enum for XDP statistics."""
40 RX = 0 # Count of valid packets received for testing variable in XDPStats
52 xdp_sec: str = "xdp" # XDP section name (e.g., "xdp" or "xdp.frags")
70 rx_udp_cmd = f"socat -{cfg.addr_ipver} -T 2 -u UDP-RECV:{port},reuseport STDOUT"
71 tx_udp_cmd = f"echo -n {test_string} | socat -t 2 -u STDIN UDP:{cfg.baddr}:{port}"
100 Loads an XDP program onto a network interface.
107 dict: A dictionary containing the XDP program ID, name, and associated map IDs.
121 xdp_info = ip(f"-d link show dev {cfg.ifname}", json=True)[0]
122 prog_info["id"] = xdp_info["xdp"]["prog"]["id"]
123 prog_info["name"] = xdp_info["xdp"]["prog"]["name"]
151 Updates an XDP map with a given key-value pair using bpftool.
154 map_name: The name of the XDP map to update.
167 Retrieves and formats statistics from an XDP map.
170 xdp_map_id: The ID of the XDP map from which to retrieve statistics.
173 A dictionary containing formatted packet statistics for various XDP actions.
186 if stats_dump[key]["formatted"]["key"] == XDPStats.RX.value:
187 stats_formatted[XDPStats.RX.value] = val
219 ksft_ne(stats[XDPStats.RX.value], 0, "RX stats should not be zero")
220 ksft_eq(stats[XDPStats.RX.value], stats[XDPStats.PASS.value], "RX and PASS stats mismatch")
230 bpf_info = BPFProgInfo("xdp_prog", "xdp_native.bpf.o", "xdp", 1500)
237 Tests the XDP_PASS action for a multi-buff size.
242 bpf_info = BPFProgInfo("xdp_prog_frags", "xdp_native.bpf.o", "xdp.frags", 9000)
266 ksft_ne(stats[XDPStats.RX.value], 0, "RX stats should be zero")
267 ksft_eq(stats[XDPStats.RX.value], stats[XDPStats.DROP.value], "RX and DROP stats mismatch")
272 Tests the XDP_DROP action for a signle-buff case.
277 bpf_info = BPFProgInfo("xdp_prog", "xdp_native.bpf.o", "xdp", 1500)
284 Tests the XDP_DROP action for a multi-buff case.
289 bpf_info = BPFProgInfo("xdp_prog_frags", "xdp_native.bpf.o", "xdp.frags", 9000)
300 bpf_info: BPFProgInfo object containing the BPF program metadata.
316 rx_udp = f"socat -{cfg.addr_ipver} -T 2 " + \
317 f"-u UDP-RECV:{port},reuseport STDOUT"
320 # but with the shut-null flag socat generates a zero sized packet
322 tx_cmd_suffix = ",shut-null" if payload_len == 0 else ""
323 tx_udp = f"echo -n {test_string} | socat -t 2 " + \
324 f"-u STDIN UDP:{cfg.baddr}:{port}{tx_cmd_suffix}"
334 ksft_eq(stats[XDPStats.RX.value], expected_pkts, "RX stats mismatch")
340 Tests the XDP_TX action for a single-buff case.
345 bpf_info = BPFProgInfo("xdp_prog", "xdp_native.bpf.o", "xdp", 1500)
350 _test_xdp_native_tx(cfg, bpf_info, [0, 1500 // 2, 1500 - pkt_hdr_len])
355 Tests the XDP_TX action for a multi-buff case.
361 "xdp.frags", 9000)
363 # And the subsequent 0-sized packet ensures the driver
388 prev_offset = offset_lst[tmp_idx - 1]
391 prev_pkt_sz = pkt_sz_lst[tmp_idx - 1]
409 stats: A dictionary containing formatted packet statistics for various XDP actions.
420 # we can't use RX stats only to track data exchange failure without taking a previous
421 # snapshot. An easier way is to simply check for non-zero length of received string.
425 # Check for RX and PASS stats mismatch. Ideally, they should be equal for a successful run
426 if stats[XDPStats.RX.value] != stats[XDPStats.PASS.value]:
427 return "RX stats mismatch"
434 Tests the XDP tail adjustment functionality.
436 This function loads the appropriate XDP program based on the provided
437 program name and configures the XDP map for tail adjustment. It then
443 prog: Name of the XDP program to load.
451 bpf_info = BPFProgInfo("xdp_prog_frags", "xdp_native.bpf.o", "xdp.frags", 9000)
455 # Configure the XDP map for tail adjustment
500 Tests the XDP tail adjustment by growing packet data.
518 Tests the XDP tail adjustment by shrinking packet data.
524 offset_lst = [-16, -32, -64, -128, -256]
549 rings = ethnl.rings_get({'header': {'dev-index': cfg.ifindex}})
550 if 'hds-thresh' not in rings:
551 ksft_pr(f'hds-thresh not supported. Using default: {hds_thresh}')
553 hds_thresh = rings['hds-thresh']
562 Tests the XDP head adjustment action for a multi-buffer case.
573 prog_info = _load_xdp_prog(cfg, BPFProgInfo(prog, "xdp_native.bpf.o", "xdp.frags", 9000))
583 # after we eat into it. We send large-enough packets, but if HDS
585 # more than 28 bytes (UDPv4 + eth hdr left: (14 + 20 + 8) - 14)
618 expected_data = chr(int(tag, 16)) * (0 - offset) + test_str
635 Tests the XDP headroom growth support.
648 offset_lst = [-16, -32, -64, -128, -256]
656 Tests the XDP headroom shrinking support.
678 bpf_info = BPFProgInfo("xdp_prog", "xdp_native.bpf.o", "xdp", 1500)
686 rx_udp = f"socat -{cfg.addr_ipver} -T 2 -u UDP-RECV:{port},reuseport " + \
692 "for i in `seq 2000`; do echo a >&5; done; exec 5>&-"
696 # XDP is the "first layer of the stack" so XDP packets should be counted
707 ksft_ge(after['rx-packets'] - before['rx-packets'], 2000)
709 ksft_ge(after['tx-packets'] - before['tx-packets'], 2000)
713 ksft_eq(stats[XDPStats.RX.value], expected_pkts, "XDP RX stats mismatch")
715 ksft_eq(stats[XDPStats.TX.value], expected_pkts, "XDP TX stats mismatch")
717 # Flip the ring count back and forth to make sure the stats from XDP rings
719 chans = cfg.ethnl.channels_get({'header': {'dev-index': cfg.ifindex}})
720 if chans.get('combined-count', 0) > 1:
721 cfg.ethnl.channels_set({'header': {'dev-index': cfg.ifindex},
722 'combined-count': 1})
723 cfg.ethnl.channels_set({'header': {'dev-index': cfg.ifindex},
724 'combined-count': chans['combined-count']})
728 ksft_ge(after['rx-packets'], before['rx-packets'])
730 ksft_ge(after['tx-packets'], before['tx-packets'])
736 to interface level qstats (Rx).
744 to interface level qstats (Rx).
752 to interface level qstats (Rx and Tx)
759 Main function to execute the XDP tests.
761 This function runs a series of tests to validate the XDP support for
762 both the single and multi-buffer. It uses the NetDrvEpEnv context