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 8F05B45721; Fri, 2 Aug 2024 22:53:50 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6693840DD3; Fri, 2 Aug 2024 22:53:50 +0200 (CEST) Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by mails.dpdk.org (Postfix) with ESMTP id C665240B90 for ; Fri, 2 Aug 2024 22:53:49 +0200 (CEST) Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-2cb81c0ecb4so2717545a91.0 for ; Fri, 02 Aug 2024 13:53:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1722632029; x=1723236829; 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=nNjBASqt8JvI3lYI7BLHDiOB1SjUF9gR07Kzq0ixCI4=; b=S3UoppD7SGRZLOdcMAHv19PwAJPDq9QO54kK+Ko0l222ZTWBD78YhqRRSw3sEGG/9A tig6QYXqoBEucvlHYmXnRMiucDCis5CX4GQUeBZBonqj82R8x/NHbU8uJIG94aTY1ylz Z9aNXG6rOAsvMAWVSUulkLb7zsocrEQ0mK+wI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722632029; x=1723236829; 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=nNjBASqt8JvI3lYI7BLHDiOB1SjUF9gR07Kzq0ixCI4=; b=RNFF14+tKv66MSdt8aZw/o0LR26QyPdl0OgIx1VMQOnNAo3gYFUmt2xg62/iPC8TLy gOY5e3oNx/ZCjPw/O0wmjXmI15zNC8V4kd5j4xi4+uxPLGormDh97n2ABPVQaZRq68UV I1izWyM9L4yJ9BxsI/AL/XhehibFR83qOEcfSY0a95gCe+y0OGo2FQr/YdQ0UEBLfIXd 2dSe+3N9U90JF7hg0HRtLXeUViq+G+EFbgG901HAo8YuMFHB4Swpk5lQK5IAUcUr9jen XVv+rb62eniDF/dGCrBvLKwfL4hCi8dak2bpGc61Msv0Lw+LjcqK9Ak/vw6P/uKDCrtn GpXw== X-Forwarded-Encrypted: i=1; AJvYcCX6Bz7UglBxDKlDb3R7sG7cJm/7EGSOPlZYINtuzKVV1yVcYp+j5St9KYOsVRgHW8HKpA7lveRzK3FgZ2k= X-Gm-Message-State: AOJu0YxdMav2ko0q1yqVWXUpbQfPUAr2Zj6S5ntNSHJVzFJz4EuKdak6 FOsvaKFJFmHi/EPKLvTXZFj0c3OJvzaQ4WOmSmK6b5Rca7jUTsvnEvl+X56UjQ/1lYd+w8AbGAC emJ+pODlBolDw43u9ArxyfisQlOPihA14TofpBw== X-Google-Smtp-Source: AGHT+IHjC89HVF49oUNC3PbTZiQd8texUv5jiCtulfkxA3nbGxOsPT8mk3T/TDaNbpwp2L53HdmzftHTkGZVILU3Od8= X-Received: by 2002:a17:90a:b115:b0:2c9:63fb:d3ab with SMTP id 98e67ed59e1d1-2cffa2bf505mr7320565a91.22.1722632028778; Fri, 02 Aug 2024 13:53:48 -0700 (PDT) MIME-Version: 1.0 References: <20240726141548.688-1-dmarx@iol.unh.edu> <15f1aeb5-3123-4c87-90b7-46b43323a6db@arm.com> In-Reply-To: <15f1aeb5-3123-4c87-90b7-46b43323a6db@arm.com> From: Jeremy Spewock Date: Fri, 2 Aug 2024 16:53:37 -0400 Message-ID: Subject: Re: [PATCH v2] dts: add flow rule dataclass to testpmd shell To: Luca Vizzarro Cc: Dean Marx , probb@iol.unh.edu, npratte@iol.unh.edu, yoan.picchi@foss.arm.com, Honnappa.Nagarahalli@arm.com, paul.szczepanek@arm.com, juraj.linkes@pantheon.tech, 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 Thu, Aug 1, 2024 at 5:24=E2=80=AFAM Luca Vizzarro wrote: > > Hi Dean, thank you for your work! Some minor comments. > > On 26/07/2024 15:15, Dean Marx wrote: > > add dataclass for passing in flow rule creation arguments, as well as a > > __str__ method for converting to a sendable testpmd command. Add > > flow_create method to TestPmdShell class for initializing flow rules. > > > > Signed-off-by: Dean Marx > > --- > > dts/framework/remote_session/testpmd_shell.py | 58 ++++++++++++++++++= - > > 1 file changed, 57 insertions(+), 1 deletion(-) > > > > diff --git a/dts/framework/remote_session/testpmd_shell.py b/dts/framew= ork/remote_session/testpmd_shell.py > > index eda6eb320f..d6c111da0a 100644 > > --- a/dts/framework/remote_session/testpmd_shell.py > > +++ b/dts/framework/remote_session/testpmd_shell.py > > @@ -19,7 +19,7 @@ > > from dataclasses import dataclass, field > > from enum import Flag, auto > > from pathlib import PurePath > > -from typing import ClassVar > > +from typing import ClassVar, Optional > > > > from typing_extensions import Self, Unpack > > > > @@ -577,6 +577,43 @@ class TestPmdPortStats(TextParser): > > tx_bps: int =3D field(metadata=3DTextParser.find_int(r"Tx-bps:\s+= (\d+)")) > > > > > > +@dataclass > > +class flow_func: > Class names should be UpperCamelCase, also should be a suitable name for > what it's describing. I believe FlowRule should work. > > + """Dataclass for setting flow rule parameters.""" > > + > > + #: > > + port_id: int > > + #: > > + ingress: bool > > + #: > > + pattern: str > > + #: > > + actions: str > > + > > + #: > > + group_id: Optional[int] =3D None > > + #: > > + priority_level: Optional[int] =3D None > > + #: > > + user_id: Optional[int] =3D None > Optional[..] is an outdated notation. `int | None` is preferred instead. > See PEP 604[1]. > > + > > + def __str__(self) -> str: > > + """Returns the string representation of a flow_func instance. > > + > > + In this case, a properly formatted flow create command that ca= n be sent to testpmd. > > + """ > > + ret =3D [] > > + ret.append(f"flow create {self.port_id} ") > > + ret.append(f"group {self.group_id} " if self.group_id is not N= one else "") > > + ret.append(f"priority {self.priority_level} " if self.priority= _level is not None else "") > > + ret.append("ingress " if self.ingress else "egress ") > > + ret.append(f"user_id {self.user_id} " if self.user_id is not N= one else "") > > + ret.append(f"pattern {self.pattern} ") > > + ret.append(" / end actions ") > > + ret.append(f"{self.actions} / end") > > + return "".join(ret) > > Using a list with inline conditional appending is not particularly > readable. A regular string with conditional appending should do: > > ret =3D f"flow create {self.port_id} " > if self.group_id is not None: > ret +=3D f"group {self.group_id} " > ... > > Also the latest three append lines can all be in one, if you like the > separation you can just do a multi-line string: > > ret +=3D ( > f"pattern {self.pattern} / end " > f"actions {self.actions} / end" > ) > # or actually this may be just fine: > ret +=3D f"pattern {self.pattern} / end " > ret +=3D f"actions {self.actions} / end" > > I guess the way it's split is more of a game changer. > > If you really want to use a list (in a way that is similar to what I've > described here) then I'd take advantage of it... by omitting leading and > trailing whitespaces and then use the join to add them in between: " > ".join(ret) > > > + > > + > > class TestPmdShell(DPDKShell): > > """Testpmd interactive shell. > > > > @@ -804,6 +841,25 @@ def show_port_stats(self, port_id: int) -> TestPmd= PortStats: > > > > return TestPmdPortStats.parse(output) > > > > + def flow_create(self, cmd: str, verify: bool =3D True) -> None: > > Not a comment, but a discussion point. Normally we'd want a function to > be read as an action such as: > > create_flow > > But I understand this is basically mirroring the command format... I > wonder which one would be the best. I am personally inclined in verb > first. Maybe others can give their opinion. That's funny because Patrick also raised this point about whether to use a more testpmd-oriented naming scheme or a more human-readable one. I forget which patch it was on exactly, but Patrick did raise a good point that if our goal is to have DPDK developers be able to easily pick up and work with this API, they'll probably be more familiar with the testpmd methods as they are now. I also lean more towards the verb first method just because it makes it more readable I think, but I can't speak for DPDK developers. Even if it were `create_flow` though I'm sure people can just type `testpmd.flow` and their IDE will be able to help with the auto-complete for the flow rule options. Maybe it is something we should discuss more however since it is come up twice now. > > + """Creates a flow rule in the testpmd session. > > + > > + Args: > > + cmd: String from flow_func instance to send as a flow rule= . > > + verify: If :data:`True`, the output of the command is scan= ned > > + to ensure the flow rule was created successfully. > > + > > + Raises: > > + InteractiveCommandExecutionError: If flow rule is invalid. > > + """ > > + flow_output =3D self.send_command(cmd) > > + if verify: > > + if "created" not in flow_output: > > + self._logger.debug(f"Failed to create flow rule:\n{flo= w_output}") > > + raise InteractiveCommandExecutionError( > > + f"Failed to create flow rule:\n{flow_output}" > > + ) > > + > > def _close(self) -> None: > > """Overrides :meth:`~.interactive_shell.close`.""" > > self.stop() > > [1] https://peps.python.org/pep-0604/ >