test suite reviews and discussions
 help / color / mirror / Atom feed
From: Ke Xu <ke1.xu@intel.com>
To: dts@dpdk.org
Cc: qi.fu@intel.com, weiyuanx.li@intel.com, lijuan.tu@intel.com,
	ke1.xu@intel.com
Subject: [DTS][PATCH V3 1/5] tests/vf_offload: Improve checksum_validate method.
Date: Wed, 28 Dec 2022 13:14:59 +0800	[thread overview]
Message-ID: <20221228051503.36747-2-ke1.xu@intel.com> (raw)
In-Reply-To: <20221228051503.36747-1-ke1.xu@intel.com>

Use packet show dump methods and packet reading to
 validate the packets in a faster, more common and more stable way.

This allows packets other than the plain packets can
 be verified by this method checksum_validate.

Signed-off-by: Ke Xu <ke1.xu@intel.com>
---
 tests/TestSuite_vf_offload.py | 93 +++++++++++++++--------------------
 1 file changed, 39 insertions(+), 54 deletions(-)

diff --git a/tests/TestSuite_vf_offload.py b/tests/TestSuite_vf_offload.py
index 62e74c33..279b38d8 100644
--- a/tests/TestSuite_vf_offload.py
+++ b/tests/TestSuite_vf_offload.py
@@ -253,6 +253,16 @@ class TestVfOffload(TestCase):
         dut.send_expect("tunnel_tso set 800 %d" % port, "testpmd>")
         dut.send_expect("port start %d" % port, "testpmd>")
 
+    def filter_packets(self, packets):
+        return [
+            p
+            for p in packets
+            if len(p.layers()) >= 3
+            and p.layers()[1] in {IP, IPv6}
+            and p.layers()[2] in {IP, IPv6, UDP, TCP, SCTP, GRE, MPLS}
+            and Raw in p
+        ]
+
     def checksum_validate(self, packets_sent, packets_expected):
         """
         Validate the checksum.
@@ -266,17 +276,16 @@ class TestVfOffload(TestCase):
         sniff_src = self.vm0_testpmd.get_port_mac(0)
         checksum_pattern = re.compile("chksum.*=.*(0x[0-9a-z]+)")
         sniff_src = "52:00:00:00:00:00"
-        chksum = dict()
+        expected_chksum_list = dict()
         result = dict()
-
         self.tester.send_expect("scapy", ">>> ")
-
+        self.tester.send_expect("from scapy.contrib.gtp import GTP_U_Header", ">>>")
         for packet_type in list(packets_expected.keys()):
             self.tester.send_expect("p = %s" % packets_expected[packet_type], ">>>")
             out = self.tester.send_expect("p.show2()", ">>>")
-            chksums = checksum_pattern.findall(out)
-            chksum[packet_type] = chksums
-            print(packet_type, ": ", chksums)
+            chksum = checksum_pattern.findall(out)
+            expected_chksum_list[packet_type] = chksum
+            print(packet_type, ": ", chksum)
 
         self.tester.send_expect("exit()", "#")
 
@@ -289,7 +298,7 @@ class TestVfOffload(TestCase):
 
         # Send packet.
         self.tester.scapy_foreground()
-
+        self.tester.scapy_append("from scapy.contrib.gtp import GTP_U_Header")
         for packet_type in list(packets_sent.keys()):
             self.tester.scapy_append(
                 'sendp([%s], iface="%s")' % (packets_sent[packet_type], tx_interface)
@@ -297,58 +306,34 @@ class TestVfOffload(TestCase):
 
         self.tester.scapy_execute()
         out = self.tester.scapy_get_result()
-
-        p = self.tester.load_tcpdump_sniff_packets(inst)
-        nr_packets = len(p)
-        print(p)
-        packets_received = [
-            p[i].sprintf("%IP.chksum%;%TCP.chksum%;%UDP.chksum%;%SCTP.chksum%")
-            for i in range(nr_packets)
-        ]
+        packets_received = self.filter_packets(
+            self.tester.load_tcpdump_sniff_packets(inst)
+        )
+        print(list(packets_received))
 
         self.verify(
             len(packets_sent) == len(packets_received), "Unexpected Packets Drop"
         )
-
-        for packet_received in packets_received:
-            (
-                ip_checksum,
-                tcp_checksum,
-                udp_checksum,
-                sctp_checksum,
-            ) = packet_received.split(";")
-            print(
-                "ip_checksum: ",
-                ip_checksum,
-                "tcp_checksum:, ",
-                tcp_checksum,
-                "udp_checksum: ",
-                udp_checksum,
-                "sctp_checksum: ",
-                sctp_checksum,
+        for i in range(len(packets_sent)):
+            packet_type = list(packets_sent.keys())[i]
+            checksum_received = checksum_pattern.findall(
+                packets_received[i].show2(dump=True)
             )
-
-            packet_type = ""
-            l4_checksum = ""
-            if tcp_checksum != "??":
-                packet_type = "TCP"
-                l4_checksum = tcp_checksum
-            elif udp_checksum != "??":
-                packet_type = "UDP"
-                l4_checksum = udp_checksum
-            elif sctp_checksum != "??":
-                packet_type = "SCTP"
-                l4_checksum = sctp_checksum
-
-            if ip_checksum != "??":
-                packet_type = "IP/" + packet_type
-                if chksum[packet_type] != [ip_checksum, l4_checksum]:
-                    result[packet_type] = packet_type + " checksum error"
-            else:
-                packet_type = "IPv6/" + packet_type
-                if chksum[packet_type] != [l4_checksum]:
-                    result[packet_type] = packet_type + " checksum error"
-
+            checksum_expected = expected_chksum_list[list(packets_sent.keys())[i]]
+            self.logger.debug(f"checksum_received: {checksum_received}")
+            self.logger.debug(f"checksum_expected: {checksum_expected}")
+            if not len(checksum_expected) == len(checksum_received):
+                result[packet_type] = (
+                    packet_type
+                    + " Failed:"
+                    + f"The chksum type {packet_type} length of the actual result is inconsistent with the expected length!"
+                )
+            elif not (checksum_received == checksum_expected):
+                result[packet_type] = (
+                    packet_type
+                    + " Failed:"
+                    + f"The actually received chksum {packet_type} is inconsistent with the expectation"
+                )
         return result
 
     def test_checksum_offload_enable(self):
-- 
2.25.1


  reply	other threads:[~2022-12-28  5:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-28  5:14 [DTS][PATCH V3 0/5] Improve checksum validate and tso packet counting Ke Xu
2022-12-28  5:14 ` Ke Xu [this message]
2022-12-28  5:15 ` [DTS][PATCH V3 2/5] tests/vf_offload: Remove redundant variable used Ke Xu
2022-12-28  5:15 ` [DTS][PATCH V3 3/5] tests/vf_offload: Use modified checksum_validate to replace checksum_validate_tunnel Ke Xu
2022-12-28  5:15 ` [DTS][PATCH V3 4/5] tests/vf_offload: Improve tcpdump_analyse_sniff method Ke Xu
2022-12-28  5:15 ` [DTS][PATCH V3 5/5] tests/vf_offload: Replace the tcpdump implementation to a packet reading implementation Ke Xu
2022-12-28  6:08   ` Li, WeiyuanX
2023-01-03  6:05 ` [DTS][PATCH V3 0/5] Improve checksum validate and tso packet counting Fu, Qi
2023-01-04  1:08 ` Tu, Lijuan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221228051503.36747-2-ke1.xu@intel.com \
    --to=ke1.xu@intel.com \
    --cc=dts@dpdk.org \
    --cc=lijuan.tu@intel.com \
    --cc=qi.fu@intel.com \
    --cc=weiyuanx.li@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).