From: "Chen, Zhaoyan" <zhaoyan.chen@intel.com>
To: "Ma, LihongX" <lihongx.ma@intel.com>, "dts@dpdk.org" <dts@dpdk.org>
Cc: "Ma, LihongX" <lihongx.ma@intel.com>,
"Chen, Zhaoyan" <zhaoyan.chen@intel.com>
Subject: Re: [dts] [PATCH V2 1/3][nsh] dep: add support of mpls and nsh
Date: Mon, 4 Nov 2019 05:33:09 +0000 [thread overview]
Message-ID: <9DEEADBC57E43F4DA73B571777FECECA41E0F174@SHSMSX104.ccr.corp.intel.com> (raw)
In-Reply-To: <1571089742-7077-1-git-send-email-lihongx.ma@intel.com>
Acked-by: Chen, Zhaoyan <zhaoyan.chen@intel.com>
Regards,
Zhaoyan Chen
> -----Original Message-----
> From: dts <dts-bounces@dpdk.org> On Behalf Of lihong
> Sent: Tuesday, October 15, 2019 5:49 AM
> To: dts@dpdk.org
> Cc: Ma, LihongX <lihongx.ma@intel.com>
> Subject: [dts] [PATCH V2 1/3][nsh] dep: add support of mpls and nsh
>
> Signed-off-by: lihong <lihongx.ma@intel.com>
> ---
> 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
prev parent reply other threads:[~2019-11-04 5:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-14 21:49 lihong
2019-10-14 21:49 ` [dts] [PATCH V2 2/3][nsh] framework/packet: add support of nsh and mpls lihong
2019-11-04 5:33 ` Chen, Zhaoyan
2019-11-22 5:38 ` Tu, Lijuan
2019-10-14 21:49 ` [dts] [PATCH V2 3/3][nsh] tests/uni_pkt: update code lihong
2019-10-16 1:59 ` Ma, LihongX
2019-11-04 5:34 ` Chen, Zhaoyan
2019-11-04 5:33 ` Chen, Zhaoyan [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=9DEEADBC57E43F4DA73B571777FECECA41E0F174@SHSMSX104.ccr.corp.intel.com \
--to=zhaoyan.chen@intel.com \
--cc=dts@dpdk.org \
--cc=lihongx.ma@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).