-    def scatter_pktgen_send_packet(self, pktsize: int) -> str:
+    def scatter_pktgen_send_packet(self, pktsize: int) -> list[Packet]:

A note: We should make this method a part of TestSuite (so that we have a common way to filter packets across all test suites) in a separate patchset as part of https://bugs.dpdk.org/show_bug.cgi?id=1438.

          """Generate and send a packet to the SUT then capture what is 
forwarded back.
Generate an IP packet of a specific length and send it to the SUT,
-        then capture the resulting received packet and extract its payload.
-        The desired length of the packet is met by packing its payload
+        then capture the resulting received packets and filter them down to 
the ones that have the
+        correct layers. The desired length of the packet is met by packing its 
payload
          with the letter "X" in hexadecimal.
Args:
              pktsize: Size of the packet to generate and send.
Returns:
-            The payload of the received packet as a string.
+            The filtered down list of received packets.
          """

<snip>

          with testpmd_shell as testpmd:
              testpmd.set_forward_mode(TestPmdForwardingModes.mac)
+            # adjust the MTU of the SUT ports
+            for port_id in range(testpmd.number_of_ports):
+                testpmd.set_port_mtu(port_id, 9000)

For a second I thought about maybe somehow using the decorator from the previous patch, but that only works with testpmd methods.

But then I thought about us setting this multiple times (twice (9000, then back to 1500) in each test case) and that a "better" place to put this would be set_up_suite() (and tear_down_suite()), but that has a major downside of starting testpmd two more times. Having it all in one place in set_up_suite() would surely make the whole test suite more understandable, but starting testpmd multiple times is not ideal. Maybe we have to do it like in this patch.

I also noticed that we don't really document why we're setting MTU to 9000. The relation between MTU and mbuf size (I think that relation is the reason, correct me if I'm wrong) should be better documented, probably in set_up_suite().

              testpmd.start()
for offset in [-1, 0, 1, 4, 5]:
-                recv_payload = self.scatter_pktgen_send_packet(mbsize + offset)
-                self._logger.debug(
-                    f"Payload of scattered packet after forwarding: 
\n{recv_payload}"
-                )
+                recv_packets = self.scatter_pktgen_send_packet(mbsize + offset)
+                self._logger.debug(f"Relevant captured packets: 
\n{recv_packets}")
+
                  self.verify(
-                    ("58 " * 8).strip() in recv_payload,
+                    any(
+                        " ".join(["58"] * 8) in hexstr(pakt.getlayer(2), 
onlyhex=1)
+                        for pakt in recv_packets
+                    ),
                      "Payload of scattered packet did not match expected payload 
with offset "
                      f"{offset}.",
                  )
+            testpmd.stop()

This sneaked right back in.

Reply via email to