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
radiotap-header.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2009 CTTC
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, Include., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Nicola Baldo <nbaldo@cttc.es>
19
*/
20
21
#include <iomanip>
22
#include <cmath>
23
#include "ns3/log.h"
24
#include "
radiotap-header.h
"
25
26
namespace
ns3
{
27
28
NS_LOG_COMPONENT_DEFINE
(
"RadiotapHeader"
);
29
30
NS_OBJECT_ENSURE_REGISTERED
(RadiotapHeader);
31
32
RadiotapHeader::RadiotapHeader
()
33
: m_length (8),
34
m_present (0),
35
m_tsft (0),
36
m_flags (FRAME_FLAG_NONE),
37
m_rate (0),
38
m_channelFreq (0),
39
m_channelFlags (CHANNEL_FLAG_NONE),
40
m_antennaSignal (0),
41
m_antennaNoise (0)
42
{
43
NS_LOG_FUNCTION
(
this
);
44
}
45
46
TypeId
RadiotapHeader::GetTypeId
(
void
)
47
{
48
static
TypeId
tid =
TypeId
(
"ns3::RadiotapHeader"
)
49
.
SetParent
<
Header
> ()
50
.SetGroupName(
"Network"
)
51
52
.AddConstructor<
RadiotapHeader
> ()
53
;
54
return
tid;
55
}
56
57
TypeId
58
RadiotapHeader::GetInstanceTypeId
(
void
)
const
59
{
60
return
GetTypeId
();
61
}
62
63
uint32_t
64
RadiotapHeader::GetSerializedSize
(
void
)
const
65
{
66
NS_LOG_FUNCTION
(
this
);
67
return
m_length
;
68
}
69
70
void
71
RadiotapHeader::Serialize
(
Buffer::Iterator
start
)
const
72
{
73
NS_LOG_FUNCTION
(
this
<< &start);
74
75
start.
WriteU8
(0);
// major version of radiotap header
76
start.
WriteU8
(0);
// pad field
77
start.
WriteU16
(
m_length
);
// entire length of radiotap data + header
78
start.
WriteU32
(
m_present
);
// bits describing which fields follow header
79
80
//
81
// Time Synchronization Function Timer (when the first bit of the MPDU
82
// arrived at the MAC)
83
//
84
if
(
m_present
&
RADIOTAP_TSFT
)
// bit 0
85
{
86
start.
WriteU64
(
m_tsft
);
87
}
88
89
//
90
// Properties of transmitted and received frames.
91
//
92
if
(
m_present
&
RADIOTAP_FLAGS
)
// bit 1
93
{
94
start.
WriteU8
(
m_flags
);
95
}
96
97
//
98
// TX/RX data rate in units of 500 kbps
99
//
100
if
(
m_present
&
RADIOTAP_RATE
)
// bit 2
101
{
102
start.
WriteU8
(
m_rate
);
103
}
104
105
//
106
// Tx/Rx frequency in MHz, followed by flags.
107
//
108
if
(
m_present
&
RADIOTAP_CHANNEL
)
// bit 3
109
{
110
start.
WriteU16
(
m_channelFreq
);
111
start.
WriteU16
(
m_channelFlags
);
112
}
113
114
//
115
// RF signal power at the antenna, decibel difference from an arbitrary, fixed
116
// reference.
117
//
118
if
(
m_present
&
RADIOTAP_DBM_ANTSIGNAL
)
// bit 5
119
{
120
start.
WriteU8
(
m_antennaSignal
);
121
}
122
123
//
124
// RF noise power at the antenna, decibel difference from an arbitrary, fixed
125
// reference.
126
//
127
if
(
m_present
&
RADIOTAP_DBM_ANTNOISE
)
// bit 6
128
{
129
start.
WriteU8
(
m_antennaNoise
);
130
}
131
}
132
133
uint32_t
134
RadiotapHeader::Deserialize
(
Buffer::Iterator
start
)
135
{
136
NS_LOG_FUNCTION
(
this
<< &start);
137
138
uint8_t tmp = start.
ReadU8
();
// major version of radiotap header
139
NS_ASSERT_MSG
(tmp == 0x00,
"RadiotapHeader::Deserialize(): Unexpected major version"
);
140
start.
ReadU8
();
// pad field
141
142
m_length
= start.
ReadU16
();
// entire length of radiotap data + header
143
m_present
= start.
ReadU32
();
// bits describing which fields follow header
144
145
uint32_t bytesRead = 8;
146
147
//
148
// Time Synchronization Function Timer (when the first bit of the MPDU arrived at the MAC)
149
//
150
if
(
m_present
&
RADIOTAP_TSFT
)
// bit 0
151
{
152
m_tsft
= start.
ReadU64
();
153
bytesRead += 8;
154
}
155
156
//
157
// Properties of transmitted and received frames.
158
//
159
if
(
m_present
&
RADIOTAP_FLAGS
)
// bit 1
160
{
161
m_flags
= start.
ReadU8
();
162
++bytesRead;
163
}
164
165
//
166
// TX/RX data rate in units of 500 kbps
167
//
168
if
(
m_present
&
RADIOTAP_RATE
)
// bit 2
169
{
170
m_rate
= start.
ReadU8
();
171
++bytesRead;
172
}
173
174
//
175
// Tx/Rx frequency in MHz, followed by flags.
176
//
177
if
(
m_present
&
RADIOTAP_CHANNEL
)
// bit 3
178
{
179
m_channelFreq
= start.
ReadU16
();
180
m_channelFlags
= start.
ReadU16
();
181
bytesRead += 4;
182
}
183
184
//
185
// The hop set and pattern for frequency-hopping radios. We don't need it but
186
// still need to account for it.
187
//
188
if
(
m_present
&
RADIOTAP_FHSS
)
// bit 4
189
{
190
start.
ReadU8
();
191
++bytesRead;
192
}
193
194
//
195
// RF signal power at the antenna, decibel difference from an arbitrary, fixed
196
// reference.
197
//
198
if
(
m_present
&
RADIOTAP_DBM_ANTSIGNAL
)
// bit 5
199
{
200
m_antennaSignal
= start.
ReadU8
();
201
++bytesRead;
202
}
203
204
//
205
// RF noise power at the antenna, decibel difference from an arbitrary, fixed
206
// reference.
207
//
208
if
(
m_present
&
RADIOTAP_DBM_ANTNOISE
)
// bit 6
209
{
210
m_antennaNoise
= start.
ReadU8
();
211
++bytesRead;
212
}
213
214
NS_ASSERT_MSG
(
m_length
== bytesRead,
"RadiotapHeader::Deserialize(): expected and actual lengths inconsistent"
);
215
return
bytesRead;
216
}
217
218
void
219
RadiotapHeader::Print
(std::ostream &os)
const
220
{
221
NS_LOG_FUNCTION
(
this
<< &os);
222
os <<
" tsft="
<<
m_tsft
223
<<
" flags="
<< std::hex <<
m_flags
<< std::dec
224
<<
" rate="
<< (uint16_t)
m_rate
225
<<
" freq="
<<
m_channelFreq
226
<<
" chflags="
<< std::hex << (uint32_t)
m_channelFlags
<< std::dec
227
<<
" signal="
<< (int16_t)
m_antennaSignal
228
<<
" noise="
<< (int16_t)
m_antennaNoise
;
229
}
230
231
void
232
RadiotapHeader::SetTsft
(uint64_t value)
233
{
234
NS_LOG_FUNCTION
(
this
<< value);
235
m_tsft
= value;
236
237
if
(!(
m_present
&
RADIOTAP_TSFT
))
238
{
239
m_present
|=
RADIOTAP_TSFT
;
240
m_length
+= 8;
241
}
242
243
NS_LOG_LOGIC
(
this
<<
" m_length="
<<
m_length
<<
" m_present=0x"
<< std::hex <<
m_present
<< std::dec);
244
}
245
246
uint64_t
247
RadiotapHeader::GetTsft
()
const
248
{
249
NS_LOG_FUNCTION
(
this
);
250
return
m_tsft
;
251
}
252
253
void
254
RadiotapHeader::SetFrameFlags
(uint8_t flags)
255
{
256
NS_LOG_FUNCTION
(
this
<< static_cast<uint32_t> (flags));
257
m_flags
= flags;
258
259
if
(!(
m_present
&
RADIOTAP_FLAGS
))
260
{
261
m_present
|=
RADIOTAP_FLAGS
;
262
m_length
+= 1;
263
}
264
265
NS_LOG_LOGIC
(
this
<<
" m_length="
<<
m_length
<<
" m_present=0x"
<< std::hex <<
m_present
<< std::dec);
266
}
267
268
uint8_t
269
RadiotapHeader::GetFrameFlags
(
void
)
const
270
{
271
NS_LOG_FUNCTION
(
this
);
272
return
m_flags
;
273
}
274
275
void
276
RadiotapHeader::SetRate
(uint8_t rate)
277
{
278
NS_LOG_FUNCTION
(
this
<< static_cast<uint32_t> (rate));
279
m_rate
= rate;
280
281
if
(!(
m_present
&
RADIOTAP_RATE
))
282
{
283
m_present
|=
RADIOTAP_RATE
;
284
m_length
+= 1;
285
}
286
287
NS_LOG_LOGIC
(
this
<<
" m_length="
<<
m_length
<<
" m_present=0x"
<< std::hex <<
m_present
<< std::dec);
288
}
289
290
uint8_t
291
RadiotapHeader::GetRate
(
void
)
const
292
{
293
NS_LOG_FUNCTION
(
this
);
294
return
m_rate
;
295
}
296
297
void
298
RadiotapHeader::SetChannelFrequencyAndFlags
(uint16_t frequency, uint16_t flags)
299
{
300
NS_LOG_FUNCTION
(
this
<< frequency << flags);
301
m_channelFreq
= frequency;
302
m_channelFlags
= flags;
303
304
if
(!(
m_present
&
RADIOTAP_CHANNEL
))
305
{
306
m_present
|=
RADIOTAP_CHANNEL
;
307
m_length
+= 4;
308
}
309
310
NS_LOG_LOGIC
(
this
<<
" m_length="
<<
m_length
<<
" m_present=0x"
<< std::hex <<
m_present
<< std::dec);
311
}
312
313
uint16_t
314
RadiotapHeader::GetChannelFrequency
(
void
)
const
315
{
316
NS_LOG_FUNCTION
(
this
);
317
return
m_channelFreq
;
318
}
319
320
uint16_t
321
RadiotapHeader::GetChannelFlags
(
void
)
const
322
{
323
NS_LOG_FUNCTION
(
this
);
324
return
m_channelFlags
;
325
}
326
327
void
328
RadiotapHeader::SetAntennaSignalPower
(
double
signal)
329
{
330
NS_LOG_FUNCTION
(
this
<< signal);
331
332
if
(!(
m_present
&
RADIOTAP_DBM_ANTSIGNAL
))
333
{
334
m_present
|=
RADIOTAP_DBM_ANTSIGNAL
;
335
m_length
+= 1;
336
}
337
if
(signal > 127)
338
{
339
m_antennaSignal
= 127;
340
}
341
else
if
(signal < -128)
342
{
343
m_antennaSignal
= -128;
344
}
345
else
346
{
347
m_antennaSignal
=
static_cast<
int8_t
>
(floor (signal + 0.5));
348
}
349
350
NS_LOG_LOGIC
(
this
<<
" m_length="
<<
m_length
<<
" m_present=0x"
<< std::hex <<
m_present
<< std::dec);
351
}
352
353
uint8_t
354
RadiotapHeader::GetAntennaSignalPower
(
void
)
const
355
{
356
NS_LOG_FUNCTION
(
this
);
357
return
m_antennaSignal
;
358
}
359
360
void
361
RadiotapHeader::SetAntennaNoisePower
(
double
noise)
362
{
363
NS_LOG_FUNCTION
(
this
<< noise);
364
365
if
(!(
m_present
&
RADIOTAP_DBM_ANTNOISE
))
366
{
367
m_present
|=
RADIOTAP_DBM_ANTNOISE
;
368
m_length
+= 1;
369
}
370
if
(noise > 127.0)
371
{
372
m_antennaNoise
= 127;
373
}
374
else
if
(noise < -128.0)
375
{
376
m_antennaNoise
= -128;
377
}
378
else
379
{
380
m_antennaNoise
=
static_cast<
int8_t
>
(floor (noise + 0.5));
381
}
382
383
NS_LOG_LOGIC
(
this
<<
" m_length="
<<
m_length
<<
" m_present=0x"
<< std::hex <<
m_present
<< std::dec);
384
}
385
386
uint8_t
387
RadiotapHeader::GetAntennaNoisePower
(
void
)
const
388
{
389
NS_LOG_FUNCTION
(
this
);
390
return
m_antennaNoise
;
391
}
392
393
}
// namespace ns3
ns3::Buffer::Iterator::ReadU16
uint16_t ReadU16(void)
Definition:
buffer.h:1036
ns3::Header
Protocol header serialization and deserialization.
Definition:
header.h:42
ns3::Buffer::Iterator::ReadU32
uint32_t ReadU32(void)
Definition:
buffer.cc:1001
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Definition:
log-macros-enabled.h:213
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:44
ns3::RadiotapHeader
Radiotap header implementation.
Definition:
radiotap-header.h:48
radiotap-header.h
ns3::RadiotapHeader::GetTsft
uint64_t GetTsft(void) const
Get the Time Synchronization Function Timer (TSFT) value.
Definition:
radiotap-header.cc:247
ns3::RadiotapHeader::Print
virtual void Print(std::ostream &os) const
This method is used by Packet::Print to print the content of the header as ascii data to a C++ output...
Definition:
radiotap-header.cc:219
ns3::RadiotapHeader::GetRate
uint8_t GetRate(void) const
Get the transmit/receive channel frequency in units of megahertz.
Definition:
radiotap-header.cc:291
visualizer.core.start
def start()
Definition:
core.py:1482
ns3::RadiotapHeader::Deserialize
virtual uint32_t Deserialize(Buffer::Iterator start)
This method is used by Packet::RemoveHeader to re-create a header from the byte buffer of a packet...
Definition:
radiotap-header.cc:134
ns3::RadiotapHeader::GetSerializedSize
virtual uint32_t GetSerializedSize(void) const
This method is used by Packet::AddHeader to store the header into the byte buffer of a packet...
Definition:
radiotap-header.cc:64
ns3::RadiotapHeader::RADIOTAP_TSFT
Definition:
radiotap-header.h:232
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:201
ns3::RadiotapHeader::m_channelFreq
uint16_t m_channelFreq
Tx/Rx frequency in MHz.
Definition:
radiotap-header.h:255
ns3::RadiotapHeader::GetInstanceTypeId
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition:
radiotap-header.cc:58
ns3::RadiotapHeader::RADIOTAP_FHSS
Definition:
radiotap-header.h:236
ns3::RadiotapHeader::SetAntennaNoisePower
void SetAntennaNoisePower(double noise)
Set the RF noise power at the antenna as a decibel difference from an arbitrary, fixed reference...
Definition:
radiotap-header.cc:361
ns3::RadiotapHeader::GetAntennaNoisePower
uint8_t GetAntennaNoisePower(void) const
Get the RF noise power at the antenna as a decibel difference from an arbitrary, fixed reference...
Definition:
radiotap-header.cc:387
ns3::RadiotapHeader::SetTsft
void SetTsft(uint64_t tsft)
Set the Time Synchronization Function Timer (TSFT) value.
Definition:
radiotap-header.cc:232
ns3::RadiotapHeader::RADIOTAP_CHANNEL
Definition:
radiotap-header.h:235
ns3::RadiotapHeader::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition:
radiotap-header.cc:46
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition:
buffer.h:98
ns3::RadiotapHeader::SetChannelFrequencyAndFlags
void SetChannelFrequencyAndFlags(uint16_t frequency, uint16_t flags)
Set the transmit/receive channel frequency and flags.
Definition:
radiotap-header.cc:298
ns3::RadiotapHeader::m_tsft
uint64_t m_tsft
Time Synchronization Function Timer (when the first bit of the MPDU arrived at the MAC) ...
Definition:
radiotap-header.h:252
ns3::Buffer::Iterator::WriteU16
void WriteU16(uint16_t data)
Definition:
buffer.cc:899
ns3::RadiotapHeader::m_antennaNoise
int8_t m_antennaNoise
RF noise power at the antenna, dB difference from an arbitrary, fixed reference.
Definition:
radiotap-header.h:258
ns3::Buffer::Iterator::WriteU64
void WriteU64(uint64_t data)
Definition:
buffer.cc:919
ns3::RadiotapHeader::m_channelFlags
uint16_t m_channelFlags
Tx/Rx channel flags.
Definition:
radiotap-header.h:256
NS_LOG_LOGIC
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition:
log.h:252
ns3::RadiotapHeader::RADIOTAP_DBM_ANTNOISE
Definition:
radiotap-header.h:238
ns3::RadiotapHeader::SetFrameFlags
void SetFrameFlags(uint8_t flags)
Set the frame flags of the transmitted or received frame.
Definition:
radiotap-header.cc:254
ns3::RadiotapHeader::SetRate
void SetRate(uint8_t rate)
Set the transmit/receive channel frequency in units of megahertz.
Definition:
radiotap-header.cc:276
ns3::RadiotapHeader::RADIOTAP_RATE
Definition:
radiotap-header.h:234
ns3::RadiotapHeader::m_antennaSignal
int8_t m_antennaSignal
RF signal power at the antenna, dB difference from an arbitrary, fixed reference. ...
Definition:
radiotap-header.h:257
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::RadiotapHeader::m_flags
uint8_t m_flags
Properties of transmitted and received frames.
Definition:
radiotap-header.h:253
ns3::RadiotapHeader::GetFrameFlags
uint8_t GetFrameFlags(void) const
Get the frame flags of the transmitted or received frame.
Definition:
radiotap-header.cc:269
ns3::RadiotapHeader::GetChannelFlags
uint16_t GetChannelFlags(void) const
Get the channel flags of the transmitted or received frame.
Definition:
radiotap-header.cc:321
ns3::RadiotapHeader::m_present
uint32_t m_present
bits describing which fields follow header
Definition:
radiotap-header.h:250
ns3::Buffer::Iterator::ReadU64
uint64_t ReadU64(void)
Definition:
buffer.cc:1018
ns3::RadiotapHeader::RADIOTAP_DBM_ANTSIGNAL
Definition:
radiotap-header.h:237
NS_ASSERT_MSG
#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:90
ns3::RadiotapHeader::GetAntennaSignalPower
uint8_t GetAntennaSignalPower(void) const
Get the RF signal power at the antenna as a decibel difference from an arbitrary, fixed reference...
Definition:
radiotap-header.cc:354
ns3::Buffer::Iterator::WriteU8
void WriteU8(uint8_t data)
Definition:
buffer.h:876
ns3::RadiotapHeader::RADIOTAP_FLAGS
Definition:
radiotap-header.h:233
ns3::Buffer::Iterator::ReadU8
uint8_t ReadU8(void)
Definition:
buffer.h:1028
ns3::RadiotapHeader::m_length
uint16_t m_length
entire length of radiotap data + header
Definition:
radiotap-header.h:249
ns3::RadiotapHeader::m_rate
uint8_t m_rate
TX/RX data rate in units of 500 kbps.
Definition:
radiotap-header.h:254
ns3::RadiotapHeader::Serialize
virtual void Serialize(Buffer::Iterator start) const
This method is used by Packet::AddHeader to store the header into the byte buffer of a packet...
Definition:
radiotap-header.cc:71
ns3::Buffer::Iterator::WriteU32
void WriteU32(uint32_t data)
Definition:
buffer.cc:907
ns3::RadiotapHeader::GetChannelFrequency
uint16_t GetChannelFrequency(void) const
Get the transmit/receive data rate in units of 500 kbps.
Definition:
radiotap-header.cc:314
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:57
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Definition:
type-id.cc:638
ns3::RadiotapHeader::RadiotapHeader
RadiotapHeader()
Definition:
radiotap-header.cc:32
ns3::RadiotapHeader::SetAntennaSignalPower
void SetAntennaSignalPower(double signal)
Set the RF signal power at the antenna as a decibel difference from an arbitrary, fixed reference...
Definition:
radiotap-header.cc:328
src
network
utils
radiotap-header.cc
Generated on Wed May 13 2015 14:59:29 for ns-3 by
1.8.9.1