INET Framework for OMNeT++/OMNEST
inet::Ieee8021dBpduSerializer Class Reference

Converts between Bpdu and binary (network byte order) Ieee 802.1d BPDU packets. More...

#include <Ieee8021dBpduSerializer.h>

Inheritance diagram for inet::Ieee8021dBpduSerializer:
inet::FieldsChunkSerializer inet::ChunkSerializer

Public Member Functions

 Ieee8021dBpduSerializer ()
 
- Public Member Functions inherited from inet::FieldsChunkSerializer
virtual void serialize (MemoryOutputStream &stream, const Ptr< const Chunk > &chunk, b offset, b length) const override
 Serializes a chunk into a stream by writing the bytes representing the chunk at the end of the stream. More...
 
virtual const Ptr< Chunkdeserialize (MemoryInputStream &stream, const std::type_info &typeInfo) const override
 Deserializes a chunk from a stream by reading the bytes at the current position of the stream. More...
 

Protected Member Functions

virtual void serialize (MemoryOutputStream &stream, const Ptr< const Chunk > &chunk) const override
 Serializes a chunk into a stream by writing all bytes representing the chunk at the end of the stream. More...
 
virtual const Ptr< Chunkdeserialize (MemoryInputStream &stream) const override
 Deserializes a chunk from a stream by reading the bytes at the current position of the stream. More...
 

Additional Inherited Members

- Static Public Attributes inherited from inet::ChunkSerializer
static b totalSerializedLength = b(0)
 
static b totalDeserializedLength = b(0)
 

Detailed Description

Converts between Bpdu and binary (network byte order) Ieee 802.1d BPDU packets.

Constructor & Destructor Documentation

◆ Ieee8021dBpduSerializer()

inet::Ieee8021dBpduSerializer::Ieee8021dBpduSerializer ( )
inline
25 : FieldsChunkSerializer() {}

Member Function Documentation

◆ deserialize()

const Ptr< Chunk > inet::Ieee8021dBpduSerializer::deserialize ( MemoryInputStream stream) const
overrideprotectedvirtual

Deserializes a chunk from a stream by reading the bytes at the current position of the stream.

The current stream position is updated according to the length of the returned chunk.

Implements inet::FieldsChunkSerializer.

55 {
56  auto protocolIdentifier = static_cast<BpduProtocolIdentifier>(stream.readUint16Be());
57  auto protocolVersionIdentifier = static_cast<BpduProtocolVersionIdentifier>(stream.readUint8());
58  BpduType bpduType = static_cast<BpduType>(stream.readUint8());
59 
60  switch (bpduType) {
61  case BPDU_CFG: {
62  auto bpdu = makeShared<BpduCfg>();
63  bpdu->setProtocolIdentifier(protocolIdentifier);
64  bpdu->setProtocolVersionIdentifier(protocolVersionIdentifier);
65  bpdu->setBpduType(bpduType);
66  bpdu->setTcaFlag(stream.readBit());
67  bpdu->setReserved(stream.readNBitsToUint64Be(6));
68  bpdu->setTcFlag(stream.readBit());
69  bpdu->setRootPriority(stream.readUint16Be());
70  bpdu->setRootAddress(stream.readMacAddress());
71  bpdu->setRootPathCost(stream.readUint32Be());
72  bpdu->setBridgePriority(stream.readUint16Be());
73  bpdu->setBridgeAddress(stream.readMacAddress());
74  bpdu->setPortPriority(stream.readByte());
75  bpdu->setPortNum(stream.readByte());
76  bpdu->setMessageAge(SimTime(stream.readUint16Be() / 256.0));
77  bpdu->setMaxAge(SimTime(stream.readUint16Be() / 256.0));
78  bpdu->setHelloTime(SimTime(stream.readUint16Be() / 256.0));
79  bpdu->setForwardDelay(SimTime(stream.readUint16Be() / 256.0));
80  return bpdu;
81  }
82  case BPDU_TCN: {
83  auto bpdu = makeShared<BpduTcn>();
84  bpdu->setProtocolIdentifier(protocolIdentifier);
85  bpdu->setProtocolVersionIdentifier(protocolVersionIdentifier);
86  bpdu->setBpduType(bpduType);
87  return bpdu;
88  }
89  default:
90  throw cRuntimeError("Unknown BPDU TYPE value: %d", static_cast<int>(bpduType));
91  }
92 }

◆ serialize()

void inet::Ieee8021dBpduSerializer::serialize ( MemoryOutputStream stream,
const Ptr< const Chunk > &  chunk 
) const
overrideprotectedvirtual

Serializes a chunk into a stream by writing all bytes representing the chunk at the end of the stream.

Implements inet::FieldsChunkSerializer.

20 {
21  const auto& bpduBase = staticPtrCast<const BpduBase>(chunk);
22  stream.writeUint16Be(bpduBase->getProtocolIdentifier());
23  stream.writeUint8(bpduBase->getProtocolVersionIdentifier());
24  stream.writeUint8(bpduBase->getBpduType());
25  switch (bpduBase->getBpduType()) {
26  case BPDU_CFG: {
27  const auto& bpdu = CHK(dynamicPtrCast<const BpduCfg>(chunk));
28  break;
29  stream.writeBit(bpdu->getTcaFlag());
30  stream.writeNBitsOfUint64Be(bpdu->getReserved(), 6);
31  stream.writeBit(bpdu->getTcFlag());
32  stream.writeUint16Be(bpdu->getRootPriority());
33  stream.writeMacAddress(bpdu->getRootAddress());
34  stream.writeUint32Be(bpdu->getRootPathCost());
35  stream.writeUint16Be(bpdu->getBridgePriority());
36  stream.writeMacAddress(bpdu->getBridgeAddress());
37  stream.writeByte(bpdu->getPortPriority());
38  stream.writeByte(bpdu->getPortNum());
39  stream.writeUint16Be(bpdu->getMessageAge().dbl() * 256);
40  stream.writeUint16Be(bpdu->getMaxAge().dbl() * 256);
41  stream.writeUint16Be(bpdu->getHelloTime().dbl() * 256);
42  stream.writeUint16Be(bpdu->getForwardDelay().dbl() * 256);
43  }
44  case BPDU_TCN: {
45  const auto& bpdu = CHK(dynamicPtrCast<const BpduTcn>(chunk));
46  (void)bpdu; // unused
47  break;
48  }
49  default:
50  throw cRuntimeError("Unknown BPDU TYPE value: %d", static_cast<int>(bpduBase->getBpduType()));
51  }
52 }

The documentation for this class was generated from the following files:
CHK
#define CHK(x)
Definition: INETDefs.h:87
inet::BpduProtocolIdentifier
BpduProtocolIdentifier
Enum generated from inet/linklayer/ieee8021d/common/Ieee8021dBpdu.msg:13 by opp_msgtool.
Definition: Ieee8021dBpdu_m.h:57
inet::BPDU_CFG
@ BPDU_CFG
Definition: Ieee8021dBpdu_m.h:96
inet::BpduType
BpduType
Enum generated from inet/linklayer/ieee8021d/common/Ieee8021dBpdu.msg:23 by opp_msgtool.
Definition: Ieee8021dBpdu_m.h:95
inet::BpduProtocolVersionIdentifier
BpduProtocolVersionIdentifier
Enum generated from inet/linklayer/ieee8021d/common/Ieee8021dBpdu.msg:17 by opp_msgtool.
Definition: Ieee8021dBpdu_m.h:75
inet::BPDU_TCN
@ BPDU_TCN
Definition: Ieee8021dBpdu_m.h:97