The ethertype test suite requires many different internal runtime vlan offload options to test ethertype configuration. The following patch adds a new RxVlanOffloadOptions class that contains all the different vlan configuration options available within testpmd. Additionally, an extra method has beena added to adjust both the inner and outer tpids of ingressing and egressing packets.
Bugzilla ID: 1505 Signed-off-by: Nicholas Pratte <npra...@iol.unh.edu> --- dts/framework/remote_session/testpmd_shell.py | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/dts/framework/remote_session/testpmd_shell.py b/dts/framework/remote_session/testpmd_shell.py index 288be9a085..268e34f0eb 100644 --- a/dts/framework/remote_session/testpmd_shell.py +++ b/dts/framework/remote_session/testpmd_shell.py @@ -70,6 +70,10 @@ class VLANOffloadFlag(Flag): #: QINQ_STRIP = auto() + def __str__(self): + """Return flag name when cast to a string.""" + return self.name + @classmethod def from_str_dict(cls, d): """Makes an instance from a dict containing the flag member names with an "on" value. @@ -915,6 +919,26 @@ def show_port_stats_all(self) -> list[TestPmdPortStats]: iter = re.finditer(r"(^ #*.+#*$[^#]+)^ #*\r$", output, re.MULTILINE) return [TestPmdPortStats.parse(block.group(1)) for block in iter] + def set_vlan_tpid(self, port_id: int, tpid: int, inner_id: bool) -> None: + """Set ethertype tpid values using the ethdev api. + + Args: + port_id: the ID of the port the tpid is being changed on. + tpid: The tpid value being changed on the port. + inner_id: If :data:`True`, set the inner tpid to the specified value. If + :data:`False`, change the outer tpid to the specified value. + + Raises: + InteractiveCommandExecutionError: If either `port_id` or `tpid` value is invalid. + """ + if tpid < 0 or tpid > 65535: + raise InteractiveCommandExecutionError("Invalid TPID value given.") + output = self.send_command( + f'vlan set {"inner" if inner_id else "outer"} tpid {tpid} {port_id}' + ) + if output.startswith("Invalid port"): + raise InteractiveCommandExecutionError(f"Invalid port ID {port_id} given.") + def show_port_stats(self, port_id: int) -> TestPmdPortStats: """Returns the given port statistics. @@ -978,6 +1002,37 @@ def rx_vlan(self, vlan: int, port: int, add: bool, verify: bool = True) -> None: f"Testpmd failed to {'add' if add else 'remove'} tag {vlan} on port {port}." ) + def set_vlan_offload_option( + self, port: int, offload_option: VLANOffloadFlag, on: bool, verify: bool = True + ) -> None: + """Enable extended vlans on the specified port. + + Args: + port: The port number to use, should be within 0-32. + on: If :data:`True`, extended vlan turn on, otherwise it turns off. + offload_options: The rx vlan offload option to be set. + 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. + """ + offload_output = self.send_command( + f"vlan set {str(offload_option).lower()} {'on' if on else 'off'} {port}" + ) + if verify: + if on ^ (str(offload_option) in str(self.show_port_info(port_id=port).vlan_offload)): + self._logger.debug( + f"""Failed to set {offload_option} {'on' if on else 'off'} port {port}: + \n{offload_output} + """ + ) + raise InteractiveCommandExecutionError( + f"Testpmd failed to set {offload_option} {'on' if on else 'off'} port {port}." + ) + def port_stop_all(self, verify: bool = True) -> None: """Stop all ports. -- 2.44.0