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 D3E45456B8; Fri, 26 Jul 2024 16:22:24 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6746143278; Fri, 26 Jul 2024 16:22:24 +0200 (CEST) Received: from mail-ot1-f51.google.com (mail-ot1-f51.google.com [209.85.210.51]) by mails.dpdk.org (Postfix) with ESMTP id D4C744281D for ; Fri, 26 Jul 2024 16:22:22 +0200 (CEST) Received: by mail-ot1-f51.google.com with SMTP id 46e09a7af769-7093f3a1af9so101541a34.1 for ; Fri, 26 Jul 2024 07:22:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1722003742; x=1722608542; darn=dpdk.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=dO2j77Tx/yWwjn1+uQwQfCQFjoif8b65lW+r2H1oZMw=; b=QwW+8YlagsnlU+9CrBKFGdjlCdtNs4ZNrgQ7U1kAfbvwudjyD9d6L98nOAuieUQS/z XtWSg3whwcQKmMtisS0jFrHYvcfbZ2fUKInyRPef00l2tE/YWXnPRWHyTui3MQkKuEdv QQQvQ1zKHZwko38oKmjhgOjTgiMVitqiTi4ng= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722003742; x=1722608542; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dO2j77Tx/yWwjn1+uQwQfCQFjoif8b65lW+r2H1oZMw=; b=ZcbpSGHWtGfdzH1iIDD9KQXRjq9fda7QHYkPfUC2cltM7MIl16l+LP3mBd8mkyjh58 A7ndg3TGP/a+rJOy9KUwNonRWXslWQXYGdY1aj7AmhduoSK5kI5zm4zDcNC4gdanUwDg o39oczDqRmqpgowPOH2EWiEzthUXUwv2MYWm8PbcRRdnWx4vhyyIj575IpLTD3xkbEnI DL773QKo0eLr15VX8AaMJvYoFEX7ccGkm7/drb6cxN2AiueRF5w9DAiKo7KZSe6cZcDD n19WuwZRC1C8anxVCT5wCBnVLILD4SogZ0BkAD10JQV5XMBpV4CBilOnYi1q4HRx+BQ+ 5PLA== X-Gm-Message-State: AOJu0YwsDuuGMk/3QxSKCjP2W36qedti3PwMTRrTaZuKUwbbRQTdmzS2 iIRfEulk4wiwB0sRqd8MjU/VGtcar2UQMQspFiOUyMixOLnGiVuxsy9UHBEHgH0= X-Google-Smtp-Source: AGHT+IEGAM0FQGFaqFPqXwExiONtyeZV68Pid2BDNYA49PlAMTGOq4Hz/C//wv8Rfx+DaFOEdUunlA== X-Received: by 2002:a05:6358:579e:b0:1aa:d121:d1cb with SMTP id e5c5f4694b2df-1acfb8f29demr691812155d.18.1722003741807; Fri, 26 Jul 2024 07:22:21 -0700 (PDT) Received: from dean-laptop.iol.unh.edu ([2606:4100:3880:1271:f9bd:24da:464d:6294]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6bb3f9143e1sm16862246d6.61.2024.07.26.07.22.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jul 2024 07:22:21 -0700 (PDT) From: Dean Marx To: 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, juraj.linkes@pantheon.tech Cc: dev@dpdk.org, Dean Marx Subject: [PATCH v1] dts: add flow rule dataclass to testpmd shell Date: Fri, 26 Jul 2024 10:22:13 -0400 Message-ID: <20240726142213.3109-1-dmarx@iol.unh.edu> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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/framework/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 = field(metadata=TextParser.find_int(r"Tx-bps:\s+(\d+)")) +@dataclass +class flow_func: + """Dataclass for setting flow rule parameters.""" + + #: + port_id: int + #: + ingress: bool + #: + pattern: str + #: + actions: str + + #: + group_id: Optional[int] = None + #: + priority_level: Optional[int] = None + #: + user_id: Optional[int] = 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. + """ + ret = [] + ret.append(f"flow create {self.port_id} ") + ret.append(f"group {self.group_id} " if self.group_id is not None 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 None else "") + ret.append(f"pattern {self.pattern} ") + ret.append(" / end actions ") + ret.append(f"{self.actions} / end") + return "".join(ret) + + class TestPmdShell(DPDKShell): """Testpmd interactive shell. @@ -804,6 +841,25 @@ def show_port_stats(self, port_id: int) -> TestPmdPortStats: return TestPmdPortStats.parse(output) + def flow_create(self, cmd: str, verify: bool = True) -> None: + """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 scanned + to ensure the flow rule was created successfully. + + Raises: + InteractiveCommandExecutionError: If flow rule is invalid. + """ + flow_output = self.send_command(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() -- 2.44.0