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 73FB445681; Mon, 22 Jul 2024 15:08:48 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5F904402AC; Mon, 22 Jul 2024 15:08:48 +0200 (CEST) Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) by mails.dpdk.org (Postfix) with ESMTP id 52744400D7 for ; Mon, 22 Jul 2024 15:08:46 +0200 (CEST) Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-7a18ba4143bso639265a12.2 for ; Mon, 22 Jul 2024 06:08:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1721653725; x=1722258525; darn=dpdk.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=01RE9AhQdOTuoEjb7KTIXC7WwPVxuh3l+iwKscEHqWk=; b=MuHNwUqAbEa3O0JbicK+IGSVcooPjJDmiXe0Syo/bWAPZ9Cxt86qovxhVBng7y5sTH bpiOuA58kUcKr9q1ITzeHsJubFg/o9L5CAjPTYZZAPr2IQRjbqvCR//UVe6rUzSkFIq0 MlVVRYphyOms7uG0NoVV3pvV+38jfLSTpRJrk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721653725; x=1722258525; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=01RE9AhQdOTuoEjb7KTIXC7WwPVxuh3l+iwKscEHqWk=; b=WqrcCqCY31vyBYKyCjtne3iUnzmakPD8OuJkDHIlnG9pZ/dvtyQkliEDuachiEatsU lp8+b+2KpoXViR4efN8D+J3ZluEr8na8xwkfmeXWweEK7pHRRcfCGcsbPrz7hI+fkI/1 xZh7O4+ETvn7jvXO52vP2rt1xid6Log/Op1TY/QhI0qpHjKBb7DtV2cFnvAYuImQsIeB 8DMaSchh99ub2pY4n/+48i4KuqJq03rkAI14Gu5q/HPLskW6jCmZUxgr9pQ/mcSdHu2a JOUDyYOQ5p2Ytkl+Q+BnLKDbTD+DJjW5yGDU0BD5fR25auBL8Z2hL9rGMD/+zSoUSApl BxCA== X-Forwarded-Encrypted: i=1; AJvYcCVPoEtD/svh9FQOYy0mAhUsI3zpdwLH7Iia9qNyUitL+suQVvmE9dWLmX1JMkBWi6oZoRZ4jhLGAJ9Qrr0= X-Gm-Message-State: AOJu0YztU+pbd30ny6SSNr12M6+igeW76wdxabCKkKEtuKq5MKD+JbOb rNmBMbKhIG57FdRg3c1UeSEuxKVTJBPMIY7lNGcHk2sM69terOvQZPpZ3/kyspARJJppOg2j2Wm e1r92h1R4I1L3ttLT0/GiyLP2cRsna0grTEmNGQ== X-Google-Smtp-Source: AGHT+IFJtG1Fwcvzej4BajOm1QOjfjw7hEPgSH6QD/aEU26114RYrjYtzn0K0ADycWshM738Fs8g5xvr+QP/yeht5Q8= X-Received: by 2002:a05:6a20:7486:b0:1c0:f648:8574 with SMTP id adf61e73a8af0-1c4285ef476mr4514212637.29.1721653725161; Mon, 22 Jul 2024 06:08:45 -0700 (PDT) MIME-Version: 1.0 References: <20240718190509.4203-1-npratte@iol.unh.edu> <20240718194028.2849-1-npratte@iol.unh.edu> In-Reply-To: <20240718194028.2849-1-npratte@iol.unh.edu> From: Dean Marx Date: Mon, 22 Jul 2024 09:08:28 -0400 Message-ID: Subject: Re: [PATCH v3 3/3] dts: mac filter test suite refactored for new dts To: Nicholas Pratte Cc: probb@iol.unh.edu, paul.szczepanek@arm.com, luca.vizzarro@arm.com, jspewock@iol.unh.edu, Honnappa.Nagarahalli@arm.com, yoan.picchi@foss.arm.com, juraj.linkes@pantheon.tech, dev@dpdk.org Content-Type: multipart/alternative; boundary="000000000000b700d9061dd5be9b" 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 --000000000000b700d9061dd5be9b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > > +This test suite ensures proper and expected behavior of Allowlist filterin= g > via mac > +addresses on devices bound to the Poll Mode Driver. If a packet received > on a device > +contains a mac address not contained with its mac address pool, the > packet should > +be dropped. Alternatively, if a packet is received that contains a > destination mac > +within the devices address pool, the packet should be accepted and > forwarded. This > +behavior should remain consistent across all packets, namely those > containing dot1q > +tags or otherwise. > This is pretty minor but you might want to change "with its mac address pool" to "within", just to stay consistent with the wording in the rest of the suite > > + received_packets =3D [ > + packets > + for packets in self.send_packet_and_capture(packet, > adjust_addresses=3DFalse) > + if hasattr(packets, "load") and "X" * 22 in str(packets.load= ) > + ] > Also Jeremy said he mentioned Juraj's opinion on using Jeremy's method of turning off adjust addresses, if you end up doing that just make it depend on this patch: patch-1142113 ("add send_packets to test suites and rework packet addressing") Reviewed-by: Dean Marx On Thu, Jul 18, 2024 at 3:40=E2=80=AFPM Nicholas Pratte wrote: > The mac address filter test suite, whose test cases are based on old > DTS's test cases, has been refactored to interface with the new DTS > framework. > > In porting over this test suite into the new framework, some > adjustments were made, namely in the EAL and TestPMD parameter provided > before executing the application. While the original test plan was > referenced, by and large, only for the individual test cases, I'll leave > the parameters the original test plan was asking for below for the sake > of discussion: > > --burst=3D1 --rxpt=3D0 --rxht=3D0 --rxwt=3D0 --txpt=3D36 --txht=3D0 --txw= t=3D0 > --txfreet=3D32 --rxfreet=3D64 --mbcache=3D250 --portmask=3D0x3 > > Bugzilla ID: 1454 > Signed-off-by: Nicholas Pratte > > --- > v2: > * Refactored the address pool capacity tests to use all available > octets in the mac address. > * Change the payload to 'X' characters instead of 'P' characters. > --- > dts/framework/config/conf_yaml_schema.json | 3 +- > dts/tests/TestSuite_mac_filter.py | 223 +++++++++++++++++++++ > 2 files changed, 225 insertions(+), 1 deletion(-) > create mode 100644 dts/tests/TestSuite_mac_filter.py > > diff --git a/dts/framework/config/conf_yaml_schema.json > b/dts/framework/config/conf_yaml_schema.json > index f02a310bb5..ad1f3757f7 100644 > --- a/dts/framework/config/conf_yaml_schema.json > +++ b/dts/framework/config/conf_yaml_schema.json > @@ -187,7 +187,8 @@ > "enum": [ > "hello_world", > "os_udp", > - "pmd_buffer_scatter" > + "pmd_buffer_scatter", > + "mac_filter" > ] > }, > "test_target": { > diff --git a/dts/tests/TestSuite_mac_filter.py > b/dts/tests/TestSuite_mac_filter.py > new file mode 100644 > index 0000000000..53a3331224 > --- /dev/null > +++ b/dts/tests/TestSuite_mac_filter.py > @@ -0,0 +1,223 @@ > +# SPDX-License-Identifier: BSD-3-Clause > +# Copyright(c) 2023-2024 University of New Hampshire > +"""Mac address filtering test suite. > + > +This test suite ensures proper and expected behavior of Allowlist > filtering via mac > +addresses on devices bound to the Poll Mode Driver. If a packet received > on a device > +contains a mac address not contained with its mac address pool, the > packet should > +be dropped. Alternatively, if a packet is received that contains a > destination mac > +within the devices address pool, the packet should be accepted and > forwarded. This > +behavior should remain consistent across all packets, namely those > containing dot1q > +tags or otherwise. > + > +The following test suite assesses behaviors based on the aforementioned > logic. > +Additionally, testing is done within the PMD itself to ensure that the > mac address > +allow list is behaving as expected. > +""" > + > +from time import sleep > + > +from scapy.layers.inet import IP # type: ignore[import-untyped] > +from scapy.layers.l2 import Dot1Q, Ether # type: ignore[import-untyped] > +from scapy.packet import Raw # type: ignore[import-untyped] > + > +from framework.exception import InteractiveCommandExecutionError > +from framework.remote_session.testpmd_shell import TestPmdShell > +from framework.test_suite import TestSuite > + > + > +class TestMacFilter(TestSuite): > + """Mac address allowlist filtering test suite. > + > + Configure mac address filtering on a given port, and test the port's > filtering behavior > + using both a given port's hardware address as well as dummy > addresses. If a port accepts > + a packet that is not contained within its mac address allowlist, the= n > a given test case > + fails. Alternatively, if a port drops a packet that is designated > within its mac address > + allowlist, a given test case will fail. > + > + Moreover, a given port should demonstrate proper behavior when bound > to the Poll Mode > + Driver. A port should not have a mac address allowlist that exceeds > its designated size. > + A port's default hardware address should not be removed from its > address pool, and invalid > + addresses should not be included in the allowlist. If a port abides > by the above rules, the > + test case passes. > + """ > + > + def send_packet_and_verify( > + self, > + mac_address: str, > + add_vlan: bool =3D False, > + should_receive: bool =3D True, > + ) -> None: > + """Generate, send, and verify a packet based on specified > parameters. > + > + Test cases within this suite utilize this method to create, send= , > and verify > + packets based on criteria relating to the packet's destination > mac address, > + vlan tag, and whether or not the packet should be received or > not. Packets > + are verified using an inserted payload. Assuming the test case > expects to > + receive a specified packet, if the list of received packets > contains this > + payload within any of its packets, the test case passes. > Alternatively, if > + the designed packet should not be received, and the packet > payload is not, > + received, then the test case fails. Each call with this method > sends exactly > + one packet. > + > + Args: > + mac_address: The destination mac address of the packet being > sent. > + add_vlan: If :data:'True', add a vlan tag to the packet bein= g > sent. The > + vlan tag will be :data:'2' if the packet should be > received and > + :data:'1' if the packet should not be received but > requires a vlan tag. > + should_receive: If :data:'True', assert whether or not the > sent packet > + has been received. If :data:'False', assert that the sen= d > packet was not > + received. :data:'True' by default > + """ > + if add_vlan: > + packet =3D Ether() / Dot1Q(vlan=3D2 if should_receive else 1= ) / > IP() / Raw(load=3D"X" * 22) > + else: > + packet =3D Ether() / IP() / Raw(load=3D"X" * 22) > + packet.dst =3D mac_address > + received_packets =3D [ > + packets > + for packets in self.send_packet_and_capture(packet, > adjust_addresses=3DFalse) > + if hasattr(packets, "load") and "X" * 22 in str(packets.load= ) > + ] > + if should_receive: > + self.verify(len(received_packets) =3D=3D 1, "Expected packet= not > received") > + else: > + self.verify(len(received_packets) =3D=3D 0, "Expected packet > received") > + > + def test_add_remove_mac_addresses(self) -> None: > + """Assess basic mac addressing filtering functionalities. > + > + This test case validates for proper behavior of mac address > filtering with both > + a port's default, burned-in mac address, as well as additional > mac addresses > + added to the PMD. Packets should either be received or not > received depending on > + the properties applied to the PMD at any given time. > + > + Test: > + Start TestPMD with promiscuous mode. > + Send a packet with the port's default mac address. (Should > receive) > + Send a packet with fake mac address. (Should not receive) > + Add fake mac address to the PMD's address pool. > + Send a packet with the fake mac address to the PMD. (Should > receive) > + Remove the fake mac address from the PMD's address pool. > + Sent a packet with the fake mac address to the PMD. (Should > not receive) > + """ > + testpmd =3D TestPmdShell(self.sut_node) > + testpmd.set_promisc(0, on=3DFalse) > + testpmd.start() > + mac_address =3D self._sut_port_ingress.mac_address > + > + # Send a packet with NIC default mac address > + self.send_packet_and_verify(mac_address=3Dmac_address, > should_receive=3DTrue) > + # Send a packet with different mac address > + fake_address =3D "00:00:00:00:00:01" > + self.send_packet_and_verify(mac_address=3Dfake_address, > should_receive=3DFalse) > + > + # Add mac address to pool and rerun tests > + testpmd.set_mac_addr(0, mac_address=3Dfake_address, add=3DTrue) > + self.send_packet_and_verify(mac_address=3Dfake_address, > should_receive=3DTrue) > + testpmd.set_mac_addr(0, mac_address=3Dfake_address, add=3DFalse) > + self.send_packet_and_verify(mac_address=3Dfake_address, > should_receive=3DFalse) > + testpmd.close() > + sleep(6) > + > + def test_invalid_address(self) -> None: > + """Assess the behavior of a NIC mac address pool while bound to > the PMD. > + > + An assessment of a NIC's behavior when mounted to a PMD as it > relates to mac addresses > + and address pooling. Devices should not be able to use invalid > mac addresses, remove their > + built-in hardware address, or exceed their address pools. > + > + Test: > + Start TestPMD. > + Attempt to add an invalid mac address. (Should fail) > + Attempt to remove the device's hardware address with no > additional addresses in the > + address pool. (Should fail) > + Add a fake mac address to the pool twice in succession. > (Should not create any errors) > + Attempt to remove the device's hardware address with other > addresses in the address > + pool. (Should fail) > + Determine the device's mac address pool size, and fill the > pool with fake addresses. > + Attempt to add another fake mac address, overloading the > address pool. (Should fail) > + """ > + testpmd =3D TestPmdShell(self.sut_node) > + testpmd.start() > + mac_address =3D self._sut_port_ingress.mac_address > + try: > + testpmd.set_mac_addr(0, "00:00:00:00:00:00", add=3DTrue) > + self.verify(False, "Invalid mac address added.") > + except InteractiveCommandExecutionError: > + pass > + try: > + testpmd.set_mac_addr(0, mac_address, add=3DFalse) > + self.verify(False, "Default mac address removed.") > + except InteractiveCommandExecutionError: > + pass > + # Should be no errors adding this twice > + testpmd.set_mac_addr(0, "1" + mac_address[1:], add=3DTrue) > + testpmd.set_mac_addr(0, "1" + mac_address[1:], add=3DTrue) > + # Double check to see if default mac address can be removed > + try: > + testpmd.set_mac_addr(0, mac_address, add=3DFalse) > + self.verify(False, "Default mac address removed.") > + except InteractiveCommandExecutionError: > + pass > + > + for i in range(testpmd.show_port_info(0).max_mac_addresses_num - > 1): > + # A0 fake address based on the index 'i'. > + fake_address =3D str(hex(i)[2:].zfill(12)) > + # Insert ':' characters every two indexes to create a fake > mac address. > + fake_address =3D ":".join(fake_address[x : x + 2] for x in > range(0, len(fake_address), 2)) > + testpmd.set_mac_addr(0, fake_address, add=3DTrue, verify=3DF= alse) > + try: > + testpmd.set_mac_addr(0, "F" + mac_address[1:], add=3DTrue) > + self.verify(False, "Mac address limit exceeded.") > + except InteractiveCommandExecutionError: > + pass > + testpmd.close() > + sleep(6) > + > + def test_multicast_filter(self) -> None: > + """Assess basic multicast address filtering functionalities. > + > + Ensure that multicast filtering performs as intended when a give= n > device is bound > + to the PMD, with and without dot1q vlan tagging. > + > + Test: > + Start TestPMD with promiscuous mode. > + Add a fake multicast address to the PMD's multicast address > pool. > + Send a packet with the fake multicast address to the PMD. > (Should receive) > + Set vlan filtering on the PMD, and add vlan ID to the PMD. > + Send a packet with the fake multicast address and vlan ID to > the PMD. (Should receive) > + Send a packet with the fake multicast address and a differen= t > vlan ID to the PMD. > + (Should not receive) > + Remove the vlan tag from the PMD, and turn vlan filtering of= f > on the PMD. > + Send a packet with the fake multicast address and no vlan ta= g > to the PMD. > + (Should receive) > + Remove the fake multicast address from the PMDs multicast > address filter. > + Send a packet with the fake multicast address to the PMD. > (Should not receive) > + """ > + testpmd =3D TestPmdShell(self.sut_node) > + testpmd.start() > + testpmd.set_promisc(0, on=3DFalse) > + multicast_address =3D "01:00:5E:00:00:00" > + vlan_id =3D 2 > + > + testpmd.set_multicast_mac_addr(0, multi_addr=3Dmulticast_address= , > add=3DTrue) > + self.send_packet_and_verify(multicast_address, > should_receive=3DTrue) > + > + # Test vlan filtering on multicast addressing. > + # Verify vlan functionality for debugging purposes. > + testpmd.vlan_filter_set_on(port=3D0) > + testpmd.rx_vlan_add(vlan_id, 0) > + self.send_packet_and_verify(multicast_address, > should_receive=3DTrue, add_vlan=3DTrue) > + self.send_packet_and_verify(multicast_address, > should_receive=3DFalse, add_vlan=3DTrue) > + > + # Remove vlan tag and filtering and run basic multicast addr tes= t. > + testpmd.rx_vlan_rm(vlan_id, 0) > + testpmd.vlan_filter_set_off(port=3D0) > + self.send_packet_and_verify(multicast_address, > should_receive=3DTrue) > + > + # Remove multicast filter and verify the packet was not received= . > + testpmd.set_multicast_mac_addr(0, multicast_address, add=3DFalse= ) > + self.send_packet_and_verify(multicast_address, > should_receive=3DFalse) > + testpmd.close() > + sleep(6) > -- > 2.44.0 > > --000000000000b700d9061dd5be9b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
<snip= >=C2=A0
+This test suite ensure= s proper and expected behavior of Allowlist=C2=A0f= iltering=C2=A0via=C2=A0mac
+addre= sses on devices bound to the Poll Mode Driver. If a packet received on a de= vice
+contains a=C2=A0mac=C2=A0address n= ot contained with its=C2=A0mac=C2=A0address= pool, the packet should
+be dropped. Alternatively, if a packet is rece= ived that contains a destination=C2=A0mac+within the devices address pool, the packet should be accepted and forwa= rded. This
+behavior should remain consistent across all packets, namely= those containing dot1q
+tags or otherwise.
=
This is pretty minor but you might want to change "with= its=C2=A0mac=C2=A0address pool" to &q= uot;within", just
to stay consistent with the wording in the= rest of the suite
=C2=A0
<snip>
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 received_packets =3D [
+=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 packets
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 for packets in self.send_packet_and_capture(packet, adjust_ad= dresses=3DFalse)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if hasattr(p= ackets, "load") and "X" * 22 in str(packets.load)
+= =C2=A0 =C2=A0 =C2=A0 =C2=A0 ]

Al= so Jeremy said he mentioned Juraj's opinion on using Jeremy's metho= d of turning off
adjust addresses, if you end up doing that just = make it depend on this patch:
patch-1142113 ("add send_packe= ts to test suites and rework
packet addressing")
=C2= =A0
Reviewed-by: Dean Marx <dmarx@iol.unh.edu>

On Thu, Jul 18, 2024 at= 3:40=E2=80=AFPM Nicholas Pratte <npratte@iol.unh.edu> wrote:
The mac address filter test suite, whose test cases are= based on old
DTS's test cases, has been refactored to interface with the new DTS
framework.

In porting over this test suite into the new framework, some
adjustments were made, namely in the EAL and TestPMD parameter provided
before executing the application. While the original test plan was
referenced, by and large, only for the individual test cases, I'll leav= e
the parameters the original test plan was asking for below for the sake
of discussion:

--burst=3D1 --rxpt=3D0 --rxht=3D0 --rxwt=3D0 --txpt=3D36 --txht=3D0 --txwt= =3D0
--txfreet=3D32 --rxfreet=3D64 --mbcache=3D250 --portmask=3D0x3

Bugzilla ID: 1454
Signed-off-by: Nicholas Pratte <npratte@iol.unh.edu>

---
v2:
=C2=A0* Refactored the address pool capacity tests to use all available
=C2=A0 =C2=A0octets in the mac address.
=C2=A0* Change the payload to 'X' characters instead of 'P'= characters.
---
=C2=A0dts/framework/config/conf_yaml_schema.json |=C2=A0 =C2=A03 +-
=C2=A0dts/tests/TestSuite_mac_filter.py=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 |= 223 +++++++++++++++++++++
=C2=A02 files changed, 225 insertions(+), 1 deletion(-)
=C2=A0create mode 100644 dts/tests/TestSuite_mac_filter.py

diff --git a/dts/framework/config/conf_yaml_schema.json b/dts/framework/con= fig/conf_yaml_schema.json
index f02a310bb5..ad1f3757f7 100644
--- a/dts/framework/config/conf_yaml_schema.json
+++ b/dts/framework/config/conf_yaml_schema.json
@@ -187,7 +187,8 @@
=C2=A0 =C2=A0 =C2=A0 =C2=A0"enum": [
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"hello_world",
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0"os_udp",
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 "pmd_buffer_scatter"
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 "pmd_buffer_scatter",
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 "mac_filter"
=C2=A0 =C2=A0 =C2=A0 =C2=A0]
=C2=A0 =C2=A0 =C2=A0},
=C2=A0 =C2=A0 =C2=A0"test_target": {
diff --git a/dts/tests/TestSuite_mac_filter.py b/dts/tests/TestSuite_mac_fi= lter.py
new file mode 100644
index 0000000000..53a3331224
--- /dev/null
+++ b/dts/tests/TestSuite_mac_filter.py
@@ -0,0 +1,223 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2023-2024 University of New Hampshire
+"""Mac address filtering test suite.
+
+This test suite ensures proper and expected behavior of Allowlist filterin= g via mac
+addresses on devices bound to the Poll Mode Driver. If a packet received o= n a device
+contains a mac address not contained with its mac address pool, the packet= should
+be dropped. Alternatively, if a packet is received that contains a destina= tion mac
+within the devices address pool, the packet should be accepted and forward= ed. This
+behavior should remain consistent across all packets, namely those contain= ing dot1q
+tags or otherwise.
+
+The following test suite assesses behaviors based on the aforementioned lo= gic.
+Additionally, testing is done within the PMD itself to ensure that the mac= address
+allow list is behaving as expected.
+"""
+
+from time import sleep
+
+from scapy.layers.inet import IP=C2=A0 # type: ignore[import-untyped]
+from scapy.layers.l2 import Dot1Q, Ether=C2=A0 # type: ignore[import-untyp= ed]
+from scapy.packet import Raw=C2=A0 # type: ignore[import-untyped]
+
+from framework.exception import InteractiveCommandExecutionError
+from framework.remote_session.testpmd_shell import TestPmdShell
+from framework.test_suite import TestSuite
+
+
+class TestMacFilter(TestSuite):
+=C2=A0 =C2=A0 """Mac address allowlist filtering test suite= .
+
+=C2=A0 =C2=A0 Configure mac address filtering on a given port, and test th= e port's filtering behavior
+=C2=A0 =C2=A0 using both a given port's hardware address as well as du= mmy addresses. If a port accepts
+=C2=A0 =C2=A0 a packet that is not contained within its mac address allowl= ist, then a given test case
+=C2=A0 =C2=A0 fails. Alternatively, if a port drops a packet that is desig= nated within its mac address
+=C2=A0 =C2=A0 allowlist, a given test case will fail.
+
+=C2=A0 =C2=A0 Moreover, a given port should demonstrate proper behavior wh= en bound to the Poll Mode
+=C2=A0 =C2=A0 Driver. A port should not have a mac address allowlist that = exceeds its designated size.
+=C2=A0 =C2=A0 A port's default hardware address should not be removed = from its address pool, and invalid
+=C2=A0 =C2=A0 addresses should not be included in the allowlist. If a port= abides by the above rules, the
+=C2=A0 =C2=A0 test case passes.
+=C2=A0 =C2=A0 """
+
+=C2=A0 =C2=A0 def send_packet_and_verify(
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 mac_address: str,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 add_vlan: bool =3D False,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 should_receive: bool =3D True,
+=C2=A0 =C2=A0 ) -> None:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Generate, send, and verify a= packet based on specified parameters.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Test cases within this suite utilize this meth= od to create, send, and verify
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 packets based on criteria relating to the pack= et's destination mac address,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 vlan tag, and whether or not the packet should= be received or not. Packets
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 are verified using an inserted payload. Assumi= ng the test case expects to
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 receive a specified packet, if the list of rec= eived packets contains this
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 payload within any of its packets, the test ca= se passes. Alternatively, if
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 the designed packet should not be received, an= d the packet payload is not,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 received, then the test case fails. Each call = with this method sends exactly
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 one packet.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Args:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 mac_address: The destination mac= address of the packet being sent.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 add_vlan: If :data:'True'= ;, add a vlan tag to the packet being sent. The
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 vlan tag will be := data:'2' if the packet should be received and
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 :data:'1' = if the packet should not be received but requires a vlan tag.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 should_receive: If :data:'Tr= ue', assert whether or not the sent packet
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 has been received.= If :data:'False', assert that the send packet was not
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 received. :data:&#= 39;True' by default
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if add_vlan:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 packet =3D Ether() / Dot1Q(vlan= =3D2 if should_receive else 1) / IP() / Raw(load=3D"X" * 22)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 else:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 packet =3D Ether() / IP() / Raw(= load=3D"X" * 22)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 packet.dst =3D mac_address
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 received_packets =3D [
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 packets
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 for packets in self.send_packet_= and_capture(packet, adjust_addresses=3DFalse)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if hasattr(packets, "load&q= uot;) and "X" * 22 in str(packets.load)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 ]
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if should_receive:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self.verify(len(received_packets= ) =3D=3D 1, "Expected packet not received")
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 else:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self.verify(len(received_packets= ) =3D=3D 0, "Expected packet received")
+
+=C2=A0 =C2=A0 def test_add_remove_mac_addresses(self) -> None:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Assess basic mac addressing = filtering functionalities.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 This test case validates for proper behavior o= f mac address filtering with both
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 a port's default, burned-in mac address, a= s well as additional mac addresses
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 added to the PMD. Packets should either be rec= eived or not received depending on
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 the properties applied to the PMD at any given= time.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Test:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Start TestPMD with promiscuous m= ode.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Send a packet with the port'= s default mac address. (Should receive)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Send a packet with fake mac addr= ess. (Should not receive)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Add fake mac address to the PMD&= #39;s address pool.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Send a packet with the fake mac = address to the PMD. (Should receive)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Remove the fake mac address from= the PMD's address pool.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Sent a packet with the fake mac = address to the PMD. (Should not receive)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd =3D TestPmdShell(self.sut_node)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd.set_promisc(0, on=3DFalse)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd.start()
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 mac_address =3D self._sut_port_ingress.mac_add= ress
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 # Send a packet with NIC default mac address +=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.send_packet_and_verify(mac_address=3Dmac_= address, should_receive=3DTrue)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 # Send a packet with different mac address
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 fake_address =3D "00:00:00:00:00:01"=
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.send_packet_and_verify(mac_address=3Dfake= _address, should_receive=3DFalse)
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 # Add mac address to pool and rerun tests
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd.set_mac_addr(0, mac_address=3Dfake_add= ress, add=3DTrue)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.send_packet_and_verify(mac_address=3Dfake= _address, should_receive=3DTrue)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd.set_mac_addr(0, mac_address=3Dfake_add= ress, add=3DFalse)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.send_packet_and_verify(mac_address=3Dfake= _address, should_receive=3DFalse)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd.close()
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 sleep(6)
+
+=C2=A0 =C2=A0 def test_invalid_address(self) -> None:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Assess the behavior of a NIC= mac address pool while bound to the PMD.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 An assessment of a NIC's behavior when mou= nted to a PMD as it relates to mac addresses
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 and address pooling. Devices should not be abl= e to use invalid mac addresses, remove their
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 built-in hardware address, or exceed their add= ress pools.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Test:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Start TestPMD.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Attempt to add an invalid mac ad= dress. (Should fail)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Attempt to remove the device'= ;s hardware address with no additional addresses in the
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 address pool. (Sho= uld fail)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Add a fake mac address to the po= ol twice in succession. (Should not create any errors)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Attempt to remove the device'= ;s hardware address with other addresses in the address
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 pool. (Should fail= )
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Determine the device's mac a= ddress pool size, and fill the pool with fake addresses.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Attempt to add another fake mac = address, overloading the address pool. (Should fail)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd =3D TestPmdShell(self.sut_node)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd.start()
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 mac_address =3D self._sut_port_ingress.mac_add= ress
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 try:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd.set_mac_addr(0, "00= :00:00:00:00:00", add=3DTrue)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self.verify(False, "Invalid= mac address added.")
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 except InteractiveCommandExecutionError:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 pass
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 try:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd.set_mac_addr(0, mac_addr= ess, add=3DFalse)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self.verify(False, "Default= mac address removed.")
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 except InteractiveCommandExecutionError:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 pass
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 # Should be no errors adding this twice
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd.set_mac_addr(0, "1" + mac_ad= dress[1:], add=3DTrue)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd.set_mac_addr(0, "1" + mac_ad= dress[1:], add=3DTrue)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 # Double check to see if default mac address c= an be removed
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 try:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd.set_mac_addr(0, mac_addr= ess, add=3DFalse)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self.verify(False, "Default= mac address removed.")
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 except InteractiveCommandExecutionError:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 pass
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 for i in range(testpmd.show_port_info(0).max_m= ac_addresses_num - 1):
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 # A0 fake address based on the i= ndex 'i'.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fake_address =3D str(hex(i)[2:].= zfill(12))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 # Insert ':' characters = every two indexes to create a fake mac address.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fake_address =3D ":".j= oin(fake_address[x : x + 2] for x in range(0, len(fake_address), 2))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd.set_mac_addr(0, fake_add= ress, add=3DTrue, verify=3DFalse)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 try:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd.set_mac_addr(0, "F&= quot; + mac_address[1:], add=3DTrue)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self.verify(False, "Mac add= ress limit exceeded.")
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 except InteractiveCommandExecutionError:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 pass
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd.close()
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 sleep(6)
+
+=C2=A0 =C2=A0 def test_multicast_filter(self) -> None:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Assess basic multicast addre= ss filtering functionalities.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Ensure that multicast filtering performs as in= tended when a given device is bound
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 to the PMD, with and without dot1q vlan taggin= g.
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 Test:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Start TestPMD with promiscuous m= ode.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Add a fake multicast address to = the PMD's multicast address pool.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Send a packet with the fake mult= icast address to the PMD. (Should receive)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Set vlan filtering on the PMD, a= nd add vlan ID to the PMD.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Send a packet with the fake mult= icast address and vlan ID to the PMD. (Should receive)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Send a packet with the fake mult= icast address and a different vlan ID to the PMD.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (Should not receiv= e)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Remove the vlan tag from the PMD= , and turn vlan filtering off on the PMD.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Send a packet with the fake mult= icast address and no vlan tag to the PMD.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (Should receive) +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Remove the fake multicast addres= s from the PMDs multicast address filter.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Send a packet with the fake mult= icast address to the PMD. (Should not receive)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 """
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd =3D TestPmdShell(self.sut_node)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd.start()
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd.set_promisc(0, on=3DFalse)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 multicast_address =3D "01:00:5E:00:00:00&= quot;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 vlan_id =3D 2
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd.set_multicast_mac_addr(0, multi_addr= =3Dmulticast_address, add=3DTrue)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.send_packet_and_verify(multicast_address,= should_receive=3DTrue)
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 # Test vlan filtering on multicast addressing.=
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 # Verify vlan functionality for debugging purp= oses.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd.vlan_filter_set_on(port=3D0)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd.rx_vlan_add(vlan_id, 0)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.send_packet_and_verify(multicast_address,= should_receive=3DTrue, add_vlan=3DTrue)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.send_packet_and_verify(multicast_address,= should_receive=3DFalse, add_vlan=3DTrue)
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 # Remove vlan tag and filtering and run basic = multicast addr test.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd.rx_vlan_rm(vlan_id, 0)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd.vlan_filter_set_off(port=3D0)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.send_packet_and_verify(multicast_address,= should_receive=3DTrue)
+
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 # Remove multicast filter and verify the packe= t was not received.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd.set_multicast_mac_addr(0, multicast_ad= dress, add=3DFalse)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.send_packet_and_verify(multicast_address,= should_receive=3DFalse)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 testpmd.close()
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 sleep(6)
--
2.44.0

--000000000000b700d9061dd5be9b--