14#include "ns3/boolean.h" 
   15#include "ns3/channel.h" 
   16#include "ns3/ipv6-extension-header.h" 
   17#include "ns3/ipv6-l3-protocol.h" 
   19#include "ns3/mac16-address.h" 
   20#include "ns3/mac48-address.h" 
   21#include "ns3/mac64-address.h" 
   23#include "ns3/packet.h" 
   24#include "ns3/pointer.h" 
   25#include "ns3/simulator.h" 
   26#include "ns3/string.h" 
   27#include "ns3/udp-header.h" 
   28#include "ns3/udp-l4-protocol.h" 
   29#include "ns3/uinteger.h" 
   44        TypeId(
"ns3::SixLowPanNetDevice")
 
   46            .SetGroupName(
"SixLowPan")
 
   48            .AddAttribute(
"Rfc6282",
 
   49                          "Use RFC6282 (IPHC) if true, RFC4944 (HC1) otherwise.",
 
   53            .AddAttribute(
"OmitUdpChecksum",
 
   54                          "Omit the UDP checksum in IPHC compression.",
 
   59                "FragmentReassemblyListSize",
 
   60                "The maximum size of the reassembly buffer (in packets). Zero meaning infinite.",
 
   65                "FragmentExpirationTimeout",
 
   66                "When this timeout expires, the fragments will be cleared from the buffer.",
 
   70            .AddAttribute(
"CompressionThreshold",
 
   71                          "The minimum MAC layer payload size.",
 
   75            .AddAttribute(
"UseMeshUnder",
 
   76                          "Use a mesh-under routing protocol.",
 
   80            .AddAttribute(
"MeshUnderRadius",
 
   81                          "Hops Left to use in mesh-under.",
 
   85            .AddAttribute(
"MeshCacheLength",
 
   86                          "Length of the cache for each source.",
 
   90            .AddAttribute(
"MeshUnderJitter",
 
   91                          "The jitter in ms a node uses to forward mesh-under packets - used to " 
   93                          StringValue(
"ns3::UniformRandomVariable[Min=0.0|Max=10.0]"),
 
   97                            "Send - packet (including 6LoWPAN header), " 
   98                            "SixLoWPanNetDevice Ptr, interface index.",
 
  100                            "ns3::SixLowPanNetDevice::RxTxTracedCallback")
 
  101            .AddTraceSource(
"Rx",
 
  102                            "Receive - packet (including 6LoWPAN header), " 
  103                            "SixLoWPanNetDevice Ptr, interface index.",
 
  105                            "ns3::SixLowPanNetDevice::RxTxTracedCallback")
 
  106            .AddTraceSource(
"Drop",
 
  107                            "Drop - DropReason, packet (including 6LoWPAN header), " 
  108                            "SixLoWPanNetDevice Ptr, interface index.",
 
  110                            "ns3::SixLowPanNetDevice::DropTracedCallback");
 
 
  116      m_netDevice(nullptr),
 
 
  138    NS_LOG_DEBUG(
"RegisterProtocolHandler for " << device->GetInstanceTypeId().GetName());
 
  141    if (device->GetInstanceTypeId().GetName().find(
"LrWpanNetDevice") != std::string::npos)
 
 
  158    m_rng->SetStream(stream);
 
 
  179        iter->second = 
nullptr;
 
 
  194    NS_LOG_FUNCTION(
this << incomingPort << packet << protocol << src << dst);
 
  196    uint8_t dispatchRawVal = 0;
 
  202    copyPkt->CopyData(&dispatchRawVal, 
sizeof(dispatchRawVal));
 
  204    bool isPktDecompressed = 
false;
 
  205    bool fragmented = 
false;
 
  209    NS_LOG_DEBUG(
"Dispatches: " << 
int(dispatchRawVal) << 
" - " << 
int(dispatchVal));
 
  213    bool hasMesh = 
false;
 
  219        copyPkt->RemoveHeader(meshHdr);
 
  220        copyPkt->CopyData(&dispatchRawVal, 
sizeof(dispatchRawVal));
 
  226        copyPkt->RemoveHeader(bc0Hdr);
 
  227        copyPkt->CopyData(&dispatchRawVal, 
sizeof(dispatchRawVal));
 
  235            NS_LOG_LOGIC(
"Dropped packet - we only support mesh if it is paired with a BC0");
 
  244            NS_LOG_LOGIC(
"We have already seen this, no further processing.");
 
  255                        "SixLowPan mesh-under flooding can not currently handle extended address " 
  256                        "final destinations: " 
  259                        "SixLowPan mesh-under flooding can not currently handle devices using " 
  260                        "extended addresses: " 
  273                NS_LOG_LOGIC(
"Not forwarding packet -- hop limit reached");
 
  277                NS_LOG_LOGIC(
"Not forwarding packet -- I am the originator");
 
  283                sendPkt->AddHeader(bc0Hdr);
 
  284                sendPkt->AddHeader(meshHdr);
 
  320        if (!isPktDecompressed)
 
  326            copyPkt->CopyData(&dispatchRawVal, 
sizeof(dispatchRawVal));
 
  334        NS_LOG_DEBUG(
"Packet without compression. Length: " << copyPkt->GetSize());
 
  337            copyPkt->RemoveHeader(uncompressedHdr);
 
  338            isPktDecompressed = 
true;
 
  348        isPktDecompressed = 
true;
 
  362            isPktDecompressed = 
true;
 
  366        NS_LOG_DEBUG(
"Unsupported 6LoWPAN encoding: dropping.");
 
  371    if (!isPktDecompressed)
 
  376    NS_LOG_DEBUG(
"Packet decompressed length: " << copyPkt->GetSize());
 
  377    NS_LOG_DEBUG(
"Packet decompressed received: " << *copyPkt);
 
 
  472    return m_netDevice->AddLinkChangeCallback(callback);
 
 
  545    ret = 
DoSend(packet, src, dest, protocolNumber, 
false);
 
 
  553                             uint16_t protocolNumber)
 
  558    ret = 
DoSend(packet, src, dest, protocolNumber, 
true);
 
 
  566                           uint16_t protocolNumber,
 
  569    NS_LOG_FUNCTION(
this << *packet << src << dest << protocolNumber << doSendFrom);
 
  574    uint32_t origPacketSize = packet->GetSize();
 
  594    uint16_t 
pktSize = packet->GetSize();
 
  630        NS_LOG_LOGIC(
"Compressed packet too short, using uncompressed one");
 
  633        packet->AddHeader(ipv6UncompressedHdr);
 
  643        NS_LOG_LOGIC(
"Fragmentation: Packet size " << packet->GetSize() << 
" - Mtu " 
  646        std::list<Ptr<Packet>> fragmentList;
 
  647        DoFragmentation(packet, origPacketSize, origHdrSize, extraHdrSize, fragmentList);
 
  649        for (
auto it = fragmentList.begin(); it != fragmentList.end(); it++)
 
  651            NS_LOG_DEBUG(
"SixLowPanNetDevice::Send (Fragment) " << **it);
 
  657                (*it)->AddHeader(bc0Hdr);
 
  658                (*it)->AddHeader(meshHdr);
 
  662                success &= 
m_netDevice->SendFrom(*it, src, destination, protocolNumber);
 
  666                success &= 
m_netDevice->Send(*it, destination, protocolNumber);
 
  678            packet->AddHeader(bc0Hdr);
 
  679            packet->AddHeader(meshHdr);
 
  685            ret = 
m_netDevice->SendFrom(packet, src, destination, protocolNumber);
 
  690            ret = 
m_netDevice->Send(packet, destination, protocolNumber);
 
 
  750    NS_LOG_DEBUG(
"Original packet: " << *packet << 
" Size " << packet->GetSize());
 
  752    if (packet->PeekHeader(ipHeader) != 0)
 
  754        packet->RemoveHeader(ipHeader);
 
  765        NS_LOG_LOGIC(
"Checking source compression: " << mySrcAddr << 
" - " << srcAddr);
 
  768        bool isSrcSrc = (memcmp(bufOne + 8, bufTwo + 8, 8) == 0);
 
  795        NS_LOG_LOGIC(
"Checking destination compression: " << myDstAddr << 
" - " << dstAddr);
 
  798        bool isDstDst = (memcmp(bufOne + 8, bufTwo + 8, 8) == 0);
 
  839        NS_LOG_DEBUG(
"HC1 Compression - packet size = " << packet->GetSize());
 
  841        packet->AddHeader(hc1Header);
 
 
  857    uint32_t ret [[maybe_unused]] = packet->RemoveHeader(encoding);
 
  858    NS_LOG_DEBUG(
"removed " << ret << 
" bytes - pkt is " << *packet);
 
  862    switch (encoding.GetSrcCompression())
 
  864        const uint8_t* interface;
 
  865        const uint8_t* prefix;
 
  869        prefix = encoding.GetSrcPrefix();
 
  870        interface = encoding.GetSrcInterface();
 
  871        for (
int j = 0; j < 8; j++)
 
  873            address[j + 8] = interface[j];
 
  874            address[j] = prefix[j];
 
  879        prefix = encoding.GetSrcPrefix();
 
  880        for (
int j = 0; j < 8; j++)
 
  883            address[j] = prefix[j];
 
  888        interface = encoding.GetSrcInterface();
 
  891        for (
int j = 0; j < 8; j++)
 
  893            address[j + 8] = interface[j];
 
  902    switch (encoding.GetDstCompression())
 
  904        const uint8_t* interface;
 
  905        const uint8_t* prefix;
 
  909        prefix = encoding.GetDstPrefix();
 
  910        interface = encoding.GetDstInterface();
 
  911        for (
int j = 0; j < 8; j++)
 
  913            address[j + 8] = interface[j];
 
  914            address[j] = prefix[j];
 
  919        prefix = encoding.GetDstPrefix();
 
  920        for (
int j = 0; j < 8; j++)
 
  923            address[j] = prefix[j];
 
  928        interface = encoding.GetDstInterface();
 
  931        for (
int j = 0; j < 8; j++)
 
  933            address[j + 8] = interface[j];
 
  942    if (!encoding.IsTcflCompression())
 
  958        encoding.IsHc2HeaderPresent() == 
false,
 
  959        "6LoWPAN: error in decompressing HC1 encoding, unsupported L4 compressed header present.");
 
  961    packet->AddHeader(ipHeader);
 
  963    NS_LOG_DEBUG(
"Rebuilt packet:  " << *packet << 
" Size " << packet->GetSize());
 
 
  975    NS_LOG_DEBUG(
"Original packet: " << *packet << 
" Size " << packet->GetSize() << 
" src: " << src
 
  978    if (packet->PeekHeader(ipHeader) != 0)
 
  980        packet->RemoveHeader(ipHeader);
 
 1015                iphcHeader.
SetNh(
true);
 
 1020                iphcHeader.
SetNh(
true);
 
 1029                    iphcHeader.
SetNh(
true);
 
 1034                    iphcHeader.
SetNh(
false);
 
 1041            iphcHeader.
SetNh(
false);
 
 1066        iphcHeader.
SetCid(
false);
 
 1067        iphcHeader.
SetSac(
false);
 
 1068        iphcHeader.
SetDac(
false);
 
 1071        uint8_t unicastAddrCheckerBuf[16];
 
 1072        checker.
GetBytes(unicastAddrCheckerBuf);
 
 1073        uint8_t addressBuf[16];
 
 1078            uint8_t srcContextId;
 
 1091                NS_LOG_LOGIC(
"Checking stateful source compression: " << srcAddr);
 
 1094                if (srcContextId != 0)
 
 1114                    uint8_t serializedCleanedAddress[16];
 
 1115                    cleanedAddr.
Serialize(serializedCleanedAddress);
 
 1117                    if (serializedCleanedAddress[8] == 0x00 &&
 
 1118                        serializedCleanedAddress[9] == 0x00 &&
 
 1119                        serializedCleanedAddress[10] == 0x00 &&
 
 1120                        serializedCleanedAddress[11] == 0xff &&
 
 1121                        serializedCleanedAddress[12] == 0xfe &&
 
 1122                        serializedCleanedAddress[13] == 0x00)
 
 1137                NS_LOG_LOGIC(
"Checking stateless source compression: " << srcAddr);
 
 1141                uint8_t serializedSrcAddress[16];
 
 1142                srcAddr.
Serialize(serializedSrcAddress);
 
 1148                else if (memcmp(addressBuf, unicastAddrCheckerBuf, 14) == 0)
 
 1169            iphcHeader.
SetM(
true);
 
 1173            iphcHeader.
SetM(
false);
 
 1181            NS_LOG_LOGIC(
"Checking destination compression: " << dstAddr);
 
 1183            uint8_t serializedDstAddress[16];
 
 1184            dstAddr.
Serialize(serializedDstAddress);
 
 1186            if (!iphcHeader.
GetM())
 
 1190                uint8_t dstContextId;
 
 1194                    NS_LOG_LOGIC(
"Checking stateful destination compression: " << dstAddr);
 
 1197                    if (dstContextId != 0)
 
 1217                        uint8_t serializedCleanedAddress[16];
 
 1218                        cleanedAddr.
Serialize(serializedCleanedAddress);
 
 1220                        if (serializedCleanedAddress[8] == 0x00 &&
 
 1221                            serializedCleanedAddress[9] == 0x00 &&
 
 1222                            serializedCleanedAddress[10] == 0x00 &&
 
 1223                            serializedCleanedAddress[11] == 0xff &&
 
 1224                            serializedCleanedAddress[12] == 0xfe &&
 
 1225                            serializedCleanedAddress[13] == 0x00)
 
 1239                    NS_LOG_LOGIC(
"Checking stateless destination compression: " << dstAddr);
 
 1245                    else if (memcmp(addressBuf, unicastAddrCheckerBuf, 14) == 0)
 
 1266                uint8_t dstContextId;
 
 1272                    uint8_t dstInlinePart[6] = {};
 
 1273                    dstInlinePart[0] = serializedDstAddress[1];
 
 1274                    dstInlinePart[1] = serializedDstAddress[2];
 
 1275                    dstInlinePart[2] = serializedDstAddress[12];
 
 1276                    dstInlinePart[3] = serializedDstAddress[13];
 
 1277                    dstInlinePart[4] = serializedDstAddress[14];
 
 1278                    dstInlinePart[5] = serializedDstAddress[15];
 
 1281                    if (dstContextId != 0)
 
 1294                    uint8_t multicastAddrCheckerBuf[16];
 
 1296                    multicastCheckAddress.
GetBytes(multicastAddrCheckerBuf);
 
 1299                    if (memcmp(addressBuf, multicastAddrCheckerBuf, 15) == 0)
 
 1306                    else if ((addressBuf[0] == multicastAddrCheckerBuf[0]) &&
 
 1307                             (memcmp(addressBuf + 2, multicastAddrCheckerBuf + 2, 11) == 0))
 
 1309                        uint8_t dstInlinePart[4] = {};
 
 1310                        memcpy(dstInlinePart, serializedDstAddress + 1, 1);
 
 1311                        memcpy(dstInlinePart + 1, serializedDstAddress + 13, 3);
 
 1317                    else if ((addressBuf[0] == multicastAddrCheckerBuf[0]) &&
 
 1318                             (memcmp(addressBuf + 2, multicastAddrCheckerBuf + 2, 9) == 0))
 
 1320                        uint8_t dstInlinePart[6] = {};
 
 1321                        memcpy(dstInlinePart, serializedDstAddress + 1, 1);
 
 1322                        memcpy(dstInlinePart + 1, serializedDstAddress + 11, 5);
 
 1336        NS_LOG_DEBUG(
"IPHC Compression - packet size = " << packet->GetSize());
 
 1338        packet->AddHeader(iphcHeader);
 
 1340        NS_LOG_DEBUG(
"Packet after IPHC compression: " << *packet);
 
 
 1376    uint32_t ret [[maybe_unused]] = packet->RemoveHeader(encoding);
 
 1377    NS_LOG_DEBUG(
"removed " << ret << 
" bytes - pkt is " << *packet);
 
 1383    if (encoding.GetSac())
 
 1392            uint8_t contextId = encoding.GetSrcContextId();
 
 1395                NS_LOG_LOGIC(
"Unknown Source compression context (" << +contextId
 
 1396                                                                    << 
"), dropping packet");
 
 1401                NS_LOG_LOGIC(
"Expired Source compression context (" << +contextId
 
 1402                                                                    << 
"), dropping packet");
 
 1406            uint8_t contextPrefix[16];
 
 1408            uint8_t contextLength = 
m_contextTable[contextId].contextPrefix.GetPrefixLength();
 
 1410            uint8_t srcAddress[16] = {};
 
 1413                memcpy(srcAddress + 8, encoding.GetSrcInlinePart(), 8);
 
 1417                srcAddress[11] = 0xff;
 
 1418                srcAddress[12] = 0xfe;
 
 1419                memcpy(srcAddress + 14, encoding.GetSrcInlinePart(), 2);
 
 1426            uint8_t bytesToCopy = contextLength / 8;
 
 1427            uint8_t bitsToCopy = contextLength % 8;
 
 1430            for (uint8_t i = 0; i < bytesToCopy; i++)
 
 1432                srcAddress[i] = contextPrefix[i];
 
 1436                uint8_t addressBitMask = (1 << (8 - bitsToCopy)) - 1;
 
 1437                uint8_t prefixBitMask = ~addressBitMask;
 
 1438                srcAddress[bytesToCopy] = (contextPrefix[bytesToCopy] & prefixBitMask) |
 
 1439                                          (srcAddress[bytesToCopy] & addressBitMask);
 
 1450            uint8_t srcAddress[16] = {};
 
 1451            memcpy(srcAddress, encoding.GetSrcInlinePart(), 16);
 
 1456            uint8_t srcAddress[16] = {};
 
 1457            memcpy(srcAddress + 8, encoding.GetSrcInlinePart(), 8);
 
 1458            srcAddress[0] = 0xfe;
 
 1459            srcAddress[1] = 0x80;
 
 1464            uint8_t srcAddress[16] = {};
 
 1465            memcpy(srcAddress + 14, encoding.GetSrcInlinePart(), 2);
 
 1466            srcAddress[0] = 0xfe;
 
 1467            srcAddress[1] = 0x80;
 
 1468            srcAddress[11] = 0xff;
 
 1469            srcAddress[12] = 0xfe;
 
 1478    if (encoding.GetDac())
 
 1489        uint8_t contextId = encoding.GetDstContextId();
 
 1492            NS_LOG_LOGIC(
"Unknown Destination compression context (" << +contextId
 
 1493                                                                     << 
"), dropping packet");
 
 1498            NS_LOG_LOGIC(
"Expired Destination compression context (" << +contextId
 
 1499                                                                     << 
"), dropping packet");
 
 1503        uint8_t contextPrefix[16];
 
 1505        uint8_t contextLength = 
m_contextTable[contextId].contextPrefix.GetPrefixLength();
 
 1507        if (!encoding.GetM())
 
 1510            uint8_t dstAddress[16] = {};
 
 1513                memcpy(dstAddress + 8, encoding.GetDstInlinePart(), 8);
 
 1517                dstAddress[11] = 0xff;
 
 1518                dstAddress[12] = 0xfe;
 
 1519                memcpy(dstAddress + 14, encoding.GetDstInlinePart(), 2);
 
 1526            uint8_t bytesToCopy = 
m_contextTable[contextId].contextPrefix.GetPrefixLength() / 8;
 
 1527            uint8_t bitsToCopy = contextLength % 8;
 
 1530            for (uint8_t i = 0; i < bytesToCopy; i++)
 
 1532                dstAddress[i] = contextPrefix[i];
 
 1536                uint8_t addressBitMask = (1 << (8 - bitsToCopy)) - 1;
 
 1537                uint8_t prefixBitMask = ~addressBitMask;
 
 1538                dstAddress[bytesToCopy] = (contextPrefix[bytesToCopy] & prefixBitMask) |
 
 1539                                          (dstAddress[bytesToCopy] & addressBitMask);
 
 1547            uint8_t dstAddress[16] = {};
 
 1548            dstAddress[0] = 0xff;
 
 1549            memcpy(dstAddress + 1, encoding.GetDstInlinePart(), 2);
 
 1550            dstAddress[3] = contextLength;
 
 1551            memcpy(dstAddress + 4, contextPrefix, 8);
 
 1552            memcpy(dstAddress + 12, encoding.GetDstInlinePart() + 2, 4);
 
 1559        if (!encoding.GetM())
 
 1564                uint8_t dstAddress[16] = {};
 
 1565                memcpy(dstAddress, encoding.GetDstInlinePart(), 16);
 
 1570                uint8_t dstAddress[16] = {};
 
 1571                memcpy(dstAddress + 8, encoding.GetDstInlinePart(), 8);
 
 1572                dstAddress[0] = 0xfe;
 
 1573                dstAddress[1] = 0x80;
 
 1578                uint8_t dstAddress[16] = {};
 
 1579                memcpy(dstAddress + 14, encoding.GetDstInlinePart(), 2);
 
 1580                dstAddress[0] = 0xfe;
 
 1581                dstAddress[1] = 0x80;
 
 1582                dstAddress[11] = 0xff;
 
 1583                dstAddress[12] = 0xfe;
 
 1596                uint8_t dstAddress[16] = {};
 
 1597                memcpy(dstAddress, encoding.GetDstInlinePart(), 16);
 
 1602                uint8_t dstAddress[16] = {};
 
 1603                dstAddress[0] = 0xff;
 
 1604                memcpy(dstAddress + 1, encoding.GetDstInlinePart(), 1);
 
 1605                memcpy(dstAddress + 11, encoding.GetDstInlinePart() + 1, 5);
 
 1610                uint8_t dstAddress[16] = {};
 
 1611                dstAddress[0] = 0xff;
 
 1612                memcpy(dstAddress + 1, encoding.GetDstInlinePart(), 1);
 
 1613                memcpy(dstAddress + 13, encoding.GetDstInlinePart() + 1, 3);
 
 1618                uint8_t dstAddress[16] = {};
 
 1619                dstAddress[0] = 0xff;
 
 1620                dstAddress[1] = 0x02;
 
 1621                memcpy(dstAddress + 15, encoding.GetDstInlinePart(), 1);
 
 1628    uint8_t traf = 0x00;
 
 1629    switch (encoding.GetTf())
 
 1632        traf |= encoding.GetEcn();
 
 1633        traf = (traf << 6) | encoding.GetDscp();
 
 1635        ipHeader.
SetFlowLabel(encoding.GetFlowLabel() & 0xfff); 
 
 1638        traf |= encoding.GetEcn();
 
 1644        traf |= encoding.GetEcn();
 
 1645        traf = (traf << 6) | encoding.GetDscp();
 
 1655    if (encoding.GetNh())
 
 1658        uint8_t dispatchRawVal = 0;
 
 1661        packet->CopyData(&dispatchRawVal, 
sizeof(dispatchRawVal));
 
 1693    packet->AddHeader(ipHeader);
 
 1695    NS_LOG_DEBUG(
"Rebuilt packet:  " << *packet << 
" Size " << packet->GetSize());
 
 
 1715        packet->PeekHeader(hopHeader);
 
 1719                "LOWPAN_NHC MUST NOT be used to encode IPv6 Extension Headers " 
 1720                "that have more than 255 octets following the Length field after compression. " 
 1721                "Packet uncompressed.");
 
 1725        size += packet->RemoveHeader(hopHeader);
 
 1734                nhcHeader.
SetNh(
true);
 
 1739                nhcHeader.
SetNh(
true);
 
 1748                    nhcHeader.
SetNh(
true);
 
 1753                    nhcHeader.
SetNh(
false);
 
 1760            nhcHeader.
SetNh(
false);
 
 1774        packet->PeekHeader(routingHeader);
 
 1778                "LOWPAN_NHC MUST NOT be used to encode IPv6 Extension Headers " 
 1779                "that have more than 255 octets following the Length field after compression. " 
 1780                "Packet uncompressed.");
 
 1784        size += packet->RemoveHeader(routingHeader);
 
 1793                nhcHeader.
SetNh(
true);
 
 1798                nhcHeader.
SetNh(
true);
 
 1807                    nhcHeader.
SetNh(
true);
 
 1812                    nhcHeader.
SetNh(
false);
 
 1819            nhcHeader.
SetNh(
false);
 
 1833        packet->PeekHeader(fragHeader);
 
 1837                "LOWPAN_NHC MUST NOT be used to encode IPv6 Extension Headers " 
 1838                "that have more than 255 octets following the Length field after compression. " 
 1839                "Packet uncompressed.");
 
 1842        size += packet->RemoveHeader(fragHeader);
 
 1851                nhcHeader.
SetNh(
true);
 
 1856                nhcHeader.
SetNh(
true);
 
 1865                    nhcHeader.
SetNh(
true);
 
 1870                    nhcHeader.
SetNh(
false);
 
 1877            nhcHeader.
SetNh(
false);
 
 1891        packet->PeekHeader(destHeader);
 
 1895                "LOWPAN_NHC MUST NOT be used to encode IPv6 Extension Headers " 
 1896                "that have more than 255 octets following the Length field after compression. " 
 1897                "Packet uncompressed.");
 
 1900        size += packet->RemoveHeader(destHeader);
 
 1909                nhcHeader.
SetNh(
true);
 
 1914                nhcHeader.
SetNh(
true);
 
 1923                    nhcHeader.
SetNh(
true);
 
 1928                    nhcHeader.
SetNh(
false);
 
 1935            nhcHeader.
SetNh(
false);
 
 1949        NS_ABORT_MSG(
"IPv6 Mobility Header is not supported in ns-3 yet");
 
 1958    NS_LOG_DEBUG(
"NHC Compression - packet size = " << packet->GetSize());
 
 1960    packet->AddHeader(nhcHeader);
 
 1962    NS_LOG_DEBUG(
"Packet after NHC compression: " << *packet);
 
 
 1966std::pair<uint8_t, bool>
 
 1977    uint32_t ret [[maybe_unused]] = packet->RemoveHeader(encoding);
 
 1978    NS_LOG_DEBUG(
"removed " << ret << 
" bytes - pkt is " << *packet);
 
 1986    uint8_t blobData[260];
 
 1987    blobSize = encoding.CopyBlob(blobData + 2, 260 - 2);
 
 1988    uint8_t paddingSize = 0;
 
 1990    uint8_t actualEncodedHeaderType = encoding.GetEid();
 
 1991    uint8_t actualHeaderType;
 
 1994    switch (actualEncodedHeaderType)
 
 1998        if (encoding.GetNh())
 
 2001            uint8_t dispatchRawVal = 0;
 
 2004            packet->CopyData(&dispatchRawVal, 
sizeof(dispatchRawVal));
 
 2019            blobData[0] = encoding.GetNextHeader();
 
 2023        if ((blobSize + 2) % 8 > 0)
 
 2025            paddingSize = 8 - (blobSize + 2) % 8;
 
 2027        if (paddingSize == 1)
 
 2029            blobData[blobSize + 2] = 0;
 
 2031        else if (paddingSize > 1)
 
 2033            blobData[blobSize + 2] = 1;
 
 2034            blobData[blobSize + 2 + 1] = paddingSize - 2;
 
 2035            for (uint8_t i = 0; i < paddingSize - 2; i++)
 
 2037                blobData[blobSize + 2 + 2 + i] = 0;
 
 2040        blobData[1] = ((blobSize + 2 + paddingSize) >> 3) - 1;
 
 2042        blob.
Begin().
Write(blobData, blobSize + 2 + paddingSize);
 
 2045        packet->AddHeader(hopHeader);
 
 2050        if (encoding.GetNh())
 
 2053            uint8_t dispatchRawVal = 0;
 
 2056            packet->CopyData(&dispatchRawVal, 
sizeof(dispatchRawVal));
 
 2071            blobData[0] = encoding.GetNextHeader();
 
 2073        blobData[1] = ((blobSize + 2) >> 3) - 1;
 
 2077        packet->AddHeader(routingHeader);
 
 2082        if (encoding.GetNh())
 
 2085            uint8_t dispatchRawVal = 0;
 
 2088            packet->CopyData(&dispatchRawVal, 
sizeof(dispatchRawVal));
 
 2103            blobData[0] = encoding.GetNextHeader();
 
 2111        packet->AddHeader(fragHeader);
 
 2116        if (encoding.GetNh())
 
 2119            uint8_t dispatchRawVal = 0;
 
 2122            packet->CopyData(&dispatchRawVal, 
sizeof(dispatchRawVal));
 
 2137            blobData[0] = encoding.GetNextHeader();
 
 2141        if ((blobSize + 2) % 8 > 0)
 
 2143            paddingSize = 8 - (blobSize + 2) % 8;
 
 2145        if (paddingSize == 1)
 
 2147            blobData[blobSize + 2] = 0;
 
 2149        else if (paddingSize > 1)
 
 2151            blobData[blobSize + 2] = 1;
 
 2152            blobData[blobSize + 2 + 1] = paddingSize - 2;
 
 2153            for (uint8_t i = 0; i < paddingSize - 2; i++)
 
 2155                blobData[blobSize + 2 + 2 + i] = 0;
 
 2158        blobData[1] = ((blobSize + 2 + paddingSize) >> 3) - 1;
 
 2160        blob.
Begin().
Write(blobData, blobSize + 2 + paddingSize);
 
 2163        packet->AddHeader(destHeader);
 
 2167        NS_ABORT_MSG(
"IPv6 Mobility Header is not supported in ns-3 yet");
 
 2174            return std::pair<uint8_t, bool>(0, 
true);
 
 2178        NS_ABORT_MSG(
"Trying to decode unknown Extension Header");
 
 2182    NS_LOG_DEBUG(
"Rebuilt packet: " << *packet << 
" Size " << packet->GetSize());
 
 2183    return std::pair<uint8_t, bool>(actualHeaderType, 
false);
 
 
 2195    NS_ASSERT_MSG(packet->PeekHeader(udpHeader) != 0, 
"UDP header not found, abort");
 
 2197    size += packet->RemoveHeader(udpHeader);
 
 2200    udpNhcHeader.
SetC(
false);
 
 2206        udpNhcHeader.
SetC(
true);
 
 2234        "UDP_NHC Compression - UDP_NHC header size = " << udpNhcHeader.
GetSerializedSize());
 
 2235    NS_LOG_DEBUG(
"UDP_NHC Compression - packet size = " << packet->GetSize());
 
 2237    packet->AddHeader(udpNhcHeader);
 
 2239    NS_LOG_DEBUG(
"Packet after UDP_NHC compression: " << *packet);
 
 
 2252    uint32_t ret [[maybe_unused]] = packet->RemoveHeader(encoding);
 
 2253    NS_LOG_DEBUG(
"removed " << ret << 
" bytes - pkt is " << *packet);
 
 2256    switch (encoding.GetPorts())
 
 2265        temp = (0xf0 << 8) | encoding.GetDstPort();
 
 2269        temp = (0xf0 << 8) | encoding.GetSrcPort();
 
 2274        temp = (0xf0b << 4) | encoding.GetSrcPort();
 
 2276        temp = (0xf0b << 4) | encoding.GetDstPort();
 
 2284        if (encoding.GetC())
 
 2289            packet->AddHeader(udpHeader);
 
 2293            NS_LOG_LOGIC(
"Forcing UDP Checksum to " << encoding.GetChecksum());
 
 2295            packet->AddHeader(udpHeader);
 
 2301        packet->AddHeader(udpHeader);
 
 2304    NS_LOG_DEBUG(
"Rebuilt packet: " << *packet << 
" Size " << packet->GetSize());
 
 
 2318    uint16_t offsetData = 0;
 
 2319    uint16_t offset = 0;
 
 2324    auto tag = 
static_cast<uint16_t
>(
m_rng->GetValue(0, 65535));
 
 2333                  "6LoWPAN: can not fragment, 6LoWPAN headers are bigger than MTU");
 
 2336    size = l2Mtu - frag1Hdr.
GetSerializedSize() - compressedHeaderSize - extraHdrSize;
 
 2338    size += compressedHeaderSize;
 
 2342    Ptr<Packet> fragment1 = p->CreateFragment(offsetData, size);
 
 2343    offset += size + origHdrSize - compressedHeaderSize;
 
 2346    fragment1->AddHeader(frag1Hdr);
 
 2347    listFragments.push_back(fragment1);
 
 2349    bool moreFrag = 
true;
 
 2368            NS_LOG_LOGIC(
"Fragment creation - " << offset << 
", " << offset);
 
 2369            Ptr<Packet> fragment = p->CreateFragment(offsetData, size);
 
 2370            NS_LOG_LOGIC(
"Fragment created - " << offset << 
", " << fragment->GetSize());
 
 2375            fragment->AddHeader(fragNHdr);
 
 2376            listFragments.push_back(fragment);
 
 
 2392    key.first = std::pair<Address, Address>(src, dst);
 
 2395    uint16_t offset = 0;
 
 2409        uint8_t dispatchRawValFrag1 = 0;
 
 2412        p->RemoveHeader(frag1Header);
 
 2414        p->CopyData(&dispatchRawValFrag1, 
sizeof(dispatchRawValFrag1));
 
 2416        NS_LOG_DEBUG(
"Dispatches: " << 
int(dispatchRawValFrag1) << 
" - " << 
int(dispatchValFrag1));
 
 2419        switch (dispatchValFrag1)
 
 2423            p->RemoveHeader(uncompressedHdr);
 
 2441        key.second = std::pair<uint16_t, uint16_t>(frag1Header.
GetDatagramSize(),
 
 2446        p->RemoveHeader(fragNHeader);
 
 2449        key.second = std::pair<uint16_t, uint16_t>(fragNHeader.
GetDatagramSize(),
 
 2464            std::list<Ptr<Packet>> storedFragments = 
m_fragments[oldestKey]->GetFragments();
 
 2465            for (
auto fragIter = storedFragments.begin(); fragIter != storedFragments.end();
 
 2477        m_fragments.insert(std::make_pair(key, fragments));
 
 2481        fragments->SetTimeoutIter(iter);
 
 2485        fragments = it->second;
 
 2488    fragments->AddFragment(p, offset);
 
 2494        fragments->AddFirstFragment(packet);
 
 2497    if (fragments->IsEntire())
 
 2499        packet = fragments->GetPacket();
 
 2503        packet->RemoveHeader(frag1Header);
 
 2505        NS_LOG_LOGIC(
"Rebuilt packet. Size " << packet->GetSize() << 
" - " << *packet);
 
 2507        fragments = 
nullptr;
 
 
 2531    std::list<std::pair<Ptr<Packet>, uint16_t>>::iterator it;
 
 2532    bool duplicate = 
false;
 
 2536        if (it->second > fragmentOffset)
 
 2540        if (it->second == fragmentOffset)
 
 2544                          "Duplicate fragment size differs. Aborting.");
 
 2550        m_fragments.insert(it, std::make_pair(fragment, fragmentOffset));
 
 
 2559    m_firstFragment = fragment;
 
 
 2568    uint16_t lastEndOffset = 0;
 
 2575            NS_LOG_LOGIC(
"Checking overlaps " << lastEndOffset << 
" - " << it->second);
 
 2577            if (lastEndOffset < it->
second)
 
 2583            uint16_t fragmentEnd = it->first->GetSize() + it->second;
 
 2584            lastEndOffset = std::max(lastEndOffset, fragmentEnd);
 
 2588    return ret && lastEndOffset == m_packetSize;
 
 
 2599    uint16_t lastEndOffset = 0;
 
 2601    p->AddAtEnd(m_firstFragment);
 
 2603    lastEndOffset = it->first->GetSize();
 
 2607        if (lastEndOffset > it->second)
 
 2609            NS_ABORT_MSG(
"Overlapping fragments found, forbidden condition");
 
 2614            p->AddAtEnd(it->first);
 
 2616        lastEndOffset += it->first->GetSize();
 
 
 2629std::list<Ptr<Packet>>
 
 2632    std::list<Ptr<Packet>> fragments;
 
 2635        fragments.push_back(iter->first);
 
 
 2643    m_timeoutIter = iter;
 
 
 2649    return m_timeoutIter;
 
 
 2658    std::list<Ptr<Packet>> storedFragments = it->second->GetFragments();
 
 2659    for (
auto fragIter = storedFragments.begin(); fragIter != storedFragments.end(); fragIter++)
 
 2664    it->second = 
nullptr;
 
 
 2723                               bool compressionAllowed,
 
 2727                         << contextPrefix << compressionAllowed << validLifetime.
As(
Time::S));
 
 2731        NS_LOG_LOGIC(
"Invalid context ID (" << +contextId << 
"), ignoring");
 
 2735    if (validLifetime.
IsZero())
 
 2737        NS_LOG_LOGIC(
"Context (" << +contextId << 
"), removed (validity time is zero)");
 
 2743    m_contextTable[contextId].compressionAllowed = compressionAllowed;
 
 
 2750                               bool& compressionAllowed,
 
 2751                               Time& validLifetime)
 
 2757        NS_LOG_LOGIC(
"Invalid context ID (" << +contextId << 
"), ignoring");
 
 2763        NS_LOG_LOGIC(
"Context not found (" << +contextId << 
"), ignoring");
 
 2768    compressionAllowed = 
m_contextTable[contextId].compressionAllowed;
 
 
 2781        NS_LOG_LOGIC(
"Invalid context ID (" << +contextId << 
"), ignoring");
 
 2787        NS_LOG_LOGIC(
"Context not found (" << +contextId << 
"), ignoring");
 
 
 2801        NS_LOG_LOGIC(
"Invalid context ID (" << +contextId << 
"), ignoring");
 
 2807        NS_LOG_LOGIC(
"Context not found (" << +contextId << 
"), ignoring");
 
 
 2820        NS_LOG_LOGIC(
"Invalid context ID (" << +contextId << 
"), ignoring");
 
 2826        NS_LOG_LOGIC(
"Context not found (" << +contextId << 
"), ignoring");
 
 
 2847                             << +contextId << 
" " 
 2851                contextId = iter.first;
 
 
 2875            if (contextLength <= 64) 
 
 2877                uint8_t contextBytes[16];
 
 2878                uint8_t addressBytes[16];
 
 2881                address.GetBytes(addressBytes);
 
 2883                if (addressBytes[3] == contextLength && addressBytes[4] == contextBytes[0] &&
 
 2884                    addressBytes[5] == contextBytes[1] && addressBytes[6] == contextBytes[2] &&
 
 2885                    addressBytes[7] == contextBytes[3] && addressBytes[8] == contextBytes[4] &&
 
 2886                    addressBytes[9] == contextBytes[5] && addressBytes[10] == contextBytes[6] &&
 
 2887                    addressBytes[11] == contextBytes[7])
 
 2890                                 << +contextId << 
" " 
 2894                    contextId = iter.first;
 
 
 2906    uint8_t addressBytes[16];
 
 2907    address.GetBytes(addressBytes);
 
 2910    uint8_t bytesToClean = prefixLength / 8;
 
 2911    uint8_t bitsToClean = prefixLength % 8;
 
 2912    for (uint8_t i = 0; i < bytesToClean; i++)
 
 2914        addressBytes[i] = 0;
 
 2918        uint8_t cleanupMask = (1 << bitsToClean) - 1;
 
 2919        addressBytes[bytesToClean] &= cleanupMask;
 
 2924    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 IsPending() 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 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.
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.
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.
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
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
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.
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.
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.
#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.
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.