From patchwork Wed Dec 28 05:08:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ke Xu X-Patchwork-Id: 121425 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 79E10A0540; Wed, 28 Dec 2022 06:10:24 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 115554161A; Wed, 28 Dec 2022 06:10:24 +0100 (CET) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mails.dpdk.org (Postfix) with ESMTP id DCA1C40FDF for ; Wed, 28 Dec 2022 06:10:22 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672204223; x=1703740223; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NO/XTrGHV0LapGI69dz9JKmzVp9xjaeGJlJ1U9xKSrM=; b=LhlPj3uxRcBYV52EWs3xRJeNPLxkuBURQPpFkmJn1fQVx2xYoOC41es4 77tqvN7+fynmPXCWf9TageD7jVUjLpy2i/nX0biY44E+NsMhthDhXpybj 70dOUa9jk4zTNLG8DGGgT+4+NH/XkkkKwalbspJx26efbGlscPFhAn0I2 jAk9LjaWqyxxcQbUex9FPcUydPSRTK6RNNyq2gkCfDWcm9gCRLx4mA39E cqzlFmhNL6NvjojT8pKTzlB9tFi/FO8EkErTy3qqjBmLy6w9x4peYbcd2 dqxBC8D+VQjigabQbsaLcoyzKnx3tqeGDbx+DJf2peZ8N11Y0Yv7I+e1n A==; X-IronPort-AV: E=McAfee;i="6500,9779,10573"; a="300499465" X-IronPort-AV: E=Sophos;i="5.96,280,1665471600"; d="scan'208";a="300499465" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Dec 2022 21:10:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10573"; a="760536347" X-IronPort-AV: E=Sophos;i="5.96,280,1665471600"; d="scan'208";a="760536347" Received: from dpdk-xuke-lab.sh.intel.com ([10.67.119.8]) by fmsmga002.fm.intel.com with ESMTP; 27 Dec 2022 21:10:20 -0800 From: Ke Xu To: dts@dpdk.org Cc: qi.fu@intel.com, weiyuanx.li@intel.com, lijuan.tu@intel.com, ke1.xu@intel.com Subject: [DTS][PATCH V2 1/5] tests/vf_offload: Improve checksum_validate method. Date: Wed, 28 Dec 2022 13:08:46 +0800 Message-Id: <20221228050850.33004-2-ke1.xu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221228050850.33004-1-ke1.xu@intel.com> References: <20221228050850.33004-1-ke1.xu@intel.com> MIME-Version: 1.0 X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: test suite reviews and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dts-bounces@dpdk.org 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 --- tests/TestSuite_vf_offload.py | 89 +++++++++++++---------------------- 1 file changed, 34 insertions(+), 55 deletions(-) diff --git a/tests/TestSuite_vf_offload.py b/tests/TestSuite_vf_offload.py index 62e74c33..abe7d752 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,28 @@ 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, - ) - - 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" - + 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)) + 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):