PcapPlusPlus  24.09
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 (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  virtual ~MplsLayer()
57  {}
58 
62  uint8_t getTTL() const
63  {
64  return getMplsHeader()->ttl;
65  }
66 
71  void setTTL(uint8_t ttl)
72  {
73  getMplsHeader()->ttl = ttl;
74  }
75 
80  bool isBottomOfStack() const;
81 
86  void setBottomOfStack(bool val);
87 
91  uint8_t getExperimentalUseValue() const;
92 
98  bool setExperimentalUseValue(uint8_t val);
99 
103  uint32_t getMplsLabel() const;
104 
110  bool setMplsLabel(uint32_t label);
111 
112  // implement abstract methods
113 
118 
122  size_t getHeaderLen() const
123  {
124  return sizeof(mpls_header);
125  }
126 
132 
133  std::string toString() const;
134 
136  {
137  return OsiModelNetworkLayer;
138  }
139  };
140 
141 } // namespace pcpp
Definition: Layer.h:70
Definition: MplsLayer.h:19
uint8_t getTTL() const
Definition: MplsLayer.h:62
bool setMplsLabel(uint32_t label)
size_t getHeaderLen() const
Definition: MplsLayer.h:122
uint8_t getExperimentalUseValue() const
OsiModelLayer getOsiModelLayer() const
Definition: MplsLayer.h:135
bool setExperimentalUseValue(uint8_t val)
MplsLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: MplsLayer.h:42
void setTTL(uint8_t ttl)
Definition: MplsLayer.h:71
bool isBottomOfStack() const
void parseNextLayer()
uint32_t getMplsLabel() const
void computeCalculateFields()
void setBottomOfStack(bool val)
MplsLayer(uint32_t mplsLabel, uint8_t ttl, uint8_t experimentalUseValue, bool bottomOfStack)
std::string toString() const
Definition: Packet.h:27
The main namespace for the PcapPlusPlus lib.
const ProtocolType MPLS
Definition: ProtocolType.h:113
OsiModelLayer
Definition: ProtocolType.h:354
@ OsiModelNetworkLayer
Definition: ProtocolType.h:360