25 #include "ns3/channel.h" 26 #include "ns3/packet.h" 28 #include "ns3/boolean.h" 29 #include "ns3/uinteger.h" 30 #include "ns3/simulator.h" 31 #include "ns3/mac16-address.h" 32 #include "ns3/mac48-address.h" 33 #include "ns3/mac64-address.h" 34 #include "ns3/ipv6-l3-protocol.h" 35 #include "ns3/ipv6-extension-header.h" 36 #include "ns3/udp-header.h" 37 #include "ns3/udp-l4-protocol.h" 38 #include "ns3/string.h" 39 #include "ns3/pointer.h" 53 .SetGroupName (
"SixLowPan")
55 .AddAttribute (
"Rfc6282",
"Use RFC6282 (IPHC) if true, RFC4944 (HC1) otherwise.",
59 .AddAttribute (
"OmitUdpChecksum",
60 "Omit the UDP checksum in IPHC compression.",
64 .AddAttribute (
"FragmentReassemblyListSize",
"The maximum size of the reassembly buffer (in packets). Zero meaning infinite.",
67 MakeUintegerChecker<uint16_t> ())
68 .AddAttribute (
"FragmentExpirationTimeout",
69 "When this timeout expires, the fragments will be cleared from the buffer.",
73 .AddAttribute (
"CompressionThreshold",
74 "The minimum MAC layer payload size.",
77 MakeUintegerChecker<uint32_t> ())
78 .AddAttribute (
"ForceEtherType",
79 "Force a specific EtherType in L2 frames.",
83 .AddAttribute (
"EtherType",
84 "The specific EtherType to be used in L2 frames.",
87 MakeUintegerChecker<uint16_t> ())
88 .AddAttribute (
"UseMeshUnder",
89 "Use a mesh-under routing protocol.",
93 .AddAttribute (
"MeshUnderRadius",
94 "Hops Left to use in mesh-under.",
97 MakeUintegerChecker<uint8_t> ())
98 .AddAttribute (
"MeshCacheLength",
99 "Length of the cache for each source.",
102 MakeUintegerChecker<uint16_t> ())
103 .AddAttribute (
"MeshUnderJitter",
104 "The jitter in ms a node uses to forward mesh-under packets - used to prevent collisions",
105 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=10.0]"),
107 MakePointerChecker<RandomVariableStream> ())
108 .AddTraceSource (
"Tx",
109 "Send - packet (including 6LoWPAN header), " 110 "SixLoWPanNetDevice Ptr, interface index.",
112 "ns3::SixLowPanNetDevice::RxTxTracedCallback")
113 .AddTraceSource (
"Rx",
114 "Receive - packet (including 6LoWPAN header), " 115 "SixLoWPanNetDevice Ptr, interface index.",
117 "ns3::SixLowPanNetDevice::RxTxTracedCallback")
118 .AddTraceSource (
"Drop",
119 "Drop - DropReason, packet (including 6LoWPAN header), " 120 "SixLoWPanNetDevice Ptr, interface index.",
122 "ns3::SixLowPanNetDevice::DropTracedCallback")
134 m_rng = CreateObject<UniformRandomVariable> ();
149 NS_LOG_DEBUG (
"RegisterProtocolHandler for " << device->GetInstanceTypeId ().GetName ());
151 uint16_t protocolType = 0;
158 protocolType, device,
false);
198 NS_LOG_FUNCTION (
this << incomingPort << packet << protocol << src << dst);
201 uint8_t dispatchRawVal = 0;
207 copyPkt->
CopyData (&dispatchRawVal,
sizeof(dispatchRawVal));
209 bool isPktDecompressed =
false;
210 bool fragmented =
false;
214 NS_LOG_DEBUG (
"Dispatches: " <<
int(dispatchRawVal) <<
" - " <<
int(dispatchVal) );
218 bool hasMesh =
false;
225 copyPkt->
CopyData (&dispatchRawVal,
sizeof(dispatchRawVal));
232 copyPkt->
CopyData (&dispatchRawVal,
sizeof(dispatchRawVal));
240 NS_LOG_LOGIC (
"Dropped packet - we only support mesh if it is paired with a BC0");
249 NS_LOG_LOGIC (
"We have already seen this, no further processing.");
266 || finalDst.IsBroadcast ()
267 || finalDst.IsMulticast ()
274 NS_LOG_LOGIC (
"Not forwarding packet -- hop limit reached");
278 NS_LOG_LOGIC (
"Not forwarding packet -- I am the originator");
289 if (!finalDst.IsBroadcast () && !finalDst.IsMulticast ())
311 isPktDecompressed =
ProcessFragment (copyPkt, realSrc, realDst,
false);
316 if ( !isPktDecompressed )
322 copyPkt->
CopyData (&dispatchRawVal,
sizeof(dispatchRawVal));
327 switch ( dispatchVal )
334 isPktDecompressed =
true;
344 isPktDecompressed =
true;
353 isPktDecompressed =
true;
356 NS_LOG_DEBUG (
"Unsupported 6LoWPAN encoding: dropping.");
361 if ( !isPktDecompressed )
367 NS_LOG_DEBUG (
"Packet decompressed received: " << *copyPkt );
450 return m_netDevice->AddLinkChangeCallback (callback);
511 uint16_t protocolNumber)
517 ret =
DoSend (packet, src, dest, protocolNumber,
false);
524 uint16_t protocolNumber)
529 ret =
DoSend (packet, src, dest, protocolNumber,
true);
536 uint16_t protocolNumber,
539 NS_LOG_FUNCTION (
this << *packet << src << dest << protocolNumber << doSendFrom);
543 uint32_t origHdrSize = 0;
544 uint32_t origPacketSize = packet->
GetSize ();
599 NS_LOG_LOGIC (
"Compressed packet too short, using uncompressed one");
615 std::list<Ptr<Packet> > fragmentList;
617 std::list<Ptr<Packet> >::iterator it;
619 for ( it = fragmentList.begin (); it != fragmentList.end (); it++ )
621 NS_LOG_DEBUG (
"SixLowPanNetDevice::Send (Fragment) " << **it );
627 (*it)->AddHeader (bc0Hdr);
628 (*it)->AddHeader (meshHdr);
632 success &=
m_netDevice->SendFrom (*it, src, destination, protocolNumber);
636 success &=
m_netDevice->Send (*it, destination, protocolNumber);
655 ret =
m_netDevice->SendFrom (packet, src, destination, protocolNumber);
660 ret =
m_netDevice->Send (packet, destination, protocolNumber);
727 NS_LOG_LOGIC (
"Checking source compression: " << mySrcAddr <<
" - " << srcAddr );
730 bool isSrcSrc = (memcmp (bufOne + 8, bufTwo + 8, 8) == 0);
757 NS_LOG_LOGIC (
"Checking destination compression: " << myDstAddr <<
" - " << dstAddr );
760 bool isDstDst = (memcmp (bufOne + 8, bufTwo + 8, 8) == 0);
820 NS_LOG_DEBUG (
"removed " << ret <<
" bytes - pkt is " << *packet);
827 const uint8_t* interface;
828 const uint8_t* prefix;
833 interface = encoding.GetSrcInterface ();
834 for (
int j = 0; j < 8; j++)
843 for (
int j = 0; j < 8; j++)
851 interface = encoding.GetSrcInterface ();
854 for (
int j = 0; j < 8; j++)
867 const uint8_t* interface;
868 const uint8_t* prefix;
873 interface = encoding.GetDstInterface ();
874 for (
int j = 0; j < 8; j++)
883 for (
int j = 0; j < 8; j++)
891 interface = encoding.GetDstInterface ();
894 for (
int j = 0; j < 8; j++)
921 "6LoWPAN: error in decompressing HC1 encoding, unsupported L4 compressed header present.");
975 iphcHeader.
SetNh (
true);
980 iphcHeader.
SetNh (
true);
989 iphcHeader.
SetNh (
true);
994 iphcHeader.
SetNh (
false);
1001 iphcHeader.
SetNh (
false);
1028 iphcHeader.
SetCid (
false);
1032 iphcHeader.
SetSac (
false);
1034 uint8_t addressBuf[16];
1035 uint8_t unicastAddrCheckerBuf[16];
1040 checker.
GetBytes (unicastAddrCheckerBuf);
1047 NS_LOG_LOGIC (
"Checking source compression: " << mySrcAddr <<
" - " << srcAddr );
1049 if ( mySrcAddr == srcAddr )
1053 else if (memcmp (addressBuf, unicastAddrCheckerBuf, 14) == 0)
1069 iphcHeader.
SetM (
true);
1073 iphcHeader.
SetM (
false);
1078 iphcHeader.
SetDac (
false);
1088 NS_LOG_LOGIC (
"Checking destination compression: " << myDstAddr <<
" - " << dstAddr );
1090 if ( !iphcHeader.
GetM () )
1093 if ( myDstAddr == dstAddr )
1097 else if (memcmp (addressBuf, unicastAddrCheckerBuf, 14) == 0)
1113 uint8_t multicastAddrCheckerBuf[16];
1115 multicastCheckAddress.
GetBytes (multicastAddrCheckerBuf);
1118 if ( memcmp (addressBuf, multicastAddrCheckerBuf, 15) == 0 )
1124 else if ( (addressBuf[0] == multicastAddrCheckerBuf[0])
1125 && (memcmp (addressBuf + 2, multicastAddrCheckerBuf + 2, 11) == 0) )
1131 else if ( (addressBuf[0] == multicastAddrCheckerBuf[0])
1132 && (memcmp (addressBuf + 2, multicastAddrCheckerBuf + 2, 9) == 0) )
1147 NS_LOG_DEBUG (
"Packet after IPHC compression: " << *packet);
1185 NS_LOG_DEBUG (
"removed " << ret <<
" bytes - pkt is " << *packet);
1192 if ( encoding.
GetSac () )
1215 if ( encoding.
GetDac () )
1242 uint8_t traf = 0x00;
1243 switch (encoding.
GetTf ())
1246 traf |= encoding.
GetEcn ();
1247 traf = ( traf << 6 ) | encoding.
GetDscp ();
1252 traf |= encoding.
GetEcn ();
1258 traf |= encoding.
GetEcn ();
1259 traf = ( traf << 6 ) | encoding.
GetDscp ();
1269 if ( encoding.
GetNh () )
1272 uint8_t dispatchRawVal = 0;
1275 packet->
CopyData (&dispatchRawVal,
sizeof(dispatchRawVal));
1316 NS_LOG_DEBUG (
"LOWPAN_NHC MUST NOT be used to encode IPv6 Extension Headers " 1317 "that have more than 255 octets following the Length field after compression. " 1318 "Packet uncompressed.");
1331 nhcHeader.
SetNh (
true);
1336 nhcHeader.
SetNh (
true);
1345 nhcHeader.
SetNh (
true);
1350 nhcHeader.
SetNh (
false);
1357 nhcHeader.
SetNh (
false);
1374 NS_LOG_DEBUG (
"LOWPAN_NHC MUST NOT be used to encode IPv6 Extension Headers " 1375 "that have more than 255 octets following the Length field after compression. " 1376 "Packet uncompressed.");
1389 nhcHeader.
SetNh (
true);
1394 nhcHeader.
SetNh (
true);
1403 nhcHeader.
SetNh (
true);
1408 nhcHeader.
SetNh (
false);
1415 nhcHeader.
SetNh (
false);
1432 NS_LOG_DEBUG (
"LOWPAN_NHC MUST NOT be used to encode IPv6 Extension Headers " 1433 "that have more than 255 octets following the Length field after compression. " 1434 "Packet uncompressed.");
1446 nhcHeader.
SetNh (
true);
1451 nhcHeader.
SetNh (
true);
1460 nhcHeader.
SetNh (
true);
1465 nhcHeader.
SetNh (
false);
1472 nhcHeader.
SetNh (
false);
1489 NS_LOG_DEBUG (
"LOWPAN_NHC MUST NOT be used to encode IPv6 Extension Headers " 1490 "that have more than 255 octets following the Length field after compression. " 1491 "Packet uncompressed.");
1503 nhcHeader.
SetNh (
true);
1508 nhcHeader.
SetNh (
true);
1517 nhcHeader.
SetNh (
true);
1522 nhcHeader.
SetNh (
false);
1529 nhcHeader.
SetNh (
false);
1543 NS_ABORT_MSG (
"IPv6 Mobility Header is not supported in ns-3 yet");
1556 NS_LOG_DEBUG (
"Packet after NHC compression: " << *packet);
1568 NS_LOG_DEBUG (
"removed " << ret <<
" bytes - pkt is " << *packet);
1577 uint8_t blobData[260];
1578 blobSize = encoding.
CopyBlob (blobData + 2, 260 - 2);
1579 uint8_t paddingSize = 0;
1581 uint8_t actualEncodedHeaderType = encoding.
GetEid ();
1582 uint8_t actualHeaderType;
1585 switch (actualEncodedHeaderType)
1589 if ( encoding.
GetNh () )
1592 uint8_t dispatchRawVal = 0;
1595 packet->
CopyData (&dispatchRawVal,
sizeof(dispatchRawVal));
1614 if ((blobSize + 2) % 8 > 0)
1616 paddingSize = 8 - (blobSize + 2) % 8;
1618 if (paddingSize == 1)
1620 blobData[blobSize + 2] = 0;
1622 else if (paddingSize > 1)
1624 blobData[blobSize + 2] = 1;
1625 blobData[blobSize + 2 + 1] = paddingSize - 2;
1626 for (uint8_t i = 0; i < paddingSize - 2; i++)
1628 blobData[blobSize + 2 + 2 + i] = 0;
1631 blobData [1] = ((blobSize + 2 + paddingSize) >> 3) - 1;
1632 blob.
AddAtStart (blobSize + 2 + paddingSize);
1633 blob.
Begin ().
Write (blobData, blobSize + 2 + paddingSize);
1641 if ( encoding.
GetNh () )
1644 uint8_t dispatchRawVal = 0;
1647 packet->
CopyData (&dispatchRawVal,
sizeof(dispatchRawVal));
1664 blobData [1] = ((blobSize + 2) >> 3) - 1;
1666 blob.
Begin ().
Write (blobData, blobSize + 2);
1673 if ( encoding.
GetNh () )
1676 uint8_t dispatchRawVal = 0;
1679 packet->
CopyData (&dispatchRawVal,
sizeof(dispatchRawVal));
1699 blob.
Begin ().
Write (blobData, blobSize + 2);
1707 if ( encoding.
GetNh () )
1710 uint8_t dispatchRawVal = 0;
1713 packet->
CopyData (&dispatchRawVal,
sizeof(dispatchRawVal));
1732 if ((blobSize + 2) % 8 > 0)
1734 paddingSize = 8 - (blobSize + 2) % 8;
1736 if (paddingSize == 1)
1738 blobData[blobSize + 2] = 0;
1740 else if (paddingSize > 1)
1742 blobData[blobSize + 2] = 1;
1743 blobData[blobSize + 2 + 1] = paddingSize - 2;
1744 for (uint8_t i = 0; i < paddingSize - 2; i++)
1746 blobData[blobSize + 2 + 2 + i] = 0;
1749 blobData [1] = ((blobSize + 2 + paddingSize) >> 3) - 1;
1750 blob.
AddAtStart (blobSize + 2 + paddingSize);
1751 blob.
Begin ().
Write (blobData, blobSize + 2 + paddingSize);
1758 NS_ABORT_MSG (
"IPv6 Mobility Header is not supported in ns-3 yet");
1765 NS_ABORT_MSG (
"Trying to decode unknown Extension Header");
1770 return actualHeaderType;
1787 udpNhcHeader.
SetC (
false);
1793 udpNhcHeader.
SetC (
true);
1823 NS_LOG_DEBUG (
"Packet after UDP_NHC compression: " << *packet);
1837 NS_LOG_DEBUG (
"removed " << ret <<
" bytes - pkt is " << *packet);
1851 temp |= (temp << 8) | encoding.
GetDstPort ();
1856 temp |= (temp << 8) | encoding.
GetSrcPort ();
1862 temp |= (temp << 4) | encoding.
GetSrcPort ();
1865 temp |= (temp << 4) | encoding.
GetDstPort ();
1873 if ( encoding.
GetC () )
1899 uint32_t origPacketSize,
1900 uint32_t origHdrSize,
1907 uint16_t offsetData = 0;
1908 uint16_t offset = 0;
1911 uint32_t compressedHeaderSize =
packetSize - (origPacketSize - origHdrSize);
1922 "6LoWPAN: can not fragment, 6LoWPAN headers are bigger than MTU");
1926 size += compressedHeaderSize;
1931 offset += size + origHdrSize - compressedHeaderSize;
1935 listFragments.push_back (fragment1);
1937 bool moreFrag =
true;
1954 NS_LOG_LOGIC (
"Fragment creation - " << offset <<
", " << offset );
1962 listFragments.push_back (fragment);
1977 key.first = std::pair<Address, Address> (src, dst);
1980 uint16_t offset = 0;
1994 uint8_t dispatchRawValFrag1 = 0;
1999 p->CopyData (&dispatchRawValFrag1,
sizeof(dispatchRawValFrag1));
2001 NS_LOG_DEBUG (
"Dispatches: " <<
int(dispatchRawValFrag1) <<
" - " <<
int(dispatchValFrag1) );
2004 switch ( dispatchValFrag1 )
2009 p->RemoveHeader (uncompressedHdr);
2027 p->RemoveHeader (fragNHeader);
2035 MapFragments_t::iterator it =
m_fragments.find (key);
2044 std::list< Ptr<Packet> > storedFragments =
m_fragments[oldestKey]->GetFraments ();
2046 fragIter != storedFragments.end (); fragIter++)
2056 fragments = Create<Fragments> ();
2058 m_fragments.insert (std::make_pair (key, fragments));
2066 fragments = it->second;
2111 std::list<std::pair<Ptr<Packet>, uint16_t> >::iterator it;
2112 bool duplicate =
false;
2116 if (it->second > fragmentOffset)
2120 if (it->second == fragmentOffset)
2123 NS_ASSERT_MSG (fragment->
GetSize () == it->first->GetSize (),
"Duplicate fragment size differs. Aborting.");
2129 m_fragments.insert (it, std::make_pair (fragment, fragmentOffset));
2137 m_firstFragment = fragment;
2145 uint16_t lastEndOffset = 0;
2152 NS_LOG_LOGIC (
"Checking overlaps " << lastEndOffset <<
" - " << it->second );
2154 if (lastEndOffset < it->
second)
2160 uint16_t fragmentEnd = it->first->GetSize () + it->second;
2161 lastEndOffset =
std::max ( lastEndOffset, fragmentEnd );
2165 if ( ret && (lastEndOffset == m_packetSize))
2176 std::list<std::pair<Ptr<Packet>, uint16_t> >::const_iterator it =
m_fragments.begin ();
2179 uint16_t lastEndOffset = 0;
2183 lastEndOffset = it->first->GetSize ();
2187 if ( lastEndOffset > it->second )
2189 NS_ABORT_MSG (
"Overlapping fragments found, forbidden condition");
2196 lastEndOffset += it->first->GetSize ();
2210 std::list< Ptr<Packet> > fragments;
2211 std::list<std::pair<Ptr<Packet>, uint16_t> >::const_iterator iter;
2214 fragments.push_back (iter->first);
2222 m_timeoutIter = iter;
2229 return m_timeoutIter;
2236 MapFragments_t::iterator it =
m_fragments.find (key);
2237 std::list< Ptr<Packet> > storedFragments = it->second->GetFraments ();
2239 fragIter != storedFragments.end (); fragIter++)
uint8_t GetEcn(void) const
Get the ECN.
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
void SetCid(bool cidField)
Set the CID (Context Identifier Extension) compression.
void DecompressLowPanUdpNhc(Ptr< Packet > packet, Ipv6Address saddr, Ipv6Address daddr)
Decompress the headers according to NHC compression.
static bool IsMatchingType(const Address &address)
uint8_t GetNextHeader(void) const
Get the Next Header field value.
Address GetOriginator(void) const
Get the "Originator" address.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
void AddAtStart(uint32_t start)
NhcDispatch_e
Dispatch values for Next Header compression.
uint64_t GetUid(void) const
Returns the packet's Uid.
Simulation virtual time values and global simulation resolution.
void SetTcflCompression(bool tcflCompression)
Set the Traffic Class and Flow Labels as compressed.
Smart pointer class similar to boost::intrusive_ptr.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
std::pair< std::pair< Address, Address >, std::pair< uint16_t, uint16_t > > FragmentKey_t
Fragment identifier type: src/dst address src/dst port.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
void HandleTimeout(void)
Handles a fragmented packet timeout.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
AttributeValue implementation for Boolean.
void SetHopLimit(uint8_t hopLimit)
Set the Hop Limit field.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
uint32_t GetId(void) const
void SetDstCompression(LowPanHc1Addr_e dstCompression)
Set Destination Compression type.
NetDevice::PromiscReceiveCallback m_promiscRxCallback
The callback used to notify higher layers that a packet has been received in promiscuous mode...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
uint8_t GetHopsLeft(void) const
Get the "Hops Left" field.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
EventId m_timeoutEvent
Event for the next scheduled timeout.
6LoWPAN IPv6 uncompressed header - see RFC 4944.
void RemoveAtStart(uint32_t start)
uint8_t GetDscp(void) const
Get the DSCP.
uint16_t GetDstPort() const
Get the Destination Port.
Hold variables of type string.
void SetNextHeader(uint8_t nextHeader)
Set the Next Header field values.
uint8_t GetSequenceNumber(void) const
Get the "Sequence Number" field.
virtual void SetIfIndex(const uint32_t index)
static Mac16Address ConvertFrom(const Address &address)
void SetPacketSize(uint32_t packetSize)
Set the packet-to-be-defragmented size.
void AddFirstFragment(Ptr< Packet > fragment)
Add the first packet fragment.
TracedCallback< Ptr< const Packet >, Ptr< SixLowPanNetDevice >, uint32_t > m_txTrace
Callback to trace TX (transmission) packets.
static const uint32_t packetSize
static Ipv6Address MakeAutoconfiguredLinkLocalAddress(Address mac)
Make the autoconfigured link-local IPv6 address from a Mac address.
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
static Dispatch_e GetDispatchType(uint8_t dispatch)
Get the Dispatch type.
static bool ChecksumEnabled(void)
LOWPAN_IPHC base Encoding - see RFC 6282.
automatically resized byte buffer
static Ipv6Address MakeAutoconfiguredAddress(Address addr, Ipv6Address prefix)
Make the autoconfigured IPv6 address from a Mac address.
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the address.
void CopyFrom(const uint8_t buffer[2])
void SetPorts(Ports_e port)
Set the compressed Src and Dst Ports.
void SetSrcCompression(LowPanHc1Addr_e srcCompression)
Set Source Compression type.
void SetTimeoutIter(FragmentsTimeoutsListI_t iter)
Set the Timeout iterator.
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
static TypeId GetTypeId(void)
Get the type ID.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
virtual bool IsBroadcast(void) const
FragmentsTimeoutsListI_t GetTimeoutIter()
Get the Timeout iterator.
HeaderCompression_e GetSam(void) const
Get the SAM (Source Address Mode) compression.
std::list< std::tuple< Time, FragmentKey_t, uint32_t > >::iterator FragmentsTimeoutsListI_t
Container Iterator for fragment timeouts.
Unsupported compression kind.
#define NS_UNUSED(x)
Mark a local variable as unused.
bool GetNh(void) const
Get the Next Header field value.
LOWPAN_NHC Extension Header Encoding - see RFC 6282.
uint16_t m_fragmentReassemblyListSize
How many packets can be rebuilt at the same time.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
virtual void DoDispose(void)
Destructor implementation.
void SetDatagramOffset(uint8_t datagramOffset)
Set the datagram offset.
void SetSam(HeaderCompression_e samField)
Set the SAM (Source Address Mode) compression.
uint8_t const * PeekData(void) const
6LoWPAN FRAGN header - see RFC 4944.
virtual Address GetAddress(void) const
void HandleFragmentsTimeout(FragmentKey_t key, uint32_t iif)
Process the timeout for packet fragments.
uint32_t GetFlowLabel(void) const
Get the Flow Label.
void SetDatagramSize(uint16_t datagramSize)
Set the datagram size.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
uint8_t m_bc0Serial
Serial number used in BC0 header.
Fragment buffer size exceeded.
virtual bool SetMtu(const uint16_t mtu)
bool IsEntire() const
If all fragments have been added.
void SetNetDevice(Ptr< NetDevice > device)
Setup SixLowPan to be a proxy for the specified NetDevice.
void SetTrafficClass(uint8_t trafficClass)
Set the Traffic Class value.
virtual double GetValue(void)=0
Get the next random value as a double drawn from the distribution.
a polymophic address class
void SetSequenceNumber(uint8_t seqNumber)
Set the "Sequence Number" field.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
void SetHopsLeft(uint8_t hopsLeft)
Set the "Hops Left" field.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
void SetHlim(Hlim_e hlimField)
Set the HLIM (Hop Limit) compression.
virtual bool IsMulticast(void) const
uint32_t CompressLowPanNhc(Ptr< Packet > packet, uint8_t headerType, Address const &src, Address const &dst)
Compress the headers according to NHC compression.
bool m_useIphc
Use IPHC or HC1.
void AddAtEnd(Ptr< const Packet > packet)
Concatenate the input packet at the end of the current packet.
Ptr< Node > m_node
Smart pointer to the Node.
uint8_t GetHopLimit(void) const
Get the "Hop limit" field (TTL).
void SetBlob(const uint8_t *blob, uint32_t size)
Set the option header data blob.
uint32_t CompressLowPanUdpNhc(Ptr< Packet > packet, bool omitChecksum)
Compress the headers according to NHC compression.
uint32_t CompressLowPanIphc(Ptr< Packet > packet, Address const &src, Address const &dst)
Compress the headers according to IPHC compression.
HeaderCompression_e GetDam(void) const
Get the DAM (Destination Address Mode) compression.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
void SetHc2HeaderPresent(bool hc2HeaderPresent)
Set the next header a HC2 compressed header.
Address GetFinalDst(void) const
Get the "Final Destination" address.
AttributeValue implementation for Time.
void SetDscp(uint8_t dscp)
Set the DSCP (6bits).
std::map< Address, std::list< uint8_t > > m_seenPkts
Seen packets, memorized by OriginatorAdddress, SequenceNumber.
Ptr< Packet > GetPacket() const
Get the entire packet.
Ptr< RandomVariableStream > m_meshUnderJitter
Random variable for the mesh-under packet retransmission.
Hold an unsigned integer type.
void SetDstInterface(const uint8_t *dstInterface)
Set the destination interface.
uint32_t m_packetSize
The size of the reconstructed packet (bytes).
bool GetNh(void) const
Get the NH (Next Header) compression.
void SetOriginator(Address originator)
Set the "Originator" address.
void SetSac(bool sacField)
Set the SAC (Source Address Compression) compression.
std::list< Ptr< Packet > > GetFraments() const
Get a list of the current stored fragments.
6LoWPAN BC0 header - see RFC 4944.
void SetNh(bool nhField)
Set the NH (Next Header) compression.
bool IsLinkLocal() const
If the IPv6 address is a link-local address (fe80::/64).
void SetChecksum(uint16_t checksum)
Set the Checksum field values.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
Ipv6Address GetSrcAddress() const
Get the Source Address.
uint8_t GetNextHeader(void) const
Get the Next Header field.
void SetDstPort(uint16_t port)
Set the Destination Port.
uint8_t GetTrafficClass() const
Get the Traffic Class value.
void SetDatagramSize(uint16_t datagramSize)
Set the datagram size.
bool IsHc2HeaderPresent() const
Check if there is a HC2 compressed header.
HC1 while in IPHC mode or viceversa.
bool m_meshUnder
Use a mesh-under routing.
TracedCallback< DropReason, Ptr< const Packet >, Ptr< SixLowPanNetDevice >, uint32_t > m_dropTrace
Callback to trace drop packets.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
virtual void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb)
void SetSrcPort(uint16_t port)
Set the Source Port.
virtual Ptr< Channel > GetChannel(void) const
Time m_fragmentExpirationTimeout
Time limit for fragment rebuilding.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
bool m_forceEtherType
Force the EtherType number.
virtual bool NeedsArp(void) const
virtual uint32_t GetIfIndex(void) const
const uint8_t * GetDstPrefix() const
Get the destination prefix.
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
virtual void SetNode(Ptr< Node > node)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetNextHeader(uint8_t nextHeader)
Set the Next Header field.
TrafficClassFlowLabel_e GetTf(void) const
Get the TF (Traffic Class, Flow Label) compression.
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
uint32_t m_compressionThreshold
Minimum L2 payload size.
Shim performing 6LoWPAN compression, decompression and fragmentation.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
bool IsTcflCompression() const
Check if the Traffic Class and Flow Labels are compressed.
Address Get16MacFrom48Mac(Address addr)
Get a Mac16 from its Mac48 pseudo-MAC.
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)=0
uint16_t GetSrcPort() const
Get the Source Port.
virtual void AddLinkChangeCallback(Callback< void > callback)
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
LowPanHc1Addr_e GetDstCompression() const
Get Destination Compression type.
NetDevice::ReceiveCallback m_rxCallback
The callback used to notify higher layers that a packet has been received.
void SetSrcAddress(Ipv6Address srcAddress)
Set the Source Address.
uint8_t GetDatagramOffset(void) const
Get the datagram offset.
void DoFragmentation(Ptr< Packet > packet, uint32_t origPacketSize, uint32_t origHdrSize, std::list< Ptr< Packet > > &listFragments)
Performs a packet fragmentation.
This class can contain 16 bit addresses.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
bool GetSac(void) const
Get the SAC (Source Address Compression) compression.
static Time Now(void)
Return the current simulation virtual time.
uint16_t GetChecksum(void) const
Get the Checksum field value.
uint16_t GetDatagramSize(void) const
Get the datagram size.
6LoWPAN HC1 header - see RFC 4944.
void SetHopLimit(uint8_t limit)
Set the "Hop limit" field (TTL).
virtual bool SupportsSendFrom() const
void SetDac(bool dacField)
Set the DAC (Destination Address Compression) compression.
void RegisterProtocolHandler(ProtocolHandler handler, uint16_t protocolType, Ptr< NetDevice > device, bool promiscuous=false)
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
void SetSrcInterface(const uint8_t *srcInterface)
Set the source interface.
uint16_t m_etherType
EtherType number (used only if m_forceEtherType is true).
void SetDstPrefix(const uint8_t *dstPrefix)
Set the destination prefix.
uint16_t GetDatagramTag(void) const
Get the datagram tag.
Describes an IPv6 address.
void DecompressLowPanIphc(Ptr< Packet > packet, Address const &src, Address const &dst)
Decompress the headers according to IPHC compression.
Ipv4 addresses are stored in host order in this class.
SixLowPanNetDevice()
Constructor for the SixLowPanNetDevice.
virtual Ptr< Node > GetNode(void) const
uint32_t GetFlowLabel() const
Get the Flow Label value.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
void SetFlowLabel(uint32_t flowLabel)
Set the Flow Label (20bits).
void SetFinalDst(Address finalDst)
Set the "Final Destination" address.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
void ReceiveFromDevice(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, Address const &source, Address const &destination, PacketType packetType)
Receives all the packets from a NetDevice for further processing.
Network layer to device interface.
uint8_t GetHopLimit(void) const
Get the Hop Limit field.
6LoWPAN Mesh header - see RFC 4944.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Time Seconds(double value)
Construct a Time in the indicated unit.
Ptr< const AttributeChecker > MakeBooleanChecker(void)
LowPanHc1Addr_e GetSrcCompression() const
Get Source Compression type.
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
static NhcDispatch_e GetNhcDispatchType(uint8_t dispatch)
Get the NhcDispatch type.
uint32_t GetSize(void) const
FragmentsTimeoutsList_t m_timeoutEventList
Timeout "events" container.
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
void SetEid(Eid_e extensionHeaderType)
Set the Extension Header Type.
std::map< FragmentKey_t, Ptr< Fragments > >::iterator MapFragmentsI_t
Container Iterator for fragment key -> fragments.
Eid_e GetEid(void) const
Get the Extension Header Type.
bool CanCompressLowPanNhc(uint8_t headerType)
Checks if the next header can be compressed using NHC.
void Write(uint8_t const *buffer, uint32_t size)
bool m_omitUdpChecksum
Omit UDP checksum in NC1 encoding.
Ports_e GetPorts(void) const
Get the compressed Src and Dst Ports.
Fragment timeout exceeded.
bool DoSend(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber, bool doSendFrom)
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
TracedCallback< Ptr< const Packet >, Ptr< SixLowPanNetDevice >, uint32_t > m_rxTrace
Callback to trace RX (reception) packets.
void SetNh(bool nhField)
Set the NH field values.
void SetTf(TrafficClassFlowLabel_e tfField)
Set the TF (Traffic Class, Flow Label) compression.
uint16_t m_meshCacheLength
length of the cache for each source.
uint16_t GetDatagramSize(void) const
Get the datagram size.
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
Dispatch_e
Dispatch values, as defined in RFC 4944 and RFC 6282
FragmentsTimeoutsListI_t SetTimeout(FragmentKey_t key, uint32_t iif)
Set a new timeout "event" for a fragmented packet.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
void SetDstAddress(Ipv6Address dstAddress)
Set the Destination Address.
Ptr< NetDevice > m_netDevice
Smart pointer to the underlying NetDevice.
void AddFragment(Ptr< Packet > fragment, uint16_t fragmentOffset)
Add a fragment to the pool.
bool ProcessFragment(Ptr< Packet > &packet, Address const &src, Address const &dst, bool isFirst)
Process a packet fragment.
void SetM(bool mField)
Set the M (Multicast) compression.
PacketType
Packet types are used as they are in Linux.
void SetSrcPrefix(const uint8_t *srcPrefix)
Set the source prefix.
bool GetM(void) const
Get the M (Multicast) compression.
Ptr< NetDevice > GetNetDevice() const
Returns a smart pointer to the underlying NetDevice.
virtual bool IsLinkUp(void) const
virtual uint16_t GetMtu(void) const
Returns the link-layer MTU for this interface.
static bool IsMatchingType(const Address &address)
bool IsNull(void) const
Check for null implementation.
uint32_t CopyBlob(uint8_t *blob, uint32_t size) const
Get the option header data blob.
uint32_t pktSize
packet size used for the simulation (in bytes)
void SetDatagramTag(uint16_t datagramTag)
Set the datagram tag.
void SetEcn(uint8_t ecn)
Set the ECN (2bits).
bool GetC(void) const
Get the C (Checksum).
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
uint16_t GetDatagramTag(void) const
Get the datagram tag.
6LoWPAN FRAG1 header - see RFC 4944.
uint32_t CompressLowPanHc1(Ptr< Packet > packet, Address const &src, Address const &dst)
Compress the headers according to HC1 compression.
virtual Address GetBroadcast(void) const
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
a unique identifier for an interface.
bool GetDac(void) const
Get the DAC (Destination Address Compression) compression.
static const uint8_t PROT_NUMBER
protocol number (0x11)
uint8_t m_meshUnderHopsLeft
Start value for mesh-under hops left.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
uint32_t m_ifIndex
Interface index.
Buffer::Iterator Begin(void) const
UDP LOWPAN_NHC Extension Header Encoding - see RFC 6282.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
void SetC(bool cField)
Set the C (Checksum).
uint8_t DecompressLowPanNhc(Ptr< Packet > packet, Address const &src, Address const &dst, Ipv6Address srcAddress, Ipv6Address dstAddress)
Decompress the headers according to NHC compression.
static const uint16_t PROT_NUMBER
The protocol number for IPv6 (0x86DD).
virtual void SetAddress(Address address)
Set the address of this interface.
const uint8_t * GetSrcPrefix() const
Get the source prefix.
void DecompressLowPanHc1(Ptr< Packet > packet, Address const &src, Address const &dst)
Decompress the headers according to HC1 compression.
void SetNextHeader(uint8_t nextHeader)
Set the Next Header value.
void AddHeader(const Header &header)
Add header to this packet.
void SetDam(HeaderCompression_e damField)
Set the DAM (Destination Address Mode) compression.
MapFragments_t m_fragments
Fragments hold to be rebuilt.
Ptr< UniformRandomVariable > m_rng
Rng for the fragments tag.
void SetFlowLabel(uint32_t flowLabel)
Set the Flow Label value.
Ipv6Address GetDstAddress() const
Get the Destination Address.
virtual void DoDispose(void)
Destructor implementation.
void SetDatagramTag(uint16_t datagramTag)
Set the datagram tag.
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
uint8_t GetNextHeader() const
Get the Next Header value.