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 19247A3160 for ; Fri, 11 Oct 2019 09:50:11 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id F32721E974; Fri, 11 Oct 2019 09:50:10 +0200 (CEST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by dpdk.org (Postfix) with ESMTP id 7B82B1E957 for ; Fri, 11 Oct 2019 09:50:07 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Oct 2019 00:50:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.67,283,1566889200"; d="scan'208";a="198628081" Received: from dpdk-lihong-ub1604.sh.intel.com ([10.67.118.203]) by orsmga006.jf.intel.com with ESMTP; 11 Oct 2019 00:50:06 -0700 From: lihong To: dts@dpdk.org Cc: lihong Date: Fri, 11 Oct 2019 08:25:05 +0800 Message-Id: <1570753506-1810-2-git-send-email-lihongx.ma@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1570753506-1810-1-git-send-email-lihongx.ma@intel.com> References: <1570753506-1810-1-git-send-email-lihongx.ma@intel.com> Subject: [dts] [PATCH V1 2/3][nsh] dep: add support of mpls and nsh 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: lihong --- dep/mpls.py | 24 ++++++++++++++++++++++ dep/nsh.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 dep/mpls.py create mode 100644 dep/nsh.py diff --git a/dep/mpls.py b/dep/mpls.py new file mode 100644 index 0000000..0b37bba --- /dev/null +++ b/dep/mpls.py @@ -0,0 +1,24 @@ +from scapy.packet import Packet, bind_layers, Padding +from scapy.fields import BitField,ByteField +from scapy.layers.inet import IP +from scapy.layers.inet6 import IPv6 +from scapy.layers.l2 import Ether, GRE + +class MPLS(Packet): + name = "MPLS" + fields_desc = [ BitField("label", 3, 20), + BitField("cos", 0, 3), + BitField("s", 1, 1), + ByteField("ttl", 0) ] + + def guess_payload_class(self, payload): + if len(payload) >= 1: + ip_version = (ord(payload[0]) >> 4) & 0xF + if ip_version == 4: + return IP + elif ip_version == 6: + return IPv6 + return Padding + +bind_layers(Ether, MPLS, type=0x8847) +bind_layers(GRE, MPLS, proto=0x8847) diff --git a/dep/nsh.py b/dep/nsh.py new file mode 100644 index 0000000..2e249c9 --- /dev/null +++ b/dep/nsh.py @@ -0,0 +1,67 @@ +from scapy.packet import * +from scapy.fields import * +from scapy.layers.inet import Ether, IP +from scapy.layers.inet6 import IPv6 +from vxlan import VXLAN +from mpls import MPLS + + +class Metadata(Packet): + name = 'NSH metadata' + fields_desc = [XIntField('value', 0)] + + +class NSHTLV(Packet): + "NSH MD-type 2 - Variable Length Context Headers" + name = "NSHTLV" + fields_desc = [ + ShortField('Class', 0), + BitField('Critical', 0, 1), + BitField('Type', 0, 7), + BitField('Reserved', 0, 3), + BitField('Len', 0, 5), + PacketListField('Metadata', None, XIntField, count_from='Len') + ] + + +class NSH(Packet): + """Network Service Header. + NSH MD-type 1 if there is no ContextHeaders""" + name = "NSH" + + fields_desc = [ + BitField('Ver', 0, 2), + BitField('OAM', 0, 1), + BitField('Critical', 0, 1), + BitField('Reserved', 0, 6), + BitField('Len', 0, 6), + ByteEnumField('MDType', 1, {1: 'Fixed Length', + 2: 'Variable Length'}), + ByteEnumField('NextProto', 3, {1: 'IPv4', + 2: 'IPv6', + 3: 'Ethernet', + 4: 'NSH', + 5: 'MPLS'}), + X3BytesField('NSP', 0), + ByteField('NSI', 1), + ConditionalField(XIntField('NPC', 0), lambda pkt: pkt.MDType == 1), + ConditionalField(XIntField('NSC', 0), lambda pkt: pkt.MDType == 1), + ConditionalField(XIntField('SPC', 0), lambda pkt: pkt.MDType == 1), + ConditionalField(XIntField('SSC', 0), lambda pkt: pkt.MDType == 1), + ConditionalField(PacketListField("ContextHeaders", None, + NSHTLV, count_from="Length"), + lambda pkt: pkt.MDType == 2) + ] + + def mysummary(self): + return self.sprintf("NSP: %NSP% - NSI: %NSI%") + + +bind_layers(Ether, NSH, {'type': 0x894F}, type=0x894F) +bind_layers(VXLAN, NSH, {'flags': 0xC, 'NextProtocol': 4}, NextProtocol=4) + +bind_layers(NSH, IP, {'NextProto': 1}, NextProto=1) +bind_layers(NSH, IPv6, {'NextProto': 2}, NextProto=2) +bind_layers(NSH, Ether, {'NextProto': 3}, NextProto=3) +bind_layers(NSH, NSH, {'NextProto': 4}, NextProto=4) +bind_layers(NSH, MPLS, {'NextProto': 5}, NextProto=5) -- 2.7.4