test suite reviews and discussions
 help / color / mirror / Atom feed
From: "Zhao, XinfengX" <xinfengx.zhao@intel.com>
To: "dts@dpdk.org" <dts@dpdk.org>
Cc: "Chen, Zhaoyan" <zhaoyan.chen@intel.com>
Subject: Re: [dts] [PATCH V1 1/5] dep: add dependency modules for ddp suites
Date: Wed, 18 Sep 2019 07:28:34 +0000	[thread overview]
Message-ID: <44051B25D8C8784BB77FFB604D6A70CA1208993A@shsmsx102.ccr.corp.intel.com> (raw)
In-Reply-To: <1568762365-19112-1-git-send-email-xinfengx.zhao@intel.com>

Tested-by: Zhao, XinfengX <xinfengx.zhao@intel.com>

-----Original Message-----
From: Zhao, XinfengX 
Sent: Wednesday, September 18, 2019 7:19 AM
To: dts@dpdk.org
Cc: Zhao, XinfengX <xinfengx.zhao@intel.com>
Subject: [dts][PATCH V1 1/5] dep: add dependency modules for ddp suites

Signed-off-by: Xinfeng Zhao <xinfengx.zhao@intel.com>
---
 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    <alexis.sultan@sfr.com>
+##               2017 Alessio Deiana <adeiana@gmail.com>
+##               2014 Guillaume Valadon <guillaume.valadon@ssi.gouv.fr>
+##               2012 ffranz <ffranz@iniqua.com>
+##
+## 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.p
+df
+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 <phil@secdev.org> ## 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


      parent reply	other threads:[~2019-09-18  7:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-17 23:19 Xinfeng Zhao
2019-09-17 23:19 ` [dts] [PATCH V1 2/5] tests/TestSuite_ddp_gtp.py: load the local dep module in scapy command Xinfeng Zhao
2019-09-17 23:19 ` [dts] [PATCH V1 3/5] tests/TestSuite_ddp_gtp_qregion.py: " Xinfeng Zhao
2019-09-17 23:19 ` [dts] [PATCH V1 4/5] tests/TestSuite_ddp_mpls.py: " Xinfeng Zhao
2019-09-17 23:19 ` [dts] [PATCH V1 5/5] tests/TestSuite_ddp_ppp_l2tp.py: " Xinfeng Zhao
2019-09-18  7:28 ` Zhao, XinfengX [this message]

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=44051B25D8C8784BB77FFB604D6A70CA1208993A@shsmsx102.ccr.corp.intel.com \
    --to=xinfengx.zhao@intel.com \
    --cc=dts@dpdk.org \
    --cc=zhaoyan.chen@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).