A Discrete-Event Network Simulator
API
ipv6-extension.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007-2009 Strasbourg University
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: David Gross <gdavid.devel@gmail.com>
18 */
19
20#ifndef IPV6_EXTENSION_H
21#define IPV6_EXTENSION_H
22
23#include "ipv6-interface.h"
24
25#include "ns3/buffer.h"
26#include "ns3/ipv6-address.h"
27#include "ns3/ipv6-header.h"
28#include "ns3/ipv6-l3-protocol.h"
29#include "ns3/node.h"
30#include "ns3/object.h"
31#include "ns3/packet.h"
32#include "ns3/ptr.h"
33#include "ns3/random-variable-stream.h"
34#include "ns3/traced-callback.h"
35
36#include <list>
37#include <map>
38#include <tuple>
39
40namespace ns3
41{
42
55class Ipv6Extension : public Object
56{
57 public:
62 static TypeId GetTypeId();
63
68
72 ~Ipv6Extension() override;
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 const Ipv6Header& 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 const Ipv6Header& ipv6Header,
134 Ipv6Address dst,
135 uint8_t* nextHeader,
136 bool& stopProcessing,
137 bool& isDropped,
138 Ipv6L3Protocol::DropReason& dropReason);
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
190 ~Ipv6ExtensionHopByHop() override;
191
196 uint8_t GetExtensionNumber() const override;
197
198 uint8_t Process(Ptr<Packet>& packet,
199 uint8_t offset,
200 const Ipv6Header& ipv6Header,
201 Ipv6Address dst,
202 uint8_t* nextHeader,
203 bool& stopProcessing,
204 bool& isDropped,
205 Ipv6L3Protocol::DropReason& dropReason) override;
206};
207
214{
215 public:
219 static const uint8_t EXT_NUMBER = 60;
220
225 static TypeId GetTypeId();
226
231
235 ~Ipv6ExtensionDestination() override;
236
241 uint8_t GetExtensionNumber() const override;
242
243 uint8_t Process(Ptr<Packet>& packet,
244 uint8_t offset,
245 const Ipv6Header& ipv6Header,
246 Ipv6Address dst,
247 uint8_t* nextHeader,
248 bool& stopProcessing,
249 bool& isDropped,
250 Ipv6L3Protocol::DropReason& dropReason) override;
251};
252
259{
260 public:
264 static const uint8_t EXT_NUMBER = 44;
265
270 static TypeId GetTypeId();
271
276
280 ~Ipv6ExtensionFragment() override;
281
286 uint8_t GetExtensionNumber() const override;
287
288 uint8_t Process(Ptr<Packet>& packet,
289 uint8_t offset,
290 const Ipv6Header& ipv6Header,
291 Ipv6Address dst,
292 uint8_t* nextHeader,
293 bool& stopProcessing,
294 bool& isDropped,
295 Ipv6L3Protocol::DropReason& dropReason) override;
296
300 typedef std::pair<Ptr<Packet>, Ipv6Header> Ipv6PayloadHeaderPair;
301
311 void GetFragments(Ptr<Packet> packet,
312 Ipv6Header ipv6Header,
313 uint32_t fragmentSize,
314 std::list<Ipv6PayloadHeaderPair>& listFragments);
315
316 protected:
320 void DoDispose() override;
321
322 private:
326 typedef std::pair<Ipv6Address, uint32_t> FragmentKey_t;
327
331 typedef std::list<std::tuple<Time, FragmentKey_t, Ipv6Header>> FragmentsTimeoutsList_t;
335 typedef std::list<std::tuple<Time, FragmentKey_t, Ipv6Header>>::iterator
337
343 class Fragments : public SimpleRefCount<Fragments>
344 {
345 public:
349 Fragments();
350
354 ~Fragments();
355
362 void AddFragment(Ptr<Packet> fragment, uint16_t fragmentOffset, bool moreFragment);
363
368 void SetUnfragmentablePart(Ptr<Packet> unfragmentablePart);
369
374 bool IsEntire() const;
375
380 Ptr<Packet> GetPacket() const;
381
387
393
399
400 private:
405
409 std::list<std::pair<Ptr<Packet>, uint16_t>> m_packetFragments;
410
415
420 };
421
428
434
440
445
449 typedef std::map<FragmentKey_t, Ptr<Fragments>> MapFragments_t;
450
455
463
467 void HandleTimeout();
468
472};
473
483{
484 public:
488 static const uint8_t EXT_NUMBER = 43;
489
494 static TypeId GetTypeId();
495
500
504 ~Ipv6ExtensionRouting() override;
505
510 uint8_t GetExtensionNumber() const override;
511
516 virtual uint8_t GetTypeRouting() const;
517
518 uint8_t Process(Ptr<Packet>& packet,
519 uint8_t offset,
520 const Ipv6Header& ipv6Header,
521 Ipv6Address dst,
522 uint8_t* nextHeader,
523 bool& stopProcessing,
524 bool& isDropped,
525 Ipv6L3Protocol::DropReason& dropReason) override;
526};
527
534{
535 public:
540 static TypeId GetTypeId();
541
546
551
556 void SetNode(Ptr<Node> node);
557
562 void Insert(Ptr<Ipv6ExtensionRouting> extensionRouting);
563
570
575 void Remove(Ptr<Ipv6ExtensionRouting> extensionRouting);
576
577 protected:
581 void DoDispose() override;
582
583 private:
587 typedef std::list<Ptr<Ipv6ExtensionRouting>> Ipv6ExtensionRoutingList_t;
588
593
598};
599
606{
607 public:
611 static const uint8_t TYPE_ROUTING = 0;
612
617 static TypeId GetTypeId();
618
623
628
633 uint8_t GetTypeRouting() const override;
634
635 uint8_t Process(Ptr<Packet>& packet,
636 uint8_t offset,
637 const Ipv6Header& ipv6Header,
638 Ipv6Address dst,
639 uint8_t* nextHeader,
640 bool& stopProcessing,
641 bool& isDropped,
642 Ipv6L3Protocol::DropReason& dropReason) override;
643};
644
651{
652 public:
656 static const uint8_t EXT_NUMBER = 50;
657
662 static TypeId GetTypeId();
663
668
672 ~Ipv6ExtensionESP() override;
673
678 uint8_t GetExtensionNumber() const override;
679
680 uint8_t Process(Ptr<Packet>& packet,
681 uint8_t offset,
682 const Ipv6Header& ipv6Header,
683 Ipv6Address dst,
684 uint8_t* nextHeader,
685 bool& stopProcessing,
686 bool& isDropped,
687 Ipv6L3Protocol::DropReason& dropReason) override;
688};
689
696{
697 public:
701 static const uint8_t EXT_NUMBER = 51;
702
707 static TypeId GetTypeId();
708
713
717 ~Ipv6ExtensionAH() override;
718
723 uint8_t GetExtensionNumber() const override;
724
725 uint8_t Process(Ptr<Packet>& packet,
726 uint8_t offset,
727 const Ipv6Header& ipv6Header,
728 Ipv6Address dst,
729 uint8_t* nextHeader,
730 bool& stopProcessing,
731 bool& isDropped,
732 Ipv6L3Protocol::DropReason& dropReason) override;
733};
734
735} /* namespace ns3 */
736
737#endif /* IPV6_EXTENSION_H */
An identifier for simulation events.
Definition: event-id.h:55
Describes an IPv6 address.
Definition: ipv6-address.h:49
IPv6 Extension AH (Authentication Header)
~Ipv6ExtensionAH() override
Destructor.
uint8_t Process(Ptr< Packet > &packet, uint8_t offset, const Ipv6Header &ipv6Header, Ipv6Address dst, uint8_t *nextHeader, bool &stopProcessing, bool &isDropped, Ipv6L3Protocol::DropReason &dropReason) override
Process method Called from Ipv6L3Protocol::Receive.
static TypeId GetTypeId()
Get the type identificator.
uint8_t GetExtensionNumber() const override
Get the extension number.
Ipv6ExtensionAH()
Constructor.
static const uint8_t EXT_NUMBER
AH extension number.
IPv6 Extension Destination.
uint8_t GetExtensionNumber() const override
Get the extension number.
static const uint8_t EXT_NUMBER
Destination extension number.
static TypeId GetTypeId()
Get the type identificator.
~Ipv6ExtensionDestination() override
Destructor.
uint8_t Process(Ptr< Packet > &packet, uint8_t offset, const Ipv6Header &ipv6Header, Ipv6Address dst, uint8_t *nextHeader, bool &stopProcessing, bool &isDropped, Ipv6L3Protocol::DropReason &dropReason) override
Process method Called from Ipv6L3Protocol::Receive.
IPv6 Extension ESP (Encapsulating Security Payload)
~Ipv6ExtensionESP() override
Destructor.
Ipv6ExtensionESP()
Constructor.
uint8_t Process(Ptr< Packet > &packet, uint8_t offset, const Ipv6Header &ipv6Header, Ipv6Address dst, uint8_t *nextHeader, bool &stopProcessing, bool &isDropped, Ipv6L3Protocol::DropReason &dropReason) override
Process method Called from Ipv6L3Protocol::Receive.
uint8_t GetExtensionNumber() const override
Get the extension number.
static const uint8_t EXT_NUMBER
ESP extension number.
static TypeId GetTypeId()
Get the type identificator.
This class stores the fragments of a packet waiting to be rebuilt.
Ptr< Packet > GetPartialPacket() const
Get the packet parts so far received.
Ptr< Packet > GetPacket() const
Get the entire packet.
std::list< std::pair< Ptr< Packet >, uint16_t > > m_packetFragments
The current fragments.
void AddFragment(Ptr< Packet > fragment, uint16_t fragmentOffset, bool moreFragment)
Add a fragment.
void SetTimeoutIter(FragmentsTimeoutsListI_t iter)
Set the Timeout iterator.
bool m_moreFragment
If other fragments will be sent.
Ptr< Packet > m_unfragmentable
The unfragmentable part.
FragmentsTimeoutsListI_t m_timeoutIter
Timeout iterator to "event" handler.
void SetUnfragmentablePart(Ptr< Packet > unfragmentablePart)
Set the unfragmentable part of the packet.
bool IsEntire() const
If all fragments have been added.
FragmentsTimeoutsListI_t GetTimeoutIter()
Get the Timeout iterator.
IPv6 Extension Fragment.
Time m_fragmentExpirationTimeout
Expiration timeout.
void HandleTimeout()
Handles a fragmented packet timeout.
Ptr< Packet > GetPartialPacket() const
Get the packet parts so far received.
Ipv6ExtensionFragment()
Constructor.
static TypeId GetTypeId()
Get the type identificator.
std::pair< Ptr< Packet >, Ipv6Header > Ipv6PayloadHeaderPair
Pair of a packet and an Ipv6 header.
void GetFragments(Ptr< Packet > packet, Ipv6Header ipv6Header, uint32_t fragmentSize, std::list< Ipv6PayloadHeaderPair > &listFragments)
Fragment a packet.
std::pair< Ipv6Address, uint32_t > FragmentKey_t
Key identifying a fragmented packet.
EventId m_timeoutEvent
Event for the next scheduled timeout.
std::map< FragmentKey_t, Ptr< Fragments > > MapFragments_t
Container for the packet fragments.
MapFragments_t m_fragments
The hash of fragmented packets.
void DoDispose() override
Dispose this object.
void SetTimeoutEventId(EventId event)
Set the Timeout EventId.
uint8_t Process(Ptr< Packet > &packet, uint8_t offset, const Ipv6Header &ipv6Header, Ipv6Address dst, uint8_t *nextHeader, bool &stopProcessing, bool &isDropped, Ipv6L3Protocol::DropReason &dropReason) override
Process method Called from Ipv6L3Protocol::Receive.
std::list< std::tuple< Time, FragmentKey_t, Ipv6Header > >::iterator FragmentsTimeoutsListI_t
Container Iterator for fragment timeouts.
~Ipv6ExtensionFragment() override
Destructor.
FragmentsTimeoutsList_t m_timeoutEventList
Timeout "events" container.
void HandleFragmentsTimeout(FragmentKey_t key, Ipv6Header ipHeader)
Process the timeout for packet fragments.
FragmentsTimeoutsListI_t SetTimeout(FragmentKey_t key, Ipv6Header ipHeader)
Set a new timeout "event" for a fragmented packet.
uint8_t GetExtensionNumber() const override
Get the extension number.
std::list< std::tuple< Time, FragmentKey_t, Ipv6Header > > FragmentsTimeoutsList_t
Container for fragment timeouts.
static const uint8_t EXT_NUMBER
Fragmentation extension number.
void CancelTimeout()
Cancel the timeout event.
IPv6 Extension "Hop By Hop".
static TypeId GetTypeId()
Get the type identificator.
~Ipv6ExtensionHopByHop() override
Destructor.
Ipv6ExtensionHopByHop()
Constructor.
uint8_t Process(Ptr< Packet > &packet, uint8_t offset, const Ipv6Header &ipv6Header, Ipv6Address dst, uint8_t *nextHeader, bool &stopProcessing, bool &isDropped, Ipv6L3Protocol::DropReason &dropReason) override
Process method Called from Ipv6L3Protocol::Receive.
static const uint8_t EXT_NUMBER
Hop-by-hop extension number.
uint8_t GetExtensionNumber() const override
Get the extension number.
IPv6 Extension base If you want to implement a new IPv6 extension, all you have to do is implement a ...
Ptr< Node > GetNode() const
Get the node.
virtual uint8_t ProcessOptions(Ptr< Packet > &packet, uint8_t offset, uint8_t length, const Ipv6Header &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 GetExtensionNumber() const =0
Get the extension number.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Ptr< Node > m_node
The node.
void SetNode(Ptr< Node > node)
Set the node.
virtual uint8_t Process(Ptr< Packet > &packet, uint8_t offset, const Ipv6Header &ipv6Header, Ipv6Address dst, uint8_t *nextHeader, bool &stopProcessing, bool &isDropped, Ipv6L3Protocol::DropReason &dropReason)=0
Process method Called from Ipv6L3Protocol::Receive.
Ptr< UniformRandomVariable > m_uvar
Provides uniform random variables.
~Ipv6Extension() override
Destructor.
Ipv6Extension()
Constructor.
static TypeId GetTypeId()
Get the type identificator.
IPv6 Extension Loose Routing.
static TypeId GetTypeId()
Get the type identificator.
~Ipv6ExtensionLooseRouting() override
Destructor.
uint8_t Process(Ptr< Packet > &packet, uint8_t offset, const Ipv6Header &ipv6Header, Ipv6Address dst, uint8_t *nextHeader, bool &stopProcessing, bool &isDropped, Ipv6L3Protocol::DropReason &dropReason) override
Process method Called from Ipv6L3Protocol::Receive.
uint8_t GetTypeRouting() const override
Get the type of routing.
static const uint8_t TYPE_ROUTING
Routing type.
IPv6 Extension Routing Demux.
void DoDispose() override
Dispose this object.
std::list< Ptr< Ipv6ExtensionRouting > > Ipv6ExtensionRoutingList_t
Container for the extension routing.
void Insert(Ptr< Ipv6ExtensionRouting > extensionRouting)
Insert a new IPv6 Routing Extension.
static TypeId GetTypeId()
The interface ID.
void SetNode(Ptr< Node > node)
Set the node.
Ptr< Ipv6ExtensionRouting > GetExtensionRouting(uint8_t typeRouting)
Get the routing extension corresponding to typeRouting.
void Remove(Ptr< Ipv6ExtensionRouting > extensionRouting)
Remove a routing extension from this demux.
Ptr< Node > m_node
The node.
Ipv6ExtensionRoutingList_t m_extensionsRouting
List of IPv6 Routing Extensions supported.
~Ipv6ExtensionRoutingDemux() override
Destructor.
IPv6 Extension Routing.
uint8_t GetExtensionNumber() const override
Get the extension number.
static const uint8_t EXT_NUMBER
Routing extension number.
Ipv6ExtensionRouting()
Constructor.
~Ipv6ExtensionRouting() override
Destructor.
static TypeId GetTypeId()
Get the type identificator.
virtual uint8_t GetTypeRouting() const
Get the type of routing.
uint8_t Process(Ptr< Packet > &packet, uint8_t offset, const Ipv6Header &ipv6Header, Ipv6Address dst, uint8_t *nextHeader, bool &stopProcessing, bool &isDropped, Ipv6L3Protocol::DropReason &dropReason) override
Process method Called from Ipv6L3Protocol::Receive.
Packet header for IPv6.
Definition: ipv6-header.h:35
DropReason
Reason why a packet has been dropped.
A base class which provides memory management and object aggregation.
Definition: object.h:89
A template-based reference counting class.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.