DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH v1 1/2] dts: allow expected packets to come from the TG
@ 2024-12-31 11:24 Paul Szczepanek
  2024-12-31 11:24 ` [PATCH v1 2/2] dts: add softnic test Paul Szczepanek
  2024-12-31 11:31 ` [PATCH v2 1/2] dts: allow expected packets to come from the TG Paul Szczepanek
  0 siblings, 2 replies; 4+ messages in thread
From: Paul Szczepanek @ 2024-12-31 11:24 UTC (permalink / raw)
  To: dev; +Cc: probb, Paul Szczepanek, Thomas Wilks

Add sent_from_tg variable to get_expected_packets
for when packets are sent from the TG.

Signed-off-by: Thomas Wilks <thomas.wilks@arm.com>
Signed-off-by: Paul Szczepanek <paul.szczepanek@arm.com>
---
 dts/framework/test_suite.py | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/dts/framework/test_suite.py b/dts/framework/test_suite.py
index adee01f031..69b24fd126 100644
--- a/dts/framework/test_suite.py
+++ b/dts/framework/test_suite.py
@@ -274,31 +274,41 @@ def send_packets(
         packets = self._adjust_addresses(packets)
         self.tg_node.send_packets(packets, self._tg_port_egress)
 
-    def get_expected_packets(self, packets: list[Packet]) -> list[Packet]:
+    def get_expected_packets(
+        self,
+        packets: list[Packet],
+        sent_from_tg: bool = False,
+    ) -> list[Packet]:
         """Inject the proper L2/L3 addresses into `packets`.
 
         Inject the L2/L3 addresses expected at the receiving end of the traffic generator.
 
         Args:
             packets: The packets to modify.
+            sent_from_tg: True if packet was sent from the TG.
 
         Returns:
             `packets` with injected L2/L3 addresses.
         """
-        return self._adjust_addresses(packets, expected=True)
+        return self._adjust_addresses(packets, not sent_from_tg)
 
-    def get_expected_packet(self, packet: Packet) -> Packet:
+    def get_expected_packet(
+        self,
+        packet: Packet,
+        sent_from_tg: bool = False,
+    ) -> Packet:
         """Inject the proper L2/L3 addresses into `packet`.
 
         Inject the L2/L3 addresses expected at the receiving end of the traffic generator.
 
         Args:
             packet: The packet to modify.
+            sent_from_tg: True if packet was sent from the TG.
 
         Returns:
             `packet` with injected L2/L3 addresses.
         """
-        return self.get_expected_packets([packet])[0]
+        return self.get_expected_packets([packet], sent_from_tg)[0]
 
     def _adjust_addresses(self, packets: list[Packet], expected: bool = False) -> list[Packet]:
         """L2 and L3 address additions in both directions.
-- 
2.39.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v1 2/2] dts: add softnic test
  2024-12-31 11:24 [PATCH v1 1/2] dts: allow expected packets to come from the TG Paul Szczepanek
@ 2024-12-31 11:24 ` Paul Szczepanek
  2024-12-31 11:31 ` [PATCH v2 1/2] dts: allow expected packets to come from the TG Paul Szczepanek
  1 sibling, 0 replies; 4+ messages in thread
From: Paul Szczepanek @ 2024-12-31 11:24 UTC (permalink / raw)
  To: dev; +Cc: probb, Paul Szczepanek, Thomas Wilks

Add test that uses a softnic virtual device to froward packets.

Signed-off-by: Thomas Wilks <thomas.wilks@arm.com>
Signed-off-by: Paul Szczepanek <paul.szczepanek@arm.com>
---
 dts/tests/TestSuite_softnic.py | 119 +++++++++++++++++++++++++++++++++
 1 file changed, 119 insertions(+)
 create mode 100644 dts/tests/TestSuite_softnic.py

diff --git a/dts/tests/TestSuite_softnic.py b/dts/tests/TestSuite_softnic.py
new file mode 100644
index 0000000000..7944b18029
--- /dev/null
+++ b/dts/tests/TestSuite_softnic.py
@@ -0,0 +1,119 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2024 Arm Limited
+
+"""Softnic test suite.
+
+Create a softnic virtual device and verify it successfully forwards packets.
+"""
+from pathlib import Path, PurePath
+
+from framework.params.testpmd import EthPeer
+from framework.remote_session.testpmd_shell import TestPmdShell
+from framework.test_suite import TestSuite, func_test
+from framework.testbed_model.capability import requires
+from framework.testbed_model.topology import TopologyType
+from framework.testbed_model.virtual_device import VirtualDevice
+from framework.utils import generate_random_packets
+
+
+@requires(topology_type=TopologyType.two_links)
+class TestSoftnic(TestSuite):
+    """Softnic test suite."""
+
+    #: The total number of packets to generate and send for forwarding.
+    NUMBER_OF_PACKETS_TO_SEND = 10
+    #: The payload size to use for the generated packets in bytes.
+    PAYLOAD_SIZE = 100
+
+    def set_up_suite(self) -> None:
+        """Set up the test suite.
+
+        Setup:
+            Generate the random packets that will be sent and create the softnic config files.
+        """
+        self.packets = generate_random_packets(self.NUMBER_OF_PACKETS_TO_SEND, self.PAYLOAD_SIZE)
+        self.cli_file = self.prepare_softnic_files()
+
+    def prepare_softnic_files(self) -> PurePath:
+        """Creates the config files that are required for the creation of the softnic.
+
+        The config files are created at runtime to accommodate paths and device addresses.
+        """
+        # paths of files needed by softnic
+        cli_file = Path("rx_tx.cli")
+        spec_file = Path("rx_tx.spec")
+        rx_tx_1_file = Path("rx_tx_1.io")
+        rx_tx_2_file = Path("rx_tx_2.io")
+        path_sut = self.sut_node.remote_dpdk_build_dir
+        cli_file_sut = self.sut_node.main_session.join_remote_path(path_sut, cli_file)
+        spec_file_sut = self.sut_node.main_session.join_remote_path(path_sut, spec_file)
+        rx_tx_1_file_sut = self.sut_node.main_session.join_remote_path(path_sut, rx_tx_1_file)
+        rx_tx_2_file_sut = self.sut_node.main_session.join_remote_path(path_sut, rx_tx_2_file)
+        firmware_c_file_sut = self.sut_node.main_session.join_remote_path(path_sut, "firmware.c")
+        firmware_so_file_sut = self.sut_node.main_session.join_remote_path(path_sut, "firmware.so")
+
+        # write correct remote paths to local files
+        with open(cli_file, "w+") as fh:
+            fh.write(f"pipeline codegen {spec_file_sut} {firmware_c_file_sut}\n")
+            fh.write(f"pipeline libbuild {firmware_c_file_sut} {firmware_so_file_sut}\n")
+            fh.write(f"pipeline RX build lib {firmware_so_file_sut} io {rx_tx_1_file_sut} numa 0\n")
+            fh.write(f"pipeline TX build lib {firmware_so_file_sut} io {rx_tx_2_file_sut} numa 0\n")
+            fh.write("thread 2 pipeline RX enable\n")
+            fh.write("thread 2 pipeline TX enable\n")
+        with open(spec_file, "w+") as fh:
+            fh.write("struct metadata_t {{\n")
+            fh.write("	bit<32> port\n")
+            fh.write("}}\n")
+            fh.write("metadata instanceof metadata_t\n")
+            fh.write("apply {{\n")
+            fh.write("	rx m.port\n")
+            fh.write("	tx m.port\n")
+            fh.write("}}\n")
+        with open(rx_tx_1_file, "w+") as fh:
+            fh.write(f"port in 0 ethdev {self.sut_node.config.ports[0].pci} rxq 0 bsz 32\n")
+            fh.write("port out 0 ring RXQ0 bsz 32\n")
+        with open(rx_tx_2_file, "w+") as fh:
+            fh.write("port in 0 ring TXQ0 bsz 32\n")
+            fh.write(f"port out 1 ethdev {self.sut_node.config.ports[1].pci} txq 0 bsz 32\n")
+
+        # copy files over to SUT
+        self.sut_node.main_session.copy_to(cli_file, cli_file_sut)
+        self.sut_node.main_session.copy_to(spec_file, spec_file_sut)
+        self.sut_node.main_session.copy_to(rx_tx_1_file, rx_tx_1_file_sut)
+        self.sut_node.main_session.copy_to(rx_tx_2_file, rx_tx_2_file_sut)
+        # and cleanup local files
+        cli_file.unlink()
+        spec_file.unlink()
+        rx_tx_1_file.unlink()
+        rx_tx_2_file.unlink()
+
+        return cli_file_sut
+
+    @func_test
+    def softnic(self) -> None:
+        """Softnic test.
+
+        Steps:
+            Start Testpmd with a softnic vdev using the provided config files.
+            Testpmd forwarding is disabled, instead configure softnic to forward packets
+            from port 0 to port 1 of the physical device.
+            Send generated packets from the TG.
+
+        Verify:
+            The packets that are received are the same as the packets sent.
+
+        """
+        with TestPmdShell(
+            self.sut_node,
+            vdevs=[VirtualDevice(f"net_softnic0,firmware={self.cli_file},cpu_id=1,conn_port=8086")],
+            eth_peer=[EthPeer(1, self.tg_node.ports[1].mac_address)],
+            port_topology=None,
+            disable_device_start=True,
+        ) as shell:
+            shell.start()
+            received_packets = self.send_packets_and_capture(self.packets)
+            # packets are being forwarded without addresses being amended so
+            # we get the address as it would be expected to come from TG
+            expected_packets = self.get_expected_packets(self.packets, sent_from_tg=True)
+
+            self.match_all_packets(expected_packets, received_packets)
-- 
2.39.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] dts: allow expected packets to come from the TG
  2024-12-31 11:24 [PATCH v1 1/2] dts: allow expected packets to come from the TG Paul Szczepanek
  2024-12-31 11:24 ` [PATCH v1 2/2] dts: add softnic test Paul Szczepanek
@ 2024-12-31 11:31 ` Paul Szczepanek
  2024-12-31 11:31   ` [PATCH v2 2/2] dts: add softnic test Paul Szczepanek
  1 sibling, 1 reply; 4+ messages in thread
From: Paul Szczepanek @ 2024-12-31 11:31 UTC (permalink / raw)
  To: dev; +Cc: probb, Paul Szczepanek, Thomas Wilks

Add sent_from_tg variable to get_expected_packets
for when packets are sent from the TG.

Signed-off-by: Thomas Wilks <thomas.wilks@arm.com>
Signed-off-by: Paul Szczepanek <paul.szczepanek@arm.com>
---
 dts/framework/test_suite.py | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/dts/framework/test_suite.py b/dts/framework/test_suite.py
index adee01f031..69b24fd126 100644
--- a/dts/framework/test_suite.py
+++ b/dts/framework/test_suite.py
@@ -274,31 +274,41 @@ def send_packets(
         packets = self._adjust_addresses(packets)
         self.tg_node.send_packets(packets, self._tg_port_egress)
 
-    def get_expected_packets(self, packets: list[Packet]) -> list[Packet]:
+    def get_expected_packets(
+        self,
+        packets: list[Packet],
+        sent_from_tg: bool = False,
+    ) -> list[Packet]:
         """Inject the proper L2/L3 addresses into `packets`.
 
         Inject the L2/L3 addresses expected at the receiving end of the traffic generator.
 
         Args:
             packets: The packets to modify.
+            sent_from_tg: True if packet was sent from the TG.
 
         Returns:
             `packets` with injected L2/L3 addresses.
         """
-        return self._adjust_addresses(packets, expected=True)
+        return self._adjust_addresses(packets, not sent_from_tg)
 
-    def get_expected_packet(self, packet: Packet) -> Packet:
+    def get_expected_packet(
+        self,
+        packet: Packet,
+        sent_from_tg: bool = False,
+    ) -> Packet:
         """Inject the proper L2/L3 addresses into `packet`.
 
         Inject the L2/L3 addresses expected at the receiving end of the traffic generator.
 
         Args:
             packet: The packet to modify.
+            sent_from_tg: True if packet was sent from the TG.
 
         Returns:
             `packet` with injected L2/L3 addresses.
         """
-        return self.get_expected_packets([packet])[0]
+        return self.get_expected_packets([packet], sent_from_tg)[0]
 
     def _adjust_addresses(self, packets: list[Packet], expected: bool = False) -> list[Packet]:
         """L2 and L3 address additions in both directions.
-- 
2.39.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] dts: add softnic test
  2024-12-31 11:31 ` [PATCH v2 1/2] dts: allow expected packets to come from the TG Paul Szczepanek
@ 2024-12-31 11:31   ` Paul Szczepanek
  0 siblings, 0 replies; 4+ messages in thread
From: Paul Szczepanek @ 2024-12-31 11:31 UTC (permalink / raw)
  To: dev; +Cc: probb, Paul Szczepanek, Thomas Wilks

Add test that uses a softnic virtual device to forward packets.

Signed-off-by: Thomas Wilks <thomas.wilks@arm.com>
Signed-off-by: Paul Szczepanek <paul.szczepanek@arm.com>
---
 dts/tests/TestSuite_softnic.py | 119 +++++++++++++++++++++++++++++++++
 1 file changed, 119 insertions(+)
 create mode 100644 dts/tests/TestSuite_softnic.py

diff --git a/dts/tests/TestSuite_softnic.py b/dts/tests/TestSuite_softnic.py
new file mode 100644
index 0000000000..7944b18029
--- /dev/null
+++ b/dts/tests/TestSuite_softnic.py
@@ -0,0 +1,119 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2024 Arm Limited
+
+"""Softnic test suite.
+
+Create a softnic virtual device and verify it successfully forwards packets.
+"""
+from pathlib import Path, PurePath
+
+from framework.params.testpmd import EthPeer
+from framework.remote_session.testpmd_shell import TestPmdShell
+from framework.test_suite import TestSuite, func_test
+from framework.testbed_model.capability import requires
+from framework.testbed_model.topology import TopologyType
+from framework.testbed_model.virtual_device import VirtualDevice
+from framework.utils import generate_random_packets
+
+
+@requires(topology_type=TopologyType.two_links)
+class TestSoftnic(TestSuite):
+    """Softnic test suite."""
+
+    #: The total number of packets to generate and send for forwarding.
+    NUMBER_OF_PACKETS_TO_SEND = 10
+    #: The payload size to use for the generated packets in bytes.
+    PAYLOAD_SIZE = 100
+
+    def set_up_suite(self) -> None:
+        """Set up the test suite.
+
+        Setup:
+            Generate the random packets that will be sent and create the softnic config files.
+        """
+        self.packets = generate_random_packets(self.NUMBER_OF_PACKETS_TO_SEND, self.PAYLOAD_SIZE)
+        self.cli_file = self.prepare_softnic_files()
+
+    def prepare_softnic_files(self) -> PurePath:
+        """Creates the config files that are required for the creation of the softnic.
+
+        The config files are created at runtime to accommodate paths and device addresses.
+        """
+        # paths of files needed by softnic
+        cli_file = Path("rx_tx.cli")
+        spec_file = Path("rx_tx.spec")
+        rx_tx_1_file = Path("rx_tx_1.io")
+        rx_tx_2_file = Path("rx_tx_2.io")
+        path_sut = self.sut_node.remote_dpdk_build_dir
+        cli_file_sut = self.sut_node.main_session.join_remote_path(path_sut, cli_file)
+        spec_file_sut = self.sut_node.main_session.join_remote_path(path_sut, spec_file)
+        rx_tx_1_file_sut = self.sut_node.main_session.join_remote_path(path_sut, rx_tx_1_file)
+        rx_tx_2_file_sut = self.sut_node.main_session.join_remote_path(path_sut, rx_tx_2_file)
+        firmware_c_file_sut = self.sut_node.main_session.join_remote_path(path_sut, "firmware.c")
+        firmware_so_file_sut = self.sut_node.main_session.join_remote_path(path_sut, "firmware.so")
+
+        # write correct remote paths to local files
+        with open(cli_file, "w+") as fh:
+            fh.write(f"pipeline codegen {spec_file_sut} {firmware_c_file_sut}\n")
+            fh.write(f"pipeline libbuild {firmware_c_file_sut} {firmware_so_file_sut}\n")
+            fh.write(f"pipeline RX build lib {firmware_so_file_sut} io {rx_tx_1_file_sut} numa 0\n")
+            fh.write(f"pipeline TX build lib {firmware_so_file_sut} io {rx_tx_2_file_sut} numa 0\n")
+            fh.write("thread 2 pipeline RX enable\n")
+            fh.write("thread 2 pipeline TX enable\n")
+        with open(spec_file, "w+") as fh:
+            fh.write("struct metadata_t {{\n")
+            fh.write("	bit<32> port\n")
+            fh.write("}}\n")
+            fh.write("metadata instanceof metadata_t\n")
+            fh.write("apply {{\n")
+            fh.write("	rx m.port\n")
+            fh.write("	tx m.port\n")
+            fh.write("}}\n")
+        with open(rx_tx_1_file, "w+") as fh:
+            fh.write(f"port in 0 ethdev {self.sut_node.config.ports[0].pci} rxq 0 bsz 32\n")
+            fh.write("port out 0 ring RXQ0 bsz 32\n")
+        with open(rx_tx_2_file, "w+") as fh:
+            fh.write("port in 0 ring TXQ0 bsz 32\n")
+            fh.write(f"port out 1 ethdev {self.sut_node.config.ports[1].pci} txq 0 bsz 32\n")
+
+        # copy files over to SUT
+        self.sut_node.main_session.copy_to(cli_file, cli_file_sut)
+        self.sut_node.main_session.copy_to(spec_file, spec_file_sut)
+        self.sut_node.main_session.copy_to(rx_tx_1_file, rx_tx_1_file_sut)
+        self.sut_node.main_session.copy_to(rx_tx_2_file, rx_tx_2_file_sut)
+        # and cleanup local files
+        cli_file.unlink()
+        spec_file.unlink()
+        rx_tx_1_file.unlink()
+        rx_tx_2_file.unlink()
+
+        return cli_file_sut
+
+    @func_test
+    def softnic(self) -> None:
+        """Softnic test.
+
+        Steps:
+            Start Testpmd with a softnic vdev using the provided config files.
+            Testpmd forwarding is disabled, instead configure softnic to forward packets
+            from port 0 to port 1 of the physical device.
+            Send generated packets from the TG.
+
+        Verify:
+            The packets that are received are the same as the packets sent.
+
+        """
+        with TestPmdShell(
+            self.sut_node,
+            vdevs=[VirtualDevice(f"net_softnic0,firmware={self.cli_file},cpu_id=1,conn_port=8086")],
+            eth_peer=[EthPeer(1, self.tg_node.ports[1].mac_address)],
+            port_topology=None,
+            disable_device_start=True,
+        ) as shell:
+            shell.start()
+            received_packets = self.send_packets_and_capture(self.packets)
+            # packets are being forwarded without addresses being amended so
+            # we get the address as it would be expected to come from TG
+            expected_packets = self.get_expected_packets(self.packets, sent_from_tg=True)
+
+            self.match_all_packets(expected_packets, received_packets)
-- 
2.39.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-12-31 11:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-31 11:24 [PATCH v1 1/2] dts: allow expected packets to come from the TG Paul Szczepanek
2024-12-31 11:24 ` [PATCH v1 2/2] dts: add softnic test Paul Szczepanek
2024-12-31 11:31 ` [PATCH v2 1/2] dts: allow expected packets to come from the TG Paul Szczepanek
2024-12-31 11:31   ` [PATCH v2 2/2] dts: add softnic test Paul Szczepanek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).