From patchwork Mon Sep 23 18:42:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Spewock X-Patchwork-Id: 144393 X-Patchwork-Delegate: paul.szczepanek@arm.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C3AC245A12; Mon, 23 Sep 2024 20:42:58 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 55FE6402DC; Mon, 23 Sep 2024 20:42:54 +0200 (CEST) Received: from mail-yw1-f226.google.com (mail-yw1-f226.google.com [209.85.128.226]) by mails.dpdk.org (Postfix) with ESMTP id 79AD54027C for ; Mon, 23 Sep 2024 20:42:51 +0200 (CEST) Received: by mail-yw1-f226.google.com with SMTP id 00721157ae682-6dbc5db8a31so33813517b3.1 for ; Mon, 23 Sep 2024 11:42:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1727116970; x=1727721770; 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=qG6Qiopb5PuXf59YRD/ZcNnWMp0DKJBzVvK1k2ALL30=; b=a5eHiz7ke9TRX8+w67/a7i0Bv/vQU4WBLTIW7FLtDm+gqPHRjZHGIvxDGS1hAhgIvx AX4mPmJodqsdyjd8NgBkScRoRYJAovnPmon46HGFdE/GYJebHZXsfZLT72JuVHJx/+eV QY7MW7vCD4X24k09xxegMZtMW8Kx8g8XVeWkY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727116970; x=1727721770; 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=qG6Qiopb5PuXf59YRD/ZcNnWMp0DKJBzVvK1k2ALL30=; b=Qf+crunZmjEPYLX3qdpwsx5QmNQmgvTWRHtoQPzei81sO3wCypPWpROaJ39zr+pbrc 4YzsEHF1dnkbvn0n0bUA1FZSI89ihWdbbsxnv9b9cUG9cQ5l0KFyPosuOa3/XE5Wj6Am QCX48xptPQcQymzEjdUjkvkIt2ZoB23Hs4+9+ums6Ba5npGG1z9rNlTGLD4WHMiZas/s H7igdfdAtTROEJxZvBWwoaFo4/qdU5Y9trbJttk9ehrRnYNcBvRF4X+wIOpuDwYNduIG LBlred7RoxJm4mV69ZLYsiv22xWU5mFnONFNgOzB2W3/OVitUe6rfhHgTcMo7AD8C17i mCRw== X-Gm-Message-State: AOJu0YzFvewc14ufvclRstQdJMW0nX2dJouq+OyDGdc++zMW8iFcg2k+ PcerZqlJsA9cKMxA4N2eSV1n8WeT7hdLKeTyEqYyeMLzSQYmPRcCPBhF1OXP/Fs8JsxrI2fS7Ml taygL0bBBjrbYaDIERgfSdGtppqSH5CWv+ZwquwLpSo+O6sxB X-Google-Smtp-Source: AGHT+IEwVGRzrsIhp0Gxf2lLka2ElEzd6n+8n9O2TIKRMOWfPLOurt9FieEGly0L2x3xIiOshD0j+2zndcfZ X-Received: by 2002:a05:690c:2508:b0:652:e900:550a with SMTP id 00721157ae682-6e20886da73mr5040597b3.19.1727116970620; Mon, 23 Sep 2024 11:42:50 -0700 (PDT) Received: from postal.iol.unh.edu (postal.iol.unh.edu. [2606:4100:3880:1234::84]) by smtp-relay.gmail.com with ESMTPS id 00721157ae682-6dbe2ed006dsm10273237b3.61.2024.09.23.11.42.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Sep 2024 11:42:50 -0700 (PDT) X-Relaying-Domain: iol.unh.edu Received: from iol.unh.edu (unknown [IPv6:2606:4100:3880:1257::1083]) by postal.iol.unh.edu (Postfix) with ESMTP id BE782605C351; Mon, 23 Sep 2024 14:42:49 -0400 (EDT) From: jspewock@iol.unh.edu To: npratte@iol.unh.edu, juraj.linkes@pantheon.tech, yoan.picchi@foss.arm.com, thomas@monjalon.net, Honnappa.Nagarahalli@arm.com, probb@iol.unh.edu, wathsala.vithanage@arm.com, paul.szczepanek@arm.com, Luca.Vizzarro@arm.com, alex.chapman@arm.com Cc: dev@dpdk.org, Jeremy Spewock Subject: [PATCH v4 1/5] dts: allow binding only a single port to a different driver Date: Mon, 23 Sep 2024 14:42:31 -0400 Message-ID: <20240923184235.22582-2-jspewock@iol.unh.edu> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923184235.22582-1-jspewock@iol.unh.edu> References: <20240821191557.18744-1-jspewock@iol.unh.edu> <20240923184235.22582-1-jspewock@iol.unh.edu> MIME-Version: 1.0 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 From: Jeremy Spewock Previously the DTS framework only included methods that bind all ports that the test run was aware of to either the DPDK driver or the OS driver. There are however some cases, like creating virtual functions, where you would want some ports bound to the OS driver and others bound to their DPDK driver. This patch adds the ability to bind individual ports to their respective drviers to solve this problem. Depends-on: patch-144318 ("dts: add binding to different drivers to TG node") Signed-off-by: Jeremy Spewock --- dts/framework/testbed_model/node.py | 21 ++++++++++++--------- dts/tests/TestSuite_os_udp.py | 4 ++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/dts/framework/testbed_model/node.py b/dts/framework/testbed_model/node.py index 6484e16a0f..106e189ce3 100644 --- a/dts/framework/testbed_model/node.py +++ b/dts/framework/testbed_model/node.py @@ -138,11 +138,11 @@ def set_up_build_target(self, build_target_config: BuildTargetConfiguration) -> the setup steps will be taken. This is unused in this method, but subclasses that extend this method may need it. """ - self.bind_ports_to_driver() + self.bind_all_ports_to_driver() def tear_down_build_target(self) -> None: """Bind ports to their OS drivers.""" - self.bind_ports_to_driver(for_dpdk=False) + self.bind_all_ports_to_driver(for_dpdk=False) def create_session(self, name: str) -> OSSession: """Create and return a new OS-aware remote session. @@ -258,7 +258,7 @@ def skip_setup(func: Callable[..., Any]) -> Callable[..., Any]: else: return func - def bind_ports_to_driver(self, for_dpdk: bool = True) -> None: + def bind_all_ports_to_driver(self, for_dpdk: bool = True) -> None: """Bind all ports on the node to a driver. Args: @@ -266,12 +266,15 @@ def bind_ports_to_driver(self, for_dpdk: bool = True) -> None: If :data:`False`, binds to os_driver. """ for port in self.ports: - driver = port.os_driver_for_dpdk if for_dpdk else port.os_driver - self.main_session.send_command( - f"{self.path_to_devbind_script} -b {driver} --force {port.pci}", - privileged=True, - verify=True, - ) + self._bind_port_to_driver(port, for_dpdk) + + def _bind_port_to_driver(self, port: Port, for_dpdk: bool = True) -> None: + driver = port.os_driver_for_dpdk if for_dpdk else port.os_driver + self.main_session.send_command( + f"{self.path_to_devbind_script} -b {driver} --force {port.pci}", + privileged=True, + verify=True, + ) def create_session(node_config: NodeConfiguration, name: str, logger: DTSLogger) -> OSSession: diff --git a/dts/tests/TestSuite_os_udp.py b/dts/tests/TestSuite_os_udp.py index a78bd74139..5e9469bbac 100644 --- a/dts/tests/TestSuite_os_udp.py +++ b/dts/tests/TestSuite_os_udp.py @@ -23,7 +23,7 @@ def set_up_suite(self) -> None: Bind the SUT ports to the OS driver, configure the ports and configure the SUT to route traffic from if1 to if2. """ - self.sut_node.bind_ports_to_driver(for_dpdk=False) + self.sut_node.bind_all_ports_to_driver(for_dpdk=False) self.configure_testbed_ipv4() def test_os_udp(self) -> None: @@ -50,4 +50,4 @@ def tear_down_suite(self) -> None: """ self.configure_testbed_ipv4(restore=True) # Assume other suites will likely need dpdk driver - self.sut_node.bind_ports_to_driver(for_dpdk=True) + self.sut_node.bind_all_ports_to_driver(for_dpdk=True) From patchwork Mon Sep 23 18:42:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Spewock X-Patchwork-Id: 144394 X-Patchwork-Delegate: paul.szczepanek@arm.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D3AE745A12; Mon, 23 Sep 2024 20:43:05 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B37DC402EA; Mon, 23 Sep 2024 20:42:55 +0200 (CEST) Received: from mail-pj1-f102.google.com (mail-pj1-f102.google.com [209.85.216.102]) by mails.dpdk.org (Postfix) with ESMTP id E35C9402CA for ; Mon, 23 Sep 2024 20:42:52 +0200 (CEST) Received: by mail-pj1-f102.google.com with SMTP id 98e67ed59e1d1-2d87196ec9fso3184246a91.1 for ; Mon, 23 Sep 2024 11:42:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1727116972; x=1727721772; 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=BbMwwmdIa+dHbnaWZJNHsdx1Y4VrdlWIzalDi9CBwjg=; b=aPtJAzxIhNt6Wvg8JmpPW963cVleLa/HWF9sIuyXHBouoCi1pjFVo9IvdI72fgs4xM tNEglLv+x8GZ4n17Iye0dUfnPO3y3hcPgfOxNn551xnmL/4m5h5KRMiawTuDIsCK7914 743xm3TZApl3l5r52ZQrh1luK2pe3si0TTPCM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727116972; x=1727721772; 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=BbMwwmdIa+dHbnaWZJNHsdx1Y4VrdlWIzalDi9CBwjg=; b=Dgl4OjXkMUCepdhk0f/1SDKsqcWxbBL40HEuFjTP5kaAwvhFGHWbxbnzgQXgzAgzGT IeSM1L3EgK1/wLwqDGXkG2T29ONeIO7uI/eDeDFbyTgcc0r9mjqUBWniTwrKNL8XsDDh 92fd/lNQvpkYCFD+fnErTpDdMLcpjj1SDHjw37Tqe8Q1ee5p45jD3R80yk6JNKHoyQQd G6NhE4Q+fE57TLTnnJhkwGZfC3l/yfgS/pILSwbGYPgZ9tI8CYBU9AUAe0tNGipe2PL8 dHwGsWlAqAebylG38+slXuNWc0isPwwhmTIzThxoNnvAdL57H6462rP85rI8d5tFqK8e +IJw== X-Gm-Message-State: AOJu0Yy7nNJ2baUsSBo9Z/L3whBByda9TkvMSXDD8tUusLM5H0DHJFXy +G475kJPt+V5Hnbm2gxEFmAuC4NPMZ+1crzLPYKQglLpXiXKJgs42ks2ZRmnbroMaZDCc2OUw+j KzMiRUmpv06GrQLZ5PlT51adWGgCx4gKC12iTBbs33RWyp/hn X-Google-Smtp-Source: AGHT+IEKn4+dQB74jmJ44E/F68sTWhZ7+a6Qi4B8j4sxne0OAlLmsLpGV4/h1jYkpkdAqp7PD7ZMRkJgekyc X-Received: by 2002:a17:90b:4b83:b0:2d3:d68e:e8d8 with SMTP id 98e67ed59e1d1-2dd7f752757mr12444210a91.40.1727116971829; Mon, 23 Sep 2024 11:42:51 -0700 (PDT) Received: from postal.iol.unh.edu (postal.iol.unh.edu. [2606:4100:3880:1234::84]) by smtp-relay.gmail.com with ESMTPS id 98e67ed59e1d1-2dd7f7d960esm482396a91.8.2024.09.23.11.42.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Sep 2024 11:42:51 -0700 (PDT) X-Relaying-Domain: iol.unh.edu Received: from iol.unh.edu (unknown [IPv6:2606:4100:3880:1257::1083]) by postal.iol.unh.edu (Postfix) with ESMTP id D99BA605C351; Mon, 23 Sep 2024 14:42:50 -0400 (EDT) From: jspewock@iol.unh.edu To: npratte@iol.unh.edu, juraj.linkes@pantheon.tech, yoan.picchi@foss.arm.com, thomas@monjalon.net, Honnappa.Nagarahalli@arm.com, probb@iol.unh.edu, wathsala.vithanage@arm.com, paul.szczepanek@arm.com, Luca.Vizzarro@arm.com, alex.chapman@arm.com Cc: dev@dpdk.org, Jeremy Spewock Subject: [PATCH v4 2/5] dts: parameterize what ports the TG sends packets to Date: Mon, 23 Sep 2024 14:42:32 -0400 Message-ID: <20240923184235.22582-3-jspewock@iol.unh.edu> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923184235.22582-1-jspewock@iol.unh.edu> References: <20240821191557.18744-1-jspewock@iol.unh.edu> <20240923184235.22582-1-jspewock@iol.unh.edu> MIME-Version: 1.0 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 From: Jeremy Spewock Previously in the DTS framework the helper methods in the TestSuite class designated ports as either ingress or egress ports and would wrap the methods of the traffic generator to allow packets to only flow to those designated ingress or egress ports. This is undesirable in some cases, such as when you have virtual functions on top of your port, where the TG ports can send to more than one SUT port. This patch solves this problem by creating optional parameters that allow the user to specify which port to gather the MAC addresses from when sending and receiving packets. Signed-off-by: Jeremy Spewock --- dts/framework/test_suite.py | 48 +++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/dts/framework/test_suite.py b/dts/framework/test_suite.py index 051509fb86..9b707ca46d 100644 --- a/dts/framework/test_suite.py +++ b/dts/framework/test_suite.py @@ -186,6 +186,8 @@ def send_packet_and_capture( packet: Packet, filter_config: PacketFilteringConfig = PacketFilteringConfig(), duration: float = 1, + sut_ingress: Port | None = None, + sut_egress: Port | None = None, ) -> list[Packet]: """Send and receive `packet` using the associated TG. @@ -196,14 +198,16 @@ def send_packet_and_capture( packet: The packet to send. filter_config: The filter to use when capturing packets. duration: Capture traffic for this amount of time after sending `packet`. + sut_ingress: Optional port to use as the SUT ingress port. Defaults to + `self._sut_port_ingress`. + sut_egress: Optional port to use as the SUT egress port. Defaults to + `self._sut_port_egress` Returns: A list of received packets. """ return self.send_packets_and_capture( - [packet], - filter_config, - duration, + [packet], filter_config, duration, sut_ingress, sut_egress ) def send_packets_and_capture( @@ -211,6 +215,8 @@ def send_packets_and_capture( packets: list[Packet], filter_config: PacketFilteringConfig = PacketFilteringConfig(), duration: float = 1, + sut_ingress: Port | None = None, + sut_egress: Port | None = None, ) -> list[Packet]: """Send and receive `packets` using the associated TG. @@ -221,11 +227,19 @@ def send_packets_and_capture( packets: The packets to send. filter_config: The filter to use when capturing packets. duration: Capture traffic for this amount of time after sending `packet`. + sut_ingress: Optional port to use as the SUT ingress port. Defaults to + `self._sut_port_ingress`. + sut_egress: Optional port to use as the SUT egress port. Defaults to + `self._sut_port_egress` Returns: A list of received packets. """ - packets = [self._adjust_addresses(packet) for packet in packets] + if sut_ingress is None: + sut_ingress = self._sut_port_ingress + if sut_egress is None: + sut_egress = self._sut_port_egress + packets = [self._adjust_addresses(packet, sut_ingress, sut_egress) for packet in packets] return self.tg_node.send_packets_and_capture( packets, self._tg_port_egress, @@ -234,18 +248,30 @@ def send_packets_and_capture( duration, ) - def get_expected_packet(self, packet: Packet) -> Packet: + def get_expected_packet( + self, packet: Packet, sut_ingress: Port | None = None, sut_egress: Port | None = None + ) -> Packet: """Inject the proper L2/L3 addresses into `packet`. Args: packet: The packet to modify. + sut_ingress: Optional port to use as the SUT ingress port. Defaults to + `self._sut_port_ingress`. + sut_egress: Optional port to use as the SUT egress port. Defaults to + `self._sut_port_egress`. Returns: `packet` with injected L2/L3 addresses. """ - return self._adjust_addresses(packet, expected=True) - - def _adjust_addresses(self, packet: Packet, expected: bool = False) -> Packet: + if sut_ingress is None: + sut_ingress = self._sut_port_ingress + if sut_egress is None: + sut_egress = self._sut_port_egress + return self._adjust_addresses(packet, sut_ingress, sut_egress, expected=True) + + def _adjust_addresses( + self, packet: Packet, sut_ingress_port: Port, sut_egress_port: Port, expected: bool = False + ) -> Packet: """L2 and L3 address additions in both directions. Assumptions: @@ -255,11 +281,13 @@ def _adjust_addresses(self, packet: Packet, expected: bool = False) -> Packet: packet: The packet to modify. expected: If :data:`True`, the direction is SUT -> TG, otherwise the direction is TG -> SUT. + sut_ingress_port: The port to use as the Rx port on the SUT. + sut_egress_port: The port to use as the Tx port on the SUT. """ if expected: # The packet enters the TG from SUT # update l2 addresses - packet.src = self._sut_port_egress.mac_address + packet.src = sut_egress_port.mac_address packet.dst = self._tg_port_ingress.mac_address # The packet is routed from TG egress to TG ingress @@ -270,7 +298,7 @@ def _adjust_addresses(self, packet: Packet, expected: bool = False) -> Packet: # The packet leaves TG towards SUT # update l2 addresses packet.src = self._tg_port_egress.mac_address - packet.dst = self._sut_port_ingress.mac_address + packet.dst = sut_ingress_port.mac_address # The packet is routed from TG egress to TG ingress # update l3 addresses From patchwork Mon Sep 23 18:42:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Spewock X-Patchwork-Id: 144395 X-Patchwork-Delegate: paul.szczepanek@arm.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id F110645A12; Mon, 23 Sep 2024 20:43:12 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DB28E4042E; Mon, 23 Sep 2024 20:42:56 +0200 (CEST) Received: from mail-oa1-f99.google.com (mail-oa1-f99.google.com [209.85.160.99]) by mails.dpdk.org (Postfix) with ESMTP id 50D00402CF for ; Mon, 23 Sep 2024 20:42:54 +0200 (CEST) Received: by mail-oa1-f99.google.com with SMTP id 586e51a60fabf-27d045a73easo2588288fac.0 for ; Mon, 23 Sep 2024 11:42:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1727116973; x=1727721773; 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=Z8zYhPZWI64RRFqa9ZLdttUYZYQ8/fRrqM6Y+FxHvgc=; b=RyGc7HFqZOmYVJBuD1stUBtB0nkywKkqkC4cmrl6v2EgOrNH/GZKj01+E0hVj9Cnsj hQUUcLpumnwukBOpCJrPvzgH/9bHZpzzZoEXOPyJPG5xQFBwGTuXJtRwjQfonYniFrfQ +lBN7X8bosB/e3xc46D6ocyPMOY001NnRHiSc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727116973; x=1727721773; 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=Z8zYhPZWI64RRFqa9ZLdttUYZYQ8/fRrqM6Y+FxHvgc=; b=UiaBgrjFZNlNNc81msuitfbd8YA3wQNTnNKduPmSbcTuLhsGl1KGl9FPehoNOmA9Wj 7cbYBR6+qd5Pdbd1oom0FnkLJPx61tOZjfqsvR1gsvO8b8uw0YSrUAOw1LjoJ2cOSxzJ LGjmLpu1F8lMg8V3lJE63EjguNtLkJqgezOP8jEbzCNDVGm6I5A7T6Q7QJYZaVIZt78+ cr/88Xx44XFDCwePRjXLqHq9nQQVn/e8ol0sNnJnN6GPcmBnu5vMyW3rETs7NmEIlfZz hz8zXSm9KEAUU/KtqVjd7S9M25QRtRz01IxwEaqzrI12fWj1DgvZAeZua7oBKMRmKgbl 1Xlg== X-Gm-Message-State: AOJu0YwtKr9fY1kmGeMtP91+QxTRsTs/MQPVFSTBjx0wsw/kr9F/vqCn cyQz9Sa6CMzcwZKlRyjeArLyOmlGLa3MxpWT7O5j0tepN8KFhROHoadGZyz9Gx+y2FolQtrkf9f gX6BlMJHE1EVngz/czbMfl1oLgpalhAfQ0pF1YqQm7p3LS9gW X-Google-Smtp-Source: AGHT+IGV6UsT1ktqAEDh/fyXyRCn2Zb4ZS1oJ2ysYNzdJXaBtD4t/i9zx73mFvRtT/DYU8iOjAoaj227NuyI X-Received: by 2002:a05:6871:581f:b0:277:ce5e:1e94 with SMTP id 586e51a60fabf-2803d119450mr8008481fac.30.1727116973486; Mon, 23 Sep 2024 11:42:53 -0700 (PDT) Received: from postal.iol.unh.edu (postal.iol.unh.edu. [2606:4100:3880:1234::84]) by smtp-relay.gmail.com with ESMTPS id 586e51a60fabf-27d0b560d99sm666999fac.36.2024.09.23.11.42.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Sep 2024 11:42:53 -0700 (PDT) X-Relaying-Domain: iol.unh.edu Received: from iol.unh.edu (unknown [IPv6:2606:4100:3880:1257::1083]) by postal.iol.unh.edu (Postfix) with ESMTP id EDFA7605C352; Mon, 23 Sep 2024 14:42:51 -0400 (EDT) From: jspewock@iol.unh.edu To: npratte@iol.unh.edu, juraj.linkes@pantheon.tech, yoan.picchi@foss.arm.com, thomas@monjalon.net, Honnappa.Nagarahalli@arm.com, probb@iol.unh.edu, wathsala.vithanage@arm.com, paul.szczepanek@arm.com, Luca.Vizzarro@arm.com, alex.chapman@arm.com Cc: dev@dpdk.org, Jeremy Spewock Subject: [PATCH v4 3/5] dts: add class for virtual functions Date: Mon, 23 Sep 2024 14:42:33 -0400 Message-ID: <20240923184235.22582-4-jspewock@iol.unh.edu> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923184235.22582-1-jspewock@iol.unh.edu> References: <20240821191557.18744-1-jspewock@iol.unh.edu> <20240923184235.22582-1-jspewock@iol.unh.edu> MIME-Version: 1.0 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 From: Jeremy Spewock In DPDK applications virtual functions are treated the same as ports, but within the framework there are benefits to differentiating the two in order to add more metadata to VFs about where they originate from. For this reason this patch adds a new class for handling virtual functions that extends the Port class with some additional information about the VF. Bugzilla ID: 1500 Signed-off-by: Jeremy Spewock --- dts/framework/testbed_model/port.py | 37 ++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/dts/framework/testbed_model/port.py b/dts/framework/testbed_model/port.py index 817405bea4..c1d85fec2b 100644 --- a/dts/framework/testbed_model/port.py +++ b/dts/framework/testbed_model/port.py @@ -27,7 +27,7 @@ class PortIdentifier: pci: str -@dataclass(slots=True) +@dataclass class Port: """Physical port on a node. @@ -80,6 +80,41 @@ def pci(self) -> str: return self.identifier.pci +@dataclass +class VirtualFunction(Port): + """Virtual Function (VF) on a port. + + DPDK applications often treat VFs the same as they do the physical ports (PFs) on the host. + For this reason VFs are represented in the framework as a type of port with some additional + metadata that allows the framework to more easily identify which device the VF belongs to as + well as where the VF originated from. + + Attributes: + created_by_framework: :data:`True` if this VF represents one that the DTS framework created + on the node, :data:`False` otherwise. + pf_port: The PF that this VF was created on/gathered from. + """ + + created_by_framework: bool = False + pf_port: Port | None = None + + def __init__( + self, node_name: str, config: PortConfig, created_by_framework: bool, pf_port: Port + ) -> None: + """Extends :meth:`Port.__init__` with VF specific metadata. + + Args: + node_name: The name of the node the VF resides on. + config: Configuration information about the VF. + created_by_framework: :data:`True` if DTS created this VF, otherwise :data:`False` if + this class represents a VF that was preexisting on the node. + pf_port: The PF that this VF was created on/gathered from. + """ + super().__init__(node_name, config) + self.created_by_framework = created_by_framework + self.pf_port = pf_port + + @dataclass(slots=True, frozen=True) class PortLink: """The physical, cabled connection between the ports. From patchwork Mon Sep 23 18:42:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Spewock X-Patchwork-Id: 144396 X-Patchwork-Delegate: paul.szczepanek@arm.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2F2DD45A12; Mon, 23 Sep 2024 20:43:19 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 090D14060A; Mon, 23 Sep 2024 20:42:58 +0200 (CEST) Received: from mail-yb1-f227.google.com (mail-yb1-f227.google.com [209.85.219.227]) by mails.dpdk.org (Postfix) with ESMTP id A279F402CF for ; Mon, 23 Sep 2024 20:42:54 +0200 (CEST) Received: by mail-yb1-f227.google.com with SMTP id 3f1490d57ef6-e249807cf13so147656276.3 for ; Mon, 23 Sep 2024 11:42:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1727116974; x=1727721774; 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=nQJNsgpJJyV9wgXuic5bVU5OqpDNQI3p7LF2jhYr4OM=; b=hAJ1mWjzQ6rNlSzT5UgodwTsUokFnENuaEIi4+cHHU3kVybaJ9pKrZD4Bt/xNWda0y dZZfDiyy86Oyw9g/nc968O4V6EMNj8y/swutB7qvPx5vxwyNQ5ZMEnWHa7suVuAxuCt4 rhiCN0Rz+bbYLifXpH17iATVAJfIQZjq/gBck= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727116974; x=1727721774; 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=nQJNsgpJJyV9wgXuic5bVU5OqpDNQI3p7LF2jhYr4OM=; b=Gxts7lEJF/kX+Zk7ggMQ3A29FBTayqBCFSOtWJ6IS+u2+AjOo89y6FcWDgX15zXf9g A9B676F4JZBtBhpZCqaiSaDWzs7v21qRI4ukcFyszwfe/rS5g5fL6N0crChIq3TFSV02 xI+Yl7wcZY0cHF2X8wQsP5iwIuWwm/VcRm6kstlM/bOGlxNqEmUtHGSaJhq49pcZ3ahK ZxhsfRxpSaHdfkeGJdbwTIyDWF/89Z30Upfpz78dktlCfahQMfHeOoo/OIuvOa0Pzicl cu7eUIwgJVvSMPHZATezsDSWj8YdAxz1bBs1B+IURVdabBzFD76dVF6MCZl8Gco6hJ2k TPPg== X-Gm-Message-State: AOJu0YwdNt7KapffOrSk9VGVwztKERqeqhvvlaGoDUSxhcUtov6NqyAt DeRLXe04BmUG4IyeMGmhMjuiYVc7jW1xL2vdUtCGZWxXx4XbHhbFt1lAt6g5l8kvAuShtQS65Il 14pJimLUAJsgUudgsNGqYa0T9g495K2AV X-Google-Smtp-Source: AGHT+IHdrpjJ55o5ZyVTuZrGZ786NrW0YH2yn8UErqt43SsVrn4lOwsx2qDB6wq6hX4NmUz4/73OuVyScobT X-Received: by 2002:a05:690c:90:b0:6af:55ec:3cd7 with SMTP id 00721157ae682-6dff290369amr91405087b3.28.1727116973971; Mon, 23 Sep 2024 11:42:53 -0700 (PDT) Received: from postal.iol.unh.edu (postal.iol.unh.edu. [132.177.123.84]) by smtp-relay.gmail.com with ESMTPS id af79cd13be357-7acb07de0a7sm68319385a.2.2024.09.23.11.42.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Sep 2024 11:42:53 -0700 (PDT) X-Relaying-Domain: iol.unh.edu Received: from iol.unh.edu (unknown [IPv6:2606:4100:3880:1257::1083]) by postal.iol.unh.edu (Postfix) with ESMTP id EF791605C351; Mon, 23 Sep 2024 14:42:52 -0400 (EDT) From: jspewock@iol.unh.edu To: npratte@iol.unh.edu, juraj.linkes@pantheon.tech, yoan.picchi@foss.arm.com, thomas@monjalon.net, Honnappa.Nagarahalli@arm.com, probb@iol.unh.edu, wathsala.vithanage@arm.com, paul.szczepanek@arm.com, Luca.Vizzarro@arm.com, alex.chapman@arm.com Cc: dev@dpdk.org, Jeremy Spewock Subject: [PATCH v4 4/5] dts: add OS abstractions for creating virtual functions Date: Mon, 23 Sep 2024 14:42:34 -0400 Message-ID: <20240923184235.22582-5-jspewock@iol.unh.edu> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923184235.22582-1-jspewock@iol.unh.edu> References: <20240821191557.18744-1-jspewock@iol.unh.edu> <20240923184235.22582-1-jspewock@iol.unh.edu> MIME-Version: 1.0 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 From: Jeremy Spewock Virtual functions in the framework are created using SR-IOV. The process for doing this can vary depending on the operating system, so the commands to create VFs have to be abstracted into different classes based on the operating system. This patch adds the stubs for methods that create VFs and get the PCI addresses of all VFs on a port to the abstract class as well as a linux implementation for the methods. Bugzilla ID: 1500 Signed-off-by: Jeremy Spewock --- dts/framework/testbed_model/linux_session.py | 40 +++++++++++++++++++- dts/framework/testbed_model/os_session.py | 40 ++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/dts/framework/testbed_model/linux_session.py b/dts/framework/testbed_model/linux_session.py index 544a665b83..2615411470 100644 --- a/dts/framework/testbed_model/linux_session.py +++ b/dts/framework/testbed_model/linux_session.py @@ -15,7 +15,11 @@ from typing_extensions import NotRequired -from framework.exception import ConfigurationError, RemoteCommandExecutionError +from framework.exception import ( + ConfigurationError, + InternalError, + RemoteCommandExecutionError, +) from framework.utils import expand_range from .cpu import LogicalCore @@ -210,3 +214,37 @@ def configure_ipv4_forwarding(self, enable: bool) -> None: """Overrides :meth:`~.os_session.OSSession.configure_ipv4_forwarding`.""" state = 1 if enable else 0 self.send_command(f"sysctl -w net.ipv4.ip_forward={state}", privileged=True) + + def set_num_virtual_functions(self, num: int, pf_port: Port) -> bool: + """Overrides :meth:`~.os_session.OSSession.set_num_virtual_functions`.""" + sys_bus_path = f"/sys/bus/pci/devices/{pf_port.pci}/sriov_numvfs".replace(":", "\\:") + curr_num_vfs = int(self.send_command(f"cat {sys_bus_path}").stdout) + if num > 0 and curr_num_vfs >= num: + self._logger.info( + f"{curr_num_vfs} VFs already configured on port {pf_port.identifier.pci} on node " + f"{pf_port.identifier.node}." + ) + return False + elif num > 0 and curr_num_vfs > 0: + self._logger.error( + f"Not enough VFs configured on port {pf_port.identifier.pci} on node " + f"{pf_port.identifier.node}. Need {num} but only {curr_num_vfs} are configured. " + "DTS is unable to modify number of preexisting VFs." + ) + raise InternalError("Failed to create VFs on port.") + self.send_command(f"echo {num} > {sys_bus_path}", privileged=True, verify=True) + return True + + def get_pci_addr_of_vfs(self, pf_port: Port) -> list[str]: + """Overrides :meth:`~.os_session.OSSession.get_pci_addr_of_vfs`.""" + sys_bus_path = f"/sys/bus/pci/devices/{pf_port.pci}".replace(":", "\\:") + curr_num_vfs = int(self.send_command(f"cat {sys_bus_path}/sriov_numvfs").stdout) + if curr_num_vfs > 0: + pci_addrs = self.send_command( + 'awk -F "PCI_SLOT_NAME=" "/PCI_SLOT_NAME=/ {print \\$2}" ' + + f"{sys_bus_path}/virtfn*/uevent", + privileged=True, + ) + return pci_addrs.stdout.splitlines() + else: + return [] diff --git a/dts/framework/testbed_model/os_session.py b/dts/framework/testbed_model/os_session.py index 79f56b289b..191fc3c0c8 100644 --- a/dts/framework/testbed_model/os_session.py +++ b/dts/framework/testbed_model/os_session.py @@ -395,3 +395,43 @@ def configure_ipv4_forwarding(self, enable: bool) -> None: Args: enable: If :data:`True`, enable the forwarding, otherwise disable it. """ + + @abstractmethod + def set_num_virtual_functions(self, num: int, pf_port: Port) -> bool: + """Update the number of virtual functions (VFs) on a port. + + It should be noted that, due to the nature of VFs, if there are already VFs that exist on + the physical function (PF) prior to calling this function, additional ones cannot be added. + The only way to add more VFs is to remove the existing and then set the desired amount. For + this reason, this method will handle creation in the following order: + + 1. Use existing VFs on the PF if the number of existing VFs is greater than or equal to + `num` + 2. Throw an exception noting that VFs cannot be created if the PF has some VFs already set + on it, but the total VFs that it has are less then `num`. + 3. Create `num` VFs on the PF if there are none on it already + + Args: + num: The number of VFs to set on the port. + pf_port: The port to add the VFs to. + + Raises: + InternalError: If `pf_port` has less than `num` VFs configured on it + already. + + Returns: + :data:`True` if this method successfully created VFs, :data:`False` if existing VFs + were used instead. + """ + + @abstractmethod + def get_pci_addr_of_vfs(self, pf_port: Port) -> list[str]: + """Find the PCI addresses of all virtual functions (VFs) on the port `pf_port`. + + Args: + pf_port: The port to find the VFs on. + + Returns: + A list containing all of the PCI addresses of the VFs on the port. If the port has no + VFs then the list will be empty. + """ From patchwork Mon Sep 23 18:42:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Spewock X-Patchwork-Id: 144397 X-Patchwork-Delegate: paul.szczepanek@arm.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 156A645A12; Mon, 23 Sep 2024 20:43:28 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D837D4064A; Mon, 23 Sep 2024 20:42:59 +0200 (CEST) Received: from mail-il1-f228.google.com (mail-il1-f228.google.com [209.85.166.228]) by mails.dpdk.org (Postfix) with ESMTP id 133EE40608 for ; Mon, 23 Sep 2024 20:42:57 +0200 (CEST) Received: by mail-il1-f228.google.com with SMTP id e9e14a558f8ab-3a0cdd77dbeso9438995ab.2 for ; Mon, 23 Sep 2024 11:42:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1727116976; x=1727721776; 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=a83cvxp67ZIRrEOBil2F0eDUK9GDuaqDP0wR+nzvNIQ=; b=YX4pDWtHFyrT41ISXOxS3P33bB14fRf1U9UBlLX72rKcydodAsWuMTqt034Jc0SPRR tA2Mmhd+3mNNQHyi3y8Jx+retxNOoSKwhLhGwiNRLYDDtpqNaHZRkikJ7qNo0EbgzPIG LeX17gHzGGZ3s5gPNGGCIdrC3H7zEm0yuHM08= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727116976; x=1727721776; 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=a83cvxp67ZIRrEOBil2F0eDUK9GDuaqDP0wR+nzvNIQ=; b=fMP26fG9Li7SJ9J+ViMyHVy6mSPFmJFDHFFztl3QctWTphTIST40BnSCAp5+ha3xbZ ufuHFQSLXrAQRbv1Jlvhr9jTY9OVT7eE1zZa4m2Y1bEhu1FDmUyGwKSnRwM+db4rGBcN vb49lLrwzMsKv7wiILMd8YkXNGf9g6Ytv6AkhV0L34yJ17iaaBfvk5gHLVVaqI9UiN2T qgDlJFFrfYF9eVQumg2tyr6YDLIdi2AGXE1NwCwaTR9mri+96nbD336+gxAfa4mcjGs7 Nr90HA4ag6TduAkTpButohszM5Pjbw94kAGIbfwXv/miskm8KCnh7vUKeIIspV4yFk/6 N27g== X-Gm-Message-State: AOJu0YwEkAe+fERASyTZHHTZizXdQSgPI4yyXzdI+sApuFr6//gub7Wy CBo1hYKgv2GW9k+nxIDsw+NCFWHQHZaOKW7mX8H7HgzU6I52LKnzNkqFJBpJgkm1ec23o0veXob VizuXW4gMbp8aA6ll1WHFllCPMt3qPA2+B1GOorwCWzoPioxS X-Google-Smtp-Source: AGHT+IERw64q/6HWxx77R8gmxuamig3YWLg9xH1zTGxMPwOVq0WxObOBizLzMItppROueCylWK3nK1qvdCdv X-Received: by 2002:a05:6e02:1c04:b0:3a0:a0bd:f92b with SMTP id e9e14a558f8ab-3a0c9d251e7mr111127185ab.10.1727116976230; Mon, 23 Sep 2024 11:42:56 -0700 (PDT) Received: from postal.iol.unh.edu (postal.iol.unh.edu. [2606:4100:3880:1234::84]) by smtp-relay.gmail.com with ESMTPS id e9e14a558f8ab-3a193732a8esm3061075ab.28.2024.09.23.11.42.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Sep 2024 11:42:56 -0700 (PDT) X-Relaying-Domain: iol.unh.edu Received: from iol.unh.edu (unknown [IPv6:2606:4100:3880:1257::1083]) by postal.iol.unh.edu (Postfix) with ESMTP id 0B612605C351; Mon, 23 Sep 2024 14:42:55 -0400 (EDT) From: jspewock@iol.unh.edu To: npratte@iol.unh.edu, juraj.linkes@pantheon.tech, yoan.picchi@foss.arm.com, thomas@monjalon.net, Honnappa.Nagarahalli@arm.com, probb@iol.unh.edu, wathsala.vithanage@arm.com, paul.szczepanek@arm.com, Luca.Vizzarro@arm.com, alex.chapman@arm.com Cc: dev@dpdk.org, Jeremy Spewock Subject: [PATCH v4 5/5] dts: add functions for managing VFs to Node Date: Mon, 23 Sep 2024 14:42:35 -0400 Message-ID: <20240923184235.22582-6-jspewock@iol.unh.edu> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240923184235.22582-1-jspewock@iol.unh.edu> References: <20240821191557.18744-1-jspewock@iol.unh.edu> <20240923184235.22582-1-jspewock@iol.unh.edu> MIME-Version: 1.0 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 From: Jeremy Spewock In order for test suites to create virtual functions there has to be functions in the API that developers can use. This patch adds the ability to create virtual functions to the Node API so that they are reachable within test suites. Bugzilla ID: 1500 Depends-on: patch-144318 ("dts: add binding to different drivers to TG node") Signed-off-by: Jeremy Spewock --- dts/framework/testbed_model/node.py | 97 ++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 3 deletions(-) diff --git a/dts/framework/testbed_model/node.py b/dts/framework/testbed_model/node.py index 106e189ce3..d9b6ee040b 100644 --- a/dts/framework/testbed_model/node.py +++ b/dts/framework/testbed_model/node.py @@ -13,7 +13,7 @@ The :func:`~Node.skip_setup` decorator can be used without subclassing. """ - +import re from abc import ABC, abstractmethod from ipaddress import IPv4Interface, IPv6Interface from pathlib import PurePath @@ -23,9 +23,10 @@ OS, BuildTargetConfiguration, NodeConfiguration, + PortConfig, TestRunConfiguration, ) -from framework.exception import ConfigurationError +from framework.exception import ConfigurationError, InternalError from framework.logger import DTSLogger, get_dts_logger from framework.settings import SETTINGS @@ -38,7 +39,7 @@ ) from .linux_session import LinuxSession from .os_session import OSSession -from .port import Port +from .port import Port, VirtualFunction class Node(ABC): @@ -276,6 +277,96 @@ def _bind_port_to_driver(self, port: Port, for_dpdk: bool = True) -> None: verify=True, ) + def create_virtual_functions( + self, num: int, pf_port: Port, dpdk_driver: str | None = None + ) -> list[VirtualFunction]: + """Create virtual functions (VFs) from a given physical function (PF) on the node. + + Virtual functions will be created if there are not any currently configured on `pf_port`. + If there are greater than or equal to `num` VFs already configured on `pf_port`, those will + be used instead of creating more. In order to create VFs, the PF must be bound to its + kernel driver. This method will handle binding `pf_port` and any other ports in the test + run that reside on the same device back to their OS drivers if this was not done already. + VFs gathered in this method will be bound to `driver` if one is provided, or the DPDK + driver for `pf_port` and then added to `self.ports`. + + Args: + num: The number of VFs to create. Must be greater than 0. + pf_port: The PF to create the VFs on. + dpdk_driver: Optional driver to bind the VFs to after they are created. Defaults to the + DPDK driver of `pf_port`. + + Raises: + InternalError: If `num` is less than or equal to 0. + """ + if num <= 0: + raise InternalError( + "Method for creating virtual functions received a non-positive value." + ) + if not dpdk_driver: + dpdk_driver = pf_port.os_driver_for_dpdk + # Get any other port that is on the same device which DTS is aware of + all_device_ports = [ + p for p in self.ports if p.pci.split(".")[0] == pf_port.pci.split(".")[0] + ] + # Ports must be bound to the kernel driver in order to create VFs from them + for port in all_device_ports: + self._bind_port_to_driver(port, False) + # Some PMDs require the interface being up in order to make VFs + self.configure_port_state(port) + created_vfs = self.main_session.set_num_virtual_functions(num, pf_port) + # We don't need more then `num` VFs from the list + vf_pcis = self.main_session.get_pci_addr_of_vfs(pf_port)[:num] + devbind_info = self.main_session.send_command( + f"{self.path_to_devbind_script} -s", privileged=True + ).stdout + + ret = [] + + for pci in vf_pcis: + original_driver = re.search(f"{pci}.*drv=([\\d\\w-]*)", devbind_info) + os_driver = original_driver[1] if original_driver else pf_port.os_driver + vf_config = PortConfig( + self.name, pci, dpdk_driver, os_driver, pf_port.peer.node, pf_port.peer.pci + ) + vf_port = VirtualFunction(self.name, vf_config, created_vfs, pf_port) + self.main_session.update_ports([vf_port]) + self._bind_port_to_driver(vf_port) + self.ports.append(vf_port) + ret.append(vf_port) + return ret + + def get_vfs_on_port(self, pf_port: Port) -> list[VirtualFunction]: + """Get all virtual functions (VFs) that DTS is aware of on `pf_port`. + + Args: + pf_port: The port to search for the VFs on. + + Returns: + A list of VFs in the framework that were created/gathered from `pf_port`. + """ + return [p for p in self.ports if isinstance(p, VirtualFunction) and p.pf_port == pf_port] + + def remove_virtual_functions(self, pf_port: Port) -> None: + """Removes all virtual functions (VFs) created on `pf_port` by DTS. + + Finds all the VFs that were created from `pf_port` and either removes them if they were + created by the DTS framework or binds them back to their os_driver if they were preexisting + on the node. + + Args: + pf_port: Port to remove the VFs from. + """ + vf_ports = self.get_vfs_on_port(pf_port) + if any(vf.created_by_framework for vf in vf_ports): + self.main_session.set_num_virtual_functions(0, pf_port) + else: + self._logger.info("Skipping removing VFs since they were not created by DTS.") + # Bind all VFs that we are no longer using back to their original driver + for vf in vf_ports: + self._bind_port_to_driver(vf, for_dpdk=False) + self.ports = [p for p in self.ports if p not in vf_ports] + def create_session(node_config: NodeConfiguration, name: str, logger: DTSLogger) -> OSSession: """Factory for OS-aware sessions.