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-fs-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-fs-header.h
"
36
37
namespace
ns3 {
38
namespace
dsr {
39
40
NS_LOG_COMPONENT_DEFINE
(
"DsrFsHeader"
);
41
42
NS_OBJECT_ENSURE_REGISTERED
(DsrFsHeader)
43
;
44
45
TypeId
DsrFsHeader::GetTypeId
()
46
{
47
static
TypeId
tid =
TypeId
(
"ns3::dsr::DsrFsHeader"
)
48
.
AddConstructor
<
DsrFsHeader
> ()
49
.SetParent<Header> ()
50
;
51
return
tid;
52
}
53
54
TypeId
DsrFsHeader::GetInstanceTypeId
()
const
55
{
56
return
GetTypeId
();
57
}
58
59
DsrFsHeader::DsrFsHeader
()
60
: m_nextHeader (0),
61
m_messageType (0),
62
m_payloadLen (0),
63
m_sourceId (0),
64
m_destId (0),
65
m_data (0)
66
{
67
}
68
69
DsrFsHeader::~DsrFsHeader
()
70
{
71
}
72
73
void
DsrFsHeader::SetNextHeader
(uint8_t protocol)
74
{
75
m_nextHeader
= protocol;
76
}
77
78
uint8_t
DsrFsHeader::GetNextHeader
()
const
79
{
80
return
m_nextHeader
;
81
}
82
83
void
DsrFsHeader::SetMessageType
(uint8_t messageType)
84
{
85
m_messageType
= messageType;
86
}
87
88
uint8_t
DsrFsHeader::GetMessageType
()
const
89
{
90
return
m_messageType
;
91
}
92
93
void
DsrFsHeader::SetPayloadLength
(uint16_t length)
94
{
95
m_payloadLen
= length;
96
}
97
98
uint16_t
DsrFsHeader::GetPayloadLength
()
const
99
{
100
return
m_payloadLen
;
101
}
102
103
void
DsrFsHeader::SetSourceId
(uint16_t sourceId)
104
{
105
m_sourceId
= sourceId;
106
}
107
108
uint16_t
DsrFsHeader::GetSourceId
()
const
109
{
110
return
m_sourceId
;
111
}
112
113
void
DsrFsHeader::SetDestId
(uint16_t destId)
114
{
115
m_destId
= destId;
116
}
117
118
uint16_t
DsrFsHeader::GetDestId
()
const
119
{
120
return
m_destId
;
121
}
122
123
void
DsrFsHeader::Print
(std::ostream &os)
const
124
{
125
os
126
<<
"nextHeader: "
<< (uint32_t)
GetNextHeader
() <<
" messageType: "
<< (uint32_t)
GetMessageType
()
127
<<
" sourceId: "
<< (uint32_t)
GetSourceId
() <<
" destinationId: "
<< (uint32_t)
GetDestId
()
128
<<
" length: "
<< (uint32_t)
GetPayloadLength
();
129
}
130
131
uint32_t
DsrFsHeader::GetSerializedSize
()
const
132
{
133
return
8;
134
}
135
136
void
DsrFsHeader::Serialize
(
Buffer::Iterator
start
)
const
137
{
138
Buffer::Iterator
i =
start
;
139
140
i.
WriteU8
(
m_nextHeader
);
141
i.
WriteU8
(
m_messageType
);
142
i.
WriteU16
(
m_sourceId
);
143
i.
WriteU16
(
m_destId
);
144
i.
WriteU16
(
m_payloadLen
);
145
146
i.
Write
(
m_data
.
PeekData
(),
m_data
.
GetSize
());
147
}
148
149
uint32_t
DsrFsHeader::Deserialize
(
Buffer::Iterator
start
)
150
{
151
Buffer::Iterator
i =
start
;
152
153
m_nextHeader
= i.
ReadU8
();
154
m_messageType
= i.
ReadU8
();
155
m_sourceId
= i.
ReadU16
();
156
m_destId
= i.
ReadU16
();
157
m_payloadLen
= i.
ReadU16
();
158
159
uint32_t dataLength =
GetPayloadLength
();
160
uint8_t
data
[dataLength];
161
i.
Read
(data, dataLength);
162
163
if
(dataLength >
m_data
.
GetSize
())
164
{
165
m_data
.
AddAtEnd
(dataLength -
m_data
.
GetSize
());
166
}
167
else
168
{
169
m_data
.
RemoveAtEnd
(
m_data
.
GetSize
() - dataLength);
170
}
171
172
i =
m_data
.
Begin
();
173
i.
Write
(data, dataLength);
174
175
return
GetSerializedSize
();
176
}
177
178
DsrOptionField::DsrOptionField
(uint32_t optionsOffset)
179
: m_optionData (0),
180
m_optionsOffset (optionsOffset)
181
{
182
}
183
184
DsrOptionField::~DsrOptionField
()
185
{
186
}
187
188
uint32_t
DsrOptionField::GetSerializedSize
()
const
189
{
190
DsrOptionHeader::Alignment
align = {4,0};
191
return
m_optionData
.
GetSize
() +
CalculatePad
(align);
192
}
193
194
void
DsrOptionField::Serialize
(
Buffer::Iterator
start
)
const
195
{
196
start.
Write
(
m_optionData
.
Begin
(),
m_optionData
.
End
());
197
DsrOptionHeader::Alignment
align = {4,0};
198
uint32_t fill =
CalculatePad
(align);
199
NS_LOG_LOGIC
(
"fill with "
<< fill <<
" bytes padding"
);
200
switch
(fill)
201
{
202
case
0:
203
return
;
204
case
1:
205
DsrOptionPad1Header
().
Serialize
(start);
206
return
;
207
default
:
208
DsrOptionPadnHeader
(fill).
Serialize
(start);
209
return
;
210
}
211
}
212
213
uint32_t
DsrOptionField::Deserialize
(
Buffer::Iterator
start
, uint32_t length)
214
{
215
uint8_t buf[length];
216
start.
Read
(buf, length);
217
m_optionData
=
Buffer
();
218
m_optionData
.
AddAtEnd
(length);
219
m_optionData
.
Begin
().
Write
(buf, length);
220
return
length;
221
}
222
223
void
DsrOptionField::AddDsrOption
(
DsrOptionHeader
const
& option)
224
{
225
NS_LOG_FUNCTION_NOARGS
();
226
227
uint32_t pad =
CalculatePad
(option.
GetAlignment
());
228
NS_LOG_LOGIC
(
"need "
<< pad <<
" bytes padding"
);
229
switch
(pad)
230
{
231
case
0:
232
break
;
// no padding needed
233
case
1:
234
AddDsrOption
(
DsrOptionPad1Header
());
235
break
;
236
default
:
237
AddDsrOption
(
DsrOptionPadnHeader
(pad));
238
break
;
239
}
240
241
m_optionData
.
AddAtEnd
(option.
GetSerializedSize
());
242
Buffer::Iterator
it =
m_optionData
.
End
();
243
it.
Prev
(option.
GetSerializedSize
());
244
option.
Serialize
(it);
245
}
246
247
uint32_t
DsrOptionField::CalculatePad
(
DsrOptionHeader::Alignment
alignment)
const
248
{
249
return
(alignment.
offset
- (
m_optionData
.
GetSize
() +
m_optionsOffset
)) % alignment.
factor
;
250
}
251
252
uint32_t
DsrOptionField::GetDsrOptionsOffset
()
253
{
254
return
m_optionsOffset
;
255
}
256
257
Buffer
DsrOptionField::GetDsrOptionBuffer
()
258
{
259
return
m_optionData
;
260
}
261
262
NS_OBJECT_ENSURE_REGISTERED
(
DsrRoutingHeader
)
263
;
264
265
TypeId
DsrRoutingHeader::GetTypeId
()
266
{
267
static
TypeId
tid =
TypeId
(
"ns3::DsrRoutingHeader"
)
268
.
AddConstructor
<
DsrRoutingHeader
> ()
269
.SetParent<DsrFsHeader> ()
270
;
271
return
tid;
272
}
273
274
TypeId
DsrRoutingHeader::GetInstanceTypeId
()
const
275
{
276
return
GetTypeId
();
277
}
278
279
DsrRoutingHeader::DsrRoutingHeader
()
280
:
DsrOptionField
(8)
281
{
282
}
283
284
DsrRoutingHeader::~DsrRoutingHeader
()
285
{
286
}
287
288
void
DsrRoutingHeader::Print
(std::ostream &os)
const
289
{
290
os
291
<<
" nextHeader: "
<< (uint32_t)
GetNextHeader
() <<
" messageType: "
<< (uint32_t)
GetMessageType
()
292
<<
" sourceId: "
<< (uint32_t)
GetSourceId
() <<
" destinationId: "
<< (uint32_t)
GetDestId
()
293
<<
" length: "
<< (uint32_t)
GetPayloadLength
();
294
}
295
296
uint32_t
DsrRoutingHeader::GetSerializedSize
()
const
297
{
298
// 8 bytes is the DsrFsHeader length
299
return
8 +
DsrOptionField::GetSerializedSize
();
300
}
301
302
void
DsrRoutingHeader::Serialize
(
Buffer::Iterator
start
)
const
303
{
304
Buffer::Iterator
i =
start
;
305
306
i.
WriteU8
(
GetNextHeader
());
307
i.
WriteU8
(
GetMessageType
());
308
i.
WriteU16
(
GetSourceId
());
309
i.
WriteU16
(
GetDestId
());
310
i.
WriteU16
(
GetPayloadLength
());
311
312
DsrOptionField::Serialize
(i);
313
}
314
315
uint32_t
DsrRoutingHeader::Deserialize
(
Buffer::Iterator
start
)
316
{
317
Buffer::Iterator
i =
start
;
318
319
SetNextHeader
(i.
ReadU8
());
320
SetMessageType
(i.
ReadU8
());
321
SetSourceId
(i.
ReadU16
());
322
SetDestId
(i.
ReadU16
());
323
SetPayloadLength
(i.
ReadU16
());
324
325
DsrOptionField::Deserialize
(i,
GetPayloadLength
());
326
327
return
GetSerializedSize
();
328
}
329
330
}
/* namespace dsr */
331
}
/* namespace ns3 */
ns3::dsr::DsrOptionField::~DsrOptionField
~DsrOptionField()
Destructor.
Definition:
dsr-fs-header.cc:184
ns3::Buffer::Iterator::ReadU16
uint16_t ReadU16(void)
Definition:
buffer.h:845
ns3::dsr::DsrFsHeader::GetPayloadLength
uint16_t GetPayloadLength() const
Get the payload length of the header.
Definition:
dsr-fs-header.cc:98
ns3::dsr::DsrRoutingHeader::GetTypeId
static TypeId GetTypeId()
Get the type identificator.
Definition:
dsr-fs-header.cc:265
ns3::TypeId::AddConstructor
TypeId AddConstructor(void)
Definition:
type-id.h:418
ns3::dsr::DsrRoutingHeader::DsrRoutingHeader
DsrRoutingHeader()
Constructor.
Definition:
dsr-fs-header.cc:279
ns3::Buffer::RemoveAtEnd
void RemoveAtEnd(uint32_t end)
Definition:
buffer.cc:497
ns3::dsr::DsrOptionPadnHeader::Serialize
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
Definition:
dsr-option-header.cc:224
ns3::dsr::DsrOptionField::Deserialize
uint32_t Deserialize(Buffer::Iterator start, uint32_t length)
Deserialize the packet.
Definition:
dsr-fs-header.cc:213
ns3::Buffer
automatically resized byte buffer
Definition:
buffer.h:92
ns3::dsr::DsrOptionField::m_optionsOffset
uint32_t m_optionsOffset
Offset.
Definition:
dsr-fs-header.h:270
ns3::dsr::DsrFsHeader::GetMessageType
uint8_t GetMessageType() const
brief Get the message type of the header.
Definition:
dsr-fs-header.cc:88
ns3::dsr::DsrOptionPad1Header
Doxygen introspection did not find any typical Config paths.
Definition:
dsr-option-header.h:150
ns3::dsr::DsrFsHeader::SetNextHeader
void SetNextHeader(uint8_t protocol)
Set the "Next header" field.
Definition:
dsr-fs-header.cc:73
ns3::NS_OBJECT_ENSURE_REGISTERED
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
ns3::dsr::DsrOptionHeader::Serialize
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
Definition:
dsr-option-header.cc:102
ns3::dsr::DsrFsHeader::~DsrFsHeader
virtual ~DsrFsHeader()
Destructor.
Definition:
dsr-fs-header.cc:69
ns3::dsr::DsrFsHeader::SetSourceId
void SetSourceId(uint16_t sourceId)
brief Set the source ID of the header.
Definition:
dsr-fs-header.cc:103
NS_LOG_FUNCTION_NOARGS
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition:
log.h:309
visualizer.core.start
def start
Definition:
core.py:1482
ns3::dsr::DsrFsHeader
Dsr fixed size header Format.
Definition:
dsr-fs-header.h:79
ns3::dsr::DsrFsHeader::Serialize
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
Definition:
dsr-fs-header.cc:136
ns3::dsr::DsrOptionHeader::GetAlignment
virtual Alignment GetAlignment() const
Get the Alignment requirement of this option header.
Definition:
dsr-option-header.cc:128
ns3::dsr::DsrFsHeader::SetDestId
void SetDestId(uint16_t destId)
brief Set the dest ID of the header.
Definition:
dsr-fs-header.cc:113
ns3::dsr::DsrRoutingHeader::Serialize
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
Definition:
dsr-fs-header.cc:302
ns3::dsr::DsrOptionField
Definition:
dsr-fs-header.h:210
ns3::dsr::DsrOptionHeader::Alignment
represents the alignment requirements of an option header
Definition:
dsr-option-header.h:57
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition:
buffer.h:98
ns3::dsr::DsrFsHeader::Print
virtual void Print(std::ostream &os) const
Print some informations about the packet.
Definition:
dsr-fs-header.cc:123
ns3::dsr::DsrRoutingHeader::GetInstanceTypeId
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
Definition:
dsr-fs-header.cc:274
ns3::dsr::DsrOptionPad1Header::Serialize
virtual void Serialize(Buffer::Iterator start) const
Serialize the packet.
Definition:
dsr-option-header.cc:170
ns3::dsr::DsrOptionField::GetDsrOptionsOffset
uint32_t GetDsrOptionsOffset()
Get the offset where the options begin, measured from the start of the extension header.
Definition:
dsr-fs-header.cc:252
ns3::dsr::DsrOptionHeader::Alignment::offset
uint8_t offset
Offset.
Definition:
dsr-option-header.h:60
ns3::dsr::DsrFsHeader::m_destId
uint16_t m_destId
The destination node id.
Definition:
dsr-fs-header.h:193
ns3::Buffer::Iterator::Prev
void Prev(void)
go backward by one byte
Definition:
buffer.h:672
ns3::dsr::DsrOptionHeader::GetSerializedSize
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
Definition:
dsr-option-header.cc:97
ns3::dsr::DsrFsHeader::m_nextHeader
uint8_t m_nextHeader
The "next header" field.
Definition:
dsr-fs-header.h:177
data
uint8_t data[writeSize]
Definition:
socket-bound-tcp-static-routing.cc:53
ns3::dsr::DsrOptionHeader::Alignment::factor
uint8_t factor
Factor.
Definition:
dsr-option-header.h:59
ns3::Buffer::Iterator::WriteU16
void WriteU16(uint16_t data)
Definition:
buffer.cc:895
ns3::Buffer::End
Buffer::Iterator End(void) const
Definition:
buffer.h:881
ns3::Buffer::PeekData
uint8_t const * PeekData(void) const
Definition:
buffer.cc:729
ns3::dsr::DsrFsHeader::m_payloadLen
uint16_t m_payloadLen
The "payload length" field.
Definition:
dsr-fs-header.h:185
ns3::dsr::DsrFsHeader::GetSourceId
uint16_t GetSourceId() const
brief Get the source ID of the header.
Definition:
dsr-fs-header.cc:108
NS_LOG_LOGIC
#define NS_LOG_LOGIC(msg)
Definition:
log.h:368
ns3::Buffer::Begin
Buffer::Iterator Begin(void) const
Definition:
buffer.h:875
ns3::dsr::DsrOptionField::GetSerializedSize
uint32_t GetSerializedSize() const
Get the serialized size of the packet.
Definition:
dsr-fs-header.cc:188
ns3::dsr::DsrFsHeader::SetPayloadLength
void SetPayloadLength(uint16_t length)
brief Set the payload length of the header.
Definition:
dsr-fs-header.cc:93
ns3::dsr::DsrFsHeader::GetDestId
uint16_t GetDestId() const
brief Get the dest ID of the header.
Definition:
dsr-fs-header.cc:118
ns3::dsr::DsrFsHeader::Deserialize
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
Definition:
dsr-fs-header.cc:149
ns3::dsr::DsrRoutingHeader::GetSerializedSize
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
Definition:
dsr-fs-header.cc:296
ns3::dsr::DsrFsHeader::DsrFsHeader
DsrFsHeader()
Constructor.
Definition:
dsr-fs-header.cc:59
ns3::dsr::DsrFsHeader::GetNextHeader
uint8_t GetNextHeader() const
Get the next header.
Definition:
dsr-fs-header.cc:78
ns3::Buffer::Iterator::Read
void Read(uint8_t *buffer, uint32_t size)
Definition:
buffer.cc:1148
ns3::dsr::DsrFsHeader::m_messageType
uint8_t m_messageType
The type of the message.
Definition:
dsr-fs-header.h:181
ns3::Buffer::GetSize
uint32_t GetSize(void) const
Definition:
buffer.h:869
ns3::dsr::NS_LOG_COMPONENT_DEFINE
NS_LOG_COMPONENT_DEFINE("DsrFsHeader")
ns3::dsr::DsrFsHeader::SetMessageType
void SetMessageType(uint8_t messageType)
brief Set the message type of the header.
Definition:
dsr-fs-header.cc:83
ns3::dsr::DsrFsHeader::GetInstanceTypeId
virtual TypeId GetInstanceTypeId() const
Get the instance type ID.
Definition:
dsr-fs-header.cc:54
ns3::Buffer::AddAtEnd
bool AddAtEnd(uint32_t end)
Definition:
buffer.cc:356
ns3::dsr::DsrFsHeader::GetSerializedSize
virtual uint32_t GetSerializedSize() const
Get the serialized size of the packet.
Definition:
dsr-fs-header.cc:131
dsr-fs-header.h
ns3::dsr::DsrFsHeader::m_sourceId
uint16_t m_sourceId
The source node id.
Definition:
dsr-fs-header.h:189
ns3::dsr::DsrFsHeader::GetTypeId
static TypeId GetTypeId()
Get the type identificator.
Definition:
dsr-fs-header.cc:45
ns3::dsr::DsrFsHeader::m_data
Buffer m_data
The data of the extension.
Definition:
dsr-fs-header.h:197
ns3::dsr::DsrRoutingHeader::Deserialize
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the packet.
Definition:
dsr-fs-header.cc:315
ns3::Buffer::Iterator::WriteU8
void WriteU8(uint8_t data)
Definition:
buffer.h:690
ns3::dsr::DsrOptionField::DsrOptionField
DsrOptionField(uint32_t optionsOffset)
Constructor.
Definition:
dsr-fs-header.cc:178
ns3::dsr::DsrOptionField::AddDsrOption
void AddDsrOption(DsrOptionHeader const &option)
Serialize the option, prepending pad1 or padn option as necessary.
Definition:
dsr-fs-header.cc:223
ns3::dsr::DsrOptionHeader
Doxygen introspection did not find any typical Config paths.
Definition:
dsr-option-header.h:50
ns3::dsr::DsrRoutingHeader::~DsrRoutingHeader
virtual ~DsrRoutingHeader()
Destructor.
Definition:
dsr-fs-header.cc:284
ns3::dsr::DsrRoutingHeader::Print
virtual void Print(std::ostream &os) const
Print some informations about the packet.
Definition:
dsr-fs-header.cc:288
ns3::dsr::DsrOptionPadnHeader
Doxygen introspection did not find any typical Config paths.
Definition:
dsr-option-header.h:199
ns3::Buffer::Iterator::ReadU8
uint8_t ReadU8(void)
Definition:
buffer.h:819
ns3::Buffer::Iterator::Write
void Write(uint8_t const *buffer, uint32_t size)
Definition:
buffer.cc:978
ns3::dsr::DsrOptionField::CalculatePad
uint32_t CalculatePad(DsrOptionHeader::Alignment alignment) const
Calculate padding.
Definition:
dsr-fs-header.cc:247
ns3::dsr::DsrRoutingHeader
Header of Dsr Routing.
Definition:
dsr-fs-header.h:277
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:49
ns3::dsr::DsrOptionField::m_optionData
Buffer m_optionData
Data payload.
Definition:
dsr-fs-header.h:266
ns3::dsr::DsrOptionField::Serialize
void Serialize(Buffer::Iterator start) const
Serialize all added options.
Definition:
dsr-fs-header.cc:194
ns3::dsr::DsrOptionField::GetDsrOptionBuffer
Buffer GetDsrOptionBuffer()
Get the buffer.
Definition:
dsr-fs-header.cc:257
src
dsr
model
dsr-fs-header.cc
Generated on Sat Apr 19 2014 14:06:53 for ns-3 by
1.8.6