Coverage Report

Created: 2026-07-16 07:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/PcapPlusPlus/Packet++/header/StpLayer.h
Line
Count
Source
1
#pragma once
2
3
#include "Layer.h"
4
#include "MacAddress.h"
5
#include <cstring>
6
7
/// @file
8
9
/// @namespace pcpp
10
/// @brief The main namespace for the PcapPlusPlus lib
11
namespace pcpp
12
{
13
  /// @struct stp_tcn_bpdu
14
  /// Represents payload of network changes announcements of BPDU
15
#pragma pack(push, 1)
16
  struct stp_tcn_bpdu
17
  {
18
    /// Protocol ID. Fixed at 0x0, which represents IEEE 802.1d
19
    uint16_t protoId;
20
    /// Protocol version. 0x0 for STP, 0x2 for RSTP, 0x3 for MSTP
21
    uint8_t version;
22
    /// Type of the BPDU. 0x0 for configuration, 0x2 for RSTP/MSTP, 0x80 for TCN
23
    uint8_t type;
24
  };
25
#pragma pack(pop)
26
  static_assert(sizeof(stp_tcn_bpdu) == 4, "stp_tcn_bpdu size is not 4 bytes");
27
28
  /// Spanning Tree protocol common header
29
  typedef stp_tcn_bpdu stp_header;
30
  static_assert(sizeof(stp_header) == 4, "stp_header size is not 4 bytes");
31
32
  /// @struct stp_conf_bpdu
33
  /// Represents payload configuration of BPDU for STP
34
#pragma pack(push, 1)
35
  struct stp_conf_bpdu : stp_tcn_bpdu
36
  {
37
    /// Flag for indicate purpose of BPDU
38
    uint8_t flag;
39
    /// Root bridge ID
40
    uint64_t rootId;
41
    /// Cost of path
42
    uint32_t pathCost;
43
    /// Bridge ID
44
    uint64_t bridgeId;
45
    /// Port ID
46
    uint16_t portId;
47
    /// Age of the BPDU
48
    uint16_t msgAge;
49
    /// Maximum age of the BPDU
50
    uint16_t maxAge;
51
    /// BPDU transmission interval
52
    uint16_t helloTime;
53
    /// Delay for STP
54
    uint16_t forwardDelay;
55
  };
56
#pragma pack(pop)
57
  static_assert(sizeof(stp_conf_bpdu) == 35, "stp_conf_bpdu size is not 35 bytes");
58
59
  /// @struct rstp_conf_bpdu
60
  /// Represents payload configuration of BPDU for Rapid STP (RSTP)
61
#pragma pack(push, 1)
62
  struct rstp_conf_bpdu : stp_conf_bpdu
63
  {
64
    /// Version1 length. The value is 0x0
65
    uint8_t version1Len;
66
  };
67
#pragma pack(pop)
68
  static_assert(sizeof(rstp_conf_bpdu) == 36, "rstp_conf_bpdu size is not 36 bytes");
69
70
  /// @struct mstp_conf_bpdu
71
  /// Represents payload configuration of BPDU for Multiple STP (MSTP)
72
#pragma pack(push, 1)
73
  struct mstp_conf_bpdu : rstp_conf_bpdu
74
  {
75
    /// Version3 length.
76
    uint16_t version3Len;
77
    /// Configuration id format selector
78
    uint8_t mstConfigFormatSelector;
79
    /// Configuration id name
80
    uint8_t mstConfigName[32];
81
    /// Configuration id revision
82
    uint16_t mstConfigRevision;
83
    /// Configuration id digest
84
    uint8_t mstConfigDigest[16];
85
    /// CIST internal root path cost
86
    uint32_t irpc;
87
    /// CIST bridge id
88
    uint64_t cistBridgeId;
89
    /// CIST remaining hop count
90
    uint8_t remainId;
91
  };
92
#pragma pack(pop)
93
  static_assert(sizeof(mstp_conf_bpdu) == 102, "mstp_conf_bpdu size is not 102 bytes");
94
95
  /// @struct msti_conf_msg
96
  /// Represents MSTI configuration messages. Each message contains 16 bytes and MSTP can contain 0 to 64 MSTI
97
  /// messages.
98
#pragma pack(push, 1)
99
  struct msti_conf_msg
100
  {
101
    /// MSTI flags
102
    uint8_t flags;
103
    /// Regional root switching id (Priority (4 bits) + ID (12 bits) + Regional root (48 bits - MAC address))
104
    uint64_t regionalRootId;
105
    /// Total path cost from local port to regional port
106
    uint32_t pathCost;
107
    /// Priority value of switching device
108
    uint8_t bridgePriority;
109
    /// Priority value of port
110
    uint8_t portPriority;
111
    /// Remaining hops of BPDU
112
    uint8_t remainingHops;
113
  };
114
#pragma pack(pop)
115
  static_assert(sizeof(msti_conf_msg) == 16, "msti_conf_msg size is not 16 bytes");
116
117
  /// @class StpLayer
118
  /// Represents an Spanning Tree Protocol Layer
119
  class StpLayer : public Layer
120
  {
121
  protected:
122
    StpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
123
5.31k
        : Layer(data, dataLen, prevLayer, packet, STP)
124
5.31k
    {}
125
126
    explicit StpLayer(size_t dataLen)
127
0
    {
128
0
      allocData(dataLen);
129
0
      m_Protocol = STP;
130
0
    }
131
132
    static pcpp::MacAddress IDtoMacAddress(uint64_t id);
133
    static uint64_t macAddressToID(const pcpp::MacAddress& addr);
134
135
  public:
136
    /// STP protocol uses "01:80:C2:00:00:00" multicast address as destination MAC
137
    static pcpp::MacAddress StpMulticastDstMAC;
138
    /// STP Uplink Fast protocol uses "01:00:0C:CD:CD:CD" as destination MAC
139
    static pcpp::MacAddress StpUplinkFastMulticastDstMAC;
140
141
    /// Get a pointer to base Spanning tree header
142
    /// @return A pointer to spanning tree header
143
    stp_header* getStpHeader() const
144
0
    {
145
0
      return reinterpret_cast<stp_header*>(m_Data);
146
0
    }
147
148
    /// Returns the protocol id. Fixed at 0x0 for STP messages which represents IEEE 802.1d
149
    /// @return ID of the protocol
150
    uint16_t getProtoId() const
151
0
    {
152
0
      return getStpHeader()->protoId;
153
0
    }
154
155
    /// Sets the protocol id
156
    /// @param[in] value ID of the protocol
157
158
    void setProtoId(uint16_t value)
159
0
    {
160
0
      getStpHeader()->protoId = value;
161
0
    }
162
163
    /// Returns the version. Fixed at 0x0 for STP messages
164
    /// @return Version number
165
    uint8_t getVersion() const
166
0
    {
167
0
      return getStpHeader()->version;
168
0
    }
169
170
    /// Sets the version
171
    /// @param[in] value Version number
172
    void setVersion(uint8_t value)
173
0
    {
174
0
      getStpHeader()->version = value;
175
0
    }
176
177
    /// Returns the type of configuration message.
178
    /// @return Type of configuration message
179
    uint8_t getType() const
180
0
    {
181
0
      return getStpHeader()->type;
182
0
    }
183
184
    /// Sets the type of configuration message
185
    /// @param[in] value Type of configuration message
186
    void setType(uint8_t value)
187
0
    {
188
0
      getStpHeader()->type = value;
189
0
    }
190
191
    // overridden methods
192
193
    /// @return The size of STP packet
194
    size_t getHeaderLen() const override
195
0
    {
196
0
      return m_DataLen;
197
0
    }
198
199
    /// Does nothing for this layer
200
    void computeCalculateFields() override
201
891
    {}
202
203
    /// @return The OSI layer level of STP (Data Link Layer).
204
    OsiModelLayer getOsiModelLayer() const override
205
891
    {
206
891
      return OsiModelDataLinkLayer;
207
891
    }
208
209
    /// A static method that validates the input data
210
    /// @param[in] data The pointer to the beginning of a byte stream of an Spanning Tree packet
211
    /// @param[in] dataLen The length of the byte stream
212
    /// @return True if the data is valid and can represent an Spanning Tree packet
213
    static bool isDataValid(const uint8_t* data, size_t dataLen);
214
215
    /// A method to create STP layer from existing packet
216
    /// @param[in] data A pointer to the raw data
217
    /// @param[in] dataLen Size of the data in bytes
218
    /// @param[in] prevLayer A pointer to the previous layer
219
    /// @param[in] packet A pointer to the Packet instance where layer will be stored
220
    /// @return A newly allocated STP layer of one of the following types (according to the message type):
221
    /// StpConfigurationBPDULayer, StpTopologyChangeBPDULayer, RapidStpLayer, MultipleStpLayer
222
    static StpLayer* parseStpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet);
223
  };
224
225
  /// @class StpTopologyChangeBPDULayer
226
  /// Represents network topology change BPDU message of Spanning Tree Protocol
227
  class StpTopologyChangeBPDULayer : public StpLayer
228
  {
229
  protected:
230
0
    explicit StpTopologyChangeBPDULayer(size_t dataLen) : StpLayer(dataLen)
231
0
    {}
232
233
  public:
234
    /// A constructor that creates the layer from an existing packet raw data
235
    /// @param[in] data A pointer to the raw data
236
    /// @param[in] dataLen Size of the data in bytes
237
    /// @param[in] prevLayer A pointer to the previous layer
238
    /// @param[in] packet A pointer to the Packet instance where layer will be stored in
239
    StpTopologyChangeBPDULayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
240
5.31k
        : StpLayer(data, dataLen, prevLayer, packet)
241
5.31k
    {}
242
243
    /// Empty c'tor to create a new network topology change (TCN) BPDU layer.
244
    /// Initializes the protocol identifier, version and STP type fields with correct values
245
    StpTopologyChangeBPDULayer();
246
247
    /// Get a pointer to network topology change (TCN) BPDU message
248
    /// @return A pointer to TCN BPDU message
249
    stp_tcn_bpdu* getStpTcnHeader()
250
0
    {
251
0
      return getStpHeader();
252
0
    }
253
254
    // overridden methods
255
256
    /// @return The size of STP TCN message
257
    size_t getHeaderLen() const override
258
329
    {
259
329
      return sizeof(stp_tcn_bpdu);
260
329
    }
261
262
    /// Parses next layer
263
    void parseNextLayer() override;
264
265
    /// @return Returns the protocol info as readable string
266
    std::string toString() const override
267
658
    {
268
658
      return "Spanning Tree Topology Change Notification";
269
658
    }
270
271
    /// A static method that validates the input data
272
    /// @param[in] data The pointer to the beginning of a byte stream of an Spanning Tree Topology Change BPDU
273
    /// packet
274
    /// @param[in] dataLen The length of the byte stream
275
    /// @return True if the data is valid and can represent an Spanning Tree packet
276
    static bool isDataValid(const uint8_t* data, size_t dataLen)
277
1.97k
    {
278
1.97k
      return canReinterpretAs<stp_tcn_bpdu>(data, dataLen);
279
1.97k
    }
280
  };
281
282
  /// @class StpConfigurationBPDULayer
283
  /// Represents configuration BPDU message of Spanning Tree Protocol
284
  class StpConfigurationBPDULayer : public StpTopologyChangeBPDULayer
285
  {
286
  protected:
287
0
    explicit StpConfigurationBPDULayer(size_t dataLen) : StpTopologyChangeBPDULayer(dataLen)
288
0
    {}
289
290
  public:
291
    /// A constructor that creates the layer from an existing packet raw data
292
    /// @param[in] data A pointer to the raw data
293
    /// @param[in] dataLen Size of the data in bytes
294
    /// @param[in] prevLayer A pointer to the previous layer
295
    /// @param[in] packet A pointer to the Packet instance where layer will be stored in
296
    StpConfigurationBPDULayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
297
3.34k
        : StpTopologyChangeBPDULayer(data, dataLen, prevLayer, packet)
298
3.34k
    {}
299
300
    /// Empty c'tor to create a new configuration BPDU layer.
301
    /// Initializes the protocol identifier, version and STP type fields with correct values
302
    StpConfigurationBPDULayer();
303
304
    /// Get a pointer to configuration BPDU message
305
    /// @return A pointer to configuration BPDU message
306
    stp_conf_bpdu* getStpConfHeader() const
307
0
    {
308
0
      return reinterpret_cast<stp_conf_bpdu*>(m_Data);
309
0
    }
310
311
    /// Returns the flags of configuration message which indicates purpose of BPDU
312
    /// @return Flags of the configuration message
313
    uint8_t getFlag() const
314
0
    {
315
0
      return getStpConfHeader()->flag;
316
0
    }
317
318
    /// Returns the flags of configuration message which indicates purpose of BPDU
319
    /// @param[in] value Flags of the configuration message
320
    void setFlag(uint8_t value)
321
0
    {
322
0
      getStpConfHeader()->flag = value;
323
0
    }
324
325
    /// Returns the root bridge identifier
326
    /// @return Root bridge identifier
327
    uint64_t getRootId() const;
328
329
    /// Sets the root bridge identifier
330
    /// @param[in] value Root bridge identifier
331
    void setRootId(uint64_t value);
332
333
    /// Returns the priority of root bridge
334
    /// @return Priority of root bridge
335
    uint16_t getRootPriority() const;
336
337
    /// Sets the priority of root bridge
338
    /// @param[in] value Priority of root bridge
339
    void setRootPriority(uint16_t value);
340
341
    /// Returns the system identifier extension of root bridge
342
    /// @return System extension of root bridge
343
    uint16_t getRootSystemIDExtension() const;
344
345
    /// Sets the system identifier extension of root bridge
346
    /// @param[in] value System extension of root bridge
347
    void setRootSystemIDExtension(uint16_t value);
348
349
    /// Returns the system identifier of root bridge
350
    /// @return System identifier of root bridge
351
    pcpp::MacAddress getRootSystemID() const
352
0
    {
353
0
      return IDtoMacAddress(getRootId());
354
0
    }
355
356
    /// Sets the system identifier of root bridge
357
    /// @param[in] value System identifier of root bridge
358
    void setRootSystemID(const pcpp::MacAddress& value);
359
360
    /// Returns the value of the cost of path
361
    /// @return Cost of path
362
    uint32_t getPathCost() const;
363
364
    /// Sets the value of the cost of path
365
    /// @param[in] value Cost of path
366
    void setPathCost(uint32_t value);
367
368
    /// Returns the bridge identifier
369
    /// @return Bridge identifier
370
    uint64_t getBridgeId() const;
371
372
    /// Sets the bridge identifier
373
    /// @param[in] value Bridge identifier
374
    void setBridgeId(uint64_t value);
375
376
    /// Returns the priority of bridge
377
    /// @return Priority of bridge
378
    uint16_t getBridgePriority() const;
379
380
    /// Sets the priority of bridge
381
    /// @param[in] value Priority of bridge
382
    void setBridgePriority(uint16_t value);
383
384
    /// Returns the system identifier extension of bridge
385
    /// @return System extension of bridge
386
    uint16_t getBridgeSystemIDExtension() const;
387
388
    /// Sets the system identifier extension of bridge
389
    /// @param[in] value System extension of bridge
390
    void setBridgeSystemIDExtension(uint16_t value);
391
392
    /// Returns the system identifier of bridge
393
    /// @return System identifier of bridge
394
    pcpp::MacAddress getBridgeSystemID() const
395
0
    {
396
0
      return IDtoMacAddress(getBridgeId());
397
0
    }
398
399
    /// Sets the system identifier of bridge
400
    /// @param[in] value System identifier of bridge
401
    void setBridgeSystemID(const pcpp::MacAddress& value);
402
403
    /// Returns the port identifier
404
    /// @return Port identifier
405
    uint16_t getPortId() const;
406
407
    /// Sets the port identifier
408
    /// @param[in] value Port identifier
409
    void setPortId(uint16_t value);
410
411
    /// Returns age of the BPDU message
412
    /// @return Age of BPDU in seconds
413
    double getMessageAge() const;
414
415
    /// Sets age of the BPDU message
416
    /// @param[in] value Age of BPDU in seconds
417
    void setMessageAge(double value);
418
419
    /// Returns maximum age of the BPDU message
420
    /// @return Maximum age of BPDU in seconds
421
    double getMaximumAge() const;
422
423
    /// Sets maximum age of the BPDU message
424
    /// @param[in] value Maximum age of BPDU in seconds
425
    void setMaximumAge(double value);
426
427
    /// Returns the BPDU transmission interval
428
    /// @return Value of the transmission interval in seconds
429
    double getTransmissionInterval() const;
430
431
    /// Sets the BPDU transmission interval
432
    /// @param[in] value Value of the transmission interval in seconds
433
    void setTransmissionInterval(double value);
434
435
    /// Returns the delay for STP message
436
    /// @return Value of the forward delay in seconds
437
    double getForwardDelay() const;
438
439
    /// Sets the delay for STP message
440
    /// @param[in] value Value of the forward delay in seconds
441
    void setForwardDelay(double value);
442
443
    // overridden methods
444
445
    /// @return The size of STP configuration BPDU message
446
    size_t getHeaderLen() const override
447
361
    {
448
361
      return sizeof(stp_conf_bpdu);
449
361
    }
450
451
    /// Parses next layer
452
    void parseNextLayer() override;
453
454
    /// @return Returns the protocol info as readable string
455
    std::string toString() const override
456
722
    {
457
722
      return "Spanning Tree Configuration";
458
722
    }
459
460
    /// A static method that validates the input data
461
    /// @param[in] data The pointer to the beginning of a byte stream of an Spanning Tree Configuration BPDU packet
462
    /// @param[in] dataLen The length of the byte stream
463
    /// @return True if the data is valid and can represent an Spanning Tree packet
464
    static bool isDataValid(const uint8_t* data, size_t dataLen)
465
2.16k
    {
466
2.16k
      return canReinterpretAs<stp_conf_bpdu>(data, dataLen);
467
2.16k
    }
468
  };
469
470
  /// @class RapidStpLayer
471
  /// Represents Rapid Spanning Tree Protocol (RSTP)
472
  class RapidStpLayer : public StpConfigurationBPDULayer
473
  {
474
  protected:
475
0
    explicit RapidStpLayer(size_t dataLen) : StpConfigurationBPDULayer(dataLen)
476
0
    {}
477
478
  public:
479
    /// A constructor that creates the layer from an existing packet raw data
480
    /// @param[in] data A pointer to the raw data
481
    /// @param[in] dataLen Size of the data in bytes
482
    /// @param[in] prevLayer A pointer to the previous layer
483
    /// @param[in] packet A pointer to the Packet instance where layer will be stored in
484
    RapidStpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
485
1.17k
        : StpConfigurationBPDULayer(data, dataLen, prevLayer, packet)
486
1.17k
    {}
487
488
    /// Empty c'tor to create a new Rapid STP layer.
489
    /// Initializes the protocol identifier, version and STP type fields with correct values
490
    RapidStpLayer();
491
492
    /// Get a pointer to Rapid STP header
493
    /// @return A pointer to Rapid STP header
494
    rstp_conf_bpdu* getRstpConfHeader() const
495
0
    {
496
0
      return reinterpret_cast<rstp_conf_bpdu*>(m_Data);
497
0
    }
498
499
    /// Returns the length of version1 field. Fixed at 0x0 for Rapid STP
500
    /// @return Length of the version1 field
501
    uint8_t getVersion1Len() const
502
0
    {
503
0
      return getRstpConfHeader()->version1Len;
504
0
    }
505
506
    /// Returns the length of version1 field
507
    /// @param[in] value Length of the version1 field
508
    void setVersion1Len(uint8_t value)
509
0
    {
510
0
      getRstpConfHeader()->version1Len = value;
511
0
    }
512
513
    // overridden methods
514
515
    /// @return The size of Rapid STP message
516
    size_t getHeaderLen() const override
517
201
    {
518
201
      return sizeof(rstp_conf_bpdu);
519
201
    }
520
521
    /// Parses next layer
522
    void parseNextLayer() override;
523
524
    /// @return Returns the protocol info as readable string
525
    std::string toString() const override
526
370
    {
527
370
      return "Rapid Spanning Tree";
528
370
    }
529
530
    /// A static method that validates the input data
531
    /// @param[in] data The pointer to the beginning of a byte stream of an Rapid STP packet
532
    /// @param[in] dataLen The length of the byte stream
533
    /// @return True if the data is valid and can represent an Spanning Tree packet
534
    static bool isDataValid(const uint8_t* data, size_t dataLen)
535
1.11k
    {
536
1.11k
      return canReinterpretAs<rstp_conf_bpdu>(data, dataLen);
537
1.11k
    }
538
  };
539
540
  /// @class MultipleStpLayer
541
  /// Represents Multiple Spanning Tree Protocol (MSTP). It has limited capabilities (no crafting / limited editing)
542
  /// over MSTI configuration
543
  class MultipleStpLayer : public RapidStpLayer
544
  {
545
  public:
546
    /// A constructor that creates the layer from an existing packet raw data
547
    /// @param[in] data A pointer to the raw data
548
    /// @param[in] dataLen Size of the data in bytes
549
    /// @param[in] prevLayer A pointer to the previous layer
550
    /// @param[in] packet A pointer to the Packet instance where layer will be stored in
551
    MultipleStpLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
552
64
        : RapidStpLayer(data, dataLen, prevLayer, packet)
553
64
    {}
554
555
    /// Empty c'tor to create a new Multiple STP layer.
556
    /// Initializes the protocol identifier, version and STP type fields with correct values
557
    MultipleStpLayer();
558
559
    /// Get a pointer to Multiple STP header
560
    /// @return A pointer to Multiple STP header
561
    mstp_conf_bpdu* getMstpHeader() const
562
0
    {
563
0
      return reinterpret_cast<mstp_conf_bpdu*>(m_Data);
564
0
    }
565
566
    /// @return Length of version3 field
567
    uint16_t getVersion3Len() const;
568
569
    /// Sets the length of version3 field
570
    /// @param[in] value Length of version3 field
571
    void setVersion3Len(uint16_t value);
572
573
    /// Returns the configuration ID format selector
574
    /// @return Configuration ID of format selector
575
    uint8_t getMstConfigurationFormatSelector() const
576
0
    {
577
0
      return getMstpHeader()->mstConfigFormatSelector;
578
0
    }
579
580
    /// Sets the configuration ID format selector
581
    /// @param[in] value Configuration ID of format selector
582
    void setMstConfigurationFormatSelector(uint8_t value)
583
0
    {
584
0
      getMstpHeader()->mstConfigFormatSelector = value;
585
0
    }
586
587
    /// Returns the pointer to configuration name field
588
    /// @return Configuration name
589
    std::string getMstConfigurationName() const;
590
591
    /// Sets the configuration name field
592
    /// @param[in] value Configuration name. Length should be less than 32, if longer value provided first 32
593
    /// characters are used
594
    void setMstConfigurationName(const std::string& value);
595
596
    /// Returns the revision of configuration ID
597
    /// @return Revision of configuration ID
598
    uint16_t getMstConfigRevision() const;
599
600
    /// Sets the revision of configuration ID
601
    /// @param[in] value Revision of configuration ID
602
    void setMstConfigRevision(uint16_t value);
603
604
    /// Returns the pointer to configuration message digest. The field itself always 16 bytes long.
605
    /// @return A pointer to configuration digest
606
    uint8_t* getMstConfigDigest() const
607
0
    {
608
0
      return getMstpHeader()->mstConfigDigest;
609
0
    }
610
611
    /// Sets the pointer to configuration message digest. The field itself always 16 bytes long.
612
    /// @param[in] value Pointer to digest
613
    /// @param[in] len Length of the digest, should be less than 16. If longer first 16 bytes are used
614
    void setMstConfigDigest(const uint8_t* value, uint8_t len);
615
616
    /// Returns CIST internal root path cost
617
    /// @return Value of the internal root path cost
618
    uint32_t getCISTIrpc() const;
619
620
    /// Sets CIST internal root path cost
621
    /// @param[in] value Value of the internal root path cost
622
    void setCISTIrpc(uint32_t value);
623
624
    /// Returns CIST bridge identifier
625
    /// @return Value of the bridge identifier
626
    uint64_t getCISTBridgeId() const;
627
628
    /// Sets CIST bridge identifier
629
    /// @param[in] value Value of the bridge identifier
630
    void setCISTBridgeId(uint64_t value);
631
632
    /// Returns the priority of CIST bridge
633
    /// @return Priority of CIST bridge
634
    uint16_t getCISTBridgePriority() const;
635
636
    /// Sets the priority of CIST bridge
637
    /// @param[in] value Priority of CIST bridge
638
    void setCISTBridgePriority(uint16_t value);
639
640
    /// Returns the system identifier extension of CIST bridge
641
    /// @return System extension of CIST bridge
642
    uint16_t getCISTBridgeSystemIDExtension() const;
643
644
    /// Sets the system identifier extension of CIST bridge
645
    /// @param[in] value System extension of CIST bridge
646
    void setCISTBridgeSystemIDExtension(uint16_t value);
647
648
    /// Returns the system identifier of CIST bridge
649
    /// @return System identifier of CIST bridge
650
    pcpp::MacAddress getCISTBridgeSystemID() const
651
0
    {
652
0
      return IDtoMacAddress(getCISTBridgeId());
653
0
    }
654
655
    /// Sets the system identifier of CIST bridge
656
    /// @param[in] value System identifier of CIST bridge
657
    void setCISTBridgeSystemID(const pcpp::MacAddress& value);
658
659
    /// Returns the remaining hop count
660
    /// @return Value of remaining hop count
661
    uint8_t getRemainingHopCount() const
662
0
    {
663
0
      return getMstpHeader()->remainId;
664
0
    }
665
666
    /// Returns the remaining hop count
667
    /// @param[in] value Value of remaining hop count
668
    void setRemainingHopCount(uint8_t value)
669
0
    {
670
0
      getMstpHeader()->remainId = value;
671
0
    }
672
673
    /// Returns the total number of MSTI configuration messages
674
    /// @return Number of MSTI configuration messages. Can be between 0 and 64.
675
    uint8_t getNumberOfMSTIConfMessages() const
676
0
    {
677
0
      return (getVersion3Len() - (sizeof(mstp_conf_bpdu) - sizeof(rstp_conf_bpdu) - sizeof(uint16_t))) /
678
0
             sizeof(msti_conf_msg);
679
0
    }
680
681
    /// Returns a reference to MSTI configuration messages. An MSTP packet can contain between 0 to 64 MSTI
682
    /// messages. The number of messages can be obtained by using getNumberOfMSTIConfMessages()
683
    /// @return An array pointer to MSTI configuration messages. Returns nullptr if there is no MSTI message.
684
    msti_conf_msg* getMstiConfMessages() const;
685
686
    // overridden methods
687
688
    /// Parses next layer
689
    void parseNextLayer() override
690
64
    {}
691
692
    /// @return Returns the protocol info as readable string
693
    std::string toString() const override
694
32
    {
695
32
      return "Multiple Spanning Tree";
696
32
    }
697
698
    /// A static method that validates the input data
699
    /// @param[in] data The pointer to the beginning of a byte stream of an Multiple STP packet
700
    /// @param[in] dataLen The length of the byte stream
701
    /// @return True if the data is valid and can represent an Spanning Tree packet
702
    static bool isDataValid(const uint8_t* data, size_t dataLen)
703
68
    {
704
68
      return canReinterpretAs<mstp_conf_bpdu>(data, dataLen);
705
68
    }
706
  };
707
}  // namespace pcpp