A Discrete-Event Network Simulator
API
ipv6-option.cc
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 #include "ipv6-option.h"
21 
22 #include "ipv6-option-header.h"
23 
24 #include "ns3/assert.h"
25 #include "ns3/log.h"
26 #include "ns3/uinteger.h"
27 
28 namespace ns3
29 {
30 
31 NS_LOG_COMPONENT_DEFINE("Ipv6Option");
32 
33 NS_OBJECT_ENSURE_REGISTERED(Ipv6Option);
34 
35 TypeId
37 {
38  static TypeId tid = TypeId("ns3::Ipv6Option")
39  .SetParent<Object>()
40  .SetGroupName("Internet")
41  .AddAttribute("OptionNumber",
42  "The IPv6 option number.",
43  UintegerValue(0),
45  MakeUintegerChecker<uint8_t>());
46  return tid;
47 }
48 
50 {
51  NS_LOG_FUNCTION(this);
52 }
53 
54 void
56 {
57  NS_LOG_FUNCTION(this << node);
58  m_node = node;
59 }
60 
62 
63 TypeId
65 {
66  static TypeId tid = TypeId("ns3::Ipv6OptionPad1")
68  .SetGroupName("Internet")
69  .AddConstructor<Ipv6OptionPad1>();
70  return tid;
71 }
72 
74 {
75  NS_LOG_FUNCTION(this);
76 }
77 
79 {
80  NS_LOG_FUNCTION(this);
81 }
82 
83 uint8_t
85 {
86  NS_LOG_FUNCTION(this);
87 
88  return OPT_NUMBER;
89 }
90 
91 uint8_t
93  uint8_t offset,
94  const Ipv6Header& ipv6Header,
95  bool& isDropped)
96 {
97  NS_LOG_FUNCTION(this << packet << offset << ipv6Header << isDropped);
98 
99  Ptr<Packet> p = packet->Copy();
100  p->RemoveAtStart(offset);
101 
102  Ipv6OptionPad1Header pad1Header;
103  p->RemoveHeader(pad1Header);
104 
105  isDropped = false;
106 
107  return pad1Header.GetSerializedSize();
108 }
109 
111 
112 TypeId
114 {
115  static TypeId tid = TypeId("ns3::Ipv6OptionPadn")
117  .SetGroupName("Internet")
118  .AddConstructor<Ipv6OptionPadn>();
119  return tid;
120 }
121 
123 {
124  NS_LOG_FUNCTION(this);
125 }
126 
128 {
129  NS_LOG_FUNCTION(this);
130 }
131 
132 uint8_t
134 {
135  NS_LOG_FUNCTION(this);
136 
137  return OPT_NUMBER;
138 }
139 
140 uint8_t
142  uint8_t offset,
143  const Ipv6Header& ipv6Header,
144  bool& isDropped)
145 {
146  NS_LOG_FUNCTION(this << packet << offset << ipv6Header << isDropped);
147 
148  Ptr<Packet> p = packet->Copy();
149  p->RemoveAtStart(offset);
150 
151  Ipv6OptionPadnHeader padnHeader;
152  p->RemoveHeader(padnHeader);
153 
154  isDropped = false;
155 
156  return padnHeader.GetSerializedSize();
157 }
158 
160 
161 TypeId
163 {
164  static TypeId tid = TypeId("ns3::Ipv6OptionJumbogram")
166  .SetGroupName("Internet")
167  .AddConstructor<Ipv6OptionJumbogram>();
168  return tid;
169 }
170 
172 {
173  NS_LOG_FUNCTION(this);
174 }
175 
177 {
178  NS_LOG_FUNCTION(this);
179 }
180 
181 uint8_t
183 {
184  NS_LOG_FUNCTION(this);
185 
186  return OPT_NUMBER;
187 }
188 
189 uint8_t
191  uint8_t offset,
192  const Ipv6Header& ipv6Header,
193  bool& isDropped)
194 {
195  NS_LOG_FUNCTION(this << packet << offset << ipv6Header << isDropped);
196 
197  Ptr<Packet> p = packet->Copy();
198  p->RemoveAtStart(offset);
199 
200  Ipv6OptionJumbogramHeader jumbogramHeader;
201  p->RemoveHeader(jumbogramHeader);
202 
203  isDropped = false;
204 
205  return jumbogramHeader.GetSerializedSize();
206 }
207 
209 
210 TypeId
212 {
213  static TypeId tid = TypeId("ns3::Ipv6OptionRouterAlert")
215  .SetGroupName("Internet")
216  .AddConstructor<Ipv6OptionRouterAlert>();
217  return tid;
218 }
219 
221 {
222  NS_LOG_FUNCTION(this);
223 }
224 
226 {
227  NS_LOG_FUNCTION(this);
228 }
229 
230 uint8_t
232 {
233  NS_LOG_FUNCTION(this);
234 
235  return OPT_NUMBER;
236 }
237 
238 uint8_t
240  uint8_t offset,
241  const Ipv6Header& ipv6Header,
242  bool& isDropped)
243 {
244  NS_LOG_FUNCTION(this << packet << offset << ipv6Header << isDropped);
245 
246  Ptr<Packet> p = packet->Copy();
247  p->RemoveAtStart(offset);
248 
249  Ipv6OptionRouterAlertHeader routerAlertHeader;
250  p->RemoveHeader(routerAlertHeader);
251 
252  isDropped = false;
253 
254  return routerAlertHeader.GetSerializedSize();
255 }
256 
257 } /* namespace ns3 */
Packet header for IPv6.
Definition: ipv6-header.h:35
IPv6 Option base.
Definition: ipv6-option.h:47
static TypeId GetTypeId()
Get the type identificator.
Definition: ipv6-option.cc:36
~Ipv6Option() override
Destructor.
Definition: ipv6-option.cc:49
virtual uint8_t GetOptionNumber() const =0
Get the option number.
Ptr< Node > m_node
The node.
Definition: ipv6-option.h:91
void SetNode(Ptr< Node > node)
Set the node.
Definition: ipv6-option.cc:55
Header of IPv6 Option Jumbogram.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
IPv6 Option Jumbogram.
Definition: ipv6-option.h:202
uint8_t GetOptionNumber() const override
Get the option number.
Definition: ipv6-option.cc:182
~Ipv6OptionJumbogram() override
Destructor.
Definition: ipv6-option.cc:176
static TypeId GetTypeId()
Get the type identificator.
Definition: ipv6-option.cc:162
uint8_t Process(Ptr< Packet > packet, uint8_t offset, const Ipv6Header &ipv6Header, bool &isDropped) override
Process method Called from Ipv6L3Protocol::Receive.
Definition: ipv6-option.cc:190
static const uint8_t OPT_NUMBER
Jumbogram option number.
Definition: ipv6-option.h:207
Ipv6OptionJumbogram()
Constructor.
Definition: ipv6-option.cc:171
Header of IPv6 Option Pad1.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
IPv6 Option Pad1.
Definition: ipv6-option.h:100
static TypeId GetTypeId()
Get the type identificator.
Definition: ipv6-option.cc:64
static const uint8_t OPT_NUMBER
Pad1 option number.
Definition: ipv6-option.h:105
uint8_t GetOptionNumber() const override
Get the option number.
Definition: ipv6-option.cc:84
Ipv6OptionPad1()
Constructor.
Definition: ipv6-option.cc:73
~Ipv6OptionPad1() override
Destructor.
Definition: ipv6-option.cc:78
uint8_t Process(Ptr< Packet > packet, uint8_t offset, const Ipv6Header &ipv6Header, bool &isDropped) override
Process method.
Definition: ipv6-option.cc:92
Header of IPv6 Option Padn.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
IPv6 Option Padn.
Definition: ipv6-option.h:151
~Ipv6OptionPadn() override
Destructor.
Definition: ipv6-option.cc:127
static const uint8_t OPT_NUMBER
PadN option number.
Definition: ipv6-option.h:156
uint8_t GetOptionNumber() const override
Get the option number.
Definition: ipv6-option.cc:133
uint8_t Process(Ptr< Packet > packet, uint8_t offset, const Ipv6Header &ipv6Header, bool &isDropped) override
Process method.
Definition: ipv6-option.cc:141
Ipv6OptionPadn()
Constructor.
Definition: ipv6-option.cc:122
static TypeId GetTypeId()
Get the type identificator.
Definition: ipv6-option.cc:113
Header of IPv6 Option Router Alert.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
IPv6 Option Router Alert.
Definition: ipv6-option.h:252
static const uint8_t OPT_NUMBER
Router alert option number.
Definition: ipv6-option.h:257
uint8_t Process(Ptr< Packet > packet, uint8_t offset, const Ipv6Header &ipv6Header, bool &isDropped) override
Process method.
Definition: ipv6-option.cc:239
~Ipv6OptionRouterAlert() override
Destructor.
Definition: ipv6-option.cc:225
uint8_t GetOptionNumber() const override
Get the option number.
Definition: ipv6-option.cc:231
static TypeId GetTypeId()
Get the type identificator.
Definition: ipv6-option.cc:211
Ipv6OptionRouterAlert()
Constructor.
Definition: ipv6-option.cc:220
A base class which provides memory management and object aggregation.
Definition: object.h:89
uint32_t RemoveHeader(Header &header)
Deserialize and remove the header from the internal buffer.
Definition: packet.cc:294
void RemoveAtStart(uint32_t size)
Remove size bytes from the start of the current packet.
Definition: packet.cc:384
Ptr< Packet > Copy() const
performs a COW copy of the packet.
Definition: packet.cc:131
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
Hold an unsigned integer type.
Definition: uinteger.h:45
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46