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 4F6B243866; Mon, 8 Jan 2024 17:39:38 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2C55E40693; Mon, 8 Jan 2024 17:39:38 +0100 (CET) Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by mails.dpdk.org (Postfix) with ESMTP id 8312740273 for ; Mon, 8 Jan 2024 17:39:36 +0100 (CET) Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-6daa89a6452so944800b3a.2 for ; Mon, 08 Jan 2024 08:39:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1704731976; x=1705336776; 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=H72Y2kYEdOszVs6Nk66zR60pujgJokJbnSeu7VgXcYs=; b=H/ghb2P3e4VgV0rjhOaBp0KhwCTkGV0YnMiRp1YQDpXz1I3reM4Zz9vK/8t7RBqRK7 wahfnC54QjSA3JEZKFC1tlFDc9reWFTpPSTGIOiGytfeJI5XFunOOb2a7M5Yb1ndBzlj 6pezyQs+FMsgDPtiUGQgZSSsRsVJec7yJ+GZ8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704731976; x=1705336776; 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=H72Y2kYEdOszVs6Nk66zR60pujgJokJbnSeu7VgXcYs=; b=Qz2g1BGSyzFrvgSLK13DWJO7J+1Jm+k/L0ZMC4giZ4m2wtQUNMDmE2Hrood9AJ/SsR 90tRiZ4sNzp34BjkwIJE2H0v1qCwzReaPK4fZyzt+Jr9Fpro3kkHFaCqkgPFaPPyvQ82 g/cwz6E/XcC5spL/s7zU+qjJryYiZ6VrAOIplhrFheKc0NjFoxaJ8ztJddGnXSNV4NUi ppt4AlDMzx3KaQWzxb+oEjVXBD+tx4rN75ot7zP9pOw7R/xXOvGA6D57uQGYzSPYTYJq zn7RGQD5KcGFcLigWllo7+1N19ClxlR177zWC9jycF0CjbSsWRfiodomOC2mEWJDgQ9r +zyQ== X-Gm-Message-State: AOJu0Yz9xwXzoWn9ETtNtUPb1X+9kbsdhDnCU7ASMH7LrikGAuGKTyxI +ncxAhNzZ7dGS+7rLVGSJyqLgFiM2iS3XkKHgawpvOYbb946sw== X-Google-Smtp-Source: AGHT+IGIjrvJj+WjLeS+YkJjCB8R9Nw+QGaSwsBwHHRwnLztJ+oUAwf/q+OLj2Zqyi/0so0LxXS0rVfUdstFscas07Q= X-Received: by 2002:a05:6a00:8d97:b0:6da:a81e:b3a9 with SMTP id im23-20020a056a008d9700b006daa81eb3a9mr1776610pfb.49.1704731975758; Mon, 08 Jan 2024 08:39:35 -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: From: Jeremy Spewock Date: Mon, 8 Jan 2024 11:39:24 -0500 Message-ID: Subject: Re: [PATCH v6 3/7] dts: add optional packet filtering to scapy sniffer To: =?UTF-8?Q?Juraj_Linke=C5=A1?= 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: multipart/alternative; boundary="000000000000da4d20060e71d7fa" 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 --000000000000da4d20060e71d7fa Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Jan 8, 2024 at 7:01=E2=80=AFAM Juraj Linke=C5=A1 wrote: > 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 tes= t > > 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_traffic_generat= or.py > b/dts/framework/testbed_model/traffic_generator/capturing_traffic_generat= or.py > > index 0246590333..c1c9facedd 100644 > > --- > a/dts/framework/testbed_model/traffic_generator/capturing_traffic_generat= or.py > > +++ > b/dts/framework/testbed_model/traffic_generator/capturing_traffic_generat= or.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:`CapturingTrafficGenerator`. > > + > > + 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 > capturing. > > + """ > > + > > + 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_name) > > > > + 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 > filter what packets are > > + collected based on various attributes of the packet. > > + > > + Args: > > + filter_config: Config class that specifies which filters > should be applied. > > + > > + Returns: > > + A string representing the combination of BPF filters to be > passed 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. > Good catch, this might have been left over from when I was experimenting with formatting the filters, I'll remove it. > > > + 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]: > --000000000000da4d20060e71d7fa Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


<= div dir=3D"ltr" class=3D"gmail_attr">On Mon, Jan 8, 2024 at 7:01=E2=80=AFAM= Juraj Linke=C5=A1 <juraj.linkes@pantheon.tech> wrote:
On Wed, Jan 3, 2024 at 11:33= =E2=80=AFPM <j= spewock@iol.unh.edu> wrote:
>
> From: Jeremy Spewock <jspewock@iol.unh.edu>
>
> 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 te= st
> cases.
>
> Signed-off-by: Jeremy Spewock <jspewock@iol.unh.edu>
> ---
>=C2=A0 dts/framework/test_suite.py=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| 15 +++++++++--
>=C2=A0 dts/framework/testbed_model/tg_node.py=C2=A0 =C2=A0 =C2=A0 =C2= =A0 | 14 ++++++++--
>=C2=A0 .../traffic_generator/__init__.py=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0|=C2=A0 7 ++++-
>=C2=A0 .../capturing_traffic_generator.py=C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 | 22 ++++++++++++++-
>=C2=A0 .../testbed_model/traffic_generator/scapy.py=C2=A0 | 27 ++++++++= +++++++++++
>=C2=A0 5 files changed, 79 insertions(+), 6 deletions(-)
>

<snip>

> diff --git a/dts/framework/testbed_model/traffic_generator/capturing_t= raffic_generator.py b/dts/framework/testbed_model/traffic_generator/capturi= ng_traffic_generator.py
> index 0246590333..c1c9facedd 100644
> --- a/dts/framework/testbed_model/traffic_generator/capturing_traffic_= generator.py
> +++ b/dts/framework/testbed_model/traffic_generator/capturing_traffic_= generator.py
<snip>
> @@ -26,6 +27,19 @@ def _get_default_capture_name() -> str:
>=C2=A0 =C2=A0 =C2=A0 return str(uuid.uuid4())
>
>
> +@dataclass(slots=3DTrue)

This should also be frozen. If we need a different filter, it's better<= br> to create a new object I think.

> +class PacketFilteringConfig:
> +=C2=A0 =C2=A0 """The supported filtering options for := class:`CapturingTrafficGenerator`.
> +
> +=C2=A0 =C2=A0 Attributes:
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 no_lldp: If :data:`True`, LLDP packets wi= ll be filtered out when capturing.
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 no_arp: If :data:`True`, ARP packets will= be filtered out when capturing.
> +=C2=A0 =C2=A0 """
> +
> +=C2=A0 =C2=A0 no_lldp: bool =3D True
> +=C2=A0 =C2=A0 no_arp: bool =3D True
> +
> +
>=C2=A0 class CapturingTrafficGenerator(TrafficGenerator):
>=C2=A0 =C2=A0 =C2=A0 """Capture packets after sending tr= affic.
>
<snip>
> 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
<snip>
> @@ -260,11 +263,34 @@ def _send_packets(self, packets: list[Packet], p= ort: Port) -> None:
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 packets =3D [packet.build() for pack= et in packets]
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self.rpc_server_proxy.scapy_send_pac= kets(packets, port.logical_name)
>
> +=C2=A0 =C2=A0 def _create_packet_filter(self, filter_config: PacketFi= lteringConfig) -> str:
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 """Combines filter setting= s from `filter_config` into a BPF that scapy can use.
> +
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 Scapy allows for the use of Berkeley Pack= et Filters (BPFs) to filter what packets are
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 collected based on various attributes of = the packet.
> +
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 Args:
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 filter_config: Config class= that specifies which filters should be applied.
> +
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 Returns:
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 A string representing the c= ombination of BPF filters to be passed to scapy. For
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 example:
> +
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "ether[12:2] !=3D 0x88= cc && ether[12:2] !=3D 0x0806"
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 """
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 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.

Good catch, this might have bee= n left over from when I was experimenting with formatting the filters, I= 9;ll remove it.
=C2=A0

> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if filter_config.no_arp:
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 bpf_filter.append("eth= er[12:2] !=3D 0x0806")
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if filter_config.no_lldp:
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 bpf_filter.append("eth= er[12:2] !=3D 0x88cc")
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 return " && ".join(bpf_= filter)
> +
>=C2=A0 =C2=A0 =C2=A0 def _send_packets_and_capture(
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self,
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 packets: list[Packet],
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 send_port: Port,
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 receive_port: Port,
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 filter_config: PacketFilteringConfig,
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 duration: float,
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 capture_name: str =3D _get_default_c= apture_name(),
>=C2=A0 =C2=A0 =C2=A0 ) -> list[Packet]:
--000000000000da4d20060e71d7fa--