23 #include "ns3/channel.h"
24 #include "ns3/packet.h"
26 #include "ns3/boolean.h"
27 #include "ns3/abort.h"
28 #include "ns3/simulator.h"
29 #include "ns3/uinteger.h"
30 #include "ns3/icmpv6-header.h"
31 #include "ns3/ipv6-header.h"
32 #include "ns3/random-variable.h"
33 #include "ns3/mac16-address.h"
34 #include "ns3/mac48-address.h"
35 #include "ns3/mac64-address.h"
36 #include "ns3/unused.h"
37 #include "ns3/ipv6-l3-protocol.h"
38 #include "ns3/ipv6-extension-header.h"
39 #include "ns3/udp-header.h"
40 #include "ns3/udp-l4-protocol.h"
54 .AddConstructor<SixLowPanNetDevice> ()
55 .AddAttribute (
"Rfc6282",
"Use RFC6282 (IPHC) if true, RFC4944 (HC1) otherwise.",
58 MakeBooleanChecker ())
59 .AddAttribute (
"OmitUdpChecksum",
60 "Omit the UDP checksum in IPHC compression.",
63 MakeBooleanChecker ())
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.",
82 MakeBooleanChecker ())
83 .AddAttribute (
"EtherType",
84 "The specific EtherType to be used in L2 frames.",
87 MakeUintegerChecker<uint16_t> ())
88 .AddTraceSource (
"Tx",
"Send - packet (including 6LoWPAN header), SixLoWPanNetDevice Ptr, interface index.",
90 .AddTraceSource (
"Rx",
"Receive - packet (including 6LoWPAN header), SixLoWPanNetDevice Ptr, interface index.",
92 .AddTraceSource (
"Drop",
"Drop - DropReason, packet (including 6LoWPAN header), SixLoWPanNetDevice Ptr, interface index.",
105 m_rng = CreateObject<UniformRandomVariable> ();
119 NS_LOG_DEBUG (
"RegisterProtocolHandler for " << device->GetInstanceTypeId ().GetName ());
121 uint16_t protocolType = 0;
128 protocolType, device,
false);
147 iter->second.Cancel ();
167 NS_LOG_FUNCTION (
this << incomingPort << packet << protocol << src << dst);
170 uint8_t dispatchRawVal = 0;
176 copyPkt->
CopyData (&dispatchRawVal,
sizeof(dispatchRawVal));
178 bool isPktDecompressed =
false;
179 bool fragmented =
false;
183 NS_LOG_DEBUG (
"Dispatches: " <<
int(dispatchRawVal) <<
" - " <<
int(dispatchVal) );
197 if ( !isPktDecompressed )
203 copyPkt->
CopyData (&dispatchRawVal,
sizeof(dispatchRawVal));
208 switch ( dispatchVal )
211 NS_LOG_DEBUG (
"Unsupported 6LoWPAN encoding: MESH, dropping.");
215 NS_LOG_DEBUG (
"Unsupported 6LoWPAN encoding: BC0, dropping.");
223 isPktDecompressed =
true;
228 isPktDecompressed =
true;
232 isPktDecompressed =
true;
235 NS_LOG_DEBUG (
"Unsupported 6LoWPAN encoding: dropping.");
240 if ( !isPktDecompressed )
246 NS_LOG_DEBUG (
"Packet decompressed received: " << *copyPkt );
329 return m_netDevice->AddLinkChangeCallback (callback);
390 uint16_t protocolNumber)
396 ret =
DoSend (packet, src, dest, protocolNumber,
false);
403 uint16_t protocolNumber)
408 ret =
DoSend (packet, src, dest, protocolNumber,
true);
415 uint16_t protocolNumber,
418 NS_LOG_FUNCTION (
this << *packet << src << dest << protocolNumber << doSendFrom);
422 uint32_t origHdrSize = 0;
423 uint32_t origPacketSize = packet->
GetSize ();
444 std::list<Ptr<Packet> > fragmentList;
446 std::list<Ptr<Packet> >::iterator it;
448 for ( it = fragmentList.begin (); it != fragmentList.end (); it++ )
450 NS_LOG_DEBUG (
"SixLowPanNetDevice::Send (Fragment) " << **it );
454 success &=
m_netDevice->SendFrom (*it, src, dest, protocolNumber);
458 success &=
m_netDevice->Send (*it, dest, protocolNumber);
467 NS_LOG_LOGIC (
"Compressed packet too short, using uncompressed one");
477 ret =
m_netDevice->SendFrom (packet, src, dest, protocolNumber);
482 ret =
m_netDevice->Send (packet, dest, protocolNumber);
549 NS_LOG_LOGIC (
"Checking source compression: " << mySrcAddr <<
" - " << srcAddr );
552 bool isSrcSrc = (memcmp (bufOne + 8, bufTwo + 8, 8) == 0);
579 NS_LOG_LOGIC (
"Checking destination compression: " << myDstAddr <<
" - " << dstAddr );
582 bool isDstDst = (memcmp (bufOne + 8, bufTwo + 8, 8) == 0);
642 NS_LOG_DEBUG (
"removed " << ret <<
" bytes - pkt is " << *packet);
649 const uint8_t* interface;
650 const uint8_t* prefix;
655 interface = encoding.GetSrcInterface ();
656 for (
int j = 0; j < 8; j++)
658 address[j + 8] = interface[j];
659 address[j] = prefix[j];
665 for (
int j = 0; j < 8; j++)
668 address[j] = prefix[j];
673 interface = encoding.GetSrcInterface ();
676 for (
int j = 0; j < 8; j++)
678 address[j + 8] = interface[j];
689 const uint8_t* interface;
690 const uint8_t* prefix;
695 interface = encoding.GetDstInterface ();
696 for (
int j = 0; j < 8; j++)
698 address[j + 8] = interface[j];
699 address[j] = prefix[j];
705 for (
int j = 0; j < 8; j++)
708 address[j] = prefix[j];
713 interface = encoding.GetDstInterface ();
716 for (
int j = 0; j < 8; j++)
718 address[j + 8] = interface[j];
743 "6LoWPAN: error in decompressing HC1 encoding, unsupported L4 compressed header present.");
797 iphcHeader.
SetNh (
true);
802 iphcHeader.
SetNh (
true);
811 iphcHeader.
SetNh (
true);
816 iphcHeader.
SetNh (
false);
823 iphcHeader.
SetNh (
false);
850 iphcHeader.
SetCid (
false);
854 iphcHeader.
SetSac (
false);
856 uint8_t addressBuf[16];
857 uint8_t unicastAddrCheckerBuf[16];
862 checker.
GetBytes (unicastAddrCheckerBuf);
869 NS_LOG_LOGIC (
"Checking source compression: " << mySrcAddr <<
" - " << srcAddr );
871 if ( mySrcAddr == srcAddr )
875 else if (memcmp (addressBuf, unicastAddrCheckerBuf, 14) == 0)
891 iphcHeader.
SetM (
true);
895 iphcHeader.
SetM (
false);
900 iphcHeader.
SetDac (
false);
910 NS_LOG_LOGIC (
"Checking destination compression: " << myDstAddr <<
" - " << dstAddr );
912 if ( !iphcHeader.
GetM () )
915 if ( myDstAddr == dstAddr )
919 else if (memcmp (addressBuf, unicastAddrCheckerBuf, 14) == 0)
935 uint8_t multicastAddrCheckerBuf[16];
937 multicastCheckAddress.
GetBytes (multicastAddrCheckerBuf);
940 if ( memcmp (addressBuf, multicastAddrCheckerBuf, 15) == 0 )
946 else if ( (addressBuf[0] == multicastAddrCheckerBuf[0])
947 && (memcmp (addressBuf + 2, multicastAddrCheckerBuf + 2, 11) ) )
953 else if ( (addressBuf[0] == multicastAddrCheckerBuf[0])
954 && (memcmp (addressBuf + 2, multicastAddrCheckerBuf + 2, 9) ) )
969 NS_LOG_DEBUG (
"Packet after IPHC compression: " << *packet);
1007 NS_LOG_DEBUG (
"removed " << ret <<
" bytes - pkt is " << *packet);
1014 if ( encoding.
GetSac () )
1037 if ( encoding.
GetDac () )
1064 uint8_t traf = 0x00;
1065 switch (encoding.
GetTf ())
1068 traf |= encoding.
GetEcn ();
1069 traf = ( traf << 6 ) | encoding.
GetDscp ();
1074 traf |= encoding.
GetEcn ();
1080 traf |= encoding.
GetEcn ();
1081 traf = ( traf << 6 ) | encoding.
GetDscp ();
1091 if ( encoding.
GetNh () )
1094 uint8_t dispatchRawVal = 0;
1097 packet->
CopyData (&dispatchRawVal,
sizeof(dispatchRawVal));
1138 NS_LOG_DEBUG (
"LOWPAN_NHC MUST NOT be used to encode IPv6 Extension Headers "
1139 "that have more than 255 octets following the Length field after compression. "
1140 "Packet uncompressed.");
1153 nhcHeader.
SetNh (
true);
1158 nhcHeader.
SetNh (
true);
1167 nhcHeader.
SetNh (
true);
1172 nhcHeader.
SetNh (
false);
1179 nhcHeader.
SetNh (
false);
1196 NS_LOG_DEBUG (
"LOWPAN_NHC MUST NOT be used to encode IPv6 Extension Headers "
1197 "that have more than 255 octets following the Length field after compression. "
1198 "Packet uncompressed.");
1211 nhcHeader.
SetNh (
true);
1216 nhcHeader.
SetNh (
true);
1225 nhcHeader.
SetNh (
true);
1230 nhcHeader.
SetNh (
false);
1237 nhcHeader.
SetNh (
false);
1254 NS_LOG_DEBUG (
"LOWPAN_NHC MUST NOT be used to encode IPv6 Extension Headers "
1255 "that have more than 255 octets following the Length field after compression. "
1256 "Packet uncompressed.");
1268 nhcHeader.
SetNh (
true);
1273 nhcHeader.
SetNh (
true);
1282 nhcHeader.
SetNh (
true);
1287 nhcHeader.
SetNh (
false);
1294 nhcHeader.
SetNh (
false);
1311 NS_LOG_DEBUG (
"LOWPAN_NHC MUST NOT be used to encode IPv6 Extension Headers "
1312 "that have more than 255 octets following the Length field after compression. "
1313 "Packet uncompressed.");
1325 nhcHeader.
SetNh (
true);
1330 nhcHeader.
SetNh (
true);
1339 nhcHeader.
SetNh (
true);
1344 nhcHeader.
SetNh (
false);
1351 nhcHeader.
SetNh (
false);
1365 NS_ABORT_MSG (
"IPv6 Mobility Header is not supported in ns-3 yet");
1378 NS_LOG_DEBUG (
"Packet after NHC compression: " << *packet);
1390 NS_LOG_DEBUG (
"removed " << ret <<
" bytes - pkt is " << *packet);
1399 uint8_t blobData[260];
1400 blobSize = encoding.
CopyBlob (blobData + 2, 260);
1401 uint8_t paddingSize = 0;
1403 uint8_t actualEncodedHeaderType = encoding.
GetEid ();
1404 uint8_t actualHeaderType;
1407 switch (actualEncodedHeaderType)
1411 if ( encoding.
GetNh () )
1414 uint8_t dispatchRawVal = 0;
1417 packet->
CopyData (&dispatchRawVal,
sizeof(dispatchRawVal));
1436 if ((blobSize + 2) % 8 > 0)
1438 paddingSize = 8 - (blobSize + 2) % 8;
1440 if (paddingSize == 1)
1442 blobData[blobSize + 2] = 0;
1444 else if (paddingSize > 1)
1446 blobData[blobSize + 2] = 1;
1447 blobData[blobSize + 2 + 1] = paddingSize - 2;
1448 for (uint8_t i = 0; i < paddingSize - 2; i++)
1450 blobData[blobSize + 2 + 2 + i] = 0;
1453 blobData [1] = ((blobSize + 2 + paddingSize) >> 3) - 1;
1454 blob.
AddAtStart (blobSize + 2 + paddingSize);
1455 blob.
Begin ().
Write (blobData, blobSize + 2 + paddingSize);
1463 if ( encoding.
GetNh () )
1466 uint8_t dispatchRawVal = 0;
1469 packet->
CopyData (&dispatchRawVal,
sizeof(dispatchRawVal));
1486 blobData [1] = ((blobSize + 2) >> 3) - 1;
1488 blob.
Begin ().
Write (blobData, blobSize + 2);
1495 if ( encoding.
GetNh () )
1498 uint8_t dispatchRawVal = 0;
1501 packet->
CopyData (&dispatchRawVal,
sizeof(dispatchRawVal));
1525 if ( encoding.
GetNh () )
1528 uint8_t dispatchRawVal = 0;
1531 packet->
CopyData (&dispatchRawVal,
sizeof(dispatchRawVal));
1550 if ((blobSize + 2) % 8 > 0)
1552 paddingSize = 8 - (blobSize + 2) % 8;
1554 if (paddingSize == 1)
1556 blobData[blobSize + 2] = 0;
1558 else if (paddingSize > 1)
1560 blobData[blobSize + 2] = 1;
1561 blobData[blobSize + 2 + 1] = paddingSize - 2;
1562 for (uint8_t i = 0; i < paddingSize - 2; i++)
1564 blobData[blobSize + 2 + 2 + i] = 0;
1567 blobData [1] = ((blobSize + 2 + paddingSize) >> 3) - 1;
1568 blob.
AddAtStart (blobSize + 2 + paddingSize);
1569 blob.
Begin ().
Write (blobData, blobSize + 2 + paddingSize);
1576 NS_ABORT_MSG (
"IPv6 Mobility Header is not supported in ns-3 yet");
1583 NS_ABORT_MSG (
"Trying to decode unknown Extension Header");
1588 return actualHeaderType;
1605 udpNhcHeader.
SetC (
false);
1611 udpNhcHeader.
SetC (
true);
1641 NS_LOG_DEBUG (
"Packet after UDP_NHC compression: " << *packet);
1655 NS_LOG_DEBUG (
"removed " << ret <<
" bytes - pkt is " << *packet);
1669 temp |= (temp << 8) | encoding.
GetDstPort ();
1674 temp |= (temp << 8) | encoding.
GetSrcPort ();
1680 temp |= (temp << 4) | encoding.
GetSrcPort ();
1683 temp |= (temp << 4) | encoding.
GetDstPort ();
1691 if ( encoding.
GetC () )
1717 uint32_t origPacketSize,
1718 uint32_t origHdrSize,
1725 uint16_t offsetData = 0;
1726 uint16_t offset = 0;
1728 uint32_t packetSize = packet->
GetSize ();
1729 uint32_t compressedHeaderSize = packetSize - (origPacketSize - origHdrSize);
1732 NS_LOG_LOGIC (
"random tag " << tag <<
" - test " << packetSize );
1740 "6LoWPAN: can not fragment, 6LoWPAN headers are bigger than MTU");
1744 size += compressedHeaderSize;
1749 offset += size + origHdrSize - compressedHeaderSize;
1753 listFragments.push_back (fragment1);
1755 bool moreFrag =
true;
1766 if ( (offsetData + size) > packetSize )
1768 size = packetSize - offsetData;
1772 NS_LOG_LOGIC (
"Fragment creation - " << offset <<
", " << offset );
1780 listFragments.push_back (fragment);
1794 uint16_t packetSize;
1795 key.first = std::pair<Address, Address> (src, dst);
1798 uint16_t offset = 0;
1812 uint8_t dispatchRawValFrag1 = 0;
1817 p->CopyData (&dispatchRawValFrag1,
sizeof(dispatchRawValFrag1));
1819 NS_LOG_DEBUG (
"Dispatches: " <<
int(dispatchRawValFrag1) <<
" - " <<
int(dispatchValFrag1) );
1822 switch ( dispatchValFrag1 )
1827 p->RemoveHeader(uncompressedHdr);
1845 p->RemoveHeader (fragNHeader);
1853 MapFragments_t::iterator it =
m_fragments.find (key);
1859 MapFragmentsTimers_t::iterator iter;
1863 if ( iter->second.GetTs () < iterFound->second.GetTs () )
1870 std::list< Ptr<Packet> > storedFragments =
m_fragments[oldestKey]->GetFraments ();
1872 fragIter != storedFragments.end (); fragIter++)
1883 fragments = Create<Fragments> ();
1885 m_fragments.insert (std::make_pair (key, fragments));
1893 fragments = it->second;
1943 std::list<std::pair<Ptr<Packet>, uint16_t> >::iterator it;
1944 bool duplicate =
false;
1948 if (it->second > fragmentOffset)
1952 if (it->second == fragmentOffset)
1955 NS_ASSERT_MSG (fragment->
GetSize () == it->first->GetSize (),
"Duplicate fragment size differs. Aborting.");
1961 m_fragments.insert (it, std::make_pair (fragment, fragmentOffset));
1969 m_firstFragment = fragment;
1977 uint16_t lastEndOffset = 0;
1984 NS_LOG_LOGIC (
"Checking overlaps " << lastEndOffset <<
" - " << it->second );
1986 if (lastEndOffset < it->second)
1992 uint16_t fragmentEnd = it->first->GetSize () + it->second;
1993 lastEndOffset = std::max ( lastEndOffset, fragmentEnd );
1997 if ( ret && (lastEndOffset == m_packetSize))
2008 std::list<std::pair<Ptr<Packet>, uint16_t> >::const_iterator it =
m_fragments.begin ();
2011 uint16_t lastEndOffset = 0;
2015 lastEndOffset = it->first->GetSize ();
2019 if ( lastEndOffset > it->second )
2021 NS_ABORT_MSG (
"Overlapping fragments found, forbidden condition");
2028 lastEndOffset += it->first->GetSize ();
2037 m_packetSize = packetSize;
2042 std::list< Ptr<Packet> > fragments;
2043 std::list<std::pair<Ptr<Packet>, uint16_t> >::const_iterator iter;
2046 fragments.push_back (iter->first);
2055 MapFragments_t::iterator it =
m_fragments.find (key);
2056 std::list< Ptr<Packet> > storedFragments = it->second->GetFraments ();
2058 fragIter != storedFragments.end (); fragIter++)
2088 if (ipv6Addr.
IsAny ())
2114 if (ipv6Addr.
IsAny ())
bool IsAny() const
If the IPv6 address is the "Any" address.
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.
uint8_t GetNextHeader(void) const
Get the Next Header field.
void DecompressLowPanUdpNhc(Ptr< Packet > packet, Ipv6Address saddr, Ipv6Address daddr)
Decompress the headers according to NHC compression.
static bool IsMatchingType(const Address &address)
Ports_e GetPorts(void) const
Get the compressed Src and Dst Ports.
NhcDispatch_e
Dispatch values for Next Header compression.
void SetTcflCompression(bool tcflCompression)
Set the Traffic Class and Flow Labels as compressed.
smart pointer class similar to boost::intrusive_ptr
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
uint8_t GetNextHeader() const
Get the Next Header value.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
void SetHopLimit(uint8_t hopLimit)
Set the Hop Limit field.
#define NS_ABORT_MSG(msg)
Abnormal program termination.
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 the class in the ns-3 factory.
6LoWPAN IPv6 uncomprssed header - see RFC 4944
void RemoveAtStart(uint32_t start)
void SetNextHeader(uint8_t nextHeader)
Set the Next Header field values.
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 bool IsMatchingType(const Address &address)
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
bool IsLinkLocal() const
If the IPv6 address is a link-local address (fe80::/64).
uint64_t GetUid(void) const
Returns the packet's Uid.
virtual bool IsMulticast(void) const
bool IsNull(void) const
Check for null implementation.
void SetPorts(Ports_e port)
Set the compressed Src and Dst Ports.
void SetSrcCompression(LowPanHc1Addr_e srcCompression)
Set Source Compression type.
static Ipv6Address GetAny()
Get the "any" (::) Ipv6Address.
uint16_t GetDatagramSize(void) const
Get the datagram size.
static TypeId GetTypeId(void)
Get the type ID.
static Ipv6Address MakeAutoconfiguredAddress(Mac16Address addr, Ipv6Address prefix)
Make the autoconfigured IPv6 address with Mac16Address.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
uint16_t GetDatagramSize(void) const
Get the datagram size.
virtual Ptr< Channel > GetChannel(void) const
Unsupported compression kind.
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
LOWPAN_NHC Extension Header Encoding - see RFC 6282.
std::pair< std::pair< Address, Address >, std::pair< uint16_t, uint16_t > > FragmentKey
Fragment identifier type: src/dst address src/dst port.
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
uint16_t m_fragmentReassemblyListSize
How many packets can be rebuilt at the same time.
#define NS_FATAL_ERROR(msg)
fatal error handling
void SetDatagramOffset(uint8_t datagramOffset)
Set the datagram offset.
void SetSam(HeaderCompression_e samField)
Set the SAM (Source Address Mode) compression.
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
6LoWPAN FRAGN header - see RFC 4944
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.
void SetDatagramSize(uint16_t datagramSize)
Set the datagram size.
Fragment buffer size exceeded.
virtual bool SetMtu(const uint16_t mtu)
void SetNetDevice(Ptr< NetDevice > device)
Setup SixLowPan to be a proxy for the specified NetDevice.
bool IsTcflCompression() const
Check if the Traffic Class and Flow Labels are compressed.
bool GetM(void) const
Get the M (Multicast) compression.
void SetTrafficClass(uint8_t trafficClass)
Set the Traffic Class value.
a polymophic address class
uint16_t GetDstPort() const
Get the Destination Port.
bool GetNh(void) const
Get the Next Header field value.
std::map< FragmentKey, EventId >::iterator MapFragmentsTimersI_t
Container Iterator for fragment key -> exiration event.
uint8_t GetDscp(void) const
Get the DSCP.
void SetHlim(Hlim_e hlimField)
Set the HLIM (Hop Limit) compression.
virtual uint32_t GetIfIndex(void) const
Ptr< Packet > CreateFragment(uint32_t start, uint32_t length) const
Create a new packet which contains a fragment of the original packet.
uint32_t CompressLowPanNhc(Ptr< Packet > packet, uint8_t headerType, Address const &src, Address const &dst)
Compress the headers according to NHC compression.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
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.
uint16_t GetDatagramTag(void) const
Get the datagram tag.
Ipv6Address GetSrcAddress() const
Get the Source Address.
uint16_t GetSrcPort() const
Get the Destination Port.
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.
void SetHc2HeaderPresent(bool hc2HeaderPresent)
Set the next header a HC2 compressed header.
hold objects of type ns3::Time
void SetDscp(uint8_t dscp)
Set the DSCP (6bits).
uint8_t GetTrafficClass() const
Get the Traffic Class value.
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).
void SetSac(bool sacField)
Set the SAC (Source Address Compression) compression.
bool IsHc2HeaderPresent() const
Check if there is a HC2 compressed header.
Ptr< NetDevice > GetNetDevice() const
Returns a smart pointer to the underlying NetDevice.
uint8_t const * PeekData(void) const
void SetNh(bool nhField)
Set the NH (Next Header) compression.
Ipv6Address GetDstAddress() const
Get the Destination Address.
void SetChecksum(uint16_t checksum)
Set the Checksum field values.
uint16_t GetDatagramTag(void) const
Get the datagram tag.
uint8_t GetHopLimit(void) const
Get the Hop Limit field.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
LowPanHc1Addr_e GetDstCompression() const
Get Destination Compression type.
uint8_t GetEcn(void) const
Get the ECN.
void GetBytes(uint8_t buf[16]) const
Get the bytes corresponding to the address.
void SetDstPort(uint16_t port)
Set the Destination Port.
virtual bool IsLinkUp(void) const
void SetDatagramSize(uint16_t datagramSize)
Set the datagram size.
uint8_t GetHopLimit(void) const
Get the "Hop limit" field (TTL).
bool GetNh(void) const
Get the NH (Next Header) compression.
HeaderCompression_e GetDam(void) const
Get the DAM (Destination Address Mode) compression.
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.
Buffer::Iterator Begin(void) const
virtual void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb)
void SetSrcPort(uint16_t port)
Set the Destination Port.
HeaderCompression_e GetSam(void) const
Get the SAM (Source Address Mode) compression.
static Mac48Address ConvertFrom(const Address &address)
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
Time m_fragmentExpirationTimeout
Time limit for fragment rebuilding.
virtual bool NeedsArp(void) const
virtual bool IsBroadcast(void) const
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
bool m_forceEtherType
Force the EtherType number.
uint32_t PeekHeader(Header &header) const
Deserialize but does not remove the header from the internal buffer.
std::map< FragmentKey, Ptr< Fragments > >::iterator MapFragmentsI_t
Container Iterator for fragment key -> fragments.
virtual void SetNode(Ptr< Node > node)
void SetNextHeader(uint8_t nextHeader)
Set the Next Header field.
std::list< Ptr< Packet > > GetFraments() const
Get a list of the current stored fragments.
uint32_t m_compressionThreshold
Minimum L2 payload size.
Shim performing 6LoWPAN compression, decompression and fragmentation.
uint32_t GetFlowLabel() const
Get the Flow Label value.
Ipv6Address MakeLinkLocalAddressFromMac(Address const &addr)
make a link-local address from a MAC address.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
bool IsEntire() const
If all fragments have been added.
bool GetC(void) const
Get the C (Checksum).
virtual Ptr< Node > GetNode(void) const
MapFragmentsTimers_t m_fragmentsTimers
Timers related to fragment rebuilding.
virtual Address GetBroadcast(void) const
bool GetSac(void) const
Get the SAC (Source Address Compression) compression.
virtual void AddLinkChangeCallback(Callback< void > callback)
bool IsMulticast() const
If the IPv6 address is multicast (ff00::/8).
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.
bool GetDac(void) const
Get the DAC (Destination Address Compression) compression.
const uint8_t * GetDstPrefix() const
Get the destination prefix.
void DoFragmentation(Ptr< Packet > packet, uint32_t origPacketSize, uint32_t origHdrSize, std::list< Ptr< Packet > > &listFragments)
Return the instance type identifier.
static Time Now(void)
Return the "current simulation time".
uint32_t GetSize(void) const
uint8_t GetNextHeader(void) const
Get the Next Header field value.
6LoWPAN HC1 header - see RFC 4944
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
void SetHopLimit(uint8_t limit)
Set the "Hop limit" field (TTL).
Ptr< Packet > GetPacket() const
Get the entire packet.
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)
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
#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.
static Ipv6Address MakeAutoconfiguredLinkLocalAddress(Mac16Address mac)
Make the autoconfigured link-local IPv6 address with Mac16Address.
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.
Ipv6Address MakeGlobalAddressFromMac(Address const &addr, Ipv6Address prefix)
make a global address from a MAC address.
void SetFlowLabel(uint32_t flowLabel)
Set the Flow Label (20bits).
Eid_e GetEid(void) const
Get the Extension Header Type.
uint32_t GetId(void) const
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.
static Mac64Address ConvertFrom(const Address &address)
Network layer to device interface.
virtual bool SupportsSendFrom() const
const uint8_t * GetSrcPrefix() const
Get the source prefix.
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
virtual Address GetAddress(void) const
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
uint32_t GetFlowLabel(void) const
Get the Flow Label.
static NhcDispatch_e GetNhcDispatchType(uint8_t dispatch)
Get the NhcDispatch type.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
void SetEid(Eid_e extensionHeaderType)
Set 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.
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.
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
virtual uint16_t GetMtu(void) const
Returns the link-layer MTU for this interface.
void SetNh(bool nhField)
Set the NH field values.
void SetTf(TrafficClassFlowLabel_e tfField)
Set the TF (Traffic Class, Flow Label) compression.
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
Dispatch_e
Dispatch values, as defined in RFC4944 and RFC6282.
uint32_t CopyBlob(uint8_t *blob, uint32_t size) const
Get the option header data blob.
void SetDstAddress(Ipv6Address dstAddress)
Set the Destination Address.
Ptr< NetDevice > m_netDevice
Smart pointer to the underlying NetDevice.
void HandleFragmentsTimeout(FragmentKey key, uint32_t iif)
Process the timeout for packet fragments.
bool AddAtStart(uint32_t start)
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.
static bool IsMatchingType(const Address &address)
void SetDatagramTag(uint16_t datagramTag)
Set the datagram tag.
void SetEcn(uint8_t ecn)
Set the ECN (2bits).
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.
uint8_t GetDatagramOffset(void) const
Get the datagram offset.
Ptr< T > GetObject(void) const
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
LowPanHc1Addr_e GetSrcCompression() const
Get Source Compression type.
a unique identifier for an interface.
static const uint8_t PROT_NUMBER
protocol number (0x11)
TypeId SetParent(TypeId tid)
uint32_t m_ifIndex
Interface index.
UDP LOWPAN_NHC Extension Header Encoding - see RFC 6282.
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.
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.
virtual uint32_t GetSerializedSize(void) const
Get the serialized size of the packet.
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.
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
void SetDatagramTag(uint16_t datagramTag)
Set the datagram tag.
uint16_t GetChecksum(void) const
Get the Checksum field value.