PcapPlusPlus  22.11
StpLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_STP_LAYER
2 #define PACKETPP_STP_LAYER
3 
4 #include "Layer.h"
5 #include "MacAddress.h"
6 
8 
13 namespace pcpp
14 {
15 
20 #pragma pack(push, 1)
21  struct stp_tcn_bpdu
22  {
24  uint16_t protoId;
26  uint8_t version;
28  uint8_t type;
29  };
30 #pragma pack(pop)
31 
34 
39 #pragma pack(push, 1)
41  {
43  uint8_t flag;
45  uint64_t rootId;
47  uint32_t pathCost;
49  uint64_t bridgeId;
51  uint16_t portId;
53  uint16_t msgAge;
55  uint16_t maxAge;
57  uint16_t helloTime;
59  uint16_t forwardDelay;
60  };
61 #pragma pack(pop)
62 
67 #pragma pack(push, 1)
69  {
71  uint8_t version1Len;
72  };
73 #pragma pack(pop)
74 
79 #pragma pack(push, 1)
81  {
83  uint16_t version3Len;
87  uint8_t mstConfigName[32];
91  uint8_t mstConfigDigest[16];
93  uint32_t irpc;
95  uint64_t cistBridgeId;
97  uint8_t remainId;
98  };
99 #pragma pack(pop)
100 
105 #pragma pack(push, 1)
107  {
109  uint8_t flags;
111  uint64_t regionalRootId;
113  uint32_t pathCost;
115  uint8_t bridgePriority;
117  uint8_t portPriority;
119  uint8_t remainingHops;
120  };
121 #pragma pack(pop)
122 
127  class StpLayer : public Layer
128  {
129  protected:
130  StpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
131  : Layer(data, dataLen, prevLayer, packet)
132  {
133  m_Protocol = STP;
134  }
135 
136  static pcpp::MacAddress IDtoMacAddress(uint64_t id);
137 
138  public:
143 
148  stp_header *getStpHeader() const { return (stp_header *)(m_Data); }
149 
154  uint16_t getProtoId() const { return getStpHeader()->protoId; }
155 
160  uint8_t getVersion() const { return getStpHeader()->version; }
161 
166  uint8_t getType() const { return getStpHeader()->type; }
167 
168  // overridden methods
169 
173  size_t getHeaderLen() const { return m_DataLen; }
174 
176  void parseNextLayer() {}
177 
180 
185 
192  static bool isDataValid(const uint8_t *data, size_t dataLen);
193 
203  static StpLayer *parseStpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet);
204  };
205 
211  {
212  public:
220  StpTopologyChangeBPDULayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
221  : StpLayer(data, dataLen, prevLayer, packet)
222  {
223  }
224 
229  stp_tcn_bpdu* getStpTcnHeader() { return getStpHeader(); }
230 
231  // overridden methods
232 
236  std::string toString() const { return "Spanning Tree Topology Change Notification"; }
237 
244  static bool isDataValid(const uint8_t *data, size_t dataLen) { return data && dataLen >= sizeof(stp_tcn_bpdu); }
245  };
246 
252  {
253  public:
261  StpConfigurationBPDULayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
262  : StpTopologyChangeBPDULayer(data, dataLen, prevLayer, packet)
263  {
264  }
265 
270  stp_conf_bpdu *getStpConfHeader() const { return (stp_conf_bpdu *)(m_Data); }
271 
276  uint8_t getFlag() const { return getStpConfHeader()->flag; }
277 
282  uint64_t getRootId() const;
283 
288  uint16_t getRootPriority() const;
289 
294  uint16_t getRootSystemIDExtension() const;
295 
300  pcpp::MacAddress getRootSystemID() const { return IDtoMacAddress(getRootId()); }
301 
306  uint32_t getPathCost() const;
307 
312  uint64_t getBridgeId() const;
313 
318  uint16_t getBridgePriority() const;
319 
324  uint16_t getBridgeSystemIDExtension() const;
325 
330  pcpp::MacAddress getBridgeSystemID() const { return IDtoMacAddress(getBridgeId()); }
331 
336  uint16_t getPortId() const;
337 
342  double getMessageAge() const;
343 
348  double getMaximumAge() const;
349 
354  double getTransmissionInterval() const;
355 
360  double getForwardDelay() const;
361 
362  // overridden methods
363 
367  std::string toString() const { return "Spanning Tree Configuration"; }
368 
375  static bool isDataValid(const uint8_t *data, size_t dataLen)
376  {
377  return data && dataLen >= sizeof(stp_conf_bpdu);
378  }
379  };
380 
386  {
387  public:
395  RapidStpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
396  : StpConfigurationBPDULayer(data, dataLen, prevLayer, packet)
397  {
398  }
399 
404  rstp_conf_bpdu *getRstpConfHeader() const { return (rstp_conf_bpdu *)(m_Data); }
405 
410  uint8_t getVersion1Len() const { return getRstpConfHeader()->version1Len; }
411 
412  // overridden methods
413 
417  std::string toString() const { return "Rapid Spanning Tree"; }
418 
425  static bool isDataValid(const uint8_t *data, size_t dataLen)
426  {
427  return data && dataLen >= sizeof(rstp_conf_bpdu);
428  }
429  };
430 
436  {
437  public:
445  MultipleStpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
446  : RapidStpLayer(data, dataLen, prevLayer, packet)
447  {
448  }
449 
454  mstp_conf_bpdu *getMstpHeader() const { return (mstp_conf_bpdu *)(m_Data); }
455 
459  uint16_t getVersion3Len() const;
460 
465  uint8_t getMstConfigurationFormatSelector() const { return getMstpHeader()->mstConfigFormatSelector; }
466 
471  std::string getMstConfigurationName() const;
472 
477  uint16_t getMstConfigRevision() const { return getMstpHeader()->mstConfigRevision; }
478 
483  uint8_t *getMstConfigDigest() const { return getMstpHeader()->mstConfigDigest; }
484 
489  uint32_t getCISTIrpc() const;
490 
495  uint64_t getCISTBridgeId() const;
496 
501  uint16_t getCISTBridgePriority() const;
502 
507  uint16_t getCISTBridgeSystemIDExtension() const;
508 
513  pcpp::MacAddress getCISTBridgeSystemID() const { return IDtoMacAddress(getCISTBridgeId()); }
514 
519  uint8_t getRemainingHopCount() const { return getMstpHeader()->remainId; }
520 
525  uint8_t getNumberOfMSTIConfMessages() const { return (getVersion3Len() - (sizeof(mstp_conf_bpdu) - sizeof(rstp_conf_bpdu) - sizeof(uint16_t))) / sizeof(msti_conf_msg); }
526 
533  msti_conf_msg *getMstiConfMessages() const;
534 
535  // overridden methods
536 
540  std::string toString() const { return "Multiple Spanning Tree"; }
541 
548  static bool isDataValid(const uint8_t *data, size_t dataLen)
549  {
550  return data && dataLen >= sizeof(mstp_conf_bpdu);
551  }
552  };
553 } // namespace pcpp
554 
555 #endif /* PACKETPP_STP_LAYER */
Definition: StpLayer.h:80
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:298
Definition: StpLayer.h:435
uint16_t maxAge
Maximum age of the BPDU.
Definition: StpLayer.h:55
OsiModelLayer getOsiModelLayer() const
Definition: StpLayer.h:184
RapidStpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: StpLayer.h:395
uint32_t pathCost
Cost of path.
Definition: StpLayer.h:47
uint8_t getNumberOfMSTIConfMessages() const
Definition: StpLayer.h:525
uint16_t helloTime
BPDU transmission interval.
Definition: StpLayer.h:57
Definition: StpLayer.h:40
static bool isDataValid(const uint8_t *data, size_t dataLen)
Definition: StpLayer.h:425
stp_tcn_bpdu stp_header
Spanning Tree protocol common header.
Definition: StpLayer.h:33
Definition: ProtocolType.h:303
uint8_t remainId
CIST remaining hop count.
Definition: StpLayer.h:97
Definition: Layer.h:70
uint16_t getMstConfigRevision() const
Definition: StpLayer.h:477
uint8_t flags
MSTI flags.
Definition: StpLayer.h:109
static bool isDataValid(const uint8_t *data, size_t dataLen)
Definition: StpLayer.h:548
uint16_t portId
Port ID.
Definition: StpLayer.h:51
Definition: StpLayer.h:251
Definition: Packet.h:26
static bool isDataValid(const uint8_t *data, size_t dataLen)
Definition: StpLayer.h:375
const ProtocolType STP
Definition: ProtocolType.h:278
uint8_t * getMstConfigDigest() const
Definition: StpLayer.h:483
stp_conf_bpdu * getStpConfHeader() const
Definition: StpLayer.h:270
StpTopologyChangeBPDULayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: StpLayer.h:220
Definition: StpLayer.h:127
StpConfigurationBPDULayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: StpLayer.h:261
uint64_t regionalRootId
Regional root switching id (Priority (4 bits) + ID (12 bits) + Regional root (48 bits - MAC address))...
Definition: StpLayer.h:111
uint8_t getType() const
Definition: StpLayer.h:166
Definition: StpLayer.h:68
void parseNextLayer()
Parses the next layer. STP is the always last so does nothing for this layer.
Definition: StpLayer.h:176
std::string toString() const
Definition: StpLayer.h:540
void computeCalculateFields()
Does nothing for this layer.
Definition: StpLayer.h:179
uint8_t getVersion() const
Definition: StpLayer.h:160
uint8_t getVersion1Len() const
Definition: StpLayer.h:410
std::string toString() const
Definition: StpLayer.h:417
uint8_t portPriority
Priority value of port.
Definition: StpLayer.h:117
uint16_t mstConfigRevision
Configuration id revision.
Definition: StpLayer.h:89
Definition: StpLayer.h:21
uint64_t cistBridgeId
CIST bridge id.
Definition: StpLayer.h:95
uint8_t version1Len
Version1 length. The value is 0x0.
Definition: StpLayer.h:71
Definition: StpLayer.h:385
Definition: StpLayer.h:210
uint32_t pathCost
Total path cost from local port to regional port.
Definition: StpLayer.h:113
uint16_t msgAge
Age of the BPDU.
Definition: StpLayer.h:53
uint16_t version3Len
Version3 length.
Definition: StpLayer.h:83
stp_tcn_bpdu * getStpTcnHeader()
Definition: StpLayer.h:229
pcpp::MacAddress getRootSystemID() const
Definition: StpLayer.h:300
uint16_t protoId
Protocol ID. Fixed at 0x0, which represents IEEE 802.1d.
Definition: StpLayer.h:24
std::string toString() const
Definition: StpLayer.h:367
std::string toString() const
Definition: StpLayer.h:236
uint8_t version
Protocol version. 0x0 for STP, 0x2 for RSTP, 0x3 for MSTP.
Definition: StpLayer.h:26
uint8_t type
Type of the BPDU. 0x0 for configuration, 0x2 for RSTP/MSTP, 0x80 for TCN.
Definition: StpLayer.h:28
MultipleStpLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: StpLayer.h:445
pcpp::MacAddress getBridgeSystemID() const
Definition: StpLayer.h:330
uint64_t bridgeId
Bridge ID.
Definition: StpLayer.h:49
uint64_t rootId
Root bridge ID.
Definition: StpLayer.h:45
uint8_t getFlag() const
Definition: StpLayer.h:276
uint16_t getProtoId() const
Definition: StpLayer.h:154
Definition: StpLayer.h:106
static pcpp::MacAddress StpMulticastDstMAC
STP protocol uses "01:80:C2:00:00:00" multicast address as destination MAC.
Definition: StpLayer.h:140
mstp_conf_bpdu * getMstpHeader() const
Definition: StpLayer.h:454
static bool isDataValid(const uint8_t *data, size_t dataLen)
Definition: StpLayer.h:244
uint8_t mstConfigFormatSelector
Configuration id format selector.
Definition: StpLayer.h:85
uint8_t remainingHops
Remaining hops of BPDU.
Definition: StpLayer.h:119
rstp_conf_bpdu * getRstpConfHeader() const
Definition: StpLayer.h:404
uint8_t getRemainingHopCount() const
Definition: StpLayer.h:519
pcpp::MacAddress getCISTBridgeSystemID() const
Definition: StpLayer.h:513
uint32_t irpc
CIST internal root path cost.
Definition: StpLayer.h:93
static pcpp::MacAddress StpUplinkFastMulticastDstMAC
STP Uplink Fast protocol uses "01:00:0C:CD:CD:CD" as destination MAC.
Definition: StpLayer.h:142
uint8_t flag
Flag for indicate purpose of BPDU.
Definition: StpLayer.h:43
uint8_t bridgePriority
Priority value of switching device.
Definition: StpLayer.h:115
Definition: MacAddress.h:28
stp_header * getStpHeader() const
Definition: StpLayer.h:148
size_t getHeaderLen() const
Definition: StpLayer.h:173
uint8_t getMstConfigurationFormatSelector() const
Definition: StpLayer.h:465
uint16_t forwardDelay
Delay for STP.
Definition: StpLayer.h:59