A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
dsr-fs-header.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2011 Yufei Cheng
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Yufei Cheng <yfcheng@ittc.ku.edu>
18
*
19
* James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
20
* ResiliNets Research Group https://resilinets.org/
21
* Information and Telecommunication Technology Center (ITTC)
22
* and Department of Electrical Engineering and Computer Science
23
* The University of Kansas Lawrence, KS USA.
24
*
25
* Work supported in part by NSF FIND (Future Internet Design) Program
26
* under grant CNS-0626918 (Postmodern Internet Architecture),
27
* NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
28
* US Department of Defense (DoD), and ITTC at The University of Kansas.
29
*/
30
31
#include "
dsr-fs-header.h
"
32
33
#include "ns3/assert.h"
34
#include "ns3/header.h"
35
#include "ns3/log.h"
36
37
namespace
ns3
38
{
39
40
NS_LOG_COMPONENT_DEFINE
(
"DsrFsHeader"
);
41
42
namespace
dsr
43
{
44
45
NS_OBJECT_ENSURE_REGISTERED
(DsrFsHeader);
46
47
TypeId
48
DsrFsHeader::GetTypeId
()
49
{
50
static
TypeId
tid =
TypeId
(
"ns3::dsr::DsrFsHeader"
)
51
.
AddConstructor
<
DsrFsHeader
>()
52
.SetParent<Header>()
53
.SetGroupName(
"Dsr"
);
54
return
tid;
55
}
56
57
TypeId
58
DsrFsHeader::GetInstanceTypeId
()
const
59
{
60
return
GetTypeId
();
61
}
62
63
DsrFsHeader::DsrFsHeader
()
64
: m_nextHeader(0),
65
m_messageType(0),
66
m_payloadLen(0),
67
m_sourceId(0),
68
m_destId(0),
69
m_data(0)
70
{
71
}
72
73
DsrFsHeader::~DsrFsHeader
()
74
{
75
}
76
77
void
78
DsrFsHeader::SetNextHeader
(uint8_t protocol)
79
{
80
m_nextHeader
= protocol;
81
}
82
83
uint8_t
84
DsrFsHeader::GetNextHeader
()
const
85
{
86
return
m_nextHeader
;
87
}
88
89
void
90
DsrFsHeader::SetMessageType
(uint8_t messageType)
91
{
92
m_messageType
= messageType;
93
}
94
95
uint8_t
96
DsrFsHeader::GetMessageType
()
const
97
{
98
return
m_messageType
;
99
}
100
101
void
102
DsrFsHeader::SetPayloadLength
(uint16_t length)
103
{
104
m_payloadLen
= length;
105
}
106
107
uint16_t
108
DsrFsHeader::GetPayloadLength
()
const
109
{
110
return
m_payloadLen
;
111
}
112
113
void
114
DsrFsHeader::SetSourceId
(uint16_t sourceId)
115
{
116
m_sourceId
= sourceId;
117
}
118
119
uint16_t
120
DsrFsHeader::GetSourceId
()
const
121
{
122
return
m_sourceId
;
123
}
124
125
void
126
DsrFsHeader::SetDestId
(uint16_t destId)
127
{
128
m_destId
= destId;
129
}
130
131
uint16_t
132
DsrFsHeader::GetDestId
()
const
133
{
134
return
m_destId
;
135
}
136
137
void
138
DsrFsHeader::Print
(std::ostream& os)
const
139
{
140
os <<
"nextHeader: "
<< (uint32_t)
GetNextHeader
()
141
<<
" messageType: "
<< (uint32_t)
GetMessageType
() <<
" sourceId: "
<< (uint32_t)
GetSourceId
()
142
<<
" destinationId: "
<< (uint32_t)
GetDestId
()
143
<<
" length: "
<< (uint32_t)
GetPayloadLength
();
144
}
145
146
uint32_t
147
DsrFsHeader::GetSerializedSize
()
const
148
{
149
return
8;
150
}
151
152
void
153
DsrFsHeader::Serialize
(
Buffer::Iterator
start
)
const
154
{
155
Buffer::Iterator
i =
start
;
156
157
i.
WriteU8
(
m_nextHeader
);
158
i.
WriteU8
(
m_messageType
);
159
i.
WriteU16
(
m_sourceId
);
160
i.
WriteU16
(
m_destId
);
161
i.
WriteU16
(
m_payloadLen
);
162
163
i.
Write
(
m_data
.
PeekData
(),
m_data
.
GetSize
());
164
}
165
166
uint32_t
167
DsrFsHeader::Deserialize
(
Buffer::Iterator
start
)
168
{
169
Buffer::Iterator
i =
start
;
170
171
m_nextHeader
= i.
ReadU8
();
172
m_messageType
= i.
ReadU8
();
173
m_sourceId
= i.
ReadU16
();
174
m_destId
= i.
ReadU16
();
175
m_payloadLen
= i.
ReadU16
();
176
177
uint32_t dataLength =
GetPayloadLength
();
178
uint8_t
data
[dataLength];
179
i.
Read
(
data
, dataLength);
180
181
if
(dataLength >
m_data
.
GetSize
())
182
{
183
m_data
.
AddAtEnd
(dataLength -
m_data
.
GetSize
());
184
}
185
else
186
{
187
m_data
.
RemoveAtEnd
(
m_data
.
GetSize
() - dataLength);
188
}
189
190
i =
m_data
.
Begin
();
191
i.
Write
(
data
, dataLength);
192
193
return
GetSerializedSize
();
194
}
195
196
DsrOptionField::DsrOptionField
(uint32_t optionsOffset)
197
: m_optionData(0),
198
m_optionsOffset(optionsOffset)
199
{
200
}
201
202
DsrOptionField::~DsrOptionField
()
203
{
204
}
205
206
uint32_t
207
DsrOptionField::GetSerializedSize
()
const
208
{
209
DsrOptionHeader::Alignment
align = {4, 0};
210
return
m_optionData
.
GetSize
() +
CalculatePad
(align);
211
}
212
213
void
214
DsrOptionField::Serialize
(
Buffer::Iterator
start
)
const
215
{
216
start
.Write(
m_optionData
.
Begin
(),
m_optionData
.
End
());
217
DsrOptionHeader::Alignment
align = {4, 0};
218
uint32_t fill =
CalculatePad
(align);
219
NS_LOG_LOGIC
(
"fill with "
<< fill <<
" bytes padding"
);
220
switch
(fill)
221
{
222
case
0:
223
return
;
224
case
1:
225
DsrOptionPad1Header
().
Serialize
(
start
);
226
return
;
227
default
:
228
DsrOptionPadnHeader
(fill).
Serialize
(
start
);
229
return
;
230
}
231
}
232
233
uint32_t
234
DsrOptionField::Deserialize
(
Buffer::Iterator
start
, uint32_t length)
235
{
236
uint8_t buf[length];
237
start
.Read(buf, length);
238
m_optionData
=
Buffer
();
239
m_optionData
.
AddAtEnd
(length);
240
m_optionData
.
Begin
().
Write
(buf, length);
241
return
length;
242
}
243
244
void
245
DsrOptionField::AddDsrOption
(
const
DsrOptionHeader
& option)
246
{
247
NS_LOG_FUNCTION_NOARGS
();
248
249
uint32_t pad =
CalculatePad
(option.
GetAlignment
());
250
NS_LOG_LOGIC
(
"need "
<< pad <<
" bytes padding"
);
251
switch
(pad)
252
{
253
case
0:
254
break
;
// no padding needed
255
case
1:
256
AddDsrOption
(
DsrOptionPad1Header
());
257
break
;
258
default
:
259
AddDsrOption
(
DsrOptionPadnHeader
(pad));
260
break
;
261
}
262
263
m_optionData
.
AddAtEnd
(option.
GetSerializedSize
());
264
Buffer::Iterator
it =
m_optionData
.
End
();
265
it.
Prev
(option.
GetSerializedSize
());
266
option.
Serialize
(it);
267
}
268
269
uint32_t
270
DsrOptionField::CalculatePad
(
DsrOptionHeader::Alignment
alignment)
const
271
{
272
return
(alignment.
offset
- (
m_optionData
.
GetSize
() +
m_optionsOffset
)) % alignment.
factor
;
273
}
274
275
uint32_t
276
DsrOptionField::GetDsrOptionsOffset
()
const
277
{
278
return
m_optionsOffset
;
279
}
280
281
Buffer
282
DsrOptionField::GetDsrOptionBuffer
()
283
{
284
return
m_optionData
;
285
}
286
287
NS_OBJECT_ENSURE_REGISTERED
(
DsrRoutingHeader
);
288
289
TypeId
290
DsrRoutingHeader::GetTypeId
()
291
{
292
static
TypeId
tid =
293
TypeId
(
"ns3::DsrRoutingHeader"
).
AddConstructor
<
DsrRoutingHeader
>().SetParent<DsrFsHeader>();
294
return
tid;
295
}
296
297
TypeId
298
DsrRoutingHeader::GetInstanceTypeId
()
const
299
{
300
return
GetTypeId
();
301
}
302
303
DsrRoutingHeader::DsrRoutingHeader
()
304
:
DsrOptionField
(8)
305
{
306
}
307
308
DsrRoutingHeader::~DsrRoutingHeader
()
309
{
310
}
311
312
void
313
DsrRoutingHeader::Print
(std::ostream& os)
const
314
{
315
os <<
" nextHeader: "
<< (uint32_t)
GetNextHeader
()
316
<<
" messageType: "
<< (uint32_t)
GetMessageType
() <<
" sourceId: "
<< (uint32_t)
GetSourceId
()
317
<<
" destinationId: "
<< (uint32_t)
GetDestId
()
318
<<
" length: "
<< (uint32_t)
GetPayloadLength
();
319
}
320
321
uint32_t
322
DsrRoutingHeader::GetSerializedSize
()
const
323
{
324
// 8 bytes is the DsrFsHeader length
325
return
8 +
DsrOptionField::GetSerializedSize
();
326
}
327
328
void
329
DsrRoutingHeader::Serialize
(
Buffer::Iterator
start
)
const
330
{
331
Buffer::Iterator
i =
start
;
332
333
i.
WriteU8
(
GetNextHeader
());
334
i.
WriteU8
(
GetMessageType
());
335
i.
WriteU16
(
GetSourceId
());
336
i.
WriteU16
(
GetDestId
());
337
i.
WriteU16
(
GetPayloadLength
());
338
339
DsrOptionField::Serialize
(i);
340
}
341
342
uint32_t
343
DsrRoutingHeader::Deserialize
(
Buffer::Iterator
start
)
344
{
345
Buffer::Iterator
i =
start
;
346
347
SetNextHeader
(i.
ReadU8
());
348
SetMessageType
(i.
ReadU8
());
349
SetSourceId
(i.
ReadU16
());
350
SetDestId
(i.
ReadU16
());
351
SetPayloadLength
(i.
ReadU16
());
352
353
DsrOptionField::Deserialize
(i,
GetPayloadLength
());
354
355
return
GetSerializedSize
();
356
}
357
358
}
/* namespace dsr */
359
}
/* namespace ns3 */
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition:
buffer.h:100
ns3::Buffer::Iterator::ReadU8
uint8_t ReadU8()
Definition:
buffer.h:1027
ns3::Buffer::Iterator::WriteU8
void WriteU8(uint8_t data)
Definition:
buffer.h:881
ns3::Buffer::Iterator::Write
void Write(const uint8_t *buffer, uint32_t size)
Definition:
buffer.cc:948
ns3::Buffer::Iterator::WriteU16
void WriteU16(uint16_t data)
Definition:
buffer.cc:859
ns3::Buffer::Iterator::Read
void Read(uint8_t *buffer, uint32_t size)
Definition:
buffer.cc:1125
ns3::Buffer::Iterator::Prev
void Prev()
go backward by one byte
Definition:
buffer.h:860
ns3::Buffer::Iterator::ReadU16
uint16_t ReadU16()
Definition:
buffer.h:1035
ns3::Buffer
automatically resized byte buffer
Definition:
buffer.h:94
ns3::Buffer::RemoveAtEnd
void RemoveAtEnd(uint32_t end)
Definition:
buffer.cc:493
ns3::Buffer::GetSize
uint32_t GetSize() const
Definition:
buffer.h:1068
ns3::Buffer::Begin
Buffer::Iterator Begin() const
Definition:
buffer.h:1074
ns3::Buffer::AddAtEnd
void AddAtEnd(uint32_t end)
Definition:
buffer.cc:360
ns3::Buffer::End
Buffer::Iterator End() const
Definition:
buffer.h:1081
ns3::Buffer::PeekData
const uint8_t * PeekData() const
Definition:
buffer.cc:703
ns3::Header::Deserialize
virtual uint32_t Deserialize(Buffer::Iterator start)=0
Deserialize the object from a buffer iterator.
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:59
ns3::TypeId::AddConstructor
TypeId AddConstructor()
Record in this TypeId the fact that the default constructor is accessible.
Definition:
type-id.h:651
ns3::dsr::DsrFsHeader
Dsr fixed size header Format.
Definition:
dsr-fs-header.h:82
ns3::dsr::DsrFsHeader::SetSourceId
void SetSourceId(uint16_t sourceId)
brief Set the source ID of the header.
Definition:
dsr-fs-header.cc:114
ns3::dsr::DsrFsHeader::DsrFsHeader
DsrFsHeader()
Constructor.
Definition:
dsr-fs-header.cc:63
ns3::dsr::DsrFsHeader::SetNextHeader
void SetNextHeader(uint8_t protocol)
Set the "Next header" field.
Definition:
dsr-fs-header.cc:78
ns3::dsr::DsrFsHeader::SetDestId
void SetDestId(uint16_t destId)
brief Set the dest ID of the header.
Definition:
dsr-fs-header.cc:126
ns3::dsr::DsrFsHeader::GetMessageType
uint8_t GetMessageType() const
brief Get the message type of the header.
Definition:
dsr-fs-header.cc:96
ns3::dsr::DsrFsHeader::GetTypeId
static TypeId GetTypeId()
Get the type identificator.
Definition:
dsr-fs-header.cc:48
ns3::dsr::DsrFsHeader::GetNextHeader
uint8_t GetNextHeader() const
Get the next header.
Definition:
dsr-fs-header.cc:84
ns3::dsr::DsrFsHeader::m_destId
uint16_t m_destId
The destination node id.
Definition:
dsr-fs-header.h:194
ns3::dsr::DsrFsHeader::m_sourceId
uint16_t m_sourceId
The source node id.
Definition:
dsr-fs-header.h:190
ns3::dsr::DsrFsHeader::GetSourceId
uint16_t GetSourceId() const
brief Get the source ID of the header.
Definition:
dsr-fs-header.cc:120
ns3::dsr::DsrFsHeader::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Get the instance type ID.
Definition:
dsr-fs-header.cc:58
ns3::dsr::DsrFsHeader::Serialize
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
Definition:
dsr-fs-header.cc:153
ns3::dsr::DsrFsHeader::GetDestId
uint16_t GetDestId() const
brief Get the dest ID of the header.
Definition:
dsr-fs-header.cc:132
ns3::dsr::DsrFsHeader::m_messageType
uint8_t m_messageType
The type of the message.
Definition:
dsr-fs-header.h:182
ns3::dsr::DsrFsHeader::m_payloadLen
uint16_t m_payloadLen
The "payload length" field.
Definition:
dsr-fs-header.h:186
ns3::dsr::DsrFsHeader::SetMessageType
void SetMessageType(uint8_t messageType)
brief Set the message type of the header.
Definition:
dsr-fs-header.cc:90
ns3::dsr::DsrFsHeader::GetPayloadLength
uint16_t GetPayloadLength() const
Get the payload length of the header.
Definition:
dsr-fs-header.cc:108
ns3::dsr::DsrFsHeader::SetPayloadLength
void SetPayloadLength(uint16_t length)
brief Set the payload length of the header.
Definition:
dsr-fs-header.cc:102
ns3::dsr::DsrFsHeader::m_nextHeader
uint8_t m_nextHeader
The "next header" field.
Definition:
dsr-fs-header.h:178
ns3::dsr::DsrFsHeader::m_data
Buffer m_data
The data of the extension.
Definition:
dsr-fs-header.h:198
ns3::dsr::DsrFsHeader::Print
void Print(std::ostream &os) const override
Print some information about the packet.
Definition:
dsr-fs-header.cc:138
ns3::dsr::DsrFsHeader::~DsrFsHeader
~DsrFsHeader() override
Destructor.
Definition:
dsr-fs-header.cc:73
ns3::dsr::DsrFsHeader::GetSerializedSize
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
Definition:
dsr-fs-header.cc:147
ns3::dsr::DsrOptionField
Option field for an DsrFsHeader Enables adding options to an DsrFsHeader.
Definition:
dsr-fs-header.h:212
ns3::dsr::DsrOptionField::Serialize
void Serialize(Buffer::Iterator start) const
Serialize all added options.
Definition:
dsr-fs-header.cc:214
ns3::dsr::DsrOptionField::AddDsrOption
void AddDsrOption(const DsrOptionHeader &option)
Serialize the option, prepending pad1 or padn option as necessary.
Definition:
dsr-fs-header.cc:245
ns3::dsr::DsrOptionField::Deserialize
uint32_t Deserialize(Buffer::Iterator start, uint32_t length)
Deserialize the packet.
Definition:
dsr-fs-header.cc:234
ns3::dsr::DsrOptionField::m_optionData
Buffer m_optionData
Data payload.
Definition:
dsr-fs-header.h:267
ns3::dsr::DsrOptionField::GetDsrOptionBuffer
Buffer GetDsrOptionBuffer()
Get the buffer.
Definition:
dsr-fs-header.cc:282
ns3::dsr::DsrOptionField::m_optionsOffset
uint32_t m_optionsOffset
Offset.
Definition:
dsr-fs-header.h:271
ns3::dsr::DsrOptionField::GetDsrOptionsOffset
uint32_t GetDsrOptionsOffset() const
Get the offset where the options begin, measured from the start of the extension header.
Definition:
dsr-fs-header.cc:276
ns3::dsr::DsrOptionField::GetSerializedSize
uint32_t GetSerializedSize() const
Get the serialized size of the packet.
Definition:
dsr-fs-header.cc:207
ns3::dsr::DsrOptionField::CalculatePad
uint32_t CalculatePad(DsrOptionHeader::Alignment alignment) const
Calculate padding.
Definition:
dsr-fs-header.cc:270
ns3::dsr::DsrOptionField::DsrOptionField
DsrOptionField(uint32_t optionsOffset)
Constructor.
Definition:
dsr-fs-header.cc:196
ns3::dsr::DsrOptionField::~DsrOptionField
~DsrOptionField()
Destructor.
Definition:
dsr-fs-header.cc:202
ns3::dsr::DsrOptionHeader
Header for Dsr Options.
Definition:
dsr-option-header.h:53
ns3::dsr::DsrOptionHeader::GetAlignment
virtual Alignment GetAlignment() const
Get the Alignment requirement of this option header.
Definition:
dsr-option-header.cc:142
ns3::dsr::DsrOptionHeader::Serialize
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
Definition:
dsr-option-header.cc:114
ns3::dsr::DsrOptionHeader::GetSerializedSize
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
Definition:
dsr-option-header.cc:108
ns3::dsr::DsrOptionPad1Header
Header of Dsr Option Pad1.
Definition:
dsr-option-header.h:153
ns3::dsr::DsrOptionPad1Header::Serialize
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
Definition:
dsr-option-header.cc:188
ns3::dsr::DsrOptionPadnHeader
Header of Dsr Option Padn.
Definition:
dsr-option-header.h:201
ns3::dsr::DsrOptionPadnHeader::Serialize
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
Definition:
dsr-option-header.cc:247
ns3::dsr::DsrRoutingHeader
Header of Dsr Routing.
Definition:
dsr-fs-header.h:279
ns3::dsr::DsrRoutingHeader::DsrRoutingHeader
DsrRoutingHeader()
Constructor.
Definition:
dsr-fs-header.cc:303
ns3::dsr::DsrRoutingHeader::GetSerializedSize
uint32_t GetSerializedSize() const override
Get the serialized size of the packet.
Definition:
dsr-fs-header.cc:322
ns3::dsr::DsrRoutingHeader::~DsrRoutingHeader
~DsrRoutingHeader() override
Destructor.
Definition:
dsr-fs-header.cc:308
ns3::dsr::DsrRoutingHeader::Print
void Print(std::ostream &os) const override
Print some information about the packet.
Definition:
dsr-fs-header.cc:313
ns3::dsr::DsrRoutingHeader::GetTypeId
static TypeId GetTypeId()
Get the type identificator.
Definition:
dsr-fs-header.cc:290
ns3::dsr::DsrRoutingHeader::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Get the instance type ID.
Definition:
dsr-fs-header.cc:298
ns3::dsr::DsrRoutingHeader::Serialize
void Serialize(Buffer::Iterator start) const override
Serialize the packet.
Definition:
dsr-fs-header.cc:329
dsr-fs-header.h
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
NS_LOG_LOGIC
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition:
log.h:282
NS_LOG_FUNCTION_NOARGS
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition:
log-macros-enabled.h:206
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:46
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
two-ray-to-three-gpp-ch-calibration.start
start
Definition:
two-ray-to-three-gpp-ch-calibration.py:520
data
uint8_t data[writeSize]
Definition:
socket-bound-tcp-static-routing.cc:52
ns3::dsr::DsrOptionHeader::Alignment
represents the alignment requirements of an option header
Definition:
dsr-option-header.h:60
ns3::dsr::DsrOptionHeader::Alignment::factor
uint8_t factor
Factor.
Definition:
dsr-option-header.h:61
ns3::dsr::DsrOptionHeader::Alignment::offset
uint8_t offset
Offset.
Definition:
dsr-option-header.h:62
src
dsr
model
dsr-fs-header.cc
Generated on Sun Mar 3 2024 17:10:56 for ns-3 by
1.9.1