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
35namespace ns3 {
36
37class Node;
38class UniformRandomVariable;
39class EventId;
40
72{
73public:
78 {
84 };
85
90 static TypeId GetTypeId (void);
91
96
97 // Delete copy constructor and assignment operator to avoid misuse
100
101 // inherited from NetDevice base class
102 virtual void SetIfIndex (const uint32_t index);
103 virtual uint32_t GetIfIndex (void) const;
104 virtual Ptr<Channel> GetChannel (void) const;
105 virtual void SetAddress (Address address);
106 virtual Address GetAddress (void) const;
107 virtual bool SetMtu (const uint16_t mtu);
108
116 virtual uint16_t GetMtu (void) const;
117 virtual bool IsLinkUp (void) const;
118 virtual void AddLinkChangeCallback (Callback<void> callback);
119 virtual bool IsBroadcast (void) const;
120 virtual Address GetBroadcast (void) const;
121 virtual bool IsMulticast (void) const;
122 virtual Address GetMulticast (Ipv4Address multicastGroup) const;
123 virtual bool IsPointToPoint (void) const;
124 virtual bool IsBridge (void) const;
125 virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
126 virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
127 virtual Ptr<Node> GetNode (void) const;
128 virtual void SetNode (Ptr<Node> node);
129 virtual bool NeedsArp (void) const;
132 virtual bool SupportsSendFrom () const;
133 virtual Address GetMulticast (Ipv6Address addr) const;
134
141
149 void SetNetDevice (Ptr<NetDevice> device);
150
159 int64_t AssignStreams (int64_t stream);
160
171 typedef void (* RxTxTracedCallback)(Ptr<const Packet> packet,
172 Ptr<SixLowPanNetDevice> sixNetDevice,
173 uint32_t ifindex);
174
186 typedef void (* DropTracedCallback)(DropReason reason,
187 Ptr<const Packet> packet,
188 Ptr<SixLowPanNetDevice> sixNetDevice,
189 uint32_t ifindex);
190
202 void AddContext (uint8_t contextId, Ipv6Prefix contextPrefix, bool compressionAllowed, Time validLifetime);
203
215 bool GetContext (uint8_t contextId, Ipv6Prefix& contextPrefix, bool& compressionAllowed, Time& validLifetime);
216
225 void RenewContext (uint8_t contextId, Time validLifetime);
226
234 void InvalidateContext (uint8_t contextId);
235
241 void RemoveContext (uint8_t contextId);
242
243protected:
244 virtual void DoDispose (void);
245
246private:
256 void ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
257 Address const &source, Address const &destination, PacketType packetType);
258
259
274 bool DoSend (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber, bool doSendFrom);
275
280
285
298
311
325
333 uint32_t CompressLowPanHc1 (Ptr<Packet> packet, Address const &src, Address const &dst);
334
341 void DecompressLowPanHc1 (Ptr<Packet> packet, Address const &src, Address const &dst);
342
350 uint32_t CompressLowPanIphc (Ptr<Packet> packet, Address const &src, Address const &dst);
351
357 bool CanCompressLowPanNhc (uint8_t headerType);
358
366 bool DecompressLowPanIphc (Ptr<Packet> packet, Address const &src, Address const &dst);
367
376 uint32_t CompressLowPanNhc (Ptr<Packet> packet, uint8_t headerType, Address const &src, Address const &dst);
377
387 std::pair<uint8_t, bool> DecompressLowPanNhc (Ptr<Packet> packet, Address const &src, Address const &dst, Ipv6Address srcAddress, Ipv6Address dstAddress);
388
395 uint32_t CompressLowPanUdpNhc (Ptr<Packet> packet, bool omitChecksum);
396
403 void DecompressLowPanUdpNhc (Ptr<Packet> packet, Ipv6Address saddr, Ipv6Address daddr);
404
408 typedef std::pair< std::pair<Address, Address>, std::pair<uint16_t, uint16_t> > FragmentKey_t;
409
411 typedef std::list< std::tuple <Time, FragmentKey_t, uint32_t > > FragmentsTimeoutsList_t;
413 typedef std::list< std::tuple <Time, FragmentKey_t, uint32_t > >::iterator FragmentsTimeoutsListI_t;
414
422
426 void HandleTimeout (void);
427
429
431
435 class Fragments : public SimpleRefCount<Fragments>
436 {
437public:
441 Fragments ();
442
446 ~Fragments ();
447
453 void AddFragment (Ptr<Packet> fragment, uint16_t fragmentOffset);
454
460 void AddFirstFragment (Ptr<Packet> fragment);
461
466 bool IsEntire () const;
467
472 Ptr<Packet> GetPacket () const;
473
479
484 std::list< Ptr<Packet> > GetFraments () const;
485
491
497
498private:
503
507 std::list<std::pair<Ptr<Packet>, uint16_t> > m_fragments;
508
513
518 };
519
528 void DoFragmentation (Ptr<Packet> packet, uint32_t origPacketSize, uint32_t origHdrSize, uint32_t extraHdrSize,
529 std::list<Ptr<Packet> >& listFragments);
530
539 bool ProcessFragment (Ptr<Packet>& packet, Address const &src, Address const &dst, bool isFirst);
540
547
552
559
563 typedef std::map< FragmentKey_t, Ptr<Fragments> > MapFragments_t;
567 typedef std::map< FragmentKey_t, Ptr<Fragments> >::iterator MapFragmentsI_t;
568
571
577
579
581 uint8_t m_bc0Serial;
585 std::map <Address /* OriginatorAdddress */, std::list <uint8_t /* SequenceNumber */> > m_seenPkts;
586
590
596
597 uint16_t m_etherType;
599
601
603
608 {
612 };
613
614 std::map<uint8_t, ContextEntry> m_contextTable;
615
623 bool FindUnicastCompressionContext (Ipv6Address address, uint8_t& contextId);
624
632 bool FindMulticastCompressionContext (Ipv6Address address, uint8_t& contextId);
633
645};
646
647} // namespace ns3
648
649#endif /* SIXLOWPAN_NET_DEVICE_H */
a polymophic address class
Definition: address.h:91
An identifier for simulation events.
Definition: event-id.h:54
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
Describes an IPv6 address.
Definition: ipv6-address.h:50
Describes an IPv6 prefix.
Definition: ipv6-address.h:456
Network layer to device interface.
Definition: net-device.h:96
PacketType
Packet types are used as they are in Linux.
Definition: net-device.h:297
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.
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.
std::list< Ptr< Packet > > GetFraments() const
Get a list of the current stored 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.
bool DecompressLowPanIphc(Ptr< Packet > packet, Address const &src, Address const &dst)
Decompress the headers according to IPHC compression.
std::map< FragmentKey_t, Ptr< Fragments > >::iterator MapFragmentsI_t
Container Iterator for fragment key -> fragments.
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.
uint32_t CompressLowPanHc1(Ptr< Packet > packet, Address const &src, Address const &dst)
Compress the headers according to HC1 compression.
void(* DropTracedCallback)(DropReason reason, Ptr< const Packet > packet, Ptr< SixLowPanNetDevice > sixNetDevice, uint32_t ifindex)
TracedCallback signature fo packet drop events.
uint8_t m_bc0Serial
Serial number used in BC0 header.
EventId m_timeoutEvent
Event for the next scheduled timeout.
virtual Ptr< Channel > GetChannel(void) const
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 m_useIphc
Use IPHC or HC1.
void RenewContext(uint8_t contextId, Time validLifetime)
Renew a context used in IPHC stateful compression.
virtual Address GetAddress(void) const
virtual Address GetBroadcast(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.
void DoFragmentation(Ptr< Packet > packet, uint32_t origPacketSize, uint32_t origHdrSize, uint32_t extraHdrSize, std::list< Ptr< Packet > > &listFragments)
Performs a packet fragmentation.
virtual bool SupportsSendFrom() const
Ptr< Node > m_node
Smart pointer to the Node.
uint32_t CompressLowPanNhc(Ptr< Packet > packet, uint8_t headerType, Address const &src, Address const &dst)
Compress the headers according to NHC compression.
virtual void SetPromiscReceiveCallback(NetDevice::PromiscReceiveCallback cb)
bool CanCompressLowPanNhc(uint8_t headerType)
Checks if the next header can be compressed using NHC.
virtual void SetReceiveCallback(NetDevice::ReceiveCallback cb)
virtual Ptr< Node > GetNode(void) const
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.
bool m_forceEtherType
Force the EtherType number.
std::map< FragmentKey_t, Ptr< Fragments > > MapFragments_t
Container for fragment key -> fragments.
virtual uint32_t GetIfIndex(void) const
void DropOldestFragmentSet()
Drops the oldest fragment set.
virtual bool NeedsArp(void) const
uint32_t m_compressionThreshold
Minimum L2 payload size.
virtual void AddLinkChangeCallback(Callback< void > callback)
void DecompressLowPanHc1(Ptr< Packet > packet, Address const &src, Address const &dst)
Decompress the headers according to HC1 compression.
Ptr< NetDevice > GetNetDevice() const
Returns a smart pointer to the underlying NetDevice.
virtual bool Send(Ptr< Packet > packet, const Address &dest, uint16_t protocolNumber)
uint32_t CompressLowPanIphc(Ptr< Packet > packet, Address const &src, Address const &dst)
Compress the headers according to IPHC compression.
TracedCallback< Ptr< const Packet >, Ptr< SixLowPanNetDevice >, uint32_t > m_txTrace
Callback to trace TX (transmission) packets.
DropReason
Enumeration of the dropping reasons in SixLoWPAN.
@ DROP_DISALLOWED_COMPRESSION
HC1 while in IPHC mode or viceversa.
@ 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.
static TypeId GetTypeId(void)
Get the type ID.
Ptr< NetDevice > m_netDevice
Smart pointer to the underlying NetDevice.
std::pair< uint8_t, bool > DecompressLowPanNhc(Ptr< Packet > packet, Address const &src, Address const &dst, Ipv6Address srcAddress, Ipv6Address dstAddress)
Decompress the headers according to NHC compression.
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.
SixLowPanNetDevice & operator=(SixLowPanNetDevice const &)=delete
TracedCallback< Ptr< const Packet >, Ptr< SixLowPanNetDevice >, uint32_t > m_rxTrace
Callback to trace RX (reception) packets.
bool ProcessFragment(Ptr< Packet > &packet, Address const &src, Address const &dst, bool isFirst)
Process a packet fragment.
bool GetContext(uint8_t contextId, Ipv6Prefix &contextPrefix, bool &compressionAllowed, Time &validLifetime)
Get a context used in IPHC stateful compression.
virtual bool IsBridge(void) const
Return true if the net device is acting as a bridge.
virtual bool IsMulticast(void) const
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.
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.
SixLowPanNetDevice(SixLowPanNetDevice const &)=delete
virtual Address GetMulticast(Ipv4Address multicastGroup) const
Make and return a MAC multicast address using the provided multicast group.
virtual bool IsPointToPoint(void) const
Return true if the net device is on a point-to-point link.
virtual void DoDispose(void)
Destructor implementation.
uint32_t CompressLowPanUdpNhc(Ptr< Packet > packet, bool omitChecksum)
Compress the headers according to NHC compression.
virtual bool IsLinkUp(void) const
void RemoveContext(uint8_t contextId)
Remove a context used in IPHC stateful compression.
std::list< std::tuple< Time, FragmentKey_t, uint32_t > > FragmentsTimeoutsList_t
Container for fragment timeouts.
bool m_omitUdpChecksum
Omit UDP checksum in NC1 encoding.
std::pair< std::pair< Address, Address >, std::pair< uint16_t, uint16_t > > FragmentKey_t
Fragment identifier type: src/dst address src/dst port.
virtual bool SetMtu(const uint16_t mtu)
uint32_t m_ifIndex
Interface index.
virtual bool IsBroadcast(void) const
virtual void SetAddress(Address address)
Set the address of this interface.
void(* RxTxTracedCallback)(Ptr< const Packet > packet, Ptr< SixLowPanNetDevice > sixNetDevice, uint32_t ifindex)
TracedCallback signature for packet send/receive events.
virtual uint16_t GetMtu(void) const
Returns the link-layer MTU for this interface.
void HandleTimeout(void)
Handles a fragmented packet timeout.
virtual void SetIfIndex(const uint32_t index)
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.
FragmentsTimeoutsList_t m_timeoutEventList
Timeout "events" container.
virtual void SetNode(Ptr< Node > node)
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.
NetDevice::ReceiveCallback m_rxCallback
The callback used to notify higher layers that a packet has been received.
virtual bool SendFrom(Ptr< Packet > packet, const Address &source, const Address &dest, uint16_t protocolNumber)
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 OriginatorAdddress, SequenceNumber.
SixLowPanNetDevice()
Constructor for the SixLowPanNetDevice.
uint16_t m_etherType
EtherType number (used only if m_forceEtherType is true).
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
address
Definition: first.py:40
Every class exported by the ns3 library is enclosed in the ns3 namespace.
#define list
Structure holding the informations 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.