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 F22B8457B2; Tue, 13 Aug 2024 16:40:52 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DB35A4065B; Tue, 13 Aug 2024 16:40:52 +0200 (CEST) Received: from mail-qt1-f179.google.com (mail-qt1-f179.google.com [209.85.160.179]) by mails.dpdk.org (Postfix) with ESMTP id 7CFCA402C2 for ; Tue, 13 Aug 2024 16:40:51 +0200 (CEST) Received: by mail-qt1-f179.google.com with SMTP id d75a77b69052e-451b7e1d157so30519491cf.3 for ; Tue, 13 Aug 2024 07:40:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1723560051; x=1724164851; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Dqs+G3Ph2CpULPddzjbYosAoob8NjV5CP6CIBaj7IHg=; b=SVBEJB+AaaKvUKwSeVktTVbDIwLKOdBnnHO/orcP0KXUMaIl6INaktvOKga/HXqVGe yazevfDfdbuJYV3Up0McRRPKTXjY7if/92GwWyf3qXtHtUxZfFqIeVV22FHgQ+Wlt+T6 SD6kt3fSoZVRjKSt11hXgOlxg3TLDwM295LII= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723560051; x=1724164851; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Dqs+G3Ph2CpULPddzjbYosAoob8NjV5CP6CIBaj7IHg=; b=h+vOykSmgsm7B/nAGygciIylNutF7zGhvgF+mcgMdUnInwkwF/LWbKpK0K4b9VQDji ClAkDvrzUea8cinZLpZLtijlOm3HNrxkzpijl8mOOo8f6ah4uZCBnGeThDUOIjSUjN8Q /QMMX3kELfDbdDpZvtEfHqB6hcSaEhKgfLH9QaSkoGfB6MM3GVCUTCZXE6wiQSzpE2UT Lb7HTzQikxGO23AOR8pZ3ZjyExdQOO6VBUGN6thhuuERi9oCOWkWXUtq4673yr2J2/sA Vf6hzrsfUOLmmG0pOsgAYw8nX1DrRKKBYPsZfja2LeCHgUztl/Ac0YVDxV7CP9ZCE0IO WgVQ== X-Gm-Message-State: AOJu0YzQGXfvJryzXawFlkrhOMqOPLg6FyKWxWcKMmSSgdJ5N6ddm/EL mT8UN19nffMdPGvekLGs+ZMPolvy7YwN1RlQVwHnwuJ8Fodxsi5zWDx7Ro/5Qy9WZ2YGYmEjrT6 D X-Google-Smtp-Source: AGHT+IFIcIW3De8oW+HMaanDshvY8rdPLtHoCe+D8K48QsP6QHSOXcJ5oSHYvva2pcGGWqcKrm5Fyg== X-Received: by 2002:a05:6214:2e4a:b0:6b5:e202:bd91 with SMTP id 6a1803df08f44-6bf4f66c2a2mr52631476d6.1.1723560050684; Tue, 13 Aug 2024 07:40:50 -0700 (PDT) Received: from dean-laptop.iol.unh.edu ([2606:4100:3880:1210:52ef:3eaf:5f1e:6f6a]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6bd82e31802sm34465866d6.82.2024.08.13.07.40.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Aug 2024 07:40:50 -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 v3] dts: add flow rule dataclass to testpmd shell Date: Tue, 13 Aug 2024 10:41:07 -0400 Message-ID: <20240813144107.6195-1-dmarx@iol.unh.edu> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240806164208.3351-1-dmarx@iol.unh.edu> References: <20240806164208.3351-1-dmarx@iol.unh.edu> 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 | 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. + """ + 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: + """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(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() -- 2.44.0