Update the NSH protocol header fields
[csit.git] / resources / libraries / python / SFC / TunnelProtocol.py
1 # Copyright (c) 2017 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 """
15 This module implements the VxLAN/VXLAN-GPE/NSH protocol
16 for the packet analyse.
17 """
18 from scapy.all import Packet
19 from scapy.all import XByteField, ShortField
20 from scapy.all import BitField, XBitField, IntField
21
22 class VxLAN(Packet):
23     """Define the vxlan protocol for the packet analysis."""
24     name = "vxlan"
25     fields_desc = [XByteField("flags", 0x08), BitField("reserved", 0, 24),
26                    BitField("vni", 0, 24), XByteField("reserved", 0x00)]
27
28 class VxLANGPE(Packet):
29     """Define the vxlan-gpe protocol for the packet analysis."""
30     name = "vxlan-gpe"
31     fields_desc = [XByteField("flags", 0x0c), ShortField("reserved", 0),
32                    XByteField("nextproto", 0x3), BitField("vni", 0, 24),
33                    XByteField("reserved", 0x0)]
34
35 class NSH(Packet):
36     """Define the NSH protocol for the packet analysis."""
37     name = "nsh"
38     fields_desc = [XBitField("Version", 0x0, 2), XBitField("OAM", 0x0, 1),
39                    XBitField("Unassigned", 0x0, 1), XBitField("TTL", 0x0, 6),
40                    XBitField("length", 0x6, 6), XBitField("Unassigned", 0x0, 4),
41                    XBitField("MDtype", 0x1, 4), XByteField("nextproto", 0x3),
42                    IntField("nsp_nsi", 0), IntField("c1", 0),
43                    IntField("c2", 0), IntField("c3", 0), IntField("c4", 0)]

©2016 FD.io a Linux Foundation Collaborative Project. All Rights Reserved.
Linux Foundation is a registered trademark of The Linux Foundation. Linux is a registered trademark of Linus Torvalds.
Please see our privacy policy and terms of use.