Currently, there is no way in the testpmd shell class to set the mbuf
fast free offload configuration for queues or ports. This prohibits any
test suites to be written utilizing this offload configuration.
Additionally, the NIC capabilities for the Tx offload are not gathered.
This prevents future test suites from being skipped if they do not
support a Tx offload capability. Introduce methods that support calls
to testpmd in order to allow the configuration of mbuf fast free and to
gather Tx offload capabilities.

Signed-off-by: Andrew Bailey <abai...@iol.unh.edu>
---
 dts/framework/remote_session/testpmd_shell.py | 128 +++++++++++++++++-
 1 file changed, 127 insertions(+), 1 deletion(-)

diff --git a/dts/framework/remote_session/testpmd_shell.py 
b/dts/framework/remote_session/testpmd_shell.py
index ad8cb273dc..4d9caceb37 100644
--- a/dts/framework/remote_session/testpmd_shell.py
+++ b/dts/framework/remote_session/testpmd_shell.py
@@ -19,7 +19,7 @@
 import time
 from collections.abc import Callable, MutableSet
 from dataclasses import dataclass, field
-from enum import Flag, auto
+from enum import Enum, Flag, auto
 from os import environ
 from pathlib import PurePath
 from typing import TYPE_CHECKING, Any, ClassVar, Concatenate, Literal, 
ParamSpec, Tuple, TypeAlias
@@ -344,6 +344,13 @@ def make_parser(cls) -> ParserFn:
         )
 
 
+class RxTxArgFlag(Enum):
+    """Enum representing receiving or transmitting ports."""
+
+    TX = "tx"
+    RX = "rx"
+
+
 class DeviceCapabilitiesFlag(Flag):
     """Flag representing the device capabilities."""
 
@@ -2672,6 +2679,125 @@ def get_capabilities_physical_function(
         else:
             unsupported_capabilities.add(NicCapability.PHYSICAL_FUNCTION)
 
+    @requires_started_ports
+    def get_rxtx_offload_config(
+        self,
+        rxtx: RxTxArgFlag,
+        verify: bool,
+        port_id: int = 0,
+        num_queues: int = 0,
+    ) -> dict[int | str, str]:
+        """Get the Rx or Tx offload configuration of the queues from the given 
port.
+
+        Args:
+            rxtx: Whether to get the Rx or Tx configuration of the given 
queues.
+            verify: If :data:'True' the output of the command will be scanned 
in an attempt to
+                verify that the offload configuration was retrieved 
successfully on all queues.
+            port_id: The port ID that contains the desired queues.
+            num_queues: The number of queues to get the offload configuration 
for.
+
+        Returns:
+            A dict containing port info at key 'port' and queue info keyed by 
the appropriate queue
+                id.
+
+        Raises:
+            InteractiveCommandExecutionError: If all queue offload 
configurations could not be
+                retrieved.
+
+        """
+        returnDict: dict[int | str, str] = {}
+
+        config_output = self.send_command(f"show port {port_id} 
{rxtx.value}_offload configuration")
+        if verify:
+            if (
+                f"Rx Offloading Configuration of port {port_id}" not in 
config_output
+                and f"Tx Offloading Configuration of port {port_id}" not in 
config_output
+            ):
+                self._logger.debug(f"Get port offload config 
error\n{config_output}")
+                raise InteractiveCommandExecutionError(
+                    f"""Failed to get offload config on port 
{port_id}:\n{config_output}"""
+                )
+        # Actual output data starts on the third line
+        tempList: list[str] = config_output.splitlines()[3::]
+        returnDict["port"] = tempList[0]
+        for i in range(0, num_queues):
+            returnDict[i] = tempList[i + 1]
+        return returnDict
+
+    @requires_stopped_ports
+    def set_port_mbuf_fast_free(self, on: bool, verify: bool, port_id: int = 
0) -> None:
+        """Sets the mbuf_fast_free configuration for the Tx offload for a 
given port.
+
+        Args:
+            on: If :data:'True' mbuf_fast_free will be enabled, disable it 
otherwise.
+            verify: If :data:'True' the output of the command will be scanned 
in an attempt to
+                verify that the mbuf_fast_free was set successfully.
+            port_id: The port number to enable or disable mbuf_fast_free on.
+
+        Raises:
+            InteractiveCommandExecutionError: If mbuf_fast_free could not be 
set successfully
+        """
+        mbuf_output = self.send_command(
+            f"port config {port_id} tx_offload mbuf_fast_free {"on" if on else 
"off"}"
+        )
+
+        if "error" in mbuf_output and verify:
+            raise InteractiveCommandExecutionError(
+                f"""Unable to set mbuf_fast_free config on port 
{port_id}:\n{mbuf_output}"""
+            )
+
+    @requires_stopped_ports
+    def set_queue_mbuf_fast_free(
+        self,
+        on: bool,
+        verify: bool,
+        port_id: int = 0,
+        queue_id: int = 0,
+    ) -> None:
+        """Sets the Tx mbuf_fast_free configuration of the specified queue on 
a given port.
+
+        Args:
+            on: If :data:'True' the mbuf_fast_free configuration will be 
enabled, otherwise
+                disabled.
+            verify: If :data:'True' the output of the command will be scanned 
in an attempt to
+                verify that mbuf_fast_free was set successfully on all ports.
+            port_id: The ID of the port containing the queues.
+            queue_id: The queue to disable mbuf_fast_free on.
+
+        Raises:
+            InteractiveCommandExecutionError: If all queues could not be set 
successfully.
+        """
+        toggle = "on" if on else "off"
+        output = self.send_command(
+            f"port {port_id} txq {queue_id} tx_offload mbuf_fast_free {toggle}"
+        )
+        if verify:
+            if "Error" in output:
+                self._logger.debug(f"Set queue offload config error\n{output}")
+                raise InteractiveCommandExecutionError(
+                    f"Failed to get offload config on port {port_id}, queue 
{queue_id}:\n{output}"
+                )
+
+    def set_all_queues_mbuf_fast_free(
+        self,
+        on: bool,
+        verify: bool,
+        port_id=0,
+        num_queues: int = 0,
+    ) -> None:
+        """Sets mbuf_fast_free configuration for the Tx offload of all queues 
on a given port.
+
+        Args:
+            on: If :data:'True' the mbuf_fast_free configuration will be 
enabled, otherwise
+                disabled.
+            verify: If :data:'True' the output of the command will be scanned 
in an attempt to
+                verify that mbuf_fast_free was set successfully on all ports.
+            port_id: The ID of the port containing the queues.
+            num_queues: The amount of queues to disable mbuf_fast_free on.
+        """
+        for i in range(0, num_queues):
+            self.set_queue_mbuf_fast_free(on, verify, port_id=port_id, 
queue_id=i)
+
 
 class NicCapability(NoAliasEnum):
     """A mapping between capability names and the associated 
:class:`TestPmdShell` methods.
-- 
2.50.1

Reply via email to