dts: add multicast set function to shell

Message ID 20240708190858.26583-2-dmarx@iol.unh.edu (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series dts: add multicast set function to shell |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS

Commit Message

Dean Marx July 8, 2024, 7:08 p.m. UTC
added set multicast function for changing allmulticast mode within testpmd.

Signed-off-by: Dean Marx <dmarx@iol.unh.edu>
---
 dts/framework/remote_session/testpmd_shell.py | 46 +++++++++++++++++++
 1 file changed, 46 insertions(+)
  

Comments

Luca Vizzarro Aug. 1, 2024, 12:34 p.m. UTC | #1
Hi Dean, thank you for your work.

On 08/07/2024 20:08, Dean Marx wrote:
> +    def set_multicast_all(self, on: bool, verify: bool = True):
> +        """Turns multicast mode on/off for the specified port.
> +
> +        Args:
> +            on: If :data:`True`, turns multicast mode on, otherwise turns off.
> +            verify: If :data:`True` an additional command will be sent to verify
> +            that multicast mode is properly set. Defaults to :data:`True`.
> +
> +        Raises:
> +            InteractiveCommandExecutionError: If `verify` is :data:`True` and multicast
> +                mode is not properly set.
> +        """
> +        multicast_output = self.send_command(f"set allmulti all {'on' if on else 'off'}")
> +        if verify:
> +            stats0 = self.show_port_info(port_id=0)
> +            stats1 = self.show_port_info(port_id=1)
This assumes that we have port 0 and 1, but *technically* we shouldn't 
be making assumptions about the environment in the framework. I'd rather 
use show_port_info_all and sample from there what's available.
> +            if on ^ (stats0.is_allmulticast_mode_enabled and stats1.is_allmulticast_mode_enabled):
> +                self._logger.debug(
> +                    f"Failed to set multicast mode on all ports.: \n{multicast_output}"
> +                )
> +                raise InteractiveCommandExecutionError(
> +                    "Testpmd failed to set multicast mode on all ports."
> +                )
  

Patch

diff --git a/dts/framework/remote_session/testpmd_shell.py b/dts/framework/remote_session/testpmd_shell.py
index ec22f72221..a0be0bd09d 100644
--- a/dts/framework/remote_session/testpmd_shell.py
+++ b/dts/framework/remote_session/testpmd_shell.py
@@ -806,6 +806,52 @@  def show_port_stats(self, port_id: int) -> TestPmdPortStats:
 
         return TestPmdPortStats.parse(output)
 
+    def set_promisc(self, port: int, on: bool, verify: bool = True):
+        """Turns promiscuous mode on/off for the specified port.
+
+        Args:
+            port: Port number to use, should be within 0-32.
+            on: If :data:`True`, turn promisc mode on, otherwise turn off.
+            verify: If :data:`True` an additional command will be sent to verify that promisc mode
+                is properly set. Defaults to :data:`True`.
+
+        Raises:
+            InteractiveCommandExecutionError: If `verify` is :data:`True` and promisc mode
+                is not correctly set.
+        """
+        promisc_output = self.send_command(f"set promisc {port} {'on' if on else 'off'}")
+        if verify:
+            stats = self.show_port_info(port_id=port)
+            if on ^ stats.is_promiscuous_mode_enabled:
+                self._logger.debug(f"Failed to set promisc mode on port {port}: \n{promisc_output}")
+                raise InteractiveCommandExecutionError(
+                    f"Testpmd failed to set promisc mode on port {port}."
+                )
+
+    def set_multicast_all(self, on: bool, verify: bool = True):
+        """Turns multicast mode on/off for the specified port.
+
+        Args:
+            on: If :data:`True`, turns multicast mode on, otherwise turns off.
+            verify: If :data:`True` an additional command will be sent to verify
+            that multicast mode is properly set. Defaults to :data:`True`.
+
+        Raises:
+            InteractiveCommandExecutionError: If `verify` is :data:`True` and multicast
+                mode is not properly set.
+        """
+        multicast_output = self.send_command(f"set allmulti all {'on' if on else 'off'}")
+        if verify:
+            stats0 = self.show_port_info(port_id=0)
+            stats1 = self.show_port_info(port_id=1)
+            if on ^ (stats0.is_allmulticast_mode_enabled and stats1.is_allmulticast_mode_enabled):
+                self._logger.debug(
+                    f"Failed to set multicast mode on all ports.: \n{multicast_output}"
+                )
+                raise InteractiveCommandExecutionError(
+                    "Testpmd failed to set multicast mode on all ports."
+                )
+
     def close(self) -> None:
         """Overrides :meth:`~.interactive_shell.close`."""
         self.send_command("quit", "")