A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ipv6-option.cc
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 #include "ns3/log.h"
22 #include "ns3/assert.h"
23 #include "ns3/uinteger.h"
24 #include "ipv6-option.h"
25 #include "ipv6-option-header.h"
26 
27 NS_LOG_COMPONENT_DEFINE ("Ipv6Option");
28 
29 namespace ns3
30 {
31 
32 NS_OBJECT_ENSURE_REGISTERED (Ipv6Option);
33 
35 {
36  static TypeId tid = TypeId ("ns3::Ipv6Option")
37  .SetParent<Object> ()
38  .AddAttribute ("OptionNumber", "The IPv6 option number.",
39  UintegerValue (0),
40  MakeUintegerAccessor (&Ipv6Option::GetOptionNumber),
41  MakeUintegerChecker<uint8_t> ())
42  ;
43  return tid;
44 }
45 
47 {
49 }
50 
52 {
53  NS_LOG_FUNCTION (this << node);
54  m_node = node;
55 }
56 
57 
58 NS_OBJECT_ENSURE_REGISTERED (Ipv6OptionPad1);
59 
61 {
62  static TypeId tid = TypeId ("ns3::Ipv6OptionPad1")
64  .AddConstructor<Ipv6OptionPad1> ()
65  ;
66  return tid;
67 }
68 
70 {
72 }
73 
75 {
77 }
78 
80 {
82 
83  return OPT_NUMBER;
84 }
85 
86 uint8_t Ipv6OptionPad1::Process (Ptr<Packet> packet, uint8_t offset, Ipv6Header const& ipv6Header, bool& isDropped)
87 {
88  NS_LOG_FUNCTION (this << packet << offset << ipv6Header << isDropped);
89 
90  Ptr<Packet> p = packet->Copy ();
91  p->RemoveAtStart (offset);
92 
93  Ipv6OptionPad1Header pad1Header;
94  p->RemoveHeader (pad1Header);
95 
96  isDropped = false;
97 
98  return pad1Header.GetSerializedSize ();
99 }
100 
101 
102 NS_OBJECT_ENSURE_REGISTERED (Ipv6OptionPadn);
103 
105 {
106  static TypeId tid = TypeId ("ns3::Ipv6OptionPadn")
107  .SetParent<Ipv6Option> ()
108  .AddConstructor<Ipv6OptionPadn> ()
109  ;
110  return tid;
111 }
112 
114 {
116 }
117 
119 {
121 }
122 
124 {
126 
127  return OPT_NUMBER;
128 }
129 
130 uint8_t Ipv6OptionPadn::Process (Ptr<Packet> packet, uint8_t offset, Ipv6Header const& ipv6Header, bool& isDropped)
131 {
132  NS_LOG_FUNCTION (this << packet << offset << ipv6Header << isDropped);
133 
134  Ptr<Packet> p = packet->Copy ();
135  p->RemoveAtStart (offset);
136 
137  Ipv6OptionPadnHeader padnHeader;
138  p->RemoveHeader (padnHeader);
139 
140  isDropped = false;
141 
142  return padnHeader.GetSerializedSize ();
143 }
144 
145 
146 NS_OBJECT_ENSURE_REGISTERED (Ipv6OptionJumbogram);
147 
149 {
150  static TypeId tid = TypeId ("ns3::Ipv6OptionJumbogram")
151  .SetParent<Ipv6Option> ()
152  .AddConstructor<Ipv6OptionJumbogram> ()
153  ;
154  return tid;
155 }
156 
158 {
160 }
161 
163 {
165 }
166 
168 {
170 
171  return OPT_NUMBER;
172 }
173 
174 uint8_t Ipv6OptionJumbogram::Process (Ptr<Packet> packet, uint8_t offset, Ipv6Header const& ipv6Header, bool& isDropped)
175 {
176  NS_LOG_FUNCTION (this << packet << offset << ipv6Header << isDropped);
177 
178  Ptr<Packet> p = packet->Copy ();
179  p->RemoveAtStart (offset);
180 
181  Ipv6OptionJumbogramHeader jumbogramHeader;
182  p->RemoveHeader (jumbogramHeader);
183 
184  isDropped = false;
185 
186  return jumbogramHeader.GetSerializedSize ();
187 }
188 
189 
190 NS_OBJECT_ENSURE_REGISTERED (Ipv6OptionRouterAlert);
191 
193 {
194  static TypeId tid = TypeId ("ns3::Ipv6OptionRouterAlert")
195  .SetParent<Ipv6Option> ()
196  .AddConstructor<Ipv6OptionRouterAlert> ()
197  ;
198  return tid;
199 }
200 
202 {
204 }
205 
207 {
209 }
210 
212 {
214 
215  return OPT_NUMBER;
216 }
217 
218 uint8_t Ipv6OptionRouterAlert::Process (Ptr<Packet> packet, uint8_t offset, Ipv6Header const& ipv6Header, bool& isDropped)
219 {
220  NS_LOG_FUNCTION (this << packet << offset << ipv6Header << isDropped);
221 
222  Ptr<Packet> p = packet->Copy ();
223  p->RemoveAtStart (offset);
224 
225  Ipv6OptionRouterAlertHeader routerAlertHeader;
226  p->RemoveHeader (routerAlertHeader);
227 
228  isDropped = false;
229 
230  return routerAlertHeader.GetSerializedSize ();
231 }
232 
233 } /* namespace ns3 */
234 
uint32_t RemoveHeader(Header &header)
Definition: packet.cc:285
Packet header for IPv6.
Definition: ipv6-header.h:33
Ipv6OptionRouterAlert()
Constructor.
Definition: ipv6-option.cc:201
virtual ~Ipv6Option()
Destructor.
Definition: ipv6-option.cc:46
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
IPv6 Option Pad1.
Definition: ipv6-option.h:94
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
static TypeId GetTypeId()
Get the type identificator.
Definition: ipv6-option.cc:148
static TypeId GetTypeId()
Get the type identificator.
Definition: ipv6-option.cc:104
Header of IPv6 Option Pad1.
Ipv6OptionPadn()
Constructor.
Definition: ipv6-option.cc:113
#define NS_LOG_FUNCTION_NOARGS()
Definition: log.h:275
static const uint8_t OPT_NUMBER
Router alert option number.
Definition: ipv6-option.h:246
static const uint8_t OPT_NUMBER
Pad1 option number.
Definition: ipv6-option.h:100
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
Ipv6OptionJumbogram()
Constructor.
Definition: ipv6-option.cc:157
static TypeId GetTypeId()
Get the type identificator.
Definition: ipv6-option.cc:34
Ipv6OptionPad1()
Constructor.
Definition: ipv6-option.cc:69
~Ipv6OptionPad1()
Destructor.
Definition: ipv6-option.cc:74
void RemoveAtStart(uint32_t size)
Definition: packet.cc:370
virtual uint8_t GetOptionNumber() const
Get the option number.
Definition: ipv6-option.cc:79
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
Hold an unsigned integer type.
Definition: uinteger.h:46
virtual uint8_t Process(Ptr< Packet > packet, uint8_t offset, Ipv6Header const &ipv6Header, bool &isDropped)
Process method Called from Ipv6L3Protocol::Receive.
Definition: ipv6-option.cc:174
void SetNode(Ptr< Node > node)
Set the node.
Definition: ipv6-option.cc:51
Header of IPv6 Option Jumbogram.
~Ipv6OptionRouterAlert()
Destructor.
Definition: ipv6-option.cc:206
static const uint8_t OPT_NUMBER
PadN option number.
Definition: ipv6-option.h:147
virtual uint8_t Process(Ptr< Packet > packet, uint8_t offset, Ipv6Header const &ipv6Header, bool &isDropped)
Process method.
Definition: ipv6-option.cc:86
Ptr< Packet > Copy(void) const
Definition: packet.cc:131
virtual uint8_t GetOptionNumber() const =0
Get the option number.
static TypeId GetTypeId()
Get the type identificator.
Definition: ipv6-option.cc:192
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
IPv6 Option Padn.
Definition: ipv6-option.h:141
~Ipv6OptionPadn()
Destructor.
Definition: ipv6-option.cc:118
IPv6 Option Router Alert.
Definition: ipv6-option.h:240
virtual uint8_t GetOptionNumber() const
Get the option number.
Definition: ipv6-option.cc:123
~Ipv6OptionJumbogram()
Destructor.
Definition: ipv6-option.cc:162
virtual uint8_t GetOptionNumber() const
Get the option number.
Definition: ipv6-option.cc:211
virtual uint8_t GetOptionNumber() const
Get the option number.
Definition: ipv6-option.cc:167
static TypeId GetTypeId()
Get the type identificator.
Definition: ipv6-option.cc:60
static const uint8_t OPT_NUMBER
Jumbogram option number.
Definition: ipv6-option.h:194
Ptr< Node > m_node
The node.
Definition: ipv6-option.h:87
Header of IPv6 Option Router Alert.
a base class which provides memory management and object aggregation
Definition: object.h:63
virtual uint8_t Process(Ptr< Packet > packet, uint8_t offset, Ipv6Header const &ipv6Header, bool &isDropped)
Process method.
Definition: ipv6-option.cc:218
IPv6 Option Jumbogram.
Definition: ipv6-option.h:188
IPv6 Option base.
Definition: ipv6-option.h:45
a unique identifier for an interface.
Definition: type-id.h:44
virtual uint8_t Process(Ptr< Packet > packet, uint8_t offset, Ipv6Header const &ipv6Header, bool &isDropped)
Process method.
Definition: ipv6-option.cc:130
TypeId SetParent(TypeId tid)
Definition: type-id.cc:471
Header of IPv6 Option Padn.