INET Framework for OMNeT++/OMNEST
inet::serializer::EtherPhySerializer Class Reference

Converts between EtherFrame and binary (network byte order) Ethernet header. More...

#include <EthernetSerializer.h>

Inheritance diagram for inet::serializer::EtherPhySerializer:
inet::serializer::SerializerBase

Public Member Functions

 EtherPhySerializer (const char *name=nullptr)
 
- Public Member Functions inherited from inet::serializer::SerializerBase
 SerializerBase (const char *name=nullptr)
 
void serializePacket (const cPacket *pkt, Buffer &b, Context &context)
 
cPacket * deserializePacket (const Buffer &b, Context &context)
 

Protected Member Functions

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

Additional Inherited Members

- Static Public Member Functions inherited from inet::serializer::SerializerBase
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))
 

Detailed Description

Converts between EtherFrame and binary (network byte order) Ethernet header.

Constructor & Destructor Documentation

inet::serializer::EtherPhySerializer::EtherPhySerializer ( const char *  name = nullptr)
inline
64 : SerializerBase(name) {}
SerializerBase(const char *name=nullptr)
Definition: SerializerBase.h:84

Member Function Documentation

cPacket * inet::serializer::EtherPhySerializer::deserialize ( const Buffer b,
Context context 
)
overrideprotectedvirtual

Puts a packet sniffed from the wire into an EtherFrame.

Implements inet::serializer::SerializerBase.

178 {
179  ASSERT(b.getPos() == 0);
180  EtherPhyFrame *etherPhyFrame = nullptr;
181  char buff[PREAMBLE_BYTES + SFD_BYTES + 1];
182  b.readNBytes(PREAMBLE_BYTES + SFD_BYTES, buff);
183  if (0 == memcmp(buff, "0x550x550x550x550x550x550x550xD5", PREAMBLE_BYTES + SFD_BYTES)) {
184  etherPhyFrame = new EtherPhyFrame();
185  cPacket *encapPacket = SerializerBase::lookupAndDeserialize(b, c, LINKTYPE, LINKTYPE_ETHERNET, b.getRemainingSize());
186  ASSERT(encapPacket);
187  etherPhyFrame->encapsulate(encapPacket);
188  etherPhyFrame->setName(encapPacket->getName());
189  }
190  else {
191  b.seek(0);
192  }
193  return etherPhyFrame;
194 }
#define SFD_BYTES
Definition: Ethernet.h:46
const value< double, compose< units::m, pow< units::s,-1 > > > c(299792458)
#define PREAMBLE_BYTES
Definition: Ethernet.h:45
static cPacket * lookupAndDeserialize(const Buffer &b, Context &context, ProtocolGroup group, int id, unsigned int maxLength=(unsigned int)(-1))
Definition: SerializerBase.cc:99
value< double, units::m > b
Definition: Units.h:1054
Definition: SerializerBase.h:45
Definition: SerializerBase.h:40
void inet::serializer::EtherPhySerializer::serialize ( const cPacket *  pkt,
Buffer b,
Context context 
)
overrideprotectedvirtual

Serializes an EtherFrame for transmission on the wire.

Implements inet::serializer::SerializerBase.

168 {
169  ASSERT(b.getPos() == 0);
170  const EtherPhyFrame *ethPkt = check_and_cast<const EtherPhyFrame *>(pkt);
171  b.fillNBytes(PREAMBLE_BYTES, 0x55); // preamble
172  b.writeByte(0xD5); // SFD
173  cPacket *encapPkt = ethPkt->getEncapsulatedPacket();
174  SerializerBase::lookupAndSerialize(encapPkt, b, c, LINKTYPE, LINKTYPE_ETHERNET, b.getRemainingSize());
175 }
const value< double, compose< units::m, pow< units::s,-1 > > > c(299792458)
static void lookupAndSerialize(const cPacket *pkt, Buffer &b, Context &context, ProtocolGroup group, int id, unsigned int maxLength=(unsigned int)(-1))
Definition: SerializerBase.cc:88
#define PREAMBLE_BYTES
Definition: Ethernet.h:45
value< double, units::m > b
Definition: Units.h:1054
Definition: SerializerBase.h:45
Definition: SerializerBase.h:40

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