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

Converts between ArpPacket and binary (network byte order) Arp header. More...

#include <ArpPacketSerializer.h>

Inheritance diagram for inet::ArpPacketSerializer:
inet::FieldsChunkSerializer inet::ChunkSerializer

Public Member Functions

 ArpPacketSerializer ()
 
- 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

MacAddress readMacAddress (MemoryInputStream &stream, unsigned int size) const
 
Ipv4Address readIpv4Address (MemoryInputStream &stream, unsigned int size) const
 
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 ArpPacket and binary (network byte order) Arp header.

Constructor & Destructor Documentation

◆ ArpPacketSerializer()

inet::ArpPacketSerializer::ArpPacketSerializer ( )
inline
28 : FieldsChunkSerializer() {}

Member Function Documentation

◆ deserialize()

const Ptr< Chunk > inet::ArpPacketSerializer::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.

50 {
51  auto arpPacket = makeShared<ArpPacket>();
52  if (stream.readUint16Be() != 1)
53  arpPacket->markIncorrect();
54  if (stream.readUint16Be() != ETHERTYPE_IPv4)
55  arpPacket->markIncorrect();
56  uint8_t macAddressLength = stream.readByte(); // ar_hln
57  uint8_t ipAddressLength = stream.readByte(); // ar_pln
58  arpPacket->setOpcode(static_cast<ArpOpcode>(stream.readUint16Be())); // arphdr->ar_op
59  arpPacket->setSrcMacAddress(readMacAddress(stream, macAddressLength));
60  arpPacket->setSrcIpAddress(readIpv4Address(stream, ipAddressLength)); // ar_spa
61  arpPacket->setDestMacAddress(readMacAddress(stream, macAddressLength));
62  arpPacket->setDestIpAddress(readIpv4Address(stream, ipAddressLength)); // ar_tpa
63  return arpPacket;
64 }

◆ readIpv4Address()

Ipv4Address inet::ArpPacketSerializer::readIpv4Address ( MemoryInputStream stream,
unsigned int  size 
) const
protected
28 {
29  b curpos = stream.getPosition();
30  Ipv4Address address = stream.readIpv4Address();
31  stream.seek(curpos + B(size));
32  return address;
33 }

Referenced by deserialize().

◆ readMacAddress()

MacAddress inet::ArpPacketSerializer::readMacAddress ( MemoryInputStream stream,
unsigned int  size 
) const
protected
20 {
21  b curpos = stream.getPosition();
22  MacAddress address = stream.readMacAddress();
23  stream.seek(curpos + B(size));
24  return address;
25 }

Referenced by deserialize().

◆ serialize()

void inet::ArpPacketSerializer::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.

36 {
37  const auto& arpPacket = staticPtrCast<const ArpPacket>(chunk);
38  stream.writeUint16Be(1); // ethernet
39  stream.writeUint16Be(ETHERTYPE_IPv4);
40  stream.writeByte(MAC_ADDRESS_SIZE);
41  stream.writeByte(4); // size of IPv4 address
42  stream.writeUint16Be(arpPacket->getOpcode());
43  stream.writeMacAddress(arpPacket->getSrcMacAddress());
44  stream.writeIpv4Address(arpPacket->getSrcIpAddress());
45  stream.writeMacAddress(arpPacket->getDestMacAddress());
46  stream.writeIpv4Address(arpPacket->getDestIpAddress());
47 }

The documentation for this class was generated from the following files:
MAC_ADDRESS_SIZE
#define MAC_ADDRESS_SIZE
Definition: MacAddress.h:16
inet::ArpOpcode
ArpOpcode
Enum generated from inet/networklayer/arp/ipv4/ArpPacket.msg:18 by opp_msgtool.
Definition: ArpPacket_m.h:63
inet::units::units::B
intscale< b, 1, 8 > B
Definition: Units.h:1168
inet::ArpPacketSerializer::readIpv4Address
Ipv4Address readIpv4Address(MemoryInputStream &stream, unsigned int size) const
Definition: ArpPacketSerializer.cc:27
inet::units::values::b
value< int64_t, units::b > b
Definition: Units.h:1241
inet::ArpPacketSerializer::readMacAddress
MacAddress readMacAddress(MemoryInputStream &stream, unsigned int size) const
Definition: ArpPacketSerializer.cc:19
inet::ETHERTYPE_IPv4
@ ETHERTYPE_IPv4
Definition: EtherType_m.h:77