A Discrete-Event Network Simulator
API
ipv6-extension.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007-2009 Strasbourg University
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: David Gross <gdavid.devel@gmail.com>
19  */
20 
21 #ifndef IPV6_EXTENSION_H
22 #define IPV6_EXTENSION_H
23 
24 #include <map>
25 #include <list>
26 #include <tuple>
27 
28 #include "ns3/object.h"
29 #include "ns3/node.h"
30 #include "ns3/ptr.h"
31 #include "ipv6-interface.h"
32 #include "ns3/ipv6-header.h"
33 #include "ns3/buffer.h"
34 #include "ns3/packet.h"
35 #include "ns3/random-variable-stream.h"
36 #include "ns3/ipv6-address.h"
37 #include "ns3/ipv6-l3-protocol.h"
38 #include "ns3/traced-callback.h"
39 
40 
41 namespace ns3 {
42 
55 class Ipv6Extension : public Object
56 {
57 public:
62  static TypeId GetTypeId ();
63 
67  Ipv6Extension ();
68 
72  virtual ~Ipv6Extension ();
73 
78  void SetNode (Ptr<Node> node);
79 
84  Ptr<Node> GetNode () const;
85 
90  virtual uint8_t GetExtensionNumber () const = 0;
91 
106  virtual uint8_t Process (Ptr<Packet>& packet,
107  uint8_t offset,
108  Ipv6Header const& ipv6Header,
109  Ipv6Address dst,
110  uint8_t *nextHeader,
111  bool& stopProcessing,
112  bool& isDropped,
113  Ipv6L3Protocol::DropReason& dropReason) = 0;
114 
130  virtual uint8_t ProcessOptions (Ptr<Packet>& packet,
131  uint8_t offset,
132  uint8_t length,
133  Ipv6Header const& ipv6Header,
134  Ipv6Address dst,
135  uint8_t *nextHeader,
136  bool& stopProcessing,
137  bool& isDropped,
138  Ipv6L3Protocol::DropReason& dropReason
139  );
140 
149  int64_t AssignStreams (int64_t stream);
150 
151 protected:
156 
157 private:
162 };
163 
170 {
171 public:
175  static const uint8_t EXT_NUMBER = 0;
176 
181  static TypeId GetTypeId ();
182 
187 
192 
197  virtual uint8_t GetExtensionNumber () const;
198 
199  virtual uint8_t Process (Ptr<Packet>& packet,
200  uint8_t offset,
201  Ipv6Header const& ipv6Header,
202  Ipv6Address dst,
203  uint8_t *nextHeader,
204  bool& stopProcessing,
205  bool& isDropped,
206  Ipv6L3Protocol::DropReason& dropReason);
207 };
208 
215 {
216 public:
220  static const uint8_t EXT_NUMBER = 60;
221 
226  static TypeId GetTypeId ();
227 
232 
237 
242  virtual uint8_t GetExtensionNumber () const;
243 
244  virtual uint8_t Process (Ptr<Packet>& packet,
245  uint8_t offset,
246  Ipv6Header const& ipv6Header,
247  Ipv6Address dst,
248  uint8_t *nextHeader,
249  bool& stopProcessing,
250  bool& isDropped,
251  Ipv6L3Protocol::DropReason& dropReason);
252 };
253 
260 {
261 public:
265  static const uint8_t EXT_NUMBER = 44;
266 
271  static TypeId GetTypeId ();
272 
277 
282 
287  virtual uint8_t GetExtensionNumber () const;
288 
289  virtual uint8_t Process (Ptr<Packet>& packet,
290  uint8_t offset,
291  Ipv6Header const& ipv6Header,
292  Ipv6Address dst,
293  uint8_t *nextHeader,
294  bool& stopProcessing,
295  bool& isDropped,
296  Ipv6L3Protocol::DropReason& dropReason);
297 
301  typedef std::pair<Ptr<Packet>, Ipv6Header> Ipv6PayloadHeaderPair;
302 
311  void GetFragments (Ptr<Packet> packet, Ipv6Header ipv6Header, uint32_t fragmentSize, std::list<Ipv6PayloadHeaderPair>& listFragments);
312 
313 protected:
317  virtual void DoDispose ();
318 
319 private:
320 
324  typedef std::pair<Ipv6Address, uint32_t> FragmentKey_t;
325 
329  typedef std::list< std::tuple <Time, FragmentKey_t, Ipv6Header > > FragmentsTimeoutsList_t;
333  typedef std::list< std::tuple <Time, FragmentKey_t, Ipv6Header > >::iterator FragmentsTimeoutsListI_t;
334 
340  class Fragments : public SimpleRefCount<Fragments>
341  {
342 public:
346  Fragments ();
347 
351  ~Fragments ();
352 
359  void AddFragment (Ptr<Packet> fragment, uint16_t fragmentOffset, bool moreFragment);
360 
365  void SetUnfragmentablePart (Ptr<Packet> unfragmentablePart);
366 
371  bool IsEntire () const;
372 
377  Ptr<Packet> GetPacket () const;
378 
383  Ptr<Packet> GetPartialPacket () const;
384 
390 
396 
397 private:
402 
406  std::list<std::pair<Ptr<Packet>, uint16_t> > m_packetFragments;
407 
412 
417  };
418 
424  void HandleFragmentsTimeout (FragmentKey_t key, Ipv6Header ipHeader);
425 
430  Ptr<Packet> GetPartialPacket () const;
431 
436  void SetTimeoutEventId (EventId event);
437 
441  void CancelTimeout ();
442 
446  typedef std::map<FragmentKey_t, Ptr<Fragments> > MapFragments_t;
447 
452 
460 
464  void HandleTimeout (void);
465 
469 };
470 
480 {
481 public:
485  static const uint8_t EXT_NUMBER = 43;
486 
491  static TypeId GetTypeId ();
492 
497 
502 
507  virtual uint8_t GetExtensionNumber () const;
508 
513  virtual uint8_t GetTypeRouting () const;
514 
515  virtual uint8_t Process (Ptr<Packet>& packet,
516  uint8_t offset,
517  Ipv6Header const& ipv6Header,
518  Ipv6Address dst,
519  uint8_t *nextHeader,
520  bool& stopProcessing,
521  bool& isDropped,
522  Ipv6L3Protocol::DropReason& dropReason);
523 };
524 
531 {
532 public:
537  static TypeId GetTypeId ();
538 
543 
547  virtual ~Ipv6ExtensionRoutingDemux ();
548 
553  void SetNode (Ptr<Node> node);
554 
559  void Insert (Ptr<Ipv6ExtensionRouting> extensionRouting);
560 
566  Ptr<Ipv6ExtensionRouting> GetExtensionRouting (uint8_t typeRouting);
567 
572  void Remove (Ptr<Ipv6ExtensionRouting> extensionRouting);
573 
574 protected:
578  virtual void DoDispose ();
579 
580 private:
584  typedef std::list<Ptr<Ipv6ExtensionRouting> > Ipv6ExtensionRoutingList_t;
585 
590 
595 };
596 
603 {
604 public:
608  static const uint8_t TYPE_ROUTING = 0;
609 
614  static TypeId GetTypeId ();
615 
620 
625 
630  virtual uint8_t GetTypeRouting () const;
631 
632  virtual uint8_t Process (Ptr<Packet>& packet,
633  uint8_t offset,
634  Ipv6Header const& ipv6Header,
635  Ipv6Address dst,
636  uint8_t *nextHeader,
637  bool& stopProcessing,
638  bool& isDropped,
639  Ipv6L3Protocol::DropReason& dropReason);
640 };
641 
648 {
649 public:
653  static const uint8_t EXT_NUMBER = 50;
654 
659  static TypeId GetTypeId ();
660 
664  Ipv6ExtensionESP ();
665 
670 
675  virtual uint8_t GetExtensionNumber () const;
676 
677  virtual uint8_t Process (Ptr<Packet>& packet,
678  uint8_t offset,
679  Ipv6Header const& ipv6Header,
680  Ipv6Address dst,
681  uint8_t *nextHeader,
682  bool& stopProcessing,
683  bool& isDropped,
684  Ipv6L3Protocol::DropReason& dropReason);
685 };
686 
693 {
694 public:
698  static const uint8_t EXT_NUMBER = 51;
699 
704  static TypeId GetTypeId ();
705 
709  Ipv6ExtensionAH ();
710 
714  ~Ipv6ExtensionAH ();
715 
720  virtual uint8_t GetExtensionNumber () const;
721 
722  virtual uint8_t Process (Ptr<Packet>& packet,
723  uint8_t offset,
724  Ipv6Header const& ipv6Header,
725  Ipv6Address dst,
726  uint8_t *nextHeader,
727  bool& stopProcessing,
728  bool& isDropped,
729  Ipv6L3Protocol::DropReason& dropReason);
730 };
731 
732 } /* namespace ns3 */
733 
734 #endif /* IPV6_EXTENSION_H */
735 
Ptr< UniformRandomVariable > m_uvar
Provides uniform random variables.
This class stores the fragments of a packet waiting to be rebuilt.
IPv6 Extension base If you want to implement a new IPv6 extension, all you have to do is implement a ...
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
virtual uint8_t Process(Ptr< Packet > &packet, uint8_t offset, Ipv6Header const &ipv6Header, Ipv6Address dst, uint8_t *nextHeader, bool &stopProcessing, bool &isDropped, Ipv6L3Protocol::DropReason &dropReason)
Process method Called from Ipv6L3Protocol::Receive.
void HandleTimeout(void)
Handles a fragmented packet timeout.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Ipv6ExtensionLooseRouting()
Constructor.
Packet header for IPv6.
Definition: ipv6-header.h:34
virtual void DoDispose()
Dispose this object.
FragmentsTimeoutsListI_t GetTimeoutIter()
Get the Timeout iterator.
void Insert(Ptr< Ipv6ExtensionRouting > extensionRouting)
Insert a new IPv6 Routing Extension.
Ptr< Packet > GetPartialPacket() const
Get the packet parts so far received.
static const uint8_t EXT_NUMBER
Fragmentation extension number.
void SetTimeoutEventId(EventId event)
Set the Timeout EventId.
void SetNode(Ptr< Node > node)
Set the node.
void HandleFragmentsTimeout(FragmentKey_t key, Ipv6Header ipHeader)
Process the timeout for packet fragments.
virtual void DoDispose()
Dispose this object.
std::map< FragmentKey_t, Ptr< Fragments > > MapFragments_t
Container for the packet fragments.
static TypeId GetTypeId()
Get the type identificator.
static const uint8_t TYPE_ROUTING
Routing type.
FragmentsTimeoutsListI_t m_timeoutIter
Timeout iterator to "event" handler.
virtual uint8_t Process(Ptr< Packet > &packet, uint8_t offset, Ipv6Header const &ipv6Header, Ipv6Address dst, uint8_t *nextHeader, bool &stopProcessing, bool &isDropped, Ipv6L3Protocol::DropReason &dropReason)
Process method Called from Ipv6L3Protocol::Receive.
static TypeId GetTypeId()
Get the type identificator.
void GetFragments(Ptr< Packet > packet, Ipv6Header ipv6Header, uint32_t fragmentSize, std::list< Ipv6PayloadHeaderPair > &listFragments)
Fragment a packet.
virtual ~Ipv6ExtensionRoutingDemux()
Destructor.
Ipv6ExtensionRoutingDemux()
Constructor.
FragmentsTimeoutsList_t m_timeoutEventList
Timeout "events" container.
Time m_fragmentExpirationTimeout
Expiration timeout.
IPv6 Extension Destination.
Ipv6ExtensionFragment()
Constructor.
IPv6 Extension Routing.
void CancelTimeout()
Cancel the timeout event.
static TypeId GetTypeId()
Get the type identificator.
~Ipv6ExtensionHopByHop()
Destructor.
virtual uint8_t Process(Ptr< Packet > &packet, uint8_t offset, Ipv6Header const &ipv6Header, Ipv6Address dst, uint8_t *nextHeader, bool &stopProcessing, bool &isDropped, Ipv6L3Protocol::DropReason &dropReason)
Process method Called from Ipv6L3Protocol::Receive.
virtual uint8_t Process(Ptr< Packet > &packet, uint8_t offset, Ipv6Header const &ipv6Header, Ipv6Address dst, uint8_t *nextHeader, bool &stopProcessing, bool &isDropped, Ipv6L3Protocol::DropReason &dropReason)=0
Process method Called from Ipv6L3Protocol::Receive.
Ipv6ExtensionHopByHop()
Constructor.
virtual uint8_t Process(Ptr< Packet > &packet, uint8_t offset, Ipv6Header const &ipv6Header, Ipv6Address dst, uint8_t *nextHeader, bool &stopProcessing, bool &isDropped, Ipv6L3Protocol::DropReason &dropReason)
Process method Called from Ipv6L3Protocol::Receive.
virtual uint8_t Process(Ptr< Packet > &packet, uint8_t offset, Ipv6Header const &ipv6Header, Ipv6Address dst, uint8_t *nextHeader, bool &stopProcessing, bool &isDropped, Ipv6L3Protocol::DropReason &dropReason)
Process method Called from Ipv6L3Protocol::Receive.
virtual uint8_t GetExtensionNumber() const
Get the extension number.
std::list< Ptr< Ipv6ExtensionRouting > > Ipv6ExtensionRoutingList_t
Container for the extension routing.
Ptr< Packet > m_unfragmentable
The unfragmentable part.
std::list< std::tuple< Time, FragmentKey_t, Ipv6Header > >::iterator FragmentsTimeoutsListI_t
Container Iterator for fragment timeouts.
IPv6 Extension ESP (Encapsulating Security Payload)
bool m_moreFragment
If other fragments will be sent.
~Ipv6ExtensionFragment()
Destructor.
virtual uint8_t Process(Ptr< Packet > &packet, uint8_t offset, Ipv6Header const &ipv6Header, Ipv6Address dst, uint8_t *nextHeader, bool &stopProcessing, bool &isDropped, Ipv6L3Protocol::DropReason &dropReason)
Process method Called from Ipv6L3Protocol::Receive.
~Ipv6ExtensionRouting()
Destructor.
Ptr< Node > m_node
The node.
static TypeId GetTypeId()
Get the type identificator.
virtual uint8_t Process(Ptr< Packet > &packet, uint8_t offset, Ipv6Header const &ipv6Header, Ipv6Address dst, uint8_t *nextHeader, bool &stopProcessing, bool &isDropped, Ipv6L3Protocol::DropReason &dropReason)
Process method Called from Ipv6L3Protocol::Receive.
virtual uint8_t GetTypeRouting() const
Get the type of routing.
Ipv6ExtensionDestination()
Constructor.
IPv6 Extension Routing Demux.
void SetUnfragmentablePart(Ptr< Packet > unfragmentablePart)
Set the unfragmentable part of the packet.
IPv6 Extension "Hop By Hop".
void Remove(Ptr< Ipv6ExtensionRouting > extensionRouting)
Remove a routing extension from this demux.
void AddFragment(Ptr< Packet > fragment, uint16_t fragmentOffset, bool moreFragment)
Add a fragment.
virtual uint8_t GetExtensionNumber() const
Get the extension number.
void SetNode(Ptr< Node > node)
Set the node.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TypeId GetTypeId()
Get the type identificator.
virtual uint8_t GetExtensionNumber() const
Get the extension number.
MapFragments_t m_fragments
The hash of fragmented packets.
static TypeId GetTypeId()
The interface ID.
static TypeId GetTypeId()
Get the type identificator.
Ptr< Ipv6ExtensionRouting > GetExtensionRouting(uint8_t typeRouting)
Get the routing extension corresponding to typeRouting.
~Ipv6ExtensionESP()
Destructor.
Ipv6ExtensionAH()
Constructor.
std::pair< Ptr< Packet >, Ipv6Header > Ipv6PayloadHeaderPair
Pair of a packet and an Ipv6 header.
static TypeId GetTypeId()
Get the type identificator.
IPv6 Extension Loose Routing.
virtual uint8_t GetExtensionNumber() const =0
Get the extension number.
static const uint8_t EXT_NUMBER
Hop-by-hop extension number.
Ipv6Extension()
Constructor.
IPv6 Extension Fragment.
Describes an IPv6 address.
Definition: ipv6-address.h:49
std::list< std::tuple< Time, FragmentKey_t, Ipv6Header > > FragmentsTimeoutsList_t
Container for fragment timeouts.
void SetTimeoutIter(FragmentsTimeoutsListI_t iter)
Set the Timeout iterator.
An identifier for simulation events.
Definition: event-id.h:53
virtual uint8_t GetExtensionNumber() const
Get the extension number.
Ipv6ExtensionRouting()
Constructor.
FragmentsTimeoutsListI_t SetTimeout(FragmentKey_t key, Ipv6Header ipHeader)
Set a new timeout "event" for a fragmented packet.
virtual uint8_t ProcessOptions(Ptr< Packet > &packet, uint8_t offset, uint8_t length, Ipv6Header const &ipv6Header, Ipv6Address dst, uint8_t *nextHeader, bool &stopProcessing, bool &isDropped, Ipv6L3Protocol::DropReason &dropReason)
Process options Called by implementing classes to process the options.
EventId m_timeoutEvent
Event for the next scheduled timeout.
bool IsEntire() const
If all fragments have been added.
static const uint8_t EXT_NUMBER
ESP extension number.
virtual uint8_t GetTypeRouting() const
Get the type of routing.
Ptr< Node > GetNode() const
Get the node.
Ipv6ExtensionRoutingList_t m_extensionsRouting
List of IPv6 Routing Extensions supported.
std::list< std::pair< Ptr< Packet >, uint16_t > > m_packetFragments
The current fragments.
std::pair< Ipv6Address, uint32_t > FragmentKey_t
Key identifying a fragmented packet.
virtual uint8_t GetExtensionNumber() const
Get the extension number.
Ipv6ExtensionESP()
Constructor.
A base class which provides memory management and object aggregation.
Definition: object.h:87
Ptr< Packet > GetPartialPacket() const
Get the packet parts so far received.
static const uint8_t EXT_NUMBER
Destination extension number.
Ptr< Node > m_node
The node.
virtual uint8_t GetExtensionNumber() const
Get the extension number.
static const uint8_t EXT_NUMBER
Routing extension number.
A template-based reference counting class.
a unique identifier for an interface.
Definition: type-id.h:58
Ptr< Packet > GetPacket() const
Get the entire packet.
static TypeId GetTypeId()
Get the type identificator.
static const uint8_t EXT_NUMBER
AH extension number.
~Ipv6ExtensionAH()
Destructor.
DropReason
Reason why a packet has been dropped.
virtual ~Ipv6Extension()
Destructor.
IPv6 Extension AH (Authentication Header)