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 399C8A2EFC for ; Wed, 18 Sep 2019 09:28:00 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 036621BF8A; Wed, 18 Sep 2019 09:28:00 +0200 (CEST) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by dpdk.org (Postfix) with ESMTP id 3BD842C6A for ; Wed, 18 Sep 2019 09:27:58 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Sep 2019 00:27:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,519,1559545200"; d="scan'208";a="202006456" Received: from dpdk-xinfengx-dut242.sh.intel.com ([10.67.117.34]) by fmsmga001.fm.intel.com with ESMTP; 18 Sep 2019 00:27:47 -0700 From: Xinfeng Zhao To: dts@dpdk.org Cc: Xinfeng Zhao Date: Wed, 18 Sep 2019 07:19:21 +0800 Message-Id: <1568762365-19112-1-git-send-email-xinfengx.zhao@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [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" 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 = GTP +# scapy.contrib.status = 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 = { 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" } + +# http://www.arib.or.jp/IMT-2000/V720Mar09/5_Appendix/Rel8/29/29281-800.pdf +ExtensionHeadersTypes = { + 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 = "GTP-C Header" + fields_desc=[ 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==1 or pkt.S==1 or pkt.PN==1), + ConditionalField(ByteField("npdu", 0), lambda pkt:pkt.E==1 or pkt.S==1 or pkt.PN==1), + ConditionalField(ByteEnumField("next_ex", 0, ExtensionHeadersTypes), lambda pkt:pkt.E==1 or pkt.S==1 or pkt.PN==1), ] + + def post_build(self, p, pay): + p += pay + if self.length is None: + l = len(p)-8 + p = 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 == other.version and + self.payload.answers(other.payload)) + + @classmethod + def dispatch_hook(cls, _pkt=None, *args, **kargs): + if _pkt and len(_pkt) >= 1: + if (struct.unpack("B", _pkt[0])[0] >> 5) & 0x7 == 2: + from . import gtp_v2 + return gtp_v2.GTPHeader + if _pkt and len(_pkt) >= 8: + _gtp_type = 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 = "GTP-U Header" + # GTP-U protocol is used to transmit T-PDUs between GSN pairs (or between 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 tunnels may be multiplexed on a single path. + +# Some gtp_types have to be associated with a certain type of header +GTPforcedTypes = { + 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 = 2152) +bind_layers(UDP, GTP_U_Header, sport = 2152) +bind_layers(GTP_U_Header, IP, gtp_type = 255) +bind_layers(GTP_U_Header, IPv6, gtp_type = 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 +## Copyright (C) Philippe Biondi +## This program is 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 = [ 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 = len(pkt)+len(pay) + pkt = pkt[:2]+struct.pack("!H", l)+pkt[4:] + return pkt+pay + +class PPP_L2TP(Packet): + fields_desc = [ 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 = len(pkt)+2+len(pay) + pkt = pkt[:2]+struct.pack("!H", l)+pkt[2:] + return pkt+pay + +bind_layers( UDP, L2TP, sport=1701, dport=1701) +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 = MPLS + +# scapy.contrib.status = loads + + + +from scapy.packet import Packet,bind_layers + +from scapy.fields import BitField,ByteField + +from scapy.layers.l2 import Ether + + + +class MPLS(Packet): + + name = "MPLS" + + fields_desc = [ BitField("label", 3, 20), + + BitField("cos", 0, 3), + + BitField("s", 1, 1), + + ByteField("ttl", 0) ] + + + +bind_layers(Ether, MPLS, type=0x8847) -- 2.17.1