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 59EFD45AE3; Tue, 8 Oct 2024 19:15:34 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4BA97402A9; Tue, 8 Oct 2024 19:15:34 +0200 (CEST) Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) by mails.dpdk.org (Postfix) with ESMTP id 2BFC54021E for ; Tue, 8 Oct 2024 19:15:33 +0200 (CEST) Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-7afc847094fso49368685a.2 for ; Tue, 08 Oct 2024 10:15:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1728407732; x=1729012532; 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=9gx3nNoyVv+JMnLI4lMISu7OtjpVZVoDTh+gHX+a8zs=; b=Zu5woxuRUkHIspkOpLI5d3YA3axY8yF3CLMUdjiVKM0Hlhy6GpRx7SBxmRqFS7XzzK /s+yduuqYV0vbxPiCnGGHhIDLxFHHLfqwKMEM4uOJhwQfY5dWzSQ2aiB8mJpseNGgNsE K2Q62y+Aw9UVtWFWoUMfC36SrLnw9/s+PDDy0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728407732; x=1729012532; 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=9gx3nNoyVv+JMnLI4lMISu7OtjpVZVoDTh+gHX+a8zs=; b=TDYvuBHVgXC5LbIwVHbMJtJMjLddD2jiEL5HVEVntvHdhSClrtxerOR5RSuszyeqXA ZHeOgGy/aRDpH/JjCUm0j/5rI23JQCGCZEfC15PX2OBJ5IM9n6A5gv01MLNpzBju0VIg qst8zGKc87K9iAJjAkIy07IMpVC2hG8tU8KjgNeCaTzEo/j2iUTaevOGu+rcTJCL11/k RwPx1I7/56hoR6dNAJYC6mqrQD+O1HKeazENAHJd+m/st/Zsjh5QEnhOWCiR5OBBpevd YyyGrMOyXJ2JCVEJXa2pvbEOa1Ah0/lncW/JNJsQjYPaf7ujKVRvTQoU/FdJYgLt8Ilv duQw== X-Gm-Message-State: AOJu0YzK4zoKadXhbeIKorH5x3iypvXOVryRQLF0C3j4cxkOy1ihaWDA s6Wf10b9JSwMB1PZ9cS9aSByFRAtEOqfY6WS8HMb/1yNdKzT6LmUgGjl/2cJHDc= X-Google-Smtp-Source: AGHT+IHCFTypfIwxAaSuw147HJruccEMreeiRLdFWLuqBEIoAmCjXXPc2gyVlnkLYvCAv+UGYM/eQQ== X-Received: by 2002:a05:620a:1aaa:b0:7ae:2f04:bf9c with SMTP id af79cd13be357-7ae6f44194emr2416968285a.18.1728407732394; Tue, 08 Oct 2024 10:15:32 -0700 (PDT) Received: from dean-laptop.iol.unh.edu ([2606:4100:3880:1210::208]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7ae7562f4bcsm367100185a.51.2024.10.08.10.15.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2024 10:15:31 -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 v2] dts: add VLAN methods to testpmd shell Date: Tue, 8 Oct 2024 13:15:57 -0400 Message-ID: <20241008171557.6502-1-dmarx@iol.unh.edu> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240918194127.11556-1-dmarx@iol.unh.edu> References: <20240918194127.11556-1-dmarx@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 Added the following methods to testpmd shell class: set vlan filter on/off, rx vlan add/rm, set vlan strip on/off, tx vlan set/reset, set promisc/verbose. Fixed a bug in the VLAN regex used in testpmd shell flags. Fixes: 61d5bc9bf974 ("dts: add port info command to testpmd shell") Signed-off-by: Dean Marx --- dts/framework/remote_session/testpmd_shell.py | 192 ++++++++++++++++-- 1 file changed, 172 insertions(+), 20 deletions(-) diff --git a/dts/framework/remote_session/testpmd_shell.py b/dts/framework/remote_session/testpmd_shell.py index 88eceb1c87..575261585f 100644 --- a/dts/framework/remote_session/testpmd_shell.py +++ b/dts/framework/remote_session/testpmd_shell.py @@ -102,7 +102,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, ), @@ -670,25 +670,6 @@ def __init__( TestPmdParams(**app_params), name, ) -<<<<<<< HEAD - self._ports = None - - @property - def ports(self) -> list[TestPmdPort]: - """The ports of the instance. - - This caches the ports returned by :meth:`show_port_info_all`. - To force an update of port information, execute :meth:`show_port_info_all` or - :meth:`show_port_info`. - - Returns: The list of known testpmd ports. - """ - if self._ports is None: - return self.show_port_info_all() - return self._ports - -======= ->>>>>>> 8538685a3a86a021c2a634b8f948ae0a39331a26 self.ports_started = not self._app_params.disable_device_start self._ports = None @@ -1000,6 +981,177 @@ def set_port_mtu_all(self, mtu: int, verify: bool = True) -> None: for port in self.ports: self.set_port_mtu(port.id, mtu, verify) + def set_vlan_filter(self, port: int, enable: bool, verify: bool = True) -> None: + """Set vlan filter on. + + Args: + port: The port number to enable VLAN filter on. + enable: Enable the filter on `port` if :data:`True`, otherwise disable it. + verify: If :data:`True`, the output of the command and show port info + is scanned to verify that vlan filtering was set successfully. + + 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 enable else 'off'} {port}") + if verify: + vlan_settings = self.show_port_info(port_id=port).vlan_offload + if enable ^ (vlan_settings is not None and VLANOffloadFlag.FILTER in vlan_settings): + self._logger.debug( + f"""Failed to {'enable' if enable else 'disable'} + filter on port {port}: \n{filter_cmd_output}""" + ) + raise InteractiveCommandExecutionError( + f"""Failed to {'enable' if enable else 'disable'} + 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. Requires vlan filter to be on. + + Args: + vlan: The vlan tag to add, should be within 1-1005. + port: The port number to add the tag on. + add: Adds the tag if :data:`True`, otherwise removes the 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. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and the tag + is not added. + """ + rx_cmd_output = self.send_command(f"rx_vlan {'add' if add else 'rm'} {vlan} {port}") + if verify: + if ( + "VLAN-filtering disabled" in rx_cmd_output + or "Invalid vlan_id" in rx_cmd_output + or "Bad arguments" in rx_cmd_output + ): + self._logger.debug( + f"""Failed to {'add' if add else 'remove'} tag {vlan} + port {port}: \n{rx_cmd_output}""" + ) + raise InteractiveCommandExecutionError( + f"Testpmd failed to {'add' if add else 'remove'} tag {vlan} on port {port}." + ) + + def set_vlan_strip(self, port: int, enable: bool, verify: bool = True) -> None: + """Enable or disable vlan stripping on the specified port. + + Args: + port: The port number to use. + enable: If :data:`True`, will turn vlan stripping 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. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and stripping + fails to update. + """ + strip_cmd_output = self.send_command(f"vlan set strip {'on' if enable else 'off'} {port}") + if verify: + vlan_settings = self.show_port_info(port_id=port).vlan_offload + if enable ^ (vlan_settings is not None and VLANOffloadFlag.STRIP in vlan_settings): + self._logger.debug( + f"""Failed to set strip {'on' if enable else 'off'} + port {port}: \n{strip_cmd_output}""" + ) + raise InteractiveCommandExecutionError( + f"Testpmd failed to set strip {'on' if enable else 'off'} port {port}." + ) + + @requires_stopped_ports + def tx_vlan_set( + self, port: int, enable: bool, vlan: int | None = None, verify: bool = True + ) -> None: + """Set hardware insertion of vlan tags in packets sent on a port. + + Args: + port: The port number to use. + enable: Sets vlan tag insertion if :data:`True`, and resets if :data:`False`. + vlan: The vlan tag to insert if enable is :data:`True`. + verify: If :data:`True`, the output of the command is scanned to verify that + vlan insertion was enabled on the specified port. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and the insertion + tag is not set. + """ + if enable: + tx_vlan_cmd_output = self.send_command(f"tx_vlan set {port} {vlan}") + if verify: + if ( + "Please stop port" in tx_vlan_cmd_output + or "Invalid vlan_id" in tx_vlan_cmd_output + or "Invalid port" in tx_vlan_cmd_output + ): + self._logger.debug( + f"Failed to set vlan tag {vlan} on port {port}:\n{tx_vlan_cmd_output}" + ) + raise InteractiveCommandExecutionError( + f"Testpmd failed to set vlan insertion tag {vlan} on port {port}." + ) + else: + tx_vlan_cmd_output = self.send_command(f"tx_vlan reset {port}") + if verify: + if "Please stop port" in tx_vlan_cmd_output or "Invalid port" in tx_vlan_cmd_output: + self._logger.debug( + f"Failed to reset vlan insertion on port {port}: \n{tx_vlan_cmd_output}" + ) + raise InteractiveCommandExecutionError( + f"Testpmd failed to reset vlan insertion on port {port}." + ) + + def set_promisc(self, port: int, enable: bool, verify: bool = True) -> None: + """Enable or disable promiscuous mode for the specified port. + + Args: + port: Port number to use. + enable: If :data:`True`, turn promiscuous mode on, otherwise turn off. + verify: If :data:`True` an additional command will be sent to verify that + promiscuous mode is properly set. Defaults to :data:`True`. + + Raises: + InteractiveCommandExecutionError: If `verify` is :data:`True` and promiscuous mode + is not correctly set. + """ + promisc_cmd_output = self.send_command(f"set promisc {port} {'on' if enable else 'off'}") + if verify: + stats = self.show_port_info(port_id=port) + if enable ^ stats.is_promiscuous_mode_enabled: + self._logger.debug( + f"Failed to set promiscuous mode on port {port}: \n{promisc_cmd_output}" + ) + raise InteractiveCommandExecutionError( + f"Testpmd failed to set promiscuous 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_cmd_output = self.send_command(f"set verbose {level}") + if verify: + if "Change verbose level" not in verbose_cmd_output: + self._logger.debug( + f"Failed to set verbose level to {level}: \n{verbose_cmd_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