From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1B92B44164; Wed, 5 Jun 2024 23:32:49 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E951D40E5E; Wed, 5 Jun 2024 23:32:36 +0200 (CEST) Received: from mail-pf1-f225.google.com (mail-pf1-f225.google.com [209.85.210.225]) by mails.dpdk.org (Postfix) with ESMTP id 4673A40DDA for ; Wed, 5 Jun 2024 23:32:34 +0200 (CEST) Received: by mail-pf1-f225.google.com with SMTP id d2e1a72fcca58-70264bcb631so213293b3a.2 for ; Wed, 05 Jun 2024 14:32:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1717623153; x=1718227953; 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=8InlCOuNxtL+MQsHquxxw2B5vJk4y2Hk5HfJx4Gr8I8=; b=GVGVlO9wL6uyknWXo9k7iRjPgBPeYklGRWLXTtZouAG8BugKmSx5+O1fRpQWw9ZEyA jSDsqb0tastIkJgpIUpL7r2lBRrIXPPgFQ7OWV/+MI2jlDOGrj0vbAyw4wtX6OLnGh1a jSMh1C4xLBDrFvGnHrfETeW+0b4ZtM181s7Es= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717623153; x=1718227953; 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=8InlCOuNxtL+MQsHquxxw2B5vJk4y2Hk5HfJx4Gr8I8=; b=dJZ49AJ6bowZ4m/GkxInU0YCx69dgirv/QWX2ro/Zof/5tLSX0bPjB2YHzTb6Mo9C5 plbgrI9iyUdDFYk44f0zXald3Vj5c2ZaGVBd1VAZUlORbJshi303W/g2Wl2TePniGYaV zorRniaXmipmivvw6xyC91CZaZ/nLwsNtKKvrSD9RmbaFJr5e5YYQtnApwNN//JgihTE JltkQ7mTgeG/F2MBfQ+vlHJ1EtWCtID1lu35BroYIuNCixOqOcm+DCGoDXSnOag6O5Pc AZIBzhrEThqcRqcZYBZTGoZVgr7hmHHACJWkHFJL3xlVONBac0oMQiiJAeTV5x9L7rrp Zdwg== X-Gm-Message-State: AOJu0Ywd/cmGRrl/496W8sXtIt7GwuYbXVoMUGLSPc7qNoM8xZZEPH3U 9CcwtU+U0wtnjSmlwThwxJbtdUoKtI9GSa3bvBZJk3Rcam+IHbsaEbM5YSPk+Q4r/IHuNKnmSEk ST7+lvqFiRQ0PnwnX4cp7PaZrXQzQQc0Ov9N0js8bKoq6siKv X-Google-Smtp-Source: AGHT+IH6UEBpeOdgDlNfXWyRuZI74K5SGIlLzxxdJLMzO5XuBF9IpAvA2IdqPj1Q53Kt3qhUhn0XzLD1iPiz X-Received: by 2002:a05:6a00:cca:b0:6f6:7bf1:72cd with SMTP id d2e1a72fcca58-703e596aecemr3807647b3a.11.1717623153458; Wed, 05 Jun 2024 14:32:33 -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 41be03b00d2f7-6de20a1cdf5sm449a12.9.2024.06.05.14.32.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Jun 2024 14:32:33 -0700 (PDT) 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 36D47605C381; Wed, 5 Jun 2024 17:32:32 -0400 (EDT) From: jspewock@iol.unh.edu To: Honnappa.Nagarahalli@arm.com, probb@iol.unh.edu, paul.szczepanek@arm.com, juraj.linkes@pantheon.tech, thomas@monjalon.net, wathsala.vithanage@arm.com, npratte@iol.unh.edu, yoan.picchi@foss.arm.com, Luca.Vizzarro@arm.com Cc: dev@dpdk.org, Jeremy Spewock Subject: [PATCH v3 3/4] dts: add methods for modifying MTU to testpmd shell Date: Wed, 5 Jun 2024 17:31:47 -0400 Message-ID: <20240605213148.21371-4-jspewock@iol.unh.edu> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240605213148.21371-1-jspewock@iol.unh.edu> References: <20240514201436.2496-1-jspewock@iol.unh.edu> <20240605213148.21371-1-jspewock@iol.unh.edu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 There are methods within DTS currently that support updating the MTU of ports on a node, but the methods for doing this in a linux session rely on the ip command and the port being bound to the kernel driver. Since test suites are run while bound to the driver for DPDK, there needs to be a way to modify the value while bound to said driver as well. This is done by using testpmd to modify the MTU. Signed-off-by: Jeremy Spewock --- .../remote_session/interactive_shell.py | 14 +++- dts/framework/remote_session/testpmd_shell.py | 76 ++++++++++++++++++- 2 files changed, 86 insertions(+), 4 deletions(-) diff --git a/dts/framework/remote_session/interactive_shell.py b/dts/framework/remote_session/interactive_shell.py index 6dee7ebce0..34d1acf439 100644 --- a/dts/framework/remote_session/interactive_shell.py +++ b/dts/framework/remote_session/interactive_shell.py @@ -139,7 +139,9 @@ def _start_application(self, get_privileged_command: Callable[[str], str] | None raise InteractiveCommandExecutionError("Failed to start application.") self._ssh_channel.settimeout(self._timeout) - def send_command(self, command: str, prompt: str | None = None) -> str: + def send_command( + self, command: str, prompt: str | None = None, print_to_debug: bool = False + ) -> str: """Send `command` and get all output before the expected ending string. Lines that expect input are not included in the stdout buffer, so they cannot @@ -155,6 +157,10 @@ def send_command(self, command: str, prompt: str | None = None) -> str: command: The command to send. prompt: After sending the command, `send_command` will be expecting this string. If :data:`None`, will use the class's default prompt. + print_to_debug: If :data:`True` the logging message that displays what command is + being sent prior to sending it will be logged at the debug level instead of the + info level. Useful when a single action requires multiple commands to complete to + avoid clutter in the logs. Returns: All output in the buffer before expected string. @@ -163,7 +169,11 @@ def send_command(self, command: str, prompt: str | None = None) -> str: raise InteractiveCommandExecutionError( f"Cannot send command {command} to application because the shell is not running." ) - self._logger.info(f"Sending: '{command}'") + log_message = f"Sending: '{command}'" + if print_to_debug: + self._logger.debug(log_message) + else: + self._logger.info(log_message) if prompt is None: prompt = self._default_prompt self._stdin.write(f"{command}{self._command_extra_chars}\n") diff --git a/dts/framework/remote_session/testpmd_shell.py b/dts/framework/remote_session/testpmd_shell.py index ca30aac264..f2fa842b7f 100644 --- a/dts/framework/remote_session/testpmd_shell.py +++ b/dts/framework/remote_session/testpmd_shell.py @@ -135,10 +135,11 @@ def start(self, verify: bool = True) -> None: InteractiveCommandExecutionError: If `verify` is :data:`True` and forwarding fails to start or ports fail to come up. """ - self.send_command("start") + self._logger.info('Starting packet forwarding and waiting for port links to be "up".') + self.send_command("start", print_to_debug=True) if verify: # If forwarding was already started, sending "start" again should tell us - start_cmd_output = self.send_command("start") + start_cmd_output = self.send_command("start", print_to_debug=True) 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.") @@ -227,6 +228,77 @@ def set_forward_mode(self, mode: TestPmdForwardingModes, verify: bool = True): f"Test pmd failed to set fwd mode to {mode.value}" ) + def _stop_port(self, port_id: int, verify: bool = True) -> None: + """Stop port `port_id` in testpmd. + + Depending on the PMD, the port may need to be stopped before configuration can take place. + This method wraps the command needed to properly stop ports and take their link down. + + Args: + port_id: ID of the port to take down. + verify: If :data:`True` the output will be scanned in an attempt to verify that the + stopping of ports was successful. Defaults to True. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and the port did not + successfully stop. + """ + stop_port_output = self.send_command(f"port stop {port_id}", print_to_debug=True) + if verify and ("Done" not in stop_port_output): + self._logger.debug(f"Failed to stop port {port_id}. Output was:\n{stop_port_output}") + raise InteractiveCommandExecutionError(f"Test pmd failed to stop port {port_id}.") + + def _start_port(self, port_id: int, verify: bool = True) -> None: + """Start port `port_id` in testpmd. + + Because the port may need to be stopped to make some configuration changes, it naturally + follows that it will need to be started again once those changes have been made. + + Args: + port_id: ID of the port to start. + verify: If :data:`True` the output will be scanned in an attempt to verify that the + port came back up without error. Defaults to True. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and the port did not come + back up. + """ + start_port_output = self.send_command(f"port start {port_id}", print_to_debug=True) + if verify and ("Done" not in start_port_output): + self._logger.debug(f"Failed to start port {port_id}. Output was:\n{start_port_output}") + raise InteractiveCommandExecutionError(f"Test pmd failed to start port {port_id}.") + + def set_port_mtu(self, port_id: int, mtu: int, verify: bool = True) -> None: + """Change the MTU of a port using testpmd. + + Some PMDs require that the port be stopped before changing the MTU, and it does no harm to + stop the port before configuring in cases where it isn't required, so we first stop ports, + then update the MTU, then start the ports again afterwards. + + Args: + port_id: ID of the port to adjust the MTU on. + mtu: Desired value for the MTU to be set to. + verify: If `verify` is :data:`True` then the output will be scanned in an attempt to + verify that the mtu was properly set on the port. Defaults to True. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and the MTU was not + properly updated on the port matching `port_id`. + """ + self._logger.info(f"Changing MTU of port {port_id} to be {mtu}") + self._stop_port(port_id, verify) + set_mtu_output = self.send_command(f"port config mtu {port_id} {mtu}", print_to_debug=True) + self._start_port(port_id, verify) + if verify and ( + f"MTU: {mtu}" not in self.send_command(f"show port info {port_id}", print_to_debug=True) + ): + self._logger.debug( + f"Failed to set mtu to {mtu} on port {port_id}." f" Output was:\n{set_mtu_output}" + ) + raise InteractiveCommandExecutionError( + f"Test pmd failed to update mtu of port {port_id} to {mtu}" + ) + def _close(self) -> None: """Overrides :meth:`~.interactive_shell.close`.""" self.send_command("quit", "Bye...") -- 2.45.1