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 6BBE1456B1; Fri, 26 Jul 2024 15:47:35 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E903740DFD; Fri, 26 Jul 2024 15:47:34 +0200 (CEST) Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) by mails.dpdk.org (Postfix) with ESMTP id 3CBD040281 for ; Fri, 26 Jul 2024 15:47:33 +0200 (CEST) Received: by mail-qt1-f170.google.com with SMTP id d75a77b69052e-44ff6f3c427so3549471cf.1 for ; Fri, 26 Jul 2024 06:47:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1722001652; x=1722606452; 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=Obwnd6bkBdbt9Fo8nLuhdgvEBGuufb15eNzLSUfUD9Y=; b=LK7xdZejFZhbM5c/PmsC85fesg30maixETpt7fQNph8gM4d4+bpe5eSdUvhMWqmNNN qHw34FL2vZhw6KxITGIk8/MTMzYrY80voaTOg1ziiDkK3iNW5IAXub6MxHNYtt2/mYPh sFZEuP32mUC+st5UhZOhr4qBjT+0LJh0S78BM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722001652; x=1722606452; 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=Obwnd6bkBdbt9Fo8nLuhdgvEBGuufb15eNzLSUfUD9Y=; b=KIqxrPv+ARC965kWCFPjwVmvqgWUa+rqD+HqGOIvZH3OEFHNTQKCfjFldWMjslfyON 9ReMcZaSY4YZpeSOGH8DPXug5uR//VMeZKiPJkOFNHvqSXqicjKPFz22VIjyRCKPbSMR Nb5RWgFZyjql7UnQSpQyowOPGz0uGDKrLoRUkhol+0fhF9voVGSBQ4FcAgNZvtFyi8E2 kcagkqGzq1ED8CvUSAHakofMDv9FR7mnpp3Poi1UGsr4+CHsAaEN0IommhA4nnQyC9Cd y3ilaeLCpYZWMDorivXFN08x4LfzaPIf+bQpMDeD6wvDytyGzQ77swf84l49Xm4O6b+W FdDA== X-Gm-Message-State: AOJu0YzEgut4zggREXyngK4xNZ/XuHUOL44412glfUFpvnervRFFqLJT 6XQ9+Q+7znvshYJGnMyV2LSqGNdsc1YaxyYW4XwWVnYpxRnJehhuQ61FSSTnR/E= X-Google-Smtp-Source: AGHT+IHd/WuCs9Si0UKSTLJx89+UD+FAfQb9fk+AacNzdFiZBg2gH+5x3Wx6TLkFwXJ1ei5ShLeIdA== X-Received: by 2002:a05:622a:144d:b0:447:ed12:77ea with SMTP id d75a77b69052e-44fe910dd88mr61474441cf.11.1722001652167; Fri, 26 Jul 2024 06:47:32 -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-44fe7e8a2e9sm13897281cf.0.2024.07.26.06.47.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jul 2024 06:47:31 -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 09:47:23 -0400 Message-ID: <20240726134723.20247-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 intializing flow rules. Signed-off-by: Dean Marx --- dts/framework/remote_session/testpmd_shell.py | 66 ++++++++++++++++--- 1 file changed, 57 insertions(+), 9 deletions(-) diff --git a/dts/framework/remote_session/testpmd_shell.py b/dts/framework/remote_session/testpmd_shell.py index 71d27c6c2a..61c1c935a6 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 create 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,16 +841,27 @@ 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() -<<<<<<< HEAD -<<<<<<< HEAD - self.send_command("quit", "Bye...") -======= - self.send_command("quit", "") ->>>>>>> dec6a393bf (dts: add context manager for interactive shells) -======= self.send_command("quit", "Bye...") ->>>>>>> c4dc8483a8 (dts: improve starting and stopping interactive shells) return super()._close() -- 2.44.0