<div dir="ltr">I think Jeremy already mentioned this but just make sure you update vlan_set_filter_on/off to the <span class="gmail-il">new</span> version that has an on boolean arg.<div><br></div><div>Reviewed-by: Dean Marx <<a href="mailto:dmarx@iol.unh.edu" target="_blank">dmarx@iol.unh.edu</a>></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 18, 2024 at 3:12 PM Nicholas Pratte <<a href="mailto:npratte@iol.unh.edu">npratte@iol.unh.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Several new methods have been added to TestPMDShell in order to produce<br>
the mac filter's individual test cases:<br>
- set_mac_addr<br>
- set_multicast_mac_addr<br>
- rx_vlan_add<br>
- rx_vlan_rm<br>
- vlan_filter_set_on<br>
- vlan_filter_set_off<br>
- set_promisc<br>
<br>
set_mac_addr and set_multicast_addr were created for the mac filter test<br>
suite, enabling users to both add or remove mac and multicast<br>
addresses based on a boolean 'add or remove' parameter. The success or<br>
failure of each call can be verified if a user deems it necessary.<br>
<br>
The other methods listed are implemented in other respective test<br>
suites, and their implementations have been copied, but are subject to<br>
change; they are not the focus of this patch.<br>
<br>
Bugzilla ID: 1454<br>
Signed-off-by: Nicholas Pratte <<a href="mailto:npratte@iol.unh.edu" target="_blank">npratte@iol.unh.edu</a>><br>
---<br>
dts/framework/remote_session/testpmd_shell.py | 179 ++++++++++++++++++<br>
1 file changed, 179 insertions(+)<br>
<br>
diff --git a/dts/framework/remote_session/testpmd_shell.py b/dts/framework/remote_session/testpmd_shell.py<br>
index ec22f72221..8122457ad1 100644<br>
--- a/dts/framework/remote_session/testpmd_shell.py<br>
+++ b/dts/framework/remote_session/testpmd_shell.py<br>
@@ -767,6 +767,185 @@ def show_port_info(self, port_id: int) -> TestPmdPort:<br>
<br>
return TestPmdPort.parse(output)<br>
<br>
+ def set_mac_addr(self, port_id: int, mac_address: str, add: bool, verify: bool = True) -> None:<br>
+ """Add or remove a mac address on a given port's Allowlist.<br>
+<br>
+ Args:<br>
+ port_id: The port ID the mac address is set on.<br>
+ mac_address: The mac address to be added or removed to the specified port.<br>
+ add: If :data:`True`, add the specified mac address. If :data:`False`, remove specified<br>
+ mac address.<br>
+ verify: If :data:'True', assert that the 'mac_addr' operation was successful. If<br>
+ :data:'False', run the command and skip this assertion.<br>
+<br>
+ Raises:<br>
+ InteractiveCommandExecutionError: If the set mac address operation fails.<br>
+ """<br>
+ mac_cmd = "add" if add else "remove"<br>
+ output = self.send_command(f"mac_addr {mac_cmd} {port_id} {mac_address}")<br>
+ if "Bad arguments" in output:<br>
+ self._logger.debug("Invalid argument provided to mac_addr")<br>
+ raise InteractiveCommandExecutionError("Invalid argument provided")<br>
+<br>
+ if verify:<br>
+ if "mac_addr_cmd error:" in output:<br>
+ self._logger.debug(f"Failed to {mac_cmd} {mac_address} on port {port_id}")<br>
+ raise InteractiveCommandExecutionError(<br>
+ f"Failed to {mac_cmd} {mac_address} on port {port_id} \n{output}"<br>
+ )<br>
+<br>
+ def set_multicast_mac_addr(<br>
+ self, port_id: int, multi_addr: str, add: bool, verify: bool = True<br>
+ ) -> None:<br>
+ """Add or remove multicast mac address to a specified port's filter.<br>
+<br>
+ Args:<br>
+ port_id: The port ID the multicast address is set on.<br>
+ multi_addr: The multicast address to be added to the filter.<br>
+ add: If :data:'True', add the specified multicast address to the port filter.<br>
+ If :data:'False', remove the specified multicast address from the port filter.<br>
+ verify: If :data:'True', assert that the 'mcast_addr' operations was successful.<br>
+ If :data:'False', execute the 'mcast_addr' operation and skip the assertion.<br>
+<br>
+ Raises:<br>
+ InteractiveCommandExecutionError: If either the 'add' or 'remove' operations fails.<br>
+ """<br>
+ mcast_cmd = "add" if add else "remove"<br>
+ output = self.send_command(f"mcast_addr {mcast_cmd} {port_id} {multi_addr}")<br>
+ if "Bad arguments" in output:<br>
+ self._logger.debug("Invalid arguments provided to mcast_addr")<br>
+ raise InteractiveCommandExecutionError("Invalid argument provided")<br>
+<br>
+ if verify:<br>
+ if (<br>
+ "Invalid multicast_addr" in output<br>
+ or f'multicast address {"already" if add else "not"} filtered by port' in output<br>
+ ):<br>
+ self._logger.debug(f"Failed to {mcast_cmd} {multi_addr} on port {port_id}")<br>
+ raise InteractiveCommandExecutionError(<br>
+ f"Failed to {mcast_cmd} {multi_addr} on port {port_id} \n{output}"<br>
+ )<br>
+<br>
+ def rx_vlan_add(self, vlan: int, port: int, verify: bool = True) -> None:<br>
+ """Add specified vlan tag to the filter list on a port.<br>
+<br>
+ Args:<br>
+ vlan: The vlan tag to add, should be within 1-1005, 1-4094 extended.<br>
+ port: The port number to add the tag on, should be within 0-32.<br>
+ verify: If :data:`True`, the output of the command is scanned to verify that<br>
+ the vlan tag was added to the filter list on the specified port. If not, it is<br>
+ considered an error.<br>
+<br>
+ Raises:<br>
+ InteractiveCommandExecutionError: If `verify` is :data:`True` and the tag<br>
+ is not added.<br>
+ """<br>
+ vlan_add_output = self.send_command(f"rx_vlan add {vlan} {port}")<br>
+ if verify:<br>
+ if "VLAN-filtering disabled" in vlan_add_output or "Invalid vlan_id" in vlan_add_output:<br>
+ self._logger.debug(<br>
+ f"Failed to add vlan tag {vlan} on port {port}: \n{vlan_add_output}"<br>
+ )<br>
+ raise InteractiveCommandExecutionError(<br>
+ f"Testpmd failed to add vlan tag {vlan} on port {port}."<br>
+ )<br>
+<br>
+ def rx_vlan_rm(self, vlan: int, port: int, verify: bool = True) -> None:<br>
+ """Remove specified vlan tag from filter list on a port.<br>
+<br>
+ Args:<br>
+ vlan: The vlan tag to remove, should be within 1-4094.<br>
+ port: The port number to remove the tag from, should be within 0-32.<br>
+ verify: If :data:`True`, the output of the command is scanned to verify that<br>
+ the vlan tag was removed from the filter list on the specified port. If not, it is<br>
+ considered an error.<br>
+<br>
+ Raises:<br>
+ InteractiveCommandExecutionError: If `verify` is :data:`True` and the tag<br>
+ is not removed.<br>
+ """<br>
+ vlan_rm_output = self.send_command(f"rx_vlan rm {vlan} {port}")<br>
+ if verify:<br>
+ if "VLAN-filtering disabled" in vlan_rm_output or "Invalid vlan_id" in vlan_rm_output:<br>
+ self._logger.debug(<br>
+ f"Failed to remove vlan tag {vlan} on port {port}: \n{vlan_rm_output}"<br>
+ )<br>
+ raise InteractiveCommandExecutionError(<br>
+ f"Testpmd failed to remove vlan tag {vlan} on port {port}."<br>
+ )<br>
+<br>
+ def vlan_filter_set_on(self, port: int, verify: bool = True) -> None:<br>
+ """Set vlan filter on.<br>
+<br>
+ Args:<br>
+ port: The port number to enable VLAN filter on, should be within 0-32.<br>
+ verify: If :data:`True`, the output of the command and show port info<br>
+ is scanned to verify that vlan filtering was enabled successfully.<br>
+ If not, it is considered an error.<br>
+<br>
+ Raises:<br>
+ InteractiveCommandExecutionError: If `verify` is :data:`True` and the filter<br>
+ fails to update.<br>
+ """<br>
+ filter_cmd_output = self.send_command(f"vlan set filter on {port}")<br>
+ if verify:<br>
+ if "Invalid port" in filter_cmd_output or "filter on" not in self.send_command(<br>
+ f"show port info {port}"<br>
+ ):<br>
+ self._logger.debug(<br>
+ f"Failed to enable vlan filter on port {port}: \n{filter_cmd_output}"<br>
+ )<br>
+ raise InteractiveCommandExecutionError(<br>
+ f"Testpmd failed to enable vlan filter on port {port}."<br>
+ )<br>
+<br>
+ def vlan_filter_set_off(self, port: int, verify: bool = True) -> None:<br>
+ """Set vlan filter off.<br>
+<br>
+ Args:<br>
+ port: The port number to disable VLAN filter on, should be within 0-32.<br>
+ verify: If :data:`True`, the output of the command and show port info<br>
+ is scanned to verify that vlan filtering was disabled successfully.<br>
+ If not, it is considered an error.<br>
+<br>
+ Raises:<br>
+ InteractiveCommandExecutionError: If `verify` is :data:`True` and the filter<br>
+ fails to update.<br>
+ """<br>
+ filter_cmd_output = self.send_command(f"vlan set filter off {port}")<br>
+ if verify:<br>
+ if "Invalid port" in filter_cmd_output or "filter off" not in self.send_command(<br>
+ f"show port info {port}"<br>
+ ):<br>
+ self._logger.debug(<br>
+ f"Failed to disable vlan filter on port {port}: \n{filter_cmd_output}"<br>
+ )<br>
+ raise InteractiveCommandExecutionError(<br>
+ f"Testpmd failed to disable vlan filter on port {port}."<br>
+ )<br>
+<br>
+ def set_promisc(self, port: int, on: bool, verify: bool = True) -> None:<br>
+ """Turns promiscuous mode on/off for the specified port.<br>
+<br>
+ Args:<br>
+ port: Port number to use, should be within 0-32.<br>
+ on: If :data:`True`, turn promisc mode on, otherwise turn off.<br>
+ verify: If :data:`True` an additional command will be sent to verify that promisc mode<br>
+ is properly set. Defaults to :data:`True`.<br>
+<br>
+ Raises:<br>
+ InteractiveCommandExecutionError: If `verify` is :data:`True` and promisc mode<br>
+ is not correctly set.<br>
+ """<br>
+ promisc_output = self.send_command(f"set promisc {port} {'on' if on else 'off'}")<br>
+ if verify:<br>
+ stats = self.show_port_info(port_id=port)<br>
+ if on ^ stats.is_promiscuous_mode_enabled:<br>
+ self._logger.debug(f"Failed to set promisc mode on port {port}: \n{promisc_output}")<br>
+ raise InteractiveCommandExecutionError(<br>
+ f"Testpmd failed to set promisc mode on port {port}."<br>
+ )<br>
+<br>
def show_port_stats_all(self) -> list[TestPmdPortStats]:<br>
"""Returns the statistics of all the ports.<br>
<br>
-- <br>
2.44.0<br>
<br>
</blockquote></div>