xref: /dpdk/dts/tests/TestSuite_pmd_buffer_scatter.py (revision bfad0948df75e95e04cba1804a2749cfc91c56fb)
17e138863SJeremy Spewock# SPDX-License-Identifier: BSD-3-Clause
27e138863SJeremy Spewock# Copyright(c) 2023-2024 University of New Hampshire
37e138863SJeremy Spewock
47e138863SJeremy Spewock"""Multi-segment packet scattering testing suite.
57e138863SJeremy Spewock
67e138863SJeremy SpewockThis testing suite tests the support of transmitting and receiving scattered packets.
77e138863SJeremy SpewockThis is shown by the Poll Mode Driver being able to forward
87e138863SJeremy Spewockscattered multi-segment packets composed of multiple non-contiguous memory buffers.
97e138863SJeremy SpewockTo ensure the receipt of scattered packets,
107e138863SJeremy Spewockthe DMA rings of the port's Rx queues must be configured
117e138863SJeremy Spewockwith mbuf data buffers whose size is less than the maximum length.
127e138863SJeremy Spewock
137e138863SJeremy SpewockIf it is the case that the Poll Mode Driver can forward scattered packets which it receives,
147e138863SJeremy Spewockthen this suffices to show the Poll Mode Driver is capable of both receiving and transmitting
157e138863SJeremy Spewockscattered packets.
167e138863SJeremy Spewock"""
177e138863SJeremy Spewock
187e138863SJeremy Spewockimport struct
197e138863SJeremy Spewock
20282688eaSLuca Vizzarrofrom scapy.layers.inet import IP  # type: ignore[import-untyped]
21282688eaSLuca Vizzarrofrom scapy.layers.l2 import Ether  # type: ignore[import-untyped]
22282688eaSLuca Vizzarrofrom scapy.packet import Raw  # type: ignore[import-untyped]
23282688eaSLuca Vizzarrofrom scapy.utils import hexstr  # type: ignore[import-untyped]
247e138863SJeremy Spewock
25*bfad0948SLuca Vizzarrofrom framework.params.testpmd import SimpleForwardingModes
26fc0f7dc4SLuca Vizzarrofrom framework.remote_session.testpmd_shell import TestPmdShell
277e138863SJeremy Spewockfrom framework.test_suite import TestSuite
287e138863SJeremy Spewock
297e138863SJeremy Spewock
307e138863SJeremy Spewockclass TestPmdBufferScatter(TestSuite):
317e138863SJeremy Spewock    """DPDK PMD packet scattering test suite.
327e138863SJeremy Spewock
337e138863SJeremy Spewock    Configure the Rx queues to have mbuf data buffers
347e138863SJeremy Spewock    whose sizes are smaller than the maximum packet size.
357e138863SJeremy Spewock    Specifically, set mbuf data buffers to have a size of 2048
367e138863SJeremy Spewock    to fit a full 1512-byte (CRC included) ethernet frame in a mono-segment packet.
377e138863SJeremy Spewock    The testing of scattered packets is done by sending a packet
387e138863SJeremy Spewock    whose length is greater than the size of the configured size of mbuf data buffers.
397e138863SJeremy Spewock    There are a total of 5 packets sent within test cases
407e138863SJeremy Spewock    which have lengths less than, equal to, and greater than the mbuf size.
417e138863SJeremy Spewock    There are multiple packets sent with lengths greater than the mbuf size
427e138863SJeremy Spewock    in order to test cases such as:
437e138863SJeremy Spewock
447e138863SJeremy Spewock    1. A single byte of the CRC being in a second buffer
457e138863SJeremy Spewock       while the remaining 3 bytes are stored in the first buffer alongside packet data.
467e138863SJeremy Spewock    2. The entire CRC being stored in a second buffer
477e138863SJeremy Spewock       while all of the packet data is stored in the first.
487e138863SJeremy Spewock    3. Most of the packet data being stored in the first buffer
497e138863SJeremy Spewock       and a single byte of packet data stored in a second buffer alongside the CRC.
507e138863SJeremy Spewock    """
517e138863SJeremy Spewock
527e138863SJeremy Spewock    def set_up_suite(self) -> None:
537e138863SJeremy Spewock        """Set up the test suite.
547e138863SJeremy Spewock
557e138863SJeremy Spewock        Setup:
5685ceeeceSJuraj Linkeš            Verify that we have at least 2 port links in the current test run
577e138863SJeremy Spewock            and increase the MTU of both ports on the traffic generator to 9000
587e138863SJeremy Spewock            to support larger packet sizes.
597e138863SJeremy Spewock        """
607e138863SJeremy Spewock        self.verify(
617e138863SJeremy Spewock            len(self._port_links) > 1,
627e138863SJeremy Spewock            "There must be at least two port links to run the scatter test suite",
637e138863SJeremy Spewock        )
647e138863SJeremy Spewock
657e138863SJeremy Spewock        self.tg_node.main_session.configure_port_mtu(9000, self._tg_port_egress)
667e138863SJeremy Spewock        self.tg_node.main_session.configure_port_mtu(9000, self._tg_port_ingress)
677e138863SJeremy Spewock
687e138863SJeremy Spewock    def scatter_pktgen_send_packet(self, pktsize: int) -> str:
697e138863SJeremy Spewock        """Generate and send a packet to the SUT then capture what is forwarded back.
707e138863SJeremy Spewock
717e138863SJeremy Spewock        Generate an IP packet of a specific length and send it to the SUT,
727e138863SJeremy Spewock        then capture the resulting received packet and extract its payload.
737e138863SJeremy Spewock        The desired length of the packet is met by packing its payload
747e138863SJeremy Spewock        with the letter "X" in hexadecimal.
757e138863SJeremy Spewock
767e138863SJeremy Spewock        Args:
777e138863SJeremy Spewock            pktsize: Size of the packet to generate and send.
787e138863SJeremy Spewock
797e138863SJeremy Spewock        Returns:
807e138863SJeremy Spewock            The payload of the received packet as a string.
817e138863SJeremy Spewock        """
827e138863SJeremy Spewock        packet = Ether() / IP() / Raw()
837e138863SJeremy Spewock        packet.getlayer(2).load = ""
847e138863SJeremy Spewock        payload_len = pktsize - len(packet) - 4
857e138863SJeremy Spewock        payload = ["58"] * payload_len
867e138863SJeremy Spewock        # pack the payload
877e138863SJeremy Spewock        for X_in_hex in payload:
887e138863SJeremy Spewock            packet.load += struct.pack("=B", int("%s%s" % (X_in_hex[0], X_in_hex[1]), 16))
897e138863SJeremy Spewock        received_packets = self.send_packet_and_capture(packet)
907e138863SJeremy Spewock        self.verify(len(received_packets) > 0, "Did not receive any packets.")
917e138863SJeremy Spewock        load = hexstr(received_packets[0].getlayer(2), onlyhex=1)
927e138863SJeremy Spewock
937e138863SJeremy Spewock        return load
947e138863SJeremy Spewock
957e138863SJeremy Spewock    def pmd_scatter(self, mbsize: int) -> None:
967e138863SJeremy Spewock        """Testpmd support of receiving and sending scattered multi-segment packets.
977e138863SJeremy Spewock
987e138863SJeremy Spewock        Support for scattered packets is shown by sending 5 packets of differing length
997e138863SJeremy Spewock        where the length of the packet is calculated by taking mbuf-size + an offset.
1007e138863SJeremy Spewock        The offsets used in the test are -1, 0, 1, 4, 5 respectively.
1017e138863SJeremy Spewock
1027e138863SJeremy Spewock        Test:
1037e138863SJeremy Spewock            Start testpmd and run functional test with preset mbsize.
1047e138863SJeremy Spewock        """
105*bfad0948SLuca Vizzarro        testpmd = TestPmdShell(
106*bfad0948SLuca Vizzarro            self.sut_node,
1079d223a28SLuca Vizzarro            forward_mode=SimpleForwardingModes.mac,
1089d223a28SLuca Vizzarro            mbcache=200,
1099d223a28SLuca Vizzarro            mbuf_size=[mbsize],
1109d223a28SLuca Vizzarro            max_pkt_len=9000,
1119d223a28SLuca Vizzarro            tx_offloads=0x00008000,
1127e138863SJeremy Spewock        )
1137e138863SJeremy Spewock        testpmd.start()
1147e138863SJeremy Spewock
1157e138863SJeremy Spewock        for offset in [-1, 0, 1, 4, 5]:
1167e138863SJeremy Spewock            recv_payload = self.scatter_pktgen_send_packet(mbsize + offset)
1177e138863SJeremy Spewock            self._logger.debug(f"Payload of scattered packet after forwarding: \n{recv_payload}")
1187e138863SJeremy Spewock            self.verify(
1197e138863SJeremy Spewock                ("58 " * 8).strip() in recv_payload,
1207e138863SJeremy Spewock                f"Payload of scattered packet did not match expected payload with offset {offset}.",
1217e138863SJeremy Spewock            )
1227e138863SJeremy Spewock        testpmd.stop()
1237e138863SJeremy Spewock
1247e138863SJeremy Spewock    def test_scatter_mbuf_2048(self) -> None:
1257e138863SJeremy Spewock        """Run the :meth:`pmd_scatter` test with `mbsize` set to 2048."""
1267e138863SJeremy Spewock        self.pmd_scatter(mbsize=2048)
1277e138863SJeremy Spewock
1287e138863SJeremy Spewock    def tear_down_suite(self) -> None:
1297e138863SJeremy Spewock        """Tear down the test suite.
1307e138863SJeremy Spewock
1317e138863SJeremy Spewock        Teardown:
1327e138863SJeremy Spewock            Set the MTU of the tg_node back to a more standard size of 1500.
1337e138863SJeremy Spewock        """
1347e138863SJeremy Spewock        self.tg_node.main_session.configure_port_mtu(1500, self._tg_port_egress)
1357e138863SJeremy Spewock        self.tg_node.main_session.configure_port_mtu(1500, self._tg_port_ingress)
136