* [dts] [PATCH V1 1/5] dep: add dependency modules for ddp suites
@ 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
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Xinfeng Zhao @ 2019-09-17 23:19 UTC (permalink / raw)
To: dts; +Cc: Xinfeng Zhao
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.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 <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
^ permalink raw reply [flat|nested] 6+ messages in thread
* [dts] [PATCH V1 2/5] tests/TestSuite_ddp_gtp.py: load the local dep module in scapy command
2019-09-17 23:19 [dts] [PATCH V1 1/5] dep: add dependency modules for ddp suites Xinfeng Zhao
@ 2019-09-17 23:19 ` Xinfeng Zhao
2019-09-17 23:19 ` [dts] [PATCH V1 3/5] tests/TestSuite_ddp_gtp_qregion.py: " Xinfeng Zhao
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Xinfeng Zhao @ 2019-09-17 23:19 UTC (permalink / raw)
To: dts; +Cc: Xinfeng Zhao
Signed-off-by: Xinfeng Zhao <xinfengx.zhao@intel.com>
---
tests/TestSuite_ddp_gtp.py | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/tests/TestSuite_ddp_gtp.py b/tests/TestSuite_ddp_gtp.py
index b8f6817..d8e1302 100644
--- a/tests/TestSuite_ddp_gtp.py
+++ b/tests/TestSuite_ddp_gtp.py
@@ -2,15 +2,18 @@
import time
import re
+import os
import sys
import utils
from qemu_kvm import QEMUKvm
from test_case import TestCase
from pmd_output import PmdOutput
-from settings import get_nic_name
+from settings import get_nic_name, FOLDERS
import random
VM_CORES_MASK = 'all'
+CWD = os.getcwd()
+DIR_DEPEND = os.path.join(CWD, FOLDERS['Depends'])
class TestDdpGtp(TestCase):
@@ -294,6 +297,8 @@ class TestDdpGtp(TestCase):
for chksum_opt in ['good chksum', 'bad chksum']:
pkts = self.gtp_packets(
type, tunnel_pkt, inner_L3, match_opt, chk, teid)
+ self.tester.scapy_append("sys.path.append('%s')" % DIR_DEPEND)
+ self.tester.scapy_append("from gtp import *")
for packet_type in pkts.keys():
count = count + 1
self.tester.scapy_append(
--
2.17.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [dts] [PATCH V1 3/5] tests/TestSuite_ddp_gtp_qregion.py: load the local dep module in scapy command
2019-09-17 23:19 [dts] [PATCH V1 1/5] dep: add dependency modules for ddp suites 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 ` Xinfeng Zhao
2019-09-17 23:19 ` [dts] [PATCH V1 4/5] tests/TestSuite_ddp_mpls.py: " Xinfeng Zhao
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Xinfeng Zhao @ 2019-09-17 23:19 UTC (permalink / raw)
To: dts; +Cc: Xinfeng Zhao
Signed-off-by: Xinfeng Zhao <xinfengx.zhao@intel.com>
---
tests/TestSuite_ddp_gtp_qregion.py | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/tests/TestSuite_ddp_gtp_qregion.py b/tests/TestSuite_ddp_gtp_qregion.py
index 4963f5f..c79082a 100644
--- a/tests/TestSuite_ddp_gtp_qregion.py
+++ b/tests/TestSuite_ddp_gtp_qregion.py
@@ -2,12 +2,18 @@
import time
import re
+import os
import sys
import utils
-from scapy.all import *
+from scapy.all import Ether, IP, UDP, IPv6, IPv6
from test_case import TestCase
from pmd_output import PmdOutput
-from settings import get_nic_name
+from settings import get_nic_name, FOLDERS
+import random
+from gtp import *
+
+CWD = os.getcwd()
+DIR_DEPEND = os.path.join(CWD, FOLDERS['Depends'])
class TestDdpGtpQregion(TestCase):
@@ -148,6 +154,8 @@ class TestDdpGtpQregion(TestCase):
"""
pkts = self.gtp_pkts(flowtype, keyword, opt)
for packet_type in pkts.keys():
+ self.tester.scapy_append("sys.path.append('%s')" % DIR_DEPEND)
+ self.tester.scapy_append("from gtp import *")
self.tester.scapy_append(
'sendp([%s], iface="%s")'
% (pkts[packet_type], self.tester_intf))
@@ -210,6 +218,8 @@ class TestDdpGtpQregion(TestCase):
keyword = 'src_ipv6'
pkts = self.gtp_pkts(flowtype, keyword, opt)
for packet_type in pkts.keys():
+ self.tester.scapy_append("sys.path.append('%s')" % DIR_DEPEND)
+ self.tester.scapy_append("from gtp import *")
self.tester.scapy_append(
'sendp([%s], iface="%s")'
% (pkts[packet_type], self.tester_intf))
--
2.17.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [dts] [PATCH V1 4/5] tests/TestSuite_ddp_mpls.py: load the local dep module in scapy command
2019-09-17 23:19 [dts] [PATCH V1 1/5] dep: add dependency modules for ddp suites 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 ` 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 ` [dts] [PATCH V1 1/5] dep: add dependency modules for ddp suites Zhao, XinfengX
4 siblings, 0 replies; 6+ messages in thread
From: Xinfeng Zhao @ 2019-09-17 23:19 UTC (permalink / raw)
To: dts; +Cc: Xinfeng Zhao
Signed-off-by: Xinfeng Zhao <xinfengx.zhao@intel.com>
---
tests/TestSuite_ddp_mpls.py | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/tests/TestSuite_ddp_mpls.py b/tests/TestSuite_ddp_mpls.py
index 547e1c9..8e74047 100644
--- a/tests/TestSuite_ddp_mpls.py
+++ b/tests/TestSuite_ddp_mpls.py
@@ -1,6 +1,7 @@
# <COPYRIGHT_TAG>
import time
+import os
import sys
import utils
from scapy.utils import rdpcap
@@ -8,12 +9,15 @@ from scapy.utils import rdpcap
from qemu_kvm import QEMUKvm
from test_case import TestCase
from pmd_output import PmdOutput
-from settings import get_nic_name
+from settings import get_nic_name, FOLDERS
import random
VM_CORES_MASK = 'all'
PF_MAX_QUEUE = 64
VF_MAX_QUEUE = 4
+CWD = os.getcwd()
+DIR_DEPEND = os.path.join(CWD, FOLDERS['Depends'])
+
class Testddp_mpls(TestCase):
supported_vf_driver = ['pci-stub', 'vfio-pci']
@@ -175,7 +179,9 @@ class Testddp_mpls(TestCase):
/MPLS(label=%s)/Ether()/IP()/UDP()'% label,
'mpls/bad chksum gre': 'Ether()/IP(proto=47)/GRE(chksum=0x1234,\
proto=0x8847)/MPLS(label=%s)/Ether()/IP()/UDP()'% label }
- for packet_type in pkts.keys():
+ for packet_type in pkts.keys():
+ self.tester.scapy_append("sys.path.append('%s')" % DIR_DEPEND)
+ self.tester.scapy_append("from mpls import *")
self.tester.scapy_append('sendp([%s], iface="%s")'
% (pkts[packet_type], self.tester_intf))
self.tester.scapy_execute()
--
2.17.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [dts] [PATCH V1 5/5] tests/TestSuite_ddp_ppp_l2tp.py: load the local dep module in scapy command
2019-09-17 23:19 [dts] [PATCH V1 1/5] dep: add dependency modules for ddp suites Xinfeng Zhao
` (2 preceding siblings ...)
2019-09-17 23:19 ` [dts] [PATCH V1 4/5] tests/TestSuite_ddp_mpls.py: " Xinfeng Zhao
@ 2019-09-17 23:19 ` Xinfeng Zhao
2019-09-18 7:28 ` [dts] [PATCH V1 1/5] dep: add dependency modules for ddp suites Zhao, XinfengX
4 siblings, 0 replies; 6+ messages in thread
From: Xinfeng Zhao @ 2019-09-17 23:19 UTC (permalink / raw)
To: dts; +Cc: Xinfeng Zhao
Signed-off-by: Xinfeng Zhao <xinfengx.zhao@intel.com>
---
tests/TestSuite_ddp_ppp_l2tp.py | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/tests/TestSuite_ddp_ppp_l2tp.py b/tests/TestSuite_ddp_ppp_l2tp.py
index 2dd8baf..b1dc755 100644
--- a/tests/TestSuite_ddp_ppp_l2tp.py
+++ b/tests/TestSuite_ddp_ppp_l2tp.py
@@ -2,13 +2,18 @@
import time
import re
+import os
import sys
import utils
from test_case import TestCase
from pmd_output import PmdOutput
-from settings import get_nic_name
-from scapy.all import *
+from settings import get_nic_name, FOLDERS
+from scapy.all import Ether, IP, UDP, IPv6, IPv6, PPPoE
import random
+from l2tp import *
+
+CWD = os.getcwd()
+DIR_DEPEND = os.path.join(CWD, FOLDERS['Depends'])
class TestDdpPppL2tp(TestCase):
@@ -147,6 +152,8 @@ class TestDdpPppL2tp(TestCase):
"""
pkts = self.ppp_l2tp_pkts(flowtype, keyword)
for packet_type in pkts.keys():
+ self.tester.scapy_append("sys.path.append('%s')" % DIR_DEPEND)
+ self.tester.scapy_append("from l2tp import *")
self.tester.scapy_append(
'sendp([%s], iface="%s")'
% (pkts[packet_type], self.tester_intf))
--
2.17.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [dts] [PATCH V1 1/5] dep: add dependency modules for ddp suites
2019-09-17 23:19 [dts] [PATCH V1 1/5] dep: add dependency modules for ddp suites Xinfeng Zhao
` (3 preceding siblings ...)
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
4 siblings, 0 replies; 6+ messages in thread
From: Zhao, XinfengX @ 2019-09-18 7:28 UTC (permalink / raw)
To: dts; +Cc: Chen, Zhaoyan
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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-09-18 7:31 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-17 23:19 [dts] [PATCH V1 1/5] dep: add dependency modules for ddp suites 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 ` [dts] [PATCH V1 1/5] dep: add dependency modules for ddp suites Zhao, XinfengX
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).