PcapPlusPlus  Next
VxlanLayer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Layer.h"
4 
6 
9 namespace pcpp
10 {
13 #pragma pack(push, 1)
14  struct vxlan_header
15  {
16 #if (BYTE_ORDER == LITTLE_ENDIAN)
18  uint16_t reserved6_8 : 3;
20  uint16_t vniPresentFlag : 1;
22  uint16_t reserved2_4 : 3;
24  uint16_t gbpFlag : 1;
26  uint16_t reserved14_16 : 3;
28  uint16_t policyAppliedFlag : 1;
30  uint16_t reserved11_12 : 2;
32  uint16_t dontLearnFlag : 1;
34  uint16_t reserved9 : 1;
35 #else
37  uint16_t reserved9 : 1;
39  uint16_t dontLearnFlag : 1;
41  uint16_t reserved11_12 : 2;
43  uint16_t policyAppliedFlag : 1;
45  uint16_t reserved14_16 : 3;
47  uint16_t gbpFlag : 1;
49  uint16_t reserved2_4 : 3;
51  uint16_t vniPresentFlag : 1;
53  uint16_t reserved6_8 : 3;
54 #endif
55 
57  uint16_t groupPolicyID;
58 
60  uint32_t vni : 24;
62  uint32_t pad : 8;
63  };
64 #pragma pack(pop)
65  static_assert(sizeof(vxlan_header) == 8, "vxlan_header size is not 8 bytes");
66 
69  class VxlanLayer : public Layer
70  {
71  public:
77  VxlanLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
78  : Layer(data, dataLen, prevLayer, packet, VXLAN)
79  {}
80 
88  explicit VxlanLayer(uint32_t vni = 0, uint16_t groupPolicyID = 0, bool setGbpFlag = false,
89  bool setPolicyAppliedFlag = false, bool setDontLearnFlag = false);
90 
91  ~VxlanLayer() override = default;
92 
97  {
98  return reinterpret_cast<vxlan_header*>(m_Data);
99  }
100 
102  uint32_t getVNI() const;
103 
106  void setVNI(uint32_t vni);
107 
110  static bool isVxlanPort(uint16_t port)
111  {
112  return port == 4789;
113  }
114 
115  // implement abstract methods
116 
118  void parseNextLayer() override;
119 
121  size_t getHeaderLen() const override
122  {
123  return sizeof(vxlan_header);
124  }
125 
127  void computeCalculateFields() override
128  {}
129 
130  std::string toString() const override;
131 
133  {
134  return OsiModelDataLinkLayer;
135  }
136  };
137 } // namespace pcpp
Definition: Layer.h:60
Definition: Packet.h:22
Definition: VxlanLayer.h:70
uint32_t getVNI() const
void computeCalculateFields() override
Does nothing for this layer.
Definition: VxlanLayer.h:127
std::string toString() const override
vxlan_header * getVxlanHeader() const
Definition: VxlanLayer.h:96
void parseNextLayer() override
Next layer for VXLAN is always Ethernet.
OsiModelLayer getOsiModelLayer() const override
Definition: VxlanLayer.h:132
VxlanLayer(uint32_t vni=0, uint16_t groupPolicyID=0, bool setGbpFlag=false, bool setPolicyAppliedFlag=false, bool setDontLearnFlag=false)
static bool isVxlanPort(uint16_t port)
Definition: VxlanLayer.h:110
size_t getHeaderLen() const override
Definition: VxlanLayer.h:121
void setVNI(uint32_t vni)
VxlanLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: VxlanLayer.h:77
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
An enum representing OSI model layers.
Definition: ProtocolType.h:225
@ OsiModelDataLinkLayer
Data link layer (layer 2)
Definition: ProtocolType.h:229
const ProtocolType VXLAN
VXLAN protocol.
Definition: ProtocolType.h:113
Definition: VxlanLayer.h:15
uint16_t policyAppliedFlag
Policy applied flag.
Definition: VxlanLayer.h:28
uint16_t gbpFlag
GBP flag.
Definition: VxlanLayer.h:24
uint16_t reserved11_12
Reserved bits.
Definition: VxlanLayer.h:30
uint32_t vni
VXLAN Network ID (VNI)
Definition: VxlanLayer.h:60
uint16_t reserved14_16
Reserved bits.
Definition: VxlanLayer.h:26
uint16_t vniPresentFlag
VNI present flag.
Definition: VxlanLayer.h:20
uint16_t reserved9
Reserved bits.
Definition: VxlanLayer.h:34
uint16_t dontLearnFlag
Don't learn flag.
Definition: VxlanLayer.h:32
uint16_t groupPolicyID
Group Policy ID.
Definition: VxlanLayer.h:57
uint32_t pad
Reserved bits.
Definition: VxlanLayer.h:62
uint16_t reserved6_8
Reserved bits.
Definition: VxlanLayer.h:18
uint16_t reserved2_4
Reserved bits.
Definition: VxlanLayer.h:22