A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
33
TypeId
Ipv6OptionHeader::GetTypeId
()
34
{
35
static
TypeId
tid =
TypeId
(
"ns3::Ipv6OptionHeader"
)
36
.
AddConstructor
<
Ipv6OptionHeader
> ()
37
.SetParent<Header> ()
38
;
39
return
tid;
40
}
41
42
TypeId
Ipv6OptionHeader::GetInstanceTypeId
()
const
43
{
44
return
GetTypeId
();
45
}
46
47
Ipv6OptionHeader::Ipv6OptionHeader
()
48
: m_type (0),
49
m_length (0)
50
{
51
}
52
53
Ipv6OptionHeader::~Ipv6OptionHeader
()
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
82
uint32_t
Ipv6OptionHeader::GetSerializedSize
()
const
83
{
84
return
m_length
+ 2;
85
}
86
87
void
Ipv6OptionHeader::Serialize
(
Buffer::Iterator
start
)
const
88
{
89
Buffer::Iterator
i =
start
;
90
91
i.
WriteU8
(
m_type
);
92
i.
WriteU8
(
m_length
);
93
94
i.
Write
(
m_data
.
Begin
(),
m_data
.
End
());
95
}
96
97
uint32_t
Ipv6OptionHeader::Deserialize
(
Buffer::Iterator
start
)
98
{
99
Buffer::Iterator
i =
start
;
100
101
m_type
= i.
ReadU8
();
102
m_length
= i.
ReadU8
();
103
104
m_data
=
Buffer
();
105
m_data
.
AddAtEnd
(
m_length
);
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
114
Ipv6OptionHeader::Alignment
Ipv6OptionHeader::GetAlignment
()
const
115
{
116
return
(
Alignment
){ 1,0};
117
}
118
119
NS_OBJECT_ENSURE_REGISTERED
(
Ipv6OptionPad1Header
);
120
121
TypeId
Ipv6OptionPad1Header::GetTypeId
()
122
{
123
static
TypeId
tid =
TypeId
(
"ns3::Ipv6OptionPad1Header"
)
124
.
AddConstructor
<
Ipv6OptionPad1Header
> ()
125
.SetParent<Ipv6OptionHeader> ()
126
;
127
return
tid;
128
}
129
130
TypeId
Ipv6OptionPad1Header::GetInstanceTypeId
()
const
131
{
132
return
GetTypeId
();
133
}
134
135
Ipv6OptionPad1Header::Ipv6OptionPad1Header
()
136
{
137
SetType
(0);
138
}
139
140
Ipv6OptionPad1Header::~Ipv6OptionPad1Header
()
141
{
142
}
143
144
void
Ipv6OptionPad1Header::Print
(std::ostream &os)
const
145
{
146
os <<
"( type = "
<< (uint32_t)
GetType
() <<
" )"
;
147
}
148
149
uint32_t
Ipv6OptionPad1Header::GetSerializedSize
()
const
150
{
151
return
1;
152
}
153
154
void
Ipv6OptionPad1Header::Serialize
(
Buffer::Iterator
start
)
const
155
{
156
Buffer::Iterator
i =
start
;
157
158
i.
WriteU8
(
GetType
());
159
}
160
161
uint32_t
Ipv6OptionPad1Header::Deserialize
(
Buffer::Iterator
start
)
162
{
163
Buffer::Iterator
i =
start
;
164
165
SetType
(i.
ReadU8
());
166
167
return
GetSerializedSize
();
168
}
169
170
NS_OBJECT_ENSURE_REGISTERED
(
Ipv6OptionPadnHeader
);
171
172
TypeId
Ipv6OptionPadnHeader::GetTypeId
()
173
{
174
static
TypeId
tid =
TypeId
(
"ns3::Ipv6OptionPadnHeader"
)
175
.
AddConstructor
<
Ipv6OptionPadnHeader
> ()
176
.SetParent<Ipv6OptionHeader> ()
177
;
178
return
tid;
179
}
180
181
TypeId
Ipv6OptionPadnHeader::GetInstanceTypeId
()
const
182
{
183
return
GetTypeId
();
184
}
185
186
Ipv6OptionPadnHeader::Ipv6OptionPadnHeader
(uint32_t pad)
187
{
188
SetType
(1);
189
NS_ASSERT_MSG
(pad >= 2,
"PadN must be at least 2 bytes long"
);
190
SetLength
(pad - 2);
191
}
192
193
Ipv6OptionPadnHeader::~Ipv6OptionPadnHeader
()
194
{
195
}
196
197
void
Ipv6OptionPadnHeader::Print
(std::ostream &os)
const
198
{
199
os <<
"( type = "
<< (uint32_t)
GetType
() <<
" length = "
<< (uint32_t)
GetLength
() <<
" )"
;
200
}
201
202
uint32_t
Ipv6OptionPadnHeader::GetSerializedSize
()
const
203
{
204
return
GetLength
() + 2;
205
}
206
207
void
Ipv6OptionPadnHeader::Serialize
(
Buffer::Iterator
start
)
const
208
{
209
Buffer::Iterator
i =
start
;
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
220
uint32_t
Ipv6OptionPadnHeader::Deserialize
(
Buffer::Iterator
start
)
221
{
222
Buffer::Iterator
i =
start
;
223
224
SetType
(i.
ReadU8
());
225
SetLength
(i.
ReadU8
());
226
227
return
GetSerializedSize
();
228
}
229
230
NS_OBJECT_ENSURE_REGISTERED
(
Ipv6OptionJumbogramHeader
);
231
232
TypeId
Ipv6OptionJumbogramHeader::GetTypeId
()
233
{
234
static
TypeId
tid =
TypeId
(
"ns3::Ipv6OptionJumbogramHeader"
)
235
.
AddConstructor
<
Ipv6OptionJumbogramHeader
> ()
236
.SetParent<Ipv6OptionHeader> ()
237
;
238
return
tid;
239
}
240
241
TypeId
Ipv6OptionJumbogramHeader::GetInstanceTypeId
()
const
242
{
243
return
GetTypeId
();
244
}
245
246
Ipv6OptionJumbogramHeader::Ipv6OptionJumbogramHeader
()
247
{
248
SetType
(0xC2);
249
SetLength
(4);
250
}
251
252
Ipv6OptionJumbogramHeader::~Ipv6OptionJumbogramHeader
()
253
{
254
}
255
256
void
Ipv6OptionJumbogramHeader::SetDataLength
(uint32_t dataLength)
257
{
258
m_dataLength
= dataLength;
259
}
260
261
uint32_t
Ipv6OptionJumbogramHeader::GetDataLength
()
const
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
271
uint32_t
Ipv6OptionJumbogramHeader::GetSerializedSize
()
const
272
{
273
return
GetLength
() + 2;
274
}
275
276
void
Ipv6OptionJumbogramHeader::Serialize
(
Buffer::Iterator
start
)
const
277
{
278
Buffer::Iterator
i =
start
;
279
280
i.
WriteU8
(
GetType
());
281
i.
WriteU8
(
GetLength
());
282
i.
WriteHtonU32
(
m_dataLength
);
283
}
284
285
uint32_t
Ipv6OptionJumbogramHeader::Deserialize
(
Buffer::Iterator
start
)
286
{
287
Buffer::Iterator
i =
start
;
288
289
SetType
(i.
ReadU8
());
290
SetLength
(i.
ReadU8
());
291
m_dataLength
= i.
ReadNtohU16
();
292
293
return
GetSerializedSize
();
294
}
295
296
Ipv6OptionHeader::Alignment
Ipv6OptionJumbogramHeader::GetAlignment
()
const
297
{
298
return
(
Alignment
){ 4,2};
//4n+2
299
}
300
301
NS_OBJECT_ENSURE_REGISTERED
(
Ipv6OptionRouterAlertHeader
);
302
303
TypeId
Ipv6OptionRouterAlertHeader::GetTypeId
()
304
{
305
static
TypeId
tid =
TypeId
(
"ns3::Ipv6OptionRouterAlertHeader"
)
306
.
AddConstructor
<
Ipv6OptionRouterAlertHeader
> ()
307
.SetParent<Ipv6OptionHeader> ()
308
;
309
return
tid;
310
}
311
312
TypeId
Ipv6OptionRouterAlertHeader::GetInstanceTypeId
()
const
313
{
314
return
GetTypeId
();
315
}
316
317
Ipv6OptionRouterAlertHeader::Ipv6OptionRouterAlertHeader
()
318
: m_value (0)
319
{
320
SetLength
(2);
321
}
322
323
Ipv6OptionRouterAlertHeader::~Ipv6OptionRouterAlertHeader
()
324
{
325
}
326
327
void
Ipv6OptionRouterAlertHeader::SetValue
(uint16_t value)
328
{
329
m_value
= value;
330
}
331
332
uint16_t
Ipv6OptionRouterAlertHeader::GetValue
()
const
333
{
334
return
m_value
;
335
}
336
337
void
Ipv6OptionRouterAlertHeader::Print
(std::ostream &os)
const
338
{
339
os <<
"( type = "
<< (uint32_t)
GetType
() <<
" length = "
<< (uint32_t)
GetLength
() <<
" value = "
<< (uint32_t)
m_value
<<
" )"
;
340
}
341
342
uint32_t
Ipv6OptionRouterAlertHeader::GetSerializedSize
()
const
343
{
344
return
GetLength
() + 2;
345
}
346
347
void
Ipv6OptionRouterAlertHeader::Serialize
(
Buffer::Iterator
start
)
const
348
{
349
Buffer::Iterator
i =
start
;
350
351
i.
WriteU8
(
GetType
());
352
i.
WriteU8
(
GetLength
());
353
i.
WriteHtonU16
(
m_value
);
354
}
355
356
uint32_t
Ipv6OptionRouterAlertHeader::Deserialize
(
Buffer::Iterator
start
)
357
{
358
Buffer::Iterator
i =
start
;
359
360
SetType
(i.
ReadU8
());
361
SetLength
(i.
ReadU8
());
362
m_value
= i.
ReadNtohU16
();
363
364
return
GetSerializedSize
();
365
}
366
367
Ipv6OptionHeader::Alignment
Ipv6OptionRouterAlertHeader::GetAlignment
()
const
368
{
369
return
(
Alignment
){ 2,0};
//2n+0
370
}
371
372
}
/* namespace ns3 */
373
src
internet
model
ipv6-option-header.cc
Generated on Tue May 14 2013 11:08:22 for ns-3 by
1.8.1.2