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 A71B2456B8; Fri, 26 Jul 2024 16:16:14 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8C11843289; Fri, 26 Jul 2024 16:16:14 +0200 (CEST) Received: from mail-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) by mails.dpdk.org (Postfix) with ESMTP id 73F6A42DC1 for ; Fri, 26 Jul 2024 16:15:57 +0200 (CEST) Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-44c2c4ccb7aso6170091cf.1 for ; Fri, 26 Jul 2024 07:15:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1722003356; x=1722608156; 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=XX8pr7ZXAC+MNMa1c1wOx6N43JwTRFcPKv+9gtTaPrOJwb2VpoAR0xvhZchwZMOKEc jXQ40mDwk4zteGR/1XjK0WitVk9/P4Y5tJVMiV9c8tM2zVCs8pG38HRKuMQ2q0OOgwEU w5t/mUyT6BomdygzMu/q/M+dcRXcN0/JWUgpQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722003356; x=1722608156; 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=cxZlzUAVgSDMGgdXGR4NkmzkOy2M1j5oOL9GyxXu3/31HZKDVv02rICwneRHIowiCT 2NTDoso6hH6sWnwpFjeKLz8/iN1LzHyqDX4owaxnSO/TLo9daLwHTBLO9El63edjAtIr LhVqxT4BhE5fOImdJeUB0bNTrbitbIrkgn36Zw3DwKgvJgn0iwNUc435fOr3NfckFF9R 6ydOrO5YlTOJQPkcVx+YFcP9HfpoHSzc5PHS19P/Xxpo2hgLEkeTkGOLtMPWbb7DTdvp WxrDUeRXWd28bWsvQrWd21Wvy1r1uZXtGkTBiYreulBTNk11ZcJ6M1Dp85c1PN0TmwHu Bjog== X-Gm-Message-State: AOJu0YyYjaVEni8RF8gv6Wug4s0mcQ3yVvpyem2qBdM4JQQA0QI1tc3n IzyX9LNW6Zsp50Hj+0mVOA1y8ZHqdx4rF1WM+2/9mtnbV8QdKtXiRoIzE3YHOZw= X-Google-Smtp-Source: AGHT+IFdZilm6pu0KSicXuAdtbRHHMCPLYmTvCtjspKvoBLjftXHxOI9766p0IXBlQfaxwWFT3TouA== X-Received: by 2002:ac8:5f48:0:b0:447:e76e:d8de with SMTP id d75a77b69052e-44fd7ad61bamr153914391cf.1.1722003356460; Fri, 26 Jul 2024 07:15:56 -0700 (PDT) Received: from dean-laptop.iol.unh.edu ([2606:4100:3880:1271:f9bd:24da:464d:6294]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-44fe840e8eesm13930431cf.85.2024.07.26.07.15.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jul 2024 07:15:55 -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 v2] dts: add flow rule dataclass to testpmd shell Date: Fri, 26 Jul 2024 10:15:48 -0400 Message-ID: <20240726141548.688-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