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
dsr-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) 2011 Yufei Cheng
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: Yufei Cheng <yfcheng@ittc.ku.edu>
19
*
20
* James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
21
* ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets
22
* Information and Telecommunication Technology Center (ITTC)
23
* and Department of Electrical Engineering and Computer Science
24
* The University of Kansas Lawrence, KS USA.
25
*
26
* Work supported in part by NSF FIND (Future Internet Design) Program
27
* under grant CNS-0626918 (Postmodern Internet Architecture),
28
* NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
29
* US Department of Defense (DoD), and ITTC at The University of Kansas.
30
*/
31
32
#include "ns3/assert.h"
33
#include "ns3/log.h"
34
#include "ns3/header.h"
35
#include "
dsr-option-header.h
"
36
#include "ns3/ipv4-address.h"
37
#include "ns3/address-utils.h"
38
#include "ns3/packet.h"
39
#include "ns3/enum.h"
40
41
namespace
ns3 {
42
namespace
dsr {
43
NS_LOG_COMPONENT_DEFINE
(
"DsrOptionHeader"
);
44
45
NS_OBJECT_ENSURE_REGISTERED
(DsrOptionHeader);
46
47
TypeId
DsrOptionHeader::GetTypeId
()
48
{
49
static
TypeId
tid =
TypeId
(
"ns3::dsr::DsrOptionHeader"
)
50
.
AddConstructor
<
DsrOptionHeader
> ()
51
.SetParent<Header> ()
52
;
53
return
tid;
54
}
55
56
TypeId
DsrOptionHeader::GetInstanceTypeId
()
const
57
{
58
return
GetTypeId
();
59
}
60
61
DsrOptionHeader::DsrOptionHeader
()
62
: m_type (0),
63
m_length (0)
64
{
65
}
66
67
DsrOptionHeader::~DsrOptionHeader
()
68
{
69
}
70
71
void
DsrOptionHeader::SetType
(uint8_t type)
72
{
73
m_type
= type;
74
}
75
76
uint8_t
DsrOptionHeader::GetType
()
const
77
{
78
return
m_type
;
79
}
80
81
void
DsrOptionHeader::SetLength
(uint8_t length)
82
{
83
m_length
= length;
84
}
85
86
uint8_t
DsrOptionHeader::GetLength
()
const
87
{
88
return
m_length
;
89
}
90
91
void
DsrOptionHeader::Print
(std::ostream &os)
const
92
{
93
os <<
"( type = "
<< (uint32_t)
m_type
<<
" length = "
<< (uint32_t)
m_length
<<
" )"
;
94
}
95
96
uint32_t
DsrOptionHeader::GetSerializedSize
()
const
97
{
98
return
m_length
+ 2;
99
}
100
101
void
DsrOptionHeader::Serialize
(
Buffer::Iterator
start
)
const
102
{
103
Buffer::Iterator
i =
start
;
104
105
i.
WriteU8
(
m_type
);
106
i.
WriteU8
(
m_length
);
107
i.
Write
(
m_data
.
Begin
(),
m_data
.
End
());
108
}
109
110
uint32_t
DsrOptionHeader::Deserialize
(
Buffer::Iterator
start
)
111
{
112
Buffer::Iterator
i =
start
;
113
114
m_type
= i.
ReadU8
();
115
m_length
= i.
ReadU8
();
116
117
m_data
=
Buffer
();
118
m_data
.
AddAtEnd
(
m_length
);
119
Buffer::Iterator
dataStart = i;
120
i.
Next
(
m_length
);
121
Buffer::Iterator
dataEnd = i;
122
m_data
.
Begin
().
Write
(dataStart, dataEnd);
123
124
return
GetSerializedSize
();
125
}
126
127
DsrOptionHeader::Alignment
DsrOptionHeader::GetAlignment
()
const
128
{
129
Alignment
retVal = { 1, 0 };
130
return
retVal;
131
}
132
133
NS_OBJECT_ENSURE_REGISTERED
(
DsrOptionPad1Header
);
134
135
TypeId
DsrOptionPad1Header::GetTypeId
()
136
{
137
static
TypeId
tid =
TypeId
(
"ns3::dsr::DsrOptionPad1Header"
)
138
.
AddConstructor
<
DsrOptionPad1Header
> ()
139
.SetParent<DsrOptionHeader> ()
140
;
141
return
tid;
142
}
143
144
TypeId
DsrOptionPad1Header::GetInstanceTypeId
()
const
145
{
146
return
GetTypeId
();
147
}
148
149
DsrOptionPad1Header::DsrOptionPad1Header
()
150
{
151
SetType
(224);
152
}
153
154
DsrOptionPad1Header::~DsrOptionPad1Header
()
155
{
156
}
157
158
void
DsrOptionPad1Header::Print
(std::ostream &os)
const
159
{
160
os <<
"( type = "
<< (uint32_t)
GetType
() <<
" )"
;
161
}
162
163
uint32_t
DsrOptionPad1Header::GetSerializedSize
()
const
164
{
165
return
1;
166
}
167
168
void
DsrOptionPad1Header::Serialize
(
Buffer::Iterator
start
)
const
169
{
170
Buffer::Iterator
i =
start
;
171
172
i.
WriteU8
(
GetType
());
173
}
174
175
uint32_t
DsrOptionPad1Header::Deserialize
(
Buffer::Iterator
start
)
176
{
177
Buffer::Iterator
i =
start
;
178
179
SetType
(i.
ReadU8
());
180
181
return
GetSerializedSize
();
182
}
183
184
NS_OBJECT_ENSURE_REGISTERED
(
DsrOptionPadnHeader
);
185
186
TypeId
DsrOptionPadnHeader::GetTypeId
()
187
{
188
static
TypeId
tid =
TypeId
(
"ns3::dsr::DsrOptionPadnHeader"
)
189
.
AddConstructor
<
DsrOptionPadnHeader
> ()
190
.SetParent<DsrOptionHeader> ()
191
;
192
return
tid;
193
}
194
195
TypeId
DsrOptionPadnHeader::GetInstanceTypeId
()
const
196
{
197
return
GetTypeId
();
198
}
199
200
DsrOptionPadnHeader::DsrOptionPadnHeader
(uint32_t pad)
201
{
202
SetType
(0);
203
NS_ASSERT_MSG
(pad >= 2,
"PadN must be at least 2 bytes long"
);
204
SetLength
(pad - 2);
205
}
206
207
DsrOptionPadnHeader::~DsrOptionPadnHeader
()
208
{
209
}
210
211
void
DsrOptionPadnHeader::Print
(std::ostream &os)
const
212
{
213
os <<
"( type = "
<< (uint32_t)
GetType
() <<
" length = "
<< (uint32_t)
GetLength
() <<
" )"
;
214
}
215
216
uint32_t
DsrOptionPadnHeader::GetSerializedSize
()
const
217
{
218
return
GetLength
() + 2;
219
}
220
221
void
DsrOptionPadnHeader::Serialize
(
Buffer::Iterator
start
)
const
222
{
223
Buffer::Iterator
i =
start
;
224
225
i.
WriteU8
(
GetType
());
226
i.
WriteU8
(
GetLength
());
227
228
for
(
int
padding = 0; padding <
GetLength
(); padding++)
229
{
230
i.
WriteU8
(0);
231
}
232
}
233
234
uint32_t
DsrOptionPadnHeader::Deserialize
(
Buffer::Iterator
start
)
235
{
236
Buffer::Iterator
i =
start
;
237
238
SetType
(i.
ReadU8
());
239
SetLength
(i.
ReadU8
());
240
241
return
GetSerializedSize
();
242
}
243
244
NS_OBJECT_ENSURE_REGISTERED
(
DsrOptionRreqHeader
);
245
246
TypeId
DsrOptionRreqHeader::GetTypeId
()
247
{
248
static
TypeId
tid =
TypeId
(
"ns3::dsr::DsrOptionRreqHeader"
)
249
.
AddConstructor
<
DsrOptionRreqHeader
> ()
250
.SetParent<DsrOptionHeader> ()
251
;
252
return
tid;
253
}
254
255
TypeId
DsrOptionRreqHeader::GetInstanceTypeId
()
const
256
{
257
return
GetTypeId
();
258
}
259
260
DsrOptionRreqHeader::DsrOptionRreqHeader
()
261
: m_ipv4Address (0)
262
{
263
SetType
(1);
264
SetLength
(6 +
m_ipv4Address
.size () * 4);
265
}
266
267
DsrOptionRreqHeader::~DsrOptionRreqHeader
()
268
{
269
}
270
271
void
DsrOptionRreqHeader::SetNumberAddress
(uint8_t n)
272
{
273
m_ipv4Address
.clear ();
274
m_ipv4Address
.assign (n,
Ipv4Address
(
""
));
275
}
276
277
Ipv4Address
DsrOptionRreqHeader::GetTarget
()
278
{
279
return
m_target
;
280
}
281
282
void
DsrOptionRreqHeader::SetTarget
(
Ipv4Address
target)
283
{
284
m_target
= target;
285
}
286
287
void
DsrOptionRreqHeader::AddNodeAddress
(
Ipv4Address
ipv4)
288
{
289
m_ipv4Address
.push_back (ipv4);
290
SetLength
(6 +
m_ipv4Address
.size () * 4);
291
}
292
293
void
DsrOptionRreqHeader::SetNodesAddress
(std::vector<Ipv4Address> ipv4Address)
294
{
295
m_ipv4Address
= ipv4Address;
296
SetLength
(6 +
m_ipv4Address
.size () * 4);
297
}
298
299
std::vector<Ipv4Address>
DsrOptionRreqHeader::GetNodesAddresses
()
const
300
{
301
return
m_ipv4Address
;
302
}
303
304
uint32_t
DsrOptionRreqHeader::GetNodesNumber
()
const
305
{
306
return
m_ipv4Address
.size ();
307
}
308
309
void
DsrOptionRreqHeader::SetNodeAddress
(uint8_t index,
Ipv4Address
addr)
310
{
311
m_ipv4Address
.at (index) = addr;
312
}
313
314
Ipv4Address
DsrOptionRreqHeader::GetNodeAddress
(uint8_t index)
const
315
{
316
return
m_ipv4Address
.at (index);
317
}
318
319
void
DsrOptionRreqHeader::SetId
(uint16_t identification)
320
{
321
m_identification
= identification;
322
}
323
324
uint16_t
DsrOptionRreqHeader::GetId
()
const
325
{
326
return
m_identification
;
327
}
328
329
void
DsrOptionRreqHeader::Print
(std::ostream &os)
const
330
{
331
os <<
"( type = "
<< (uint32_t)
GetType
() <<
" length = "
<< (uint32_t)
GetLength
() <<
""
;
332
333
for
(std::vector<Ipv4Address>::const_iterator it =
m_ipv4Address
.begin (); it !=
m_ipv4Address
.end (); it++)
334
{
335
os << *it <<
" "
;
336
}
337
338
os <<
")"
;
339
}
340
341
uint32_t
DsrOptionRreqHeader::GetSerializedSize
()
const
342
{
343
return
8 +
m_ipv4Address
.size () * 4;
344
}
345
346
void
DsrOptionRreqHeader::Serialize
(
Buffer::Iterator
start
)
const
347
{
348
Buffer::Iterator
i =
start
;
349
uint8_t buff[4];
350
351
i.
WriteU8
(
GetType
());
352
i.
WriteU8
(
GetLength
());
353
i.
WriteHtonU16
(
m_identification
);
354
WriteTo
(i,
m_target
);
355
356
for
(VectorIpv4Address_t::const_iterator it =
m_ipv4Address
.begin (); it !=
m_ipv4Address
.end (); it++)
357
{
358
it->Serialize (buff);
359
i.
Write
(buff, 4);
360
}
361
}
362
363
uint32_t
DsrOptionRreqHeader::Deserialize
(
Buffer::Iterator
start
)
364
{
365
Buffer::Iterator
i =
start
;
366
uint8_t buff[4];
367
368
SetType
(i.
ReadU8
());
369
SetLength
(i.
ReadU8
());
370
m_identification
= i.
ReadNtohU16
();
371
ReadFrom
(i,
m_target
);
372
373
uint8_t index = 0;
374
for
(std::vector<Ipv4Address>::iterator it =
m_ipv4Address
.begin (); it !=
m_ipv4Address
.end (); it++)
375
{
376
i.
Read
(buff, 4);
377
m_address
= it->
Deserialize
(buff);
378
SetNodeAddress
(index,
m_address
);
379
++index;
380
}
381
382
return
GetSerializedSize
();
383
}
384
385
DsrOptionHeader::Alignment
DsrOptionRreqHeader::GetAlignment
()
const
386
{
387
Alignment
retVal = { 4, 0 };
388
return
retVal;
389
}
390
391
NS_OBJECT_ENSURE_REGISTERED
(
DsrOptionRrepHeader
);
392
393
TypeId
DsrOptionRrepHeader::GetTypeId
()
394
{
395
static
TypeId
tid =
TypeId
(
"ns3::dsr::DsrOptionRrepHeader"
)
396
.
AddConstructor
<
DsrOptionRrepHeader
> ()
397
.SetParent<DsrOptionHeader> ()
398
;
399
return
tid;
400
}
401
402
TypeId
DsrOptionRrepHeader::GetInstanceTypeId
()
const
403
{
404
return
GetTypeId
();
405
}
406
407
DsrOptionRrepHeader::DsrOptionRrepHeader
()
408
: m_ipv4Address (0)
409
{
410
SetType
(2);
411
SetLength
(2 +
m_ipv4Address
.size () * 4);
412
}
413
414
DsrOptionRrepHeader::~DsrOptionRrepHeader
()
415
{
416
}
417
418
void
DsrOptionRrepHeader::SetNumberAddress
(uint8_t n)
419
{
420
m_ipv4Address
.clear ();
421
m_ipv4Address
.assign (n,
Ipv4Address
(
""
));
422
}
423
424
void
DsrOptionRrepHeader::SetNodesAddress
(std::vector<Ipv4Address> ipv4Address)
425
{
426
m_ipv4Address
= ipv4Address;
427
SetLength
(2 +
m_ipv4Address
.size () * 4);
428
}
429
430
std::vector<Ipv4Address>
DsrOptionRrepHeader::GetNodesAddress
()
const
431
{
432
return
m_ipv4Address
;
433
}
434
435
void
DsrOptionRrepHeader::SetNodeAddress
(uint8_t index,
Ipv4Address
addr)
436
{
437
m_ipv4Address
.at (index) = addr;
438
}
439
440
Ipv4Address
DsrOptionRrepHeader::GetNodeAddress
(uint8_t index)
const
441
{
442
return
m_ipv4Address
.at (index);
443
}
444
445
Ipv4Address
DsrOptionRrepHeader::GetTargetAddress
(std::vector<Ipv4Address> ipv4Address)
const
446
{
447
return
m_ipv4Address
.at (ipv4Address.size () - 1);
448
}
449
450
void
DsrOptionRrepHeader::Print
(std::ostream &os)
const
451
{
452
os <<
"( type = "
<< (uint32_t)
GetType
() <<
" length = "
<< (uint32_t)
GetLength
() <<
""
;
453
454
for
(std::vector<Ipv4Address>::const_iterator it =
m_ipv4Address
.begin (); it !=
m_ipv4Address
.end (); it++)
455
{
456
os << *it <<
" "
;
457
}
458
459
os <<
")"
;
460
}
461
462
uint32_t
DsrOptionRrepHeader::GetSerializedSize
()
const
463
{
464
return
4 +
m_ipv4Address
.size () * 4;
465
}
466
467
void
DsrOptionRrepHeader::Serialize
(
Buffer::Iterator
start
)
const
468
{
469
Buffer::Iterator
i =
start
;
470
uint8_t buff[4];
471
472
i.
WriteU8
(
GetType
());
473
i.
WriteU8
(
GetLength
());
474
i.
WriteU8
(0);
475
i.
WriteU8
(0);
476
477
for
(VectorIpv4Address_t::const_iterator it =
m_ipv4Address
.begin (); it !=
m_ipv4Address
.end (); it++)
478
{
479
it->Serialize (buff);
480
i.
Write
(buff, 4);
481
}
482
}
483
484
uint32_t
DsrOptionRrepHeader::Deserialize
(
Buffer::Iterator
start
)
485
{
486
Buffer::Iterator
i =
start
;
487
uint8_t buff[4];
488
489
SetType
(i.
ReadU8
());
490
SetLength
(i.
ReadU8
());
491
i.
ReadU8
();
492
i.
ReadU8
();
493
494
uint8_t index = 0;
495
for
(std::vector<Ipv4Address>::iterator it =
m_ipv4Address
.begin (); it !=
m_ipv4Address
.end (); it++)
496
{
497
i.
Read
(buff, 4);
498
m_address
= it->
Deserialize
(buff);
499
SetNodeAddress
(index,
m_address
);
500
++index;
501
}
502
503
return
GetSerializedSize
();
504
}
505
506
DsrOptionHeader::Alignment
DsrOptionRrepHeader::GetAlignment
()
const
507
{
508
Alignment
retVal = { 4, 0 };
509
return
retVal;
510
}
511
512
NS_OBJECT_ENSURE_REGISTERED
(
DsrOptionSRHeader
);
513
514
TypeId
DsrOptionSRHeader::GetTypeId
()
515
{
516
static
TypeId
tid =
TypeId
(
"ns3::dsr::DsrOptionSRHeader"
)
517
.
AddConstructor
<
DsrOptionSRHeader
> ()
518
.SetParent<DsrOptionHeader> ()
519
;
520
return
tid;
521
}
522
523
TypeId
DsrOptionSRHeader::GetInstanceTypeId
()
const
524
{
525
return
GetTypeId
();
526
}
527
528
DsrOptionSRHeader::DsrOptionSRHeader
()
529
: m_segmentsLeft (0),
530
m_ipv4Address (0)
531
{
532
SetType
(96);
533
SetLength
(2 +
m_ipv4Address
.size () * 4);
534
}
535
536
DsrOptionSRHeader::~DsrOptionSRHeader
()
537
{
538
}
539
540
void
DsrOptionSRHeader::SetSegmentsLeft
(uint8_t segmentsLeft)
541
{
542
m_segmentsLeft
= segmentsLeft;
543
}
544
545
uint8_t
DsrOptionSRHeader::GetSegmentsLeft
()
const
546
{
547
return
m_segmentsLeft
;
548
}
549
550
void
DsrOptionSRHeader::SetSalvage
(uint8_t salvage)
551
{
552
m_salvage
= salvage;
553
}
554
555
uint8_t
DsrOptionSRHeader::GetSalvage
()
const
556
{
557
return
m_salvage
;
558
}
559
560
void
DsrOptionSRHeader::SetNumberAddress
(uint8_t n)
561
{
562
m_ipv4Address
.clear ();
563
m_ipv4Address
.assign (n,
Ipv4Address
(
""
));
564
}
565
566
void
DsrOptionSRHeader::SetNodesAddress
(std::vector<Ipv4Address> ipv4Address)
567
{
568
m_ipv4Address
= ipv4Address;
569
SetLength
(2 +
m_ipv4Address
.size () * 4);
570
}
571
572
std::vector<Ipv4Address>
DsrOptionSRHeader::GetNodesAddress
()
const
573
{
574
return
m_ipv4Address
;
575
}
576
577
void
DsrOptionSRHeader::SetNodeAddress
(uint8_t index,
Ipv4Address
addr)
578
{
579
m_ipv4Address
.at (index) = addr;
580
}
581
582
Ipv4Address
DsrOptionSRHeader::GetNodeAddress
(uint8_t index)
const
583
{
584
return
m_ipv4Address
.at (index);
585
}
586
587
uint8_t
DsrOptionSRHeader::GetNodeListSize
()
const
588
{
589
return
m_ipv4Address
.size ();
590
}
591
592
void
DsrOptionSRHeader::Print
(std::ostream &os)
const
593
{
594
os <<
"( type = "
<< (uint32_t)
GetType
() <<
" length = "
<< (uint32_t)
GetLength
() <<
""
;
595
596
for
(std::vector<Ipv4Address>::const_iterator it =
m_ipv4Address
.begin (); it !=
m_ipv4Address
.end (); it++)
597
{
598
os << *it <<
" "
;
599
}
600
601
os <<
")"
;
602
}
603
604
uint32_t
DsrOptionSRHeader::GetSerializedSize
()
const
605
{
606
return
4 +
m_ipv4Address
.size () * 4;
607
}
608
609
void
DsrOptionSRHeader::Serialize
(
Buffer::Iterator
start
)
const
610
{
611
Buffer::Iterator
i =
start
;
612
uint8_t buff[4];
613
614
i.
WriteU8
(
GetType
());
615
i.
WriteU8
(
GetLength
());
616
i.
WriteU8
(
m_salvage
);
617
i.
WriteU8
(
m_segmentsLeft
);
618
619
for
(VectorIpv4Address_t::const_iterator it =
m_ipv4Address
.begin (); it !=
m_ipv4Address
.end (); it++)
620
{
621
it->Serialize (buff);
622
i.
Write
(buff, 4);
623
}
624
}
625
626
uint32_t
DsrOptionSRHeader::Deserialize
(
Buffer::Iterator
start
)
627
{
628
Buffer::Iterator
i =
start
;
629
uint8_t buff[4];
630
631
SetType
(i.
ReadU8
());
632
SetLength
(i.
ReadU8
());
633
m_salvage
= i.
ReadU8
();
634
m_segmentsLeft
= i.
ReadU8
();
635
636
uint8_t index = 0;
637
for
(std::vector<Ipv4Address>::iterator it =
m_ipv4Address
.begin (); it !=
m_ipv4Address
.end (); it++)
638
{
639
i.
Read
(buff, 4);
640
m_address
= it->
Deserialize
(buff);
641
SetNodeAddress
(index,
m_address
);
642
++index;
643
}
644
645
return
GetSerializedSize
();
646
}
647
648
DsrOptionHeader::Alignment
DsrOptionSRHeader::GetAlignment
()
const
649
{
650
Alignment
retVal = { 4, 0 };
651
return
retVal;
652
}
653
654
NS_OBJECT_ENSURE_REGISTERED
(
DsrOptionRerrHeader
);
655
656
TypeId
DsrOptionRerrHeader::GetTypeId
()
657
{
658
static
TypeId
tid =
TypeId
(
"ns3::dsr::DsrOptionRerrHeader"
)
659
.
AddConstructor
<
DsrOptionRerrHeader
> ()
660
.SetParent<DsrOptionHeader> ()
661
.AddAttribute (
"ErrorType"
,
"Type of route errors"
,
662
EnumValue
(
NODE_UNREACHABLE
),
663
MakeEnumAccessor
(&
DsrOptionRerrHeader::m_errorType
),
664
MakeEnumChecker
(
NODE_UNREACHABLE
,
"Node unreachable"
,
665
FLOW_STATE_NOT_SUPPORTED
,
"Flow state not supported"
,
666
OPTION_NOT_SUPPORTED
,
"Option not supported"
))
667
;
668
return
tid;
669
}
670
671
TypeId
DsrOptionRerrHeader::GetInstanceTypeId
()
const
672
{
673
return
GetTypeId
();
674
}
675
676
DsrOptionRerrHeader::DsrOptionRerrHeader
()
677
: m_errorType (0),
678
m_reserved (0),
679
m_salvage (0),
680
m_errorLength (4)
681
{
682
SetType
(3);
683
SetLength
(18);
684
}
685
686
DsrOptionRerrHeader::~DsrOptionRerrHeader
()
687
{
688
}
689
690
void
DsrOptionRerrHeader::SetErrorType
(uint8_t errorType)
691
{
692
m_errorType
= errorType;
693
}
694
695
uint8_t
DsrOptionRerrHeader::GetErrorType
()
const
696
{
697
return
m_errorType
;
698
}
699
700
void
DsrOptionRerrHeader::SetSalvage
(uint8_t salvage)
701
{
702
m_salvage
= salvage;
703
}
704
705
uint8_t
DsrOptionRerrHeader::GetSalvage
()
const
706
{
707
return
m_salvage
;
708
}
709
710
void
DsrOptionRerrHeader::SetErrorSrc
(
Ipv4Address
errorSrcAddress)
711
{
712
m_errorSrcAddress
= errorSrcAddress;
713
}
714
715
Ipv4Address
DsrOptionRerrHeader::GetErrorSrc
()
const
716
{
717
return
m_errorSrcAddress
;
718
}
719
720
void
DsrOptionRerrHeader::SetErrorDst
(
Ipv4Address
errorDstAddress)
721
{
722
m_errorDstAddress
= errorDstAddress;
723
}
724
725
Ipv4Address
DsrOptionRerrHeader::GetErrorDst
()
const
726
{
727
return
m_errorDstAddress
;
728
}
729
730
void
DsrOptionRerrHeader::Print
(std::ostream &os)
const
731
{
732
os <<
"( type = "
<< (uint32_t)
GetType
() <<
" length = "
<< (uint32_t)
GetLength
()
733
<<
" errorType = "
<< (uint32_t)
m_errorType
<<
" salvage = "
<< (uint32_t)
m_salvage
734
<<
" error source = "
<<
m_errorSrcAddress
<<
" error dst = "
<<
m_errorDstAddress
<<
" )"
;
735
736
}
737
738
uint32_t
DsrOptionRerrHeader::GetSerializedSize
()
const
739
{
740
return
20;
741
}
742
743
void
DsrOptionRerrHeader::Serialize
(
Buffer::Iterator
start
)
const
744
{
745
Buffer::Iterator
i =
start
;
746
747
i.
WriteU8
(
GetType
());
748
i.
WriteU8
(
GetLength
());
749
i.
WriteU8
(
m_errorType
);
750
i.
WriteU8
(
m_salvage
);
751
WriteTo
(i,
m_errorSrcAddress
);
752
WriteTo
(i,
m_errorDstAddress
);
753
i.
Write
(
m_errorData
.
Begin
(),
m_errorData
.
End
());
754
}
755
756
uint32_t
DsrOptionRerrHeader::Deserialize
(
Buffer::Iterator
start
)
757
{
758
Buffer::Iterator
i =
start
;
759
760
SetType
(i.
ReadU8
());
761
SetLength
(i.
ReadU8
());
762
m_errorType
= i.
ReadU8
();
763
m_salvage
= i.
ReadU8
();
764
ReadFrom
(i,
m_errorSrcAddress
);
765
ReadFrom
(i,
m_errorDstAddress
);
766
767
m_errorData
=
Buffer
();
768
m_errorData
.
AddAtEnd
(
m_errorLength
);
769
Buffer::Iterator
dataStart = i;
770
i.
Next
(
m_errorLength
);
771
Buffer::Iterator
dataEnd = i;
772
m_errorData
.
Begin
().
Write
(dataStart, dataEnd);
773
774
return
GetSerializedSize
();
775
}
776
777
DsrOptionHeader::Alignment
DsrOptionRerrHeader::GetAlignment
()
const
778
{
779
Alignment
retVal = { 4, 0 };
780
return
retVal;
781
}
782
783
NS_OBJECT_ENSURE_REGISTERED
(
DsrOptionRerrUnreachHeader
);
784
785
TypeId
DsrOptionRerrUnreachHeader::GetTypeId
()
786
{
787
static
TypeId
tid =
TypeId
(
"ns3::dsr::DsrOptionRerrUnreachHeader"
)
788
.
AddConstructor
<
DsrOptionRerrUnreachHeader
> ()
789
.SetParent<DsrOptionRerrHeader> ()
790
;
791
return
tid;
792
}
793
794
TypeId
DsrOptionRerrUnreachHeader::GetInstanceTypeId
()
const
795
{
796
return
GetTypeId
();
797
}
798
799
DsrOptionRerrUnreachHeader::DsrOptionRerrUnreachHeader
()
800
: m_reserved (0),
801
m_salvage (0)
802
{
803
SetType
(3);
804
SetLength
(18);
805
SetErrorType
(1);
806
}
807
808
DsrOptionRerrUnreachHeader::~DsrOptionRerrUnreachHeader
()
809
{
810
}
811
812
void
DsrOptionRerrUnreachHeader::SetSalvage
(uint8_t salvage)
813
{
814
m_salvage
= salvage;
815
}
816
817
uint8_t
DsrOptionRerrUnreachHeader::GetSalvage
()
const
818
{
819
return
m_salvage
;
820
}
821
822
void
DsrOptionRerrUnreachHeader::SetErrorSrc
(
Ipv4Address
errorSrcAddress)
823
{
824
m_errorSrcAddress
= errorSrcAddress;
825
}
826
827
Ipv4Address
DsrOptionRerrUnreachHeader::GetErrorSrc
()
const
828
{
829
return
m_errorSrcAddress
;
830
}
831
832
void
DsrOptionRerrUnreachHeader::SetErrorDst
(
Ipv4Address
errorDstAddress)
833
{
834
m_errorDstAddress
= errorDstAddress;
835
}
836
837
Ipv4Address
DsrOptionRerrUnreachHeader::GetErrorDst
()
const
838
{
839
return
m_errorDstAddress
;
840
}
841
842
void
DsrOptionRerrUnreachHeader::SetUnreachNode
(
Ipv4Address
unreachNode)
843
{
844
m_unreachNode
= unreachNode;
845
}
846
847
Ipv4Address
DsrOptionRerrUnreachHeader::GetUnreachNode
()
const
848
{
849
return
m_unreachNode
;
850
}
851
852
void
DsrOptionRerrUnreachHeader::SetOriginalDst
(
Ipv4Address
originalDst)
853
{
854
m_originalDst
= originalDst;
855
}
856
857
Ipv4Address
DsrOptionRerrUnreachHeader::GetOriginalDst
()
const
858
{
859
return
m_originalDst
;
860
}
861
862
void
DsrOptionRerrUnreachHeader::Print
(std::ostream &os)
const
863
{
864
os <<
"( type = "
<< (uint32_t)
GetType
() <<
" length = "
<< (uint32_t)
GetLength
()
865
<<
" errorType = "
<< (uint32_t)
m_errorType
<<
" salvage = "
<< (uint32_t)
m_salvage
866
<<
" error source = "
<<
m_errorSrcAddress
<<
" error dst = "
<<
m_errorDstAddress
867
<<
" unreach node = "
<<
m_unreachNode
<<
" )"
;
868
}
869
870
uint32_t
DsrOptionRerrUnreachHeader::GetSerializedSize
()
const
871
{
872
return
20;
873
}
874
875
void
DsrOptionRerrUnreachHeader::Serialize
(
Buffer::Iterator
start
)
const
876
{
877
Buffer::Iterator
i =
start
;
878
879
i.
WriteU8
(
GetType
());
880
i.
WriteU8
(
GetLength
());
881
i.
WriteU8
(
GetErrorType
());
882
i.
WriteU8
(
m_salvage
);
883
WriteTo
(i,
m_errorSrcAddress
);
884
WriteTo
(i,
m_errorDstAddress
);
885
WriteTo
(i,
m_unreachNode
);
886
WriteTo
(i,
m_originalDst
);
887
}
888
889
uint32_t
DsrOptionRerrUnreachHeader::Deserialize
(
Buffer::Iterator
start
)
890
{
891
Buffer::Iterator
i =
start
;
892
893
SetType
(i.
ReadU8
());
894
SetLength
(i.
ReadU8
());
895
SetErrorType
(i.
ReadU8
());
896
m_salvage
= i.
ReadU8
();
897
ReadFrom
(i,
m_errorSrcAddress
);
898
ReadFrom
(i,
m_errorDstAddress
);
899
ReadFrom
(i,
m_unreachNode
);
900
ReadFrom
(i,
m_originalDst
);
901
902
return
GetSerializedSize
();
903
}
904
905
DsrOptionHeader::Alignment
DsrOptionRerrUnreachHeader::GetAlignment
()
const
906
{
907
Alignment
retVal = { 4, 0 };
908
return
retVal;
909
}
910
911
NS_OBJECT_ENSURE_REGISTERED
(
DsrOptionRerrUnsupportHeader
);
912
913
TypeId
DsrOptionRerrUnsupportHeader::GetTypeId
()
914
{
915
static
TypeId
tid =
TypeId
(
"ns3::dsr::DsrOptionRerrUnsupportHeader"
)
916
.
AddConstructor
<
DsrOptionRerrUnsupportHeader
> ()
917
.SetParent<DsrOptionRerrHeader> ()
918
;
919
return
tid;
920
}
921
922
TypeId
DsrOptionRerrUnsupportHeader::GetInstanceTypeId
()
const
923
{
924
return
GetTypeId
();
925
}
926
927
DsrOptionRerrUnsupportHeader::DsrOptionRerrUnsupportHeader
()
928
: m_reserved (0),
929
m_salvage (0)
930
{
931
SetType
(3);
932
SetLength
(14);
933
SetErrorType
(3);
934
}
935
936
DsrOptionRerrUnsupportHeader::~DsrOptionRerrUnsupportHeader
()
937
{
938
}
939
940
void
DsrOptionRerrUnsupportHeader::SetSalvage
(uint8_t salvage)
941
{
942
m_salvage
= salvage;
943
}
944
945
uint8_t
DsrOptionRerrUnsupportHeader::GetSalvage
()
const
946
{
947
return
m_salvage
;
948
}
949
950
void
DsrOptionRerrUnsupportHeader::SetErrorSrc
(
Ipv4Address
errorSrcAddress)
951
{
952
m_errorSrcAddress
= errorSrcAddress;
953
}
954
955
Ipv4Address
DsrOptionRerrUnsupportHeader::GetErrorSrc
()
const
956
{
957
return
m_errorSrcAddress
;
958
}
959
960
void
DsrOptionRerrUnsupportHeader::SetErrorDst
(
Ipv4Address
errorDstAddress)
961
{
962
m_errorDstAddress
= errorDstAddress;
963
}
964
965
Ipv4Address
DsrOptionRerrUnsupportHeader::GetErrorDst
()
const
966
{
967
return
m_errorDstAddress
;
968
}
969
970
void
DsrOptionRerrUnsupportHeader::SetUnsupported
(uint16_t unsupport)
971
{
972
m_unsupport
= unsupport;
973
}
974
975
uint16_t
DsrOptionRerrUnsupportHeader::GetUnsupported
()
const
976
{
977
return
m_unsupport
;
978
}
979
980
void
DsrOptionRerrUnsupportHeader::Print
(std::ostream &os)
const
981
{
982
os <<
"( type = "
<< (uint32_t)
GetType
() <<
" length = "
<< (uint32_t)
GetLength
()
983
<<
" errorType = "
<< (uint32_t)
m_errorType
<<
" salvage = "
<< (uint32_t)
m_salvage
984
<<
" error source = "
<<
m_errorSrcAddress
<<
" error dst = "
<<
m_errorDstAddress
985
<<
" unsupported option = "
<<
m_unsupport
<<
" )"
;
986
987
}
988
989
uint32_t
DsrOptionRerrUnsupportHeader::GetSerializedSize
()
const
990
{
991
return
16;
992
}
993
994
void
DsrOptionRerrUnsupportHeader::Serialize
(
Buffer::Iterator
start
)
const
995
{
996
Buffer::Iterator
i =
start
;
997
998
i.
WriteU8
(
GetType
());
999
i.
WriteU8
(
GetLength
());
1000
i.
WriteU8
(
GetErrorType
());
1001
i.
WriteU8
(
m_salvage
);
1002
WriteTo
(i,
m_errorSrcAddress
);
1003
WriteTo
(i,
m_errorDstAddress
);
1004
i.
WriteU16
(
m_unsupport
);
1005
1006
}
1007
1008
uint32_t
DsrOptionRerrUnsupportHeader::Deserialize
(
Buffer::Iterator
start
)
1009
{
1010
Buffer::Iterator
i =
start
;
1011
1012
SetType
(i.
ReadU8
());
1013
SetLength
(i.
ReadU8
());
1014
SetErrorType
(i.
ReadU8
());
1015
m_salvage
= i.
ReadU8
();
1016
ReadFrom
(i,
m_errorSrcAddress
);
1017
ReadFrom
(i,
m_errorDstAddress
);
1018
m_unsupport
= i.
ReadU16
();
1019
1020
return
GetSerializedSize
();
1021
}
1022
1023
DsrOptionHeader::Alignment
DsrOptionRerrUnsupportHeader::GetAlignment
()
const
1024
{
1025
Alignment
retVal = { 4, 0 };
1026
return
retVal;
1027
}
1028
1029
NS_OBJECT_ENSURE_REGISTERED
(
DsrOptionAckReqHeader
);
1030
1031
TypeId
DsrOptionAckReqHeader::GetTypeId
()
1032
{
1033
static
TypeId
tid =
TypeId
(
"ns3::dsr::DsrOptionAckReqHeader"
)
1034
.
AddConstructor
<
DsrOptionAckReqHeader
> ()
1035
.SetParent<DsrOptionHeader> ()
1036
;
1037
return
tid;
1038
}
1039
1040
TypeId
DsrOptionAckReqHeader::GetInstanceTypeId
()
const
1041
{
1042
return
GetTypeId
();
1043
}
1044
1045
DsrOptionAckReqHeader::DsrOptionAckReqHeader
()
1046
: m_identification (0)
1047
1048
{
1049
SetType
(160);
1050
SetLength
(2);
1051
}
1052
1053
DsrOptionAckReqHeader::~DsrOptionAckReqHeader
()
1054
{
1055
}
1056
1057
void
DsrOptionAckReqHeader::SetAckId
(uint16_t identification)
1058
{
1059
m_identification
= identification;
1060
}
1061
1062
uint16_t
DsrOptionAckReqHeader::GetAckId
()
const
1063
{
1064
return
m_identification
;
1065
}
1066
1067
void
DsrOptionAckReqHeader::Print
(std::ostream &os)
const
1068
{
1069
os <<
"( type = "
<< (uint32_t)
GetType
() <<
" length = "
<< (uint32_t)
GetLength
()
1070
<<
" id = "
<<
m_identification
<<
" )"
;
1071
}
1072
1073
uint32_t
DsrOptionAckReqHeader::GetSerializedSize
()
const
1074
{
1075
return
4;
1076
}
1077
1078
void
DsrOptionAckReqHeader::Serialize
(
Buffer::Iterator
start
)
const
1079
{
1080
Buffer::Iterator
i =
start
;
1081
1082
i.
WriteU8
(
GetType
());
1083
i.
WriteU8
(
GetLength
());
1084
i.
WriteU16
(
m_identification
);
1085
}
1086
1087
uint32_t
DsrOptionAckReqHeader::Deserialize
(
Buffer::Iterator
start
)
1088
{
1089
Buffer::Iterator
i =
start
;
1090
1091
SetType
(i.
ReadU8
());
1092
SetLength
(i.
ReadU8
());
1093
m_identification
= i.
ReadU16
();
1094
1095
return
GetSerializedSize
();
1096
}
1097
1098
DsrOptionHeader::Alignment
DsrOptionAckReqHeader::GetAlignment
()
const
1099
{
1100
Alignment
retVal = { 4, 0 };
1101
return
retVal;
1102
}
1103
1104
NS_OBJECT_ENSURE_REGISTERED
(
DsrOptionAckHeader
);
1105
1106
TypeId
DsrOptionAckHeader::GetTypeId
()
1107
{
1108
static
TypeId
tid =
TypeId
(
"ns3::dsr::DsrOptionAckHeader"
)
1109
.
AddConstructor
<
DsrOptionAckHeader
> ()
1110
.SetParent<DsrOptionHeader> ()
1111
;
1112
return
tid;
1113
}
1114
1115
TypeId
DsrOptionAckHeader::GetInstanceTypeId
()
const
1116
{
1117
return
GetTypeId
();
1118
}
1119
1120
DsrOptionAckHeader::DsrOptionAckHeader
()
1121
: m_identification (0)
1122
{
1123
SetType
(32);
1124
SetLength
(10);
1125
}
1126
1127
DsrOptionAckHeader::~DsrOptionAckHeader
()
1128
{
1129
}
1130
1131
void
DsrOptionAckHeader::SetAckId
(uint16_t identification)
1132
{
1133
m_identification
= identification;
1134
}
1135
1136
uint16_t
DsrOptionAckHeader::GetAckId
()
const
1137
{
1138
return
m_identification
;
1139
}
1140
1141
void
DsrOptionAckHeader::SetRealSrc
(
Ipv4Address
realSrcAddress)
1142
{
1143
m_realSrcAddress
= realSrcAddress;
1144
}
1145
1146
Ipv4Address
DsrOptionAckHeader::GetRealSrc
()
const
1147
{
1148
return
m_realSrcAddress
;
1149
}
1150
1151
void
DsrOptionAckHeader::SetRealDst
(
Ipv4Address
realDstAddress)
1152
{
1153
m_realDstAddress
= realDstAddress;
1154
}
1155
1156
Ipv4Address
DsrOptionAckHeader::GetRealDst
()
const
1157
{
1158
return
m_realDstAddress
;
1159
}
1160
1161
void
DsrOptionAckHeader::Print
(std::ostream &os)
const
1162
{
1163
os <<
"( type = "
<< (uint32_t)
GetType
() <<
" length = "
<< (uint32_t)
GetLength
()
1164
<<
" id = "
<<
m_identification
<<
" real src = "
<<
m_realSrcAddress
1165
<<
" real dst = "
<<
m_realDstAddress
<<
" )"
;
1166
1167
}
1168
1169
uint32_t
DsrOptionAckHeader::GetSerializedSize
()
const
1170
{
1171
return
12;
1172
}
1173
1174
void
DsrOptionAckHeader::Serialize
(
Buffer::Iterator
start
)
const
1175
{
1176
Buffer::Iterator
i =
start
;
1177
1178
i.
WriteU8
(
GetType
());
1179
i.
WriteU8
(
GetLength
());
1180
i.
WriteU16
(
m_identification
);
1181
WriteTo
(i,
m_realSrcAddress
);
1182
WriteTo
(i,
m_realDstAddress
);
1183
}
1184
1185
uint32_t
DsrOptionAckHeader::Deserialize
(
Buffer::Iterator
start
)
1186
{
1187
Buffer::Iterator
i =
start
;
1188
1189
SetType
(i.
ReadU8
());
1190
SetLength
(i.
ReadU8
());
1191
m_identification
= i.
ReadU16
();
1192
ReadFrom
(i,
m_realSrcAddress
);
1193
ReadFrom
(i,
m_realDstAddress
);
1194
1195
return
GetSerializedSize
();
1196
}
1197
1198
DsrOptionHeader::Alignment
DsrOptionAckHeader::GetAlignment
()
const
1199
{
1200
Alignment
retVal = { 4, 0 };
1201
return
retVal;
1202
}
1203
}
/* namespace dsr */
1204
}
/* namespace ns3 */
src
dsr
model
dsr-option-header.cc
Generated on Tue May 14 2013 11:08:20 for ns-3 by
1.8.1.2