PcapPlusPlus  Next
MplsLayer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Layer.h"
4 
6 
11 namespace pcpp
12 {
13 
18  class MplsLayer : public Layer
19  {
20  private:
21 #pragma pack(push, 1)
22  struct mpls_header
23  {
24  uint16_t hiLabel;
25  uint8_t misc;
26  uint8_t ttl;
27  };
28 #pragma pack(pop)
29 
30  mpls_header* getMplsHeader() const
31  {
32  return reinterpret_cast<mpls_header*>(m_Data);
33  }
34 
35  public:
42  MplsLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
43  : Layer(data, dataLen, prevLayer, packet, MPLS)
44  {}
45 
54  MplsLayer(uint32_t mplsLabel, uint8_t ttl, uint8_t experimentalUseValue, bool bottomOfStack);
55 
56  ~MplsLayer() override = default;
57 
61  uint8_t getTTL() const
62  {
63  return getMplsHeader()->ttl;
64  }
65 
70  void setTTL(uint8_t ttl)
71  {
72  getMplsHeader()->ttl = ttl;
73  }
74 
79  bool isBottomOfStack() const;
80 
85  void setBottomOfStack(bool val);
86 
90  uint8_t getExperimentalUseValue() const;
91 
97  bool setExperimentalUseValue(uint8_t val);
98 
102  uint32_t getMplsLabel() const;
103 
109  bool setMplsLabel(uint32_t label);
110 
111  // implement abstract methods
112 
116  void parseNextLayer() override;
117 
121  size_t getHeaderLen() const override
122  {
123  return sizeof(mpls_header);
124  }
125 
130  void computeCalculateFields() override;
131 
132  std::string toString() const override;
133 
135  {
136  return OsiModelNetworkLayer;
137  }
138  };
139 
140 } // namespace pcpp
Definition: Layer.h:69
Definition: MplsLayer.h:19
uint8_t getTTL() const
Definition: MplsLayer.h:61
bool setMplsLabel(uint32_t label)
void parseNextLayer() override
uint8_t getExperimentalUseValue() const
bool setExperimentalUseValue(uint8_t val)
void computeCalculateFields() override
MplsLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: MplsLayer.h:42
void setTTL(uint8_t ttl)
Definition: MplsLayer.h:70
OsiModelLayer getOsiModelLayer() const override
Definition: MplsLayer.h:134
size_t getHeaderLen() const override
Definition: MplsLayer.h:121
bool isBottomOfStack() const
uint32_t getMplsLabel() const
void setBottomOfStack(bool val)
MplsLayer(uint32_t mplsLabel, uint8_t ttl, uint8_t experimentalUseValue, bool bottomOfStack)
std::string toString() const override
Definition: Packet.h:27
The main namespace for the PcapPlusPlus lib.
const ProtocolType MPLS
Definition: ProtocolType.h:113
OsiModelLayer
Definition: ProtocolType.h:364
@ OsiModelNetworkLayer
Definition: ProtocolType.h:370