Serializes a cPacket for transmission on the wire.
Returns the length of data written into buffer.
41 unsigned int startpos =
b.getPos();
42 const ICMPv6Message *pkt = check_and_cast<
const ICMPv6Message *>(_pkt);
44 switch (pkt->getType()) {
46 const ICMPv6EchoRequestMsg *frame = check_and_cast<
const ICMPv6EchoRequestMsg *>(pkt);
47 PingPayload *pp = check_and_cast<PingPayload *>(pkt->getEncapsulatedPacket());
48 b.writeByte(pkt->getType());
49 b.writeByte(frame->getCode());
51 b.writeUint16(pp->getOriginatorId());
52 b.writeUint16(pp->getSeqNo());
53 unsigned int datalen = pp->getDataArraySize();
54 for (
unsigned int i = 0; i < datalen; i++)
55 b.writeByte(pp->getData(i));
56 datalen = (pp->getByteLength() - 4) - datalen;
57 b.fillNBytes(datalen,
'a');
62 const ICMPv6EchoReplyMsg *frame = check_and_cast<
const ICMPv6EchoReplyMsg *>(pkt);
63 PingPayload *pp = check_and_cast<PingPayload *>(pkt->getEncapsulatedPacket());
64 b.writeByte(pkt->getType());
65 b.writeByte(frame->getCode());
67 b.writeUint16(pp->getOriginatorId());
68 b.writeUint16(pp->getSeqNo());
69 unsigned int datalen = pp->getDataArraySize();
70 for (
unsigned int i = 0; i < datalen; i++)
71 b.writeByte(pp->getData(i));
72 datalen = (pp->getByteLength() - 4) - datalen;
73 b.fillNBytes(datalen,
'a');
78 const ICMPv6DestUnreachableMsg *frame = check_and_cast<
const ICMPv6DestUnreachableMsg *>(pkt);
79 b.writeByte(pkt->getType());
80 b.writeByte(frame->getCode());
88 const ICMPv6TimeExceededMsg *frame = check_and_cast<
const ICMPv6TimeExceededMsg *>(pkt);
89 b.writeByte(pkt->getType());
90 b.writeByte(frame->getCode());
98 const IPv6NeighbourSolicitation *frame = check_and_cast<
const IPv6NeighbourSolicitation *>(pkt);
99 b.writeByte(pkt->getType());
100 b.writeByte(frame->getCode());
103 b.writeIPv6Address(frame->getTargetAddress());
104 if (frame->getByteLength() > 8 + 16) {
107 b.writeMACAddress(frame->getSourceLinkLayerAddress());
114 if (
c.throwOnSerializerNotFound)
115 throw cRuntimeError(
"Can not serialize ICMPv6 packet: type %d not supported.", pkt->getType());
116 b.writeByte(pkt->getType());
119 ASSERT(pkt->getByteLength() >= 4);
120 b.fillNBytes(pkt->getByteLength() - 4,
'a');
Definition: SerializerBase.h:39
Definition: ICMPv6Message_m.h:82
static uint16_t checksum(const void *addr, unsigned int count)
Definition: TCPIPchecksum.h:44
Definition: ICMPv6Message_m.h:71
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
Definition: ICMPv6Message_m.h:76
Definition: ICMPv6Message_m.h:75
#define MAC_ADDRESS_SIZE
Definition: MACAddress.h:27
Definition: ICMPv6Message_m.h:73
Definition: Ieee802Ctrl_m.h:120
value< double, units::m > b
Definition: Units.h:1054
Definition: IPv6NDMessage_m.h:76