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 EF5D6457B2; Tue, 13 Aug 2024 16:39:05 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A7A064065B; Tue, 13 Aug 2024 16:39:05 +0200 (CEST) Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) by mails.dpdk.org (Postfix) with ESMTP id F1969402C2 for ; Tue, 13 Aug 2024 16:39:04 +0200 (CEST) Received: by mail-ot1-f43.google.com with SMTP id 46e09a7af769-7093ba310b0so2411247a34.2 for ; Tue, 13 Aug 2024 07:39:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1723559944; x=1724164744; 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=QNT0F4YDROJi161X99Y7/atPS7RLWcVLkrt/2uGT4a0=; b=MAzrgTsZJz2orbTA74xpvLl07pmY+MrYY78vWtAymQ3TUoeIezVebky6E7RCBmA86F ypH54acbJvtLInqRvHok6JVMhmJQvjvANELP3GRspE1zeDPWTKcqFMRKSOSH02dMdjcX vJBBxUTngZha3Lfp6zgKkTf6zPW1B/V8pRHSo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723559944; x=1724164744; 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=QNT0F4YDROJi161X99Y7/atPS7RLWcVLkrt/2uGT4a0=; b=vfAtLK9rcbTeg7rsxoEkN9p6hrl/wCQFb9WgAqllw1RxuQNl4JfIp3bGy9ndlLe17P tajiQ0zIFLyjTKodPcWmy9ToE0M5F7139j/1wObIC6PUaH4LTSk2djsbDIbEn2/DoHXL xNDpXc4u+YlH7zk0mSw9mci68Qe7ponil5xFDaNTFlkpAM3AN6UE6+dtY0wNu6nc4Vvh bcAFTg/laXYXF7gIsl5UwRQ4C3sPcA7IpFt8eYOun11/5kpcXO2eVKoou1mbusjNlhul zmA0Nj5YANiTR7xghABsPhezEILQebZ/OEFvoreH1H7598tPbBId2/hXfgm+DK2qU017 WVeQ== X-Gm-Message-State: AOJu0YwCV+4c2owPqV65PLqOvDZftv2/Q4pKE8k2LCvDGC2DA8dRxoE/ 470GJLcaqqM/vBUeWfgLlGt8LvBQgC9PQzc236mLf9IUbEAcLj81mZJn9nNW+xU= X-Google-Smtp-Source: AGHT+IH77Yot+l5/4iaYL4S2GJcD9Gzkmyjj69JmdUmIy6p+jNAQaYla+q5MeqkaZ7oFlO4DLyot9A== X-Received: by 2002:a05:6830:700b:b0:708:29dc:d2fc with SMTP id 46e09a7af769-70c938fd164mr6069430a34.19.1723559944043; Tue, 13 Aug 2024 07:39:04 -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-6bd82c7d75fsm34589606d6.30.2024.08.13.07.38.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Aug 2024 07:39:01 -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:39:17 -0400 Message-ID: <20240813143917.4940-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..6876f93e9e 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 + #: + priority_level: int | None + #: + user_id: 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 = 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