DPDK patches and discussions
 help / color / mirror / Atom feed
From: Paul Szczepanek <paul.szczepanek@arm.com>
To: dev@dpdk.org
Cc: probb@iol.unh.edu, Paul Szczepanek <paul.szczepanek@arm.com>,
	Thomas Wilks <thomas.wilks@arm.com>
Subject: [PATCH v2 2/2] dts: add softnic test
Date: Tue, 31 Dec 2024 11:31:16 +0000	[thread overview]
Message-ID: <20241231113116.1510537-2-paul.szczepanek@arm.com> (raw)
In-Reply-To: <20241231113116.1510537-1-paul.szczepanek@arm.com>

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


      reply	other threads:[~2024-12-31 11:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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   ` Paul Szczepanek [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241231113116.1510537-2-paul.szczepanek@arm.com \
    --to=paul.szczepanek@arm.com \
    --cc=dev@dpdk.org \
    --cc=probb@iol.unh.edu \
    --cc=thomas.wilks@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).