PcapPlusPlus  24.09
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()
97  {}
98 
105  {
106  return (vxlan_header*)m_Data;
107  }
108 
112  uint32_t getVNI() const;
113 
118  void setVNI(uint32_t vni);
119 
124  static bool isVxlanPort(uint16_t port)
125  {
126  return port == 4789;
127  }
128 
129  // implement abstract methods
130 
135 
139  size_t getHeaderLen() const
140  {
141  return sizeof(vxlan_header);
142  }
143 
148  {}
149 
150  std::string toString() const;
151 
153  {
154  return OsiModelDataLinkLayer;
155  }
156  };
157 
158 } // namespace pcpp
Definition: Layer.h:70
Definition: Packet.h:27
Definition: VxlanLayer.h:72
uint32_t getVNI() const
void computeCalculateFields()
Definition: VxlanLayer.h:147
size_t getHeaderLen() const
Definition: VxlanLayer.h:139
vxlan_header * getVxlanHeader() const
Definition: VxlanLayer.h:104
std::string toString() const
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:124
void setVNI(uint32_t vni)
VxlanLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: VxlanLayer.h:80
OsiModelLayer getOsiModelLayer() const
Definition: VxlanLayer.h:152
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:354
@ OsiModelDataLinkLayer
Definition: ProtocolType.h:358
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