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 "ns3/traced-callback.h"
29 #include "ns3/event-id.h"
30 #include "ns3/nstime.h"
31 #include "ns3/net-device.h"
32 #include "ns3/packet.h"
33 #include "sixlowpan-header.h"
34 #include "ns3/random-variable-stream.h"
35 
36 namespace ns3 {
37 
38 class Node;
39 
65 {
66 public:
71  {
75  };
76 
81  static TypeId GetTypeId (void);
82 
87 
88  // inherited from NetDevice base class
89  virtual void SetIfIndex (const uint32_t index);
90  virtual uint32_t GetIfIndex (void) const;
91  virtual Ptr<Channel> GetChannel (void) const;
92  virtual void SetAddress (Address address);
93  virtual Address GetAddress (void) const;
94  virtual bool SetMtu (const uint16_t mtu);
95 
103  virtual uint16_t GetMtu (void) const;
104  virtual bool IsLinkUp (void) const;
105  virtual void AddLinkChangeCallback (Callback<void> callback);
106  virtual bool IsBroadcast (void) const;
107  virtual Address GetBroadcast (void) const;
108  virtual bool IsMulticast (void) const;
109  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
110  virtual bool IsPointToPoint (void) const;
111  virtual bool IsBridge (void) const;
112  virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
113  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
114  virtual Ptr<Node> GetNode (void) const;
115  virtual void SetNode (Ptr<Node> node);
116  virtual bool NeedsArp (void) const;
119  virtual bool SupportsSendFrom () const;
120  virtual Address GetMulticast (Ipv6Address addr) const;
121 
127  Ptr<NetDevice> GetNetDevice () const;
128 
136  void SetNetDevice (Ptr<NetDevice> device);
137 
146  int64_t AssignStreams (int64_t stream);
147 
158  typedef void (* RxTxTracedCallback)
160  uint32_t ifindex);
161 
173  typedef void (* DropTracedCallback)
174  (DropReason reason, Ptr<const Packet> packet,
175  Ptr<SixLowPanNetDevice> sixNetDevice,
176  uint32_t ifindex);
177 
178 protected:
179  virtual void DoDispose (void);
180 
181 private:
205  void ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
206  Address const &source, Address const &destination, PacketType packetType);
207 
208 
223  bool DoSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber, bool doSendFrom);
224 
229 
234 
247 
259  TracedCallback<Ptr<const Packet>, Ptr<SixLowPanNetDevice>, uint32_t> m_rxTrace;
260 
273  TracedCallback<DropReason, Ptr<const Packet>, Ptr<SixLowPanNetDevice>, uint32_t> m_dropTrace;
274 
281 
289 
297  uint32_t CompressLowPanHc1 (Ptr<Packet> packet, Address const &src, Address const &dst);
298 
305  void DecompressLowPanHc1 (Ptr<Packet> packet, Address const &src, Address const &dst);
306 
314  uint32_t CompressLowPanIphc (Ptr<Packet> packet, Address const &src, Address const &dst);
315 
321  bool CanCompressLowPanNhc (uint8_t headerType);
322 
329  void DecompressLowPanIphc (Ptr<Packet> packet, Address const &src, Address const &dst);
330 
339  uint32_t CompressLowPanNhc (Ptr<Packet> packet, uint8_t headerType, Address const &src, Address const &dst);
340 
350  uint8_t DecompressLowPanNhc (Ptr<Packet> packet, Address const &src, Address const &dst, Ipv6Address srcAddress, Ipv6Address dstAddress);
351 
358  uint32_t CompressLowPanUdpNhc (Ptr<Packet> packet, bool omitChecksum);
359 
366  void DecompressLowPanUdpNhc (Ptr<Packet> packet, Ipv6Address saddr, Ipv6Address daddr);
367 
371  typedef std::pair< std::pair<Address, Address>, std::pair<uint16_t, uint16_t> > FragmentKey;
372 
376  class Fragments : public SimpleRefCount<Fragments>
377  {
378 public:
382  Fragments ();
383 
387  ~Fragments ();
388 
394  void AddFragment (Ptr<Packet> fragment, uint16_t fragmentOffset);
395 
401  void AddFirstFragment (Ptr<Packet> fragment);
402 
407  bool IsEntire () const;
408 
413  Ptr<Packet> GetPacket () const;
414 
419  void SetPacketSize (uint32_t packetSize);
420 
425  std::list< Ptr<Packet> > GetFraments () const;
426 
427 private:
431  uint32_t m_packetSize;
432 
436  std::list<std::pair<Ptr<Packet>, uint16_t> > m_fragments;
437 
442 
443  };
444 
452  void DoFragmentation (Ptr<Packet> packet, uint32_t origPacketSize, uint32_t origHdrSize,
453  std::list<Ptr<Packet> >& listFragments);
454 
463  bool ProcessFragment (Ptr<Packet>& packet, Address const &src, Address const &dst, bool isFirst);
464 
470  void HandleFragmentsTimeout ( FragmentKey key, uint32_t iif);
471 
475  void DropOldestFragmentSet ();
476 
480  typedef std::map< FragmentKey, Ptr<Fragments> > MapFragments_t;
484  typedef std::map< FragmentKey, Ptr<Fragments> >::iterator MapFragmentsI_t;
488  typedef std::map< FragmentKey, EventId > MapFragmentsTimers_t;
492  typedef std::map< FragmentKey, EventId >::iterator MapFragmentsTimersI_t;
493 
494  MapFragments_t m_fragments;
495  MapFragmentsTimers_t m_fragmentsTimers;
497 
503 
504  bool m_useIphc;
505 
508  uint32_t m_ifIndex;
509 
515 
516  uint16_t m_etherType;
518 
520 
522 };
523 
524 } // namespace ns3
525 
526 #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:102
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
std::map< FragmentKey, 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...
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.
Forward calls to a chain of Callback.
Ptr< Packet > m_firstFragment
The very first fragment.
virtual bool IsMulticast(void) const
static TypeId GetTypeId(void)
Get the type ID.
virtual Ptr< Channel > GetChannel(void) const
std::pair< std::pair< Address, Address >, std::pair< uint16_t, uint16_t > > FragmentKey
Fragment identifier type: src/dst address src/dst port.
uint16_t m_fragmentReassemblyListSize
How many packets can be rebuilt at the same time.
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
virtual bool SetMtu(const uint16_t mtu)
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
std::map< FragmentKey, EventId >::iterator MapFragmentsTimersI_t
Container Iterator for fragment key -> expiration event.
virtual uint32_t GetIfIndex(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.
uint32_t m_packetSize
The size of the reconstructed packet (bytes).
Ptr< NetDevice > GetNetDevice() const
Returns a smart pointer to the underlying NetDevice.
virtual bool IsLinkUp(void) const
TracedCallback< DropReason, Ptr< const Packet >, Ptr< SixLowPanNetDevice >, uint32_t > m_dropTrace
Callback to trace drop packets.
virtual void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb)
#define list
Time m_fragmentExpirationTimeout
Time limit for fragment rebuilding.
virtual bool NeedsArp(void) const
virtual bool IsBroadcast(void) const
bool m_forceEtherType
Force the EtherType number.
std::map< FragmentKey, Ptr< Fragments > >::iterator MapFragmentsI_t
Container Iterator for fragment key -> fragments.
virtual void SetNode(Ptr< Node > node)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::list< Ptr< Packet > > GetFraments() const
Get a list of the current stored fragments.
address
Definition: first.py:37
uint32_t m_compressionThreshold
Minimum L2 payload size.
Shim performing 6LoWPAN compression, decompression and fragmentation.
Ipv6Address MakeLinkLocalAddressFromMac(Address const &addr)
Make a link-local address from a MAC address.
bool IsEntire() const
If all fragments have been added.
virtual Ptr< Node > GetNode(void) const
MapFragmentsTimers_t m_fragmentsTimers
Timers related to fragment rebuilding.
virtual Address GetBroadcast(void) const
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 IsBridge(void) const
Return true if the net device is acting as a bridge.
Ptr< Packet > GetPacket() const
Get the entire packet.
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:40
SixLowPanNetDevice()
Constructor for the SixLowPanNetDevice.
Ipv6Address MakeGlobalAddressFromMac(Address const &addr, Ipv6Address prefix)
Make a global address from a MAC address.
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.
Network layer to device interface.
Definition: net-device.h:95
virtual bool SupportsSendFrom() const
void(* RxTxTracedCallback)(Ptr< const Packet > packet, Ptr< SixLowPanNetDevice > sixNetDevice, uint32_t ifindex)
TracedCallback signature for packet send/receive events.
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
virtual Address GetAddress(void) const
std::list< std::pair< Ptr< Packet >, uint16_t > > m_fragments
The current 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.
virtual uint16_t GetMtu(void) const
Returns the link-layer MTU for this interface.
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
static const uint32_t packetSize
Ptr< NetDevice > m_netDevice
Smart pointer to the underlying NetDevice.
void HandleFragmentsTimeout(FragmentKey key, uint32_t iif)
Process the timeout for packet fragments.
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:302
std::map< FragmentKey, EventId > MapFragmentsTimers_t
Container for fragment key -> expiration event.
uint32_t CompressLowPanHc1(Ptr< Packet > packet, Address const &src, Address const &dst)
Compress the headers according to HC1 compression.
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
A template-based reference counting class.
a unique identifier for an interface.
Definition: type-id.h:58
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.