Serializes a cPacket for transmission on the wire.
Returns the length of data written into buffer.
46 unsigned int startPos =
b.getPos();
47 const IGMPMessage *pkt = check_and_cast<
const IGMPMessage *>(_pkt);
48 const void *igmp =
b.accessNBytes(0);
50 switch (pkt->getType())
56 b.writeIPv4Address(check_and_cast<const IGMPQuery*>(pkt)->getGroupAddress());
57 if (dynamic_cast<const IGMPv3Query*>(pkt))
59 const IGMPv3Query* v3pkt =
static_cast<const IGMPv3Query*
>(pkt);
60 b.writeByteTo(1, v3pkt->getMaxRespCode());
61 ASSERT(v3pkt->getRobustnessVariable() <= 7);
62 b.writeByte((v3pkt->getSuppressRouterProc() ? 0x8 : 0) | v3pkt->getRobustnessVariable());
63 b.writeByte(v3pkt->getQueryIntervalCode());
64 unsigned int vs = v3pkt->getSourceList().size();
66 for (
unsigned int i = 0; i < vs; i++)
67 b.writeIPv4Address(v3pkt->getSourceList()[i]);
69 else if (dynamic_cast<const IGMPv2Query*>(pkt))
71 b.writeByteTo(1, static_cast<const IGMPv2Query*>(pkt)->getMaxRespTime());
80 b.writeIPv4Address(check_and_cast<const IGMPv1Report*>(pkt)->getGroupAddress());
87 b.writeIPv4Address(check_and_cast<const IGMPv2Report*>(pkt)->getGroupAddress());
94 b.writeIPv4Address(check_and_cast<const IGMPv2Leave*>(pkt)->getGroupAddress());
98 const IGMPv3Report* v3pkt = check_and_cast<
const IGMPv3Report*>(pkt);
103 unsigned int s = v3pkt->getGroupRecordArraySize();
105 for (
unsigned int i = 0; i <
s; i++) {
107 const GroupRecord& gr = v3pkt->getGroupRecord(i);
108 b.writeByte(gr.recordType);
110 b.writeUint16(gr.sourceList.size());
111 b.writeIPv4Address(gr.groupAddress);
112 for (
auto src: gr.sourceList) {
113 b.writeIPv4Address(src);
121 throw cRuntimeError(
"Can not serialize IGMP packet (%s): type %d not supported.", pkt->getClassName(), pkt->getType());
Definition: IGMPMessage_m.h:62
Definition: IGMPMessage_m.h:61
static uint16_t checksum(const void *addr, unsigned int count)
Definition: TCPIPchecksum.h:44
Definition: IGMPMessage_m.h:60
Definition: IGMPMessage_m.h:58
Definition: IGMPMessage_m.h:59
value< double, units::s > s
Definition: Units.h:1049
value< double, units::m > b
Definition: Units.h:1054