Skip to content

Commit

Permalink
dts: add flow create/delete to testpmd shell
Browse files Browse the repository at this point in the history
Add flow create/delete methods to TestPmdShell class
for initializing flow rules.

Signed-off-by: Dean Marx <[email protected]>
Reviewed-by: Luca Vizzarro <[email protected]>
  • Loading branch information
Dean Marx authored and paul-szczepanek-arm committed Feb 10, 2025
1 parent a4a5f89 commit 1f4fbb0
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions dts/framework/remote_session/testpmd_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -1950,6 +1950,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.
This command is implicitly verified as needed to return the created flow rule id.
Args:
flow_rule: :class:`FlowRule` object used for creating testpmd flow rule.
port_id: Integer representing the port to use.
Raises:
InteractiveCommandExecutionError: If flow rule is invalid.
Returns:
Id of created flow rule.
"""
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:
Expand Down

0 comments on commit 1f4fbb0

Please sign in to comment.