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