INET Framework for OMNeT++/OMNEST
inet::serializer::SerializerBase Class Referenceabstract

Converts between cPacket and binary (network byte order) packet. More...

#include <SerializerBase.h>

Inheritance diagram for inet::serializer::SerializerBase:
inet::serializer::ARPSerializer inet::serializer::ByteArraySerializer inet::serializer::DefaultSerializer inet::serializer::EthernetSerializer inet::serializer::EtherPhySerializer inet::serializer::ICMPSerializer inet::serializer::ICMPv6Serializer inet::serializer::Ieee80211Serializer inet::serializer::IGMPSerializer inet::serializer::IPv4Serializer inet::serializer::IPv6Serializer inet::serializer::SCTPSerializer inet::serializer::TCPSerializer inet::serializer::UDPSerializer

Public Member Functions

 SerializerBase (const char *name=nullptr)
 
void serializePacket (const cPacket *pkt, Buffer &b, Context &context)
 
cPacket * deserializePacket (const Buffer &b, Context &context)
 

Static Public Member Functions

static SerializerBaselookupSerializer (const cPacket *pkt, Context &context, ProtocolGroup group, int id)
 
static void lookupAndSerialize (const cPacket *pkt, Buffer &b, Context &context, ProtocolGroup group, int id, unsigned int maxLength=(unsigned int)(-1))
 
static SerializerBaselookupDeserializer (Context &context, ProtocolGroup group, int id)
 
static cPacket * lookupAndDeserialize (const Buffer &b, Context &context, ProtocolGroup group, int id, unsigned int maxLength=(unsigned int)(-1))
 

Protected Member Functions

virtual void serialize (const cPacket *pkt, Buffer &b, Context &context)=0
 Serializes a cPacket for transmission on the wire. More...
 
virtual cPacket * deserialize (const Buffer &b, Context &context)=0
 Puts a packet sniffed from the wire into an EtherFrame. More...
 

Detailed Description

Converts between cPacket and binary (network byte order) packet.

Constructor & Destructor Documentation

inet::serializer::SerializerBase::SerializerBase ( const char *  name = nullptr)
inline
84 : cOwnedObject(name) {}

Member Function Documentation

cPacket * inet::serializer::SerializerBase::deserializePacket ( const Buffer b,
Context context 
)

Referenced by inet::serializer::Ieee80211PhySerializer::deserialize(), inet::serializer::IGMPSerializer::deserialize(), inet::serializer::UDPSerializer::deserialize(), inet::physicallayer::APSKPhyFrameSerializer::deserialize(), inet::ExtInterface::handleMessage(), and lookupAndDeserialize().

43 {
44  if (b.getRemainingSize() == 0)
45  return nullptr;
46 
47  unsigned int startPos = b.getPos();
48  cPacket *pkt = deserialize(b, context);
49  if (pkt == nullptr) {
50  b.seek(startPos);
52  }
53  ASSERT(pkt);
54  if (!pkt->hasBitError() && !b.hasError() && (b.getPos() - startPos != pkt->getByteLength())) {
55  const char *encclass = pkt->getEncapsulatedPacket() ? pkt->getEncapsulatedPacket()->getClassName() : "<nullptr>";
56  throw cRuntimeError("%s deserializer error: packet %s (%s) length is %d but deserialized length is %d (encapsulated packet is %s)", getClassName(), pkt->getName(), pkt->getClassName(), pkt->getByteLength(), b.getPos() - startPos, encclass);
57  }
58  if (b.hasError())
59  pkt->setBitError(true);
60  return pkt;
61 }
static ByteArraySerializer byteArraySerializer
Definition: SerializerBase.h:113
virtual cPacket * deserialize(const Buffer &b, Context &context) override
Puts a packet sniffed from the wire into an EtherFrame.
Definition: SerializerBase.cc:146
SerializerRegistrationList serializers("default")
List of packet serializers (SerializerBase)
Definition: SerializerBase.h:146
virtual cPacket * deserialize(const Buffer &b, Context &context)=0
Puts a packet sniffed from the wire into an EtherFrame.
value< double, units::m > b
Definition: Units.h:1054
cPacket * inet::serializer::SerializerBase::lookupAndDeserialize ( const Buffer b,
Context context,
ProtocolGroup  group,
int  id,
unsigned int  maxLength = (unsigned int)(-1) 
)
static

Referenced by inet::IPv4FragBuf::addFragment(), inet::EtherMACBase::decapsulate(), inet::serializer::IPv6Serializer::deserialize(), inet::serializer::ICMPSerializer::deserialize(), inet::serializer::Ieee80211Serializer::deserialize(), inet::serializer::EthernetSerializer::deserialize(), inet::serializer::EtherPhySerializer::deserialize(), and inet::serializer::IPv4Serializer::deserialize().

100 {
101  cPacket *encapPacket = nullptr;
102  SerializerBase& serializer = lookupDeserializer(context, group, id);
103  Buffer subBuffer(b, maxLength);
104  encapPacket = serializer.deserializePacket(subBuffer, context);
105  b.accessNBytes(subBuffer.getPos());
106  return encapPacket;
107 }
SerializerBase(const char *name=nullptr)
Definition: SerializerBase.h:84
static SerializerBase & lookupDeserializer(Context &context, ProtocolGroup group, int id)
Definition: SerializerBase.cc:79
value< double, units::m > b
Definition: Units.h:1054
void inet::serializer::SerializerBase::lookupAndSerialize ( const cPacket *  pkt,
Buffer b,
Context context,
ProtocolGroup  group,
int  id,
unsigned int  maxLength = (unsigned int)(-1) 
)
static

Referenced by inet::serializer::IPv6Serializer::serialize(), inet::serializer::ICMPv6Serializer::serialize(), inet::serializer::UDPSerializer::serialize(), inet::serializer::ICMPSerializer::serialize(), inet::serializer::EthernetSerializer::serialize(), inet::serializer::Ieee80211Serializer::serialize(), inet::serializer::EtherPhySerializer::serialize(), and inet::serializer::IPv4Serializer::serialize().

89 {
90  ASSERT(pkt);
91  Buffer subBuffer(b, maxLength);
92  SerializerBase & serializer = lookupSerializer(pkt, context, group, id);
93  serializer.serializePacket(pkt, subBuffer, context);
94  b.accessNBytes(subBuffer.getPos());
95  if (subBuffer.hasError())
96  b.setError();
97 }
SerializerBase(const char *name=nullptr)
Definition: SerializerBase.h:84
value< double, units::m > b
Definition: Units.h:1054
static SerializerBase & lookupSerializer(const cPacket *pkt, Context &context, ProtocolGroup group, int id)
Definition: SerializerBase.cc:63
SerializerBase & inet::serializer::SerializerBase::lookupDeserializer ( Context context,
ProtocolGroup  group,
int  id 
)
static

Referenced by lookupAndDeserialize().

80 {
81  SerializerBase *serializer = serializers.lookup(group, id);
82  if (serializer != nullptr)
83  return *serializer;
84  else
86 }
SerializerBase(const char *name=nullptr)
Definition: SerializerBase.h:84
static ByteArraySerializer byteArraySerializer
Definition: SerializerBase.h:113
SerializerRegistrationList serializers("default")
List of packet serializers (SerializerBase)
Definition: SerializerBase.h:146
virtual SerializerBase * lookup(int protocolGroup, int protocolId) const
Returns the object with exactly the given group ID and protocol ID.
Definition: SerializerBase.cc:187
SerializerBase & inet::serializer::SerializerBase::lookupSerializer ( const cPacket *  pkt,
Context context,
ProtocolGroup  group,
int  id 
)
static

Referenced by lookupAndSerialize().

64 {
65  const RawPacket *bam = dynamic_cast<const RawPacket *>(pkt);
66  if (bam != nullptr)
68  SerializerBase *serializer = serializers.lookup(group, id);
69  if (serializer != nullptr)
70  return *serializer;
71  serializer = serializers.lookup(pkt->getClassName());
72  if (serializer != nullptr)
73  return *serializer;
74  if (context.throwOnSerializerNotFound)
75  throw cRuntimeError("Serializer not found for '%s' (%i, %i)", pkt->getClassName(), group, id);
77 }
SerializerBase(const char *name=nullptr)
Definition: SerializerBase.h:84
static ByteArraySerializer byteArraySerializer
Definition: SerializerBase.h:113
SerializerRegistrationList serializers("default")
List of packet serializers (SerializerBase)
Definition: SerializerBase.h:146
virtual SerializerBase * lookup(int protocolGroup, int protocolId) const
Returns the object with exactly the given group ID and protocol ID.
Definition: SerializerBase.cc:187
uint16_t id
Definition: TCP_NSC.cc:85
static DefaultSerializer defaultSerializer
Definition: SerializerBase.h:112
void inet::serializer::SerializerBase::serializePacket ( const cPacket *  pkt,
Buffer b,
Context context 
)

Referenced by inet::serializer::SCTPSerializer::deserialize(), inet::tcp::TCP_NSC::handleIpInputMessage(), inet::tcp::TCP_lwIP::handleIpInputMessage(), inet::ExtInterface::handleMessage(), lookupAndSerialize(), inet::sctp::SCTP::send_to_ip(), inet::physicallayer::APSKPhyFrameSerializer::serialize(), inet::PcapDump::writeFrame(), and inet::PcapDump::writeIPv6Frame().

35 {
36  unsigned int startPos = b.getPos();
37  serialize(pkt, b, c);
38  if (!b.hasError() && (b.getPos() - startPos != pkt->getByteLength()))
39  throw cRuntimeError("%s serializer error: packet %s (%s) length is %d but serialized length is %d", getClassName(), pkt->getName(), pkt->getClassName(), pkt->getByteLength(), b.getPos() - startPos);
40 }
const value< double, compose< units::m, pow< units::s,-1 > > > c(299792458)
virtual void serialize(const cPacket *pkt, Buffer &b, Context &context)=0
Serializes a cPacket for transmission on the wire.
value< double, units::m > b
Definition: Units.h:1054

The documentation for this class was generated from the following files: