From patchwork Wed Jan 10 14:42:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Spewock X-Patchwork-Id: 135823 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 4790B43883; Wed, 10 Jan 2024 15:43:14 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C448E402DC; Wed, 10 Jan 2024 15:43:13 +0100 (CET) Received: from mail-vs1-f97.google.com (mail-vs1-f97.google.com [209.85.217.97]) by mails.dpdk.org (Postfix) with ESMTP id 51394402CC for ; Wed, 10 Jan 2024 15:43:12 +0100 (CET) Received: by mail-vs1-f97.google.com with SMTP id ada2fe7eead31-46788b25f95so945635137.0 for ; Wed, 10 Jan 2024 06:43:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1704897791; x=1705502591; 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=rKIkDZzDotgALxe7lIJpJHvWlgJD02jhLY1H0QLsNps=; b=EGOH2ICVpx2wV4wAfvUR2I4LP6RpJlzO/b8MFz8+T7HB/9VpyhnvryUQVEr1yLAK0h ez6Bnqy3DyPFnxO9XNzwJVmE1gibMHmDy/0qOgH+ZVOdtHJopFFiPVPfQJOKMXgoNWs5 h9WTdf11CDH+fhO+jZA6ZQmtwBt6rPKShMMi0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704897791; x=1705502591; 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=rKIkDZzDotgALxe7lIJpJHvWlgJD02jhLY1H0QLsNps=; b=B1O1FCHM5fzpzUUXvpOHZLl/daBO+wqcd1Kxb2W05QmdkY4c9kpi3h//PKvoQ7Ioft eO/3ZXVyUt09JxKAx8RDmNMCIQhXvMywi4oFvNsdAfvbsjQ74fF4U3AoW7Ijqo/kvgEt wQqTeHrkhAc1OG06yd1FS75NQE49ntPeL7h3QHyQEVC2HCNKXF18SPwJW5oGwPV2gld2 0XXkYKD5Pt7V9oSiPqgM5MgXxwU47kdQU7g7J4nlFM/3gQmd3Tw3ES9+AjXJP1gCrQQu Zzgqa/3hFNbZjWUkdMgNKr7f4ZfrzycoHB3GtmT0DCYqhgtnIVwO6exGqiJa0ntiCZ1h utSw== X-Gm-Message-State: AOJu0YyF/40J2Ak4etHzYqrReoW2O7bbWGOIvKdssBZWYDp23WSS71Hb 3a0tVJBJY5drv/Ss7I+WkLSrdl/1OomR1aJ+EDHTGxE40So3KxNGCAUa6pnZ+7Qf+K7w8XoOZw= = X-Google-Smtp-Source: AGHT+IG3EGsb1boMYh8cY7Ktr7VDEP0WDEIk5tlRqlb+3d085QjtZsCWlTJ3YTk6Q+rRicjprOV9Q0MIFVyG X-Received: by 2002:a05:6102:5043:b0:466:fc2c:3cac with SMTP id by3-20020a056102504300b00466fc2c3cacmr781077vsb.67.1704897791013; Wed, 10 Jan 2024 06:43:11 -0800 (PST) Received: from postal.iol.unh.edu (postal.iol.unh.edu. [2606:4100:3880:1234::84]) by smtp-relay.gmail.com with ESMTPS id c12-20020a9f3e4c000000b007cc705bbad0sm166956uaj.0.2024.01.10.06.43.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Jan 2024 06:43:11 -0800 (PST) X-Relaying-Domain: iol.unh.edu Received: from iol.unh.edu (unknown [IPv6:2606:4100:3880:1257::1083]) by postal.iol.unh.edu (Postfix) with ESMTP id 4CDD26043481; Wed, 10 Jan 2024 09:43:10 -0500 (EST) 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, lylavoie@iol.unh.edu, ferruh.yigit@amd.com, andrew.rybchenko@oktetlabs.ru Cc: dev@dpdk.org, Jeremy Spewock Subject: [PATCH v8 1/7] dts: add startup verification and forwarding modes to testpmd shell Date: Wed, 10 Jan 2024 09:42:43 -0500 Message-ID: <20240110144249.20719-2-jspewock@iol.unh.edu> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240110144249.20719-1-jspewock@iol.unh.edu> References: <20240109153633.766-1-jspewock@iol.unh.edu> <20240110144249.20719-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()