DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Juraj Linkeš" <juraj.linkes@pantheon.tech>
To: Dean Marx <dmarx@iol.unh.edu>,
	probb@iol.unh.edu, npratte@iol.unh.edu, jspewock@iol.unh.edu,
	luca.vizzarro@arm.com, yoan.picchi@foss.arm.com,
	Honnappa.Nagarahalli@arm.com, paul.szczepanek@arm.com
Cc: dev@dpdk.org
Subject: Re: [PATCH v3] dts: add flow rule dataclass to testpmd shell
Date: Wed, 25 Sep 2024 10:17:47 +0200	[thread overview]
Message-ID: <a3182f37-25eb-4ce4-bf86-996496557b65@pantheon.tech> (raw)
In-Reply-To: <20240813144107.6195-1-dmarx@iol.unh.edu>



On 13. 8. 2024 16:41, Dean Marx wrote:
> add dataclass for passing in flow rule creation arguments, as well as a

Capitalize please.

> __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 <dmarx@iol.unh.edu>
> ---
>   dts/framework/remote_session/testpmd_shell.py | 57 +++++++++++++++++++
>   1 file changed, 57 insertions(+)
> 
> diff --git a/dts/framework/remote_session/testpmd_shell.py b/dts/framework/remote_session/testpmd_shell.py
> index 43e9f56517..17b9c7811d 100644
> --- a/dts/framework/remote_session/testpmd_shell.py
> +++ b/dts/framework/remote_session/testpmd_shell.py
> @@ -577,6 +577,44 @@ class TestPmdPortStats(TextParser):
>       tx_bps: int = field(metadata=TextParser.find_int(r"Tx-bps:\s+(\d+)"))
>   
>   
> +@dataclass
> +class FlowRule:
> +    """Dataclass for setting flow rule parameters."""
> +
> +    #:
> +    port_id: int
> +    #:
> +    ingress: bool
> +    #:
> +    pattern: str
> +    #:
> +    actions: str
> +
> +    #:
> +    group_id: int | None = None
> +    #:
> +    priority_level: int | None = None
> +    #:
> +    user_id: int | None = None
> +
> +    def __str__(self) -> str:
> +        """Returns the string representation of a flow_func instance.
> +
> +        In this case, a properly formatted flow create command that can be sent to testpmd.

I think it would be beneficial for a complicated command like this to 
add the actual format of the command as returned by testpmd, which 
should be (according to app/test-pmd/cmdline.c):

flow create {port_id}
  [group {group_id}] [priority {level}]
  [ingress] [egress]
  pattern {item} [/ {item} [...]] / end
  actions {action} [/ {action} [...]] / end

Looking at this, there could be multiple patterns and actions. Maybe we 
should add classes for these two as well - what do the patterns and 
actions look like?

> +        """
> +        ret = f"flow create {self.port_id} "
> +        if self.group_id is not None:
> +            ret += f"group {self.group_id} "
> +        if self.priority_level is not None:
> +            ret += f"priority {self.priority_level} "
> +        ret += "ingress " if self.ingress else "egress "
> +        if self.user_id is not None:
> +            ret += f"user_id {self.user_id} "
> +        ret += f"pattern {self.pattern} / end "
> +        ret += f"actions {self.actions} / end"
> +        return ret
> +
> +
>   class TestPmdShell(DPDKShell):
>       """Testpmd interactive shell.
>   
> @@ -806,6 +844,25 @@ def show_port_stats(self, port_id: int) -> TestPmdPortStats:
>   
>           return TestPmdPortStats.parse(output)
>   
> +    def flow_create(self, cmd: FlowRule, verify: bool = True) -> None:

Do we also need to add a method for deleting (I guess it would be called 
destroying per the command) the rule? Or any other flow rule commands? 
We could expand the test suite (I assume we're adding this because of a 
test suite) if such tests make sense.

> +        """Creates a flow rule in the testpmd session.
> +
> +        Args:
> +            cmd: String from flow_func instance to send as a flow rule.

The cmd docstring has not been updated. I'd also rename cmd to flow_rule.

> +            verify: If :data:`True`, the output of the command is scanned
> +            to ensure the flow rule was created successfully.
> +
> +        Raises:
> +            InteractiveCommandExecutionError: If flow rule is invalid.
> +        """
> +        flow_output = self.send_command(str(cmd))
> +        if verify:
> +            if "created" not in flow_output:
> +                self._logger.debug(f"Failed to create flow rule:\n{flow_output}")
> +                raise InteractiveCommandExecutionError(
> +                    f"Failed to create flow rule:\n{flow_output}"
> +                )
> +
>       def _close(self) -> None:
>           """Overrides :meth:`~.interactive_shell.close`."""
>           self.stop()


      reply	other threads:[~2024-09-25  8:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-26 14:22 [PATCH v1] " Dean Marx
2024-08-02 20:49 ` Jeremy Spewock
2024-08-06 16:42 ` [PATCH v2] " Dean Marx
2024-08-13 14:39   ` [PATCH v3] " Dean Marx
2024-08-13 14:41   ` Dean Marx
2024-09-25  8:17     ` Juraj Linkeš [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a3182f37-25eb-4ce4-bf86-996496557b65@pantheon.tech \
    --to=juraj.linkes@pantheon.tech \
    --cc=Honnappa.Nagarahalli@arm.com \
    --cc=dev@dpdk.org \
    --cc=dmarx@iol.unh.edu \
    --cc=jspewock@iol.unh.edu \
    --cc=luca.vizzarro@arm.com \
    --cc=npratte@iol.unh.edu \
    --cc=paul.szczepanek@arm.com \
    --cc=probb@iol.unh.edu \
    --cc=yoan.picchi@foss.arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).