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 0C6AC43864; Mon, 8 Jan 2024 13:02:00 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7F3D1402EF; Mon, 8 Jan 2024 13:01:59 +0100 (CET) Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) by mails.dpdk.org (Postfix) with ESMTP id 69B0C40263 for ; Mon, 8 Jan 2024 13:01:57 +0100 (CET) Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-50ea8fbf261so1690767e87.2 for ; Mon, 08 Jan 2024 04:01:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pantheon.tech; s=google; t=1704715317; x=1705320117; darn=dpdk.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=73wzeU7jxZuBdeYueMQOSsB+iB/skHoGlj5MwTbGroc=; b=aHfydBxideStEaaKZ/gf+s01wrNBBgpKbgwKZYvx3m71LySAS+2s2K/24w/ognMdww BH5w5oK75ItHacDOk/Mui2X3aoI3/XGRRqHharPKN0y5SFXMVp9wV+6z9HzVegCS9aig g2zWO/0Jatuc1z0DWboMgye7SCRrGew5soWavTo/DsYa3FAuQ0HtEUW8EkdZ/1Wh1+Vj EAr4eNO+BgEhmuaGvTjYPiXePiZ5IiywQldjgejndGGx5rSN2xW/eKIfqbPwcXJEGubu l9vKPULdntDTmLEIDPl+oB1Bc0/1hckBXg+V4fO1m/CUrBFoVOUfivU3+uqQXKABNR8a CjJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704715317; x=1705320117; h=content-transfer-encoding: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=73wzeU7jxZuBdeYueMQOSsB+iB/skHoGlj5MwTbGroc=; b=gA87Fe2Op9WdyZZA5z9OmP+iy0eWXuwvlw99cpPCUgMDt15ZCd/xVsxJRGlgFBVK+l zqD0s+It7+gD8QoMcpjJA26LxfV1QQ3+B4jG7BC7OMwXwynxV9dlhfxSMe++YWvwH8tB w5aizfli1jRE9fke8w21nfMar1JMatpOL8UfotLErln/bDlmP3iv+b918b9C23VACXeJ jUr3OBaCOwSZMjtrbsN1t0KQf26VBH0WxyYVArQWhDpZjj1FQslCYOWCtFcZV86kBNTx 6b1g8MESXxZchk48F3+RsW7yw8nJdiKuBC9vL4MTYj9861wvnttt4VNcv5VL8LhyRmVV 1FWg== X-Gm-Message-State: AOJu0Yx0KOFtRiyQjmOkFVued6+Q8JgDUWprpezty+1lSW59Ga2SC3nr 94WUWxUzyT5BLrF5oblD5296JCA2s1Kl8YUkDjPp6YDAtYWprw== X-Google-Smtp-Source: AGHT+IGw4l6YwuS9VejzD+spVHdSZi/nx06W9h7Vsp4OdEfXmu4NluyrDOoS6Rob1rDezaqRDKV9dpgtTj8OwWvSxD8= X-Received: by 2002:a05:6512:1188:b0:50e:a8ac:8ff9 with SMTP id g8-20020a056512118800b0050ea8ac8ff9mr1678428lfr.14.1704715316883; Mon, 08 Jan 2024 04:01:56 -0800 (PST) MIME-Version: 1.0 References: <20240103221217.18954-1-jspewock@iol.unh.edu> <20240103223206.23129-1-jspewock@iol.unh.edu> <20240103223206.23129-4-jspewock@iol.unh.edu> In-Reply-To: <20240103223206.23129-4-jspewock@iol.unh.edu> From: =?UTF-8?Q?Juraj_Linke=C5=A1?= Date: Mon, 8 Jan 2024 13:01:46 +0100 Message-ID: Subject: Re: [PATCH v6 3/7] dts: add optional packet filtering to scapy sniffer To: jspewock@iol.unh.edu Cc: Honnappa.Nagarahalli@arm.com, thomas@monjalon.net, wathsala.vithanage@arm.com, probb@iol.unh.edu, paul.szczepanek@arm.com, yoan.picchi@foss.arm.com, lylavoie@iol.unh.edu, ferruh.yigit@amd.com, andrew.rybchenko@oktetlabs.ru, dev@dpdk.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 On Wed, Jan 3, 2024 at 11:33=E2=80=AFPM wrote: > > From: Jeremy Spewock > > Added the options to filter out LLDP and ARP packets when > sniffing for packets with scapy. This was done using BPF filters to > ensure that the noise these packets provide does not interfere with test > cases. > > Signed-off-by: Jeremy Spewock > --- > dts/framework/test_suite.py | 15 +++++++++-- > dts/framework/testbed_model/tg_node.py | 14 ++++++++-- > .../traffic_generator/__init__.py | 7 ++++- > .../capturing_traffic_generator.py | 22 ++++++++++++++- > .../testbed_model/traffic_generator/scapy.py | 27 +++++++++++++++++++ > 5 files changed, 79 insertions(+), 6 deletions(-) > > diff --git a/dts/framework/testbed_model/traffic_generator/capturing_traf= fic_generator.py b/dts/framework/testbed_model/traffic_generator/capturing_= traffic_generator.py > index 0246590333..c1c9facedd 100644 > --- a/dts/framework/testbed_model/traffic_generator/capturing_traffic_gen= erator.py > +++ b/dts/framework/testbed_model/traffic_generator/capturing_traffic_gen= erator.py > @@ -26,6 +27,19 @@ def _get_default_capture_name() -> str: > return str(uuid.uuid4()) > > > +@dataclass(slots=3DTrue) This should also be frozen. If we need a different filter, it's better to create a new object I think. > +class PacketFilteringConfig: > + """The supported filtering options for :class:`CapturingTrafficGener= ator`. > + > + Attributes: > + no_lldp: If :data:`True`, LLDP packets will be filtered out when= capturing. > + no_arp: If :data:`True`, ARP packets will be filtered out when c= apturing. > + """ > + > + no_lldp: bool =3D True > + no_arp: bool =3D True > + > + > class CapturingTrafficGenerator(TrafficGenerator): > """Capture packets after sending traffic. > > diff --git a/dts/framework/testbed_model/traffic_generator/scapy.py b/dts= /framework/testbed_model/traffic_generator/scapy.py > index 5b60f66237..505de0be94 100644 > --- a/dts/framework/testbed_model/traffic_generator/scapy.py > +++ b/dts/framework/testbed_model/traffic_generator/scapy.py > @@ -260,11 +263,34 @@ def _send_packets(self, packets: list[Packet], port= : Port) -> None: > packets =3D [packet.build() for packet in packets] > self.rpc_server_proxy.scapy_send_packets(packets, port.logical_n= ame) > > + def _create_packet_filter(self, filter_config: PacketFilteringConfig= ) -> str: > + """Combines filter settings from `filter_config` into a BPF that= scapy can use. > + > + Scapy allows for the use of Berkeley Packet Filters (BPFs) to fi= lter what packets are > + collected based on various attributes of the packet. > + > + Args: > + filter_config: Config class that specifies which filters sho= uld be applied. > + > + Returns: > + A string representing the combination of BPF filters to be p= assed to scapy. For > + example: > + > + "ether[12:2] !=3D 0x88cc && ether[12:2] !=3D 0x0806" > + """ > + bpf_filter: list[str] =3D [] The type hint here is not needed, so let's make this consistent with the rest of the code - we don't specify local type hints if they're not necessary. > + if filter_config.no_arp: > + bpf_filter.append("ether[12:2] !=3D 0x0806") > + if filter_config.no_lldp: > + bpf_filter.append("ether[12:2] !=3D 0x88cc") > + return " && ".join(bpf_filter) > + > def _send_packets_and_capture( > self, > packets: list[Packet], > send_port: Port, > receive_port: Port, > + filter_config: PacketFilteringConfig, > duration: float, > capture_name: str =3D _get_default_capture_name(), > ) -> list[Packet]: