summaryrefslogtreecommitdiff
path: root/dts/framework/remote_session/testpmd_shell.py
diff options
context:
space:
mode:
authorLuca Vizzarro <[email protected]>2024-06-06 22:34:20 +0100
committerThomas Monjalon <[email protected]>2024-06-20 05:02:45 +0200
commit53eacf3d71f011d7c7ae9f154c5c40f8b12c1b17 (patch)
tree691dfbe77cbe3e068c7792aaf844eb609d69eb43 /dts/framework/remote_session/testpmd_shell.py
parent61d5bc9bf974d5f379ec64b1ab9d0b609b659171 (diff)
dts: add port stats command to testpmd shell
Add a new TestPmdPortStats data structure to represent the output returned by `show port stats`, which is implemented as part of TestPmdShell. Bugzilla ID: 1407 Signed-off-by: Luca Vizzarro <[email protected]> Reviewed-by: Paul Szczepanek <[email protected]> Reviewed-by: Juraj Linkeš <[email protected]> Reviewed-by: Jeremy Spewock <[email protected]> Reviewed-by: Nicholas Pratte <[email protected]> Tested-by: Nicholas Pratte <[email protected]>
Diffstat (limited to 'dts/framework/remote_session/testpmd_shell.py')
-rw-r--r--dts/framework/remote_session/testpmd_shell.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/dts/framework/remote_session/testpmd_shell.py b/dts/framework/remote_session/testpmd_shell.py
index 3357386643..b4b425db39 100644
--- a/dts/framework/remote_session/testpmd_shell.py
+++ b/dts/framework/remote_session/testpmd_shell.py
@@ -571,6 +571,42 @@ class TestPmdPort(TextParser):
)
+@dataclass
+class TestPmdPortStats(TextParser):
+ """Port statistics."""
+
+ #:
+ port_id: int = field(metadata=TextParser.find_int(r"NIC statistics for port (\d+)"))
+
+ #:
+ rx_packets: int = field(metadata=TextParser.find_int(r"RX-packets:\s+(\d+)"))
+ #:
+ rx_missed: int = field(metadata=TextParser.find_int(r"RX-missed:\s+(\d+)"))
+ #:
+ rx_bytes: int = field(metadata=TextParser.find_int(r"RX-bytes:\s+(\d+)"))
+ #:
+ rx_errors: int = field(metadata=TextParser.find_int(r"RX-errors:\s+(\d+)"))
+ #:
+ rx_nombuf: int = field(metadata=TextParser.find_int(r"RX-nombuf:\s+(\d+)"))
+
+ #:
+ tx_packets: int = field(metadata=TextParser.find_int(r"TX-packets:\s+(\d+)"))
+ #:
+ tx_errors: int = field(metadata=TextParser.find_int(r"TX-errors:\s+(\d+)"))
+ #:
+ tx_bytes: int = field(metadata=TextParser.find_int(r"TX-bytes:\s+(\d+)"))
+
+ #:
+ rx_pps: int = field(metadata=TextParser.find_int(r"Rx-pps:\s+(\d+)"))
+ #:
+ rx_bps: int = field(metadata=TextParser.find_int(r"Rx-bps:\s+(\d+)"))
+
+ #:
+ tx_pps: int = field(metadata=TextParser.find_int(r"Tx-pps:\s+(\d+)"))
+ #:
+ tx_bps: int = field(metadata=TextParser.find_int(r"Tx-bps:\s+(\d+)"))
+
+
class TestPmdShell(InteractiveShell):
"""Testpmd interactive shell.
@@ -760,6 +796,45 @@ class TestPmdShell(InteractiveShell):
return TestPmdPort.parse(output)
+ def show_port_stats_all(self) -> list[TestPmdPortStats]:
+ """Returns the statistics of all the ports.
+
+ Returns:
+ list[TestPmdPortStats]: A list containing all the ports stats as `TestPmdPortStats`.
+ """
+ output = self.send_command("show port stats all")
+
+ # Sample output of the "all" command looks like:
+ #
+ # ########### NIC statistics for port 0 ###########
+ # values...
+ # #################################################
+ #
+ # ########### NIC statistics for port 1 ###########
+ # values...
+ # #################################################
+ #
+ iter = re.finditer(r"(^ #*.+#*$[^#]+)^ #*\r$", output, re.MULTILINE)
+ return [TestPmdPortStats.parse(block.group(1)) for block in iter]
+
+ def show_port_stats(self, port_id: int) -> TestPmdPortStats:
+ """Returns the given port statistics.
+
+ Args:
+ port_id: The port ID to gather information for.
+
+ Raises:
+ InteractiveCommandExecutionError: If `port_id` is invalid.
+
+ Returns:
+ TestPmdPortStats: An instance of `TestPmdPortStats` containing the given port's stats.
+ """
+ output = self.send_command(f"show port stats {port_id}", skip_first_line=True)
+ if output.startswith("Invalid port"):
+ raise InteractiveCommandExecutionError("invalid port given")
+
+ return TestPmdPortStats.parse(output)
+
def close(self) -> None:
"""Overrides :meth:`~.interactive_shell.close`."""
self.send_command("quit", "")