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 E49F745B09; Thu, 10 Oct 2024 23:06:08 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AE221402E3; Thu, 10 Oct 2024 23:06:08 +0200 (CEST) Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) by mails.dpdk.org (Postfix) with ESMTP id 84A6D4028E for ; Thu, 10 Oct 2024 23:06:06 +0200 (CEST) Received: by mail-qt1-f182.google.com with SMTP id d75a77b69052e-45f059dcc77so13868061cf.1 for ; Thu, 10 Oct 2024 14:06:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1728594366; x=1729199166; 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=PZM0fH2kb2eENRjYLWFAKuiCYmM9xyiWf2WzxojARuk=; b=XlJeU8j5nsJc1QZm2isGYUv4P7u2LfFlQZMcsS81VIbuKVCzG1P4psIUAebqIOBCW3 oWngWk9tfN0admEnvquGrTWbJO09kGdiXk1XWznhTkZ4oqeGZA38rSDbmsKI8NCQ26mS 413Xi19wZuPYb2wZ5oTaUAIM+xjh0Jg4jhZQk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728594366; x=1729199166; 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=PZM0fH2kb2eENRjYLWFAKuiCYmM9xyiWf2WzxojARuk=; b=soBrxkR5b9mpGWujCzDtvuGEMFj8IFlxZfAnjl34xhCHEJxAFE1By8epN+v5cOgZGR k4Kbh9tLQthtLQ42T+RI69UNq1idCEciz/GFCAldrcDmCCAFTAIV2Ofn32tJ1VBuoVXu mNzjMshoqkjILfbtWqa4cGae8ra5uTEwqX7qemMEMsSP68gyElD7N67U9uHpQSsBAo8p 19WaO2MesaN2H+LLc0S3WJuUAZjcuN1RbsYzxtgyH33BpOAl+81Slw0urxpaFl14VA4m XcO/PldCFP1npNVdwak2eplJ7j0T5kehk5GNyd/5S6bOKtzQNwzPRoU2VS68gtlxSJKu HaQQ== X-Gm-Message-State: AOJu0YyT/I+zFCZZKuhzOcaKVhviyo1Ykr2RgC3Sa2r8ZkX4dPZZDkLe LfnSBWExIdWR/GMC09K9VL1siQ1rga+vNGWBQmlFPHgif9bLofp1NGYUfI/E1w4= X-Google-Smtp-Source: AGHT+IFOMk1QFPvwc1llGCsyWoty7CHuuSCaBofhx8gD7uOlZ6EMsnCCkLpjwalaaisqrDjdnjQUtg== X-Received: by 2002:ac8:59d2:0:b0:460:394e:27a with SMTP id d75a77b69052e-4604bc49733mr3339331cf.42.1728594365811; Thu, 10 Oct 2024 14:06:05 -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-46042801ee8sm8998101cf.40.2024.10.10.14.06.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 14:06:05 -0700 (PDT) From: Dean Marx To: probb@iol.unh.edu, npratte@iol.unh.edu, luca.vizzarro@arm.com, yoan.picchi@foss.arm.com, Honnappa.Nagarahalli@arm.com, paul.szczepanek@arm.com Cc: dev@dpdk.org, Dean Marx Subject: [PATCH v4] dts: add flow rule dataclass to testpmd shell Date: Thu, 10 Oct 2024 17:06:31 -0400 Message-ID: <20241010210631.705-1-dmarx@iol.unh.edu> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240813144107.6195-1-dmarx@iol.unh.edu> References: <20240813144107.6195-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 b9e7875615..aaae7e5515 100644 --- a/dts/framework/remote_session/testpmd_shell.py +++ b/dts/framework/remote_session/testpmd_shell.py @@ -672,6 +672,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 PacketOffloadFlag(Flag): """Flag representing the Packet Offload Features Flags in DPDK. @@ -1717,6 +1755,25 @@ def show_port_stats(self, port_id: int) -> TestPmdPortStats: return TestPmdPortStats.parse(output) + def flow_create(self, flow_rule: FlowRule, verify: bool = True) -> None: + """Creates a flow rule in the testpmd session. + + Args: + flow_rule: FlowRule object used for creating testpmd 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(flow_rule)) + 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}" + ) + @requires_stopped_ports def set_port_mtu(self, port_id: int, mtu: int, verify: bool = True) -> None: """Change the MTU of a port using testpmd. -- 2.44.0