A Discrete-Event Network Simulator
API
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
26namespace ns3
27{
28
29NS_LOG_COMPONENT_DEFINE ("Ipv6OptionHeader");
30
31NS_OBJECT_ENSURE_REGISTERED (Ipv6OptionHeader);
32
34{
35 static TypeId tid = TypeId ("ns3::Ipv6OptionHeader")
37 .SetParent<Header> ()
38 .SetGroupName ("Internet")
39 ;
40 return tid;
41}
42
44{
45 return GetTypeId ();
46}
47
49 : m_type (0),
50 m_length (0)
51{
52}
53
55{
56}
57
58void Ipv6OptionHeader::SetType (uint8_t type)
59{
60 m_type = type;
61}
62
64{
65 return m_type;
66}
67
68void Ipv6OptionHeader::SetLength (uint8_t length)
69{
70 m_length = length;
71}
72
74{
75 return m_length;
76}
77
78void Ipv6OptionHeader::Print (std::ostream &os) const
79{
80 os << "( type = " << (uint32_t)m_type << " )";
81}
82
84{
85 return m_length + 2;
86}
87
89{
91
92 i.WriteU8 (m_type);
93 i.WriteU8 (m_length);
94
95 i.Write (m_data.Begin (), m_data.End ());
96}
97
99{
101
102 m_type = i.ReadU8 ();
103 m_length = i.ReadU8 ();
104
105 m_data = Buffer ();
107 Buffer::Iterator dataStart = i;
108 i.Next (m_length);
109 Buffer::Iterator dataEnd = i;
110 m_data.Begin ().Write (dataStart, dataEnd);
111
112 return GetSerializedSize ();
113}
114
116{
117 return (Alignment){ 1,0};
118}
119
121
123{
124 static TypeId tid = TypeId ("ns3::Ipv6OptionPad1Header")
126 .SetParent<Ipv6OptionHeader> ()
127 .SetGroupName ("Internet")
128 ;
129 return tid;
130}
131
133{
134 return GetTypeId ();
135}
136
138{
139 SetType (0);
140}
141
143{
144}
145
146void Ipv6OptionPad1Header::Print (std::ostream &os) const
147{
148 os << "( type = " << (uint32_t)GetType () << " )";
149}
150
152{
153 return 1;
154}
155
157{
159
160 i.WriteU8 (GetType ());
161}
162
164{
166
167 SetType (i.ReadU8 ());
168
169 return GetSerializedSize ();
170}
171
173
175{
176 static TypeId tid = TypeId ("ns3::Ipv6OptionPadnHeader")
178 .SetParent<Ipv6OptionHeader> ()
179 .SetGroupName ("Internet")
180 ;
181 return tid;
182}
183
185{
186 return GetTypeId ();
187}
188
190{
191 SetType (1);
192 NS_ASSERT_MSG (pad >= 2, "PadN must be at least 2 bytes long");
193 SetLength (pad - 2);
194}
195
197{
198}
199
200void Ipv6OptionPadnHeader::Print (std::ostream &os) const
201{
202 os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " )";
203}
204
206{
207 return GetLength () + 2;
208}
209
211{
213
214 i.WriteU8 (GetType ());
215 i.WriteU8 (GetLength ());
216
217 for (int padding = 0; padding < GetLength (); padding++)
218 {
219 i.WriteU8 (0);
220 }
221}
222
224{
226
227 SetType (i.ReadU8 ());
228 SetLength (i.ReadU8 ());
229
230 return GetSerializedSize ();
231}
232
234
236{
237 static TypeId tid = TypeId ("ns3::Ipv6OptionJumbogramHeader")
239 .SetParent<Ipv6OptionHeader> ()
240 .SetGroupName ("Internet")
241 ;
242 return tid;
243}
244
246{
247 return GetTypeId ();
248}
249
251{
252 SetType (0xC2);
253 SetLength (4);
254 m_dataLength = 0;
255}
256
258{
259}
260
262{
263 m_dataLength = dataLength;
264}
265
267{
268 return m_dataLength;
269}
270
271void Ipv6OptionJumbogramHeader::Print (std::ostream &os) const
272{
273 os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " data length = " << (uint32_t)m_dataLength << " )";
274}
275
277{
278 return GetLength () + 2;
279}
280
282{
284
285 i.WriteU8 (GetType ());
286 i.WriteU8 (GetLength ());
288}
289
291{
293
294 SetType (i.ReadU8 ());
295 SetLength (i.ReadU8 ());
297
298 return GetSerializedSize ();
299}
300
302{
303 return (Alignment){ 4,2}; //4n+2
304}
305
307
309{
310 static TypeId tid = TypeId ("ns3::Ipv6OptionRouterAlertHeader")
312 .SetParent<Ipv6OptionHeader> ()
313 .SetGroupName ("Internet")
314 ;
315 return tid;
316}
317
319{
320 return GetTypeId ();
321}
322
324 : m_value (0)
325{
326 SetType (5);
327 SetLength (2);
328}
329
331{
332}
333
335{
336 m_value = value;
337}
338
340{
341 return m_value;
342}
343
344void Ipv6OptionRouterAlertHeader::Print (std::ostream &os) const
345{
346 os << "( type = " << (uint32_t)GetType () << " length = " << (uint32_t)GetLength () << " value = " << (uint32_t)m_value << " )";
347}
348
350{
351 return GetLength () + 2;
352}
353
355{
357
358 i.WriteU8 (GetType ());
359 i.WriteU8 (GetLength ());
361}
362
364{
366
367 SetType (i.ReadU8 ());
368 SetLength (i.ReadU8 ());
369 m_value = i.ReadNtohU16 ();
370
371 return GetSerializedSize ();
372}
373
375{
376 return (Alignment){ 2,0}; //2n+0
377}
378
379} /* namespace ns3 */
380
iterator in a Buffer instance
Definition: buffer.h:99
void Write(uint8_t const *buffer, uint32_t size)
Definition: buffer.cc:954
uint16_t ReadNtohU16(void)
Definition: buffer.h:946
void WriteU8(uint8_t data)
Definition: buffer.h:869
void Next(void)
go forward by one byte
Definition: buffer.h:845
uint8_t ReadU8(void)
Definition: buffer.h:1021
void WriteHtonU16(uint16_t data)
Definition: buffer.h:905
void WriteHtonU32(uint32_t data)
Definition: buffer.h:924
automatically resized byte buffer
Definition: buffer.h:93
void AddAtEnd(uint32_t end)
Definition: buffer.cc:354
Buffer::Iterator End(void) const
Definition: buffer.h:1075
Buffer::Iterator Begin(void) const
Definition: buffer.h:1069
Header for IPv6 Option.
Ipv6OptionHeader()
Constructor.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
uint8_t GetLength() const
Get the option length.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
uint8_t m_type
The type of the option.
void SetLength(uint8_t length)
Set the option length.
void SetType(uint8_t type)
Set the type of the option.
uint8_t GetType() const
Get the type of the option.
virtual ~Ipv6OptionHeader()
Destructor.
virtual Alignment GetAlignment() const
Get the Alignment requirement of this option header.
uint8_t m_length
The option length.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual void Print(std::ostream &os) const
Print some information about the packet.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
static TypeId GetTypeId()
Get the type identificator.
Buffer m_data
The anonymous data of this option.
Header of IPv6 Option Jumbogram.
static TypeId GetTypeId()
Get the type identificator.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
virtual Alignment GetAlignment() const
Get the Alignment requirement of this option header.
virtual void Print(std::ostream &os) const
Print some information about the packet.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
void SetDataLength(uint32_t dataLength)
Set the data length.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
uint32_t m_dataLength
The data length.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
virtual ~Ipv6OptionJumbogramHeader()
Destructor.
uint32_t GetDataLength() const
Get the data length.
Header of IPv6 Option Pad1.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
virtual ~Ipv6OptionPad1Header()
Destructor.
static TypeId GetTypeId()
Get the type identificator.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
virtual void Print(std::ostream &os) const
Print some information about the packet.
Header of IPv6 Option Padn.
static TypeId GetTypeId()
Get the type identificator.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
Ipv6OptionPadnHeader(uint32_t pad=2)
Constructor.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
virtual void Print(std::ostream &os) const
Print some information about the packet.
virtual ~Ipv6OptionPadnHeader()
Destructor.
Header of IPv6 Option Router Alert.
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
void SetValue(uint16_t value)
Set the field "value".
virtual ~Ipv6OptionRouterAlertHeader()
Destructor.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
static TypeId GetTypeId()
Get the type identificator.
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
virtual Alignment GetAlignment() const
Get the Alignment requirement of this option header.
virtual void Print(std::ostream &os) const
Print some information about the packet.
uint16_t GetValue() const
Get the field "value".
a unique identifier for an interface.
Definition: type-id.h:59
TypeId AddConstructor(void)
Record in this TypeId the fact that the default constructor is accessible.
Definition: type-id.h:638
#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:88
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.
def start()
Definition: core.py:1853
represents the alignment requirements of an option header