Serializes a cPacket for transmission on the wire.
Returns the length of data written into buffer.
59 const IPv6Datagram *dgram = check_and_cast<
const IPv6Datagram *>(pkt);
63 EV <<
"Serialize IPv6 packet\n";
65 unsigned int nextHdrCodePos =
b.getPos() + 6;
66 struct ip6_hdr *ip6h = (
struct ip6_hdr *)
b.accessNBytes(
sizeof(
struct ip6_hdr));
70 flowinfo |= dgram->getTrafficClass();
72 flowinfo |= dgram->getFlowLabel();
73 ip6h->ip6_flow =
htonl(flowinfo);
74 ip6h->ip6_hlim =
htons(dgram->getHopLimit());
76 ip6h->ip6_nxt = dgram->getTransportProtocol();
78 for (i = 0; i < 4; i++) {
79 ip6h->ip6_src.__u6_addr.__u6_addr32[i] =
htonl(dgram->getSrcAddress().words()[i]);
81 for (i = 0; i < 4; i++) {
82 ip6h->ip6_dst.__u6_addr.__u6_addr32[i] =
htonl(dgram->getDestAddress().words()[i]);
84 c.l3AddressesPtr = &ip6h->ip6_src.__u6_addr.__u6_addr32[0];
85 c.l3AddressesLength = 32;
88 for (i = 0; i < dgram->getExtensionHeaderArraySize(); i++) {
89 const IPv6ExtensionHeader *extHdr = dgram->getExtensionHeader(i);
90 b.writeByteTo(nextHdrCodePos, extHdr->getExtensionType());
91 nextHdrCodePos =
b.getPos();
92 b.writeByte(dgram->getTransportProtocol());
93 ASSERT((extHdr->getByteLength() & 7) == 0);
94 b.writeByte((extHdr->getByteLength() - 8) / 8);
95 switch (extHdr->getExtensionType()) {
97 const IPv6HopByHopOptionsHeader *hdr = check_and_cast<
const IPv6HopByHopOptionsHeader *>(extHdr);
98 b.fillNBytes(hdr->getByteLength() - 2,
'\0');
102 const IPv6DestinationOptionsHeader *hdr = check_and_cast<
const IPv6DestinationOptionsHeader *>(extHdr);
103 b.fillNBytes(hdr->getByteLength() - 2,
'\0');
107 const IPv6RoutingHeader *hdr = check_and_cast<
const IPv6RoutingHeader *>(extHdr);
108 b.writeByte(hdr->getRoutingType());
109 b.writeByte(hdr->getSegmentsLeft());
110 for (
unsigned int j = 0; j < hdr->getAddressArraySize(); j++) {
111 b.writeIPv6Address(hdr->getAddress(j));
113 b.fillNBytes(4,
'\0');
117 const IPv6FragmentHeader *hdr = check_and_cast<
const IPv6FragmentHeader *>(extHdr);
118 ASSERT((hdr->getFragmentOffset() & 7) == 0);
119 b.writeUint16(hdr->getFragmentOffset() | (hdr->getMoreFragments() ? 1 : 0));
120 b.writeUint32(hdr->getIdentification());
124 const IPv6AuthenticationHeader *hdr = check_and_cast<
const IPv6AuthenticationHeader *>(extHdr);
125 b.fillNBytes(hdr->getByteLength() - 2,
'\0');
129 const IPv6EncapsulatingSecurityPayloadHeader *hdr = check_and_cast<
const IPv6EncapsulatingSecurityPayloadHeader *>(extHdr);
130 b.fillNBytes(hdr->getByteLength() - 2,
'\0');
134 throw cRuntimeError(
"Unknown IPv6 extension header %d (%s)%s", extHdr->getExtensionType(), extHdr->getClassName(), extHdr->getFullName());
138 ASSERT(nextHdrCodePos + extHdr->getByteLength() ==
b.getPos());
141 const cPacket *encapPacket = dgram->getEncapsulatedPacket();
142 unsigned int encapStart =
b.getPos();
144 unsigned int encapEnd =
b.getPos();
146 ip6h->ip6_plen =
htons(encapEnd - encapStart);
Definition: SerializerBase.h:38
Definition: IPProtocolId_m.h:94
Definition: IPProtocolId_m.h:95
const value< double, compose< units::m, pow< units::s,-1 > > > c(299792458)
Definition: IPProtocolId_m.h:98
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: IPProtocolId_m.h:97
Definition: IPProtocolId_m.h:99
value< double, units::m > b
Definition: Units.h:1054
Definition: IPProtocolId_m.h:96