4b4377c895ba3adf50f553abe2dd834eb4437b55
[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("flags", 0x0, 10), XBitField("length", 0x6, 6),
39                    XByteField("MDtype", 0x1), XByteField("nextproto", 0x3),
40                    IntField("nsp_nsi", 0), IntField("c1", 0),
41                    IntField("c2", 0), IntField("c3", 0), IntField("c4", 0)]