25#include "ns3/boolean.h"
26#include "ns3/channel.h"
27#include "ns3/ipv6-extension-header.h"
28#include "ns3/ipv6-l3-protocol.h"
30#include "ns3/mac16-address.h"
31#include "ns3/mac48-address.h"
32#include "ns3/mac64-address.h"
34#include "ns3/packet.h"
35#include "ns3/pointer.h"
36#include "ns3/simulator.h"
37#include "ns3/string.h"
38#include "ns3/udp-header.h"
39#include "ns3/udp-l4-protocol.h"
40#include "ns3/uinteger.h"
55 TypeId(
"ns3::SixLowPanNetDevice")
57 .SetGroupName(
"SixLowPan")
59 .AddAttribute(
"Rfc6282",
60 "Use RFC6282 (IPHC) if true, RFC4944 (HC1) otherwise.",
64 .AddAttribute(
"OmitUdpChecksum",
65 "Omit the UDP checksum in IPHC compression.",
70 "FragmentReassemblyListSize",
71 "The maximum size of the reassembly buffer (in packets). Zero meaning infinite.",
74 MakeUintegerChecker<uint16_t>())
76 "FragmentExpirationTimeout",
77 "When this timeout expires, the fragments will be cleared from the buffer.",
81 .AddAttribute(
"CompressionThreshold",
82 "The minimum MAC layer payload size.",
85 MakeUintegerChecker<uint32_t>())
86 .AddAttribute(
"ForceEtherType",
87 "Force a specific EtherType in L2 frames.",
91 .AddAttribute(
"EtherType",
92 "The specific EtherType to be used in L2 frames.",
95 MakeUintegerChecker<uint16_t>())
96 .AddAttribute(
"UseMeshUnder",
97 "Use a mesh-under routing protocol.",
101 .AddAttribute(
"MeshUnderRadius",
102 "Hops Left to use in mesh-under.",
105 MakeUintegerChecker<uint8_t>())
106 .AddAttribute(
"MeshCacheLength",
107 "Length of the cache for each source.",
110 MakeUintegerChecker<uint16_t>())
111 .AddAttribute(
"MeshUnderJitter",
112 "The jitter in ms a node uses to forward mesh-under packets - used to "
113 "prevent collisions",
114 StringValue(
"ns3::UniformRandomVariable[Min=0.0|Max=10.0]"),
116 MakePointerChecker<RandomVariableStream>())
117 .AddTraceSource(
"Tx",
118 "Send - packet (including 6LoWPAN header), "
119 "SixLoWPanNetDevice Ptr, interface index.",
121 "ns3::SixLowPanNetDevice::RxTxTracedCallback")
122 .AddTraceSource(
"Rx",
123 "Receive - packet (including 6LoWPAN header), "
124 "SixLoWPanNetDevice Ptr, interface index.",
126 "ns3::SixLowPanNetDevice::RxTxTracedCallback")
127 .AddTraceSource(
"Drop",
128 "Drop - DropReason, packet (including 6LoWPAN header), "
129 "SixLoWPanNetDevice Ptr, interface index.",
131 "ns3::SixLowPanNetDevice::DropTracedCallback");
137 m_netDevice(nullptr),
142 m_rng = CreateObject<UniformRandomVariable>();
159 NS_LOG_DEBUG(
"RegisterProtocolHandler for " << device->GetInstanceTypeId().GetName());
161 uint16_t protocolType = 0;
197 iter->second =
nullptr;
212 NS_LOG_FUNCTION(
this << incomingPort << packet << protocol << src << dst);
214 uint8_t dispatchRawVal = 0;
220 copyPkt->CopyData(&dispatchRawVal,
sizeof(dispatchRawVal));
222 bool isPktDecompressed =
false;
223 bool fragmented =
false;
227 NS_LOG_DEBUG(
"Dispatches: " <<
int(dispatchRawVal) <<
" - " <<
int(dispatchVal));
231 bool hasMesh =
false;
237 copyPkt->RemoveHeader(meshHdr);
238 copyPkt->CopyData(&dispatchRawVal,
sizeof(dispatchRawVal));
244 copyPkt->RemoveHeader(bc0Hdr);
245 copyPkt->CopyData(&dispatchRawVal,
sizeof(dispatchRawVal));
253 NS_LOG_LOGIC(
"Dropped packet - we only support mesh if it is paired with a BC0");
262 NS_LOG_LOGIC(
"We have already seen this, no further processing.");
273 "SixLowPan mesh-under flooding can not currently handle extended address "
274 "final destinations: "
277 "SixLowPan mesh-under flooding can not currently handle devices using "
278 "extended addresses: "
291 NS_LOG_LOGIC(
"Not forwarding packet -- hop limit reached");
295 NS_LOG_LOGIC(
"Not forwarding packet -- I am the originator");
301 sendPkt->AddHeader(bc0Hdr);
302 sendPkt->AddHeader(meshHdr);
338 if (!isPktDecompressed)
344 copyPkt->CopyData(&dispatchRawVal,
sizeof(dispatchRawVal));
352 NS_LOG_DEBUG(
"Packet without compression. Length: " << copyPkt->GetSize());
355 copyPkt->RemoveHeader(uncompressedHdr);
356 isPktDecompressed =
true;
366 isPktDecompressed =
true;
380 isPktDecompressed =
true;
384 NS_LOG_DEBUG(
"Unsupported 6LoWPAN encoding: dropping.");
389 if (!isPktDecompressed)
394 NS_LOG_DEBUG(
"Packet decompressed length: " << copyPkt->GetSize());
395 NS_LOG_DEBUG(
"Packet decompressed received: " << *copyPkt);
490 return m_netDevice->AddLinkChangeCallback(callback);
563 ret =
DoSend(packet, src, dest, protocolNumber,
false);
571 uint16_t protocolNumber)
576 ret =
DoSend(packet, src, dest, protocolNumber,
true);
584 uint16_t protocolNumber,
587 NS_LOG_FUNCTION(
this << *packet << src << dest << protocolNumber << doSendFrom);
592 uint32_t origPacketSize = packet->GetSize();
615 uint16_t
pktSize = packet->GetSize();
651 NS_LOG_LOGIC(
"Compressed packet too short, using uncompressed one");
654 packet->AddHeader(ipv6UncompressedHdr);
664 NS_LOG_LOGIC(
"Fragmentation: Packet size " << packet->GetSize() <<
" - Mtu "
667 std::list<Ptr<Packet>> fragmentList;
668 DoFragmentation(packet, origPacketSize, origHdrSize, extraHdrSize, fragmentList);
669 std::list<Ptr<Packet>>::iterator it;
671 for (it = fragmentList.begin(); it != fragmentList.end(); it++)
673 NS_LOG_DEBUG(
"SixLowPanNetDevice::Send (Fragment) " << **it);
679 (*it)->AddHeader(bc0Hdr);
680 (*it)->AddHeader(meshHdr);
684 success &=
m_netDevice->SendFrom(*it, src, destination, protocolNumber);
688 success &=
m_netDevice->Send(*it, destination, protocolNumber);
700 packet->AddHeader(bc0Hdr);
701 packet->AddHeader(meshHdr);
707 ret =
m_netDevice->SendFrom(packet, src, destination, protocolNumber);
712 ret =
m_netDevice->Send(packet, destination, protocolNumber);
772 NS_LOG_DEBUG(
"Original packet: " << *packet <<
" Size " << packet->GetSize());
774 if (packet->PeekHeader(ipHeader) != 0)
776 packet->RemoveHeader(ipHeader);
787 NS_LOG_LOGIC(
"Checking source compression: " << mySrcAddr <<
" - " << srcAddr);
790 bool isSrcSrc = (memcmp(bufOne + 8, bufTwo + 8, 8) == 0);
817 NS_LOG_LOGIC(
"Checking destination compression: " << myDstAddr <<
" - " << dstAddr);
820 bool isDstDst = (memcmp(bufOne + 8, bufTwo + 8, 8) == 0);
861 NS_LOG_DEBUG(
"HC1 Compression - packet size = " << packet->GetSize());
863 packet->AddHeader(hc1Header);
879 uint32_t ret [[maybe_unused]] = packet->RemoveHeader(encoding);
880 NS_LOG_DEBUG(
"removed " << ret <<
" bytes - pkt is " << *packet);
886 const uint8_t* interface;
887 const uint8_t* prefix;
892 interface = encoding.GetSrcInterface();
893 for (
int j = 0; j < 8; j++)
895 address[j + 8] = interface[j];
896 address[j] = prefix[j];
902 for (
int j = 0; j < 8; j++)
905 address[j] = prefix[j];
910 interface = encoding.GetSrcInterface();
913 for (
int j = 0; j < 8; j++)
915 address[j + 8] = interface[j];
926 const uint8_t* interface;
927 const uint8_t* prefix;
932 interface = encoding.GetDstInterface();
933 for (
int j = 0; j < 8; j++)
935 address[j + 8] = interface[j];
936 address[j] = prefix[j];
942 for (
int j = 0; j < 8; j++)
945 address[j] = prefix[j];
950 interface = encoding.GetDstInterface();
953 for (
int j = 0; j < 8; j++)
955 address[j + 8] = interface[j];
981 "6LoWPAN: error in decompressing HC1 encoding, unsupported L4 compressed header present.");
983 packet->AddHeader(ipHeader);
985 NS_LOG_DEBUG(
"Rebuilt packet: " << *packet <<
" Size " << packet->GetSize());
997 NS_LOG_DEBUG(
"Original packet: " << *packet <<
" Size " << packet->GetSize() <<
" src: " << src
1000 if (packet->PeekHeader(ipHeader) != 0)
1002 packet->RemoveHeader(ipHeader);
1037 iphcHeader.
SetNh(
true);
1042 iphcHeader.
SetNh(
true);
1051 iphcHeader.
SetNh(
true);
1056 iphcHeader.
SetNh(
false);
1063 iphcHeader.
SetNh(
false);
1088 iphcHeader.
SetCid(
false);
1089 iphcHeader.
SetSac(
false);
1090 iphcHeader.
SetDac(
false);
1093 uint8_t unicastAddrCheckerBuf[16];
1094 checker.
GetBytes(unicastAddrCheckerBuf);
1095 uint8_t addressBuf[16];
1100 uint8_t srcContextId;
1113 NS_LOG_LOGIC(
"Checking stateful source compression: " << srcAddr);
1116 if (srcContextId != 0)
1136 uint8_t serializedCleanedAddress[16];
1137 cleanedAddr.
Serialize(serializedCleanedAddress);
1139 if (serializedCleanedAddress[8] == 0x00 &&
1140 serializedCleanedAddress[9] == 0x00 &&
1141 serializedCleanedAddress[10] == 0x00 &&
1142 serializedCleanedAddress[11] == 0xff &&
1143 serializedCleanedAddress[12] == 0xfe &&
1144 serializedCleanedAddress[13] == 0x00)
1159 NS_LOG_LOGIC(
"Checking stateless source compression: " << srcAddr);
1163 uint8_t serializedSrcAddress[16];
1164 srcAddr.
Serialize(serializedSrcAddress);
1170 else if (memcmp(addressBuf, unicastAddrCheckerBuf, 14) == 0)
1191 iphcHeader.
SetM(
true);
1195 iphcHeader.
SetM(
false);
1203 NS_LOG_LOGIC(
"Checking destination compression: " << dstAddr);
1205 uint8_t serializedDstAddress[16];
1206 dstAddr.
Serialize(serializedDstAddress);
1208 if (!iphcHeader.
GetM())
1212 uint8_t dstContextId;
1216 NS_LOG_LOGIC(
"Checking stateful destination compression: " << dstAddr);
1219 if (dstContextId != 0)
1239 uint8_t serializedCleanedAddress[16];
1240 cleanedAddr.
Serialize(serializedCleanedAddress);
1242 if (serializedCleanedAddress[8] == 0x00 &&
1243 serializedCleanedAddress[9] == 0x00 &&
1244 serializedCleanedAddress[10] == 0x00 &&
1245 serializedCleanedAddress[11] == 0xff &&
1246 serializedCleanedAddress[12] == 0xfe &&
1247 serializedCleanedAddress[13] == 0x00)
1261 NS_LOG_LOGIC(
"Checking stateless destination compression: " << dstAddr);
1267 else if (memcmp(addressBuf, unicastAddrCheckerBuf, 14) == 0)
1288 uint8_t dstContextId;
1294 uint8_t dstInlinePart[6] = {};
1295 dstInlinePart[0] = serializedDstAddress[1];
1296 dstInlinePart[1] = serializedDstAddress[2];
1297 dstInlinePart[2] = serializedDstAddress[12];
1298 dstInlinePart[3] = serializedDstAddress[13];
1299 dstInlinePart[4] = serializedDstAddress[14];
1300 dstInlinePart[5] = serializedDstAddress[15];
1303 if (dstContextId != 0)
1316 uint8_t multicastAddrCheckerBuf[16];
1318 multicastCheckAddress.
GetBytes(multicastAddrCheckerBuf);
1321 if (memcmp(addressBuf, multicastAddrCheckerBuf, 15) == 0)
1328 else if ((addressBuf[0] == multicastAddrCheckerBuf[0]) &&
1329 (memcmp(addressBuf + 2, multicastAddrCheckerBuf + 2, 11) == 0))
1331 uint8_t dstInlinePart[4] = {};
1332 memcpy(dstInlinePart, serializedDstAddress + 1, 1);
1333 memcpy(dstInlinePart + 1, serializedDstAddress + 13, 3);
1339 else if ((addressBuf[0] == multicastAddrCheckerBuf[0]) &&
1340 (memcmp(addressBuf + 2, multicastAddrCheckerBuf + 2, 9) == 0))
1342 uint8_t dstInlinePart[6] = {};
1343 memcpy(dstInlinePart, serializedDstAddress + 1, 1);
1344 memcpy(dstInlinePart + 1, serializedDstAddress + 11, 5);
1358 NS_LOG_DEBUG(
"IPHC Compression - packet size = " << packet->GetSize());
1360 packet->AddHeader(iphcHeader);
1362 NS_LOG_DEBUG(
"Packet after IPHC compression: " << *packet);
1398 uint32_t ret [[maybe_unused]] = packet->RemoveHeader(encoding);
1399 NS_LOG_DEBUG(
"removed " << ret <<
" bytes - pkt is " << *packet);
1417 NS_LOG_LOGIC(
"Unknown Source compression context (" << +contextId
1418 <<
"), dropping packet");
1423 NS_LOG_LOGIC(
"Expired Source compression context (" << +contextId
1424 <<
"), dropping packet");
1428 uint8_t contextPrefix[16];
1430 uint8_t contextLength =
m_contextTable[contextId].contextPrefix.GetPrefixLength();
1432 uint8_t srcAddress[16] = {};
1439 srcAddress[11] = 0xff;
1440 srcAddress[12] = 0xfe;
1448 uint8_t bytesToCopy = contextLength / 8;
1449 uint8_t bitsToCopy = contextLength % 8;
1452 for (uint8_t i = 0; i < bytesToCopy; i++)
1454 srcAddress[i] = contextPrefix[i];
1458 uint8_t addressBitMask = (1 << (8 - bitsToCopy)) - 1;
1459 uint8_t prefixBitMask = ~addressBitMask;
1460 srcAddress[bytesToCopy] = (contextPrefix[bytesToCopy] & prefixBitMask) |
1461 (srcAddress[bytesToCopy] & addressBitMask);
1472 uint8_t srcAddress[16] = {};
1478 uint8_t srcAddress[16] = {};
1480 srcAddress[0] = 0xfe;
1481 srcAddress[1] = 0x80;
1486 uint8_t srcAddress[16] = {};
1488 srcAddress[0] = 0xfe;
1489 srcAddress[1] = 0x80;
1490 srcAddress[11] = 0xff;
1491 srcAddress[12] = 0xfe;
1514 NS_LOG_LOGIC(
"Unknown Destination compression context (" << +contextId
1515 <<
"), dropping packet");
1520 NS_LOG_LOGIC(
"Expired Destination compression context (" << +contextId
1521 <<
"), dropping packet");
1525 uint8_t contextPrefix[16];
1527 uint8_t contextLength =
m_contextTable[contextId].contextPrefix.GetPrefixLength();
1529 if (!encoding.
GetM())
1532 uint8_t dstAddress[16] = {};
1539 dstAddress[11] = 0xff;
1540 dstAddress[12] = 0xfe;
1548 uint8_t bytesToCopy =
m_contextTable[contextId].contextPrefix.GetPrefixLength() / 8;
1549 uint8_t bitsToCopy = contextLength % 8;
1552 for (uint8_t i = 0; i < bytesToCopy; i++)
1554 dstAddress[i] = contextPrefix[i];
1558 uint8_t addressBitMask = (1 << (8 - bitsToCopy)) - 1;
1559 uint8_t prefixBitMask = ~addressBitMask;
1560 dstAddress[bytesToCopy] = (contextPrefix[bytesToCopy] & prefixBitMask) |
1561 (dstAddress[bytesToCopy] & addressBitMask);
1569 uint8_t dstAddress[16] = {};
1570 dstAddress[0] = 0xff;
1572 dstAddress[3] = contextLength;
1573 memcpy(dstAddress + 4, contextPrefix, 8);
1581 if (!encoding.
GetM())
1586 uint8_t dstAddress[16] = {};
1592 uint8_t dstAddress[16] = {};
1594 dstAddress[0] = 0xfe;
1595 dstAddress[1] = 0x80;
1600 uint8_t dstAddress[16] = {};
1602 dstAddress[0] = 0xfe;
1603 dstAddress[1] = 0x80;
1604 dstAddress[11] = 0xff;
1605 dstAddress[12] = 0xfe;
1618 uint8_t dstAddress[16] = {};
1624 uint8_t dstAddress[16] = {};
1625 dstAddress[0] = 0xff;
1632 uint8_t dstAddress[16] = {};
1633 dstAddress[0] = 0xff;
1640 uint8_t dstAddress[16] = {};
1641 dstAddress[0] = 0xff;
1642 dstAddress[1] = 0x02;
1650 uint8_t traf = 0x00;
1651 switch (encoding.
GetTf())
1654 traf |= encoding.
GetEcn();
1655 traf = (traf << 6) | encoding.
GetDscp();
1660 traf |= encoding.
GetEcn();
1666 traf |= encoding.
GetEcn();
1667 traf = (traf << 6) | encoding.
GetDscp();
1677 if (encoding.
GetNh())
1680 uint8_t dispatchRawVal = 0;
1683 packet->CopyData(&dispatchRawVal,
sizeof(dispatchRawVal));
1715 packet->AddHeader(ipHeader);
1717 NS_LOG_DEBUG(
"Rebuilt packet: " << *packet <<
" Size " << packet->GetSize());
1737 packet->PeekHeader(hopHeader);
1741 "LOWPAN_NHC MUST NOT be used to encode IPv6 Extension Headers "
1742 "that have more than 255 octets following the Length field after compression. "
1743 "Packet uncompressed.");
1747 size += packet->RemoveHeader(hopHeader);
1756 nhcHeader.
SetNh(
true);
1761 nhcHeader.
SetNh(
true);
1770 nhcHeader.
SetNh(
true);
1775 nhcHeader.
SetNh(
false);
1782 nhcHeader.
SetNh(
false);
1796 packet->PeekHeader(routingHeader);
1800 "LOWPAN_NHC MUST NOT be used to encode IPv6 Extension Headers "
1801 "that have more than 255 octets following the Length field after compression. "
1802 "Packet uncompressed.");
1806 size += packet->RemoveHeader(routingHeader);
1815 nhcHeader.
SetNh(
true);
1820 nhcHeader.
SetNh(
true);
1829 nhcHeader.
SetNh(
true);
1834 nhcHeader.
SetNh(
false);
1841 nhcHeader.
SetNh(
false);
1855 packet->PeekHeader(fragHeader);
1859 "LOWPAN_NHC MUST NOT be used to encode IPv6 Extension Headers "
1860 "that have more than 255 octets following the Length field after compression. "
1861 "Packet uncompressed.");
1864 size += packet->RemoveHeader(fragHeader);
1873 nhcHeader.
SetNh(
true);
1878 nhcHeader.
SetNh(
true);
1887 nhcHeader.
SetNh(
true);
1892 nhcHeader.
SetNh(
false);
1899 nhcHeader.
SetNh(
false);
1913 packet->PeekHeader(destHeader);
1917 "LOWPAN_NHC MUST NOT be used to encode IPv6 Extension Headers "
1918 "that have more than 255 octets following the Length field after compression. "
1919 "Packet uncompressed.");
1922 size += packet->RemoveHeader(destHeader);
1931 nhcHeader.
SetNh(
true);
1936 nhcHeader.
SetNh(
true);
1945 nhcHeader.
SetNh(
true);
1950 nhcHeader.
SetNh(
false);
1957 nhcHeader.
SetNh(
false);
1971 NS_ABORT_MSG(
"IPv6 Mobility Header is not supported in ns-3 yet");
1980 NS_LOG_DEBUG(
"NHC Compression - packet size = " << packet->GetSize());
1982 packet->AddHeader(nhcHeader);
1984 NS_LOG_DEBUG(
"Packet after NHC compression: " << *packet);
1988std::pair<uint8_t, bool>
1999 uint32_t ret [[maybe_unused]] = packet->RemoveHeader(encoding);
2000 NS_LOG_DEBUG(
"removed " << ret <<
" bytes - pkt is " << *packet);
2008 uint8_t blobData[260];
2009 blobSize = encoding.
CopyBlob(blobData + 2, 260 - 2);
2010 uint8_t paddingSize = 0;
2012 uint8_t actualEncodedHeaderType = encoding.
GetEid();
2013 uint8_t actualHeaderType;
2016 switch (actualEncodedHeaderType)
2020 if (encoding.
GetNh())
2023 uint8_t dispatchRawVal = 0;
2026 packet->CopyData(&dispatchRawVal,
sizeof(dispatchRawVal));
2045 if ((blobSize + 2) % 8 > 0)
2047 paddingSize = 8 - (blobSize + 2) % 8;
2049 if (paddingSize == 1)
2051 blobData[blobSize + 2] = 0;
2053 else if (paddingSize > 1)
2055 blobData[blobSize + 2] = 1;
2056 blobData[blobSize + 2 + 1] = paddingSize - 2;
2057 for (uint8_t i = 0; i < paddingSize - 2; i++)
2059 blobData[blobSize + 2 + 2 + i] = 0;
2062 blobData[1] = ((blobSize + 2 + paddingSize) >> 3) - 1;
2064 blob.
Begin().
Write(blobData, blobSize + 2 + paddingSize);
2067 packet->AddHeader(hopHeader);
2072 if (encoding.
GetNh())
2075 uint8_t dispatchRawVal = 0;
2078 packet->CopyData(&dispatchRawVal,
sizeof(dispatchRawVal));
2095 blobData[1] = ((blobSize + 2) >> 3) - 1;
2099 packet->AddHeader(routingHeader);
2104 if (encoding.
GetNh())
2107 uint8_t dispatchRawVal = 0;
2110 packet->CopyData(&dispatchRawVal,
sizeof(dispatchRawVal));
2133 packet->AddHeader(fragHeader);
2138 if (encoding.
GetNh())
2141 uint8_t dispatchRawVal = 0;
2144 packet->CopyData(&dispatchRawVal,
sizeof(dispatchRawVal));
2163 if ((blobSize + 2) % 8 > 0)
2165 paddingSize = 8 - (blobSize + 2) % 8;
2167 if (paddingSize == 1)
2169 blobData[blobSize + 2] = 0;
2171 else if (paddingSize > 1)
2173 blobData[blobSize + 2] = 1;
2174 blobData[blobSize + 2 + 1] = paddingSize - 2;
2175 for (uint8_t i = 0; i < paddingSize - 2; i++)
2177 blobData[blobSize + 2 + 2 + i] = 0;
2180 blobData[1] = ((blobSize + 2 + paddingSize) >> 3) - 1;
2182 blob.
Begin().
Write(blobData, blobSize + 2 + paddingSize);
2185 packet->AddHeader(destHeader);
2189 NS_ABORT_MSG(
"IPv6 Mobility Header is not supported in ns-3 yet");
2196 return std::pair<uint8_t, bool>(0,
true);
2200 NS_ABORT_MSG(
"Trying to decode unknown Extension Header");
2204 NS_LOG_DEBUG(
"Rebuilt packet: " << *packet <<
" Size " << packet->GetSize());
2205 return std::pair<uint8_t, bool>(actualHeaderType,
false);
2217 NS_ASSERT_MSG(packet->PeekHeader(udpHeader) != 0,
"UDP header not found, abort");
2219 size += packet->RemoveHeader(udpHeader);
2222 udpNhcHeader.
SetC(
false);
2228 udpNhcHeader.
SetC(
true);
2256 "UDP_NHC Compression - UDP_NHC header size = " << udpNhcHeader.
GetSerializedSize());
2257 NS_LOG_DEBUG(
"UDP_NHC Compression - packet size = " << packet->GetSize());
2259 packet->AddHeader(udpNhcHeader);
2261 NS_LOG_DEBUG(
"Packet after UDP_NHC compression: " << *packet);
2274 uint32_t ret [[maybe_unused]] = packet->RemoveHeader(encoding);
2275 NS_LOG_DEBUG(
"removed " << ret <<
" bytes - pkt is " << *packet);
2306 if (encoding.
GetC())
2311 packet->AddHeader(udpHeader);
2317 packet->AddHeader(udpHeader);
2323 packet->AddHeader(udpHeader);
2326 NS_LOG_DEBUG(
"Rebuilt packet: " << *packet <<
" Size " << packet->GetSize());
2340 uint16_t offsetData = 0;
2341 uint16_t offset = 0;
2355 "6LoWPAN: can not fragment, 6LoWPAN headers are bigger than MTU");
2358 size = l2Mtu - frag1Hdr.
GetSerializedSize() - compressedHeaderSize - extraHdrSize;
2360 size += compressedHeaderSize;
2364 Ptr<Packet> fragment1 = p->CreateFragment(offsetData, size);
2365 offset += size + origHdrSize - compressedHeaderSize;
2368 fragment1->AddHeader(frag1Hdr);
2369 listFragments.push_back(fragment1);
2371 bool moreFrag =
true;
2390 NS_LOG_LOGIC(
"Fragment creation - " << offset <<
", " << offset);
2391 Ptr<Packet> fragment = p->CreateFragment(offsetData, size);
2392 NS_LOG_LOGIC(
"Fragment created - " << offset <<
", " << fragment->GetSize());
2397 fragment->AddHeader(fragNHdr);
2398 listFragments.push_back(fragment);
2414 key.first = std::pair<Address, Address>(src, dst);
2417 uint16_t offset = 0;
2431 uint8_t dispatchRawValFrag1 = 0;
2434 p->RemoveHeader(frag1Header);
2436 p->CopyData(&dispatchRawValFrag1,
sizeof(dispatchRawValFrag1));
2438 NS_LOG_DEBUG(
"Dispatches: " <<
int(dispatchRawValFrag1) <<
" - " <<
int(dispatchValFrag1));
2441 switch (dispatchValFrag1)
2445 p->RemoveHeader(uncompressedHdr);
2463 key.second = std::pair<uint16_t, uint16_t>(frag1Header.
GetDatagramSize(),
2468 p->RemoveHeader(fragNHeader);
2471 key.second = std::pair<uint16_t, uint16_t>(fragNHeader.
GetDatagramSize(),
2477 MapFragments_t::iterator it =
m_fragments.find(key);
2486 std::list<Ptr<Packet>> storedFragments =
m_fragments[oldestKey]->GetFragments();
2487 for (std::list<
Ptr<Packet>>::iterator fragIter = storedFragments.begin();
2488 fragIter != storedFragments.end();
2498 fragments = Create<Fragments>();
2500 m_fragments.insert(std::make_pair(key, fragments));
2504 fragments->SetTimeoutIter(iter);
2508 fragments = it->second;
2511 fragments->AddFragment(p, offset);
2517 fragments->AddFirstFragment(packet);
2520 if (fragments->IsEntire())
2522 packet = fragments->GetPacket();
2526 packet->RemoveHeader(frag1Header);
2528 NS_LOG_LOGIC(
"Rebuilt packet. Size " << packet->GetSize() <<
" - " << *packet);
2530 fragments =
nullptr;
2554 std::list<std::pair<Ptr<Packet>, uint16_t>>::iterator it;
2555 bool duplicate =
false;
2559 if (it->second > fragmentOffset)
2563 if (it->second == fragmentOffset)
2567 "Duplicate fragment size differs. Aborting.");
2573 m_fragments.insert(it, std::make_pair(fragment, fragmentOffset));
2582 m_firstFragment = fragment;
2591 uint16_t lastEndOffset = 0;
2600 NS_LOG_LOGIC(
"Checking overlaps " << lastEndOffset <<
" - " << it->second);
2602 if (lastEndOffset < it->
second)
2608 uint16_t fragmentEnd = it->first->GetSize() + it->second;
2609 lastEndOffset = std::max(lastEndOffset, fragmentEnd);
2613 return ret && lastEndOffset == m_packetSize;
2621 std::list<std::pair<Ptr<Packet>, uint16_t>>::const_iterator it =
m_fragments.begin();
2624 uint16_t lastEndOffset = 0;
2626 p->AddAtEnd(m_firstFragment);
2628 lastEndOffset = it->first->GetSize();
2632 if (lastEndOffset > it->second)
2634 NS_ABORT_MSG(
"Overlapping fragments found, forbidden condition");
2639 p->AddAtEnd(it->first);
2641 lastEndOffset += it->first->GetSize();
2654std::list<Ptr<Packet>>
2657 std::list<Ptr<Packet>> fragments;
2658 std::list<std::pair<Ptr<Packet>, uint16_t>>::const_iterator iter;
2661 fragments.push_back(iter->first);
2669 m_timeoutIter = iter;
2675 return m_timeoutIter;
2683 MapFragments_t::iterator it =
m_fragments.find(key);
2684 std::list<Ptr<Packet>> storedFragments = it->second->GetFragments();
2685 for (std::list<
Ptr<Packet>>::iterator fragIter = storedFragments.begin();
2686 fragIter != storedFragments.end();
2692 it->second =
nullptr;
2751 bool compressionAllowed,
2755 << contextPrefix << compressionAllowed << validLifetime.
As(
Time::S));
2759 NS_LOG_LOGIC(
"Invalid context ID (" << +contextId <<
"), ignoring");
2763 if (validLifetime ==
Time(0))
2765 NS_LOG_LOGIC(
"Context (" << +contextId <<
"), removed (validity time is zero)");
2771 m_contextTable[contextId].compressionAllowed = compressionAllowed;
2778 bool& compressionAllowed,
2779 Time& validLifetime)
2785 NS_LOG_LOGIC(
"Invalid context ID (" << +contextId <<
"), ignoring");
2791 NS_LOG_LOGIC(
"Context not found (" << +contextId <<
"), ignoring");
2796 compressionAllowed =
m_contextTable[contextId].compressionAllowed;
2809 NS_LOG_LOGIC(
"Invalid context ID (" << +contextId <<
"), ignoring");
2815 NS_LOG_LOGIC(
"Context not found (" << +contextId <<
"), ignoring");
2829 NS_LOG_LOGIC(
"Invalid context ID (" << +contextId <<
"), ignoring");
2835 NS_LOG_LOGIC(
"Context not found (" << +contextId <<
"), ignoring");
2848 NS_LOG_LOGIC(
"Invalid context ID (" << +contextId <<
"), ignoring");
2854 NS_LOG_LOGIC(
"Context not found (" << +contextId <<
"), ignoring");
2875 << +contextId <<
" "
2879 contextId = iter.first;
2903 if (contextLength <= 64)
2905 uint8_t contextBytes[16];
2906 uint8_t addressBytes[16];
2909 address.GetBytes(addressBytes);
2911 if (addressBytes[3] == contextLength && addressBytes[4] == contextBytes[0] &&
2912 addressBytes[5] == contextBytes[1] && addressBytes[6] == contextBytes[2] &&
2913 addressBytes[7] == contextBytes[3] && addressBytes[8] == contextBytes[4] &&
2914 addressBytes[9] == contextBytes[5] && addressBytes[10] == contextBytes[6] &&
2915 addressBytes[11] == contextBytes[7])
2918 << +contextId <<
" "
2922 contextId = iter.first;
2934 uint8_t addressBytes[16];
2935 address.GetBytes(addressBytes);
2938 uint8_t bytesToClean = prefixLength / 8;
2939 uint8_t bitsToClean = prefixLength % 8;
2940 for (uint8_t i = 0; i < bytesToClean; i++)
2942 addressBytes[i] = 0;
2946 uint8_t cleanupMask = (1 << bitsToClean) - 1;
2947 addressBytes[bytesToClean] &= cleanupMask;
2952 return cleanedAddress;
a polymophic address class
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
AttributeValue implementation for Boolean.
void Write(const uint8_t *buffer, uint32_t size)
automatically resized byte buffer
void AddAtStart(uint32_t start)
Buffer::Iterator Begin() const
void RemoveAtStart(uint32_t start)
const uint8_t * PeekData() const
bool IsNull() const
Check for null implementation.
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
bool IsRunning() const
This method is syntactic sugar for !IsExpired().
Ipv4 addresses are stored in host order in this class.
Describes an IPv6 address.
bool IsLinkLocal() const
If the IPv6 address is a link-local address (fe80::/64).
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
static Ipv6Address Deserialize(const uint8_t buf[16])
Deserialize this address.
static Ipv6Address MakeAutoconfiguredAddress(Address addr, Ipv6Address prefix)
Make the autoconfigured IPv6 address from a Mac address.
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the address.
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.
static Ipv6Address GetOnes()
Get the "all-1" IPv6 address (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff).
static Ipv6Address MakeAutoconfiguredLinkLocalAddress(Address mac)
Make the autoconfigured link-local IPv6 address from a Mac address.
static const uint16_t PROT_NUMBER
The protocol number for IPv6 (0x86DD).
Describes an IPv6 prefix.
uint8_t GetPrefixLength() const
Get prefix length.
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the prefix.
This class can contain 16 bit addresses.
static bool IsMatchingType(const Address &address)
static Mac16Address ConvertFrom(const Address &address)
void CopyFrom(const uint8_t buffer[2])
bool IsMulticast() const
Checks if the address is a multicast address according to RFC 4944 Section 9 (i.e....
bool IsBroadcast() const
Checks if the address is a broadcast address according to 802.15.4 scheme (i.e., 0xFFFF).
static bool IsMatchingType(const Address &address)
Network layer to device interface.
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)=0
PacketType
Packet types are used as they are in Linux.
static bool ChecksumEnabled()
void RegisterProtocolHandler(ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device, bool promiscuous=false)
virtual void DoDispose()
Destructor implementation.
Smart pointer class similar to boost::intrusive_ptr.
virtual double GetValue()=0
Get the next random value drawn from the distribution.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now()
Return the current simulation virtual time.
6LoWPAN BC0 header - see RFC 4944.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
void SetSequenceNumber(uint8_t seqNumber)
Set the "Sequence Number" field.
uint8_t GetSequenceNumber() const
Get the "Sequence Number" field.
static Dispatch_e GetDispatchType(uint8_t dispatch)
Get the Dispatch type.
static NhcDispatch_e GetNhcDispatchType(uint8_t dispatch)
Get the NhcDispatch type.
NhcDispatch_e
Dispatch values for Next Header compression.
6LoWPAN FRAG1 header - see RFC 4944.
void SetDatagramSize(uint16_t datagramSize)
Set the datagram size.
void SetDatagramTag(uint16_t datagramTag)
Set the datagram tag.
uint16_t GetDatagramSize() const
Get the datagram size.
uint16_t GetDatagramTag() const
Get the datagram tag.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
6LoWPAN FRAGN header - see RFC 4944.
void SetDatagramSize(uint16_t datagramSize)
Set the datagram size.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
uint16_t GetDatagramTag() const
Get the datagram tag.
void SetDatagramTag(uint16_t datagramTag)
Set the datagram tag.
void SetDatagramOffset(uint8_t datagramOffset)
Set the datagram offset.
uint8_t GetDatagramOffset() const
Get the datagram offset.
uint16_t GetDatagramSize() const
Get the datagram size.
6LoWPAN HC1 header - see RFC 4944.
void SetTcflCompression(bool tcflCompression)
Set the Traffic Class and Flow Labels as compressed.
uint8_t GetHopLimit() const
Get the "Hop limit" field (TTL).
const uint8_t * GetSrcPrefix() const
Get the source prefix.
void SetFlowLabel(uint32_t flowLabel)
Set the Flow Label value.
uint8_t GetTrafficClass() const
Get the Traffic Class value.
void SetDstCompression(LowPanHc1Addr_e dstCompression)
Set Destination Compression type.
void SetTrafficClass(uint8_t trafficClass)
Set the Traffic Class value.
void SetHopLimit(uint8_t limit)
Set the "Hop limit" field (TTL).
uint32_t GetFlowLabel() const
Get the Flow Label value.
const uint8_t * GetDstPrefix() const
Get the destination prefix.
void SetHc2HeaderPresent(bool hc2HeaderPresent)
Set the next header a HC2 compressed header.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
void SetNextHeader(uint8_t nextHeader)
Set the Next Header value.
void SetSrcCompression(LowPanHc1Addr_e srcCompression)
Set Source Compression type.
void SetDstInterface(const uint8_t *dstInterface)
Set the destination interface.
void SetDstPrefix(const uint8_t *dstPrefix)
Set the destination prefix.
void SetSrcPrefix(const uint8_t *srcPrefix)
Set the source prefix.
uint8_t GetNextHeader() const
Get the Next Header value.
void SetSrcInterface(const uint8_t *srcInterface)
Set the source interface.
LowPanHc1Addr_e GetDstCompression() const
Get Destination Compression type.
bool IsHc2HeaderPresent() const
Check if there is a HC2 compressed header.
LowPanHc1Addr_e GetSrcCompression() const
Get Source Compression type.
bool IsTcflCompression() const
Check if the Traffic Class and Flow Labels are compressed.
LOWPAN_IPHC base Encoding - see RFC 6282.
bool GetSac() const
Get the SAC (Source Address Compression) compression.
void SetNextHeader(uint8_t nextHeader)
Set the Next Header field.
uint8_t GetNextHeader() const
Get the Next Header field.
void SetHlim(Hlim_e hlimField)
Set the HLIM (Hop Limit) compression.
void SetDstContextId(uint8_t dstContextId)
Set the DstContextId.
const uint8_t * GetSrcInlinePart() const
brief Get the source address inline part
void SetSam(HeaderCompression_e samField)
Set the SAM (Source Address Mode) compression.
void SetNh(bool nhField)
Set the NH (Next Header) compression.
uint8_t GetDscp() const
Get the DSCP.
HeaderCompression_e GetDam() const
Get the DAM (Destination Address Mode) compression.
uint8_t GetHopLimit() const
Get the Hop Limit field.
bool GetDac() const
Get the DAC (Destination Address Compression) compression.
void SetEcn(uint8_t ecn)
Set the ECN (2bits).
void SetFlowLabel(uint32_t flowLabel)
Set the Flow Label (20bits).
void SetDscp(uint8_t dscp)
Set the DSCP (6bits).
uint32_t GetFlowLabel() const
Get the Flow Label.
void SetTf(TrafficClassFlowLabel_e tfField)
Set the TF (Traffic Class, Flow Label) compression.
uint8_t GetEcn() const
Get the ECN.
void SetDam(HeaderCompression_e damField)
Set the DAM (Destination Address Mode) compression.
void SetCid(bool cidField)
Set the CID (Context Identifier Extension) compression.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
void SetSac(bool sacField)
Set the SAC (Source Address Compression) compression.
bool GetNh() const
Get the NH (Next Header) compression.
TrafficClassFlowLabel_e GetTf() const
Get the TF (Traffic Class, Flow Label) compression.
bool GetM() const
Get the M (Multicast) compression.
HeaderCompression_e GetSam() const
Get the SAM (Source Address Mode) compression.
void SetDstInlinePart(uint8_t dstInlinePart[16], uint8_t size)
brief Set the destination address inline part
void SetSrcContextId(uint8_t srcContextId)
Set the SrcContextId.
void SetSrcInlinePart(uint8_t srcInlinePart[16], uint8_t size)
brief Set the source address inline part
void SetM(bool mField)
Set the M (Multicast) compression.
const uint8_t * GetDstInlinePart() const
brief Get the destination address inline part
uint8_t GetSrcContextId() const
Get the SrcContextId.
void SetHopLimit(uint8_t hopLimit)
Set the Hop Limit field.
uint8_t GetDstContextId() const
Get the DstContextId.
void SetDac(bool dacField)
Set the DAC (Destination Address Compression) compression.
6LoWPAN IPv6 uncompressed header - see RFC 4944.
6LoWPAN Mesh header - see RFC 4944.
Address GetOriginator() const
Get the "Originator" address.
void SetHopsLeft(uint8_t hopsLeft)
Set the "Hops Left" field.
void SetFinalDst(Address finalDst)
Set the "Final Destination" address.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
uint8_t GetHopsLeft() const
Get the "Hops Left" field.
Address GetFinalDst() const
Get the "Final Destination" address.
void SetOriginator(Address originator)
Set the "Originator" address.
void SetTimeoutIter(FragmentsTimeoutsListI_t iter)
Set the Timeout iterator.
bool IsEntire() const
If all fragments have been added.
std::list< Ptr< Packet > > GetFragments() const
Get a list of the current stored fragments.
void SetPacketSize(uint32_t packetSize)
Set the packet-to-be-defragmented size.
void AddFragment(Ptr< Packet > fragment, uint16_t fragmentOffset)
Add a fragment to the pool.
uint32_t m_packetSize
The size of the reconstructed packet (bytes).
FragmentsTimeoutsListI_t GetTimeoutIter()
Get the Timeout iterator.
Ptr< Packet > GetPacket() const
Get the entire packet.
void AddFirstFragment(Ptr< Packet > fragment)
Add the first packet fragment.
Shim performing 6LoWPAN compression, decompression and fragmentation.
bool IsLinkUp() const override
std::map< FragmentKey_t, Ptr< Fragments > >::iterator MapFragmentsI_t
Container Iterator for fragment key -> fragments.
bool SetMtu(const uint16_t mtu) override
void DecompressLowPanUdpNhc(Ptr< Packet > packet, Ipv6Address saddr, Ipv6Address daddr)
Decompress the headers according to NHC compression.
bool DoSend(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber, bool doSendFrom)
Ipv6Address CleanPrefix(Ipv6Address address, Ipv6Prefix prefix)
Clean an address from its prefix.
uint8_t m_bc0Serial
Serial number used in BC0 header.
bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber) override
void SetNode(Ptr< Node > node) override
bool NeedsArp() const override
EventId m_timeoutEvent
Event for the next scheduled timeout.
FragmentsTimeoutsListI_t SetTimeout(FragmentKey_t key, uint32_t iif)
Set a new timeout "event" for a fragmented packet.
Ptr< UniformRandomVariable > m_rng
Rng for the fragments tag.
uint16_t m_meshCacheLength
length of the cache for each source.
bool IsPointToPoint() const override
Return true if the net device is on a point-to-point link.
bool m_useIphc
Use IPHC or HC1.
void RenewContext(uint8_t contextId, Time validLifetime)
Renew a context used in IPHC stateful compression.
bool DecompressLowPanIphc(Ptr< Packet > packet, const Address &src, const Address &dst)
Decompress the headers according to IPHC compression.
uint32_t CompressLowPanHc1(Ptr< Packet > packet, const Address &src, const Address &dst)
Compress the headers according to HC1 compression.
bool IsBridge() const override
Return true if the net device is acting as a bridge.
void DoFragmentation(Ptr< Packet > packet, uint32_t origPacketSize, uint32_t origHdrSize, uint32_t extraHdrSize, std::list< Ptr< Packet > > &listFragments)
Performs a packet fragmentation.
Ptr< Node > m_node
Smart pointer to the Node.
bool CanCompressLowPanNhc(uint8_t headerType)
Checks if the next header can be compressed using NHC.
Ptr< Channel > GetChannel() const override
uint16_t GetMtu() const override
Returns the link-layer MTU for this interface.
std::list< std::tuple< Time, FragmentKey_t, uint32_t > >::iterator FragmentsTimeoutsListI_t
Container Iterator for fragment timeouts.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
bool m_forceEtherType
Force the EtherType number.
Address GetAddress() const override
void SetReceiveCallback(NetDevice::ReceiveCallback cb) override
uint32_t m_compressionThreshold
Minimum L2 payload size.
Ptr< NetDevice > GetNetDevice() const
Returns a smart pointer to the underlying NetDevice.
void HandleTimeout()
Handles a fragmented packet timeout.
void ReceiveFromDevice(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, const Address &source, const Address &destination, PacketType packetType)
Receives all the packets from a NetDevice for further processing.
uint32_t CompressLowPanNhc(Ptr< Packet > packet, uint8_t headerType, const Address &src, const Address &dst)
Compress the headers according to NHC compression.
TracedCallback< Ptr< const Packet >, Ptr< SixLowPanNetDevice >, uint32_t > m_txTrace
Callback to trace TX (transmission) packets.
std::pair< std::pair< Address, Address >, std::pair< uint16_t, uint16_t > > FragmentKey_t
Fragment identifier type: src/dst address src/dst port.
@ DROP_DISALLOWED_COMPRESSION
HC1 while in IPHC mode or vice-versa.
@ DROP_UNKNOWN_EXTENSION
Unsupported compression kind.
@ DROP_FRAGMENT_BUFFER_FULL
Fragment buffer size exceeded.
@ DROP_SATETFUL_DECOMPRESSION_PROBLEM
Decompression failed due to missing or expired context.
@ DROP_FRAGMENT_TIMEOUT
Fragment timeout exceeded.
void AddContext(uint8_t contextId, Ipv6Prefix contextPrefix, bool compressionAllowed, Time validLifetime)
Add, remove, or update a context used in IPHC stateful compression.
Ptr< NetDevice > m_netDevice
Smart pointer to the underlying NetDevice.
void SetNetDevice(Ptr< NetDevice > device)
Setup SixLowPan to be a proxy for the specified NetDevice.
std::map< uint8_t, ContextEntry > m_contextTable
Table of the contexts used in compression/decompression.
TracedCallback< Ptr< const Packet >, Ptr< SixLowPanNetDevice >, uint32_t > m_rxTrace
Callback to trace RX (reception) packets.
bool GetContext(uint8_t contextId, Ipv6Prefix &contextPrefix, bool &compressionAllowed, Time &validLifetime)
Get a context used in IPHC stateful compression.
uint32_t GetIfIndex() const override
bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber) override
bool IsBroadcast() const override
Address Get16MacFrom48Mac(Address addr)
Get a Mac16 from its Mac48 pseudo-MAC.
TracedCallback< DropReason, Ptr< const Packet >, Ptr< SixLowPanNetDevice >, uint32_t > m_dropTrace
Callback to trace drop packets.
void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb) override
bool FindUnicastCompressionContext(Ipv6Address address, uint8_t &contextId)
Finds if the given unicast address matches a context for compression.
Ptr< RandomVariableStream > m_meshUnderJitter
Random variable for the mesh-under packet retransmission.
uint32_t CompressLowPanUdpNhc(Ptr< Packet > packet, bool omitChecksum)
Compress the headers according to NHC compression.
void RemoveContext(uint8_t contextId)
Remove a context used in IPHC stateful compression.
bool m_omitUdpChecksum
Omit UDP checksum in NC1 encoding.
Ptr< Node > GetNode() const override
void AddLinkChangeCallback(Callback< void > callback) override
uint32_t m_ifIndex
Interface index.
Address GetBroadcast() const override
void SetIfIndex(const uint32_t index) override
uint32_t CompressLowPanIphc(Ptr< Packet > packet, const Address &src, const Address &dst)
Compress the headers according to IPHC compression.
void DoDispose() override
Destructor implementation.
bool IsMulticast() const override
Address GetMulticast(Ipv4Address multicastGroup) const override
Make and return a MAC multicast address using the provided multicast group.
Time m_fragmentExpirationTimeout
Time limit for fragment rebuilding.
uint16_t m_fragmentReassemblyListSize
How many packets can be rebuilt at the same time.
uint8_t m_meshUnderHopsLeft
Start value for mesh-under hops left.
void SetAddress(Address address) override
Set the address of this interface.
void DecompressLowPanHc1(Ptr< Packet > packet, const Address &src, const Address &dst)
Decompress the headers according to HC1 compression.
FragmentsTimeoutsList_t m_timeoutEventList
Timeout "events" container.
std::pair< uint8_t, bool > DecompressLowPanNhc(Ptr< Packet > packet, const Address &src, const Address &dst, Ipv6Address srcAddress, Ipv6Address dstAddress)
Decompress the headers according to NHC compression.
NetDevice::PromiscReceiveCallback m_promiscRxCallback
The callback used to notify higher layers that a packet has been received in promiscuous mode.
void HandleFragmentsTimeout(FragmentKey_t key, uint32_t iif)
Process the timeout for packet fragments.
void InvalidateContext(uint8_t contextId)
Invalidate a context used in IPHC stateful compression.
static TypeId GetTypeId()
Get the type ID.
bool SupportsSendFrom() const override
NetDevice::ReceiveCallback m_rxCallback
The callback used to notify higher layers that a packet has been received.
bool ProcessFragment(Ptr< Packet > &packet, const Address &src, const Address &dst, bool isFirst)
Process a packet fragment.
MapFragments_t m_fragments
Fragments hold to be rebuilt.
bool FindMulticastCompressionContext(Ipv6Address address, uint8_t &contextId)
Finds if the given multicast address matches a context for compression.
bool m_meshUnder
Use a mesh-under routing.
std::map< Address, std::list< uint8_t > > m_seenPkts
Seen packets, memorized by OriginatorAddress, SequenceNumber.
SixLowPanNetDevice()
Constructor for the SixLowPanNetDevice.
uint16_t m_etherType
EtherType number (used only if m_forceEtherType is true).
LOWPAN_NHC Extension Header Encoding - see RFC 6282.
bool GetNh() const
Get the Next Header field value.
Eid_e GetEid() const
Get the Extension Header Type.
void SetNh(bool nhField)
Set the NH field values.
void SetEid(Eid_e extensionHeaderType)
Set the Extension Header Type.
void SetBlob(const uint8_t *blob, uint32_t size)
Set the option header data blob.
@ EID_DESTINATION_OPTIONS_H
uint32_t CopyBlob(uint8_t *blob, uint32_t size) const
Get the option header data blob.
uint8_t GetNextHeader() const
Get the Next Header field value.
void SetNextHeader(uint8_t nextHeader)
Set the Next Header field values.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
UDP LOWPAN_NHC Extension Header Encoding - see RFC 6282.
Ports_e GetPorts() const
Get the compressed Src and Dst Ports.
uint16_t GetChecksum() const
Get the Checksum field value.
uint16_t GetDstPort() const
Get the Destination Port.
@ PORTS_LAST_SRC_LAST_DST
void SetPorts(Ports_e port)
Set the compressed Src and Dst Ports.
bool GetC() const
Get the C (Checksum).
void SetChecksum(uint16_t checksum)
Set the Checksum field values.
void SetDstPort(uint16_t port)
Set the Destination Port.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
void SetSrcPort(uint16_t port)
Set the Source Port.
void SetC(bool cField)
Set the C (Checksum).
uint16_t GetSrcPort() const
Get the Source Port.
Hold variables of type string.
Simulation virtual time values and global simulation resolution.
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
AttributeValue implementation for Time.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
static const uint8_t PROT_NUMBER
protocol number (0x11)
Hold an unsigned integer type.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Structure holding the information for a context (used in compression and decompression)
Ipv6Prefix contextPrefix
context prefix to be used in compression/decompression
bool compressionAllowed
compression and decompression allowed (true), decompression only (false)
Time validLifetime
validity period
uint32_t pktSize
packet size used for the simulation (in bytes)
static const uint32_t packetSize
Packet size generated at the AP.