From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 51D5FA2EFC for ; Wed, 18 Sep 2019 09:31:39 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 2E8881BF79; Wed, 18 Sep 2019 09:31:39 +0200 (CEST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id 0ACDD1BF79 for ; Wed, 18 Sep 2019 09:31:36 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Sep 2019 00:28:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,519,1559545200"; d="scan'208";a="211768277" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by fmsmga004.fm.intel.com with ESMTP; 18 Sep 2019 00:28:37 -0700 Received: from fmsmsx601.amr.corp.intel.com (10.18.126.81) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 18 Sep 2019 00:28:36 -0700 Received: from fmsmsx601.amr.corp.intel.com (10.18.126.81) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Wed, 18 Sep 2019 00:28:36 -0700 Received: from shsmsx154.ccr.corp.intel.com (10.239.6.54) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.1713.5 via Frontend Transport; Wed, 18 Sep 2019 00:28:36 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.113]) by SHSMSX154.ccr.corp.intel.com ([169.254.7.195]) with mapi id 14.03.0439.000; Wed, 18 Sep 2019 15:28:34 +0800 From: "Zhao, XinfengX" To: "dts@dpdk.org" CC: "Chen, Zhaoyan" Thread-Topic: [dts][PATCH V1 1/5] dep: add dependency modules for ddp suites Thread-Index: AQHVbfKYfJaKBqM/lEK/vBIr+y3aiKcxCWOA Date: Wed, 18 Sep 2019 07:28:34 +0000 Message-ID: <44051B25D8C8784BB77FFB604D6A70CA1208993A@shsmsx102.ccr.corp.intel.com> References: <1568762365-19112-1-git-send-email-xinfengx.zhao@intel.com> In-Reply-To: <1568762365-19112-1-git-send-email-xinfengx.zhao@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dts] [PATCH V1 1/5] dep: add dependency modules for ddp suites 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" Tested-by: Zhao, XinfengX -----Original Message----- From: Zhao, XinfengX=20 Sent: Wednesday, September 18, 2019 7:19 AM To: dts@dpdk.org Cc: Zhao, XinfengX Subject: [dts][PATCH V1 1/5] dep: add dependency modules for ddp suites Signed-off-by: Xinfeng Zhao --- dep/gtp.py | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++ dep/l2tp.py | 50 +++++++++++++++++++++++ dep/mpls.py | 33 +++++++++++++= +++ 3 files changed, 195 insertions(+) create mode 100644 dep/gtp.py create mode 100644 dep/l2tp.py create mode 100644 dep/mpls.py diff --git a/dep/gtp.py b/dep/gtp.py new file mode 100644 index 0000000..693327f --- /dev/null +++ b/dep/gtp.py @@ -0,0 +1,112 @@ +#! /usr/bin/env python + +## Copyright (C) 2017 Alexis Sultan +## 2017 Alessio Deiana +## 2014 Guillaume Valadon +## 2012 ffranz +## +## This program is published under a GPLv2 license + +# scapy.contrib.description =3D GTP +# scapy.contrib.status =3D loads + +from __future__ import absolute_import +from scapy.packet import * +from scapy.fields import * +from scapy.layers.inet import IP, UDP +from scapy.layers.inet6 import IPv6 + +# GTP Data types +GTPmessageType =3D { 1: "echo_request", + 2: "echo_response", + 16: "create_pdp_context_req", + 17: "create_pdp_context_res", + 18: "update_pdp_context_req", + 19: "update_pdp_context_resp", + 20: "delete_pdp_context_req", + 21: "delete_pdp_context_res", + 26: "error_indication", + 27: "pdu_notification_req", + 31: "supported_extension_headers_notification", + 254: "end_marker", + 255: "g_pdu" } + +#=20 +http://www.arib.or.jp/IMT-2000/V720Mar09/5_Appendix/Rel8/29/29281-800.p +df +ExtensionHeadersTypes =3D { + 0: "No more extension headers", + 1: "Reserved", + 2: "Reserved", + 64: "UDP Port", + 192: "PDCP PDU Number", + 193: "Reserved", + 194: "Reserved" + } + +class GTPHeader(Packet): + # 3GPP TS 29.060 V9.1.0 (2009-12) + name =3D "GTP-C Header" + fields_desc=3D[ BitField("version", 1, 3), + BitField("PT", 1, 1), + BitField("reserved", 0, 1), + BitField("E", 0, 1), + BitField("S", 0, 1), + BitField("PN", 0, 1), + ByteEnumField("gtp_type", None, GTPmessageType), + ShortField("length", None), + IntField("teid", 0), + ConditionalField(XBitField("seq", 0, 16), lambda pkt:pkt= .E=3D=3D1 or pkt.S=3D=3D1 or pkt.PN=3D=3D1), + ConditionalField(ByteField("npdu", 0), lambda pkt:pkt.E= =3D=3D1 or pkt.S=3D=3D1 or pkt.PN=3D=3D1), + ConditionalField(ByteEnumField("next_ex", 0,=20 +ExtensionHeadersTypes), lambda pkt:pkt.E=3D=3D1 or pkt.S=3D=3D1 or pkt.PN= =3D=3D1),=20 +] + + def post_build(self, p, pay): + p +=3D pay + if self.length is None: + l =3D len(p)-8 + p =3D p[:2] + struct.pack("!H", l)+ p[4:] + return p + + def hashret(self): + return struct.pack("B", self.version) + self.payload.hashret() + + def answers(self, other): + return (isinstance(other, GTPHeader) and + self.version =3D=3D other.version and + self.payload.answers(other.payload)) + + @classmethod + def dispatch_hook(cls, _pkt=3DNone, *args, **kargs): + if _pkt and len(_pkt) >=3D 1: + if (struct.unpack("B", _pkt[0])[0] >> 5) & 0x7 =3D=3D 2: + from . import gtp_v2 + return gtp_v2.GTPHeader + if _pkt and len(_pkt) >=3D 8: + _gtp_type =3D struct.unpack("!B", _pkt[1:2])[0] + return GTPforcedTypes.get(_gtp_type, GTPHeader) + return cls + +class GTP_U_Header(GTPHeader): + # 3GPP TS 29.060 V9.1.0 (2009-12) + name =3D "GTP-U Header" + # GTP-U protocol is used to transmit T-PDUs between GSN pairs (or betw= een an SGSN and an RNC in UMTS), + # encapsulated in G-PDUs. A G-PDU is a packet including a GTP-U header= and a T-PDU. The Path Protocol + # defines the path and the GTP-U header defines the tunnel. Several tu= nnels may be multiplexed on a single path. + +# Some gtp_types have to be associated with a certain type of header=20 +GTPforcedTypes =3D { + 16: GTPHeader, + 17: GTPHeader, + 18: GTPHeader, + 19: GTPHeader, + 20: GTPHeader, + 21: GTPHeader, + 26: GTP_U_Header, + 27: GTPHeader, + 254: GTP_U_Header, + 255: GTP_U_Header + } + +# Bind GTP-U +bind_layers(UDP, GTP_U_Header, dport =3D 2152) bind_layers(UDP,=20 +GTP_U_Header, sport =3D 2152) bind_layers(GTP_U_Header, IP, gtp_type =3D=20 +255) bind_layers(GTP_U_Header, IPv6, gtp_type =3D 255) diff --git a/dep/l2tp.py b/dep/l2tp.py new file mode 100644 index 0000000..90c2bcf --- /dev/null +++ b/dep/l2tp.py @@ -0,0 +1,50 @@ +## This file is part of Scapy +## See http://www.secdev.org/projects/scapy for more informations ##=20 +Copyright (C) Philippe Biondi ## This program is=20 +published under a GPLv2 license + +""" +L2TP (Layer 2 Tunneling Protocol) for VPNs. + +[RFC 2661] +""" + +import struct + +from scapy.packet import * +from scapy.fields import * +from scapy.layers.inet import UDP +from scapy.layers.ppp import PPP + +class L2TP(Packet): + fields_desc =3D [ ShortEnumField("pkt_type",2,{2:"data"}), + ShortField("len", None), + #ShortField("tunnelid", 0), + ShortField("sessionid", 0), + ShortField("ns", 0), + ShortField("nr", 0), + ShortField("offset", 0) + ] + + def post_build(self, pkt, pay): + if self.len is None: + l =3D len(pkt)+len(pay) + pkt =3D pkt[:2]+struct.pack("!H", l)+pkt[4:] + return pkt+pay + +class PPP_L2TP(Packet): + fields_desc =3D [ ShortEnumField("pkt_type",0x4002,{2:"data"}), + ShortField("tunnelid", 0), + ShortField("sessionid", 0), + ShortField("address_control", 0xff03), + ShortField("proto", 0x0021) ] + #ShortField("proto", None) ] + + def post_build(self, pkt, pay): + if self.pkt_type & 0x4000: + l =3D len(pkt)+2+len(pay) + pkt =3D pkt[:2]+struct.pack("!H", l)+pkt[2:] + return pkt+pay + +bind_layers( UDP, L2TP, sport=3D1701, dport=3D1701) +bind_layers( L2TP, PPP, ) diff --git a/dep/mpls.py b/dep/mpls.py new file mode 100644 index 0000000..e211b7b --- /dev/null +++ b/dep/mpls.py @@ -0,0 +1,33 @@ +# http://trac.secdev.org/scapy/ticket/31 + + + +# scapy.contrib.description =3D MPLS + +# scapy.contrib.status =3D loads + + + +from scapy.packet import Packet,bind_layers + +from scapy.fields import BitField,ByteField + +from scapy.layers.l2 import Ether + + + +class MPLS(Packet): + + name =3D "MPLS" + + fields_desc =3D [ BitField("label", 3, 20), + + BitField("cos", 0, 3), + + BitField("s", 1, 1), + + ByteField("ttl", 0) ] + + + +bind_layers(Ether, MPLS, type=3D0x8847) -- 2.17.1