test suite reviews and discussions
 help / color / mirror / Atom feed
From: LihongX Ma <lihongx.ma@intel.com>
To: dts@dpdk.org
Cc: LihongX Ma <lihongx.ma@intel.com>
Subject: [dts] [PATCH V1 1/4] dep: remove the scapy modules in dep
Date: Tue, 20 Oct 2020 02:31:52 +0800	[thread overview]
Message-ID: <1603132315-19498-2-git-send-email-lihongx.ma@intel.com> (raw)
In-Reply-To: <1603132315-19498-1-git-send-email-lihongx.ma@intel.com>

 - use scapy module igmp instead of local module igmp
 - use scapy module lldp instead of local module lldp
 - use scapy module mpls instead of local module mpls
 - use scapy module nsh instead of local module nsh
 - use scapy module gre instead of local module nvgre
 - use scapy module vxlan instead of local module vxlan

Signed-off-by: LihongX Ma <lihongx.ma@intel.com>
---
 dep/scapy_modules/igmp.py  | 164 ------------------------------
 dep/scapy_modules/lldp.py  | 242 ---------------------------------------------
 dep/scapy_modules/mpls.py  |  24 -----
 dep/scapy_modules/nsh.py   |  67 -------------
 dep/scapy_modules/nvgre.py |  37 -------
 dep/scapy_modules/vxlan.py |  92 -----------------
 6 files changed, 626 deletions(-)
 delete mode 100644 dep/scapy_modules/igmp.py
 delete mode 100644 dep/scapy_modules/lldp.py
 delete mode 100644 dep/scapy_modules/mpls.py
 delete mode 100644 dep/scapy_modules/nsh.py
 delete mode 100644 dep/scapy_modules/nvgre.py
 delete mode 100644 dep/scapy_modules/vxlan.py

diff --git a/dep/scapy_modules/igmp.py b/dep/scapy_modules/igmp.py
deleted file mode 100644
index 5cbf9c0..0000000
--- a/dep/scapy_modules/igmp.py
+++ /dev/null
@@ -1,164 +0,0 @@
-#! /usr/bin/env python
-
-# This file is part of Scapy
-# Scapy is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 2 of the License, or
-# any later version.
-#
-# Scapy is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Scapy. If not, see <http://www.gnu.org/licenses/>.
-
-# flake8: noqa: E501
-
-# scapy.contrib.description = Internet Group Management Protocol v1/v2 (IGMP/IGMPv2)
-# scapy.contrib.status = loads
-
-from __future__ import print_function
-from scapy.compat import chb, orb
-from scapy.error import warning
-from scapy.fields import ByteEnumField, ByteField, IPField, XShortField
-from scapy.layers.inet import IP, IPOption_Router_Alert
-from scapy.layers.l2 import Ether, getmacbyip
-from scapy.packet import bind_layers, Packet
-from scapy.utils import atol, checksum
-
-
-def isValidMCAddr(ip):
-    """convert dotted quad string to long and check the first octet"""
-    FirstOct = atol(ip) >> 24 & 0xFF
-    return (FirstOct >= 224) and (FirstOct <= 239)
-
-
-class IGMP(Packet):
-    """IGMP Message Class for v1 and v2.
-
-This class is derived from class Packet. You  need call "igmpize()"
-so the packet is transformed according the RFC when sent.
-a=Ether(src="00:01:02:03:04:05")
-b=IP(src="1.2.3.4")
-c=IGMP(type=0x12, gaddr="224.2.3.4")
-x = a/b/c
-x[IGMP].igmpize()
-sendp(a/b/c, iface="en0")
-
-    Parameters:
-      type    IGMP type field, 0x11, 0x12, 0x16 or 0x17
-      mrcode  Maximum Response time (zero for v1)
-      gaddr   Multicast Group Address 224.x.x.x/4
-
-See RFC2236, Section 2. Introduction for definitions of proper
-IGMPv2 message format   http://www.faqs.org/rfcs/rfc2236.html
-
-  """
-    name = "IGMP"
-
-    igmptypes = {0x11: "Group Membership Query",
-                 0x12: "Version 1 - Membership Report",
-                 0x16: "Version 2 - Membership Report",
-                 0x17: "Leave Group"}
-
-    fields_desc = [ByteEnumField("type", 0x11, igmptypes),
-                   ByteField("mrcode", 20),
-                   XShortField("chksum", None),
-                   IPField("gaddr", "0.0.0.0")]
-
-    def post_build(self, p, pay):
-        """Called implicitly before a packet is sent to compute and place IGMP checksum.
-
-        Parameters:
-          self    The instantiation of an IGMP class
-          p       The IGMP message in hex in network byte order
-          pay     Additional payload for the IGMP message
-        """
-        p += pay
-        if self.chksum is None:
-            ck = checksum(p)
-            p = p[:2] + chb(ck >> 8) + chb(ck & 0xff) + p[4:]
-        return p
-
-    @classmethod
-    def dispatch_hook(cls, _pkt=None, *args, **kargs):
-        if _pkt and len(_pkt) >= 4:
-            from scapy.contrib.igmpv3 import IGMPv3
-            if orb(_pkt[0]) in [0x22, 0x30, 0x31, 0x32]:
-                return IGMPv3
-            if orb(_pkt[0]) == 0x11 and len(_pkt) >= 12:
-                return IGMPv3
-        return IGMP
-
-    def igmpize(self):
-        """Called to explicitly fixup the packet according to the IGMP RFC
-
-        The rules are:
-        General:
-            1.  the Max Response time is meaningful only in Membership Queries and should be zero
-        IP:
-            1. Send General Group Query to 224.0.0.1 (all systems)
-            2. Send Leave Group to 224.0.0.2 (all routers)
-            3a.Otherwise send the packet to the group address
-            3b.Send reports/joins to the group address
-            4. ttl = 1 (RFC 2236, section 2)
-            5. send the packet with the router alert IP option (RFC 2236, section 2)
-        Ether:
-            1. Recalculate destination
-
-        Returns:
-            True    The tuple ether/ip/self passed all check and represents
-                    a proper IGMP packet.
-            False   One of more validation checks failed and no fields
-                    were adjusted.
-
-        The function will examine the IGMP message to assure proper format.
-        Corrections will be attempted if possible. The IP header is then properly
-        adjusted to ensure correct formatting and assignment. The Ethernet header
-        is then adjusted to the proper IGMP packet format.
-        """
-        gaddr = self.gaddr if hasattr(self, "gaddr") and self.gaddr else "0.0.0.0"  # noqa: E501
-        underlayer = self.underlayer
-        if self.type not in [0x11, 0x30]:                               # General Rule 1  # noqa: E501
-            self.mrcode = 0
-        if isinstance(underlayer, IP):
-            if (self.type == 0x11):
-                if (gaddr == "0.0.0.0"):
-                    underlayer.dst = "224.0.0.1"                        # IP rule 1  # noqa: E501
-                elif isValidMCAddr(gaddr):
-                    underlayer.dst = gaddr                              # IP rule 3a  # noqa: E501
-                else:
-                    warning("Invalid IGMP Group Address detected !")
-                    return False
-            elif ((self.type == 0x17) and isValidMCAddr(gaddr)):
-                underlayer.dst = "224.0.0.2"                           # IP rule 2  # noqa: E501
-            elif ((self.type == 0x12) or (self.type == 0x16)) and (isValidMCAddr(gaddr)):  # noqa: E501
-                underlayer.dst = gaddr                                 # IP rule 3b  # noqa: E501
-            else:
-                warning("Invalid IGMP Type detected !")
-                return False
-            if not any(isinstance(x, IPOption_Router_Alert) for x in underlayer.options):  # noqa: E501
-                underlayer.options.append(IPOption_Router_Alert())
-            underlayer.ttl = 1                                         # IP rule 4
-            _root = self.firstlayer()
-            if _root.haslayer(Ether):
-                # Force recalculate Ether dst
-                _root[Ether].dst = getmacbyip(underlayer.dst)          # Ether rule 1  # noqa: E501
-        from scapy.contrib.igmpv3 import IGMPv3
-        if isinstance(self, IGMPv3):
-            self.encode_maxrespcode()
-        return True
-
-    def mysummary(self):
-        """Display a summary of the IGMP object."""
-        if isinstance(self.underlayer, IP):
-            return self.underlayer.sprintf("IGMP: %IP.src% > %IP.dst% %IGMP.type% %IGMP.gaddr%")  # noqa: E501
-        else:
-            return self.sprintf("IGMP %IGMP.type% %IGMP.gaddr%")
-
-
-bind_layers(IP, IGMP, frag=0,
-            proto=2,
-            ttl=1)
diff --git a/dep/scapy_modules/lldp.py b/dep/scapy_modules/lldp.py
deleted file mode 100644
index 8eb8bea..0000000
--- a/dep/scapy_modules/lldp.py
+++ /dev/null
@@ -1,242 +0,0 @@
-#!/usr/bin/env python
-## 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
-
-## Copyright (c) 2011 Jochen Bartl <jochen.bartl gmail com>
-
-"""
-LLDP (Link Layer Discovery Protocol)
-"""
-
-from scapy.packet import *
-from scapy.fields import *
-from scapy.layers.l2 import Ether
-from scapy.layers.inet6 import IP6Field
-
-_LLDP_tlv_cls = {0: "LLDPDUEnd",
-                 1: "LLDPChassisId",
-                 2: "LLDPPortId",
-                 3: "LLDPTTL",
-                 4: "LLDPPortDescription",
-                 5: "LLDPSystemName",
-                 6: "LLDPSystemDescription",
-                 7: "LLDPSystemCapabilities",
-                 8: "LLDPManagementAddress",
-                 127: "LLDPOrganizationalSpecific"}
-
-_LLDP_tlv_types = {0: "End of LLDPDU",
-                   1: "Chassis Id",
-                   2: "Port Id",
-                   3: "Time to Live",
-                   4: "Port Description",
-                   5: "System Name",
-                   6: "System Description",
-                   7: "System Capabilities",
-                   8: "Management Address",
-                   127: "Organization Specific"}
-
-
-# (oui, subtype)
-# 0x0080c2 - IEEE 802.1
-# 0x00120f - IEEE 802.3
-_LLDPOrgSpec_tlv_cls = {(0x0080c2, 0x01): "LLDPDot1PortVlanId",
-                       }
-
-
-def _LLDPGuessPacketClass(p=None, **kargs):
-    if p is None:
-        return LLDPGeneric(**kargs)
-
-    cls = Raw
-
-    if len(p) >= 2:
-        t = struct.unpack("!B", p[0])[0]
-        t = (0xfe & t) >> 1
-
-        if t != 127:
-            clsname = _LLDP_tlv_cls.get(t, "LLDPGeneric")
-        else:
-            oui = struct.unpack("!I", "\x00" + p[2:5])[0]
-            subtype = struct.unpack("!B", p[5])[0]
-            clsname = _LLDPOrgSpec_tlv_cls.get((oui, subtype), "LLDPOrgSpecGeneric")
-
-        cls = globals()[clsname]
-
-    return cls(p, **kargs)
-
-
-class LLDPGeneric(Packet):
-    name = "LLDP Generic TLV"
-    fields_desc = [BitField("type", 1, 7),
-                   BitFieldLenField("length", None, 9, length_of="value"),
-                   StrLenField("value", "", length_from=lambda x: x.length)]
-
-    def guess_payload_class(self, p):
-        return Padding
-
-    def post_build(self, p, pay):
-        if self.length is None:
-            l = len(p) - 2
-            p = chr((self.type << 1) ^ (l >> 8)).encode() + chr(l & 0xff).encode() + p[2:]
-
-        return p+pay
-
-
-class LLDPOrgSpecGeneric(LLDPGeneric):
-    name = "LLDP Org Spec Generic TLV"
-    fields_desc = [BitField("type", 127, 7),
-                   BitFieldLenField("length", None, 9, length_of="value"),
-                   X3BytesField("oui", 0),
-                   ByteField("subtype", 0),
-                   StrLenField("value", "", length_from=lambda x: x.length - 4)]
-
-
-class LLDPDUEnd(LLDPGeneric):
-    name = "End of LLDPDU"
-    fields_desc = [BitField("type", 0, 7),
-                   BitField("length", 0, 9)]
-
-
-_LLDPChassisId_Subtypes = {0: "Reserved",
-                           1: "Chassis component",
-                           2: "Interface alias",
-                           3: "Port component",
-                           4: "MAC address",
-                           5: "Network address",
-                           6: "Interface name",
-                           7: "Locally assigned"}
-
-
-class LLDPChassisId(LLDPGeneric):
-    name = "LLDP Chassis"
-    fields_desc = [BitField("type", 1, 7),
-                   BitField("length", None, 9),
-                   ByteEnumField("subtype", 4, _LLDPChassisId_Subtypes),
-                   ConditionalField(MACField("macaddr", "00:11:22:33:44:55"), lambda pkt: pkt.subtype == 4),
-                   # TODO Subtype 5, IPv4 / IPv6
-                   # Catch-all field for undefined subtypes
-                   ConditionalField(StrLenField("value", "", length_from=lambda x: x.length - 1),
-                                    lambda pkt: pkt.subtype not in [4])]
-
-
-_LLDPPortId_Subtypes = {0: "Reserved",
-                        1: "Interface alias",
-                        2: "Port component",
-                        3: "MAC address",
-                        4: "Network address",
-                        5: "Interface name",
-                        6: "Agent circuit ID",
-                        7: "Locally assigned"}
-
-
-class LLDPPortId(LLDPGeneric):
-    name = "LLDP PortId"
-    fields_desc = [BitField("type", 2, 7),
-                   BitField("length", None, 9),
-                   ByteEnumField("subtype", 3, _LLDPPortId_Subtypes),
-                   ConditionalField(MACField("macaddr", "00:11:22:33:44:55"), lambda pkt: pkt.subtype == 3),
-                   # TODO Subtype 4, IPv4 / IPv6
-                   # Catch-all field for undefined subtypes
-                   ConditionalField(StrLenField("value", "", length_from=lambda x: x.length - 1),
-                                    lambda pkt: pkt.subtype not in [3])]
-
-
-class LLDPTTL(LLDPGeneric):
-    name = "LLDP TTL"
-    fields_desc = [BitField("type", 3, 7),
-                   BitField("length", None, 9),
-                   ShortField("seconds", 120)]
-
-
-class LLDPPortDescription(LLDPGeneric):
-    name = "LLDP Port Description"
-    type = 4
-    value = "FastEthernet0/1"
-
-
-class LLDPSystemName(LLDPGeneric):
-    name = "LLDP System Name"
-    type = 5
-    value = "Scapy"
-
-
-class LLDPSystemDescription(LLDPGeneric):
-    name = "LLDP System Description"
-    type = 6
-    value = "Scapy"
-
-
-_LLDPSystemCapabilities = ["other", "repeater", "bridge", "wlanap", "router", "telephone", "docsiscable", "stationonly"]
-
-
-class LLDPSystemCapabilities(LLDPGeneric):
-    name = "LLDP System Capabilities"
-    fields_desc = [BitField("type", 7, 7),
-                   BitField("length", None, 9),
-                   # Available capabilities
-                   FlagsField("capabilities", 0, 16, _LLDPSystemCapabilities),
-                   # Enabled capabilities
-                   FlagsField("enabled", 0, 16, _LLDPSystemCapabilities)]
-
-
-_LLDPManagementAddress_Subtype = {1: "IPv4",
-                                  2: "IPv6",
-                                  6: "802"
-                                 }
-
-_LLDPManagementAddress_IfSubtype = {1: "Unknown",
-                                    2: "ifIndex",
-                                    3: "System Port Number"
-                                   }
-
-
-class LLDPManagementAddress(LLDPGeneric):
-    name = "LLDP Management Address"
-    fields_desc = [BitField("type", 8, 7),
-                   BitField("length", None, 9),
-                   ByteField("addrlen", None),
-                   ByteEnumField("addrsubtype", 1, _LLDPManagementAddress_Subtype),
-                   ConditionalField(IPField("ipaddr", "192.168.0.1"), lambda pkt: pkt.addrsubtype == 1),
-                   ConditionalField(IP6Field("ip6addr", "2001:db8::1"), lambda pkt: pkt.addrsubtype == 2),
-                   ConditionalField(MACField("macaddr", "00:11:22:33:44:55"), lambda pkt: pkt.addrsubtype == 6),
-                   ConditionalField(StrLenField("addrval", "", length_from=lambda x: x.addrlen - 1),
-                                    lambda pkt: pkt.addrsubtype not in [1, 2, 6]),
-                   ByteEnumField("ifsubtype", 2, _LLDPManagementAddress_IfSubtype),
-                   IntField("ifnumber", 0),
-                   FieldLenField("oidlen", None, length_of="oid", fmt="B"),
-                   StrLenField("oid", "", length_from=lambda x: x.oidlen)]
-
-    def post_build(self, p, pay):
-        # TODO Remove redundant code. LLDPGeneric.post_build()
-        if self.length is None:
-            l = len(p) - 2
-            p = chr((self.type << 1) ^ (l >> 8)).encode() + chr(l & 0xff).encode() + p[2:]
-
-        if self.addrlen is None:
-            addrlen = len(p) - 2 - 8 - len(self.oid) + 1
-            p = p[:2] + struct.pack("B", addrlen) + p[3:]
-
-        return p+pay
-
-
-_LLDPDot1Subtype = {1: "Port VLAN Id"}
-
-
-class LLDPDot1PortVlanId(LLDPOrgSpecGeneric):
-    name = "LLDP IEEE 802.1 Port VLAN Id"
-    fields_desc = [BitField("type", 127, 7),
-                   BitField("length", None, 9),
-                   # TODO: XThreeBytesEnumField
-                   X3BytesField("oui", 0x0080c2),
-                   ByteEnumField("subtype", 0x01, _LLDPDot1Subtype),
-                   ShortField("vlan", 1)]
-
-
-class LLDP(Packet):
-    name ="LLDP"
-    fields_desc = [PacketListField("tlvlist", [], _LLDPGuessPacketClass)]
-
-
-bind_layers(Ether, LLDP, type=0x88cc)
diff --git a/dep/scapy_modules/mpls.py b/dep/scapy_modules/mpls.py
deleted file mode 100644
index 0b37bba..0000000
--- a/dep/scapy_modules/mpls.py
+++ /dev/null
@@ -1,24 +0,0 @@
-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/scapy_modules/nsh.py b/dep/scapy_modules/nsh.py
deleted file mode 100644
index 2e249c9..0000000
--- a/dep/scapy_modules/nsh.py
+++ /dev/null
@@ -1,67 +0,0 @@
-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)
diff --git a/dep/scapy_modules/nvgre.py b/dep/scapy_modules/nvgre.py
deleted file mode 100644
index 8cb9a87..0000000
--- a/dep/scapy_modules/nvgre.py
+++ /dev/null
@@ -1,37 +0,0 @@
-## This file is part of Scapy
-##
-## Copyright (C) Min Cao <min.cao@intel.com>
-
-"""
-NVGRE (Network Virtual GRE).
-"""
-
-from scapy.packet import *
-from scapy.fields import *
-from scapy.layers.inet import UDP,IP
-from scapy.layers.inet6 import IPv6
-from scapy.layers.l2 import Ether
-from scapy.layers.l2 import GRE
-
-IPPROTO_NVGRE=47
-
-class NVGRE(Packet):
-    name = "Network Virtual GRE"
-    fields_desc = [BitField("c", 0, 1),
-                   BitField("r", 0, 1),
-                   BitField("k", 1, 1),
-                   BitField("s", 0, 1),
-                   BitField("reserved0", 0, 9),
-                   BitField("ver", 0, 3),
-                   XShortField("protocoltype", 0x6558),
-                   X3BytesField("TNI", 1),
-                   ByteField("reserved1", 0)]
-
-    def mysummary(self):
-        return self.sprintf("NVGRE (tni=%NVGRE.tni%)")
-
-
-bind_layers(NVGRE, Ether, protocoltype=0x6558)
-# fix conflict of GRE and NVGRE
-bind_layers(IP, NVGRE, frag=0, proto=IPPROTO_NVGRE)
-
diff --git a/dep/scapy_modules/vxlan.py b/dep/scapy_modules/vxlan.py
deleted file mode 100644
index c2661d6..0000000
--- a/dep/scapy_modules/vxlan.py
+++ /dev/null
@@ -1,92 +0,0 @@
-'''
-Created on Jul 29, 2014
-
-@author: yliu86
-'''
-from scapy.packet import *
-from scapy.fields import *
-from scapy.layers.inet import UDP, IP
-from scapy.layers.inet6 import IPv6
-from scapy.layers.dns import DNS
-from scapy.layers.l2 import Ether
-
-XLAN_PORT=4789
-
-VXLAN_PORT=4789
-_GP_FLAGS = ["R", "R", "R", "A", "R", "R", "D", "R"]
-
-class VXLAN(Packet):
-    name = "VXLAN"
-    fields_desc = [
-        FlagsField("flags", 0x8, 8,
-            ['OAM', 'R', 'NextProtocol', 'Instance',
-            'V1', 'V2', 'R', 'G']),
-        ConditionalField(
-            ShortField("reserved0", 0),
-            lambda pkt: pkt.flags & 0x04,
-        ),
-        ConditionalField(
-            ByteEnumField('NextProtocol', 0,
-                          {0: 'NotDefined',
-                           1: 'IPv4',
-                           2: 'IPv6',
-                           3: 'Ethernet',
-                           4: 'NSH'}),
-            lambda pkt: pkt.flags & 0x04,
-        ),
-        ConditionalField(
-            X3BytesField("reserved1", 0x000000),
-            lambda pkt: (not pkt.flags & 0x80) and (not pkt.flags & 0x04),
-        ),
-        ConditionalField(
-            FlagsField("gpflags", 0x0, 8, _GP_FLAGS),
-            lambda pkt: pkt.flags & 0x80,
-        ),
-        ConditionalField(
-            ShortField("gpid", 0),
-            lambda pkt: pkt.flags & 0x80,
-        ),
-        X3BytesField("vni", 0),
-        XByteField("reserved2", 0x00),
-    ]
-
-    # Use default linux implementation port
-    overload_fields = {
-        UDP: {'dport': 8472},
-    }
-
-    def mysummary(self):
-        if self.flags & 0x80:
-            return self.sprintf("VXLAN (vni=%VXLAN.vni% gpid=%VXLAN.gpid%)")
-        else:
-            return self.sprintf("VXLAN (vni=%VXLAN.vni%)")
-
-    def guess_payload_class(self, payload):
-        if self.flag == vxlanmagic:
-            return VXLAN
-        else:
-            return Packet.guess_payload_class(self, payload)
-
-bind_layers(UDP, VXLAN, dport=4789)  # RFC standard vxlan port
-bind_layers(UDP, VXLAN, dport=4790)  # RFC standard vxlan-gpe port
-bind_layers(UDP, VXLAN, dport=6633)  # New IANA assigned port for use with NSH
-bind_layers(UDP, VXLAN, dport=8472)  # Linux implementation port
-bind_layers(UDP, VXLAN, dport=48879)  # Cisco ACI
-bind_layers(UDP, VXLAN, sport=4789)
-bind_layers(UDP, VXLAN, sport=4790)
-bind_layers(UDP, VXLAN, sport=6633)
-bind_layers(UDP, VXLAN, sport=8472)
-# By default, set both ports to the RFC standard
-bind_layers(UDP, VXLAN, sport=4789, dport=4789)
-
-# Dissection
-bind_bottom_up(VXLAN, Ether, NextProtocol=0)
-bind_bottom_up(VXLAN, IP, NextProtocol=1)
-bind_bottom_up(VXLAN, IPv6, NextProtocol=2)
-bind_bottom_up(VXLAN, Ether, NextProtocol=3)
-bind_bottom_up(VXLAN, Ether, NextProtocol=None)
-# Build
-bind_top_down(VXLAN, Ether, flags=12, NextProtocol=0)
-bind_top_down(VXLAN, IP, flags=12, NextProtocol=1)
-bind_top_down(VXLAN, IPv6, flags=12, NextProtocol=2)
-bind_top_down(VXLAN, Ether, flags=12, NextProtocol=3)
-- 
2.7.4


  reply	other threads:[~2020-10-20  2:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-19 18:31 [dts] [PATCH V1 0/4] use scapy modules instead of local modules LihongX Ma
2020-10-19 18:31 ` LihongX Ma [this message]
2020-10-19 18:31 ` [dts] [PATCH V1 2/4] framework/packet: " LihongX Ma
2020-10-19 18:31 ` [dts] [PATCH V1 3/4] tests: use scapy modules vxlan " LihongX Ma
2020-10-19 18:31 ` [dts] [PATCH V1 4/4] tests: use scapy modules gre instead of local modules nvgre LihongX Ma
2020-10-28  6:35 ` [dts] [PATCH V1 0/4] use scapy modules instead of local modules Tu, Lijuan

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=1603132315-19498-2-git-send-email-lihongx.ma@intel.com \
    --to=lihongx.ma@intel.com \
    --cc=dts@dpdk.org \
    /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).