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 0403045962; Wed, 11 Sep 2024 19:37:49 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BE7EB42F93; Wed, 11 Sep 2024 19:37:48 +0200 (CEST) Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) by mails.dpdk.org (Postfix) with ESMTP id E48B242EF2 for ; Wed, 11 Sep 2024 19:37:46 +0200 (CEST) Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-6c54b1f52f7so342096d6.3 for ; Wed, 11 Sep 2024 10:37:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1726076266; x=1726681066; darn=dpdk.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=9T8FaoXbDtONQCLPeeTO26H9ya6wlb9M+ZFRF/pN9MY=; b=Ng6eGhphx2Fv5iXxrx7UW7YD9uCxWXbGOZ9MZ6tuM+JjH3oZA22gNk8pbDtmWun96s cfo3z2r0Ra6RL4U6X/1GI4stro0W4ThQV3XAmt+p470JuJyq5dWWhc+DdjC/X+1axKfO Jd0CxVGAqDdtFOwINHrh5tiP25NfEYp1nPtsY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726076266; x=1726681066; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=9T8FaoXbDtONQCLPeeTO26H9ya6wlb9M+ZFRF/pN9MY=; b=n2lmB3ZLe1GRs0WQh5iQG2GRyFuNSse/K9ZrawCkuO/r6oK0iG0LPwvrtEOIkRjGzD AlwoJY16Y7ugZ7vHo0R6LQ2pHBCxhKNkc2ruXL+PM+XvEQi6CQZtKypXsb+Gsqy/E32J DqVyXSVcL8s7gifRB104LHFzyOkXr7kB+Lj6dkeCeHptOhncMFahaYo9u+po6RsrUdjQ +2x5GNHqwDPWvsUHQiR96xmBrPBPaZ8rG/0fOGz1R5RupN7NwoAMqUae6CWR29qckV/+ RwSAczEMkz2k5RJTFDIty98PSmg6MToy2nN9xroHxk6lxR65iBBilyVmpJez+07tYzZj iNQw== X-Gm-Message-State: AOJu0YzRC+zXFRdQqCdbIncbH8u/fCE3qc/03gsBVpDAu9lwG6aeEpFx xZiBTozSqL2Ilzr9IRfEBBa61mSBxmIDNaKf5UFZcePRYiBTDnVNWvDBd1xeI6E= X-Google-Smtp-Source: AGHT+IGV3KVgD8NSayQJnyg1W3qQDVHm+M6yahOq5Uzfmazo4eIzSuDrRQ4SP6T7+6F/4QEEJulpNw== X-Received: by 2002:a05:6214:4906:b0:6c3:66f2:a645 with SMTP id 6a1803df08f44-6c573570a6amr2516096d6.35.1726076265958; Wed, 11 Sep 2024 10:37:45 -0700 (PDT) Received: from dean-laptop.iol.unh.edu ([2606:4100:3880:1271:f9bd:24da:464d:6294]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6c5347871edsm44341716d6.138.2024.09.11.10.37.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Sep 2024 10:37:45 -0700 (PDT) From: Dean Marx To: probb@iol.unh.edu, npratte@iol.unh.edu, jspewock@iol.unh.edu, luca.vizzarro@arm.com, yoan.picchi@foss.arm.com, Honnappa.Nagarahalli@arm.com, paul.szczepanek@arm.com, juraj.linkes@pantheon.tech Cc: dev@dpdk.org, Dean Marx Subject: [PATCH v1] dts: add VLAN methods to testpmd shell Date: Wed, 11 Sep 2024 13:38:01 -0400 Message-ID: <20240911173801.16538-1-dmarx@iol.unh.edu> X-Mailer: git-send-email 2.44.0 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 added the following methods to testpmd shell class: vlan set filter on/off, rx vlan add/rm, vlan set strip on/off, port stop/start all/port, tx vlan set/reset, set promisc/verbose fixed bug in vlan_offload for show port info, removed $ at end of regex Signed-off-by: Dean Marx Reviewed-by: Jeremy Spewock --- dts/framework/remote_session/testpmd_shell.py | 245 +++++++++++++++++- 1 file changed, 244 insertions(+), 1 deletion(-) diff --git a/dts/framework/remote_session/testpmd_shell.py b/dts/framework/remote_session/testpmd_shell.py index 43e9f56517..66cc5cb289 100644 --- a/dts/framework/remote_session/testpmd_shell.py +++ b/dts/framework/remote_session/testpmd_shell.py @@ -98,7 +98,7 @@ def make_parser(cls) -> ParserFn: r"strip (?Pon|off), " r"filter (?Pon|off), " r"extend (?Pon|off), " - r"qinq strip (?Pon|off)$", + r"qinq strip (?Pon|off)", re.MULTILINE, named=True, ), @@ -806,6 +806,249 @@ def show_port_stats(self, port_id: int) -> TestPmdPortStats: return TestPmdPortStats.parse(output) + def vlan_filter_set(self, port: int, on: bool, verify: bool = True) -> None: + """Set vlan filter on. + + Args: + port: The port number to enable VLAN filter on, should be within 0-32. + on: Sets filter on if :data:`True`, otherwise turns off. + verify: If :data:`True`, the output of the command and show port info + is scanned to verify that vlan filtering was enabled successfully. + If not, it is considered an error. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and the filter + fails to update. + """ + filter_cmd_output = self.send_command(f"vlan set filter {'on' if on else 'off'} {port}") + if verify: + vlan_settings = self.show_port_info(port_id=port).vlan_offload + if on ^ (vlan_settings is not None and VLANOffloadFlag.FILTER in vlan_settings): + self._logger.debug(f"Failed to set filter on port {port}: \n{filter_cmd_output}") + raise InteractiveCommandExecutionError( + f"Testpmd failed to set VLAN filter on port {port}." + ) + + def rx_vlan(self, vlan: int, port: int, add: bool, verify: bool = True) -> None: + """Add specified vlan tag to the filter list on a port. + + Args: + vlan: The vlan tag to add, should be within 1-1005, 1-4094 extended. + port: The port number to add the tag on, should be within 0-32. + add: Adds the tag if :data:`True`, otherwise removes tag. + verify: If :data:`True`, the output of the command is scanned to verify that + the vlan tag was added to the filter list on the specified port. If not, it is + considered an error. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and the tag + is not added. + """ + rx_output = self.send_command(f"rx_vlan {'add' if add else 'rm'} {vlan} {port}") + if verify: + if ( + "VLAN-filtering disabled" in rx_output + or "Invalid vlan_id" in rx_output + or "Bad arguments" in rx_output + ): + self._logger.debug( + f"Failed to {'add' if add else 'remove'} tag {vlan} port {port}: \n{rx_output}" + ) + raise InteractiveCommandExecutionError( + f"Testpmd failed to {'add' if add else 'remove'} tag {vlan} on port {port}." + ) + + def vlan_strip_set(self, port: int, on: bool, verify: bool = True) -> None: + """Enable vlan stripping on the specified port. + + Args: + port: The port number to use, should be within 0-32. + on: If :data:`True`, will turn strip on, otherwise will turn off. + verify: If :data:`True`, the output of the command and show port info + is scanned to verify that vlan stripping was enabled on the specified port. + If not, it is considered an error. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and stripping + fails to update. + """ + strip_output = self.send_command(f"vlan set strip {'on' if on else 'off'} {port}") + if verify: + vlan_settings = self.show_port_info(port_id=port).vlan_offload + if on ^ (vlan_settings is not None and VLANOffloadFlag.STRIP in vlan_settings): + self._logger.debug( + f"Failed to set strip {'on' if on else 'off'} port {port}: \n{strip_output}" + ) + raise InteractiveCommandExecutionError( + f"Testpmd failed to set strip {'on' if on else 'off'} port {port}." + ) + + def port_stop_all(self, verify: bool = True) -> None: + """Stop all ports. + + Args: + verify: If :data:`True`, the output of the command is scanned + to ensure all ports are stopped. If not, it is considered an error. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and all ports + fail to stop. + """ + port_output = self.send_command("port stop all") + if verify: + if "Done" not in port_output: + self._logger.debug(f"Failed to stop all ports: \n{port_output}") + raise InteractiveCommandExecutionError("Testpmd failed to stop all ports.") + + def port_stop(self, port: int, verify: bool = True) -> None: + """Stop specified port. + + Args: + port: Specifies the port number to use, must be between 0-32. + verify: If :data:`True`, the output of the command is scanned + to ensure specified port is stopped. If not, it is considered an error. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and the port + is not stopped. + """ + port_output = self.send_command(f"port stop {port}") + if verify: + if "Done" not in port_output: + self._logger.debug(f"Failed to stop port {port}: \n{port_output}") + raise InteractiveCommandExecutionError(f"Testpmd failed to stop port {port}.") + + def port_start_all(self, verify: bool = True) -> None: + """Start all ports. + + Args: + verify: If :data:`True`, the output of the command is scanned + to ensure all ports are started. If not, it is considered an error. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and all ports + fail to start. + """ + port_output = self.send_command("port start all") + if verify: + if "Done" not in port_output: + self._logger.debug(f"Failed to start all ports: \n{port_output}") + raise InteractiveCommandExecutionError("Testpmd failed to start all ports.") + + def port_start(self, port: int, verify: bool = True) -> None: + """Start specified port. + + Args: + port: Specifies the port number to use, must be between 0-32. + verify: If :data:`True`, the output of the command is scanned + to ensure specified port is started. If not, it is considered an error. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and the port + is not started. + """ + port_output = self.send_command(f"port start {port}") + if verify: + if "Done" not in port_output: + self._logger.debug(f"Failed to start port {port}: \n{port_output}") + raise InteractiveCommandExecutionError(f"Testpmd failed to start port {port}.") + + def tx_vlan_set(self, port: int, vlan: int, verify: bool = True) -> None: + """Set hardware insertion of vlan tags in packets sent on a port. + + Args: + port: The port number to use, should be within 0-32. + vlan: The vlan tag to insert, should be within 1-4094. + verify: If :data:`True`, the output of the command is scanned to verify that + vlan insertion was enabled on the specified port. If not, it is + considered an error. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and the insertion + tag is not set. + """ + vlan_insert_output = self.send_command(f"tx_vlan set {port} {vlan}") + if verify: + if ( + "Please stop port" in vlan_insert_output + or "Invalid vlan_id" in vlan_insert_output + or "Invalid port" in vlan_insert_output + ): + self._logger.debug( + f"Failed to set vlan tag {vlan} on port {port}:\n{vlan_insert_output}" + ) + raise InteractiveCommandExecutionError( + f"Testpmd failed to set vlan insertion tag {vlan} on port {port}." + ) + + def tx_vlan_reset(self, port: int, verify: bool = True) -> None: + """Disable hardware insertion of vlan tags in packets sent on a port. + + Args: + port: The port number to use, should be within 0-32. + verify: If :data:`True`, the output of the command is scanned to verify that + vlan insertion was disabled on the specified port. If not, it is + considered an error. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and the insertion + tag is not reset. + """ + vlan_insert_output = self.send_command(f"tx_vlan reset {port}") + if verify: + if "Please stop port" in vlan_insert_output or "Invalid port" in vlan_insert_output: + self._logger.debug( + f"Failed to reset vlan insertion on port {port}: \n{vlan_insert_output}" + ) + raise InteractiveCommandExecutionError( + f"Testpmd failed to reset vlan insertion on port {port}." + ) + + def set_promisc(self, port: int, on: bool, verify: bool = True) -> None: + """Turns promiscuous mode on/off for the specified port. + + Args: + port: Port number to use, should be within 0-32. + on: If :data:`True`, turn promisc mode on, otherwise turn off. + verify: If :data:`True` an additional command will be sent to verify that promisc mode + is properly set. Defaults to :data:`True`. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and promisc mode + is not correctly set. + """ + promisc_output = self.send_command(f"set promisc {port} {'on' if on else 'off'}") + if verify: + stats = self.show_port_info(port_id=port) + if on ^ stats.is_promiscuous_mode_enabled: + self._logger.debug(f"Failed to set promisc mode on port {port}: \n{promisc_output}") + raise InteractiveCommandExecutionError( + f"Testpmd failed to set promisc mode on port {port}." + ) + + def set_verbose(self, level: int, verify: bool = True) -> None: + """Set debug verbosity level. + + Args: + level: 0 - silent except for error + 1 - fully verbose except for Tx packets + 2 - fully verbose except for Rx packets + >2 - fully verbose + verify: If :data:`True` the command output will be scanned to verify that verbose level + is properly set. Defaults to :data:`True`. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and verbose level + is not correctly set. + """ + verbose_output = self.send_command(f"set verbose {level}") + if verify: + if "Change verbose level" not in verbose_output: + self._logger.debug(f"Failed to set verbose level to {level}: \n{verbose_output}") + raise InteractiveCommandExecutionError( + f"Testpmd failed to set verbose level to {level}." + ) + def _close(self) -> None: """Overrides :meth:`~.interactive_shell.close`.""" self.stop() -- 2.44.0