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