|
|
| 33 |
#include "ns3/log.h" |
33 |
#include "ns3/log.h" |
| 34 |
#include "ns3/double.h" |
34 |
#include "ns3/double.h" |
| 35 |
#include "ns3/boolean.h" |
35 |
#include "ns3/boolean.h" |
| 36 |
#include "ampdu-tag.h" |
|
|
| 37 |
#include "wifi-spectrum-signal-parameters.h" |
36 |
#include "wifi-spectrum-signal-parameters.h" |
| 38 |
#include "wifi-phy-tag.h" |
|
|
| 39 |
#include "ns3/antenna-model.h" |
37 |
#include "ns3/antenna-model.h" |
| 40 |
#include <cmath> |
38 |
#include "wifi-utils.h" |
| 41 |
|
39 |
|
| 42 |
namespace ns3 { |
40 |
namespace ns3 { |
| 43 |
|
41 |
|
|
|
| 98 |
} |
96 |
} |
| 99 |
} |
97 |
} |
| 100 |
|
98 |
|
| 101 |
bool |
|
|
| 102 |
SpectrumWifiPhy::DoChannelSwitch (uint16_t nch) |
| 103 |
{ |
| 104 |
if (IsInitialized () == false) |
| 105 |
{ |
| 106 |
//this is not channel switch, this is initialization |
| 107 |
NS_LOG_DEBUG ("start at channel " << nch); |
| 108 |
return true; |
| 109 |
} |
| 110 |
|
| 111 |
NS_ASSERT (!IsStateSwitching ()); |
| 112 |
switch (m_state->GetState ()) |
| 113 |
{ |
| 114 |
case SpectrumWifiPhy::RX: |
| 115 |
NS_LOG_DEBUG ("drop packet because of channel switching while reception"); |
| 116 |
m_endPlcpRxEvent.Cancel (); |
| 117 |
m_endRxEvent.Cancel (); |
| 118 |
goto switchChannel; |
| 119 |
break; |
| 120 |
case SpectrumWifiPhy::TX: |
| 121 |
NS_LOG_DEBUG ("channel switching postponed until end of current transmission"); |
| 122 |
Simulator::Schedule (GetDelayUntilIdle (), &WifiPhy::SetChannelNumber, this, nch); |
| 123 |
break; |
| 124 |
case SpectrumWifiPhy::CCA_BUSY: |
| 125 |
case SpectrumWifiPhy::IDLE: |
| 126 |
goto switchChannel; |
| 127 |
break; |
| 128 |
case SpectrumWifiPhy::SLEEP: |
| 129 |
NS_LOG_DEBUG ("channel switching ignored in sleep mode"); |
| 130 |
break; |
| 131 |
default: |
| 132 |
NS_ASSERT (false); |
| 133 |
break; |
| 134 |
} |
| 135 |
|
| 136 |
return false; |
| 137 |
|
| 138 |
switchChannel: |
| 139 |
|
| 140 |
NS_LOG_DEBUG ("switching channel " << GetChannelNumber () << " -> " << nch); |
| 141 |
m_rxSpectrumModel = WifiSpectrumValueHelper::GetSpectrumModel (GetFrequency (), GetChannelWidth ()); |
| 142 |
m_state->SwitchToChannelSwitching (GetChannelSwitchDelay ()); |
| 143 |
m_interference.EraseEvents (); |
| 144 |
/* |
| 145 |
* Needed here to be able to correctly sensed the medium for the first |
| 146 |
* time after the switching. The actual switching is not performed until |
| 147 |
* after m_channelSwitchDelay. Packets received during the switching |
| 148 |
* state are added to the event list and are employed later to figure |
| 149 |
* out the state of the medium after the switching. |
| 150 |
*/ |
| 151 |
return true; |
| 152 |
} |
| 153 |
|
| 154 |
bool |
| 155 |
SpectrumWifiPhy::DoFrequencySwitch (uint32_t frequency) |
| 156 |
{ |
| 157 |
if (IsInitialized () == false) |
| 158 |
{ |
| 159 |
//this is not channel switch, this is initialization |
| 160 |
NS_LOG_DEBUG ("start at frequency " << frequency); |
| 161 |
return true; |
| 162 |
} |
| 163 |
|
| 164 |
NS_ASSERT (!IsStateSwitching ()); |
| 165 |
switch (m_state->GetState ()) |
| 166 |
{ |
| 167 |
case SpectrumWifiPhy::RX: |
| 168 |
NS_LOG_DEBUG ("drop packet because of channel/frequency switching while reception"); |
| 169 |
m_endPlcpRxEvent.Cancel (); |
| 170 |
m_endRxEvent.Cancel (); |
| 171 |
goto switchFrequency; |
| 172 |
break; |
| 173 |
case SpectrumWifiPhy::TX: |
| 174 |
NS_LOG_DEBUG ("channel/frequency switching postponed until end of current transmission"); |
| 175 |
Simulator::Schedule (GetDelayUntilIdle (), &WifiPhy::SetFrequency, this, frequency); |
| 176 |
break; |
| 177 |
case SpectrumWifiPhy::CCA_BUSY: |
| 178 |
case SpectrumWifiPhy::IDLE: |
| 179 |
goto switchFrequency; |
| 180 |
break; |
| 181 |
case SpectrumWifiPhy::SLEEP: |
| 182 |
NS_LOG_DEBUG ("frequency switching ignored in sleep mode"); |
| 183 |
break; |
| 184 |
default: |
| 185 |
NS_ASSERT (false); |
| 186 |
break; |
| 187 |
} |
| 188 |
|
| 189 |
return false; |
| 190 |
|
| 191 |
switchFrequency: |
| 192 |
|
| 193 |
NS_LOG_DEBUG ("switching frequency " << GetFrequency () << " -> " << frequency); |
| 194 |
m_rxSpectrumModel = WifiSpectrumValueHelper::GetSpectrumModel (GetFrequency (), GetChannelWidth ()); |
| 195 |
m_state->SwitchToChannelSwitching (GetChannelSwitchDelay ()); |
| 196 |
m_interference.EraseEvents (); |
| 197 |
/* |
| 198 |
* Needed here to be able to correctly sensed the medium for the first |
| 199 |
* time after the switching. The actual switching is not performed until |
| 200 |
* after m_channelSwitchDelay. Packets received during the switching |
| 201 |
* state are added to the event list and are employed later to figure |
| 202 |
* out the state of the medium after the switching. |
| 203 |
*/ |
| 204 |
return true; |
| 205 |
} |
| 206 |
|
| 207 |
Ptr<const SpectrumModel> |
99 |
Ptr<const SpectrumModel> |
| 208 |
SpectrumWifiPhy::GetRxSpectrumModel () const |
100 |
SpectrumWifiPhy::GetRxSpectrumModel () const |
| 209 |
{ |
101 |
{ |
|
|
| 241 |
} |
133 |
} |
| 242 |
|
134 |
|
| 243 |
void |
135 |
void |
| 244 |
SpectrumWifiPhy::SetPacketReceivedCallback (RxCallback callback) |
|
|
| 245 |
{ |
| 246 |
m_rxCallback = callback; |
| 247 |
} |
| 248 |
|
| 249 |
void |
| 250 |
SpectrumWifiPhy::AddOperationalChannel (uint16_t channelNumber) |
136 |
SpectrumWifiPhy::AddOperationalChannel (uint16_t channelNumber) |
| 251 |
{ |
137 |
{ |
| 252 |
m_operationalChannelList.push_back (channelNumber); |
138 |
m_operationalChannelList.push_back (channelNumber); |
|
|
| 274 |
} |
160 |
} |
| 275 |
|
161 |
|
| 276 |
void |
162 |
void |
| 277 |
SpectrumWifiPhy::SetSleepMode (void) |
|
|
| 278 |
{ |
| 279 |
NS_LOG_FUNCTION (this); |
| 280 |
switch (m_state->GetState ()) |
| 281 |
{ |
| 282 |
case SpectrumWifiPhy::TX: |
| 283 |
NS_LOG_DEBUG ("setting sleep mode postponed until end of current transmission"); |
| 284 |
Simulator::Schedule (GetDelayUntilIdle (), &SpectrumWifiPhy::SetSleepMode, this); |
| 285 |
break; |
| 286 |
case SpectrumWifiPhy::RX: |
| 287 |
NS_LOG_DEBUG ("setting sleep mode postponed until end of current reception"); |
| 288 |
Simulator::Schedule (GetDelayUntilIdle (), &SpectrumWifiPhy::SetSleepMode, this); |
| 289 |
break; |
| 290 |
case SpectrumWifiPhy::SWITCHING: |
| 291 |
NS_LOG_DEBUG ("setting sleep mode postponed until end of channel switching"); |
| 292 |
Simulator::Schedule (GetDelayUntilIdle (), &SpectrumWifiPhy::SetSleepMode, this); |
| 293 |
break; |
| 294 |
case SpectrumWifiPhy::CCA_BUSY: |
| 295 |
case SpectrumWifiPhy::IDLE: |
| 296 |
NS_LOG_DEBUG ("setting sleep mode"); |
| 297 |
m_state->SwitchToSleep (); |
| 298 |
break; |
| 299 |
case SpectrumWifiPhy::SLEEP: |
| 300 |
NS_LOG_DEBUG ("already in sleep mode"); |
| 301 |
break; |
| 302 |
default: |
| 303 |
NS_ASSERT (false); |
| 304 |
break; |
| 305 |
} |
| 306 |
} |
| 307 |
|
| 308 |
void |
| 309 |
SpectrumWifiPhy::ResumeFromSleep (void) |
| 310 |
{ |
| 311 |
NS_LOG_FUNCTION (this); |
| 312 |
switch (m_state->GetState ()) |
| 313 |
{ |
| 314 |
case SpectrumWifiPhy::TX: |
| 315 |
case SpectrumWifiPhy::RX: |
| 316 |
case SpectrumWifiPhy::IDLE: |
| 317 |
case SpectrumWifiPhy::CCA_BUSY: |
| 318 |
case SpectrumWifiPhy::SWITCHING: |
| 319 |
{ |
| 320 |
NS_LOG_DEBUG ("not in sleep mode, there is nothing to resume"); |
| 321 |
break; |
| 322 |
} |
| 323 |
case SpectrumWifiPhy::SLEEP: |
| 324 |
{ |
| 325 |
NS_LOG_DEBUG ("resuming from sleep mode"); |
| 326 |
Time delayUntilCcaEnd = m_interference.GetEnergyDuration (DbmToW (GetCcaMode1Threshold ())); |
| 327 |
m_state->SwitchFromSleep (delayUntilCcaEnd); |
| 328 |
break; |
| 329 |
} |
| 330 |
default: |
| 331 |
{ |
| 332 |
NS_ASSERT (false); |
| 333 |
break; |
| 334 |
} |
| 335 |
} |
| 336 |
} |
| 337 |
|
| 338 |
void |
| 339 |
SpectrumWifiPhy::SetReceiveOkCallback (RxOkCallback callback) |
| 340 |
{ |
| 341 |
m_state->SetReceiveOkCallback (callback); |
| 342 |
} |
| 343 |
|
| 344 |
void |
| 345 |
SpectrumWifiPhy::SetReceiveErrorCallback (RxErrorCallback callback) |
| 346 |
{ |
| 347 |
m_state->SetReceiveErrorCallback (callback); |
| 348 |
} |
| 349 |
|
| 350 |
void |
| 351 |
SpectrumWifiPhy::StartRx (Ptr<SpectrumSignalParameters> rxParams) |
163 |
SpectrumWifiPhy::StartRx (Ptr<SpectrumSignalParameters> rxParams) |
| 352 |
{ |
164 |
{ |
| 353 |
NS_LOG_FUNCTION (this << rxParams); |
165 |
NS_LOG_FUNCTION (this << rxParams); |
|
|
| 391 |
|
203 |
|
| 392 |
NS_LOG_INFO ("Received Wi-Fi signal"); |
204 |
NS_LOG_INFO ("Received Wi-Fi signal"); |
| 393 |
Ptr<Packet> packet = wifiRxParams->packet->Copy (); |
205 |
Ptr<Packet> packet = wifiRxParams->packet->Copy (); |
| 394 |
WifiPhyTag tag; |
206 |
StartReceivePreambleAndHeader (packet, rxPowerW, rxDuration); |
| 395 |
bool found = packet->PeekPacketTag (tag); |
|
|
| 396 |
if (!found) |
| 397 |
{ |
| 398 |
NS_FATAL_ERROR ("Received Wi-Fi Spectrum Signal with no WifiPhyTag"); |
| 399 |
return; |
| 400 |
} |
| 401 |
|
| 402 |
WifiTxVector txVector = tag.GetWifiTxVector (); |
| 403 |
|
| 404 |
if (txVector.GetMode ().GetModulationClass () == WIFI_MOD_CLASS_HT |
| 405 |
&& (txVector.GetNss () != (1 + (txVector.GetMode ().GetMcsValue () / 8)))) |
| 406 |
{ |
| 407 |
NS_FATAL_ERROR ("MCS value does not match NSS value: MCS = " << (uint16_t)txVector.GetMode ().GetMcsValue () << ", NSS = " << (uint16_t)txVector.GetNss ()); |
| 408 |
} |
| 409 |
|
| 410 |
if (txVector.GetNss () > GetMaxSupportedRxSpatialStreams ()) |
| 411 |
{ |
| 412 |
NS_FATAL_ERROR ("Reception ends in failure because of an unsupported number of spatial streams"); |
| 413 |
} |
| 414 |
|
| 415 |
WifiPreamble preamble = txVector.GetPreambleType (); |
| 416 |
MpduType mpdutype = tag.GetMpduType (); |
| 417 |
|
| 418 |
// At this point forward, processing parallels that of |
| 419 |
// YansWifiPhy::StartReceivePreambleAndHeader () |
| 420 |
|
| 421 |
AmpduTag ampduTag; |
| 422 |
Time endRx = Simulator::Now () + rxDuration; |
| 423 |
Time preambleAndHeaderDuration = CalculatePlcpPreambleAndHeaderDuration (txVector); |
| 424 |
|
| 425 |
Ptr<InterferenceHelper::Event> event; |
| 426 |
event = m_interference.Add (packet->GetSize (), |
| 427 |
txVector, |
| 428 |
rxDuration, |
| 429 |
rxPowerW); |
| 430 |
|
| 431 |
switch (m_state->GetState ()) |
| 432 |
{ |
| 433 |
case SpectrumWifiPhy::SWITCHING: |
| 434 |
NS_LOG_DEBUG ("drop packet because of channel switching"); |
| 435 |
NotifyRxDrop (packet); |
| 436 |
m_plcpSuccess = false; |
| 437 |
/* |
| 438 |
* Packets received on the upcoming channel are added to the event list |
| 439 |
* during the switching state. This way the medium can be correctly sensed |
| 440 |
* when the device listens to the channel for the first time after the |
| 441 |
* switching e.g. after channel switching, the channel may be sensed as |
| 442 |
* busy due to other devices' tramissions started before the end of |
| 443 |
* the switching. |
| 444 |
*/ |
| 445 |
if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ()) |
| 446 |
{ |
| 447 |
//that packet will be noise _after_ the completion of the |
| 448 |
//channel switching. |
| 449 |
SwitchMaybeToCcaBusy (); |
| 450 |
return; |
| 451 |
} |
| 452 |
break; |
| 453 |
case SpectrumWifiPhy::RX: |
| 454 |
NS_LOG_DEBUG ("drop packet because already in Rx (power=" << |
| 455 |
rxPowerW << "W)"); |
| 456 |
NotifyRxDrop (packet); |
| 457 |
if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ()) |
| 458 |
{ |
| 459 |
//that packet will be noise _after_ the reception of the |
| 460 |
//currently-received packet. |
| 461 |
SwitchMaybeToCcaBusy (); |
| 462 |
return; |
| 463 |
} |
| 464 |
break; |
| 465 |
case SpectrumWifiPhy::TX: |
| 466 |
NS_LOG_DEBUG ("drop packet because already in Tx (power=" << |
| 467 |
rxPowerW << "W)"); |
| 468 |
NotifyRxDrop (packet); |
| 469 |
if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ()) |
| 470 |
{ |
| 471 |
//that packet will be noise _after_ the transmission of the |
| 472 |
//currently-transmitted packet. |
| 473 |
SwitchMaybeToCcaBusy (); |
| 474 |
return; |
| 475 |
} |
| 476 |
break; |
| 477 |
case SpectrumWifiPhy::CCA_BUSY: |
| 478 |
case SpectrumWifiPhy::IDLE: |
| 479 |
if (rxPowerW > GetEdThresholdW ()) //checked here, no need to check in the payload reception (current implementation assumes constant rx power over the packet duration) |
| 480 |
{ |
| 481 |
if (preamble == WIFI_PREAMBLE_NONE && m_mpdusNum == 0) |
| 482 |
{ |
| 483 |
NS_LOG_DEBUG ("drop packet because no preamble has been received"); |
| 484 |
NotifyRxDrop (packet); |
| 485 |
SwitchMaybeToCcaBusy (); |
| 486 |
return; |
| 487 |
} |
| 488 |
else if (preamble == WIFI_PREAMBLE_NONE && m_plcpSuccess == false) //A-MPDU reception fails |
| 489 |
{ |
| 490 |
NS_LOG_DEBUG ("Drop MPDU because no plcp has been received"); |
| 491 |
NotifyRxDrop (packet); |
| 492 |
SwitchMaybeToCcaBusy (); |
| 493 |
return; |
| 494 |
} |
| 495 |
else if (preamble != WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum == 0) |
| 496 |
{ |
| 497 |
//received the first MPDU in an MPDU |
| 498 |
m_mpdusNum = ampduTag.GetRemainingNbOfMpdus () - 1; |
| 499 |
m_rxMpduReferenceNumber++; |
| 500 |
} |
| 501 |
else if (preamble == WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum > 0) |
| 502 |
{ |
| 503 |
//received the other MPDUs that are part of the A-MPDU |
| 504 |
if (ampduTag.GetRemainingNbOfMpdus () < m_mpdusNum) |
| 505 |
{ |
| 506 |
NS_LOG_DEBUG ("Missing MPDU from the A-MPDU " << m_mpdusNum - ampduTag.GetRemainingNbOfMpdus ()); |
| 507 |
m_mpdusNum = ampduTag.GetRemainingNbOfMpdus (); |
| 508 |
} |
| 509 |
else |
| 510 |
{ |
| 511 |
m_mpdusNum--; |
| 512 |
} |
| 513 |
} |
| 514 |
else if (preamble != WIFI_PREAMBLE_NONE && m_mpdusNum > 0 ) |
| 515 |
{ |
| 516 |
NS_LOG_DEBUG ("Didn't receive the last MPDUs from an A-MPDU " << m_mpdusNum); |
| 517 |
m_mpdusNum = 0; |
| 518 |
} |
| 519 |
|
| 520 |
NS_LOG_DEBUG ("sync to signal (power=" << rxPowerW << "W)"); |
| 521 |
//sync to signal |
| 522 |
m_state->SwitchToRx (rxDuration); |
| 523 |
NS_ASSERT (m_endPlcpRxEvent.IsExpired ()); |
| 524 |
NotifyRxBegin (packet); |
| 525 |
m_interference.NotifyRxStart (); |
| 526 |
|
| 527 |
if (preamble != WIFI_PREAMBLE_NONE) |
| 528 |
{ |
| 529 |
NS_ASSERT (m_endPlcpRxEvent.IsExpired ()); |
| 530 |
m_endPlcpRxEvent = Simulator::Schedule (preambleAndHeaderDuration, &SpectrumWifiPhy::StartReceivePacket, this, |
| 531 |
packet, txVector, mpdutype, event); |
| 532 |
} |
| 533 |
|
| 534 |
NS_ASSERT (m_endRxEvent.IsExpired ()); |
| 535 |
m_endRxEvent = Simulator::Schedule (rxDuration, &SpectrumWifiPhy::EndReceive, this, |
| 536 |
packet, preamble, mpdutype, event); |
| 537 |
} |
| 538 |
else |
| 539 |
{ |
| 540 |
NS_LOG_DEBUG ("drop packet because signal power too Small (" << |
| 541 |
rxPowerW << "<" << GetEdThresholdW () << ")"); |
| 542 |
NotifyRxDrop (packet); |
| 543 |
m_plcpSuccess = false; |
| 544 |
SwitchMaybeToCcaBusy (); |
| 545 |
return; |
| 546 |
} |
| 547 |
break; |
| 548 |
case SpectrumWifiPhy::SLEEP: |
| 549 |
NS_LOG_DEBUG ("drop packet because in sleep mode"); |
| 550 |
NotifyRxDrop (packet); |
| 551 |
m_plcpSuccess = false; |
| 552 |
break; |
| 553 |
} |
| 554 |
|
| 555 |
return; |
| 556 |
} |
| 557 |
|
| 558 |
void |
| 559 |
SpectrumWifiPhy::StartReceivePacket (Ptr<Packet> packet, |
| 560 |
WifiTxVector txVector, |
| 561 |
MpduType mpdutype, |
| 562 |
Ptr<InterferenceHelper::Event> event) |
| 563 |
{ |
| 564 |
NS_LOG_FUNCTION (this << packet << txVector.GetMode () << txVector.GetPreambleType () << (uint32_t)mpdutype); |
| 565 |
NS_ASSERT (IsStateRx ()); |
| 566 |
NS_ASSERT (m_endPlcpRxEvent.IsExpired ()); |
| 567 |
AmpduTag ampduTag; |
| 568 |
WifiMode txMode = txVector.GetMode (); |
| 569 |
|
| 570 |
InterferenceHelper::SnrPer snrPer; |
| 571 |
snrPer = m_interference.CalculatePlcpHeaderSnrPer (event); |
| 572 |
|
| 573 |
NS_LOG_DEBUG ("snr(dB)=" << RatioToDb (snrPer.snr) << ", per=" << snrPer.per); |
| 574 |
|
| 575 |
if (m_random->GetValue () > snrPer.per) //plcp reception succeeded |
| 576 |
{ |
| 577 |
if (IsModeSupported (txMode) || IsMcsSupported (txMode)) |
| 578 |
{ |
| 579 |
NS_LOG_DEBUG ("receiving plcp payload"); //endReceive is already scheduled |
| 580 |
m_plcpSuccess = true; |
| 581 |
} |
| 582 |
else //mode is not allowed |
| 583 |
{ |
| 584 |
NS_LOG_DEBUG ("drop packet because it was sent using an unsupported mode (" << txMode << ")"); |
| 585 |
NotifyRxDrop (packet); |
| 586 |
m_plcpSuccess = false; |
| 587 |
} |
| 588 |
} |
| 589 |
else //plcp reception failed |
| 590 |
{ |
| 591 |
NS_LOG_DEBUG ("drop packet because plcp preamble/header reception failed"); |
| 592 |
NotifyRxDrop (packet); |
| 593 |
m_plcpSuccess = false; |
| 594 |
} |
| 595 |
} |
207 |
} |
| 596 |
|
208 |
|
| 597 |
Ptr<WifiSpectrumPhyInterface> |
209 |
Ptr<WifiSpectrumPhyInterface> |
|
|
| 652 |
} |
264 |
} |
| 653 |
|
265 |
|
| 654 |
void |
266 |
void |
| 655 |
SpectrumWifiPhy::SendPacket (Ptr<const Packet> packet, WifiTxVector txVector, MpduType mpdutype) |
267 |
SpectrumWifiPhy::StartTx (Ptr<Packet> packet, WifiTxVector txVector, Time txDuration) |
| 656 |
{ |
268 |
{ |
| 657 |
NS_LOG_FUNCTION (this << packet << txVector.GetMode () |
269 |
NS_LOG_DEBUG ("Start transmission: signal power before antenna gain=" << GetPowerDbm (txVector.GetTxPowerLevel ()) << "dBm"); |
| 658 |
<< txVector.GetMode ().GetDataRate (txVector) |
|
|
| 659 |
<< txVector.GetPreambleType () |
| 660 |
<< (uint32_t)txVector.GetTxPowerLevel () |
| 661 |
<< (uint32_t)mpdutype); |
| 662 |
/* Transmission can happen if: |
| 663 |
* - we are syncing on a packet. It is the responsability of the |
| 664 |
* MAC layer to avoid doing this but the PHY does nothing to |
| 665 |
* prevent it. |
| 666 |
* - we are idle |
| 667 |
*/ |
| 668 |
NS_ASSERT (!m_state->IsStateTx () && !m_state->IsStateSwitching ()); |
| 669 |
|
| 670 |
if (txVector.GetNss () > GetMaxSupportedTxSpatialStreams ()) |
| 671 |
{ |
| 672 |
NS_FATAL_ERROR ("Unsupported number of spatial streams!"); |
| 673 |
} |
| 674 |
|
| 675 |
if (m_state->IsStateSleep ()) |
| 676 |
{ |
| 677 |
NS_LOG_DEBUG ("Dropping packet because in sleep mode"); |
| 678 |
NotifyTxDrop (packet); |
| 679 |
return; |
| 680 |
} |
| 681 |
|
| 682 |
Time txDuration = CalculateTxDuration (packet->GetSize (), txVector, GetFrequency (), mpdutype, 1); |
| 683 |
NS_ASSERT (txDuration > NanoSeconds (0)); |
| 684 |
|
| 685 |
if (m_state->IsStateRx ()) |
| 686 |
{ |
| 687 |
m_endPlcpRxEvent.Cancel (); |
| 688 |
m_endRxEvent.Cancel (); |
| 689 |
m_interference.NotifyRxEnd (); |
| 690 |
} |
| 691 |
NotifyTxBegin (packet); |
| 692 |
if ((mpdutype == MPDU_IN_AGGREGATE) && (txVector.GetPreambleType () != WIFI_PREAMBLE_NONE)) |
| 693 |
{ |
| 694 |
//send the first MPDU in an MPDU |
| 695 |
m_txMpduReferenceNumber++; |
| 696 |
} |
| 697 |
MpduInfo aMpdu; |
| 698 |
aMpdu.type = mpdutype; |
| 699 |
aMpdu.mpduRefNumber = m_txMpduReferenceNumber; |
| 700 |
NotifyMonitorSniffTx (packet, (uint16_t) GetFrequency (), GetChannelNumber (), txVector, aMpdu); |
| 701 |
m_state->SwitchToTx (txDuration, packet, GetPowerDbm (txVector.GetTxPowerLevel ()), txVector); |
| 702 |
// |
| 703 |
// Spectrum elements added here |
| 704 |
// |
| 705 |
Ptr<Packet> newPacket = packet->Copy (); // obtain non-const Packet |
| 706 |
WifiPhyTag oldtag; |
| 707 |
newPacket->RemovePacketTag (oldtag); |
| 708 |
WifiPhyTag tag (txVector, mpdutype); |
| 709 |
newPacket->AddPacketTag (tag); |
| 710 |
|
| 711 |
NS_LOG_DEBUG ("Transmission signal power before antenna gain: " << GetPowerDbm (txVector.GetTxPowerLevel ()) << " dBm"); |
| 712 |
double txPowerWatts = DbmToW (GetPowerDbm (txVector.GetTxPowerLevel ()) + GetTxGain ()); |
270 |
double txPowerWatts = DbmToW (GetPowerDbm (txVector.GetTxPowerLevel ()) + GetTxGain ()); |
| 713 |
|
|
|
| 714 |
Ptr<SpectrumValue> txPowerSpectrum = GetTxPowerSpectralDensity (GetFrequency (), GetChannelWidth (), txPowerWatts); |
271 |
Ptr<SpectrumValue> txPowerSpectrum = GetTxPowerSpectralDensity (GetFrequency (), GetChannelWidth (), txPowerWatts); |
| 715 |
Ptr<WifiSpectrumSignalParameters> txParams = Create<WifiSpectrumSignalParameters> (); |
272 |
Ptr<WifiSpectrumSignalParameters> txParams = Create<WifiSpectrumSignalParameters> (); |
| 716 |
txParams->duration = txDuration; |
273 |
txParams->duration = txDuration; |
|
|
| 718 |
NS_ASSERT_MSG (m_wifiSpectrumPhyInterface, "SpectrumPhy() is not set; maybe forgot to call CreateWifiSpectrumPhyInterface?"); |
275 |
NS_ASSERT_MSG (m_wifiSpectrumPhyInterface, "SpectrumPhy() is not set; maybe forgot to call CreateWifiSpectrumPhyInterface?"); |
| 719 |
txParams->txPhy = m_wifiSpectrumPhyInterface->GetObject<SpectrumPhy> (); |
276 |
txParams->txPhy = m_wifiSpectrumPhyInterface->GetObject<SpectrumPhy> (); |
| 720 |
txParams->txAntenna = m_antenna; |
277 |
txParams->txAntenna = m_antenna; |
| 721 |
txParams->packet = newPacket; |
278 |
txParams->packet = packet; |
| 722 |
NS_LOG_DEBUG ("Starting transmission with power " << WToDbm (txPowerWatts) << " dBm on channel " << GetChannelNumber ()); |
279 |
NS_LOG_DEBUG ("Starting transmission with power " << WToDbm (txPowerWatts) << " dBm on channel " << GetChannelNumber ()); |
| 723 |
NS_LOG_DEBUG ("Starting transmission with integrated spectrum power " << WToDbm (Integral (*txPowerSpectrum)) << " dBm; spectrum model Uid: " << txPowerSpectrum->GetSpectrumModel ()->GetUid ()); |
280 |
NS_LOG_DEBUG ("Starting transmission with integrated spectrum power " << WToDbm (Integral (*txPowerSpectrum)) << " dBm; spectrum model Uid: " << txPowerSpectrum->GetSpectrumModel ()->GetUid ()); |
| 724 |
m_channel->StartTx (txParams); |
281 |
m_channel->StartTx (txParams); |
| 725 |
} |
282 |
} |
| 726 |
|
283 |
|
| 727 |
void |
|
|
| 728 |
SpectrumWifiPhy::RegisterListener (WifiPhyListener *listener) |
| 729 |
{ |
| 730 |
m_state->RegisterListener (listener); |
| 731 |
} |
| 732 |
|
| 733 |
void |
| 734 |
SpectrumWifiPhy::UnregisterListener (WifiPhyListener *listener) |
| 735 |
{ |
| 736 |
m_state->UnregisterListener (listener); |
| 737 |
} |
| 738 |
|
| 739 |
void |
| 740 |
SpectrumWifiPhy::EndReceive (Ptr<Packet> packet, WifiPreamble preamble, MpduType mpdutype, Ptr<InterferenceHelper::Event> event) |
| 741 |
{ |
| 742 |
NS_LOG_FUNCTION (this << packet << event); |
| 743 |
NS_ASSERT (IsStateRx ()); |
| 744 |
NS_ASSERT (event->GetEndTime () == Simulator::Now ()); |
| 745 |
|
| 746 |
InterferenceHelper::SnrPer snrPer; |
| 747 |
snrPer = m_interference.CalculatePlcpPayloadSnrPer (event); |
| 748 |
m_interference.NotifyRxEnd (); |
| 749 |
bool rxSucceeded; |
| 750 |
|
| 751 |
if (m_plcpSuccess == true) |
| 752 |
{ |
| 753 |
NS_LOG_DEBUG ("mode=" << (event->GetPayloadMode ().GetDataRate (event->GetTxVector ())) << |
| 754 |
", snr(dB)=" << RatioToDb (snrPer.snr) << ", per=" << snrPer.per << ", size=" << packet->GetSize ()); |
| 755 |
|
| 756 |
if (m_random->GetValue () > snrPer.per) |
| 757 |
{ |
| 758 |
NotifyRxEnd (packet); |
| 759 |
SignalNoiseDbm signalNoise; |
| 760 |
signalNoise.signal = RatioToDb (event->GetRxPowerW ()) + 30; |
| 761 |
signalNoise.noise = RatioToDb (event->GetRxPowerW () / snrPer.snr) - GetRxNoiseFigure () + 30; |
| 762 |
MpduInfo aMpdu; |
| 763 |
aMpdu.type = mpdutype; |
| 764 |
aMpdu.mpduRefNumber = m_rxMpduReferenceNumber; |
| 765 |
NotifyMonitorSniffRx (packet, (uint16_t) GetFrequency (), GetChannelNumber (), event->GetTxVector (), aMpdu, signalNoise); |
| 766 |
m_state->SwitchFromRxEndOk (packet, snrPer.snr, event->GetTxVector ()); |
| 767 |
rxSucceeded = true; |
| 768 |
} |
| 769 |
else |
| 770 |
{ |
| 771 |
/* failure. */ |
| 772 |
NotifyRxDrop (packet); |
| 773 |
m_state->SwitchFromRxEndError (packet, snrPer.snr); |
| 774 |
rxSucceeded = false; |
| 775 |
} |
| 776 |
if (!m_rxCallback.IsNull ()) |
| 777 |
{ |
| 778 |
m_rxCallback (rxSucceeded); |
| 779 |
} |
| 780 |
} |
| 781 |
else |
| 782 |
{ |
| 783 |
m_state->SwitchFromRxEndError (packet, snrPer.snr); |
| 784 |
if (!m_rxCallback.IsNull ()) |
| 785 |
{ |
| 786 |
m_rxCallback (false); |
| 787 |
} |
| 788 |
} |
| 789 |
|
| 790 |
if (preamble == WIFI_PREAMBLE_NONE && mpdutype == LAST_MPDU_IN_AGGREGATE) |
| 791 |
{ |
| 792 |
m_plcpSuccess = false; |
| 793 |
} |
| 794 |
|
| 795 |
} |
| 796 |
|
| 797 |
} //namespace ns3 |
284 |
} //namespace ns3 |