41 ASSERT(
b.getPos() == 0);
42 const EtherFrame *ethPkt = check_and_cast<
const EtherFrame *>(pkt);
43 b.writeMACAddress(ethPkt->getDest());
44 b.writeMACAddress(ethPkt->getSrc());
45 if (dynamic_cast<const EthernetIIFrame *>(pkt)) {
46 const EthernetIIFrame *frame =
static_cast<const EthernetIIFrame *
>(pkt);
47 uint16_t ethType = frame->getEtherType();
48 b.writeUint16(ethType);
49 cPacket *encapPkt = frame->getEncapsulatedPacket();
52 else if (dynamic_cast<const EtherFrameWithLLC *>(pkt)) {
53 const EtherFrameWithLLC *frame =
static_cast<const EtherFrameWithLLC *
>(pkt);
54 cPacket *encapPkt = frame->getEncapsulatedPacket();
55 unsigned int payloadLengthPos =
b.getPos();
56 b.writeUint16(0xFFFF);
57 b.writeByte(frame->getSsap());
58 b.writeByte(frame->getDsap());
59 b.writeByte(frame->getControl());
60 if (dynamic_cast<const EtherFrameWithSNAP *>(pkt)) {
61 const EtherFrameWithSNAP *frame =
static_cast<const EtherFrameWithSNAP *
>(pkt);
62 b.writeByte(frame->getOrgCode() >> 16);
63 b.writeByte(frame->getOrgCode() >> 8);
64 b.writeByte(frame->getOrgCode());
65 b.writeUint16(frame->getLocalcode());
66 unsigned int payloadLength =
b.getRemainingSize(4);
67 if (frame->getOrgCode() == 0) {
68 b.writeUint16To(payloadLengthPos, payloadLength);
73 b.writeUint16To(payloadLengthPos, payloadLength);
77 else if (
typeid(*frame) ==
typeid(EtherFrameWithLLC)) {
78 unsigned int payloadLength =
b.getRemainingSize(4);
79 b.writeUint16To(payloadLengthPos, payloadLength);
83 throw cRuntimeError(
"Serializer not found for '%s'", pkt->getClassName());
86 else if (dynamic_cast<const EtherPauseFrame *>(pkt)) {
87 const EtherPauseFrame *frame =
static_cast<const EtherPauseFrame *
>(pkt);
88 b.writeUint16(0x8808);
89 b.writeUint16(0x0001);
90 b.writeUint16(frame->getPauseTime());
93 throw cRuntimeError(
"Serializer not found for '%s'", pkt->getClassName());
95 if (
b.getPos() + 4 < pkt->getByteLength())
96 b.fillNBytes((pkt->getByteLength() - 4) -
b.getPos(), 0);
Definition: SerializerBase.h:36
Definition: SerializerBase.h:39
uint32_t ethernetCRC(const unsigned char *buf, unsigned int bufsize)
Definition: EthernetCRC.cc:67
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
value< double, units::m > b
Definition: Units.h:1054