23 #include "ns3/simulator.h"
25 #include "ns3/pointer.h"
26 #include "ns3/mobility-model.h"
27 #include "ns3/random-variable-stream.h"
28 #include "ns3/error-model.h"
38 #include "ns3/ht-configuration.h"
39 #include "ns3/he-configuration.h"
44 #include "ns3/dsss-phy.h"
45 #include "ns3/erp-ofdm-phy.h"
46 #include "ns3/he-phy.h"
301 .SetGroupName (
"Wifi")
302 .AddAttribute (
"Frequency",
303 "The center frequency (MHz) of the operating channel. "
304 "If the operating channel for this object has not been set yet, the "
305 "value of this attribute is saved and will be used, along with the channel "
306 "number and width configured via other attributes, to set the operating "
307 "channel when the standard and band are configured. The default value of "
308 "this attribute is 0, which means unspecified center frequency. Note that "
309 "if center frequency and channel number are both 0 when the standard and "
310 "band are configured, a default channel (of the configured width, if any, "
311 "or the default width for the current standard and band, otherwise) is set. "
312 "If the operating channel for this object has been already set, the "
313 "specified center frequency must uniquely identify a channel in the "
318 MakeUintegerChecker<uint16_t> ())
319 .AddAttribute (
"ChannelNumber",
320 "The channel number of the operating channel. "
321 "If the operating channel for this object has not been set yet, the "
322 "value of this attribute is saved and will be used, along with the center "
323 "frequency and width configured via other attributes, to set the operating "
324 "channel when the standard and band are configured. The default value of "
325 "this attribute is 0, which means unspecified channel number. Note that "
326 "if center frequency and channel number are both 0 when the standard and "
327 "band are configured, a default channel (of the configured width, if any, "
328 "or the default width for the current standard and band, otherwise) is set. "
329 "If the operating channel for this object has been already set, the "
330 "specified channel number must uniquely identify a channel in the "
335 MakeUintegerChecker<uint8_t> (0, 233))
336 .AddAttribute (
"ChannelWidth",
337 "The width in MHz of the operating channel (5, 10, 20, 22, 40, 80 or 160). "
338 "If the operating channel for this object has not been set yet, the "
339 "value of this attribute is saved and will be used, along with the center "
340 "frequency and channel number configured via other attributes, to set the "
341 "operating channel when the standard and band are configured. The default value "
342 "of this attribute is 0, which means unspecified channel width. Note that "
343 "if center frequency and channel number are both 0 when the standard and "
344 "band are configured, a default channel (of the configured width, if any, "
345 "or the default width for the current standard and band, otherwise) is set. "
346 "Do not set this attribute when the standard and band of this object have "
347 "been already configured, because it cannot uniquely identify a channel in "
348 "the band being used.",
352 MakeUintegerChecker<uint16_t> (5, 160))
353 .AddAttribute (
"Primary20MHzIndex",
354 "The index of the primary 20 MHz channel within the operating channel "
355 "(0 indicates the 20 MHz subchannel with the lowest center frequency). "
356 "This attribute is only valid if the width of the operating channel is "
357 "a multiple of 20 MHz.",
360 MakeUintegerChecker<uint8_t> (0, 7))
361 .AddAttribute (
"RxSensitivity",
362 "The energy of a received signal should be higher than "
363 "this threshold (dBm) for the PHY to detect the signal. "
364 "This threshold refers to a width of 20 MHz and will be "
365 "scaled to match the width of the received signal.",
369 MakeDoubleChecker<double> ())
370 .AddAttribute (
"CcaEdThreshold",
371 "The energy of a non Wi-Fi received signal should be higher than "
372 "this threshold (dBm) to allow the PHY layer to declare CCA BUSY state. "
373 "This check is performed on the 20 MHz primary channel only.",
377 MakeDoubleChecker<double> ())
378 .AddAttribute (
"TxGain",
379 "Transmission gain (dB).",
383 MakeDoubleChecker<double> ())
384 .AddAttribute (
"RxGain",
385 "Reception gain (dB).",
389 MakeDoubleChecker<double> ())
390 .AddAttribute (
"TxPowerLevels",
391 "Number of transmission power levels available between "
392 "TxPowerStart and TxPowerEnd included.",
395 MakeUintegerChecker<uint8_t> ())
396 .AddAttribute (
"TxPowerEnd",
397 "Maximum available transmission level (dBm).",
401 MakeDoubleChecker<double> ())
402 .AddAttribute (
"TxPowerStart",
403 "Minimum available transmission level (dBm).",
407 MakeDoubleChecker<double> ())
408 .AddAttribute (
"RxNoiseFigure",
409 "Loss (dB) in the Signal-to-Noise-Ratio due to non-idealities in the receiver."
410 " According to Wikipedia (http://en.wikipedia.org/wiki/Noise_figure), this is "
411 "\"the difference in decibels (dB) between"
412 " the noise output of the actual receiver to the noise output of an "
413 " ideal receiver with the same overall gain and bandwidth when the receivers "
414 " are connected to sources at the standard noise temperature T0 (usually 290 K)\".",
417 MakeDoubleChecker<double> ())
418 .AddAttribute (
"State",
419 "The state of the PHY layer.",
422 MakePointerChecker<WifiPhyStateHelper> ())
423 .AddAttribute (
"ChannelSwitchDelay",
424 "Delay between two short frames transmitted on different frequencies.",
428 .AddAttribute (
"Antennas",
429 "The number of antennas on the device.",
433 MakeUintegerChecker<uint8_t> (1, 8))
434 .AddAttribute (
"MaxSupportedTxSpatialStreams",
435 "The maximum number of supported TX spatial streams."
436 "This parameter is only valuable for 802.11n/ac/ax STAs and APs.",
440 MakeUintegerChecker<uint8_t> (1, 8))
441 .AddAttribute (
"MaxSupportedRxSpatialStreams",
442 "The maximum number of supported RX spatial streams."
443 "This parameter is only valuable for 802.11n/ac/ax STAs and APs.",
447 MakeUintegerChecker<uint8_t> (1, 8))
448 .AddAttribute (
"ShortPlcpPreambleSupported",
449 "Whether or not short PHY preamble is supported."
450 "This parameter is only valuable for 802.11b STAs and APs."
451 "Note: 802.11g APs and STAs always support short PHY preamble.",
456 .AddAttribute (
"FrameCaptureModel",
457 "Ptr to an object that implements the frame capture model",
460 MakePointerChecker <FrameCaptureModel> ())
461 .AddAttribute (
"PreambleDetectionModel",
462 "Ptr to an object that implements the preamble detection model",
465 MakePointerChecker <PreambleDetectionModel> ())
466 .AddAttribute (
"PostReceptionErrorModel",
467 "An optional packet error model can be added to the receive "
468 "packet process after any propagation-based (SNR-based) error "
469 "models have been applied. Typically this is used to force "
470 "specific packet drops, for testing purposes.",
473 MakePointerChecker<ErrorModel> ())
474 .AddAttribute (
"Sifs",
475 "The duration of the Short Interframe Space. "
476 "NOTE that the default value is overwritten by the value defined "
477 "by the standard; if you want to set this attribute, you have to "
478 "do it after that the PHY object is initialized.",
482 .AddAttribute (
"Slot",
483 "The duration of a slot. "
484 "NOTE that the default value is overwritten by the value defined "
485 "by the standard; if you want to set this attribute, you have to "
486 "do it after that the PHY object is initialized.",
490 .AddAttribute (
"Pifs",
491 "The duration of the PCF Interframe Space. "
492 "NOTE that the default value is overwritten by the value defined "
493 "by the standard; if you want to set this attribute, you have to "
494 "do it after that the PHY object is initialized.",
498 .AddAttribute (
"PowerDensityLimit",
499 "The mean equivalent isotropically radiated power density"
500 "limit (in dBm/MHz) set by regulators.",
503 MakeDoubleChecker<double> ())
504 .AddTraceSource (
"PhyTxBegin",
505 "Trace source indicating a packet "
506 "has begun transmitting over the channel medium",
508 "ns3::WifiPhy::PhyTxBeginTracedCallback")
509 .AddTraceSource (
"PhyTxPsduBegin",
510 "Trace source indicating a PSDU "
511 "has begun transmitting over the channel medium",
513 "ns3::WifiPhy::PsduTxBeginCallback")
514 .AddTraceSource (
"PhyTxEnd",
515 "Trace source indicating a packet "
516 "has been completely transmitted over the channel.",
518 "ns3::Packet::TracedCallback")
519 .AddTraceSource (
"PhyTxDrop",
520 "Trace source indicating a packet "
521 "has been dropped by the device during transmission",
523 "ns3::Packet::TracedCallback")
524 .AddTraceSource (
"PhyRxBegin",
525 "Trace source indicating a packet "
526 "has begun being received from the channel medium "
529 "ns3::WifiPhy::PhyRxBeginTracedCallback")
530 .AddTraceSource (
"PhyRxPayloadBegin",
531 "Trace source indicating the reception of the "
532 "payload of a PPDU has begun",
534 "ns3::WifiPhy::PhyRxPayloadBeginTracedCallback")
535 .AddTraceSource (
"PhyRxEnd",
536 "Trace source indicating a packet "
537 "has been completely received from the channel medium "
540 "ns3::Packet::TracedCallback")
541 .AddTraceSource (
"PhyRxDrop",
542 "Trace source indicating a packet "
543 "has been dropped by the device during reception",
545 "ns3::Packet::TracedCallback")
546 .AddTraceSource (
"MonitorSnifferRx",
547 "Trace source simulating a wifi device in monitor mode "
548 "sniffing all received frames",
550 "ns3::WifiPhy::MonitorSnifferRxTracedCallback")
551 .AddTraceSource (
"MonitorSnifferTx",
552 "Trace source simulating the capability of a wifi device "
553 "in monitor mode to sniff all frames being transmitted",
555 "ns3::WifiPhy::MonitorSnifferTxTracedCallback")
561 : m_txMpduReferenceNumber (0xffffffff),
562 m_rxMpduReferenceNumber (0xffffffff),
566 m_previouslyRxPpduUid (UINT64_MAX),
569 m_initialFrequency (0),
570 m_initialChannelNumber (0),
571 m_initialChannelWidth (0),
572 m_initialPrimary20Index (0),
577 m_blockAckTxTime (
Seconds (0)),
578 m_powerRestricted (false),
579 m_channelAccessRequested (false),
580 m_txSpatialStreams (0),
581 m_rxSpatialStreams (0),
582 m_wifiRadioEnergyModel (0),
583 m_timeLastPreambleDetected (
Seconds (0))
586 m_random = CreateObject<UniformRandomVariable> ();
587 m_state = CreateObject<WifiPhyStateHelper> ();
603 phyEntity.second->CancelAllEvents ();
617 preambleEvent.second = 0;
623 phyEntity.second = 0;
637 m_state->SetReceiveOkCallback (callback);
643 m_state->SetReceiveErrorCallback (callback);
649 m_state->RegisterListener (listener);
655 m_state->UnregisterListener (listener);
899 phyEntity->SetOwner (
this);
1022 NS_FATAL_ERROR (
"802.11p configured with a wrong channel width!");
1151 NS_LOG_DEBUG (
"Saving frequency configuration for initialization");
1182 NS_LOG_DEBUG (
"Saving channel number configuration for initialization");
1209 if (channelWidth != 0)
1218 NS_LOG_DEBUG (
"Saving channel width configuration for initialization");
1229 NS_ABORT_MSG (
"The channel width does not uniquely identify an operating channel.");
1247 NS_LOG_DEBUG (
"Saving primary20 index configuration for initialization");
1278 uint16_t prevChannelWidth = 0;
1318 NS_LOG_DEBUG (
"drop packet because of channel switching while reception");
1322 phyEntity.second->CancelAllEvents ();
1326 NS_LOG_DEBUG (
"channel switching postponed until end of current transmission");
1333 phyEntity.second->CancelAllEvents ();
1337 NS_LOG_DEBUG (
"channel switching ignored in sleep mode");
1366 NS_ASSERT_MSG (antennas > 0 && antennas <= 4,
"unsupported number of antennas");
1388 Ptr<HtPhy> htPhy = DynamicCast<HtPhy> (phyEntity->second);
1429 std::list<uint8_t>
list;
1432 Ptr<HtPhy> htPhy = DynamicCast<HtPhy> (phyEntity.second);
1435 list.emplace_back (htPhy->GetBssMembershipSelector ());
1452 NS_LOG_FUNCTION (
"Adding " << width <<
" to supported channel width set");
1456 std::vector<uint16_t>
1471 NS_LOG_DEBUG (
"setting sleep mode postponed until end of current transmission");
1475 NS_LOG_DEBUG (
"setting sleep mode postponed until end of current reception");
1479 NS_LOG_DEBUG (
"setting sleep mode postponed until end of channel switching");
1506 phyEntity.second->CancelAllEvents ();
1524 NS_LOG_DEBUG (
"not in sleep mode, there is nothing to resume");
1531 m_state->SwitchFromSleep (delayUntilCcaEnd);
1555 NS_LOG_DEBUG (
"not in off mode, there is nothing to resume");
1562 m_state->SwitchFromOff (delayUntilCcaEnd);
1588 uint32_t totalAmpduSize;
1589 double totalAmpduNumSymbols;
1590 return GetPayloadDuration (size, txVector, band, mpdutype,
false, totalAmpduSize, totalAmpduNumSymbols, staId);
1595 bool incFlag, uint32_t &totalAmpduSize,
double &totalAmpduNumSymbols,
1599 incFlag, totalAmpduSize, totalAmpduNumSymbols,
1641 for (
auto const& psdu : psdus)
1656 for (
auto const& psdu : psdus)
1716 SignalNoiseDbm signalNoise, std::vector<bool> statusPerMpdu, uint16_t staId)
1725 NS_ASSERT_MSG (statusPerMpdu.size () == nMpdus,
"Should have one reception status per MPDU");
1729 for (
size_t i = 0; i < nMpdus;)
1731 if (statusPerMpdu.at (i))
1742 NS_ASSERT_MSG (statusPerMpdu.size () == 1,
"Should have one reception status for normal MPDU");
1764 for (
size_t i = 0; i < nMpdus;)
1815 NS_LOG_DEBUG (
"Dropping packet because in sleep mode");
1816 for (
auto const& psdu : psdus)
1824 if (txVector.
IsMu ())
1835 bool noEndPreambleDetectionEvent =
true;
1838 noEndPreambleDetectionEvent &= it.second->NoEndPreambleDetectionEvents ();
1849 it.second->CancelRunningEndPreambleDetectionEvents ();
1865 NS_LOG_DEBUG (
"Transmission canceled because device is OFF");
1878 for (
auto const& psdu : psdus)
1886 ppdu->SetTruncatedTx ();
1913 phyEntity.second->CancelAllEvents ();
1924 it->second->StartReceivePreamble (ppdu, rxPowersW, rxDuration);
1929 NS_LOG_DEBUG (
"Unsupported modulation received (" << modulation <<
"), consider as noise");
1930 if (ppdu->GetTxDuration () >
m_state->GetDelayUntilIdle ())
1942 NS_ASSERT_MSG (
false,
"802.11ax can only be used with SpectrumWifiPhy");
1944 return convertedSubcarriers;
1980 if (phyEntity.second->IsModeSupported (mode))
1994 for (
const auto & mode : *(phyEntity.second))
1999 NS_ASSERT_MSG (
false,
"Should have found at least one default mode");
2011 return phyEntity->second->IsMcsSupported (mcs);
2017 std::list<WifiMode>
list;
2020 if (!phyEntity.second->HandlesMcsModes ())
2022 for (
const auto & mode : *(phyEntity.second))
2024 list.emplace_back (mode);
2034 std::list<WifiMode>
list;
2038 if (!phyEntity->second->HandlesMcsModes ())
2040 for (
const auto & mode : *(phyEntity->second))
2042 list.emplace_back (mode);
2052 uint16_t numMcs = 0;
2055 if (phyEntity.second->HandlesMcsModes ())
2057 numMcs += phyEntity.second->GetNumModes ();
2066 std::list<WifiMode>
list;
2069 if (phyEntity.second->HandlesMcsModes ())
2071 for (
const auto & mode : *(phyEntity.second))
2073 list.emplace_back (mode);
2083 std::list<WifiMode>
list;
2087 if (phyEntity->second->HandlesMcsModes ())
2089 for (
const auto & mode : *(phyEntity->second))
2091 list.emplace_back (mode);
2108 return m_state->IsStateCcaBusy ();
2114 return m_state->IsStateIdle ();
2132 return m_state->IsStateSwitching ();
2138 return m_state->IsStateSleep ();
2144 return m_state->IsStateOff ();
2150 return m_state->GetDelayUntilIdle ();
2156 return m_state->GetLastRxStartTime ();
2162 return m_state->GetLastRxEndTime ();
2174 if (!delayUntilCcaEnd.
IsZero ())
2177 m_state->SwitchMaybeToCcaBusy (delayUntilCcaEnd);
2189 phyEntity.second->CancelAllEvents ();
2203 m_state->SwitchFromRxAbort ();
2220 NS_LOG_FUNCTION (
this << powerRestricted << txPowerMaxSiso << txPowerMaxMimo);
2260 uint16_t channelWidth = ppdu->GetTransmissionChannelWidth ();
2262 NS_LOG_INFO (
"txPowerDbm=" << txPowerDbm <<
" with txPowerDbmPerMhz=" << txPowerDbmPerMhz <<
" over " << channelWidth <<
" MHz");
2273 return GetPhyEntity (ppdu->GetModulation ())->GetAddressedPsduInPpdu (ppdu);
2279 if (ppdu ==
nullptr)
2285 return GetPhyEntity (ppdu->GetModulation ())->GetMeasurementChannelWidth (ppdu);
2312 int64_t currentStream = stream;
2315 return (currentStream - stream);
2321 <<
", RSSI:" << rxSignalInfo.
rssi <<
" dBm";