From patchwork Mon Mar 11 15:43:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Spewock X-Patchwork-Id: 138159 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 89B1543C89; Mon, 11 Mar 2024 16:44:56 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 46D5740A87; Mon, 11 Mar 2024 16:44:54 +0100 (CET) Received: from mail-pj1-f100.google.com (mail-pj1-f100.google.com [209.85.216.100]) by mails.dpdk.org (Postfix) with ESMTP id 6381040A87 for ; Mon, 11 Mar 2024 16:44:53 +0100 (CET) Received: by mail-pj1-f100.google.com with SMTP id 98e67ed59e1d1-29bbff1505dso1341254a91.0 for ; Mon, 11 Mar 2024 08:44:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1710171892; x=1710776692; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=azS1COg8qyO8b0ezY6bm30EXaPEL2CnFBabHOARvho4=; b=EUVYXhZm0e3q9InBlVdBwNKAbKyqnHUvcceQClyzTbdIlocaj/RO0uyNo5KO/hEI87 I3sw6o2fyfwamYe4qBEDmhKZookszcIT8NMooXQ0/+2mbOLP76v/ajJY3/5mj2AE/Zjh 4zVZom8BiA7lXbQwTZtmRQ++lR0UwBSgN2J7I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710171892; x=1710776692; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=azS1COg8qyO8b0ezY6bm30EXaPEL2CnFBabHOARvho4=; b=rlRDk5r3mjw3AeTkI1taMBzGg1+FEmLssueFCJ893CKLKQJOAoE+mSCX5PH9QQaFxU fONRFEyR6WcNuVms3FkpVO0smM/2xm3sJgM6H5SN5VX6sARWXuYBEWIA5Ie2/CnQRkF2 ga7VSq+hQsSDmWRIz/3U4UbDJuMBFFTtA6QKIqnzphze2bdxbbZbj+pLs1eQCAf9fW/k CGPtN+o4YT4Nhb0eyc8MaHZQyQRVh9r7hXfiqeYfPXJ4YuAIhzaGNjYA7Olg3n4b8Dn1 JrIXaxPEHk/EWzJlNeUlx5cp16wHdFmoEX22GgjUA3MNRgFOBoDGYsPCxKQugsAyjsAP x0jA== X-Gm-Message-State: AOJu0YyE1viU+a2HnX/JsUWEKuhZedaO+oPv9iXX/Walw8bzgX3SQbO5 PZqNsR551R73Pu8C58sR5axkgQU26i4NBTCk8FBGLQfHI78bE0JRgnHCqNMHLn9WbyKV80KKYSO qgD6bu0GKqOd1Y96OZ9Vhryd9u3RVMieeiEQRmB7b+OemFr8h X-Google-Smtp-Source: AGHT+IFq6SIPzx938h5YwR9GcH1Pux9Or8rMbBUBMw4K9Lx1nUnvVbPiFOSsIuWtjgW30f6zr9OqEojql4+5 X-Received: by 2002:a17:90a:f417:b0:299:a69:1f8b with SMTP id ch23-20020a17090af41700b002990a691f8bmr4884355pjb.23.1710171892577; Mon, 11 Mar 2024 08:44:52 -0700 (PDT) Received: from postal.iol.unh.edu (postal.iol.unh.edu. [2606:4100:3880:1234::84]) by smtp-relay.gmail.com with ESMTPS id w12-20020a17090ad60c00b0029b47c6149csm458647pju.6.2024.03.11.08.44.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Mar 2024 08:44:52 -0700 (PDT) X-Relaying-Domain: iol.unh.edu Received: from iol.unh.edu (unknown [IPv6:2606:4100:3880:1271:90f9:1b64:f6e6:867f]) by postal.iol.unh.edu (Postfix) with ESMTP id A32876052471; Mon, 11 Mar 2024 11:44:51 -0400 (EDT) From: jspewock@iol.unh.edu To: Honnappa.Nagarahalli@arm.com, juraj.linkes@pantheon.tech, thomas@monjalon.net, wathsala.vithanage@arm.com, probb@iol.unh.edu, paul.szczepanek@arm.com, yoan.picchi@foss.arm.com, ferruh.yigit@amd.com, andrew.rybchenko@oktetlabs.ru Cc: dev@dpdk.org, Jeremy Spewock Subject: [PATCH v9 1/7] dts: add startup verification and forwarding modes to testpmd shell Date: Mon, 11 Mar 2024 11:43:59 -0400 Message-ID: <20240311154405.13269-2-jspewock@iol.unh.edu> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240311154405.13269-1-jspewock@iol.unh.edu> References: <20240110144249.20719-1-jspewock@iol.unh.edu> <20240311154405.13269-1-jspewock@iol.unh.edu> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Jeremy Spewock Added commonly used methods in testpmd such as starting and stopping packet forwarding, changing forward modes, and verifying link status of ports so that developers can configure testpmd and start forwarding through the provided class rather than sending commands to the testpmd session directly. Signed-off-by: Jeremy Spewock --- dts/framework/exception.py | 7 + dts/framework/remote_session/testpmd_shell.py | 149 +++++++++++++++++- 2 files changed, 155 insertions(+), 1 deletion(-) diff --git a/dts/framework/exception.py b/dts/framework/exception.py index 658eee2c38..cce1e0231a 100644 --- a/dts/framework/exception.py +++ b/dts/framework/exception.py @@ -146,6 +146,13 @@ def __str__(self) -> str: return f"Command {self.command} returned a non-zero exit code: {self._command_return_code}" +class InteractiveCommandExecutionError(DTSError): + """An unsuccessful execution of a remote command in an interactive environment.""" + + #: + severity: ClassVar[ErrorSeverity] = ErrorSeverity.REMOTE_CMD_EXEC_ERR + + class RemoteDirectoryExistsError(DTSError): """A directory that exists on a remote node.""" diff --git a/dts/framework/remote_session/testpmd_shell.py b/dts/framework/remote_session/testpmd_shell.py index 0184cc2e71..3a66907394 100644 --- a/dts/framework/remote_session/testpmd_shell.py +++ b/dts/framework/remote_session/testpmd_shell.py @@ -15,9 +15,15 @@ testpmd_shell.close() """ +import time +from enum import auto from pathlib import PurePath from typing import Callable, ClassVar +from framework.exception import InteractiveCommandExecutionError +from framework.settings import SETTINGS +from framework.utils import StrEnum + from .interactive_shell import InteractiveShell @@ -43,14 +49,51 @@ def __str__(self) -> str: return self.pci_address +class TestPmdForwardingModes(StrEnum): + r"""The supported packet forwarding modes for :class:`~TestPmdShell`\s.""" + + #: + io = auto() + #: + mac = auto() + #: + macswap = auto() + #: + flowgen = auto() + #: + rxonly = auto() + #: + txonly = auto() + #: + csum = auto() + #: + icmpecho = auto() + #: + ieee1588 = auto() + #: + noisy = auto() + #: + fivetswap = "5tswap" + #: + shared_rxq = "shared-rxq" + #: + recycle_mbufs = auto() + + class TestPmdShell(InteractiveShell): """Testpmd interactive shell. The testpmd shell users should never use the :meth:`~.interactive_shell.InteractiveShell.send_command` method directly, but rather call specialized methods. If there isn't one that satisfies a need, it should be added. + + Attributes: + number_of_ports: The number of ports which were allowed on the command-line when testpmd + was started. """ + number_of_ports: int + #: The path to the testpmd executable. path: ClassVar[PurePath] = PurePath("app", "dpdk-testpmd") @@ -65,9 +108,66 @@ class TestPmdShell(InteractiveShell): _command_extra_chars: ClassVar[str] = "\n" def _start_application(self, get_privileged_command: Callable[[str], str] | None) -> None: - self._app_args += " -- -i" + """Overrides :meth:`~.interactive_shell._start_application`. + + Add flags for starting testpmd in interactive mode and disabling messages for link state + change events before starting the application. Link state is verified before starting + packet forwarding and the messages create unexpected newlines in the terminal which + complicates output collection. + + Also find the number of pci addresses which were allowed on the command line when the app + was started. + """ + self._app_args += " -- -i --mask-event intr_lsc" + self.number_of_ports = self._app_args.count("-a ") super()._start_application(get_privileged_command) + def start(self, verify: bool = True) -> None: + """Start packet forwarding with the current configuration. + + Args: + verify: If :data:`True` , a second start command will be sent in an attempt to verify + packet forwarding started as expected. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and forwarding fails to + start or ports fail to come up. + """ + self.send_command("start") + if verify: + # If forwarding was already started, sending "start" again should tell us + start_cmd_output = self.send_command("start") + if "Packet forwarding already started" not in start_cmd_output: + self._logger.debug(f"Failed to start packet forwarding: \n{start_cmd_output}") + raise InteractiveCommandExecutionError("Testpmd failed to start packet forwarding.") + + for port_id in range(self.number_of_ports): + if not self.wait_link_status_up(port_id): + raise InteractiveCommandExecutionError( + "Not all ports came up after starting packet forwarding in testpmd." + ) + + def stop(self, verify: bool = True) -> None: + """Stop packet forwarding. + + Args: + verify: If :data:`True` , the output of the stop command is scanned to verify that + forwarding was stopped successfully or not started. If neither is found, it is + considered an error. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and the command to stop + forwarding results in an error. + """ + stop_cmd_output = self.send_command("stop") + if verify: + if ( + "Done." not in stop_cmd_output + and "Packet forwarding not started" not in stop_cmd_output + ): + self._logger.debug(f"Failed to stop packet forwarding: \n{stop_cmd_output}") + raise InteractiveCommandExecutionError("Testpmd failed to stop packet forwarding.") + def get_devices(self) -> list[TestPmdDevice]: """Get a list of device names that are known to testpmd. @@ -82,3 +182,50 @@ def get_devices(self) -> list[TestPmdDevice]: if "device name:" in line.lower(): dev_list.append(TestPmdDevice(line)) return dev_list + + def wait_link_status_up(self, port_id: int, timeout=SETTINGS.timeout) -> bool: + """Wait until the link status on the given port is "up". + + Arguments: + port_id: Port to check the link status on. + timeout: Time to wait for the link to come up. The default value for this + argument may be modified using the :option:`--timeout` command-line argument + or the :envvar:`DTS_TIMEOUT` environment variable. + + Returns: + Whether the link came up in time or not. + """ + time_to_stop = time.time() + timeout + port_info: str = "" + while time.time() < time_to_stop: + port_info = self.send_command(f"show port info {port_id}") + if "Link status: up" in port_info: + break + time.sleep(0.5) + else: + self._logger.error(f"The link for port {port_id} did not come up in the given timeout.") + return "Link status: up" in port_info + + def set_forward_mode(self, mode: TestPmdForwardingModes, verify: bool = True): + """Set packet forwarding mode. + + Args: + mode: The forwarding mode to use. + verify: If :data:`True` the output of the command will be scanned in an attempt to + verify that the forwarding mode was set to `mode` properly. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and the forwarding mode + fails to update. + """ + set_fwd_output = self.send_command(f"set fwd {mode.value}") + if f"Set {mode.value} packet forwarding mode" not in set_fwd_output: + self._logger.debug(f"Failed to set fwd mode to {mode.value}:\n{set_fwd_output}") + raise InteractiveCommandExecutionError( + f"Test pmd failed to set fwd mode to {mode.value}" + ) + + def close(self) -> None: + """Overrides :meth:`~.interactive_shell.close`.""" + self.send_command("quit", "") + return super().close()