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 
27 #include "ns3/object.h"
28 #include "ns3/node.h"
29 #include "ns3/ptr.h"
30 #include "ipv6-interface.h"
31 #include "ns3/ipv6-header.h"
32 #include "ns3/buffer.h"
33 #include "ns3/packet.h"
34 #include "ns3/random-variable-stream.h"
35 #include "ns3/ipv6-address.h"
36 #include "ns3/ipv6-l3-protocol.h"
37 #include "ns3/traced-callback.h"
38 
39 
40 namespace ns3 {
41 
54 class Ipv6Extension : public Object
55 {
56 public:
61  static TypeId GetTypeId ();
62 
66  Ipv6Extension ();
67 
71  virtual ~Ipv6Extension ();
72 
77  void SetNode (Ptr<Node> node);
78 
83  Ptr<Node> GetNode () const;
84 
89  virtual uint8_t GetExtensionNumber () const = 0;
90 
105  virtual uint8_t Process (Ptr<Packet>& packet,
106  uint8_t offset,
107  Ipv6Header const& ipv6Header,
108  Ipv6Address dst,
109  uint8_t *nextHeader,
110  bool& stopProcessing,
111  bool& isDropped,
112  Ipv6L3Protocol::DropReason& dropReason) = 0;
113 
129  virtual uint8_t ProcessOptions (Ptr<Packet>& packet,
130  uint8_t offset,
131  uint8_t length,
132  Ipv6Header const& ipv6Header,
133  Ipv6Address dst,
134  uint8_t *nextHeader,
135  bool& stopProcessing,
136  bool& isDropped,
137  Ipv6L3Protocol::DropReason& dropReason
138  );
139 
148  int64_t AssignStreams (int64_t stream);
149 
150 protected:
155 
156 private:
161 };
162 
169 {
170 public:
174  static const uint8_t EXT_NUMBER = 0;
175 
180  static TypeId GetTypeId ();
181 
186 
191 
196  virtual uint8_t GetExtensionNumber () const;
197 
198  virtual uint8_t Process (Ptr<Packet>& packet,
199  uint8_t offset,
200  Ipv6Header const& ipv6Header,
201  Ipv6Address dst,
202  uint8_t *nextHeader,
203  bool& stopProcessing,
204  bool& isDropped,
205  Ipv6L3Protocol::DropReason& dropReason);
206 };
207 
214 {
215 public:
219  static const uint8_t EXT_NUMBER = 60;
220 
225  static TypeId GetTypeId ();
226 
231 
236 
241  virtual uint8_t GetExtensionNumber () const;
242 
243  virtual uint8_t Process (Ptr<Packet>& packet,
244  uint8_t offset,
245  Ipv6Header const& ipv6Header,
246  Ipv6Address dst,
247  uint8_t *nextHeader,
248  bool& stopProcessing,
249  bool& isDropped,
250  Ipv6L3Protocol::DropReason& dropReason);
251 };
252 
259 {
260 public:
264  static const uint8_t EXT_NUMBER = 44;
265 
270  static TypeId GetTypeId ();
271 
276 
281 
286  virtual uint8_t GetExtensionNumber () const;
287 
288  virtual uint8_t Process (Ptr<Packet>& packet,
289  uint8_t offset,
290  Ipv6Header const& ipv6Header,
291  Ipv6Address dst,
292  uint8_t *nextHeader,
293  bool& stopProcessing,
294  bool& isDropped,
295  Ipv6L3Protocol::DropReason& dropReason);
296 
300  typedef std::pair<Ptr<Packet>, Ipv6Header> Ipv6PayloadHeaderPair;
301 
310  void GetFragments (Ptr<Packet> packet, Ipv6Header ipv6Header, uint32_t fragmentSize, std::list<Ipv6PayloadHeaderPair>& listFragments);
311 
312 protected:
316  virtual void DoDispose ();
317 
318 private:
324  class Fragments : public SimpleRefCount<Fragments>
325  {
326 public:
330  Fragments ();
331 
335  ~Fragments ();
336 
343  void AddFragment (Ptr<Packet> fragment, uint16_t fragmentOffset, bool moreFragment);
344 
349  void SetUnfragmentablePart (Ptr<Packet> unfragmentablePart);
350 
355  bool IsEntire () const;
356 
361  Ptr<Packet> GetPacket () const;
362 
367  Ptr<Packet> GetPartialPacket () const;
368 
372  void SetTimeoutEventId (EventId event);
373 
377  void CancelTimeout ();
378 
379 private:
384 
388  std::list<std::pair<Ptr<Packet>, uint16_t> > m_packetFragments;
389 
394 
399  };
400 
406  void HandleFragmentsTimeout (std::pair<Ipv6Address, uint32_t> key, Ipv6Header ipHeader);
407 
412  Ptr<Packet> GetPartialPacket () const;
413 
417  void SetTimeoutEventId (EventId event);
418 
422  void CancelTimeout ();
423 
427  typedef std::map<std::pair<Ipv6Address, uint32_t>, Ptr<Fragments> > MapFragments_t;
428 
432  MapFragments_t m_fragments;
433 };
434 
444 {
445 public:
449  static const uint8_t EXT_NUMBER = 43;
450 
455  static TypeId GetTypeId ();
456 
461 
466 
471  virtual uint8_t GetExtensionNumber () const;
472 
477  virtual uint8_t GetTypeRouting () const;
478 
479  virtual uint8_t Process (Ptr<Packet>& packet,
480  uint8_t offset,
481  Ipv6Header const& ipv6Header,
482  Ipv6Address dst,
483  uint8_t *nextHeader,
484  bool& stopProcessing,
485  bool& isDropped,
486  Ipv6L3Protocol::DropReason& dropReason);
487 };
488 
495 {
496 public:
501  static TypeId GetTypeId ();
502 
507 
511  virtual ~Ipv6ExtensionRoutingDemux ();
512 
517  void SetNode (Ptr<Node> node);
518 
523  void Insert (Ptr<Ipv6ExtensionRouting> extensionRouting);
524 
530  Ptr<Ipv6ExtensionRouting> GetExtensionRouting (uint8_t typeRouting);
531 
536  void Remove (Ptr<Ipv6ExtensionRouting> extensionRouting);
537 
538 protected:
542  virtual void DoDispose ();
543 
544 private:
548  typedef std::list<Ptr<Ipv6ExtensionRouting> > Ipv6ExtensionRoutingList_t;
549 
553  Ipv6ExtensionRoutingList_t m_extensionsRouting;
554 
559 };
560 
567 {
568 public:
572  static const uint8_t TYPE_ROUTING = 0;
573 
578  static TypeId GetTypeId ();
579 
584 
589 
594  virtual uint8_t GetTypeRouting () const;
595 
596  virtual uint8_t Process (Ptr<Packet>& packet,
597  uint8_t offset,
598  Ipv6Header const& ipv6Header,
599  Ipv6Address dst,
600  uint8_t *nextHeader,
601  bool& stopProcessing,
602  bool& isDropped,
603  Ipv6L3Protocol::DropReason& dropReason);
604 };
605 
612 {
613 public:
617  static const uint8_t EXT_NUMBER = 50;
618 
623  static TypeId GetTypeId ();
624 
628  Ipv6ExtensionESP ();
629 
634 
639  virtual uint8_t GetExtensionNumber () const;
640 
641  virtual uint8_t Process (Ptr<Packet>& packet,
642  uint8_t offset,
643  Ipv6Header const& ipv6Header,
644  Ipv6Address dst,
645  uint8_t *nextHeader,
646  bool& stopProcessing,
647  bool& isDropped,
648  Ipv6L3Protocol::DropReason& dropReason);
649 };
650 
657 {
658 public:
662  static const uint8_t EXT_NUMBER = 51;
663 
668  static TypeId GetTypeId ();
669 
673  Ipv6ExtensionAH ();
674 
678  ~Ipv6ExtensionAH ();
679 
684  virtual uint8_t GetExtensionNumber () const;
685 
686  virtual uint8_t Process (Ptr<Packet>& packet,
687  uint8_t offset,
688  Ipv6Header const& ipv6Header,
689  Ipv6Address dst,
690  uint8_t *nextHeader,
691  bool& stopProcessing,
692  bool& isDropped,
693  Ipv6L3Protocol::DropReason& dropReason);
694 };
695 
696 } /* namespace ns3 */
697 
698 #endif /* IPV6_EXTENSION_H */
699 
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.
Ipv6ExtensionLooseRouting()
Constructor.
Packet header for IPv6.
Definition: ipv6-header.h:34
virtual void DoDispose()
Dispose this object.
Ptr< Packet > GetPartialPacket() const
Get the packet parts so far received.
void Insert(Ptr< Ipv6ExtensionRouting > extensionRouting)
Insert a new IPv6 Routing Extension.
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.
virtual void DoDispose()
Dispose this object.
virtual uint8_t GetExtensionNumber() const
Get the extension number.
static TypeId GetTypeId()
Get the type identificator.
virtual uint8_t GetExtensionNumber() const
Get the extension number.
static const uint8_t TYPE_ROUTING
Routing type.
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.
IPv6 Extension Destination.
Ipv6ExtensionFragment()
Constructor.
virtual uint8_t GetExtensionNumber() const
Get the extension number.
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.
DropReason
Reason why a packet has been dropped.
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.
void SetTimeoutEventId(EventId event)
Set the Timeout EventId.
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.
std::list< Ptr< Ipv6ExtensionRouting > > Ipv6ExtensionRoutingList_t
Container for the extension routing.
Ptr< Packet > GetPacket() const
Get the entire packet.
Ptr< Packet > m_unfragmentable
The unfragmentable part.
IPv6 Extension ESP (Encapsulating Security Payload)
bool m_moreFragment
If other fragments will be sent.
~Ipv6ExtensionFragment()
Destructor.
void CancelTimeout()
Cancel the timeout event.
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.
Ipv6ExtensionDestination()
Constructor.
IPv6 Extension Routing Demux.
void SetUnfragmentablePart(Ptr< Packet > unfragmentablePart)
Set the unfragmentable part of the packet.
bool IsEntire() const
If all fragments have been added.
IPv6 Extension "Hop By Hop".
Ptr< Node > GetNode() const
Get the node.
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.
void SetNode(Ptr< Node > node)
Set the node.
virtual uint8_t GetExtensionNumber() const
Get the extension number.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TypeId GetTypeId()
Get the type identificator.
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.
std::map< std::pair< Ipv6Address, uint32_t >, Ptr< Fragments > > MapFragments_t
Container for the packet fragments.
static const uint8_t EXT_NUMBER
Hop-by-hop extension number.
Ipv6Extension()
Constructor.
IPv6 Extension Fragment.
EventId m_timeoutEventId
Timeout handler event.
Describes an IPv6 address.
Definition: ipv6-address.h:48
virtual uint8_t GetTypeRouting() const
Get the type of routing.
An identifier for simulation events.
Definition: event-id.h:53
Ipv6ExtensionRouting()
Constructor.
virtual uint8_t GetExtensionNumber() const
Get the extension number.
virtual uint8_t GetExtensionNumber() const
Get the extension number.
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.
virtual uint8_t GetTypeRouting() const
Get the type of routing.
static const uint8_t EXT_NUMBER
ESP extension number.
Ipv6ExtensionRoutingList_t m_extensionsRouting
List of IPv6 Routing Extensions supported.
std::list< std::pair< Ptr< Packet >, uint16_t > > m_packetFragments
The current fragments.
Ipv6ExtensionESP()
Constructor.
void HandleFragmentsTimeout(std::pair< Ipv6Address, uint32_t > key, Ipv6Header ipHeader)
Process the timeout for packet fragments.
A base class which provides memory management and object aggregation.
Definition: object.h:87
static const uint8_t EXT_NUMBER
Destination extension number.
Ptr< Node > m_node
The node.
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
static TypeId GetTypeId()
Get the type identificator.
static const uint8_t EXT_NUMBER
AH extension number.
~Ipv6ExtensionAH()
Destructor.
Ptr< Packet > GetPartialPacket() const
Get the packet parts so far received.
virtual ~Ipv6Extension()
Destructor.
IPv6 Extension AH (Authentication Header)