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
yans-wifi-phy.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2005,2006 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
*/
20
21
#include "
yans-wifi-phy.h
"
22
#include "
yans-wifi-channel.h
"
23
#include "
wifi-mode.h
"
24
#include "
wifi-preamble.h
"
25
#include "
wifi-phy-state-helper.h
"
26
#include "
error-rate-model.h
"
27
#include "ns3/simulator.h"
28
#include "ns3/packet.h"
29
#include "ns3/assert.h"
30
#include "ns3/log.h"
31
#include "ns3/double.h"
32
#include "ns3/uinteger.h"
33
#include "ns3/enum.h"
34
#include "ns3/pointer.h"
35
#include "ns3/net-device.h"
36
#include "ns3/trace-source-accessor.h"
37
#include <cmath>
38
39
NS_LOG_COMPONENT_DEFINE
(
"YansWifiPhy"
);
40
41
namespace
ns3 {
42
43
NS_OBJECT_ENSURE_REGISTERED
(YansWifiPhy);
44
45
TypeId
46
YansWifiPhy::GetTypeId
(
void
)
47
{
48
static
TypeId
tid =
TypeId
(
"ns3::YansWifiPhy"
)
49
.
SetParent
<
WifiPhy
> ()
50
.AddConstructor<YansWifiPhy> ()
51
.AddAttribute (
"EnergyDetectionThreshold"
,
52
"The energy of a received signal should be higher than "
53
"this threshold (dbm) to allow the PHY layer to detect the signal."
,
54
DoubleValue
(-96.0),
55
MakeDoubleAccessor (&
YansWifiPhy::SetEdThreshold
,
56
&
YansWifiPhy::GetEdThreshold
),
57
MakeDoubleChecker<double> ())
58
.AddAttribute (
"CcaMode1Threshold"
,
59
"The energy of a received signal should be higher than "
60
"this threshold (dbm) to allow the PHY layer to declare CCA BUSY state"
,
61
DoubleValue
(-99.0),
62
MakeDoubleAccessor (&
YansWifiPhy::SetCcaMode1Threshold
,
63
&
YansWifiPhy::GetCcaMode1Threshold
),
64
MakeDoubleChecker<double> ())
65
.AddAttribute (
"TxGain"
,
66
"Transmission gain (dB)."
,
67
DoubleValue
(1.0),
68
MakeDoubleAccessor (&
YansWifiPhy::SetTxGain
,
69
&
YansWifiPhy::GetTxGain
),
70
MakeDoubleChecker<double> ())
71
.AddAttribute (
"RxGain"
,
72
"Reception gain (dB)."
,
73
DoubleValue
(1.0),
74
MakeDoubleAccessor (&
YansWifiPhy::SetRxGain
,
75
&
YansWifiPhy::GetRxGain
),
76
MakeDoubleChecker<double> ())
77
.AddAttribute (
"TxPowerLevels"
,
78
"Number of transmission power levels available between "
79
"TxPowerStart and TxPowerEnd included."
,
80
UintegerValue
(1),
81
MakeUintegerAccessor (&
YansWifiPhy::m_nTxPower
),
82
MakeUintegerChecker<uint32_t> ())
83
.AddAttribute (
"TxPowerEnd"
,
84
"Maximum available transmission level (dbm)."
,
85
DoubleValue
(16.0206),
86
MakeDoubleAccessor (&
YansWifiPhy::SetTxPowerEnd
,
87
&
YansWifiPhy::GetTxPowerEnd
),
88
MakeDoubleChecker<double> ())
89
.AddAttribute (
"TxPowerStart"
,
90
"Minimum available transmission level (dbm)."
,
91
DoubleValue
(16.0206),
92
MakeDoubleAccessor (&
YansWifiPhy::SetTxPowerStart
,
93
&
YansWifiPhy::GetTxPowerStart
),
94
MakeDoubleChecker<double> ())
95
.AddAttribute (
"RxNoiseFigure"
,
96
"Loss (dB) in the Signal-to-Noise-Ratio due to non-idealities in the receiver."
97
" According to Wikipedia (http://en.wikipedia.org/wiki/Noise_figure), this is "
98
"\"the difference in decibels (dB) between"
99
" the noise output of the actual receiver to the noise output of an "
100
" ideal receiver with the same overall gain and bandwidth when the receivers "
101
" are connected to sources at the standard noise temperature T0 (usually 290 K)\"."
102
" For"
,
103
DoubleValue
(7),
104
MakeDoubleAccessor (&
YansWifiPhy::SetRxNoiseFigure
,
105
&
YansWifiPhy::GetRxNoiseFigure
),
106
MakeDoubleChecker<double> ())
107
.AddAttribute (
"State"
,
"The state of the PHY layer"
,
108
PointerValue
(),
109
MakePointerAccessor (&
YansWifiPhy::m_state
),
110
MakePointerChecker<WifiPhyStateHelper> ())
111
.AddAttribute (
"ChannelSwitchDelay"
,
112
"Delay between two short frames transmitted on different frequencies. NOTE: Unused now."
,
113
TimeValue
(
MicroSeconds
(250)),
114
MakeTimeAccessor (&
YansWifiPhy::m_channelSwitchDelay
),
115
MakeTimeChecker ())
116
.AddAttribute (
"ChannelNumber"
,
117
"Channel center frequency = Channel starting frequency + 5 MHz * (nch - 1)"
,
118
UintegerValue
(1),
119
MakeUintegerAccessor (&
YansWifiPhy::SetChannelNumber
,
120
&
YansWifiPhy::GetChannelNumber
),
121
MakeUintegerChecker<uint16_t> ())
122
123
;
124
return
tid;
125
}
126
127
YansWifiPhy::YansWifiPhy
()
128
: m_channelNumber (1),
129
m_endRxEvent (),
130
m_channelStartingFrequency (0)
131
{
132
NS_LOG_FUNCTION
(
this
);
133
m_random
= CreateObject<UniformRandomVariable> ();
134
m_state
= CreateObject<WifiPhyStateHelper> ();
135
}
136
137
YansWifiPhy::~YansWifiPhy
()
138
{
139
NS_LOG_FUNCTION
(
this
);
140
}
141
142
void
143
YansWifiPhy::DoDispose
(
void
)
144
{
145
NS_LOG_FUNCTION
(
this
);
146
m_channel
= 0;
147
m_deviceRateSet
.clear ();
148
m_device
= 0;
149
m_mobility
= 0;
150
m_state
= 0;
151
}
152
153
void
154
YansWifiPhy::ConfigureStandard
(
enum
WifiPhyStandard
standard)
155
{
156
NS_LOG_FUNCTION
(
this
<< standard);
157
switch
(standard)
158
{
159
case
WIFI_PHY_STANDARD_80211a
:
160
Configure80211a
();
161
break
;
162
case
WIFI_PHY_STANDARD_80211b
:
163
Configure80211b
();
164
break
;
165
case
WIFI_PHY_STANDARD_80211g
:
166
Configure80211g
();
167
break
;
168
case
WIFI_PHY_STANDARD_80211_10MHZ
:
169
Configure80211_10Mhz
();
170
break
;
171
case
WIFI_PHY_STANDARD_80211_5MHZ
:
172
Configure80211_5Mhz
();
173
break
;
174
case
WIFI_PHY_STANDARD_holland
:
175
ConfigureHolland
();
176
break
;
177
case
WIFI_PHY_STANDARD_80211p_CCH
:
178
Configure80211p_CCH
();
179
break
;
180
case
WIFI_PHY_STANDARD_80211p_SCH
:
181
Configure80211p_SCH
();
182
break
;
183
default
:
184
NS_ASSERT
(
false
);
185
break
;
186
}
187
}
188
189
190
void
191
YansWifiPhy::SetRxNoiseFigure
(
double
noiseFigureDb)
192
{
193
NS_LOG_FUNCTION
(
this
<< noiseFigureDb);
194
m_interference
.
SetNoiseFigure
(
DbToRatio
(noiseFigureDb));
195
}
196
void
197
YansWifiPhy::SetTxPowerStart
(
double
start
)
198
{
199
NS_LOG_FUNCTION
(
this
<< start);
200
m_txPowerBaseDbm
=
start
;
201
}
202
void
203
YansWifiPhy::SetTxPowerEnd
(
double
end)
204
{
205
NS_LOG_FUNCTION
(
this
<< end);
206
m_txPowerEndDbm
= end;
207
}
208
void
209
YansWifiPhy::SetNTxPower
(uint32_t n)
210
{
211
NS_LOG_FUNCTION
(
this
<< n);
212
m_nTxPower
= n;
213
}
214
void
215
YansWifiPhy::SetTxGain
(
double
gain)
216
{
217
NS_LOG_FUNCTION
(
this
<< gain);
218
m_txGainDb
= gain;
219
}
220
void
221
YansWifiPhy::SetRxGain
(
double
gain)
222
{
223
NS_LOG_FUNCTION
(
this
<< gain);
224
m_rxGainDb
= gain;
225
}
226
void
227
YansWifiPhy::SetEdThreshold
(
double
threshold)
228
{
229
NS_LOG_FUNCTION
(
this
<< threshold);
230
m_edThresholdW
=
DbmToW
(threshold);
231
}
232
void
233
YansWifiPhy::SetCcaMode1Threshold
(
double
threshold)
234
{
235
NS_LOG_FUNCTION
(
this
<< threshold);
236
m_ccaMode1ThresholdW
=
DbmToW
(threshold);
237
}
238
void
239
YansWifiPhy::SetErrorRateModel
(
Ptr<ErrorRateModel>
rate)
240
{
241
m_interference
.
SetErrorRateModel
(rate);
242
}
243
void
244
YansWifiPhy::SetDevice
(
Ptr<Object>
device)
245
{
246
m_device
= device;
247
}
248
void
249
YansWifiPhy::SetMobility
(
Ptr<Object>
mobility)
250
{
251
m_mobility
= mobility;
252
}
253
254
double
255
YansWifiPhy::GetRxNoiseFigure
(
void
)
const
256
{
257
return
RatioToDb
(
m_interference
.
GetNoiseFigure
());
258
}
259
double
260
YansWifiPhy::GetTxPowerStart
(
void
)
const
261
{
262
return
m_txPowerBaseDbm
;
263
}
264
double
265
YansWifiPhy::GetTxPowerEnd
(
void
)
const
266
{
267
return
m_txPowerEndDbm
;
268
}
269
double
270
YansWifiPhy::GetTxGain
(
void
)
const
271
{
272
return
m_txGainDb
;
273
}
274
double
275
YansWifiPhy::GetRxGain
(
void
)
const
276
{
277
return
m_rxGainDb
;
278
}
279
280
double
281
YansWifiPhy::GetEdThreshold
(
void
)
const
282
{
283
return
WToDbm
(
m_edThresholdW
);
284
}
285
286
double
287
YansWifiPhy::GetCcaMode1Threshold
(
void
)
const
288
{
289
return
WToDbm
(
m_ccaMode1ThresholdW
);
290
}
291
292
Ptr<ErrorRateModel>
293
YansWifiPhy::GetErrorRateModel
(
void
)
const
294
{
295
return
m_interference
.
GetErrorRateModel
();
296
}
297
Ptr<Object>
298
YansWifiPhy::GetDevice
(
void
)
const
299
{
300
return
m_device
;
301
}
302
Ptr<Object>
303
YansWifiPhy::GetMobility
(
void
)
304
{
305
return
m_mobility
;
306
}
307
308
double
309
YansWifiPhy::CalculateSnr
(
WifiMode
txMode,
double
ber)
const
310
{
311
return
m_interference
.
GetErrorRateModel
()->
CalculateSnr
(txMode, ber);
312
}
313
314
Ptr<WifiChannel>
315
YansWifiPhy::GetChannel
(
void
)
const
316
{
317
return
m_channel
;
318
}
319
void
320
YansWifiPhy::SetChannel
(
Ptr<YansWifiChannel>
channel)
321
{
322
m_channel
= channel;
323
m_channel
->
Add
(
this
);
324
}
325
326
void
327
YansWifiPhy::SetChannelNumber
(uint16_t nch)
328
{
329
if
(
Simulator::Now
() ==
Seconds
(0))
330
{
331
// this is not channel switch, this is initialization
332
NS_LOG_DEBUG
(
"start at channel "
<< nch);
333
m_channelNumber
= nch;
334
return
;
335
}
336
337
NS_ASSERT
(!
IsStateSwitching
());
338
switch
(
m_state
->
GetState
())
339
{
340
case
YansWifiPhy::RX
:
341
NS_LOG_DEBUG
(
"drop packet because of channel switching while reception"
);
342
m_endRxEvent
.
Cancel
();
343
goto
switchChannel;
344
break
;
345
case
YansWifiPhy::TX
:
346
NS_LOG_DEBUG
(
"channel switching postponed until end of current transmission"
);
347
Simulator::Schedule
(
GetDelayUntilIdle
(), &
YansWifiPhy::SetChannelNumber
,
this
, nch);
348
break
;
349
case
YansWifiPhy::CCA_BUSY
:
350
case
YansWifiPhy::IDLE
:
351
goto
switchChannel;
352
break
;
353
default
:
354
NS_ASSERT
(
false
);
355
break
;
356
}
357
358
return
;
359
360
switchChannel:
361
362
NS_LOG_DEBUG
(
"switching channel "
<<
m_channelNumber
<<
" -> "
<< nch);
363
m_state
->
SwitchToChannelSwitching
(
m_channelSwitchDelay
);
364
m_interference
.
EraseEvents
();
365
/*
366
* Needed here to be able to correctly sensed the medium for the first
367
* time after the switching. The actual switching is not performed until
368
* after m_channelSwitchDelay. Packets received during the switching
369
* state are added to the event list and are employed later to figure
370
* out the state of the medium after the switching.
371
*/
372
m_channelNumber
= nch;
373
}
374
375
uint16_t
376
YansWifiPhy::GetChannelNumber
()
const
377
{
378
return
m_channelNumber
;
379
}
380
381
double
382
YansWifiPhy::GetChannelFrequencyMhz
()
const
383
{
384
return
m_channelStartingFrequency
+ 5 *
GetChannelNumber
();
385
}
386
387
void
388
YansWifiPhy::SetReceiveOkCallback
(
RxOkCallback
callback)
389
{
390
m_state
->
SetReceiveOkCallback
(callback);
391
}
392
void
393
YansWifiPhy::SetReceiveErrorCallback
(
RxErrorCallback
callback)
394
{
395
m_state
->
SetReceiveErrorCallback
(callback);
396
}
397
void
398
YansWifiPhy::StartReceivePacket
(
Ptr<Packet>
packet,
399
double
rxPowerDbm,
400
WifiMode
txMode,
401
enum
WifiPreamble
preamble)
402
{
403
NS_LOG_FUNCTION
(
this
<< packet << rxPowerDbm << txMode << preamble);
404
rxPowerDbm +=
m_rxGainDb
;
405
double
rxPowerW =
DbmToW
(rxPowerDbm);
406
Time
rxDuration =
CalculateTxDuration
(packet->
GetSize
(), txMode, preamble);
407
Time
endRx =
Simulator::Now
() + rxDuration;
408
409
Ptr<InterferenceHelper::Event>
event;
410
event
=
m_interference
.
Add
(packet->
GetSize
(),
411
txMode,
412
preamble,
413
rxDuration,
414
rxPowerW);
415
416
switch
(
m_state
->
GetState
())
417
{
418
case
YansWifiPhy::SWITCHING
:
419
NS_LOG_DEBUG
(
"drop packet because of channel switching"
);
420
NotifyRxDrop
(packet);
421
/*
422
* Packets received on the upcoming channel are added to the event list
423
* during the switching state. This way the medium can be correctly sensed
424
* when the device listens to the channel for the first time after the
425
* switching e.g. after channel switching, the channel may be sensed as
426
* busy due to other devices' tramissions started before the end of
427
* the switching.
428
*/
429
if
(endRx >
Simulator::Now
() +
m_state
->
GetDelayUntilIdle
())
430
{
431
// that packet will be noise _after_ the completion of the
432
// channel switching.
433
goto
maybeCcaBusy;
434
}
435
break
;
436
case
YansWifiPhy::RX
:
437
NS_LOG_DEBUG
(
"drop packet because already in Rx (power="
<<
438
rxPowerW <<
"W)"
);
439
NotifyRxDrop
(packet);
440
if
(endRx >
Simulator::Now
() +
m_state
->
GetDelayUntilIdle
())
441
{
442
// that packet will be noise _after_ the reception of the
443
// currently-received packet.
444
goto
maybeCcaBusy;
445
}
446
break
;
447
case
YansWifiPhy::TX
:
448
NS_LOG_DEBUG
(
"drop packet because already in Tx (power="
<<
449
rxPowerW <<
"W)"
);
450
NotifyRxDrop
(packet);
451
if
(endRx >
Simulator::Now
() +
m_state
->
GetDelayUntilIdle
())
452
{
453
// that packet will be noise _after_ the transmission of the
454
// currently-transmitted packet.
455
goto
maybeCcaBusy;
456
}
457
break
;
458
case
YansWifiPhy::CCA_BUSY
:
459
case
YansWifiPhy::IDLE
:
460
if
(rxPowerW >
m_edThresholdW
)
461
{
462
NS_LOG_DEBUG
(
"sync to signal (power="
<< rxPowerW <<
"W)"
);
463
// sync to signal
464
m_state
->
SwitchToRx
(rxDuration);
465
NS_ASSERT
(
m_endRxEvent
.
IsExpired
());
466
NotifyRxBegin
(packet);
467
m_interference
.
NotifyRxStart
();
468
m_endRxEvent
=
Simulator::Schedule
(rxDuration, &
YansWifiPhy::EndReceive
,
this
,
469
packet,
470
event);
471
}
472
else
473
{
474
NS_LOG_DEBUG
(
"drop packet because signal power too Small ("
<<
475
rxPowerW <<
"<"
<<
m_edThresholdW
<<
")"
);
476
NotifyRxDrop
(packet);
477
goto
maybeCcaBusy;
478
}
479
break
;
480
}
481
482
return
;
483
484
maybeCcaBusy:
485
// We are here because we have received the first bit of a packet and we are
486
// not going to be able to synchronize on it
487
// In this model, CCA becomes busy when the aggregation of all signals as
488
// tracked by the InterferenceHelper class is higher than the CcaBusyThreshold
489
490
Time
delayUntilCcaEnd =
m_interference
.
GetEnergyDuration
(
m_ccaMode1ThresholdW
);
491
if
(!delayUntilCcaEnd.
IsZero
())
492
{
493
m_state
->
SwitchMaybeToCcaBusy
(delayUntilCcaEnd);
494
}
495
}
496
497
void
498
YansWifiPhy::SendPacket
(
Ptr<const Packet>
packet,
WifiMode
txMode,
WifiPreamble
preamble, uint8_t txPower)
499
{
500
NS_LOG_FUNCTION
(
this
<< packet << txMode << preamble << (uint32_t)txPower);
501
/* Transmission can happen if:
502
* - we are syncing on a packet. It is the responsability of the
503
* MAC layer to avoid doing this but the PHY does nothing to
504
* prevent it.
505
* - we are idle
506
*/
507
NS_ASSERT
(!
m_state
->
IsStateTx
() && !
m_state
->
IsStateSwitching
());
508
509
Time
txDuration =
CalculateTxDuration
(packet->
GetSize
(), txMode, preamble);
510
if
(
m_state
->
IsStateRx
())
511
{
512
m_endRxEvent
.
Cancel
();
513
m_interference
.
NotifyRxEnd
();
514
}
515
NotifyTxBegin
(packet);
516
uint32_t dataRate500KbpsUnits = txMode.
GetDataRate
() / 500000;
517
bool
isShortPreamble = (
WIFI_PREAMBLE_SHORT
== preamble);
518
NotifyMonitorSniffTx
(packet, (uint16_t)
GetChannelFrequencyMhz
(),
GetChannelNumber
(), dataRate500KbpsUnits, isShortPreamble);
519
m_state
->
SwitchToTx
(txDuration, packet, txMode, preamble, txPower);
520
m_channel
->
Send
(
this
, packet,
GetPowerDbm
(txPower) +
m_txGainDb
, txMode, preamble);
521
}
522
523
uint32_t
524
YansWifiPhy::GetNModes
(
void
)
const
525
{
526
return
m_deviceRateSet
.size ();
527
}
528
WifiMode
529
YansWifiPhy::GetMode
(uint32_t mode)
const
530
{
531
return
m_deviceRateSet
[mode];
532
}
533
uint32_t
534
YansWifiPhy::GetNTxPower
(
void
)
const
535
{
536
return
m_nTxPower
;
537
}
538
539
void
540
YansWifiPhy::Configure80211a
(
void
)
541
{
542
NS_LOG_FUNCTION
(
this
);
543
m_channelStartingFrequency
= 5e3;
// 5.000 GHz
544
545
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate6Mbps
());
546
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate9Mbps
());
547
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate12Mbps
());
548
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate18Mbps
());
549
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate24Mbps
());
550
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate36Mbps
());
551
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate48Mbps
());
552
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate54Mbps
());
553
}
554
555
556
void
557
YansWifiPhy::Configure80211b
(
void
)
558
{
559
NS_LOG_FUNCTION
(
this
);
560
m_channelStartingFrequency
= 2407;
// 2.407 GHz
561
562
m_deviceRateSet
.push_back (
WifiPhy::GetDsssRate1Mbps
());
563
m_deviceRateSet
.push_back (
WifiPhy::GetDsssRate2Mbps
());
564
m_deviceRateSet
.push_back (
WifiPhy::GetDsssRate5_5Mbps
());
565
m_deviceRateSet
.push_back (
WifiPhy::GetDsssRate11Mbps
());
566
}
567
568
void
569
YansWifiPhy::Configure80211g
(
void
)
570
{
571
NS_LOG_FUNCTION
(
this
);
572
m_channelStartingFrequency
= 2407;
// 2.407 GHz
573
574
m_deviceRateSet
.push_back (
WifiPhy::GetDsssRate1Mbps
());
575
m_deviceRateSet
.push_back (
WifiPhy::GetDsssRate2Mbps
());
576
m_deviceRateSet
.push_back (
WifiPhy::GetDsssRate5_5Mbps
());
577
m_deviceRateSet
.push_back (
WifiPhy::GetErpOfdmRate6Mbps
());
578
m_deviceRateSet
.push_back (
WifiPhy::GetErpOfdmRate9Mbps
());
579
m_deviceRateSet
.push_back (
WifiPhy::GetDsssRate11Mbps
());
580
m_deviceRateSet
.push_back (
WifiPhy::GetErpOfdmRate12Mbps
());
581
m_deviceRateSet
.push_back (
WifiPhy::GetErpOfdmRate18Mbps
());
582
m_deviceRateSet
.push_back (
WifiPhy::GetErpOfdmRate24Mbps
());
583
m_deviceRateSet
.push_back (
WifiPhy::GetErpOfdmRate36Mbps
());
584
m_deviceRateSet
.push_back (
WifiPhy::GetErpOfdmRate48Mbps
());
585
m_deviceRateSet
.push_back (
WifiPhy::GetErpOfdmRate54Mbps
());
586
}
587
588
void
589
YansWifiPhy::Configure80211_10Mhz
(
void
)
590
{
591
NS_LOG_FUNCTION
(
this
);
592
m_channelStartingFrequency
= 5e3;
// 5.000 GHz, suppose 802.11a
593
594
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate3MbpsBW10MHz
());
595
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate4_5MbpsBW10MHz
());
596
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate6MbpsBW10MHz
());
597
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate9MbpsBW10MHz
());
598
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate12MbpsBW10MHz
());
599
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate18MbpsBW10MHz
());
600
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate24MbpsBW10MHz
());
601
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate27MbpsBW10MHz
());
602
}
603
604
void
605
YansWifiPhy::Configure80211_5Mhz
(
void
)
606
{
607
NS_LOG_FUNCTION
(
this
);
608
m_channelStartingFrequency
= 5e3;
// 5.000 GHz, suppose 802.11a
609
610
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate1_5MbpsBW5MHz
());
611
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate2_25MbpsBW5MHz
());
612
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate3MbpsBW5MHz
());
613
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate4_5MbpsBW5MHz
());
614
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate6MbpsBW5MHz
());
615
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate9MbpsBW5MHz
());
616
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate12MbpsBW5MHz
());
617
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate13_5MbpsBW5MHz
());
618
}
619
620
void
621
YansWifiPhy::ConfigureHolland
(
void
)
622
{
623
NS_LOG_FUNCTION
(
this
);
624
m_channelStartingFrequency
= 5e3;
// 5.000 GHz
625
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate6Mbps
());
626
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate12Mbps
());
627
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate18Mbps
());
628
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate36Mbps
());
629
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate54Mbps
());
630
}
631
632
void
633
YansWifiPhy::Configure80211p_CCH
(
void
)
634
{
635
NS_LOG_FUNCTION
(
this
);
636
m_channelStartingFrequency
= 5e3;
// 802.11p works over the 5Ghz freq range
637
638
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate3MbpsBW10MHz
());
639
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate4_5MbpsBW10MHz
());
640
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate6MbpsBW10MHz
());
641
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate9MbpsBW10MHz
());
642
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate12MbpsBW10MHz
());
643
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate18MbpsBW10MHz
());
644
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate24MbpsBW10MHz
());
645
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate27MbpsBW10MHz
());
646
}
647
648
void
649
YansWifiPhy::Configure80211p_SCH
(
void
)
650
{
651
NS_LOG_FUNCTION
(
this
);
652
m_channelStartingFrequency
= 5e3;
// 802.11p works over the 5Ghz freq range
653
654
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate3MbpsBW10MHz
());
655
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate4_5MbpsBW10MHz
());
656
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate6MbpsBW10MHz
());
657
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate9MbpsBW10MHz
());
658
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate12MbpsBW10MHz
());
659
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate18MbpsBW10MHz
());
660
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate24MbpsBW10MHz
());
661
m_deviceRateSet
.push_back (
WifiPhy::GetOfdmRate27MbpsBW10MHz
());
662
}
663
664
void
665
YansWifiPhy::RegisterListener
(
WifiPhyListener
*listener)
666
{
667
m_state
->
RegisterListener
(listener);
668
}
669
670
bool
671
YansWifiPhy::IsStateCcaBusy
(
void
)
672
{
673
return
m_state
->
IsStateCcaBusy
();
674
}
675
676
bool
677
YansWifiPhy::IsStateIdle
(
void
)
678
{
679
return
m_state
->
IsStateIdle
();
680
}
681
bool
682
YansWifiPhy::IsStateBusy
(
void
)
683
{
684
return
m_state
->
IsStateBusy
();
685
}
686
bool
687
YansWifiPhy::IsStateRx
(
void
)
688
{
689
return
m_state
->
IsStateRx
();
690
}
691
bool
692
YansWifiPhy::IsStateTx
(
void
)
693
{
694
return
m_state
->
IsStateTx
();
695
}
696
bool
697
YansWifiPhy::IsStateSwitching
(
void
)
698
{
699
return
m_state
->
IsStateSwitching
();
700
}
701
702
Time
703
YansWifiPhy::GetStateDuration
(
void
)
704
{
705
return
m_state
->
GetStateDuration
();
706
}
707
Time
708
YansWifiPhy::GetDelayUntilIdle
(
void
)
709
{
710
return
m_state
->
GetDelayUntilIdle
();
711
}
712
713
Time
714
YansWifiPhy::GetLastRxStartTime
(
void
)
const
715
{
716
return
m_state
->
GetLastRxStartTime
();
717
}
718
719
double
720
YansWifiPhy::DbToRatio
(
double
dB)
const
721
{
722
double
ratio = std::pow (10.0, dB / 10.0);
723
return
ratio;
724
}
725
726
double
727
YansWifiPhy::DbmToW
(
double
dBm)
const
728
{
729
double
mW = std::pow (10.0, dBm / 10.0);
730
return
mW / 1000.0;
731
}
732
733
double
734
YansWifiPhy::WToDbm
(
double
w
)
const
735
{
736
return
10.0 * std::log10 (w * 1000.0);
737
}
738
739
double
740
YansWifiPhy::RatioToDb
(
double
ratio)
const
741
{
742
return
10.0 * std::log10 (ratio);
743
}
744
745
double
746
YansWifiPhy::GetEdThresholdW
(
void
)
const
747
{
748
return
m_edThresholdW
;
749
}
750
751
double
752
YansWifiPhy::GetPowerDbm
(uint8_t power)
const
753
{
754
NS_ASSERT
(
m_txPowerBaseDbm
<=
m_txPowerEndDbm
);
755
NS_ASSERT
(
m_nTxPower
> 0);
756
double
dbm;
757
if
(
m_nTxPower
> 1)
758
{
759
dbm =
m_txPowerBaseDbm
+ power * (
m_txPowerEndDbm
-
m_txPowerBaseDbm
) / (
m_nTxPower
- 1);
760
}
761
else
762
{
763
NS_ASSERT_MSG
(
m_txPowerBaseDbm
==
m_txPowerEndDbm
,
"cannot have TxPowerEnd != TxPowerStart with TxPowerLevels == 1"
);
764
dbm =
m_txPowerBaseDbm
;
765
}
766
return
dbm;
767
}
768
769
void
770
YansWifiPhy::EndReceive
(
Ptr<Packet>
packet,
Ptr<InterferenceHelper::Event>
event)
771
{
772
NS_LOG_FUNCTION
(
this
<< packet << event);
773
NS_ASSERT
(
IsStateRx
());
774
NS_ASSERT
(event->GetEndTime () ==
Simulator::Now
());
775
776
struct
InterferenceHelper::SnrPer
snrPer;
777
snrPer =
m_interference
.
CalculateSnrPer
(event);
778
m_interference
.
NotifyRxEnd
();
779
780
NS_LOG_DEBUG
(
"mode="
<< (event->GetPayloadMode ().GetDataRate ()) <<
781
", snr="
<< snrPer.snr <<
", per="
<< snrPer.per <<
", size="
<< packet->
GetSize
());
782
if
(
m_random
->
GetValue
() > snrPer.per)
783
{
784
NotifyRxEnd
(packet);
785
uint32_t dataRate500KbpsUnits =
event
->GetPayloadMode ().GetDataRate () / 500000;
786
bool
isShortPreamble = (
WIFI_PREAMBLE_SHORT
==
event
->GetPreambleType ());
787
double
signalDbm =
RatioToDb
(event->GetRxPowerW ()) + 30;
788
double
noiseDbm =
RatioToDb
(event->GetRxPowerW () / snrPer.snr) -
GetRxNoiseFigure
() + 30;
789
NotifyMonitorSniffRx
(packet, (uint16_t)
GetChannelFrequencyMhz
(),
GetChannelNumber
(), dataRate500KbpsUnits, isShortPreamble, signalDbm, noiseDbm);
790
m_state
->
SwitchFromRxEndOk
(packet, snrPer.snr, event->GetPayloadMode (),
event
->GetPreambleType ());
791
}
792
else
793
{
794
/* failure. */
795
NotifyRxDrop
(packet);
796
m_state
->
SwitchFromRxEndError
(packet, snrPer.snr);
797
}
798
}
799
800
int64_t
801
YansWifiPhy::AssignStreams
(int64_t stream)
802
{
803
NS_LOG_FUNCTION
(
this
<< stream);
804
m_random
->
SetStream
(stream);
805
return
1;
806
}
807
}
// namespace ns3
src
wifi
model
yans-wifi-phy.cc
Generated on Tue May 14 2013 11:08:36 for ns-3 by
1.8.1.2