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 5BF09459E1; Fri, 20 Sep 2024 20:09:05 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B5BCB43467; Fri, 20 Sep 2024 20:09:03 +0200 (CEST) Received: from mail-oi1-f226.google.com (mail-oi1-f226.google.com [209.85.167.226]) by mails.dpdk.org (Postfix) with ESMTP id 9126F43467 for ; Fri, 20 Sep 2024 20:09:00 +0200 (CEST) Received: by mail-oi1-f226.google.com with SMTP id 5614622812f47-3e06b72f3e7so1534813b6e.0 for ; Fri, 20 Sep 2024 11:09:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1726855739; x=1727460539; 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=ppI3RpkbGsleopSBC/6JWIDqVnCZti/mOTYRxkN5bro=; b=Wsgtod6VIC1y3xRkcUt3V1N9+KD9bXalsr56oUpznQ6o/wWDR2fcAm6jBzJYmFlHv7 y7E6c6RaFDPhs/FgaH6woxzFTm3BSst7+YxG6i/wK8KdAsLwjPzsrMqIHFf5vXmyJf9R BqSHtG1aOwmefwFnJ6TYKDQhJkqbwFNwHuo6I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726855739; x=1727460539; 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=ppI3RpkbGsleopSBC/6JWIDqVnCZti/mOTYRxkN5bro=; b=f3iU2BjRLin7AewnN+BwONnTqPGZQOH7EWdhsIkdYG+eHuFz7bbeEo0k83j8VO2t0t V3FFHsMQFSE3xuu/mJiPsm2hhdEVL2mmXkLLsrDTcKT5QlfqA283YPxwTfscujY4oQjx fhSSiRv/xdpBu7jMhZxTyt2fqOGeT1R65JtHgXvlx/CIpyr6TYAt2paSMxWIx1yZhelH ulwjcpExwYUgvmeSJnuGh2e6p4tLnRzYst5KZMhpuE1g5q7/dysldtSKeUu+hQ+Aa2e4 sZiMShU+kILw3el/QrDV3p93Ww6HdJaM0gjtoVejeoIbDns7RKOrxjZR0AIy4AjupKG1 VbEQ== X-Gm-Message-State: AOJu0Yxolj1SywXzXu5shviOIYRL1noIWymOar8FWsKHIVE8//RKjl0/ Na8KYNC6sLj6wGqfUgK0YPu8J7H+0hx+1Lw8cf5R0u3yO4D4XGtIz9SbkXpXpR8j3M9eKyaUXpW BqhRVWkk6el1Qb60XljWZ9fV4/dyJIgqWEUSbGaF1giaNdACI X-Google-Smtp-Source: AGHT+IEOa64yeyF4Dd5TlRCCz60pdjN18MzhK1AWn3nPynupzWFiCxtWDEaNzi+o9k6PHeiGW4HBtIm2ezSR X-Received: by 2002:a05:6808:1b2a:b0:3d5:188d:46cf with SMTP id 5614622812f47-3e26a7e6f84mr3702463b6e.10.1726855739667; Fri, 20 Sep 2024 11:08:59 -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 006d021491bc7-5e3b0e5045esm195655eaf.17.2024.09.20.11.08.59 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Sep 2024 11:08:59 -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 478966050A6B; Fri, 20 Sep 2024 14:08:58 -0400 (EDT) From: jspewock@iol.unh.edu To: paul.szczepanek@arm.com, Honnappa.Nagarahalli@arm.com, probb@iol.unh.edu, alex.chapman@arm.com, thomas@monjalon.net, Luca.Vizzarro@arm.com, juraj.linkes@pantheon.tech, npratte@iol.unh.edu, yoan.picchi@foss.arm.com, wathsala.vithanage@arm.com Cc: dev@dpdk.org, Jeremy Spewock Subject: [PATCH v2 1/1] dts: add send_packets to test suites and rework packet addressing Date: Fri, 20 Sep 2024 14:08:52 -0400 Message-ID: <20240920180852.34792-2-jspewock@iol.unh.edu> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240920180852.34792-1-jspewock@iol.unh.edu> References: <20240904152827.11914-1-jspewock@iol.unh.edu> <20240920180852.34792-1-jspewock@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 From: Jeremy Spewock Currently the only method provided in the test suite class for sending packets sends a single packet and then captures the results. There is, in some cases, a need to send multiple packets at once while not really needing to capture any traffic received back. The method to do this exists in the traffic generator already, but this patch exposes the method to test suites. This patch also updates the _adjust_addresses method of test suites so that addresses of packets are only modified if the developer did not configure them beforehand. This allows for developers to have more control over the content of their packets when sending them through the framework. Signed-off-by: Jeremy Spewock --- dts/framework/test_suite.py | 87 +++++++++++++++++++------- dts/framework/testbed_model/tg_node.py | 9 +++ 2 files changed, 75 insertions(+), 21 deletions(-) diff --git a/dts/framework/test_suite.py b/dts/framework/test_suite.py index 051509fb86..4c12c4a328 100644 --- a/dts/framework/test_suite.py +++ b/dts/framework/test_suite.py @@ -225,7 +225,7 @@ def send_packets_and_capture( Returns: A list of received packets. """ - packets = [self._adjust_addresses(packet) for packet in packets] + packets = self._adjust_addresses(packets) return self.tg_node.send_packets_and_capture( packets, self._tg_port_egress, @@ -234,6 +234,18 @@ def send_packets_and_capture( duration, ) + def send_packets( + self, + packets: list[Packet], + ) -> None: + """Send packets using the traffic generator and do not capture received traffic. + + Args: + packets: Packets to send. + """ + packets = self._adjust_addresses(packets) + self.tg_node.send_packets(packets, self._tg_port_egress) + def get_expected_packet(self, packet: Packet) -> Packet: """Inject the proper L2/L3 addresses into `packet`. @@ -243,41 +255,74 @@ def get_expected_packet(self, packet: Packet) -> Packet: Returns: `packet` with injected L2/L3 addresses. """ - return self._adjust_addresses(packet, expected=True) + return self._adjust_addresses([packet], expected=True)[0] - def _adjust_addresses(self, packet: Packet, expected: bool = False) -> Packet: + def _adjust_addresses(self, packets: list[Packet], expected: bool = False) -> list[Packet]: """L2 and L3 address additions in both directions. + Packets in `packets` will be directly modified in this method. The returned list of packets + however will be copies of the modified packets in order to keep the two lists distinct. + + Only missing addresses are added to packets, existing addresses will not be overridden. If + any packet in `packets` has multiple IP layers (using GRE, for example) only the inner-most + IP layer will have its addresses adjusted. + Assumptions: Two links between SUT and TG, one link is TG -> SUT, the other SUT -> TG. Args: - packet: The packet to modify. + packets: The packets to modify. expected: If :data:`True`, the direction is SUT -> TG, otherwise the direction is TG -> SUT. + + Returns: + A list containing copies of all packets in `packets` after modification. """ - if expected: - # The packet enters the TG from SUT - # update l2 addresses - packet.src = self._sut_port_egress.mac_address - packet.dst = self._tg_port_ingress.mac_address + ret_packets = [] + for packet in packets: + # The fields parameter of a packet does not include fields of the payload, so this can + # only be the Ether src/dst. + pkt_src_is_unset = "src" not in packet.fields + pkt_dst_is_unset = "dst" not in packet.fields + num_ip_layers = packet.layers().count(IP) + + # Update the last IP layer if there are multiple to account for GRE addressing (the + # framework should be modifying the packet address instead of the tunnel). + l3_to_use = packet.getlayer(IP, num_ip_layers) + if num_ip_layers > 0: + ip_src_is_unset = "src" not in l3_to_use.fields + ip_dst_is_unset = "dst" not in l3_to_use.fields + else: + ip_src_is_unset = None + ip_dst_is_unset = None - # The packet is routed from TG egress to TG ingress - # update l3 addresses - packet.payload.src = self._tg_ip_address_egress.ip.exploded - packet.payload.dst = self._tg_ip_address_ingress.ip.exploded - else: - # 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 + # If `expected` is :data:`True`, the packet enters the TG from SUT, otherwise the + # packet leaves the TG towards the SUT + if pkt_src_is_unset: + packet.src = ( + self._sut_port_egress.mac_address + if expected + else self._tg_port_egress.mac_address + ) + if pkt_dst_is_unset: + packet.dst = ( + self._tg_port_ingress.mac_address + if expected + else self._sut_port_ingress.mac_address + ) - # The packet is routed from TG egress to TG ingress # update l3 addresses - packet.payload.src = self._tg_ip_address_egress.ip.exploded - packet.payload.dst = self._tg_ip_address_ingress.ip.exploded + # The packet is routed from TG egress to TG ingress regardless of whether it is + # expected or not. + if ip_src_is_unset: + l3_to_use.src = self._tg_ip_address_egress.ip.exploded + + if ip_dst_is_unset: + l3_to_use.dst = self._tg_ip_address_ingress.ip.exploded + ret_packets.append(Ether(packet.build())) - return Ether(packet.build()) + return ret_packets def verify(self, condition: bool, failure_description: str) -> None: """Verify `condition` and handle failures. diff --git a/dts/framework/testbed_model/tg_node.py b/dts/framework/testbed_model/tg_node.py index 19b5b6e74c..4179365abb 100644 --- a/dts/framework/testbed_model/tg_node.py +++ b/dts/framework/testbed_model/tg_node.py @@ -83,6 +83,15 @@ def send_packets_and_capture( duration, ) + def send_packets(self, packets: list[Packet], port: Port): + """Send packets without capturing resulting received packets. + + Args: + packets: Packets to send. + port: Port to send the packets on. + """ + self.traffic_generator.send_packets(packets, port) + def close(self) -> None: """Free all resources used by the node. -- 2.46.0