[PATCH v5 2/3] dts: refactored VLAN test suite
Dean Marx
dmarx at iol.unh.edu
Tue Jun 18 18:29:38 CEST 2024
Tweaked logic on sending and verifying packets for
more concise code, added verbose and promisc
function calls from pmd shell module.
Signed-off-by: Dean Marx <dmarx at iol.unh.edu>
---
dts/tests/TestSuite_vlan.py | 167 ++++++++++++++++++++++++++++++++++++
1 file changed, 167 insertions(+)
create mode 100644 dts/tests/TestSuite_vlan.py
diff --git a/dts/tests/TestSuite_vlan.py b/dts/tests/TestSuite_vlan.py
new file mode 100644
index 0000000000..b9b2a98588
--- /dev/null
+++ b/dts/tests/TestSuite_vlan.py
@@ -0,0 +1,167 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2024 University of New Hampshire
+
+"""Test the support of VLAN Offload Features by Poll Mode Drivers.
+
+The test suite ensures that with the correct configuration, a port
+will not drop a VLAN tagged packet. In order for this to be successful,
+packet header stripping and packet receipts must be enabled on the Poll Mode Driver.
+The test suite checks that when these conditions are met, the packet is received without issue.
+The suite also checks to ensure that when these conditions are not met, as in the cases where
+stripping is disabled, or VLAN packet receipts are disabled, the packet is not received.
+Additionally, it checks the case where VLAN header insertion is enabled in transmitted packets,
+which should be successful if the previous cases pass.
+
+"""
+
+from scapy.layers.l2 import Dot1Q, Ether # type: ignore[import]
+from scapy.packet import Raw # type: ignore[import]
+
+from framework.remote_session.testpmd_shell import TestPmdForwardingModes, TestPmdShell
+from framework.test_suite import TestSuite
+
+
+class TestVlan(TestSuite):
+ """DPDK VLAN test suite.
+
+ Ensures VLAN packet reception on the Poll Mode Driver when certain conditions are met.
+ If one or more of these conditions are not met, the packet reception should be unsuccessful.
+ """
+
+ def set_up_suite(self) -> None:
+ """Set up the test suite.
+
+ Setup:
+ Create a testpmd session and set up tg nodes
+ verify that at least two ports are open for session
+ """
+ self.verify(len(self._port_links) > 1, "Not enough ports")
+
+ def send_vlan_packet_and_verify(
+ self, should_receive: bool = True, strip: bool = False, vlan_id: int = -1
+ ) -> None:
+ """Generate a vlan packet, send and verify on the dut.
+
+ Args:
+ should_receive: indicate whether the packet should be successfully received
+ vlan_id: expected vlan ID
+ strip: indicates whether stripping is on or off,
+ and when the vlan tag is checked for a match
+ """
+ packet = Ether() / Dot1Q(vlan=vlan_id) / Raw(load='xxxxx')
+ received_packets = self.send_packet_and_capture(packet)
+ test_packet = None
+ for packet in received_packets:
+ if packet.haslayer(Raw) and packet[Raw].load == b'xxxxx':
+ test_packet = packet
+ break
+ if should_receive:
+ self.verify(
+ test_packet is not None, "Packet was dropped when it should have been received"
+ )
+ if strip:
+ self.verify(Dot1Q not in test_packet, "Vlan tag was not stripped successfully")
+ else:
+ self.verify(
+ test_packet.vlan == vlan_id, "The received tag did not match the expected tag"
+ )
+ else:
+ self.verify(
+ test_packet is None,
+ "Packet was received when it should have been dropped",
+ )
+
+ def send_packet_and_verify_insertion(self, expected_id: int = -1) -> None:
+ """Generate a packet with no vlan tag, send and verify on the dut.
+
+ Args:
+ expected_id: the vlan id that is being inserted through tx_offload configuration
+ should_receive: indicate whether the packet should be successfully received
+ """
+ packet = Ether() / Raw(load='xxxxx')
+ received_packets = self.send_packet_and_capture(packet)
+ test_packet = None
+ for packet in received_packets:
+ if packet.haslayer(Raw) and packet[Raw].load == b'xxxxx':
+ test_packet = packet
+ break
+ self.verify(
+ test_packet is not None, "Packet was dropped when it should have been received"
+ )
+ self.verify(Dot1Q in test_packet, "The received packet did not have a vlan tag")
+ self.verify(test_packet.vlan == expected_id, "The received tag did not match the expected tag")
+
+ def test_vlan_receipt_no_stripping(self) -> None:
+ """Ensure vlan packet is dropped when receipts are enabled and header stripping is disabled.
+
+ Test:
+ Create an interactive testpmd shell and verify a vlan packet.
+ """
+ testpmd = self.sut_node.create_interactive_shell(TestPmdShell, privileged=True)
+ testpmd.set_forward_mode(TestPmdForwardingModes.mac)
+ testpmd.set_verbose(1)
+ testpmd.set_promisc(0, False)
+ testpmd.vlan_filter_set_on(0)
+ testpmd.rx_vlan_add(1, 0)
+ testpmd.start()
+
+ filtered_vlan = 1
+ self.send_vlan_packet_and_verify(True, vlan_id=filtered_vlan)
+ testpmd.close()
+
+ def test_vlan_receipt_stripping(self) -> None:
+ """Ensure vlan packet received with no tag when receipts and header stripping are enabled.
+
+ Test:
+ Create an interactive testpmd shell and verify a vlan packet.
+ """
+ testpmd = self.sut_node.create_interactive_shell(TestPmdShell, privileged=True)
+ testpmd.set_forward_mode(TestPmdForwardingModes.mac)
+ testpmd.set_verbose(1)
+ testpmd.set_promisc(0, False)
+ testpmd.vlan_filter_set_on(0)
+ testpmd.rx_vlan_add(1, 0)
+ testpmd.vlan_strip_set_on(0)
+ testpmd.start()
+
+ self.send_vlan_packet_and_verify(should_receive=True, strip=True, vlan_id=1)
+ testpmd.close()
+
+ def test_vlan_no_receipt(self) -> None:
+ """Ensure vlan packet dropped when filter is on and sent tag not in the filter list.
+
+ Test:
+ Create an interactive testpmd shell and verify a vlan packet.
+ """
+ testpmd = self.sut_node.create_interactive_shell(TestPmdShell, privileged=True)
+ testpmd.set_forward_mode(TestPmdForwardingModes.mac)
+ testpmd.set_verbose(1)
+ testpmd.set_promisc(0, False)
+ testpmd.vlan_filter_set_on(0)
+ testpmd.rx_vlan_add(1, 0)
+ testpmd.start()
+
+ filtered_vlan = 1
+ self.send_vlan_packet_and_verify(should_receive=False, vlan_id=filtered_vlan + 1)
+ testpmd.close()
+
+ def test_vlan_header_insertion(self) -> None:
+ """Ensure that vlan packet is received with the correct inserted vlan tag.
+
+ Test:
+ Create an interactive testpmd shell and verify a non-vlan packet.
+ """
+ testpmd = self.sut_node.create_interactive_shell(TestPmdShell, privileged=True)
+ testpmd.set_forward_mode(TestPmdForwardingModes.mac)
+ testpmd.set_verbose(1)
+ testpmd.set_promisc(0, False)
+ testpmd.port_stop_all()
+ testpmd.tx_vlan_set(1, 51)
+ testpmd.port_start_all()
+ testpmd.start()
+
+ self.send_packet_and_verify_insertion(expected_id=51)
+ testpmd.close()
+
+ def tear_down_suite(self) -> None:
+ """Tear down the suite."""
--
2.44.0
More information about the dev
mailing list