[PATCH v7 2/2] dts: add flow create/delete to testpmd shell
Dean Marx
dmarx at iol.unh.edu
Tue Jan 28 23:59:02 CET 2025
Add flow create/delete methods to TestPmdShell class
for initializing flow rules.
Signed-off-by: Dean Marx <dmarx at iol.unh.edu>
---
dts/framework/remote_session/testpmd_shell.py | 45 +++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/dts/framework/remote_session/testpmd_shell.py b/dts/framework/remote_session/testpmd_shell.py
index 3e86f52a7e..d58e4891b0 100644
--- a/dts/framework/remote_session/testpmd_shell.py
+++ b/dts/framework/remote_session/testpmd_shell.py
@@ -1910,6 +1910,51 @@ def csum_set_hw(
{port_id}:\n{csum_output}"""
)
+ def flow_create(self, flow_rule: FlowRule, port_id: int) -> int:
+ """Creates a flow rule in the testpmd session.
+
+ Args:
+ flow_rule: :class:`FlowRule` object used for creating testpmd flow rule.
+ port_id: Integer representing the port to use.
+ verify: If :data:`True`, the output of the command is scanned
+ to ensure the flow rule was created successfully.
+
+ Raises:
+ InteractiveCommandExecutionError: If flow rule is invalid.
+
+ Returns:
+ Id of created flow rule. Acts as implicit verification.
+ """
+ flow_output = self.send_command(f"flow create {port_id} {flow_rule}")
+ match = re.search(r"#(\d+)", flow_output)
+ if match is not None:
+ match_str = match.group(1)
+ flow_id = int(match_str)
+ return flow_id
+ else:
+ self._logger.debug(f"Failed to create flow rule:\n{flow_output}")
+ raise InteractiveCommandExecutionError(f"Failed to create flow rule:\n{flow_output}")
+
+ def flow_delete(self, flow_id: int, port_id: int, verify: bool = True) -> None:
+ """Deletes the specified flow rule from the testpmd session.
+
+ Args:
+ flow_id: ID of the flow to remove.
+ port_id: Integer representing the port to use.
+ verify: If :data:`True`, the output of the command is scanned
+ to ensure the flow rule was deleted successfully.
+
+ Raises:
+ InteractiveCommandExecutionError: If flow rule is invalid.
+ """
+ flow_output = self.send_command(f"flow destroy {port_id} rule {flow_id}")
+ if verify:
+ if "destroyed" not in flow_output:
+ self._logger.debug(f"Failed to delete flow rule:\n{flow_output}")
+ raise InteractiveCommandExecutionError(
+ f"Failed to delete flow rule:\n{flow_output}"
+ )
+
@requires_started_ports
@requires_stopped_ports
def set_port_mtu(self, port_id: int, mtu: int, verify: bool = True) -> None:
--
2.47.0
More information about the dev
mailing list