From patchwork Mon Oct 19 18:31:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ma, LihongX" X-Patchwork-Id: 81410 Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id DD9CFA04DD; Tue, 20 Oct 2020 04:06:37 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 51A15BC56; Tue, 20 Oct 2020 04:06:36 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id C0FE2BBF0 for ; Tue, 20 Oct 2020 04:06:34 +0200 (CEST) IronPort-SDR: MjSrZiU+dY8VtC2aNC/gN0Uv37vA20cMHEYiOolGLbHTj7GeHHSpmVATlE4sq6VFcFDyPdSXtz TA1beIE+KQGA== X-IronPort-AV: E=McAfee;i="6000,8403,9779"; a="154923991" X-IronPort-AV: E=Sophos;i="5.77,395,1596524400"; d="scan'208";a="154923991" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Oct 2020 19:06:34 -0700 IronPort-SDR: wkyJ09chLsnaogO0tJW5MpYDZLbKsX0oCJEEO+sYzgLJ8kAh40ZxyI6qfrxOOv/eoHb8PDFJNC E0Fl99f7g2xg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,395,1596524400"; d="scan'208";a="465751279" Received: from dpdk-lihong-ub1604.sh.intel.com ([10.67.118.174]) by orsmga004.jf.intel.com with ESMTP; 19 Oct 2020 19:06:33 -0700 From: LihongX Ma To: dts@dpdk.org Cc: LihongX Ma Date: Tue, 20 Oct 2020 02:31:53 +0800 Message-Id: <1603132315-19498-3-git-send-email-lihongx.ma@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1603132315-19498-1-git-send-email-lihongx.ma@intel.com> References: <1603132315-19498-1-git-send-email-lihongx.ma@intel.com> Subject: [dts] [PATCH V1 2/4] framework/packet: use scapy modules instead of local modules X-BeenThere: dts@dpdk.org X-Mailman-Version: 2.1.15 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 Sender: "dts" - use GRE instead of NVGRE - use LLDPDU, LLDPDUManagementAddress instead of LLDP and LLDPManagementAddress - as vxlan is the default supported layers, delete the extra import action - add api to analysis the scapy string that include NVGRE field, and will use GRE instead of it Signed-off-by: LihongX Ma --- framework/packet.py | 49 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/framework/packet.py b/framework/packet.py index a7cd172..44b8e0e 100644 --- a/framework/packet.py +++ b/framework/packet.py @@ -51,10 +51,9 @@ sys.path.append(DEP_FOLDER + '/scapy_modules') from utils import convert_ip2int from utils import convert_int2ip -scapy_modules_required = {'nvgre': ['NVGRE', 'IPPROTO_NVGRE'], - 'gtp': ['GTP_U_Header', 'GTP_PDUSession_ExtensionHeader'], - 'lldp': ['LLDP', 'LLDPManagementAddress'], 'Dot1BR': ['Dot1BR'], 'pfcp': ['PFCP'], - 'nsh': ['NSH'], 'igmp': ['IGMP'], 'mpls': ['MPLS'], 'sctp': ['SCTP', 'SCTPChunkData'], 'vxlan': ['VXLAN']} +scapy_modules_required = {'gtp': ['GTP_U_Header', 'GTP_PDUSession_ExtensionHeader'], + 'lldp': ['LLDPDU', 'LLDPDUManagementAddress'], 'Dot1BR': ['Dot1BR'], 'pfcp': ['PFCP'], + 'nsh': ['NSH'], 'igmp': ['IGMP'], 'mpls': ['MPLS'], 'sctp': ['SCTP', 'SCTPChunkData']} local_modules = [m[:-3] for m in os.listdir(DEP_FOLDER + '/scapy_modules') if (m.endswith('.py') and not m.startswith('__'))] for m in scapy_modules_required: @@ -91,6 +90,14 @@ LayersTypes = { # ipv4_ext_unknown, ipv6_ext_unknown "L3": ['ipv4', 'ipv4ihl', 'ipv6', 'ipv4_ext', 'ipv6_ext', 'ipv6_ext2', 'ipv6_frag'], "L4": ['tcp', 'udp', 'frag', 'sctp', 'icmp', 'nofrag'], + # The NVGRE pkt format is + # <'ether type'=0x0800 'version'=4, 'protocol'=47 'protocol type'=0x6558> + # or + # <'ether type'=0x86DD 'version'=6, 'next header'=47 'protocol type'=0x6558'> + # The GRE pkt format is + # <'ether type'=0x0800 'version'=4, 'protocol'=17 'destination port'=4789> + # or + # <'ether type'=0x86DD 'version'=6, 'next header'=17 'destination port'=4789> "TUNNEL": ['ip', 'gre', 'vxlan', 'nvgre', 'geneve', 'grenat'], "INNER L2": ['inner_mac', 'inner_vlan'], # inner_ipv4_unknown, inner_ipv6_unknown @@ -145,14 +152,14 @@ class scapy(object): 'inner_sctp': SCTP(), 'inner_icmp': ICMP(), - 'lldp': LLDP() / LLDPManagementAddress(), + 'lldp': LLDPDU() / LLDPDUManagementAddress(_length=6, _management_address_string_length=6,management_address=':12') / IP(), 'ip_frag': IP(frag=5), 'ipv6_frag': IPv6(src="::1") / IPv6ExtHdrFragment(), 'ip_in_ip': IP() / IP(), 'ip_in_ip_frag': IP() / IP(frag=5), 'ipv6_in_ip': IP() / IPv6(src="::1"), 'ipv6_frag_in_ip': IP() / IPv6(src="::1", nh=44) / IPv6ExtHdrFragment(), - 'nvgre': NVGRE(), + 'nvgre': GRE(key_present=1,proto=0x6558,key=0x00000100), 'geneve': "Not Implement", } @@ -685,8 +692,34 @@ class Packet(object): pkts_str = method_pattern.sub(i.strip('<>')+'()', pkts_str, count=1) return pkts_str + # use the GRE to configure the nvgre package + # the field key last Byte configure the reserved1 of NVGRE, first 3 Bytes configure the TNI value of NVGRE + def transform_nvgre_layer(self, pkt_str): + tni = re.search('TNI\s*=\s*(0x)*(\d*)', pkt_str) + if tni is None: + nvgre = 'GRE(key_present=1,proto=0x6558,key=0x00000100)' + else: + tni = int(tni.group(2)) + tni = tni<<8 + nvgre = 'GRE(key_present=1,proto=0x6558,key=%d)' % tni + pkt_str = re.sub(r'NVGRE\(\)|NVGRE\(TNI=\s*(0x)*\d*\)', nvgre, pkt_str) + return pkt_str + + def gernerator_pkt_str(self): + pkt_str_list = [] + for p in self.pktgen.pkts: + if not isinstance(p, str): + p_str = p.command() + else: + p_str = p + # process the NVGRE + if 'NVGRE' in p_str: + p_str = self.transform_nvgre_layer(p_str) + pkt_str_list.append(p_str) + return '[' + ','.join(pkt_str_list) + ']' + def send_pkt(self, crb, tx_port='', count=1, interval=0, timeout=120): - p_str = '[' + ','.join([p.command() if not isinstance(p, str) else p for p in self.pktgen.pkts]) + ']' + p_str = self.gernerator_pkt_str() pkts_str = self._recompose_pkts_str(pkts_str=p_str) cmd = 'sendp(' + pkts_str + f',iface="{tx_port}",count={count},inter={interval},verbose=False)' if crb.name == 'tester': @@ -700,7 +733,7 @@ class Packet(object): if crb.name != 'tester': raise Exception('crb should be tester') scapy_session_bg = crb.prepare_scapy_env() - p_str = '[' + ','.join([p.command() if not isinstance(p, str) else p for p in self.pktgen.pkts]) + ']' + p_str = self.gernerator_pkt_str() pkts_str = self._recompose_pkts_str(pkts_str=p_str) cmd = 'sendp(' + pkts_str + f',iface="{tx_port}",count={count},inter={interval},loop={loop},verbose=False)' scapy_session_bg.send_command(cmd)