xref: /dpdk/dts/tests/TestSuite_l2fwd.py (revision f5418c97fc19a20234ec0cb72ef0ffb5e93fdf2e)
1# SPDX-License-Identifier: BSD-3-Clause
2# Copyright(c) 2024 Arm Limited
3
4"""Basic L2 forwarding test suite.
5
6This testing suites runs basic L2 forwarding on testpmd across multiple different queue sizes.
7The forwarding test is performed with several packets being sent at once.
8"""
9
10from framework.params.testpmd import EthPeer, SimpleForwardingModes
11from framework.remote_session.testpmd_shell import TestPmdShell
12from framework.test_suite import TestSuite, func_test
13from framework.testbed_model.capability import requires
14from framework.testbed_model.cpu import LogicalCoreCount
15from framework.testbed_model.topology import TopologyType
16from framework.utils import generate_random_packets
17
18
19@requires(topology_type=TopologyType.two_links)
20class TestL2fwd(TestSuite):
21    """L2 forwarding test suite."""
22
23    #: The total number of packets to generate and send for forwarding.
24    NUMBER_OF_PACKETS_TO_SEND = 50
25    #: The payload size to use for the generated packets in bytes.
26    PAYLOAD_SIZE = 100
27
28    def set_up_suite(self) -> None:
29        """Set up the test suite.
30
31        Setup:
32            Generate the random packets that will be sent.
33        """
34        self.packets = generate_random_packets(self.NUMBER_OF_PACKETS_TO_SEND, self.PAYLOAD_SIZE)
35
36    @func_test
37    def l2fwd_integrity(self) -> None:
38        """Test the L2 forwarding integrity.
39
40        Test:
41            Configure a testpmd shell with a different numbers of queues (1, 2, 4 and 8) per run.
42            Start up L2 forwarding, send random packets from the TG and verify they were all
43            received back.
44        """
45        queues = [1, 2, 4, 8]
46
47        with TestPmdShell(
48            self.sut_node,
49            lcore_filter_specifier=LogicalCoreCount(cores_per_socket=4),
50            forward_mode=SimpleForwardingModes.mac,
51            eth_peer=[EthPeer(1, self.tg_node.ports[1].mac_address)],
52            disable_device_start=True,
53        ) as shell:
54            for queues_num in queues:
55                self._logger.info(f"Testing L2 forwarding with {queues_num} queue(s)")
56                shell.set_ports_queues(queues_num)
57                shell.start()
58
59                received_packets = self.send_packets_and_capture(self.packets)
60                expected_packets = self.get_expected_packets(self.packets)
61                self.match_all_packets(expected_packets, received_packets)
62
63                shell.stop()
64