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