PcapPlusPlus  Next
VxlanLayer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Layer.h"
4 
6 
7 namespace pcpp
8 {
9 
14 #pragma pack(push, 1)
15  struct vxlan_header
16  {
17 #if (BYTE_ORDER == LITTLE_ENDIAN)
19  uint16_t reserved6_8 : 3;
21  uint16_t vniPresentFlag : 1;
23  uint16_t reserved2_4 : 3;
25  uint16_t gbpFlag : 1;
27  uint16_t reserved14_16 : 3;
29  uint16_t policyAppliedFlag : 1;
31  uint16_t reserved11_12 : 2;
33  uint16_t dontLearnFlag : 1;
35  uint16_t reserved9 : 1;
36 #else
38  uint16_t reserved9 : 1;
40  uint16_t dontLearnFlag : 1;
42  uint16_t reserved11_12 : 2;
44  uint16_t policyAppliedFlag : 1;
46  uint16_t reserved14_16 : 3;
48  uint16_t gbpFlag : 1;
50  uint16_t reserved2_4 : 3;
52  uint16_t vniPresentFlag : 1;
54  uint16_t reserved6_8 : 3;
55 #endif
56 
58  uint16_t groupPolicyID;
59 
61  uint32_t vni : 24;
63  uint32_t pad : 8;
64  };
65 #pragma pack(pop)
66 
71  class VxlanLayer : public Layer
72  {
73  public:
80  VxlanLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
81  : Layer(data, dataLen, prevLayer, packet, VXLAN)
82  {}
83 
93  explicit VxlanLayer(uint32_t vni = 0, uint16_t groupPolicyID = 0, bool setGbpFlag = false,
94  bool setPolicyAppliedFlag = false, bool setDontLearnFlag = false);
95 
96  ~VxlanLayer() override = default;
97 
104  {
105  return reinterpret_cast<vxlan_header*>(m_Data);
106  }
107 
111  uint32_t getVNI() const;
112 
117  void setVNI(uint32_t vni);
118 
123  static bool isVxlanPort(uint16_t port)
124  {
125  return port == 4789;
126  }
127 
128  // implement abstract methods
129 
133  void parseNextLayer() override;
134 
138  size_t getHeaderLen() const override
139  {
140  return sizeof(vxlan_header);
141  }
142 
146  void computeCalculateFields() override
147  {}
148 
149  std::string toString() const override;
150 
152  {
153  return OsiModelDataLinkLayer;
154  }
155  };
156 
157 } // namespace pcpp
Definition: Layer.h:69
Definition: Packet.h:27
Definition: VxlanLayer.h:72
uint32_t getVNI() const
void computeCalculateFields() override
Definition: VxlanLayer.h:146
std::string toString() const override
vxlan_header * getVxlanHeader() const
Definition: VxlanLayer.h:103
void parseNextLayer() override
OsiModelLayer getOsiModelLayer() const override
Definition: VxlanLayer.h:151
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:123
size_t getHeaderLen() const override
Definition: VxlanLayer.h:138
void setVNI(uint32_t vni)
VxlanLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: VxlanLayer.h:80
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:364
@ OsiModelDataLinkLayer
Definition: ProtocolType.h:368
const ProtocolType VXLAN
Definition: ProtocolType.h:183
Definition: VxlanLayer.h:16
uint16_t policyAppliedFlag
Definition: VxlanLayer.h:29
uint16_t gbpFlag
Definition: VxlanLayer.h:25
uint16_t reserved11_12
Definition: VxlanLayer.h:31
uint32_t vni
Definition: VxlanLayer.h:61
uint16_t reserved14_16
Definition: VxlanLayer.h:27
uint16_t vniPresentFlag
Definition: VxlanLayer.h:21
uint16_t reserved9
Definition: VxlanLayer.h:35
uint16_t dontLearnFlag
Definition: VxlanLayer.h:33
uint16_t groupPolicyID
Definition: VxlanLayer.h:58
uint32_t pad
Definition: VxlanLayer.h:63
uint16_t reserved6_8
Definition: VxlanLayer.h:19
uint16_t reserved2_4
Definition: VxlanLayer.h:23