A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ipv6-option-header.cc
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 #include "ns3/assert.h"
22 #include "ns3/log.h"
23 #include "ns3/header.h"
24 #include "ipv6-option-header.h"
25 
26 namespace ns3
27 {
28 
29 NS_LOG_COMPONENT_DEFINE ("Ipv6OptionHeader");
30 
31 NS_OBJECT_ENSURE_REGISTERED (Ipv6OptionHeader);
32 
34 {
35  static TypeId tid = TypeId ("ns3::Ipv6OptionHeader")
37  .SetParent<Header> ()
38  ;
39  return tid;
40 }
41 
43 {
44  return GetTypeId ();
45 }
46 
48  : m_type (0),
49  m_length (0)
50 {
51 }
52 
54 {
55 }
56 
57 void Ipv6OptionHeader::SetType (uint8_t type)
58 {
59  m_type = type;
60 }
61 
62 uint8_t Ipv6OptionHeader::GetType () const
63 {
64  return m_type;
65 }
66 
67 void Ipv6OptionHeader::SetLength (uint8_t length)
68 {
69  m_length = length;
70 }
71 
72 uint8_t Ipv6OptionHeader::GetLength () const
73 {
74  return m_length;
75 }
76 
77 void Ipv6OptionHeader::Print (std::ostream &os) const
78 {
79  os << "( type = " << (uint32_t)m_type << " )";
80 }
81 
83 {
84  return m_length + 2;
85 }
86 
88 {
90 
91  i.WriteU8 (m_type);
92  i.WriteU8 (m_length);
93 
94  i.Write (m_data.Begin (), m_data.End ());
95 }
96 
98 {
100 
101  m_type = i.ReadU8 ();
102  m_length = i.ReadU8 ();
103 
104  m_data = Buffer ();
106  Buffer::Iterator dataStart = i;
107  i.Next (m_length);
108  Buffer::Iterator dataEnd = i;
109  m_data.Begin ().Write (dataStart, dataEnd);
110 
111  return GetSerializedSize ();
112 }
113 
115 {
116  return (Alignment){ 1,0};
117 }
118 
120 
122 {
123  static TypeId tid = TypeId ("ns3::Ipv6OptionPad1Header")
125  .SetParent<Ipv6OptionHeader> ()
126  ;
127  return tid;
128 }
129 
131 {
132  return GetTypeId ();
133 }
134 
136 {
137  SetType (0);
138 }
139 
141 {
142 }
143 
144 void Ipv6OptionPad1Header::Print (std::ostream &os) const
145 {
146  os << "( type = " << (uint32_t)GetType () << " )";
147 }
148 
150 {
151  return 1;
152 }
153 
155 {
157 
158  i.WriteU8 (GetType ());
159 }
160 
162 {
164 
165  SetType (i.ReadU8 ());
166 
167  return GetSerializedSize ();
168 }
169 
171 
173 {
174  static TypeId tid = TypeId ("ns3::Ipv6OptionPadnHeader")
176  .SetParent<Ipv6OptionHeader> ()
177  ;
178  return tid;
179 }
180 
182 {
183  return GetTypeId ();
184 }
185 
187 {
188  SetType (1);
189  NS_ASSERT_MSG (pad >= 2, "PadN must be at least 2 bytes long");
190  SetLength (pad - 2);
191 }
192 
194 {
195 }
196 
197 void Ipv6OptionPadnHeader::Print (std::ostream &os) const
198 {
199  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " )";
200 }
201 
203 {
204  return GetLength () + 2;
205 }
206 
208 {
210 
211  i.WriteU8 (GetType ());
212  i.WriteU8 (GetLength ());
213 
214  for (int padding = 0; padding < GetLength (); padding++)
215  {
216  i.WriteU8 (0);
217  }
218 }
219 
221 {
223 
224  SetType (i.ReadU8 ());
225  SetLength (i.ReadU8 ());
226 
227  return GetSerializedSize ();
228 }
229 
231 
233 {
234  static TypeId tid = TypeId ("ns3::Ipv6OptionJumbogramHeader")
236  .SetParent<Ipv6OptionHeader> ()
237  ;
238  return tid;
239 }
240 
242 {
243  return GetTypeId ();
244 }
245 
247 {
248  SetType (0xC2);
249  SetLength (4);
250 }
251 
253 {
254 }
255 
257 {
258  m_dataLength = dataLength;
259 }
260 
262 {
263  return m_dataLength;
264 }
265 
266 void Ipv6OptionJumbogramHeader::Print (std::ostream &os) const
267 {
268  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " data length = " << (uint32_t)m_dataLength << " )";
269 }
270 
272 {
273  return GetLength () + 2;
274 }
275 
277 {
279 
280  i.WriteU8 (GetType ());
281  i.WriteU8 (GetLength ());
283 }
284 
286 {
288 
289  SetType (i.ReadU8 ());
290  SetLength (i.ReadU8 ());
291  m_dataLength = i.ReadNtohU16 ();
292 
293  return GetSerializedSize ();
294 }
295 
297 {
298  return (Alignment){ 4,2}; //4n+2
299 }
300 
302 
304 {
305  static TypeId tid = TypeId ("ns3::Ipv6OptionRouterAlertHeader")
307  .SetParent<Ipv6OptionHeader> ()
308  ;
309  return tid;
310 }
311 
313 {
314  return GetTypeId ();
315 }
316 
318  : m_value (0)
319 {
320  SetType (5);
321  SetLength (2);
322 }
323 
325 {
326 }
327 
329 {
330  m_value = value;
331 }
332 
334 {
335  return m_value;
336 }
337 
338 void Ipv6OptionRouterAlertHeader::Print (std::ostream &os) const
339 {
340  os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " value = " << (uint32_t)m_value << " )";
341 }
342 
344 {
345  return GetLength () + 2;
346 }
347 
349 {
351 
352  i.WriteU8 (GetType ());
353  i.WriteU8 (GetLength ());
354  i.WriteHtonU16 (m_value);
355 }
356 
358 {
360 
361  SetType (i.ReadU8 ());
362  SetLength (i.ReadU8 ());
363  m_value = i.ReadNtohU16 ();
364 
365  return GetSerializedSize ();
366 }
367 
369 {
370  return (Alignment){ 2,0}; //2n+0
371 }
372 
373 } /* namespace ns3 */
374 
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
TypeId AddConstructor(void)
Definition: type-id.h:418
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
void SetType(uint8_t type)
Set the type of the option.
Doxygen introspection did not find any typical Config paths.
virtual Alignment GetAlignment() const
Get the Alignment requirement of this option header.
virtual ~Ipv6OptionPad1Header()
Destructor.
Ipv6OptionPadnHeader(uint32_t pad=2)
Constructor.
automatically resized byte buffer
Definition: buffer.h:92
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
static TypeId GetTypeId()
Get the type identificator.
virtual void Print(std::ostream &os) const
Print some informations about the packet.
uint8_t m_type
The type of the option.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
Doxygen introspection did not find any typical Config paths.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
uint8_t GetType() const
Get the type of the option.
static TypeId GetTypeId()
Get the type identificator.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
represents the alignment requirements of an option header
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
iterator in a Buffer instance
Definition: buffer.h:98
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
virtual void Print(std::ostream &os) const
Print some informations about the packet.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual ~Ipv6OptionHeader()
Destructor.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
static TypeId GetTypeId()
Get the type identificator.
virtual void Print(std::ostream &os) const
Print some informations about the packet.
void WriteHtonU16(uint16_t data)
Definition: buffer.h:912
Buffer::Iterator End(void) const
Definition: buffer.h:1082
void Next(void)
go forward by one byte
Definition: buffer.h:852
virtual ~Ipv6OptionJumbogramHeader()
Destructor.
Buffer m_data
The anonymous data of this option.
Doxygen introspection did not find any typical Config paths.
virtual ~Ipv6OptionRouterAlertHeader()
Destructor.
Buffer::Iterator Begin(void) const
Definition: buffer.h:1076
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
void SetDataLength(uint32_t dataLength)
Set the data length.
virtual Alignment GetAlignment() const
Get the Alignment requirement of this option header.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
virtual ~Ipv6OptionPadnHeader()
Destructor.
virtual Alignment GetAlignment() const
Get the Alignment requirement of this option header.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
void WriteHtonU32(uint32_t data)
Definition: buffer.h:931
void SetValue(uint16_t value)
Set the field "value".
uint32_t GetDataLength() const
Get the data length.
bool AddAtEnd(uint32_t end)
Definition: buffer.cc:360
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:84
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
static TypeId GetTypeId()
Get the type identificator.
void WriteU8(uint8_t data)
Definition: buffer.h:876
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
uint8_t GetLength() const
Get the option length.
uint8_t ReadU8(void)
Definition: buffer.h:1028
void Write(uint8_t const *buffer, uint32_t size)
Definition: buffer.cc:982
Doxygen introspection did not find any typical Config paths.
uint16_t ReadNtohU16(void)
Definition: buffer.h:953
uint16_t GetValue() const
Get the field "value".
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
uint8_t m_length
The option length.
static TypeId GetTypeId()
Get the type identificator.
a unique identifier for an interface.
Definition: type-id.h:49
void SetLength(uint8_t length)
Set the option length.
Doxygen introspection did not find any typical Config paths.
virtual void Print(std::ostream &os) const
Print some informations about the packet.
virtual void Print(std::ostream &os) const
Print some informations about the packet.
uint32_t m_dataLength
The data length.
Ipv6OptionHeader()
Constructor.