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 * Compression type.
80 */
82 {
83 HC1, //!< HC1 (RFC4944)
84 IPHC, //!< IPHC (RFC6282)
85 };
86
87 /**
88 * @brief The protocol number for 6LoWPAN (0xA0ED) - see \RFC{7973}.
89 */
90 static constexpr uint16_t PROT_NUMBER{0xA0ED};
91
92 /**
93 * @brief Get the type ID.
94 * @return The object TypeId.
95 */
96 static TypeId GetTypeId();
97
98 /**
99 * Constructor for the SixLowPanNetDevice.
100 */
102
103 // Delete copy constructor and assignment operator to avoid misuse
106
107 // inherited from NetDevice base class
108 void SetIfIndex(const uint32_t index) override;
109 uint32_t GetIfIndex() const override;
110 Ptr<Channel> GetChannel() const override;
111 void SetAddress(Address address) override;
112 Address GetAddress() const override;
113 bool SetMtu(const uint16_t mtu) override;
114
115 /**
116 * @brief Returns the link-layer MTU for this interface.
117 * If the link-layer MTU is smaller than IPv6's minimum MTU (\RFC{4944}),
118 * 1280 will be returned.
119 *
120 * @return The link-level MTU in bytes for this interface.
121 */
122 uint16_t GetMtu() const override;
123 bool IsLinkUp() const override;
124 void AddLinkChangeCallback(Callback<void> callback) override;
125 bool IsBroadcast() const override;
126 Address GetBroadcast() const override;
127 bool IsMulticast() const override;
128 Address GetMulticast(Ipv4Address multicastGroup) const override;
129 bool IsPointToPoint() const override;
130 bool IsBridge() const override;
131 bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber) override;
132 bool SendFrom(Ptr<Packet> packet,
133 const Address& source,
134 const Address& dest,
135 uint16_t protocolNumber) override;
136 Ptr<Node> GetNode() const override;
137 void SetNode(Ptr<Node> node) override;
138 bool NeedsArp() const override;
141 bool SupportsSendFrom() const override;
142 Address GetMulticast(Ipv6Address addr) const override;
143
144 /**
145 * @brief Returns a smart pointer to the underlying NetDevice.
146 *
147 * @return A smart pointer to the underlying NetDevice.
148 */
150
151 /**
152 * @brief Setup SixLowPan to be a proxy for the specified NetDevice.
153 * All the packets incoming and outgoing from the NetDevice will be
154 * processed by SixLowPanNetDevice.
155 *
156 * @param [in] device A smart pointer to the NetDevice to be proxied.
157 */
158 void SetNetDevice(Ptr<NetDevice> device);
159
160 /**
161 * Assign a fixed random variable stream number to the random variables
162 * used by this model. Return the number of streams (possibly zero) that
163 * have been assigned.
164 *
165 * @param [in] stream First stream index to use.
166 * @return the number of stream indices assigned by this model.
167 */
168 int64_t AssignStreams(int64_t stream);
169
170 /**
171 * TracedCallback signature for packet send/receive events.
172 *
173 * @param [in] packet The packet.
174 * @param [in] sixNetDevice The SixLowPanNetDevice.
175 * @param [in] ifindex The ifindex of the device.
176 * @deprecated The non-const \c Ptr<SixLowPanNetDevice> argument
177 * is deprecated and will be changed to \c Ptr<const SixLowPanNetDevice>
178 * in a future release.
179 */
180 // NS_DEPRECATED() - tag for future removal
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 // NS_DEPRECATED() - tag for future removal
197 typedef void (*DropTracedCallback)(DropReason reason,
198 Ptr<const Packet> packet,
199 Ptr<SixLowPanNetDevice> sixNetDevice,
200 uint32_t ifindex);
201
202 /**
203 * Add, remove, or update a context used in IPHC stateful compression.
204 *
205 * A context with a zero validLifetime will be immediately removed.
206 *
207 * @param [in] contextId context id (must be between 0 and 15 included).
208 * @param [in] contextPrefix context prefix to be used in compression/decompression.
209 * @param [in] compressionAllowed compression and decompression allowed (true), decompression
210 * only (false).
211 * @param [in] validLifetime validity time (relative to the actual time).
212 * @param [in] source source of the context.
213 */
214 void AddContext(uint8_t contextId,
215 Ipv6Prefix contextPrefix,
216 bool compressionAllowed,
217 Time validLifetime,
219
220 /**
221 * Get a context used in IPHC stateful compression.
222 *
223 * @param [in] contextId context id (most be between 0 and 15 included).
224 * @param [out] contextPrefix context prefix to be used in compression/decompression.
225 * @param [out] compressionAllowed compression and decompression allowed (true), decompression
226 * only (false).
227 * @param [out] validLifetime validity time (relative to the actual time).
228 *
229 * @return false if the context has not been found.
230 *
231 */
232 bool GetContext(uint8_t contextId,
233 Ipv6Prefix& contextPrefix,
234 bool& compressionAllowed,
235 Time& validLifetime);
236
237 /**
238 * Renew a context used in IPHC stateful compression.
239 *
240 * The context will have its lifetime extended and its validity for compression re-enabled.
241 *
242 * @param [in] contextId context id (most be between 0 and 15 included).
243 * @param [in] validLifetime validity time (relative to the actual time).
244 */
245 void RenewContext(uint8_t contextId, Time validLifetime);
246
247 /**
248 * Invalidate a context used in IPHC stateful compression.
249 *
250 * An invalid context will not be used for compression but it will be used for decompression.
251 *
252 * @param [in] contextId context id (most be between 0 and 15 included).
253 */
254 void InvalidateContext(uint8_t contextId);
255
256 /**
257 * Remove a context used in IPHC stateful compression.
258 *
259 * @param [in] contextId context id (most be between 0 and 15 included).
260 */
261 void RemoveContext(uint8_t contextId);
262
263 protected:
264 void DoDispose() override;
265
266 private:
267 /**
268 * @brief Receives all the packets from a NetDevice for further processing.
269 * @param [in] device The NetDevice the packet ws received from.
270 * @param [in] packet The received packet.
271 * @param [in] protocol The protocol (if known).
272 * @param [in] source The source address.
273 * @param [in] destination The destination address.
274 * @param [in] packetType The packet kind (e.g., HOST, BROADCAST, etc.).
275 */
277 Ptr<const Packet> packet,
278 uint16_t protocol,
279 const Address& source,
280 const Address& destination,
281 PacketType packetType);
282
283 /**
284 * @param [in] packet Packet sent from above down to Network Device.
285 * @param [in] source Source mac address (only used if doSendFrom is true, i.e., "MAC
286 * spoofing").
287 * @param [in] dest Mac address of the destination (already resolved).
288 * @param [in] protocolNumber Identifies the type of payload contained in this packet. Used to
289 * call the right L3Protocol when the packet is received.
290 * @param [in] doSendFrom Perform a SendFrom instead of a Send.
291 *
292 * Called from higher layer to send packet into Network Device
293 * with the specified source and destination Addresses.
294 *
295 * @return Whether the Send operation succeeded.
296 */
297 bool DoSend(Ptr<Packet> packet,
298 const Address& source,
299 const Address& dest,
300 uint16_t protocolNumber,
301 bool doSendFrom);
302
303 /**
304 * The callback used to notify higher layers that a packet has been received.
305 */
307
308 /**
309 * The callback used to notify higher layers that a packet has been received in promiscuous
310 * mode.
311 */
313
314 /**
315 * @brief Callback to trace TX (transmission) packets.
316 *
317 * Data passed:
318 * \li Packet received (including 6LoWPAN header)
319 * \li Ptr to SixLowPanNetDevice
320 * \li interface index
321 * @deprecated The non-const \c Ptr<SixLowPanNetDevice> argument
322 * is deprecated and will be changed to \c Ptr<const SixLowPanNetDevice>
323 * in a future release.
324 */
325 // NS_DEPRECATED() - tag for future removal
327
328 /**
329 * @brief Callback to trace TX (transmission) packets.
330 *
331 * Data passed:
332 * \li Packet received (including 6LoWPAN header)
333 * \li Ptr to SixLowPanNetDevice
334 * \li interface index
335 * @deprecated The non-const \c Ptr<SixLowPanNetDevice> argument
336 * is deprecated and will be changed to \c Ptr<const SixLowPanNetDevice>
337 * in a future release.
338 */
340
341 /**
342 * @brief Callback to trace RX (reception) packets.
343 *
344 * Data passed:
345 * \li Packet received (including 6LoWPAN header)
346 * \li Ptr to SixLowPanNetDevice
347 * \li interface index
348 * @deprecated The non-const \c Ptr<SixLowPanNetDevice> argument
349 * is deprecated and will be changed to \c Ptr<const SixLowPanNetDevice>
350 * in a future release.
351 */
352 // NS_DEPRECATED() - tag for future removal
354
355 /**
356 * @brief Callback to trace RX (reception) packets.
357 *
358 * Data passed:
359 * \li Packet received (including 6LoWPAN header)
360 * \li Ptr to SixLowPanNetDevice
361 * \li interface index
362 * @deprecated The non-const \c Ptr<SixLowPanNetDevice> argument
363 * is deprecated and will be changed to \c Ptr<const SixLowPanNetDevice>
364 * in a future release.
365 */
367
368 /**
369 * @brief Callback to trace drop packets.
370 *
371 * Data passed:
372 * \li DropReason
373 * \li Packet dropped (including 6LoWPAN header)
374 * \li Ptr to SixLowPanNetDevice
375 * \li interface index
376 * @deprecated The non-const \c Ptr<SixLowPanNetDevice> argument
377 * is deprecated and will be changed to \c Ptr<const SixLowPanNetDevice>
378 * in a future release.
379 */
380 // NS_DEPRECATED() - tag for future removal
382
383 /**
384 * @brief Compress 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 * @return The size of the removed headers.
389 */
390 uint32_t CompressLowPanHc1(Ptr<Packet> packet, const Address& src, const Address& dst);
391
392 /**
393 * @brief Decompress the headers according to HC1 compression.
394 * @param [in] packet the packet to be compressed.
395 * @param [in] src the MAC source address.
396 * @param [in] dst the MAC destination address.
397 */
398 void DecompressLowPanHc1(Ptr<Packet> packet, const Address& src, const Address& dst);
399
400 /**
401 * @brief Compress the headers according to IPHC compression.
402 * @param [in] packet The packet to be compressed.
403 * @param [in] src The MAC source address.
404 * @param [in] dst The MAC destination address.
405 * @return The size of the removed headers.
406 */
407 uint32_t CompressLowPanIphc(Ptr<Packet> packet, const Address& src, const Address& dst);
408
409 /**
410 * @brief Checks if the next header can be compressed using NHC.
411 * @param [in] headerType The header kind to be compressed.
412 * @return True if the header can be compressed.
413 */
414 bool CanCompressLowPanNhc(uint8_t headerType);
415
416 /**
417 * @brief Decompress the headers according to IPHC compression.
418 * @param [in] packet The packet to be compressed.
419 * @param [in] src The MAC source address.
420 * @param [in] dst The MAC destination address.
421 * @return true if the packet can not be decompressed due to wrong context information.
422 */
423 bool DecompressLowPanIphc(Ptr<Packet> packet, const Address& src, const Address& dst);
424
425 /**
426 * @brief Compress the headers according to NHC compression.
427 * @param [in] packet The packet to be compressed.
428 * @param [in] headerType The header type.
429 * @param [in] src The MAC source address.
430 * @param [in] dst The MAC destination address.
431 * @return The size of the removed headers.
432 */
434 uint8_t headerType,
435 const Address& src,
436 const Address& dst);
437
438 /**
439 * @brief Decompress the headers according to NHC compression.
440 * @param [in] packet The packet to be compressed.
441 * @param [in] src The MAC source address.
442 * @param [in] dst The MAC destination address.
443 * @param [in] srcAddress The IPv6 source address.
444 * @param [in] dstAddress The IPv6 destination address.
445 * @return A std::pair containing the decompressed header type and a flag - true if the packet
446 * can not be decompressed due to wrong context information.
447 */
448 std::pair<uint8_t, bool> DecompressLowPanNhc(Ptr<Packet> packet,
449 const Address& src,
450 const Address& dst,
451 Ipv6Address srcAddress,
452 Ipv6Address dstAddress);
453
454 /**
455 * @brief Compress the headers according to NHC compression.
456 * @param [in] packet The packet to be compressed.
457 * @param [in] omitChecksum Omit UDP checksum (if true).
458 * @return The size of the removed headers.
459 */
460 uint32_t CompressLowPanUdpNhc(Ptr<Packet> packet, bool omitChecksum);
461
462 /**
463 * @brief Decompress the headers according to NHC compression.
464 * @param [in] packet The packet to be compressed.
465 * @param [in] saddr The IPv6 source address.
466 * @param [in] daddr The IPv6 destination address.
467 */
469
470 /**
471 * Fragment identifier type: src/dst address src/dst port.
472 */
473 typedef std::pair<std::pair<Address, Address>, std::pair<uint16_t, uint16_t>> FragmentKey_t;
474
475 /// Container for fragment timeouts.
476 typedef std::list<std::tuple<Time, FragmentKey_t, uint32_t>> FragmentsTimeoutsList_t;
477 /// Container Iterator for fragment timeouts.
478 typedef std::list<std::tuple<Time, FragmentKey_t, uint32_t>>::iterator FragmentsTimeoutsListI_t;
479
480 /**
481 * @brief Set a new timeout "event" for a fragmented packet
482 * @param key the fragment identification
483 * @param iif input interface of the packet
484 * @return an iterator to the inserted "event"
485 */
487
488 /**
489 * @brief Handles a fragmented packet timeout
490 */
491 void HandleTimeout();
492
493 FragmentsTimeoutsList_t m_timeoutEventList; //!< Timeout "events" container
494
495 EventId m_timeoutEvent; //!< Event for the next scheduled timeout
496
497 /**
498 * @brief A Set of Fragments.
499 */
501 {
502 public:
503 /**
504 * @brief Constructor.
505 */
506 Fragments();
507
508 /**
509 * @brief Destructor.
510 */
511 ~Fragments();
512
513 /**
514 * @brief Add a fragment to the pool.
515 * @param [in] fragment the fragment.
516 * @param [in] fragmentOffset the offset of the fragment.
517 */
518 void AddFragment(Ptr<Packet> fragment, uint16_t fragmentOffset);
519
520 /**
521 * @brief Add the first packet fragment. The first fragment is needed to
522 * allow the post-defragmentation decompression.
523 * @param [in] fragment The fragment.
524 */
525 void AddFirstFragment(Ptr<Packet> fragment);
526
527 /**
528 * @brief If all fragments have been added.
529 * @returns True if the packet is entire.
530 */
531 bool IsEntire() const;
532
533 /**
534 * @brief Get the entire packet.
535 * @return The entire packet.
536 */
537 Ptr<Packet> GetPacket() const;
538
539 /**
540 * @brief Set the packet-to-be-defragmented size.
541 * @param [in] packetSize The packet size (bytes).
542 */
544
545 /**
546 * @brief Get a list of the current stored fragments.
547 * @returns The current stored fragments.
548 */
549 std::list<Ptr<Packet>> GetFragments() const;
550
551 /**
552 * @brief Set the Timeout iterator.
553 * @param iter The iterator.
554 */
556
557 /**
558 * @brief Get the Timeout iterator.
559 * @returns The iterator.
560 */
562
563 private:
564 /**
565 * @brief The size of the reconstructed packet (bytes).
566 */
568
569 /**
570 * @brief The current fragments.
571 */
572 std::list<std::pair<Ptr<Packet>, uint16_t>> m_fragments;
573
574 /**
575 * @brief The very first fragment.
576 */
578
579 /**
580 * @brief Timeout iterator to "event" handler
581 */
583 };
584
585 /**
586 * @brief Performs a packet fragmentation.
587 * @param [in] packet the packet to be fragmented (with headers already compressed with
588 * 6LoWPAN).
589 * @param [in] origPacketSize the size of the IP packet before the 6LoWPAN header compression,
590 * including the IP/L4 headers.
591 * @param [in] origHdrSize the size of the IP header before the 6LoWPAN header compression.
592 * @param [in] extraHdrSize the sum of the sizes of BC0 header and MESH header if mesh routing
593 * is used or 0.
594 * @param [out] listFragments A reference to the list of the resulting packets, all with the
595 * proper headers in place.
596 */
597 void DoFragmentation(Ptr<Packet> packet,
598 uint32_t origPacketSize,
599 uint32_t origHdrSize,
600 uint32_t extraHdrSize,
601 std::list<Ptr<Packet>>& listFragments);
602
603 /**
604 * @brief Process a packet fragment.
605 * @param [in] packet The packet.
606 * @param [in] src The source MAC address.
607 * @param [in] dst The destination MAC address.
608 * @param [in] isFirst True if it is the first fragment, false otherwise.
609 * @return True is the fragment completed the packet.
610 */
611 bool ProcessFragment(Ptr<Packet>& packet, const Address& src, const Address& dst, bool isFirst);
612
613 /**
614 * @brief Process the timeout for packet fragments.
615 * @param [in] key A key representing the packet fragments.
616 * @param [in] iif Input Interface.
617 */
619
620 /**
621 * @brief Drops the oldest fragment set.
622 */
624
625 /**
626 * Get a Mac16 from its Mac48 pseudo-MAC
627 * @param addr the PseudoMac address
628 * @return the Mac16Address
629 */
631
632 /**
633 * Container for fragment key -> fragments.
634 */
635 typedef std::map<FragmentKey_t, std::shared_ptr<Fragments>> MapFragments_t;
636
637 MapFragments_t m_fragments; //!< Fragments hold to be rebuilt.
638 Time m_fragmentExpirationTimeout; //!< Time limit for fragment rebuilding.
639
640 /**
641 * @brief How many packets can be rebuilt at the same time.
642 * Some real implementation do limit this. Zero means no limit.
643 */
645
647
648 bool m_meshUnder; //!< Use a mesh-under routing.
649 uint8_t m_bc0Serial; //!< Serial number used in BC0 header.
650 uint8_t m_meshUnderHopsLeft; //!< Start value for mesh-under hops left.
651 uint16_t m_meshCacheLength; //!< length of the cache for each source.
653 m_meshUnderJitter; //!< Random variable for the mesh-under packet retransmission.
654 std::map<Address /* OriginatorAddress */, std::list<uint8_t /* SequenceNumber */>>
655 m_seenPkts; //!< Seen packets, memorized by OriginatorAddress, SequenceNumber.
656
657 Ptr<Node> m_node; //!< Smart pointer to the Node.
658 Ptr<NetDevice> m_netDevice; //!< Smart pointer to the underlying NetDevice.
659 uint32_t m_ifIndex; //!< Interface index.
660
661 bool m_omitUdpChecksum; //!< Omit UDP checksum in NC1 encoding.
662
663 uint32_t m_compressionThreshold; //!< Minimum L2 payload size.
664
665 Ptr<UniformRandomVariable> m_rng; //!< Rng for the fragments tag.
666
667 /**
668 * Structure holding the information for a context (used in compression and decompression)
669 */
671 {
672 Ipv6Prefix contextPrefix; //!< context prefix to be used in compression/decompression
673 bool compressionAllowed; //!< compression and decompression allowed (true), decompression
674 //!< only (false)
675 Time validLifetime; //!< validity period
676 Ipv6Address source; //!< Source of the context ("::" if from the Helper)
677 };
678
679 std::map<uint8_t, ContextEntry>
680 m_contextTable; //!< Table of the contexts used in compression/decompression
681
682 /**
683 * @brief Finds if the given unicast 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 FindUnicastCompressionContext(Ipv6Address address, uint8_t& contextId);
690
691 /**
692 * @brief Finds if the given multicast address matches a context for compression
693 *
694 * @param[in] address the address to check
695 * @param[out] contextId the context found
696 * @return true if a valid context has been found
697 */
698 bool FindMulticastCompressionContext(Ipv6Address address, uint8_t& contextId);
699
700 /**
701 * @brief Clean an address from its prefix.
702 *
703 * This function is used to find the relevant bits to be sent in stateful IPHC compression.
704 * Only the prefix length is used - the address prefix is assumed to be matching the prefix.
705 *
706 * @param address the address to be cleaned
707 * @param prefix the prefix to remove
708 * @return An address with the prefix zeroed.
709 */
711};
712
713} // namespace ns3
714
715#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:352
PacketType
Packet types are used as they are in Linux.
Definition net-device.h:300
Callback< bool, Ptr< NetDevice >, Ptr< const Packet >, uint16_t, const Address & > ReceiveCallback
Definition net-device.h:322
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.
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.
CompressionType_e m_compressionType
Compression type.
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.
CompressionType_e
Compression type.
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.