On Wed, May 21, 2025 at 3:26 PM Dean Marx wrote: > Add an RTE Flow API testing suite, which covers some basic > synchronous Flow API rules that should be supported across PMDs. > This suite will be added to over time, as the Flow API is too large > to cover all in one suite, and sending one monolithic series > would be impossible. > > Signed-off-by: Dean Marx > --- > dts/tests/TestSuite_flow.py | 585 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 585 insertions(+) > create mode 100644 dts/tests/TestSuite_flow.py > > diff --git a/dts/tests/TestSuite_flow.py b/dts/tests/TestSuite_flow.py > new file mode 100644 > index 0000000000..15566205c9 > --- /dev/null > +++ b/dts/tests/TestSuite_flow.py > @@ -0,0 +1,585 @@ > +# SPDX-License-Identifier: BSD-3-Clause > +# Copyright(c) 2025 University of New Hampshire > + > +"""RTE Flow testing suite. > + > +This suite verifies a range of flow rules built using patterns > +and actions from the RTE Flow API. It would be impossible to cover > +every valid flow rule, but this suite aims to test the most > +important and common functionalities across PMDs. > + > +""" > + > +from collections.abc import Callable > +from itertools import zip_longest > +from typing import Any, Iterator, cast > + > +from scapy.layers.inet import IP, TCP, UDP > +from scapy.layers.inet6 import IPv6 > +from scapy.layers.l2 import Dot1Q, Ether > +from scapy.packet import Packet, Raw > + > +from framework.remote_session.testpmd_shell import FlowRule, TestPmdShell > +from framework.test_suite import TestSuite, func_test > +from framework.testbed_model.capability import NicCapability, > TopologyType, requires > + > + > +@requires(topology_type=TopologyType.two_links) > I am thinking this testsuite might be valid for 1 link instead of requiring 2 links. > +@requires(NicCapability.FLOW_CTRL) > +class TestFlow(TestSuite): > + """RTE Flow test suite. > + > + This suite consists of 10 test cases: > + 1. Queue Action Ethernet: Verifies queue actions with ethernet > patterns > + 2. Queue Action IP: Verifies queue actions with IPv4 and IPv6 patterns > + 3. Queue Action L4: Verifies queue actions with TCP and UDP patterns > + 4. Queue Action VLAN: Verifies queue actions with VLAN patterns > + 5. Drop Action Eth: Verifies drop action with ethernet patterns > You are using both Ethernet and Eth - choose 1 > + 6. Drop Action IP: Verifies drop actions with IPV4 and IPv6 patterns > + 7. Drop Action L4: Verifies drop actions with TCP and UDP patterns > + 8. Drop Action VLAN: Verifies drop actions with VLAN patterns > + 9. Modify Field Action: Verifies packet modification patterns > + 10. Egress Rules: Verifies previously covered rules are still valid > as egress. > + > + """ > + > + def runner( > + self, > + verification_method: Callable[..., Any], > + flows: list[FlowRule], > + packets: list[Packet], > + expected_packets: list[Packet] | None = None, > + *args: Any, > + **kwargs: Any, > + ) -> None: > + """Runner method that validates each flow using the corresponding > verification method. > + > + Args: > + verification_method: Callable that performs verification > logic. > + flows: List of flow rules to create and test. > + packets: List of packets corresponding to each flow. > + expected_packets: List of packets to check sent packets > against in modification cases. > + *args: Additional positional arguments to pass to the > verification method. > + **kwargs: Additional keyword arguments to pass to the > verification method. > + """ > + > + def zip_lists( > + rules: list[FlowRule], > + packets1: list[Packet], > + packets2: list[Packet] | None, > + ) -> Iterator[tuple[FlowRule, Packet, Packet | None]]: > + """Method that creates an iterable zip containing lists used > in runner. > + > + Args: > + rules: List of flow rules. > + packets1: List of packets. > + packets2: Optional list of packets, excluded from zip if > not passed to runner. > + """ > + return cast( > + Iterator[tuple[FlowRule, Packet, Packet | None]], > + zip_longest(rules, packets1, packets2 or [], > fillvalue=None), > + ) > + > + with TestPmdShell(rx_queues=4, tx_queues=4) as testpmd: > + for flow, packet, expected_packet in zip_lists(flows, > packets, expected_packets): > + flow_id = testpmd.flow_create(flow_rule=flow, port_id=0) > + > + if verification_method == self.send_packet_and_verify: > + verification_method(*args, **kwargs) > + > + elif verification_method == > self.send_packet_and_verify_queue: > + verification_method( > + packet=packet, test_queue=kwargs["test_queue"], > testpmd=testpmd > + ) > + > + elif verification_method == > self.send_packet_and_verify_modification: > + verification_method(packet=packet, > expected_packet=expected_packet) > + > + testpmd.flow_delete(flow_id, port_id=0) > + > > > + @func_test > + def test_egress_rules(self) -> None: > + """Validate flow rules with egress directions. > + > + Steps: > + Create a list of packets to test, with a corresponding flow > list. > + Launch testpmd with the necessary configuration. > + Send each packet in the list, check reception status. > + > + Verify: > + Check that each packet is dropped. > + > + One packet will be sent as a confidence check, to ensure packets > are being > + received under normal circumstances. > + """ > + packet_list = [ > + Ether(src="02:00:00:00:00:00"), > + IP(src="192.168.1.1"), > + TCP(sport=1234), > + UDP(sport=5000), > + ] > + flow_list = [ > + FlowRule( > + direction="egress", pattern=["eth src is > 02:00:00:00:00:00"], actions=["drop"] > + ), > + FlowRule(direction="egress", pattern=["ipv4 src is > 192.168.1.1"], actions=["drop"]), > + FlowRule(direction="egress", pattern=["tcp src is 1234"], > actions=["drop"]), > + FlowRule(direction="egress", pattern=["udp src is 5000"], > actions=["drop"]), > + ] > + # Verify packet reception without flow rule > + self.send_packet_and_verify(packet=Raw(load="xxxxx"), > should_receive=True) > + self.runner( > + verification_method=self.send_packet_and_verify, > + flows=flow_list, > + packets=packet_list, > + should_receive=False, > + ) > It looks like for testing these egress rules you are adding the egress flow rule on port 0, but we are actually egressing on port 1 (if 2 link topology is enforced as you decorate this testsuite with). So, if my understanding is correct, then you need to egress on port 1, or on ctx.topology egress port (same thing). > -- > 2.49.0 > > Remember to include a testsuite rst like https://git.dpdk.org/dpdk/commit/?id=d23083df08114975987753a887f1d1deed387ce2 Reviewed-by: Patrick Robb