A Discrete-Event Network Simulator
API
sixlowpan-net-device.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Universita' di Firenze, Italy
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
19  * Michele Muccio <michelemuccio@virgilio.it>
20  */
21 
22 #ifndef SIXLOWPAN_NET_DEVICE_H
23 #define SIXLOWPAN_NET_DEVICE_H
24 
25 #include <stdint.h>
26 #include <string>
27 #include <map>
28 #include <tuple>
29 #include "ns3/traced-callback.h"
30 #include "ns3/nstime.h"
31 #include "ns3/net-device.h"
32 #include "ns3/random-variable-stream.h"
33 #include "ns3/simulator.h"
34 
35 namespace ns3 {
36 
37 class Node;
38 class UniformRandomVariable;
39 class EventId;
40 
66 {
67 public:
72  {
77  };
78 
83  static TypeId GetTypeId (void);
84 
89 
90  // inherited from NetDevice base class
91  virtual void SetIfIndex (const uint32_t index);
92  virtual uint32_t GetIfIndex (void) const;
93  virtual Ptr<Channel> GetChannel (void) const;
94  virtual void SetAddress (Address address);
95  virtual Address GetAddress (void) const;
96  virtual bool SetMtu (const uint16_t mtu);
97 
105  virtual uint16_t GetMtu (void) const;
106  virtual bool IsLinkUp (void) const;
107  virtual void AddLinkChangeCallback (Callback<void> callback);
108  virtual bool IsBroadcast (void) const;
109  virtual Address GetBroadcast (void) const;
110  virtual bool IsMulticast (void) const;
111  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
112  virtual bool IsPointToPoint (void) const;
113  virtual bool IsBridge (void) const;
114  virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
115  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
116  virtual Ptr<Node> GetNode (void) const;
117  virtual void SetNode (Ptr<Node> node);
118  virtual bool NeedsArp (void) const;
121  virtual bool SupportsSendFrom () const;
122  virtual Address GetMulticast (Ipv6Address addr) const;
123 
129  Ptr<NetDevice> GetNetDevice () const;
130 
138  void SetNetDevice (Ptr<NetDevice> device);
139 
148  int64_t AssignStreams (int64_t stream);
149 
160  typedef void (* RxTxTracedCallback)(Ptr<const Packet> packet,
161  Ptr<SixLowPanNetDevice> sixNetDevice,
162  uint32_t ifindex);
163 
175  typedef void (* DropTracedCallback)(DropReason reason,
176  Ptr<const Packet> packet,
177  Ptr<SixLowPanNetDevice> sixNetDevice,
178  uint32_t ifindex);
179 
180 protected:
181  virtual void DoDispose (void);
182 
183 private:
207  void ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
208  Address const &source, Address const &destination, PacketType packetType);
209 
210 
225  bool DoSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber, bool doSendFrom);
226 
231 
236 
249 
262 
276 
284  uint32_t CompressLowPanHc1 (Ptr<Packet> packet, Address const &src, Address const &dst);
285 
292  void DecompressLowPanHc1 (Ptr<Packet> packet, Address const &src, Address const &dst);
293 
301  uint32_t CompressLowPanIphc (Ptr<Packet> packet, Address const &src, Address const &dst);
302 
308  bool CanCompressLowPanNhc (uint8_t headerType);
309 
316  void DecompressLowPanIphc (Ptr<Packet> packet, Address const &src, Address const &dst);
317 
326  uint32_t CompressLowPanNhc (Ptr<Packet> packet, uint8_t headerType, Address const &src, Address const &dst);
327 
337  uint8_t DecompressLowPanNhc (Ptr<Packet> packet, Address const &src, Address const &dst, Ipv6Address srcAddress, Ipv6Address dstAddress);
338 
345  uint32_t CompressLowPanUdpNhc (Ptr<Packet> packet, bool omitChecksum);
346 
353  void DecompressLowPanUdpNhc (Ptr<Packet> packet, Ipv6Address saddr, Ipv6Address daddr);
354 
358  typedef std::pair< std::pair<Address, Address>, std::pair<uint16_t, uint16_t> > FragmentKey_t;
359 
361  typedef std::list< std::tuple <Time, FragmentKey_t, uint32_t > > FragmentsTimeoutsList_t;
363  typedef std::list< std::tuple <Time, FragmentKey_t, uint32_t > >::iterator FragmentsTimeoutsListI_t;
364 
372 
376  void HandleTimeout (void);
377 
379 
381 
385  class Fragments : public SimpleRefCount<Fragments>
386  {
387 public:
391  Fragments ();
392 
396  ~Fragments ();
397 
403  void AddFragment (Ptr<Packet> fragment, uint16_t fragmentOffset);
404 
410  void AddFirstFragment (Ptr<Packet> fragment);
411 
416  bool IsEntire () const;
417 
422  Ptr<Packet> GetPacket () const;
423 
428  void SetPacketSize (uint32_t packetSize);
429 
434  std::list< Ptr<Packet> > GetFraments () const;
435 
441 
447 
448 private:
452  uint32_t m_packetSize;
453 
457  std::list<std::pair<Ptr<Packet>, uint16_t> > m_fragments;
458 
463 
468  };
469 
477  void DoFragmentation (Ptr<Packet> packet, uint32_t origPacketSize, uint32_t origHdrSize,
478  std::list<Ptr<Packet> >& listFragments);
479 
488  bool ProcessFragment (Ptr<Packet>& packet, Address const &src, Address const &dst, bool isFirst);
489 
495  void HandleFragmentsTimeout (FragmentKey_t key, uint32_t iif);
496 
500  void DropOldestFragmentSet ();
501 
508 
512  typedef std::map< FragmentKey_t, Ptr<Fragments> > MapFragments_t;
516  typedef std::map< FragmentKey_t, Ptr<Fragments> >::iterator MapFragmentsI_t;
517 
520 
526 
527  bool m_useIphc;
528 
529  bool m_meshUnder;
530  uint8_t m_bc0Serial;
532  uint16_t m_meshCacheLength;
534  std::map <Address /* OriginatorAdddress */, std::list <uint8_t /* SequenceNumber */> > m_seenPkts;
535 
538  uint32_t m_ifIndex;
539 
545 
546  uint16_t m_etherType;
548 
550 
552 };
553 
554 } // namespace ns3
555 
556 #endif /* SIXLOWPAN_NET_DEVICE_H */
void DropOldestFragmentSet()
Drops the oldest fragment set.
void DecompressLowPanUdpNhc(Ptr< Packet > packet, Ipv6Address saddr, Ipv6Address daddr)
Decompress the headers according to NHC compression.
SixLowPanNetDevice & operator=(SixLowPanNetDevice const &)
Copy constructor.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
std::pair< std::pair< Address, Address >, std::pair< uint16_t, uint16_t > > FragmentKey_t
Fragment identifier type: src/dst address src/dst port.
void HandleTimeout(void)
Handles a fragmented packet timeout.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
std::map< FragmentKey_t, Ptr< Fragments > > MapFragments_t
Container for fragment key -> fragments.
NetDevice::PromiscReceiveCallback m_promiscRxCallback
The callback used to notify higher layers that a packet has been received in promiscuous mode...
EventId m_timeoutEvent
Event for the next scheduled timeout.
virtual void SetIfIndex(const uint32_t index)
void SetPacketSize(uint32_t packetSize)
Set the packet-to-be-defragmented size.
void AddFirstFragment(Ptr< Packet > fragment)
Add the first packet fragment.
TracedCallback< Ptr< const Packet >, Ptr< SixLowPanNetDevice >, uint32_t > m_txTrace
Callback to trace TX (transmission) packets.
static const uint32_t packetSize
Forward calls to a chain of Callback.
Ptr< Packet > m_firstFragment
The very first fragment.
void SetTimeoutIter(FragmentsTimeoutsListI_t iter)
Set the Timeout iterator.
static TypeId GetTypeId(void)
Get the type ID.
virtual bool IsBroadcast(void) const
FragmentsTimeoutsListI_t GetTimeoutIter()
Get the Timeout iterator.
std::list< std::tuple< Time, FragmentKey_t, uint32_t > >::iterator FragmentsTimeoutsListI_t
Container Iterator for fragment timeouts.
uint16_t m_fragmentReassemblyListSize
How many packets can be rebuilt at the same time.
virtual Address GetAddress(void) const
void HandleFragmentsTimeout(FragmentKey_t key, uint32_t iif)
Process the timeout for packet fragments.
uint8_t m_bc0Serial
Serial number used in BC0 header.
virtual bool SetMtu(const uint16_t mtu)
bool IsEntire() const
If all fragments have been added.
void SetNetDevice(Ptr< NetDevice > device)
Setup SixLowPan to be a proxy for the specified NetDevice.
DropReason
Enumeration of the dropping reasons in SixLoWPAN.
a polymophic address class
Definition: address.h:90
virtual bool IsMulticast(void) const
uint32_t CompressLowPanNhc(Ptr< Packet > packet, uint8_t headerType, Address const &src, Address const &dst)
Compress the headers according to NHC compression.
bool m_useIphc
Use IPHC or HC1.
Ptr< Node > m_node
Smart pointer to the Node.
uint32_t CompressLowPanUdpNhc(Ptr< Packet > packet, bool omitChecksum)
Compress the headers according to NHC compression.
uint32_t CompressLowPanIphc(Ptr< Packet > packet, Address const &src, Address const &dst)
Compress the headers according to IPHC compression.
std::map< Address, std::list< uint8_t > > m_seenPkts
Seen packets, memorized by OriginatorAdddress, SequenceNumber.
Ptr< Packet > GetPacket() const
Get the entire packet.
Ptr< RandomVariableStream > m_meshUnderJitter
Random variable for the mesh-under packet retransmission.
uint32_t m_packetSize
The size of the reconstructed packet (bytes).
std::list< Ptr< Packet > > GetFraments() const
Get a list of the current stored fragments.
bool m_meshUnder
Use a mesh-under routing.
TracedCallback< DropReason, Ptr< const Packet >, Ptr< SixLowPanNetDevice >, uint32_t > m_dropTrace
Callback to trace drop packets.
virtual void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb)
#define list
virtual Ptr< Channel > GetChannel(void) const
Time m_fragmentExpirationTimeout
Time limit for fragment rebuilding.
bool m_forceEtherType
Force the EtherType number.
virtual bool NeedsArp(void) const
virtual uint32_t GetIfIndex(void) const
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
virtual void SetNode(Ptr< Node > node)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
address
Definition: first.py:44
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
uint32_t m_compressionThreshold
Minimum L2 payload size.
Shim performing 6LoWPAN compression, decompression and fragmentation.
Address Get16MacFrom48Mac(Address addr)
Get a Mac16 from its Mac48 pseudo-MAC.
std::list< std::tuple< Time, FragmentKey_t, uint32_t > > FragmentsTimeoutsList_t
Container for fragment timeouts.
virtual void AddLinkChangeCallback(Callback< void > callback)
NetDevice::ReceiveCallback m_rxCallback
The callback used to notify higher layers that a packet has been received.
void DoFragmentation(Ptr< Packet > packet, uint32_t origPacketSize, uint32_t origHdrSize, std::list< Ptr< Packet > > &listFragments)
Performs a packet fragmentation.
void(* DropTracedCallback)(DropReason reason, Ptr< const Packet > packet, Ptr< SixLowPanNetDevice > sixNetDevice, uint32_t ifindex)
TracedCallback signature for.
virtual bool SupportsSendFrom() const
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
uint16_t m_etherType
EtherType number (used only if m_forceEtherType is true).
Describes an IPv6 address.
Definition: ipv6-address.h:49
void DecompressLowPanIphc(Ptr< Packet > packet, Address const &src, Address const &dst)
Decompress the headers according to IPHC compression.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
SixLowPanNetDevice()
Constructor for the SixLowPanNetDevice.
virtual Ptr< Node > GetNode(void) const
void ReceiveFromDevice(Ptr< NetDevice > device, Ptr< const Packet > packet, uint16_t protocol, Address const &source, Address const &destination, PacketType packetType)
Receives all the packets from a NetDevice for further processing.
FragmentsTimeoutsListI_t m_timeoutIter
Timeout iterator to "event" handler.
An identifier for simulation events.
Definition: event-id.h:53
Network layer to device interface.
Definition: net-device.h:95
void(* RxTxTracedCallback)(Ptr< const Packet > packet, Ptr< SixLowPanNetDevice > sixNetDevice, uint32_t ifindex)
TracedCallback signature for packet send/receive events.
std::list< std::pair< Ptr< Packet >, uint16_t > > m_fragments
The current fragments.
FragmentsTimeoutsList_t m_timeoutEventList
Timeout "events" container.
std::map< FragmentKey_t, Ptr< Fragments > >::iterator MapFragmentsI_t
Container Iterator for fragment key -> fragments.
bool CanCompressLowPanNhc(uint8_t headerType)
Checks if the next header can be compressed using NHC.
bool m_omitUdpChecksum
Omit UDP checksum in NC1 encoding.
bool DoSend(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber, bool doSendFrom)
TracedCallback< Ptr< const Packet >, Ptr< SixLowPanNetDevice >, uint32_t > m_rxTrace
Callback to trace RX (reception) packets.
uint16_t m_meshCacheLength
length of the cache for each source.
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
FragmentsTimeoutsListI_t SetTimeout(FragmentKey_t key, uint32_t iif)
Set a new timeout "event" for a fragmented packet.
Ptr< NetDevice > m_netDevice
Smart pointer to the underlying NetDevice.
void AddFragment(Ptr< Packet > fragment, uint16_t fragmentOffset)
Add a fragment to the pool.
bool ProcessFragment(Ptr< Packet > &packet, Address const &src, Address const &dst, bool isFirst)
Process a packet fragment.
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:296
Ptr< NetDevice > GetNetDevice() const
Returns a smart pointer to the underlying NetDevice.
virtual bool IsLinkUp(void) const
virtual uint16_t GetMtu(void) const
Returns the link-layer MTU for this interface.
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
uint32_t CompressLowPanHc1(Ptr< Packet > packet, Address const &src, Address const &dst)
Compress the headers according to HC1 compression.
virtual Address GetBroadcast(void) const
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
A template-based reference counting class.
a unique identifier for an interface.
Definition: type-id.h:58
uint8_t m_meshUnderHopsLeft
Start value for mesh-under hops left.
uint32_t m_ifIndex
Interface index.
uint8_t DecompressLowPanNhc(Ptr< Packet > packet, Address const &src, Address const &dst, Ipv6Address srcAddress, Ipv6Address dstAddress)
Decompress the headers according to NHC compression.
virtual void SetAddress(Address address)
Set the address of this interface.
void DecompressLowPanHc1(Ptr< Packet > packet, Address const &src, Address const &dst)
Decompress the headers according to HC1 compression.
MapFragments_t m_fragments
Fragments hold to be rebuilt.
Ptr< UniformRandomVariable > m_rng
Rng for the fragments tag.
virtual void DoDispose(void)
Destructor implementation.