A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ipv6-option-header.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007-2009 Strasbourg University
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: David Gross <gdavid.devel@gmail.com>
7 */
8
10
11#include "ns3/assert.h"
12#include "ns3/header.h"
13#include "ns3/log.h"
14
15namespace ns3
16{
17
18NS_LOG_COMPONENT_DEFINE("Ipv6OptionHeader");
19
20NS_OBJECT_ENSURE_REGISTERED(Ipv6OptionHeader);
21
22TypeId
24{
25 static TypeId tid = TypeId("ns3::Ipv6OptionHeader")
27 .SetParent<Header>()
28 .SetGroupName("Internet");
29 return tid;
30}
31
37
39 : m_type(0),
40 m_length(0)
41{
42}
43
47
48void
50{
51 m_type = type;
52}
53
54uint8_t
56{
57 return m_type;
58}
59
60void
62{
63 m_length = length;
64}
65
66uint8_t
68{
69 return m_length;
70}
71
72void
73Ipv6OptionHeader::Print(std::ostream& os) const
74{
75 os << "( type = " << (uint32_t)m_type << " )";
76}
77
80{
81 return m_length + 2;
82}
83
84void
86{
87 Buffer::Iterator i = start;
88
89 i.WriteU8(m_type);
91
92 i.Write(m_data.Begin(), m_data.End());
93}
94
97{
98 Buffer::Iterator i = start;
99
100 m_type = i.ReadU8();
101 m_length = i.ReadU8();
102
103 m_data = Buffer();
105 Buffer::Iterator dataStart = i;
106 i.Next(m_length);
107 Buffer::Iterator dataEnd = i;
108 m_data.Begin().Write(dataStart, dataEnd);
109
110 return GetSerializedSize();
111}
112
115{
116 return Alignment{1, 0};
117}
118
120
121TypeId
123{
124 static TypeId tid = TypeId("ns3::Ipv6OptionPad1Header")
126 .SetParent<Ipv6OptionHeader>()
127 .SetGroupName("Internet");
128 return tid;
129}
130
131TypeId
136
141
145
146void
147Ipv6OptionPad1Header::Print(std::ostream& os) const
148{
149 os << "( type = " << (uint32_t)GetType() << " )";
150}
151
154{
155 return 1;
156}
157
158void
160{
161 Buffer::Iterator i = start;
162
163 i.WriteU8(GetType());
164}
165
168{
169 Buffer::Iterator i = start;
170
171 SetType(i.ReadU8());
172
173 return GetSerializedSize();
174}
175
177
178TypeId
180{
181 static TypeId tid = TypeId("ns3::Ipv6OptionPadnHeader")
183 .SetParent<Ipv6OptionHeader>()
184 .SetGroupName("Internet");
185 return tid;
186}
187
188TypeId
193
195{
196 SetType(1);
197 NS_ASSERT_MSG(pad >= 2, "PadN must be at least 2 bytes long");
198 SetLength(pad - 2);
199}
200
204
205void
206Ipv6OptionPadnHeader::Print(std::ostream& os) const
207{
208 os << "( type = " << (uint32_t)GetType() << " length = " << (uint32_t)GetLength() << " )";
209}
210
213{
214 return GetLength() + 2;
215}
216
217void
219{
220 Buffer::Iterator i = start;
221
222 i.WriteU8(GetType());
223 i.WriteU8(GetLength());
224
225 for (int padding = 0; padding < GetLength(); padding++)
226 {
227 i.WriteU8(0);
228 }
229}
230
233{
234 Buffer::Iterator i = start;
235
236 SetType(i.ReadU8());
237 SetLength(i.ReadU8());
238
239 return GetSerializedSize();
240}
241
243
244TypeId
246{
247 static TypeId tid = TypeId("ns3::Ipv6OptionJumbogramHeader")
249 .SetParent<Ipv6OptionHeader>()
250 .SetGroupName("Internet");
251 return tid;
252}
253
254TypeId
259
266
270
271void
273{
274 m_dataLength = dataLength;
275}
276
282
283void
284Ipv6OptionJumbogramHeader::Print(std::ostream& os) const
285{
286 os << "( type = " << (uint32_t)GetType() << " length = " << (uint32_t)GetLength()
287 << " data length = " << (uint32_t)m_dataLength << " )";
288}
289
292{
293 return GetLength() + 2;
294}
295
296void
305
308{
309 Buffer::Iterator i = start;
310
311 SetType(i.ReadU8());
312 SetLength(i.ReadU8());
314
315 return GetSerializedSize();
316}
317
320{
321 return Alignment{4, 2}; // 4n+2
322}
323
325
326TypeId
328{
329 static TypeId tid = TypeId("ns3::Ipv6OptionRouterAlertHeader")
331 .SetParent<Ipv6OptionHeader>()
332 .SetGroupName("Internet");
333 return tid;
334}
335
336TypeId
341
348
352
353void
355{
356 m_value = value;
357}
358
359uint16_t
361{
362 return m_value;
363}
364
365void
367{
368 os << "( type = " << (uint32_t)GetType() << " length = " << (uint32_t)GetLength()
369 << " value = " << (uint32_t)m_value << " )";
370}
371
377
378void
387
390{
391 Buffer::Iterator i = start;
392
393 SetType(i.ReadU8());
394 SetLength(i.ReadU8());
395 m_value = i.ReadNtohU16();
396
397 return GetSerializedSize();
398}
399
402{
403 return Alignment{2, 0}; // 2n+0
404}
405
406} /* namespace ns3 */
iterator in a Buffer instance
Definition buffer.h:89
void WriteU8(uint8_t data)
Definition buffer.h:870
void Write(const uint8_t *buffer, uint32_t size)
Definition buffer.cc:937
void WriteHtonU16(uint16_t data)
Definition buffer.h:904
void WriteHtonU32(uint32_t data)
Definition buffer.h:922
uint16_t ReadNtohU16()
Definition buffer.h:943
void Next()
go forward by one byte
Definition buffer.h:842
automatically resized byte buffer
Definition buffer.h:83
Buffer::Iterator Begin() const
Definition buffer.h:1063
void AddAtEnd(uint32_t end)
Definition buffer.cc:349
Buffer::Iterator End() const
Definition buffer.h:1070
Header for IPv6 Option.
uint8_t GetLength() const
Get the option length.
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.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
void Print(std::ostream &os) const override
Print some information about the packet.
uint8_t GetType() const
Get the type of the option.
virtual Alignment GetAlignment() const
Get the Alignment requirement of this option header.
uint8_t m_length
The option length.
~Ipv6OptionHeader() override
Destructor.
static TypeId GetTypeId()
Get the type identificator.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
Buffer m_data
The anonymous data of this option.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
Header of IPv6 Option Jumbogram.
static TypeId GetTypeId()
Get the type identificator.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
Alignment GetAlignment() const override
Get the Alignment requirement of this option header.
~Ipv6OptionJumbogramHeader() override
Destructor.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
void SetDataLength(uint32_t dataLength)
Set the data length.
uint32_t m_dataLength
The data length.
void Print(std::ostream &os) const override
Print some information about the packet.
uint32_t GetDataLength() const
Get the data length.
Header of IPv6 Option Pad1.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
void Print(std::ostream &os) const override
Print some information about the packet.
static TypeId GetTypeId()
Get the type identificator.
~Ipv6OptionPad1Header() override
Destructor.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
Header of IPv6 Option Padn.
static TypeId GetTypeId()
Get the type identificator.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
TypeId GetInstanceTypeId() const override
Get the instance type ID.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
Ipv6OptionPadnHeader(uint32_t pad=2)
Constructor.
void Print(std::ostream &os) const override
Print some information about the packet.
~Ipv6OptionPadnHeader() override
Destructor.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
Header of IPv6 Option Router Alert.
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
void SetValue(uint16_t value)
Set the field "value".
TypeId GetInstanceTypeId() const override
Get the instance type ID.
static TypeId GetTypeId()
Get the type identificator.
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the packet.
Alignment GetAlignment() const override
Get the Alignment requirement of this option header.
uint16_t GetValue() const
Get the field "value".
void Print(std::ostream &os) const override
Print some information about the packet.
~Ipv6OptionRouterAlertHeader() override
Destructor.
a unique identifier for an interface.
Definition type-id.h:48
TypeId AddConstructor()
Record in this TypeId the fact that the default constructor is accessible.
Definition type-id.h:670
#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:75
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.
represents the alignment requirements of an option header