[v3,1/1] dts: add methods for modifying MTU to testpmd shell

Message ID 20240905142123.31342-2-jspewock@iol.unh.edu (mailing list archive)
State Superseded
Delegated to: Juraj Linkeš
Headers
Series dts: allow for updating MTU with testpmd |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/loongarch-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/loongarch-unit-testing success Unit Testing PASS
ci/github-robot: build success github build: passed
ci/intel-Functional success Functional PASS
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS

Commit Message

Jeremy Spewock Sept. 5, 2024, 2:21 p.m. UTC
From: Jeremy Spewock <jspewock@iol.unh.edu>

There are methods within DTS currently that support updating the MTU of
ports on a node, but the methods for doing this in a linux session rely
on the ip command and the port being bound to the kernel driver. Since
test suites are run while bound to the driver for DPDK, there needs to
be a way to modify the value while bound to said driver as well. This is
done by using testpmd to modify the MTU.

Depends-on: patch-142952 ("dts: add ability to start/stop testpmd
ports")

Signed-off-by: Jeremy Spewock <jspewock@iol.unh.edu>
---
 dts/framework/remote_session/testpmd_shell.py | 45 +++++++++++++++++++
 1 file changed, 45 insertions(+)
  

Comments

Juraj Linkeš Sept. 6, 2024, 1:58 p.m. UTC | #1
> diff --git a/dts/framework/remote_session/testpmd_shell.py b/dts/framework/remote_session/testpmd_shell.py
> index ca24b28070..c1462ba2d3 100644
> --- a/dts/framework/remote_session/testpmd_shell.py
> +++ b/dts/framework/remote_session/testpmd_shell.py
> @@ -888,6 +888,51 @@ def show_port_stats(self, port_id: int) -> TestPmdPortStats:

> +    def set_port_mtu_all(self, mtu: int, verify: bool = True) -> None:
> +        """Change the MTU of all ports using testpmd.
> +
> +        Runs :meth:`set_port_mtu` for every port that testpmd is aware of.
> +
> +        Args:
> +            mtu: Desired value for the MTU to be set to.
> +            verify: Whether to verify that setting the MTU on each port was successful or not.
> +                Defaults to :data:`True`.
> +
> +        Raises:
> +            InteractiveCommandExecutionError: If `verify` is :data:`True` and the MTU was not
> +                properly updated on at least one port.
> +        """
> +        if self._app_params.ports is not None:

We should utilize the port info caching patch here:
https://patches.dpdk.org/project/dpdk/patch/20240823074137.13989-1-juraj.linkes@pantheon.tech/

Other than that, the patch looks good.

> +            for port_id in range(len(self._app_params.ports)):
> +                self.set_port_mtu(port_id, mtu, verify)
> +
>       def _close(self) -> None:
>           """Overrides :meth:`~.interactive_shell.close`."""
>           self.stop()
  
Jeremy Spewock Sept. 6, 2024, 2:28 p.m. UTC | #2
On Fri, Sep 6, 2024 at 9:58 AM Juraj Linkeš <juraj.linkes@pantheon.tech> wrote:
>
> > diff --git a/dts/framework/remote_session/testpmd_shell.py b/dts/framework/remote_session/testpmd_shell.py
> > index ca24b28070..c1462ba2d3 100644
> > --- a/dts/framework/remote_session/testpmd_shell.py
> > +++ b/dts/framework/remote_session/testpmd_shell.py
> > @@ -888,6 +888,51 @@ def show_port_stats(self, port_id: int) -> TestPmdPortStats:
>
> > +    def set_port_mtu_all(self, mtu: int, verify: bool = True) -> None:
> > +        """Change the MTU of all ports using testpmd.
> > +
> > +        Runs :meth:`set_port_mtu` for every port that testpmd is aware of.
> > +
> > +        Args:
> > +            mtu: Desired value for the MTU to be set to.
> > +            verify: Whether to verify that setting the MTU on each port was successful or not.
> > +                Defaults to :data:`True`.
> > +
> > +        Raises:
> > +            InteractiveCommandExecutionError: If `verify` is :data:`True` and the MTU was not
> > +                properly updated on at least one port.
> > +        """
> > +        if self._app_params.ports is not None:
>
> We should utilize the port info caching patch here:
> https://patches.dpdk.org/project/dpdk/patch/20240823074137.13989-1-juraj.linkes@pantheon.tech/
>
> Other than that, the patch looks good.
>

That's a good idea, I also like that it sort of detaches this method
from the subtle requirement that testpmd is started with an allow list
of ports. This requirement is enforced right now, but I think it makes
more sense for this method to operate based on what testpmd is aware
of anyway. It does add another patch to the dependency chain though,
we should probably prioritize getting the info caching patch into
next-dts.

> > +            for port_id in range(len(self._app_params.ports)):
> > +                self.set_port_mtu(port_id, mtu, verify)
> > +
> >       def _close(self) -> None:
> >           """Overrides :meth:`~.interactive_shell.close`."""
> >           self.stop()
>
  

Patch

diff --git a/dts/framework/remote_session/testpmd_shell.py b/dts/framework/remote_session/testpmd_shell.py
index ca24b28070..c1462ba2d3 100644
--- a/dts/framework/remote_session/testpmd_shell.py
+++ b/dts/framework/remote_session/testpmd_shell.py
@@ -888,6 +888,51 @@  def show_port_stats(self, port_id: int) -> TestPmdPortStats:
 
         return TestPmdPortStats.parse(output)
 
+    @requires_stopped_ports
+    def set_port_mtu(self, port_id: int, mtu: int, verify: bool = True) -> None:
+        """Change the MTU of a port using testpmd.
+
+        Some PMDs require that the port be stopped before changing the MTU, and it does no harm to
+        stop the port before configuring in cases where it isn't required, so ports are stopped
+        prior to changing their MTU.
+
+        Args:
+            port_id: ID of the port to adjust the MTU on.
+            mtu: Desired value for the MTU to be set to.
+            verify: If `verify` is :data:`True` then the output will be scanned in an attempt to
+                verify that the mtu was properly set on the port. Defaults to :data:`True`.
+
+        Raises:
+            InteractiveCommandExecutionError: If `verify` is :data:`True` and the MTU was not
+                properly updated on the port matching `port_id`.
+        """
+        set_mtu_output = self.send_command(f"port config mtu {port_id} {mtu}")
+        if verify and (f"MTU: {mtu}" not in self.send_command(f"show port info {port_id}")):
+            self._logger.debug(
+                f"Failed to set mtu to {mtu} on port {port_id}." f" Output was:\n{set_mtu_output}"
+            )
+            raise InteractiveCommandExecutionError(
+                f"Test pmd failed to update mtu of port {port_id} to {mtu}"
+            )
+
+    def set_port_mtu_all(self, mtu: int, verify: bool = True) -> None:
+        """Change the MTU of all ports using testpmd.
+
+        Runs :meth:`set_port_mtu` for every port that testpmd is aware of.
+
+        Args:
+            mtu: Desired value for the MTU to be set to.
+            verify: Whether to verify that setting the MTU on each port was successful or not.
+                Defaults to :data:`True`.
+
+        Raises:
+            InteractiveCommandExecutionError: If `verify` is :data:`True` and the MTU was not
+                properly updated on at least one port.
+        """
+        if self._app_params.ports is not None:
+            for port_id in range(len(self._app_params.ports)):
+                self.set_port_mtu(port_id, mtu, verify)
+
     def _close(self) -> None:
         """Overrides :meth:`~.interactive_shell.close`."""
         self.stop()