15#include "ns3/boolean.h"
16#include "ns3/channel.h"
17#include "ns3/ipv6-extension-header.h"
18#include "ns3/ipv6-l3-protocol.h"
20#include "ns3/mac16-address.h"
21#include "ns3/mac48-address.h"
22#include "ns3/mac64-address.h"
24#include "ns3/packet.h"
25#include "ns3/pointer.h"
26#include "ns3/simulator.h"
27#include "ns3/string.h"
28#include "ns3/udp-header.h"
29#include "ns3/udp-l4-protocol.h"
30#include "ns3/uinteger.h"
45 TypeId(
"ns3::SixLowPanNetDevice")
47 .SetGroupName(
"SixLowPan")
49 .AddAttribute(
"Rfc6282",
50 "Use RFC6282 (IPHC) if true, RFC4944 (HC1) otherwise.",
54 .AddAttribute(
"OmitUdpChecksum",
55 "Omit the UDP checksum in IPHC compression.",
60 "FragmentReassemblyListSize",
61 "The maximum size of the reassembly buffer (in packets). Zero meaning infinite.",
66 "FragmentExpirationTimeout",
67 "When this timeout expires, the fragments will be cleared from the buffer.",
71 .AddAttribute(
"CompressionThreshold",
72 "The minimum MAC layer payload size.",
76 .AddAttribute(
"UseMeshUnder",
77 "Use a mesh-under routing protocol.",
81 .AddAttribute(
"MeshUnderRadius",
82 "Hops Left to use in mesh-under.",
86 .AddAttribute(
"MeshCacheLength",
87 "Length of the cache for each source.",
91 .AddAttribute(
"MeshUnderJitter",
92 "The jitter in ms a node uses to forward mesh-under packets - used to "
94 StringValue(
"ns3::UniformRandomVariable[Min=0.0|Max=10.0]"),
98 "Send - packet (including 6LoWPAN header), "
99 "SixLoWPanNetDevice Ptr, interface index.",
101 "ns3::SixLowPanNetDevice::RxTxTracedCallback")
102 .AddTraceSource(
"TxPre",
103 "Send - packet (including IPv6 header), "
104 "SixLoWPanNetDevice Ptr, interface index.",
106 "ns3::SixLowPanNetDevice::RxTxTracedCallback")
107 .AddTraceSource(
"Rx",
108 "Receive - packet (including 6LoWPAN header), "
109 "SixLoWPanNetDevice Ptr, interface index.",
111 "ns3::SixLowPanNetDevice::RxTxTracedCallback")
112 .AddTraceSource(
"RxPost",
113 "Receive - packet (including IPv6 header), "
114 "SixLoWPanNetDevice Ptr, interface index.",
116 "ns3::SixLowPanNetDevice::RxTxTracedCallback")
117 .AddTraceSource(
"Drop",
118 "Drop - DropReason, packet (including 6LoWPAN header), "
119 "SixLoWPanNetDevice Ptr, interface index.",
121 "ns3::SixLowPanNetDevice::DropTracedCallback");
149 NS_LOG_DEBUG(
"RegisterProtocolHandler for " << device->GetInstanceTypeId().GetName());
152 if (device->GetInstanceTypeId().GetName().find(
"LrWpanNetDevice") != std::string::npos)
169 m_rng->SetStream(stream);
190 iter->second =
nullptr;
205 NS_LOG_FUNCTION(
this << incomingPort << packet << protocol << src << dst);
207 uint8_t dispatchRawVal = 0;
213 copyPkt->CopyData(&dispatchRawVal,
sizeof(dispatchRawVal));
215 bool isPktDecompressed =
false;
216 bool fragmented =
false;
220 NS_LOG_DEBUG(
"Dispatches: " <<
int(dispatchRawVal) <<
" - " <<
int(dispatchVal));
224 bool hasMesh =
false;
230 copyPkt->RemoveHeader(meshHdr);
231 copyPkt->CopyData(&dispatchRawVal,
sizeof(dispatchRawVal));
237 copyPkt->RemoveHeader(bc0Hdr);
238 copyPkt->CopyData(&dispatchRawVal,
sizeof(dispatchRawVal));
246 NS_LOG_LOGIC(
"Dropped packet - we only support mesh if it is paired with a BC0");
255 NS_LOG_LOGIC(
"We have already seen this, no further processing.");
266 "SixLowPan mesh-under flooding can not currently handle extended address "
267 "final destinations: "
270 "SixLowPan mesh-under flooding can not currently handle devices using "
271 "extended addresses: "
284 NS_LOG_LOGIC(
"Not forwarding packet -- hop limit reached");
288 NS_LOG_LOGIC(
"Not forwarding packet -- I am the originator");
294 sendPkt->AddHeader(bc0Hdr);
295 sendPkt->AddHeader(meshHdr);
331 if (!isPktDecompressed)
337 copyPkt->CopyData(&dispatchRawVal,
sizeof(dispatchRawVal));
345 NS_LOG_DEBUG(
"Packet without compression. Length: " << copyPkt->GetSize());
348 copyPkt->RemoveHeader(uncompressedHdr);
349 isPktDecompressed =
true;
359 isPktDecompressed =
true;
373 isPktDecompressed =
true;
377 NS_LOG_DEBUG(
"Unsupported 6LoWPAN encoding: dropping.");
382 if (!isPktDecompressed)
387 NS_LOG_DEBUG(
"Packet decompressed length: " << copyPkt->GetSize());
388 NS_LOG_DEBUG(
"Packet decompressed received: " << *copyPkt);
484 return m_netDevice->AddLinkChangeCallback(callback);
557 ret =
DoSend(packet, src, dest, protocolNumber,
false);
565 uint16_t protocolNumber)
570 ret =
DoSend(packet, src, dest, protocolNumber,
true);
578 uint16_t protocolNumber,
581 NS_LOG_FUNCTION(
this << *packet << src << dest << protocolNumber << doSendFrom);
588 uint32_t origPacketSize = packet->GetSize();
608 uint16_t pktSize = packet->GetSize();
639 pktSize += extraHdrSize;
644 NS_LOG_LOGIC(
"Compressed packet too short, using uncompressed one");
647 packet->AddHeader(ipv6UncompressedHdr);
648 pktSize = packet->GetSize();
657 NS_LOG_LOGIC(
"Fragmentation: Packet size " << packet->GetSize() <<
" - Mtu "
660 std::list<Ptr<Packet>> fragmentList;
661 DoFragmentation(packet, origPacketSize, origHdrSize, extraHdrSize, fragmentList);
663 for (
auto it = fragmentList.begin(); it != fragmentList.end(); it++)
665 NS_LOG_DEBUG(
"SixLowPanNetDevice::Send (Fragment) " << **it);
671 (*it)->AddHeader(bc0Hdr);
672 (*it)->AddHeader(meshHdr);
676 success &=
m_netDevice->SendFrom(*it, src, destination, protocolNumber);
680 success &=
m_netDevice->Send(*it, destination, protocolNumber);
692 packet->AddHeader(bc0Hdr);
693 packet->AddHeader(meshHdr);
699 ret =
m_netDevice->SendFrom(packet, src, destination, protocolNumber);
704 ret =
m_netDevice->Send(packet, destination, protocolNumber);
764 NS_LOG_DEBUG(
"Original packet: " << *packet <<
" Size " << packet->GetSize());
766 if (packet->PeekHeader(ipHeader) != 0)
768 packet->RemoveHeader(ipHeader);
779 NS_LOG_LOGIC(
"Checking source compression: " << mySrcAddr <<
" - " << srcAddr);
782 bool isSrcSrc = (memcmp(bufOne + 8, bufTwo + 8, 8) == 0);
809 NS_LOG_LOGIC(
"Checking destination compression: " << myDstAddr <<
" - " << dstAddr);
812 bool isDstDst = (memcmp(bufOne + 8, bufTwo + 8, 8) == 0);
853 NS_LOG_DEBUG(
"HC1 Compression - packet size = " << packet->GetSize());
855 packet->AddHeader(hc1Header);
871 uint32_t ret [[maybe_unused]] = packet->RemoveHeader(encoding);
872 NS_LOG_DEBUG(
"removed " << ret <<
" bytes - pkt is " << *packet);
876 switch (encoding.GetSrcCompression())
878 const uint8_t* interface;
879 const uint8_t* prefix;
883 prefix = encoding.GetSrcPrefix();
884 interface = encoding.GetSrcInterface();
885 for (
int j = 0; j < 8; j++)
887 address[j + 8] = interface[j];
888 address[j] = prefix[j];
893 prefix = encoding.GetSrcPrefix();
894 for (
int j = 0; j < 8; j++)
897 address[j] = prefix[j];
902 interface = encoding.GetSrcInterface();
905 for (
int j = 0; j < 8; j++)
907 address[j + 8] = interface[j];
916 switch (encoding.GetDstCompression())
918 const uint8_t* interface;
919 const uint8_t* prefix;
923 prefix = encoding.GetDstPrefix();
924 interface = encoding.GetDstInterface();
925 for (
int j = 0; j < 8; j++)
927 address[j + 8] = interface[j];
928 address[j] = prefix[j];
933 prefix = encoding.GetDstPrefix();
934 for (
int j = 0; j < 8; j++)
937 address[j] = prefix[j];
942 interface = encoding.GetDstInterface();
945 for (
int j = 0; j < 8; j++)
947 address[j + 8] = interface[j];
956 if (!encoding.IsTcflCompression())
972 encoding.IsHc2HeaderPresent() ==
false,
973 "6LoWPAN: error in decompressing HC1 encoding, unsupported L4 compressed header present.");
975 packet->AddHeader(ipHeader);
977 NS_LOG_DEBUG(
"Rebuilt packet: " << *packet <<
" Size " << packet->GetSize());
989 NS_LOG_DEBUG(
"Original packet: " << *packet <<
" Size " << packet->GetSize() <<
" src: " << src
992 if (packet->PeekHeader(ipHeader) != 0)
994 packet->RemoveHeader(ipHeader);
1029 iphcHeader.
SetNh(
true);
1034 iphcHeader.
SetNh(
true);
1043 iphcHeader.
SetNh(
true);
1048 iphcHeader.
SetNh(
false);
1055 iphcHeader.
SetNh(
false);
1080 iphcHeader.
SetCid(
false);
1081 iphcHeader.
SetSac(
false);
1082 iphcHeader.
SetDac(
false);
1084 auto checker =
Ipv6Address(
"fe80:0000:0000:0000:0000:00ff:fe00:1");
1085 uint8_t unicastAddrCheckerBuf[16];
1086 checker.GetBytes(unicastAddrCheckerBuf);
1087 uint8_t addressBuf[16];
1092 uint8_t srcContextId;
1105 NS_LOG_LOGIC(
"Checking stateful source compression: " << srcAddr);
1108 if (srcContextId != 0)
1128 uint8_t serializedCleanedAddress[16];
1129 cleanedAddr.
Serialize(serializedCleanedAddress);
1131 if (serializedCleanedAddress[8] == 0x00 &&
1132 serializedCleanedAddress[9] == 0x00 &&
1133 serializedCleanedAddress[10] == 0x00 &&
1134 serializedCleanedAddress[11] == 0xff &&
1135 serializedCleanedAddress[12] == 0xfe &&
1136 serializedCleanedAddress[13] == 0x00)
1151 NS_LOG_LOGIC(
"Checking stateless source compression: " << srcAddr);
1155 uint8_t serializedSrcAddress[16];
1156 srcAddr.
Serialize(serializedSrcAddress);
1162 else if (memcmp(addressBuf, unicastAddrCheckerBuf, 14) == 0)
1183 iphcHeader.
SetM(
true);
1187 iphcHeader.
SetM(
false);
1195 NS_LOG_LOGIC(
"Checking destination compression: " << dstAddr);
1197 uint8_t serializedDstAddress[16];
1198 dstAddr.
Serialize(serializedDstAddress);
1200 if (!iphcHeader.
GetM())
1204 uint8_t dstContextId;
1208 NS_LOG_LOGIC(
"Checking stateful destination compression: " << dstAddr);
1211 if (dstContextId != 0)
1231 uint8_t serializedCleanedAddress[16];
1232 cleanedAddr.
Serialize(serializedCleanedAddress);
1234 if (serializedCleanedAddress[8] == 0x00 &&
1235 serializedCleanedAddress[9] == 0x00 &&
1236 serializedCleanedAddress[10] == 0x00 &&
1237 serializedCleanedAddress[11] == 0xff &&
1238 serializedCleanedAddress[12] == 0xfe &&
1239 serializedCleanedAddress[13] == 0x00)
1253 NS_LOG_LOGIC(
"Checking stateless destination compression: " << dstAddr);
1259 else if (memcmp(addressBuf, unicastAddrCheckerBuf, 14) == 0)
1280 uint8_t dstContextId;
1286 uint8_t dstInlinePart[6] = {};
1287 dstInlinePart[0] = serializedDstAddress[1];
1288 dstInlinePart[1] = serializedDstAddress[2];
1289 dstInlinePart[2] = serializedDstAddress[12];
1290 dstInlinePart[3] = serializedDstAddress[13];
1291 dstInlinePart[4] = serializedDstAddress[14];
1292 dstInlinePart[5] = serializedDstAddress[15];
1295 if (dstContextId != 0)
1308 uint8_t multicastAddrCheckerBuf[16];
1309 auto multicastCheckAddress =
Ipv6Address(
"ff02::1");
1310 multicastCheckAddress.GetBytes(multicastAddrCheckerBuf);
1313 if (memcmp(addressBuf, multicastAddrCheckerBuf, 15) == 0)
1320 else if ((addressBuf[0] == multicastAddrCheckerBuf[0]) &&
1321 (memcmp(addressBuf + 2, multicastAddrCheckerBuf + 2, 11) == 0))
1323 uint8_t dstInlinePart[4] = {};
1324 memcpy(dstInlinePart, serializedDstAddress + 1, 1);
1325 memcpy(dstInlinePart + 1, serializedDstAddress + 13, 3);
1331 else if ((addressBuf[0] == multicastAddrCheckerBuf[0]) &&
1332 (memcmp(addressBuf + 2, multicastAddrCheckerBuf + 2, 9) == 0))
1334 uint8_t dstInlinePart[6] = {};
1335 memcpy(dstInlinePart, serializedDstAddress + 1, 1);
1336 memcpy(dstInlinePart + 1, serializedDstAddress + 11, 5);
1350 NS_LOG_DEBUG(
"IPHC Compression - packet size = " << packet->GetSize());
1352 packet->AddHeader(iphcHeader);
1354 NS_LOG_DEBUG(
"Packet after IPHC compression: " << *packet);
1390 uint32_t ret [[maybe_unused]] = packet->RemoveHeader(encoding);
1391 NS_LOG_DEBUG(
"removed " << ret <<
" bytes - pkt is " << *packet);
1397 if (encoding.GetSac())
1406 uint8_t contextId = encoding.GetSrcContextId();
1409 NS_LOG_LOGIC(
"Unknown Source compression context (" << +contextId
1410 <<
"), dropping packet");
1415 NS_LOG_LOGIC(
"Expired Source compression context (" << +contextId
1416 <<
"), dropping packet");
1420 uint8_t contextPrefix[16];
1422 uint8_t contextLength =
m_contextTable[contextId].contextPrefix.GetPrefixLength();
1424 uint8_t srcAddress[16] = {};
1427 memcpy(srcAddress + 8, encoding.GetSrcInlinePart(), 8);
1431 srcAddress[11] = 0xff;
1432 srcAddress[12] = 0xfe;
1433 memcpy(srcAddress + 14, encoding.GetSrcInlinePart(), 2);
1440 uint8_t bytesToCopy = contextLength / 8;
1441 uint8_t bitsToCopy = contextLength % 8;
1444 for (uint8_t i = 0; i < bytesToCopy; i++)
1446 srcAddress[i] = contextPrefix[i];
1450 uint8_t addressBitMask = (1 << (8 - bitsToCopy)) - 1;
1451 uint8_t prefixBitMask = ~addressBitMask;
1452 srcAddress[bytesToCopy] = (contextPrefix[bytesToCopy] & prefixBitMask) |
1453 (srcAddress[bytesToCopy] & addressBitMask);
1464 uint8_t srcAddress[16] = {};
1465 memcpy(srcAddress, encoding.GetSrcInlinePart(), 16);
1470 uint8_t srcAddress[16] = {};
1471 memcpy(srcAddress + 8, encoding.GetSrcInlinePart(), 8);
1472 srcAddress[0] = 0xfe;
1473 srcAddress[1] = 0x80;
1478 uint8_t srcAddress[16] = {};
1479 memcpy(srcAddress + 14, encoding.GetSrcInlinePart(), 2);
1480 srcAddress[0] = 0xfe;
1481 srcAddress[1] = 0x80;
1482 srcAddress[11] = 0xff;
1483 srcAddress[12] = 0xfe;
1492 if (encoding.GetDac())
1503 uint8_t contextId = encoding.GetDstContextId();
1506 NS_LOG_LOGIC(
"Unknown Destination compression context (" << +contextId
1507 <<
"), dropping packet");
1512 NS_LOG_LOGIC(
"Expired Destination compression context (" << +contextId
1513 <<
"), dropping packet");
1517 uint8_t contextPrefix[16];
1519 uint8_t contextLength =
m_contextTable[contextId].contextPrefix.GetPrefixLength();
1521 if (!encoding.GetM())
1524 uint8_t dstAddress[16] = {};
1527 memcpy(dstAddress + 8, encoding.GetDstInlinePart(), 8);
1531 dstAddress[11] = 0xff;
1532 dstAddress[12] = 0xfe;
1533 memcpy(dstAddress + 14, encoding.GetDstInlinePart(), 2);
1540 uint8_t bytesToCopy =
m_contextTable[contextId].contextPrefix.GetPrefixLength() / 8;
1541 uint8_t bitsToCopy = contextLength % 8;
1544 for (uint8_t i = 0; i < bytesToCopy; i++)
1546 dstAddress[i] = contextPrefix[i];
1550 uint8_t addressBitMask = (1 << (8 - bitsToCopy)) - 1;
1551 uint8_t prefixBitMask = ~addressBitMask;
1552 dstAddress[bytesToCopy] = (contextPrefix[bytesToCopy] & prefixBitMask) |
1553 (dstAddress[bytesToCopy] & addressBitMask);
1561 uint8_t dstAddress[16] = {};
1562 dstAddress[0] = 0xff;
1563 memcpy(dstAddress + 1, encoding.GetDstInlinePart(), 2);
1564 dstAddress[3] = contextLength;
1565 memcpy(dstAddress + 4, contextPrefix, 8);
1566 memcpy(dstAddress + 12, encoding.GetDstInlinePart() + 2, 4);
1573 if (!encoding.GetM())
1578 uint8_t dstAddress[16] = {};
1579 memcpy(dstAddress, encoding.GetDstInlinePart(), 16);
1584 uint8_t dstAddress[16] = {};
1585 memcpy(dstAddress + 8, encoding.GetDstInlinePart(), 8);
1586 dstAddress[0] = 0xfe;
1587 dstAddress[1] = 0x80;
1592 uint8_t dstAddress[16] = {};
1593 memcpy(dstAddress + 14, encoding.GetDstInlinePart(), 2);
1594 dstAddress[0] = 0xfe;
1595 dstAddress[1] = 0x80;
1596 dstAddress[11] = 0xff;
1597 dstAddress[12] = 0xfe;
1610 uint8_t dstAddress[16] = {};
1611 memcpy(dstAddress, encoding.GetDstInlinePart(), 16);
1616 uint8_t dstAddress[16] = {};
1617 dstAddress[0] = 0xff;
1618 memcpy(dstAddress + 1, encoding.GetDstInlinePart(), 1);
1619 memcpy(dstAddress + 11, encoding.GetDstInlinePart() + 1, 5);
1624 uint8_t dstAddress[16] = {};
1625 dstAddress[0] = 0xff;
1626 memcpy(dstAddress + 1, encoding.GetDstInlinePart(), 1);
1627 memcpy(dstAddress + 13, encoding.GetDstInlinePart() + 1, 3);
1632 uint8_t dstAddress[16] = {};
1633 dstAddress[0] = 0xff;
1634 dstAddress[1] = 0x02;
1635 memcpy(dstAddress + 15, encoding.GetDstInlinePart(), 1);
1642 uint8_t traf = 0x00;
1643 switch (encoding.GetTf())
1646 traf |= encoding.GetEcn();
1647 traf = (traf << 6) | encoding.GetDscp();
1649 ipHeader.
SetFlowLabel(encoding.GetFlowLabel() & 0xfff);
1652 traf |= encoding.GetEcn();
1658 traf |= encoding.GetEcn();
1659 traf = (traf << 6) | encoding.GetDscp();
1669 if (encoding.GetNh())
1672 uint8_t dispatchRawVal = 0;
1675 packet->CopyData(&dispatchRawVal,
sizeof(dispatchRawVal));
1707 packet->AddHeader(ipHeader);
1709 NS_LOG_DEBUG(
"Rebuilt packet: " << *packet <<
" Size " << packet->GetSize());
1729 packet->PeekHeader(hopHeader);
1733 "LOWPAN_NHC MUST NOT be used to encode IPv6 Extension Headers "
1734 "that have more than 255 octets following the Length field after compression. "
1735 "Packet uncompressed.");
1739 size += packet->RemoveHeader(hopHeader);
1748 nhcHeader.
SetNh(
true);
1753 nhcHeader.
SetNh(
true);
1762 nhcHeader.
SetNh(
true);
1767 nhcHeader.
SetNh(
false);
1774 nhcHeader.
SetNh(
false);
1788 packet->PeekHeader(routingHeader);
1792 "LOWPAN_NHC MUST NOT be used to encode IPv6 Extension Headers "
1793 "that have more than 255 octets following the Length field after compression. "
1794 "Packet uncompressed.");
1798 size += packet->RemoveHeader(routingHeader);
1807 nhcHeader.
SetNh(
true);
1812 nhcHeader.
SetNh(
true);
1821 nhcHeader.
SetNh(
true);
1826 nhcHeader.
SetNh(
false);
1833 nhcHeader.
SetNh(
false);
1847 packet->PeekHeader(fragHeader);
1851 "LOWPAN_NHC MUST NOT be used to encode IPv6 Extension Headers "
1852 "that have more than 255 octets following the Length field after compression. "
1853 "Packet uncompressed.");
1856 size += packet->RemoveHeader(fragHeader);
1865 nhcHeader.
SetNh(
true);
1870 nhcHeader.
SetNh(
true);
1879 nhcHeader.
SetNh(
true);
1884 nhcHeader.
SetNh(
false);
1891 nhcHeader.
SetNh(
false);
1905 packet->PeekHeader(destHeader);
1909 "LOWPAN_NHC MUST NOT be used to encode IPv6 Extension Headers "
1910 "that have more than 255 octets following the Length field after compression. "
1911 "Packet uncompressed.");
1914 size += packet->RemoveHeader(destHeader);
1923 nhcHeader.
SetNh(
true);
1928 nhcHeader.
SetNh(
true);
1937 nhcHeader.
SetNh(
true);
1942 nhcHeader.
SetNh(
false);
1949 nhcHeader.
SetNh(
false);
1963 NS_ABORT_MSG(
"IPv6 Mobility Header is not supported in ns-3 yet");
1972 NS_LOG_DEBUG(
"NHC Compression - packet size = " << packet->GetSize());
1974 packet->AddHeader(nhcHeader);
1976 NS_LOG_DEBUG(
"Packet after NHC compression: " << *packet);
1980std::pair<uint8_t, bool>
1991 uint32_t ret [[maybe_unused]] = packet->RemoveHeader(encoding);
1992 NS_LOG_DEBUG(
"removed " << ret <<
" bytes - pkt is " << *packet);
2000 uint8_t blobData[260];
2001 blobSize = encoding.CopyBlob(blobData + 2, 260 - 2);
2002 uint8_t paddingSize = 0;
2004 uint8_t actualEncodedHeaderType = encoding.GetEid();
2005 uint8_t actualHeaderType;
2008 switch (actualEncodedHeaderType)
2012 if (encoding.GetNh())
2015 uint8_t dispatchRawVal = 0;
2018 packet->CopyData(&dispatchRawVal,
sizeof(dispatchRawVal));
2033 blobData[0] = encoding.GetNextHeader();
2037 if ((blobSize + 2) % 8 > 0)
2039 paddingSize = 8 - (blobSize + 2) % 8;
2041 if (paddingSize == 1)
2043 blobData[blobSize + 2] = 0;
2045 else if (paddingSize > 1)
2047 blobData[blobSize + 2] = 1;
2048 blobData[blobSize + 2 + 1] = paddingSize - 2;
2049 for (uint8_t i = 0; i < paddingSize - 2; i++)
2051 blobData[blobSize + 2 + 2 + i] = 0;
2054 blobData[1] = ((blobSize + 2 + paddingSize) >> 3) - 1;
2056 blob.
Begin().
Write(blobData, blobSize + 2 + paddingSize);
2059 packet->AddHeader(hopHeader);
2064 if (encoding.GetNh())
2067 uint8_t dispatchRawVal = 0;
2070 packet->CopyData(&dispatchRawVal,
sizeof(dispatchRawVal));
2085 blobData[0] = encoding.GetNextHeader();
2087 blobData[1] = ((blobSize + 2) >> 3) - 1;
2091 packet->AddHeader(routingHeader);
2096 if (encoding.GetNh())
2099 uint8_t dispatchRawVal = 0;
2102 packet->CopyData(&dispatchRawVal,
sizeof(dispatchRawVal));
2117 blobData[0] = encoding.GetNextHeader();
2125 packet->AddHeader(fragHeader);
2130 if (encoding.GetNh())
2133 uint8_t dispatchRawVal = 0;
2136 packet->CopyData(&dispatchRawVal,
sizeof(dispatchRawVal));
2151 blobData[0] = encoding.GetNextHeader();
2155 if ((blobSize + 2) % 8 > 0)
2157 paddingSize = 8 - (blobSize + 2) % 8;
2159 if (paddingSize == 1)
2161 blobData[blobSize + 2] = 0;
2163 else if (paddingSize > 1)
2165 blobData[blobSize + 2] = 1;
2166 blobData[blobSize + 2 + 1] = paddingSize - 2;
2167 for (uint8_t i = 0; i < paddingSize - 2; i++)
2169 blobData[blobSize + 2 + 2 + i] = 0;
2172 blobData[1] = ((blobSize + 2 + paddingSize) >> 3) - 1;
2174 blob.
Begin().
Write(blobData, blobSize + 2 + paddingSize);
2177 packet->AddHeader(destHeader);
2181 NS_ABORT_MSG(
"IPv6 Mobility Header is not supported in ns-3 yet");
2188 return std::pair<uint8_t, bool>(0,
true);
2192 NS_ABORT_MSG(
"Trying to decode unknown Extension Header");
2196 NS_LOG_DEBUG(
"Rebuilt packet: " << *packet <<
" Size " << packet->GetSize());
2197 return std::pair<uint8_t, bool>(actualHeaderType,
false);
2209 NS_ASSERT_MSG(packet->PeekHeader(udpHeader) != 0,
"UDP header not found, abort");
2211 size += packet->RemoveHeader(udpHeader);
2214 udpNhcHeader.
SetC(
false);
2220 udpNhcHeader.
SetC(
true);
2248 "UDP_NHC Compression - UDP_NHC header size = " << udpNhcHeader.
GetSerializedSize());
2249 NS_LOG_DEBUG(
"UDP_NHC Compression - packet size = " << packet->GetSize());
2251 packet->AddHeader(udpNhcHeader);
2253 NS_LOG_DEBUG(
"Packet after UDP_NHC compression: " << *packet);
2266 uint32_t ret [[maybe_unused]] = packet->RemoveHeader(encoding);
2267 NS_LOG_DEBUG(
"removed " << ret <<
" bytes - pkt is " << *packet);
2270 switch (encoding.GetPorts())
2279 temp = (0xf0 << 8) | encoding.GetDstPort();
2283 temp = (0xf0 << 8) | encoding.GetSrcPort();
2288 temp = (0xf0b << 4) | encoding.GetSrcPort();
2290 temp = (0xf0b << 4) | encoding.GetDstPort();
2298 if (encoding.GetC())
2303 packet->AddHeader(udpHeader);
2307 NS_LOG_LOGIC(
"Forcing UDP Checksum to " << encoding.GetChecksum());
2309 packet->AddHeader(udpHeader);
2315 packet->AddHeader(udpHeader);
2318 NS_LOG_DEBUG(
"Rebuilt packet: " << *packet <<
" Size " << packet->GetSize());
2332 uint16_t offsetData = 0;
2333 uint16_t offset = 0;
2338 auto tag =
static_cast<uint16_t
>(
m_rng->GetValue(0, 65535));
2347 "6LoWPAN: can not fragment, 6LoWPAN headers are bigger than MTU");
2350 size = l2Mtu - frag1Hdr.
GetSerializedSize() - compressedHeaderSize - extraHdrSize;
2352 size += compressedHeaderSize;
2356 Ptr<Packet> fragment1 = p->CreateFragment(offsetData, size);
2357 offset += size + origHdrSize - compressedHeaderSize;
2360 fragment1->AddHeader(frag1Hdr);
2361 listFragments.push_back(fragment1);
2363 bool moreFrag =
true;
2382 NS_LOG_LOGIC(
"Fragment creation - " << offset <<
", " << offset);
2383 Ptr<Packet> fragment = p->CreateFragment(offsetData, size);
2384 NS_LOG_LOGIC(
"Fragment created - " << offset <<
", " << fragment->GetSize());
2389 fragment->AddHeader(fragNHdr);
2390 listFragments.push_back(fragment);
2406 key.first = std::pair<Address, Address>(src, dst);
2409 uint16_t offset = 0;
2423 uint8_t dispatchRawValFrag1 = 0;
2426 p->RemoveHeader(frag1Header);
2428 p->CopyData(&dispatchRawValFrag1,
sizeof(dispatchRawValFrag1));
2430 NS_LOG_DEBUG(
"Dispatches: " <<
int(dispatchRawValFrag1) <<
" - " <<
int(dispatchValFrag1));
2433 switch (dispatchValFrag1)
2437 p->RemoveHeader(uncompressedHdr);
2455 key.second = std::pair<uint16_t, uint16_t>(frag1Header.
GetDatagramSize(),
2460 p->RemoveHeader(fragNHeader);
2463 key.second = std::pair<uint16_t, uint16_t>(fragNHeader.
GetDatagramSize(),
2467 std::shared_ptr<Fragments> fragments;
2478 std::list<Ptr<Packet>> storedFragments =
m_fragments[oldestKey]->GetFragments();
2479 for (
auto fragIter = storedFragments.begin(); fragIter != storedFragments.end();
2489 fragments = std::make_shared<Fragments>();
2491 m_fragments.insert(std::make_pair(key, fragments));
2495 fragments->SetTimeoutIter(iter);
2499 fragments = it->second;
2502 fragments->AddFragment(p, offset);
2508 fragments->AddFirstFragment(packet);
2511 if (fragments->IsEntire())
2513 packet = fragments->GetPacket();
2517 packet->RemoveHeader(frag1Header);
2519 NS_LOG_LOGIC(
"Rebuilt packet. Size " << packet->GetSize() <<
" - " << *packet);
2521 fragments =
nullptr;
2545 std::list<std::pair<Ptr<Packet>, uint16_t>>::iterator it;
2546 bool duplicate =
false;
2550 if (it->second > fragmentOffset)
2554 if (it->second == fragmentOffset)
2558 "Duplicate fragment size differs. Aborting.");
2564 m_fragments.insert(it, std::make_pair(fragment, fragmentOffset));
2582 uint16_t lastEndOffset = 0;
2589 NS_LOG_LOGIC(
"Checking overlaps " << lastEndOffset <<
" - " << it->second);
2591 if (lastEndOffset < it->
second)
2597 uint16_t fragmentEnd = it->first->GetSize() + it->second;
2598 lastEndOffset = std::max(lastEndOffset, fragmentEnd);
2613 uint16_t lastEndOffset = 0;
2617 lastEndOffset = it->first->GetSize();
2621 if (lastEndOffset > it->second)
2623 NS_ABORT_MSG(
"Overlapping fragments found, forbidden condition");
2628 p->AddAtEnd(it->first);
2630 lastEndOffset += it->first->GetSize();
2643std::list<Ptr<Packet>>
2646 std::list<Ptr<Packet>> fragments;
2649 fragments.push_back(iter->first);
2672 std::list<Ptr<Packet>> storedFragments = it->second->GetFragments();
2673 for (
auto fragIter = storedFragments.begin(); fragIter != storedFragments.end(); fragIter++)
2678 it->second =
nullptr;
2737 bool compressionAllowed,
2742 << contextPrefix << compressionAllowed << validLifetime.
As(
Time::S));
2746 NS_LOG_LOGIC(
"Invalid context ID (" << +contextId <<
"), ignoring");
2754 NS_ABORT_MSG(
"Context " << contextId <<
") can not be modified. New context is from "
2755 << source <<
" old context is from "
2760 if (validLifetime.
IsZero())
2762 NS_LOG_LOGIC(
"Context (" << +contextId <<
"), removed (validity time is zero)");
2768 m_contextTable[contextId].compressionAllowed = compressionAllowed;
2776 bool& compressionAllowed,
2777 Time& validLifetime)
2783 NS_LOG_LOGIC(
"Invalid context ID (" << +contextId <<
"), ignoring");
2789 NS_LOG_LOGIC(
"Context not found (" << +contextId <<
"), ignoring");
2794 compressionAllowed =
m_contextTable[contextId].compressionAllowed;
2807 NS_LOG_LOGIC(
"Invalid context ID (" << +contextId <<
"), ignoring");
2813 NS_LOG_LOGIC(
"Context not found (" << +contextId <<
"), ignoring");
2827 NS_LOG_LOGIC(
"Invalid context ID (" << +contextId <<
"), ignoring");
2833 NS_LOG_LOGIC(
"Context not found (" << +contextId <<
"), ignoring");
2846 NS_LOG_LOGIC(
"Invalid context ID (" << +contextId <<
"), ignoring");
2852 NS_LOG_LOGIC(
"Context not found (" << +contextId <<
"), ignoring");
2873 << +contextId <<
" "
2877 contextId = iter.first;
2901 if (contextLength <= 64)
2903 uint8_t contextBytes[16];
2904 uint8_t addressBytes[16];
2907 address.GetBytes(addressBytes);
2909 if (addressBytes[3] == contextLength && addressBytes[4] == contextBytes[0] &&
2910 addressBytes[5] == contextBytes[1] && addressBytes[6] == contextBytes[2] &&
2911 addressBytes[7] == contextBytes[3] && addressBytes[8] == contextBytes[4] &&
2912 addressBytes[9] == contextBytes[5] && addressBytes[10] == contextBytes[6] &&
2913 addressBytes[11] == contextBytes[7])
2916 << +contextId <<
" "
2920 contextId = iter.first;
2932 uint8_t addressBytes[16];
2933 address.GetBytes(addressBytes);
2936 uint8_t bytesToClean = prefixLength / 8;
2937 uint8_t bitsToClean = prefixLength % 8;
2938 for (uint8_t i = 0; i < bytesToClean; i++)
2940 addressBytes[i] = 0;
2944 uint8_t cleanupMask = (1 << bitsToClean) - 1;
2945 addressBytes[bytesToClean] &= cleanupMask;
2950 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
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 constexpr 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.
Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address &, const Address &, PacketType > PromiscReceiveCallback
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)=0
PacketType
Packet types are used as they are in Linux.
Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address & > ReceiveCallback
static bool ChecksumEnabled()
virtual void DoDispose()
Destructor implementation.
Smart pointer class similar to boost::intrusive_ptr.
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.
Dispatch_e
Dispatch values, as defined in RFC 4944 and RFC 6282.
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.
void SetFlowLabel(uint32_t flowLabel)
Set the Flow Label 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).
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.
void SetSrcInterface(const uint8_t *srcInterface)
Set the source interface.
LOWPAN_IPHC base Encoding - see RFC 6282.
void SetNextHeader(uint8_t nextHeader)
Set the Next Header field.
void SetHlim(Hlim_e hlimField)
Set the HLIM (Hop Limit) compression.
void SetDstContextId(uint8_t dstContextId)
Set the DstContextId.
void SetSam(HeaderCompression_e samField)
Set the SAM (Source Address Mode) compression.
void SetNh(bool nhField)
Set the NH (Next Header) 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).
void SetTf(TrafficClassFlowLabel_e tfField)
Set the TF (Traffic Class, Flow Label) compression.
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 GetM() const
Get the M (Multicast) 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.
void SetHopLimit(uint8_t hopLimit)
Set the Hop Limit field.
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.
FragmentsTimeoutsListI_t m_timeoutIter
Timeout iterator to "event" handler.
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.
std::list< std::pair< Ptr< Packet >, uint16_t > > m_fragments
The current fragments.
Ptr< Packet > m_firstFragment
The very first fragment.
void AddFirstFragment(Ptr< Packet > fragment)
Add the first packet fragment.
Shim performing 6LoWPAN compression, decompression and fragmentation.
bool IsLinkUp() const override
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.
TracedCallback< Ptr< const Packet >, Ptr< SixLowPanNetDevice >, uint32_t > m_rxPostTrace
Callback to trace RX (reception) packets.
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
static constexpr uint16_t PROT_NUMBER
The protocol number for 6LoWPAN (0xA0ED) - see RFC 7973.
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.
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.
TracedCallback< Ptr< const Packet >, Ptr< SixLowPanNetDevice >, uint32_t > m_txPreTrace
Callback to trace TX (transmission) packets.
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.
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.
void AddContext(uint8_t contextId, Ipv6Prefix contextPrefix, bool compressionAllowed, Time validLifetime, Ipv6Address source=Ipv6Address::GetAny())
Add, remove, or update a context used in IPHC stateful compression.
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.
LOWPAN_NHC Extension Header Encoding - see RFC 6282.
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
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_LAST_SRC_LAST_DST
void SetPorts(Ports_e port)
Set the compressed Src and Dst Ports.
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).
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.
bool IsZero() const
Exactly equivalent to t == 0.
AttributeValue implementation for Time.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
static constexpr uint8_t PROT_NUMBER
Protocol number (see http://www.iana.org/assignments/protocol-numbers).
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 AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Ptr< const AttributeChecker > MakeUintegerChecker()
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
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...
#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 ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
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.
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
static const uint32_t packetSize
Packet size generated at the AP.