Skip to content

Commit e67bc74

Browse files
Alex ChapmanPatrickRobbIOL
authored andcommitted
dts: add RSS functions to testpmd
This patch adds the required functionality for the RSS key_update, RETA, and hash test suites. This includes: The setting of custom RETA values for routing packets to specific queues. The setting of the RSS mode on all ports, to specify how to hash the packets. The updating of the RSS hash key used during the hashing process. Alongside this, there is the addition of a __str__ method to the RSSOffloadTypesFlags class, so that when flag names are cast to a string they will use '-' as separators, instead of '_'. This allows them to be directly used within testpmd RSS commands without any further changes. Depends-on: series-36111 ("Split DTS framework and public API") Signed-off-by: Alex Chapman <[email protected]> Signed-off-by: Thomas Wilks <[email protected]> Reviewed-by: Paul Szczepanek <[email protected]> Reviewed-by: Luca Vizzarro <[email protected]> Reviewed-by: Patrick Robb <[email protected]> Tested-by: Patrick Robb <[email protected]>
1 parent 95393d6 commit e67bc74

File tree

2 files changed

+98
-5
lines changed

2 files changed

+98
-5
lines changed

dts/api/testpmd/__init__.py

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
ChecksumOffloadOptions,
3838
DeviceCapabilitiesFlag,
3939
FlowRule,
40+
RSSOffloadTypesFlag,
4041
RxOffloadCapabilities,
4142
RxOffloadCapability,
4243
RxOffloadConfiguration,
@@ -369,6 +370,82 @@ def close_all_ports(self, verify: bool = True) -> None:
369370
if not all(f"Port {p_id} is closed" in port_close_output for p_id in range(num_ports)):
370371
raise InteractiveCommandExecutionError("Ports were not closed successfully.")
371372

373+
def port_config_rss_reta(
374+
self, port_id: int, hash_index: int, queue_id: int, verify: bool = True
375+
) -> None:
376+
"""Configure a port's RSS redirection table.
377+
378+
Args:
379+
port_id: The port where the redirection table will be configured.
380+
hash_index: The index into the redirection table associated with the destination queue.
381+
queue_id: The destination queue of the packet.
382+
verify: If :data:`True`, verifies if a port's redirection table
383+
was correctly configured.
384+
385+
Raises:
386+
InteractiveCommandExecutionError: If `verify` is :data:`True`
387+
Testpmd failed to config RSS reta.
388+
"""
389+
out = self.send_command(f"port config {port_id} rss reta ({hash_index},{queue_id})")
390+
if verify:
391+
if f"The reta size of port {port_id} is" not in out:
392+
self._logger.debug(f"Failed to config RSS reta: \n{out}")
393+
raise InteractiveCommandExecutionError("Testpmd failed to config RSS reta.")
394+
395+
def port_config_all_rss_offload_type(
396+
self, flag: RSSOffloadTypesFlag, verify: bool = True
397+
) -> None:
398+
"""Set the RSS mode on all ports.
399+
400+
Args:
401+
flag: The RSS iptype all ports will be configured to.
402+
verify: If :data:`True`, it verifies if all ports RSS offload type
403+
was correctly configured.
404+
405+
Raises:
406+
InteractiveCommandExecutionError: If `verify` is :data:`True`
407+
Testpmd failed to config the RSS mode on all ports.
408+
"""
409+
out = self.send_command(f"port config all rss {flag.name}")
410+
if verify:
411+
if "error" in out:
412+
self._logger.debug(f"Failed to config the RSS mode on all ports: \n{out}")
413+
raise InteractiveCommandExecutionError(
414+
f"Testpmd failed to change RSS mode to {flag.name}"
415+
)
416+
417+
def port_config_rss_hash_key(
418+
self,
419+
port_id: int,
420+
offload_type: RSSOffloadTypesFlag,
421+
hex_str: str,
422+
verify: bool = True,
423+
) -> str:
424+
"""Sets the RSS hash key for the specified port.
425+
426+
Args:
427+
port_id: The port that will have the hash key applied to.
428+
offload_type: The offload type the hash key will be applied to.
429+
hex_str: The hash key to set.
430+
verify: If :data:`True`, verify that RSS has the key.
431+
432+
Raises:
433+
InteractiveCommandExecutionError: If `verify` is :data:`True`
434+
Testpmd failed to set the RSS hash key.
435+
"""
436+
output = self.send_command(
437+
f"port config {port_id} rss-hash-key {offload_type} {hex_str}",
438+
skip_first_line=True,
439+
)
440+
441+
if verify:
442+
if output.strip():
443+
self._logger.debug(f"Failed to set rss hash key: \n{output}")
444+
raise InteractiveCommandExecutionError(
445+
f"Testpmd failed to set {hex_str} on {port_id} with a flag of {offload_type}."
446+
)
447+
return output
448+
372449
def show_port_info_all(self) -> list[TestPmdPort]:
373450
"""Returns the information of all the ports.
374451
@@ -587,22 +664,30 @@ def csum_set_hw(
587664
{port_id}:\n{csum_output}"""
588665
)
589666

590-
def flow_create(self, flow_rule: FlowRule, port_id: int) -> int:
667+
def flow_create(self, flow_rule: FlowRule, port_id: int, verify: bool = True) -> int:
591668
"""Creates a flow rule in the testpmd session.
592669
593670
This command is implicitly verified as needed to return the created flow rule id.
594671
595672
Args:
596673
flow_rule: :class:`FlowRule` object used for creating testpmd flow rule.
597674
port_id: Integer representing the port to use.
675+
verify: If :data:`True`, the output of the command is scanned
676+
to ensure the flow rule was created successfully.
598677
599678
Raises:
600679
InteractiveCommandExecutionError: If flow rule is invalid.
601680
602681
Returns:
603-
Id of created flow rule.
682+
Id of created flow rule as an integer.
604683
"""
605684
flow_output = self.send_command(f"flow create {port_id} {flow_rule}")
685+
if verify:
686+
if "created" not in flow_output:
687+
self._logger.debug(f"Failed to create flow rule:\n{flow_output}")
688+
raise InteractiveCommandExecutionError(
689+
f"Failed to create flow rule:\n{flow_output}"
690+
)
606691
match = re.search(r"#(\d+)", flow_output)
607692
if match is not None:
608693
match_str = match.group(1)
@@ -631,7 +716,7 @@ def flow_delete(self, flow_id: int, port_id: int, verify: bool = True) -> None:
631716
"""Deletes the specified flow rule from the testpmd session.
632717
633718
Args:
634-
flow_id: ID of the flow to remove.
719+
flow_id: :class:`FlowRule` id used for deleting testpmd flow rule.
635720
port_id: Integer representing the port to use.
636721
verify: If :data:`True`, the output of the command is scanned
637722
to ensure the flow rule was deleted successfully.

dts/api/testpmd/types.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,12 @@ def make_parser(cls) -> ParserFn:
309309
RSSOffloadTypesFlag.from_list_string,
310310
)
311311

312+
def __str__(self):
313+
"""Replaces underscores with hyphens to produce valid testpmd value."""
314+
if self.name is None:
315+
return ""
316+
return self.name.replace("_", "-")
317+
312318

313319
class DeviceCapabilitiesFlag(Flag):
314320
"""Flag representing the device capabilities."""
@@ -614,11 +620,13 @@ def _validate(info: str) -> str | None:
614620
)
615621
#: Maximum number of VFs
616622
max_vfs_num: int | None = field(
617-
default=None, metadata=TextParser.find_int(r"Maximum number of VFs: (\d+)")
623+
default=None,
624+
metadata=TextParser.find_int(r"Maximum number of VFs: (\d+)"),
618625
)
619626
#: Maximum number of VMDq pools
620627
max_vmdq_pools_num: int | None = field(
621-
default=None, metadata=TextParser.find_int(r"Maximum number of VMDq pools: (\d+)")
628+
default=None,
629+
metadata=TextParser.find_int(r"Maximum number of VMDq pools: (\d+)"),
622630
)
623631

624632
#:

0 commit comments

Comments
 (0)