DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH v1 0/1] dts: adjust packet addressing and sending
@ 2024-09-04 15:28 jspewock
  2024-09-04 15:28 ` [PATCH v1 1/1] dts: add send_packets to test suites and rework packet addressing jspewock
  0 siblings, 1 reply; 4+ messages in thread
From: jspewock @ 2024-09-04 15:28 UTC (permalink / raw)
  To: wathsala.vithanage, paul.szczepanek, thomas, probb, yoan.picchi,
	Luca.Vizzarro, npratte, Honnappa.Nagarahalli, alex.chapman,
	juraj.linkes
  Cc: dev, Jeremy Spewock

From: Jeremy Spewock <jspewock@iol.unh.edu>

This patch was originally part of the dynamic queue test suite series,
but since other patches require it this series creates an independent
patch to allow it to be prioritized.

This patch is slightly different than the one in dynamic queue as this
version supports address updating on packets with multiple IP layers by
modifying the method of checking whether or not the developer updated
the addresses.

Jeremy Spewock (1):
  dts: add send_packets to test suites and rework packet addressing

 dts/framework/test_suite.py            | 87 +++++++++++++++++++-------
 dts/framework/testbed_model/tg_node.py |  9 +++
 2 files changed, 75 insertions(+), 21 deletions(-)

-- 
2.46.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v1 1/1] dts: add send_packets to test suites and rework packet addressing
  2024-09-04 15:28 [PATCH v1 0/1] dts: adjust packet addressing and sending jspewock
@ 2024-09-04 15:28 ` jspewock
  2024-09-09 19:43   ` Dean Marx
  2024-09-12 12:35   ` Patrick Robb
  0 siblings, 2 replies; 4+ messages in thread
From: jspewock @ 2024-09-04 15:28 UTC (permalink / raw)
  To: wathsala.vithanage, paul.szczepanek, thomas, probb, yoan.picchi,
	Luca.Vizzarro, npratte, Honnappa.Nagarahalli, alex.chapman,
	juraj.linkes
  Cc: dev, Jeremy Spewock

From: Jeremy Spewock <jspewock@iol.unh.edu>

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 <jspewock@iol.unh.edu>
---
 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 694b2eba65..11aaa0a93a 100644
--- a/dts/framework/test_suite.py
+++ b/dts/framework/test_suite.py
@@ -199,7 +199,7 @@ def send_packet_and_capture(
         Returns:
             A list of received packets.
         """
-        packet = self._adjust_addresses(packet)
+        packet = self._adjust_addresses([packet])[0]
         return self.tg_node.send_packet_and_capture(
             packet,
             self._tg_port_egress,
@@ -208,6 +208,18 @@ def send_packet_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`.
 
@@ -217,41 +229,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 4ee326e99c..758b676258 100644
--- a/dts/framework/testbed_model/tg_node.py
+++ b/dts/framework/testbed_model/tg_node.py
@@ -83,6 +83,15 @@ def send_packet_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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1 1/1] dts: add send_packets to test suites and rework packet addressing
  2024-09-04 15:28 ` [PATCH v1 1/1] dts: add send_packets to test suites and rework packet addressing jspewock
@ 2024-09-09 19:43   ` Dean Marx
  2024-09-12 12:35   ` Patrick Robb
  1 sibling, 0 replies; 4+ messages in thread
From: Dean Marx @ 2024-09-09 19:43 UTC (permalink / raw)
  To: jspewock
  Cc: wathsala.vithanage, paul.szczepanek, thomas, probb, yoan.picchi,
	Luca.Vizzarro, npratte, Honnappa.Nagarahalli, alex.chapman,
	juraj.linkes, dev

[-- Attachment #1: Type: text/plain, Size: 924 bytes --]

On Wed, Sep 4, 2024 at 11:28 AM <jspewock@iol.unh.edu> wrote:

> From: Jeremy Spewock <jspewock@iol.unh.edu>
>
> 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 <jspewock@iol.unh.edu>
>

Reviewed-by: Dean Marx <dmarx@iol.unh.edu>

[-- Attachment #2: Type: text/html, Size: 1408 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1 1/1] dts: add send_packets to test suites and rework packet addressing
  2024-09-04 15:28 ` [PATCH v1 1/1] dts: add send_packets to test suites and rework packet addressing jspewock
  2024-09-09 19:43   ` Dean Marx
@ 2024-09-12 12:35   ` Patrick Robb
  1 sibling, 0 replies; 4+ messages in thread
From: Patrick Robb @ 2024-09-12 12:35 UTC (permalink / raw)
  To: jspewock
  Cc: wathsala.vithanage, paul.szczepanek, thomas, yoan.picchi,
	Luca.Vizzarro, npratte, Honnappa.Nagarahalli, alex.chapman,
	juraj.linkes, dev

This looks good, except for the fact that a method for sending a list
of packets has been added since you submitted this patch (which does
return the packet list, not that it matters for your application).

So, this will need to be resubmitted with your patch reformatted for
_adjust_addresses() to be used by luca's send_packet_and_capture ->
send_packets_and_capture approach which is now in the framework.

On Wed, Sep 4, 2024 at 11:28 AM <jspewock@iol.unh.edu> wrote:
>
> From: Jeremy Spewock <jspewock@iol.unh.edu>
>
> 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 <jspewock@iol.unh.edu>
> ---
>  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 694b2eba65..11aaa0a93a 100644
> --- a/dts/framework/test_suite.py
> +++ b/dts/framework/test_suite.py
> @@ -199,7 +199,7 @@ def send_packet_and_capture(
>          Returns:
>              A list of received packets.
>          """
> -        packet = self._adjust_addresses(packet)
> +        packet = self._adjust_addresses([packet])[0]
>          return self.tg_node.send_packet_and_capture(
>              packet,
>              self._tg_port_egress,
> @@ -208,6 +208,18 @@ def send_packet_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`.
>
> @@ -217,41 +229,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.

^Just confirming again I think this implementation is fine, the patch
just needs to be reformatted to work on top of the new
testsuite/tgnode pktgen methods. Cheers.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-09-12 12:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-04 15:28 [PATCH v1 0/1] dts: adjust packet addressing and sending jspewock
2024-09-04 15:28 ` [PATCH v1 1/1] dts: add send_packets to test suites and rework packet addressing jspewock
2024-09-09 19:43   ` Dean Marx
2024-09-12 12:35   ` Patrick Robb

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).