A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
sixlowpan-net-device.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013 Universita' di Firenze, Italy
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
18 * Michele Muccio <michelemuccio@virgilio.it>
19 */
20
21#ifndef SIXLOWPAN_NET_DEVICE_H
22#define SIXLOWPAN_NET_DEVICE_H
23
24#include "ns3/net-device.h"
25#include "ns3/nstime.h"
26#include "ns3/random-variable-stream.h"
27#include "ns3/simulator.h"
28#include "ns3/traced-callback.h"
29
30#include <map>
31#include <stdint.h>
32#include <string>
33#include <tuple>
34
35namespace ns3
36{
37
38class Node;
39class UniformRandomVariable;
40class EventId;
41
42/**
43 * \defgroup sixlowpan 6LoWPAN
44 * \brief Performs 6LoWPAN compression of IPv6 packets as specified by \RFC{4944} and \RFC{6282}
45 *
46 * This module acts as a shim between IPv6 and a generic NetDevice.
47 *
48 * The module implements \RFC{4944} and \RFC{6282}, with the following exceptions:
49 * <ul>
50 * <li> MESH and LOWPAN_BC0 dispatch types are not supported </li>
51 * <li> HC2 encoding is not supported </li>
52 * <li> IPHC's SAC and DAC are not supported </li>
53 *</ul>
54 */
55
56/**
57 * \ingroup sixlowpan
58 * \ingroup tests
59 * \defgroup sixlowpan-tests 6LoWPAN module tests
60 */
61
62/**
63 * \ingroup sixlowpan
64 *
65 * \brief Shim performing 6LoWPAN compression, decompression and fragmentation.
66 *
67 * This class implements the shim between IPv6 and a generic NetDevice,
68 * performing packet compression, decompression and fragmentation in a transparent way.
69 * To this end, the class pretend to be a normal NetDevice, masquerading some functions
70 * of the underlying NetDevice.
71 */
73{
74 public:
75 /**
76 * Enumeration of the dropping reasons in SixLoWPAN.
77 */
79 {
80 DROP_FRAGMENT_TIMEOUT = 1, //!< Fragment timeout exceeded
81 DROP_FRAGMENT_BUFFER_FULL, //!< Fragment buffer size exceeded
82 DROP_UNKNOWN_EXTENSION, //!< Unsupported compression kind
83 DROP_DISALLOWED_COMPRESSION, //!< HC1 while in IPHC mode or vice-versa
84 DROP_SATETFUL_DECOMPRESSION_PROBLEM, //!< Decompression failed due to missing or expired
85 //!< context
86 };
87
88 /**
89 * \brief The protocol number for 6LoWPAN (0xA0ED) - see \RFC{7973}.
90 */
91 static constexpr uint16_t PROT_NUMBER{0xA0ED};
92
93 /**
94 * \brief Get the type ID.
95 * \return The object TypeId.
96 */
97 static TypeId GetTypeId();
98
99 /**
100 * Constructor for the SixLowPanNetDevice.
101 */
103
104 // Delete copy constructor and assignment operator to avoid misuse
107
108 // inherited from NetDevice base class
109 void SetIfIndex(const uint32_t index) override;
110 uint32_t GetIfIndex() const override;
111 Ptr<Channel> GetChannel() const override;
112 void SetAddress(Address address) override;
113 Address GetAddress() const override;
114 bool SetMtu(const uint16_t mtu) override;
115
116 /**
117 * \brief Returns the link-layer MTU for this interface.
118 * If the link-layer MTU is smaller than IPv6's minimum MTU (\RFC{4944}),
119 * 1280 will be returned.
120 *
121 * \return The link-level MTU in bytes for this interface.
122 */
123 uint16_t GetMtu() const override;
124 bool IsLinkUp() const override;
125 void AddLinkChangeCallback(Callback<void> callback) override;
126 bool IsBroadcast() const override;
127 Address GetBroadcast() const override;
128 bool IsMulticast() const override;
129 Address GetMulticast(Ipv4Address multicastGroup) const override;
130 bool IsPointToPoint() const override;
131 bool IsBridge() const override;
132 bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) override;
133 bool SendFrom(Ptr<Packet> packet,
134 const Address& source,
135 const Address& dest,
136 uint16_t protocolNumber) override;
137 Ptr<Node> GetNode() const override;
138 void SetNode(Ptr<Node> node) override;
139 bool NeedsArp() const override;
142 bool SupportsSendFrom() const override;
143 Address GetMulticast(Ipv6Address addr) const override;
144
145 /**
146 * \brief Returns a smart pointer to the underlying NetDevice.
147 *
148 * \return A smart pointer to the underlying NetDevice.
149 */
151
152 /**
153 * \brief Setup SixLowPan to be a proxy for the specified NetDevice.
154 * All the packets incoming and outgoing from the NetDevice will be
155 * processed by SixLowPanNetDevice.
156 *
157 * \param [in] device A smart pointer to the NetDevice to be proxied.
158 */
159 void SetNetDevice(Ptr<NetDevice> device);
160
161 /**
162 * Assign a fixed random variable stream number to the random variables
163 * used by this model. Return the number of streams (possibly zero) that
164 * have been assigned.
165 *
166 * \param [in] stream First stream index to use.
167 * \return the number of stream indices assigned by this model.
168 */
169 int64_t AssignStreams(int64_t stream);
170
171 /**
172 * TracedCallback signature for packet send/receive events.
173 *
174 * \param [in] packet The packet.
175 * \param [in] sixNetDevice The SixLowPanNetDevice.
176 * \param [in] ifindex The ifindex of the device.
177 * \deprecated The non-const \c Ptr<SixLowPanNetDevice> argument
178 * is deprecated and will be changed to \c Ptr<const SixLowPanNetDevice>
179 * in a future release.
180 */
181 typedef void (*RxTxTracedCallback)(Ptr<const Packet> packet,
182 Ptr<SixLowPanNetDevice> sixNetDevice,
183 uint32_t ifindex);
184
185 /**
186 * TracedCallback signature for packet drop events
187 *
188 * \param [in] reason The reason for the drop.
189 * \param [in] packet The packet.
190 * \param [in] sixNetDevice The SixLowPanNetDevice.
191 * \param [in] ifindex The ifindex of the device.
192 * \deprecated The non-const \c Ptr<SixLowPanNetDevice> argument
193 * is deprecated and will be changed to \c Ptr<const SixLowPanNetDevice>
194 * in a future release.
195 */
196 typedef void (*DropTracedCallback)(DropReason reason,
197 Ptr<const Packet> packet,
198 Ptr<SixLowPanNetDevice> sixNetDevice,
199 uint32_t ifindex);
200
201 /**
202 * Add, remove, or update a context used in IPHC stateful compression.
203 *
204 * A context with a zero validLifetime will be immediately removed.
205 *
206 * \param [in] contextId context id (most be between 0 and 15 included).
207 * \param [in] contextPrefix context prefix to be used in compression/decompression.
208 * \param [in] compressionAllowed compression and decompression allowed (true), decompression
209 * only (false).
210 * \param [in] validLifetime validity time (relative to the actual time).
211 *
212 */
213 void AddContext(uint8_t contextId,
214 Ipv6Prefix contextPrefix,
215 bool compressionAllowed,
216 Time validLifetime);
217
218 /**
219 * Get a context used in IPHC stateful compression.
220 *
221 * \param [in] contextId context id (most be between 0 and 15 included).
222 * \param [out] contextPrefix context prefix to be used in compression/decompression.
223 * \param [out] compressionAllowed compression and decompression allowed (true), decompression
224 * only (false).
225 * \param [out] validLifetime validity time (relative to the actual time).
226 *
227 * \return false if the context has not been found.
228 *
229 */
230 bool GetContext(uint8_t contextId,
231 Ipv6Prefix& contextPrefix,
232 bool& compressionAllowed,
233 Time& validLifetime);
234
235 /**
236 * Renew a context used in IPHC stateful compression.
237 *
238 * The context will have its lifetime extended and its validity for compression re-enabled.
239 *
240 * \param [in] contextId context id (most be between 0 and 15 included).
241 * \param [in] validLifetime validity time (relative to the actual time).
242 */
243 void RenewContext(uint8_t contextId, Time validLifetime);
244
245 /**
246 * Invalidate a context used in IPHC stateful compression.
247 *
248 * An invalid context will not be used for compression but it will be used for decompression.
249 *
250 * \param [in] contextId context id (most be between 0 and 15 included).
251 */
252 void InvalidateContext(uint8_t contextId);
253
254 /**
255 * Remove a context used in IPHC stateful compression.
256 *
257 * \param [in] contextId context id (most be between 0 and 15 included).
258 */
259 void RemoveContext(uint8_t contextId);
260
261 protected:
262 void DoDispose() override;
263
264 private:
265 /**
266 * \brief Receives all the packets from a NetDevice for further processing.
267 * \param [in] device The NetDevice the packet ws received from.
268 * \param [in] packet The received packet.
269 * \param [in] protocol The protocol (if known).
270 * \param [in] source The source address.
271 * \param [in] destination The destination address.
272 * \param [in] packetType The packet kind (e.g., HOST, BROADCAST, etc.).
273 */
275 Ptr<const Packet> packet,
276 uint16_t protocol,
277 const Address& source,
278 const Address& destination,
279 PacketType packetType);
280
281 /**
282 * \param [in] packet Packet sent from above down to Network Device.
283 * \param [in] source Source mac address (only used if doSendFrom is true, i.e., "MAC
284 * spoofing").
285 * \param [in] dest Mac address of the destination (already resolved).
286 * \param [in] protocolNumber Identifies the type of payload contained in this packet. Used to
287 * call the right L3Protocol when the packet is received.
288 * \param [in] doSendFrom Perform a SendFrom instead of a Send.
289 *
290 * Called from higher layer to send packet into Network Device
291 * with the specified source and destination Addresses.
292 *
293 * \return Whether the Send operation succeeded.
294 */
295 bool DoSend(Ptr<Packet> packet,
296 const Address& source,
297 const Address& dest,
298 uint16_t protocolNumber,
299 bool doSendFrom);
300
301 /**
302 * The callback used to notify higher layers that a packet has been received.
303 */
305
306 /**
307 * The callback used to notify higher layers that a packet has been received in promiscuous
308 * mode.
309 */
311
312 /**
313 * \brief Callback to trace TX (transmission) packets.
314 *
315 * Data passed:
316 * \li Packet received (including 6LoWPAN header)
317 * \li Ptr to SixLowPanNetDevice
318 * \li interface index
319 * \deprecated The non-const \c Ptr<SixLowPanNetDevice> argument
320 * is deprecated and will be changed to \c Ptr<const SixLowPanNetDevice>
321 * in a future release.
322 */
324
325 /**
326 * \brief Callback to trace RX (reception) packets.
327 *
328 * Data passed:
329 * \li Packet received (including 6LoWPAN header)
330 * \li Ptr to SixLowPanNetDevice
331 * \li interface index
332 * \deprecated The non-const \c Ptr<SixLowPanNetDevice> argument
333 * is deprecated and will be changed to \c Ptr<const SixLowPanNetDevice>
334 * in a future release.
335 */
337
338 /**
339 * \brief Callback to trace drop packets.
340 *
341 * Data passed:
342 * \li DropReason
343 * \li Packet dropped (including 6LoWPAN header)
344 * \li Ptr to SixLowPanNetDevice
345 * \li interface index
346 * \deprecated The non-const \c Ptr<SixLowPanNetDevice> argument
347 * is deprecated and will be changed to \c Ptr<const SixLowPanNetDevice>
348 * in a future release.
349 */
351
352 /**
353 * \brief Compress the headers according to HC1 compression.
354 * \param [in] packet The packet to be compressed.
355 * \param [in] src The MAC source address.
356 * \param [in] dst The MAC destination address.
357 * \return The size of the removed headers.
358 */
359 uint32_t CompressLowPanHc1(Ptr<Packet> packet, const Address& src, const Address& dst);
360
361 /**
362 * \brief Decompress the headers according to HC1 compression.
363 * \param [in] packet the packet to be compressed.
364 * \param [in] src the MAC source address.
365 * \param [in] dst the MAC destination address.
366 */
367 void DecompressLowPanHc1(Ptr<Packet> packet, const Address& src, const Address& dst);
368
369 /**
370 * \brief Compress the headers according to IPHC compression.
371 * \param [in] packet The packet to be compressed.
372 * \param [in] src The MAC source address.
373 * \param [in] dst The MAC destination address.
374 * \return The size of the removed headers.
375 */
376 uint32_t CompressLowPanIphc(Ptr<Packet> packet, const Address& src, const Address& dst);
377
378 /**
379 * \brief Checks if the next header can be compressed using NHC.
380 * \param [in] headerType The header kind to be compressed.
381 * \return True if the header can be compressed.
382 */
383 bool CanCompressLowPanNhc(uint8_t headerType);
384
385 /**
386 * \brief Decompress the headers according to IPHC compression.
387 * \param [in] packet The packet to be compressed.
388 * \param [in] src The MAC source address.
389 * \param [in] dst The MAC destination address.
390 * \return true if the packet can not be decompressed due to wrong context information.
391 */
392 bool DecompressLowPanIphc(Ptr<Packet> packet, const Address& src, const Address& dst);
393
394 /**
395 * \brief Compress the headers according to NHC compression.
396 * \param [in] packet The packet to be compressed.
397 * \param [in] headerType The header type.
398 * \param [in] src The MAC source address.
399 * \param [in] dst The MAC destination address.
400 * \return The size of the removed headers.
401 */
403 uint8_t headerType,
404 const Address& src,
405 const Address& dst);
406
407 /**
408 * \brief Decompress the headers according to NHC compression.
409 * \param [in] packet The packet to be compressed.
410 * \param [in] src The MAC source address.
411 * \param [in] dst The MAC destination address.
412 * \param [in] srcAddress The IPv6 source address.
413 * \param [in] dstAddress The IPv6 destination address.
414 * \return A std::pair containing the decompressed header type and a flag - true if the packet
415 * can not be decompressed due to wrong context information.
416 */
417 std::pair<uint8_t, bool> DecompressLowPanNhc(Ptr<Packet> packet,
418 const Address& src,
419 const Address& dst,
420 Ipv6Address srcAddress,
421 Ipv6Address dstAddress);
422
423 /**
424 * \brief Compress the headers according to NHC compression.
425 * \param [in] packet The packet to be compressed.
426 * \param [in] omitChecksum Omit UDP checksum (if true).
427 * \return The size of the removed headers.
428 */
429 uint32_t CompressLowPanUdpNhc(Ptr<Packet> packet, bool omitChecksum);
430
431 /**
432 * \brief Decompress the headers according to NHC compression.
433 * \param [in] packet The packet to be compressed.
434 * \param [in] saddr The IPv6 source address.
435 * \param [in] daddr The IPv6 destination address.
436 */
438
439 /**
440 * Fragment identifier type: src/dst address src/dst port.
441 */
442 typedef std::pair<std::pair<Address, Address>, std::pair<uint16_t, uint16_t>> FragmentKey_t;
443
444 /// Container for fragment timeouts.
445 typedef std::list<std::tuple<Time, FragmentKey_t, uint32_t>> FragmentsTimeoutsList_t;
446 /// Container Iterator for fragment timeouts.
447 typedef std::list<std::tuple<Time, FragmentKey_t, uint32_t>>::iterator FragmentsTimeoutsListI_t;
448
449 /**
450 * \brief Set a new timeout "event" for a fragmented packet
451 * \param key the fragment identification
452 * \param iif input interface of the packet
453 * \return an iterator to the inserted "event"
454 */
456
457 /**
458 * \brief Handles a fragmented packet timeout
459 */
460 void HandleTimeout();
461
462 FragmentsTimeoutsList_t m_timeoutEventList; //!< Timeout "events" container
463
464 EventId m_timeoutEvent; //!< Event for the next scheduled timeout
465
466 /**
467 * \brief A Set of Fragments.
468 */
469 class Fragments : public SimpleRefCount<Fragments>
470 {
471 public:
472 /**
473 * \brief Constructor.
474 */
475 Fragments();
476
477 /**
478 * \brief Destructor.
479 */
480 ~Fragments();
481
482 /**
483 * \brief Add a fragment to the pool.
484 * \param [in] fragment the fragment.
485 * \param [in] fragmentOffset the offset of the fragment.
486 */
487 void AddFragment(Ptr<Packet> fragment, uint16_t fragmentOffset);
488
489 /**
490 * \brief Add the first packet fragment. The first fragment is needed to
491 * allow the post-defragmentation decompression.
492 * \param [in] fragment The fragment.
493 */
494 void AddFirstFragment(Ptr<Packet> fragment);
495
496 /**
497 * \brief If all fragments have been added.
498 * \returns True if the packet is entire.
499 */
500 bool IsEntire() const;
501
502 /**
503 * \brief Get the entire packet.
504 * \return The entire packet.
505 */
506 Ptr<Packet> GetPacket() const;
507
508 /**
509 * \brief Set the packet-to-be-defragmented size.
510 * \param [in] packetSize The packet size (bytes).
511 */
513
514 /**
515 * \brief Get a list of the current stored fragments.
516 * \returns The current stored fragments.
517 */
518 std::list<Ptr<Packet>> GetFragments() const;
519
520 /**
521 * \brief Set the Timeout iterator.
522 * \param iter The iterator.
523 */
525
526 /**
527 * \brief Get the Timeout iterator.
528 * \returns The iterator.
529 */
531
532 private:
533 /**
534 * \brief The size of the reconstructed packet (bytes).
535 */
537
538 /**
539 * \brief The current fragments.
540 */
541 std::list<std::pair<Ptr<Packet>, uint16_t>> m_fragments;
542
543 /**
544 * \brief The very first fragment.
545 */
547
548 /**
549 * \brief Timeout iterator to "event" handler
550 */
552 };
553
554 /**
555 * \brief Performs a packet fragmentation.
556 * \param [in] packet the packet to be fragmented (with headers already compressed with
557 * 6LoWPAN).
558 * \param [in] origPacketSize the size of the IP packet before the 6LoWPAN header compression,
559 * including the IP/L4 headers.
560 * \param [in] origHdrSize the size of the IP header before the 6LoWPAN header compression.
561 * \param [in] extraHdrSize the sum of the sizes of BC0 header and MESH header if mesh routing
562 * is used or 0.
563 * \param [out] listFragments A reference to the list of the resulting packets, all with the
564 * proper headers in place.
565 */
566 void DoFragmentation(Ptr<Packet> packet,
567 uint32_t origPacketSize,
568 uint32_t origHdrSize,
569 uint32_t extraHdrSize,
570 std::list<Ptr<Packet>>& listFragments);
571
572 /**
573 * \brief Process a packet fragment.
574 * \param [in] packet The packet.
575 * \param [in] src The source MAC address.
576 * \param [in] dst The destination MAC address.
577 * \param [in] isFirst True if it is the first fragment, false otherwise.
578 * \return True is the fragment completed the packet.
579 */
580 bool ProcessFragment(Ptr<Packet>& packet, const Address& src, const Address& dst, bool isFirst);
581
582 /**
583 * \brief Process the timeout for packet fragments.
584 * \param [in] key A key representing the packet fragments.
585 * \param [in] iif Input Interface.
586 */
588
589 /**
590 * \brief Drops the oldest fragment set.
591 */
593
594 /**
595 * Get a Mac16 from its Mac48 pseudo-MAC
596 * \param addr the PseudoMac address
597 * \return the Mac16Address
598 */
600
601 /**
602 * Container for fragment key -> fragments.
603 */
604 typedef std::map<FragmentKey_t, Ptr<Fragments>> MapFragments_t;
605 /**
606 * Container Iterator for fragment key -> fragments.
607 */
608 typedef std::map<FragmentKey_t, Ptr<Fragments>>::iterator MapFragmentsI_t;
609
610 MapFragments_t m_fragments; //!< Fragments hold to be rebuilt.
611 Time m_fragmentExpirationTimeout; //!< Time limit for fragment rebuilding.
612
613 /**
614 * \brief How many packets can be rebuilt at the same time.
615 * Some real implementation do limit this. Zero means no limit.
616 */
618
619 bool m_useIphc; //!< Use IPHC or HC1.
620
621 bool m_meshUnder; //!< Use a mesh-under routing.
622 uint8_t m_bc0Serial; //!< Serial number used in BC0 header.
623 uint8_t m_meshUnderHopsLeft; //!< Start value for mesh-under hops left.
624 uint16_t m_meshCacheLength; //!< length of the cache for each source.
626 m_meshUnderJitter; //!< Random variable for the mesh-under packet retransmission.
627 std::map<Address /* OriginatorAddress */, std::list<uint8_t /* SequenceNumber */>>
628 m_seenPkts; //!< Seen packets, memorized by OriginatorAddress, SequenceNumber.
629
630 Ptr<Node> m_node; //!< Smart pointer to the Node.
631 Ptr<NetDevice> m_netDevice; //!< Smart pointer to the underlying NetDevice.
632 uint32_t m_ifIndex; //!< Interface index.
633
634 bool m_omitUdpChecksum; //!< Omit UDP checksum in NC1 encoding.
635
636 uint32_t m_compressionThreshold; //!< Minimum L2 payload size.
637
638 Ptr<UniformRandomVariable> m_rng; //!< Rng for the fragments tag.
639
640 /**
641 * Structure holding the information for a context (used in compression and decompression)
642 */
644 {
645 Ipv6Prefix contextPrefix; //!< context prefix to be used in compression/decompression
646 bool compressionAllowed; //!< compression and decompression allowed (true), decompression
647 //!< only (false)
648 Time validLifetime; //!< validity period
649 };
650
651 std::map<uint8_t, ContextEntry>
652 m_contextTable; //!< Table of the contexts used in compression/decompression
653
654 /**
655 * \brief Finds if the given unicast address matches a context for compression
656 *
657 * \param[in] address the address to check
658 * \param[out] contextId the context found
659 * \return true if a valid context has been found
660 */
661 bool FindUnicastCompressionContext(Ipv6Address address, uint8_t& contextId);
662
663 /**
664 * \brief Finds if the given multicast address matches a context for compression
665 *
666 * \param[in] address the address to check
667 * \param[out] contextId the context found
668 * \return true if a valid context has been found
669 */
670 bool FindMulticastCompressionContext(Ipv6Address address, uint8_t& contextId);
671
672 /**
673 * \brief Clean an address from its prefix.
674 *
675 * This function is used to find the relevant bits to be sent in stateful IPHC compression.
676 * Only the prefix length is used - the address prefix is assumed to be matching the prefix.
677 *
678 * \param address the address to be cleaned
679 * \param prefix the prefix to remove
680 * \return An address with the prefix zeroed.
681 */
683};
684
685} // namespace ns3
686
687#endif /* SIXLOWPAN_NET_DEVICE_H */
a polymophic address class
Definition: address.h:101
Callback template class.
Definition: callback.h:438
An identifier for simulation events.
Definition: event-id.h:55
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:42
Describes an IPv6 address.
Definition: ipv6-address.h:49
Describes an IPv6 prefix.
Definition: ipv6-address.h:455
Network layer to device interface.
Definition: net-device.h:98
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:300
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
A template-based reference counting class.
void SetTimeoutIter(FragmentsTimeoutsListI_t iter)
Set the Timeout iterator.
bool IsEntire() const
If all fragments have been added.
FragmentsTimeoutsListI_t m_timeoutIter
Timeout iterator to "event" handler.
std::list< Ptr< Packet > > GetFragments() const
Get a list of the current stored fragments.
void SetPacketSize(uint32_t packetSize)
Set the packet-to-be-defragmented size.
void AddFragment(Ptr< Packet > fragment, uint16_t fragmentOffset)
Add a fragment to the pool.
uint32_t m_packetSize
The size of the reconstructed packet (bytes).
FragmentsTimeoutsListI_t GetTimeoutIter()
Get the Timeout iterator.
Ptr< Packet > GetPacket() const
Get the entire packet.
std::list< std::pair< Ptr< Packet >, uint16_t > > m_fragments
The current fragments.
Ptr< Packet > m_firstFragment
The very first fragment.
void AddFirstFragment(Ptr< Packet > fragment)
Add the first packet fragment.
Shim performing 6LoWPAN compression, decompression and fragmentation.
std::map< FragmentKey_t, Ptr< Fragments > > MapFragments_t
Container for fragment key -> fragments.
bool IsLinkUp() const override
std::map< FragmentKey_t, Ptr< Fragments > >::iterator MapFragmentsI_t
Container Iterator for fragment key -> fragments.
bool SetMtu(const uint16_t mtu) override
void DecompressLowPanUdpNhc(Ptr< Packet > packet, Ipv6Address saddr, Ipv6Address daddr)
Decompress the headers according to NHC compression.
bool DoSend(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber, bool doSendFrom)
Ipv6Address CleanPrefix(Ipv6Address address, Ipv6Prefix prefix)
Clean an address from its prefix.
void(* DropTracedCallback)(DropReason reason, Ptr< const Packet > packet, Ptr< SixLowPanNetDevice > sixNetDevice, uint32_t ifindex)
TracedCallback signature for packet drop events.
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 DropOldestFragmentSet()
Drops the oldest fragment set.
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.
DropReason
Enumeration of the dropping reasons in SixLoWPAN.
@ 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
SixLowPanNetDevice(const SixLowPanNetDevice &)=delete
std::list< std::tuple< Time, FragmentKey_t, uint32_t > > FragmentsTimeoutsList_t
Container for fragment timeouts.
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(* RxTxTracedCallback)(Ptr< const Packet > packet, Ptr< SixLowPanNetDevice > sixNetDevice, uint32_t ifindex)
TracedCallback signature for packet send/receive events.
SixLowPanNetDevice & operator=(const SixLowPanNetDevice &)=delete
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.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Structure holding the information for a context (used in compression and decompression)
Ipv6Prefix contextPrefix
context prefix to be used in compression/decompression
bool compressionAllowed
compression and decompression allowed (true), decompression only (false)
Time validLifetime
validity period
static const uint32_t packetSize
Packet size generated at the AP.