A Discrete-Event Network Simulator
API
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 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19 * Sébastien Deronne <sebastien.deronne@gmail.com>
20 */
21
22#include <algorithm>
23#include "ns3/simulator.h"
24#include "ns3/log.h"
25#include "ns3/pointer.h"
26#include "ns3/string.h"
27#include "ns3/tuple.h"
28#include "ns3/mobility-model.h"
29#include "ns3/random-variable-stream.h"
30#include "ns3/error-model.h"
31#include "wifi-net-device.h"
32#include "wifi-phy.h"
33#include "wifi-utils.h"
34#include "frame-capture-model.h"
37#include "error-rate-model.h"
38#include "wifi-net-device.h"
39#include "wifi-psdu.h"
40#include "wifi-ppdu.h"
41#include "ns3/dsss-phy.h"
42#include "ns3/erp-ofdm-phy.h"
43#include "ns3/he-phy.h" //includes OFDM, HT, and VHT
44
45namespace ns3 {
46
47NS_LOG_COMPONENT_DEFINE ("WifiPhy");
48
49/****************************************************************
50 * The actual WifiPhy class
51 ****************************************************************/
52
54
55TypeId
57{
58 static TypeId tid = TypeId ("ns3::WifiPhy")
59 .SetParent<Object> ()
60 .SetGroupName ("Wifi")
61 .AddAttribute ("ChannelSettings",
62 "Tuple {channel number, channel width (MHz), PHY band, primary20 index} "
63 "describing the settings of the operating channel. The primary20 index is "
64 "the index of the primary 20 MHz channel within the operating channel "
65 "(0 indicates the 20 MHz subchannel with the lowest center frequency) and "
66 "is only valid if the width of the operating channel is a multiple of 20 MHz. "
67 "If the standard for this object has not been set yet, the value of this "
68 "attribute is saved and will be used to set the operating channel when the "
69 "standard is configured. If the PHY band is left unspecified, the default "
70 "band for the configured standard is used. If the channel width and the "
71 "channel number are both 0, the default channel width for the configured "
72 "standard and band are used. If the channel number is 0, the default "
73 "channel number for the configured standard, band and channel width is used."
74 "Note that the channel width can be left unspecified (0) if the channel "
75 "number uniquely identify a frequency channel for the given standard and band. ",
76 StringValue ("{0, 0, BAND_UNSPECIFIED, 0}"),
77 MakeTupleAccessor <UintegerValue, UintegerValue, EnumValue, UintegerValue> ((void (WifiPhy::*) (const ChannelTuple&))(&WifiPhy::SetOperatingChannel)),
78 MakeTupleChecker<UintegerValue, UintegerValue, EnumValue, UintegerValue>
79 (MakeUintegerChecker<uint8_t> (0, 233),
80 MakeUintegerChecker<uint16_t> (0, 160),
84 WifiPhyBand::WIFI_PHY_BAND_UNSPECIFIED, "BAND_UNSPECIFIED"),
85 MakeUintegerChecker<uint8_t> (0, 7)))
86 .AddAttribute ("Frequency",
87 "The center frequency (MHz) of the current operating channel.",
88 UintegerValue (0),
90 MakeUintegerChecker<uint16_t> ())
91 .AddAttribute ("ChannelNumber",
92 "The channel number of the current operating channel.",
93 UintegerValue (0),
95 MakeUintegerChecker<uint8_t> (0, 233))
96 .AddAttribute ("ChannelWidth",
97 "The width in MHz of the current operating channel (5, 10, 20, 22, 40, 80 or 160).",
98 UintegerValue (0),
100 MakeUintegerChecker<uint16_t> (5, 160))
101 .AddAttribute ("Primary20MHzIndex",
102 "The index of the primary 20 MHz channel within the current operating channel "
103 "(0 indicates the 20 MHz subchannel with the lowest center frequency).",
104 UintegerValue (0),
106 MakeUintegerChecker<uint8_t> (0, 7))
107 .AddAttribute ("RxSensitivity",
108 "The energy of a received signal should be higher than "
109 "this threshold (dBm) for the PHY to detect the signal. "
110 "This threshold refers to a width of 20 MHz and will be "
111 "scaled to match the width of the received signal.",
112 DoubleValue (-101.0),
115 MakeDoubleChecker<double> ())
116 .AddAttribute ("CcaEdThreshold",
117 "The energy of a non Wi-Fi received signal should be higher than "
118 "this threshold (dBm) to allow the PHY layer to declare CCA BUSY state. "
119 "This check is performed on the 20 MHz primary channel only.",
120 DoubleValue (-62.0),
123 MakeDoubleChecker<double> ())
124 .AddAttribute ("TxGain",
125 "Transmission gain (dB).",
126 DoubleValue (0.0),
129 MakeDoubleChecker<double> ())
130 .AddAttribute ("RxGain",
131 "Reception gain (dB).",
132 DoubleValue (0.0),
135 MakeDoubleChecker<double> ())
136 .AddAttribute ("TxPowerLevels",
137 "Number of transmission power levels available between "
138 "TxPowerStart and TxPowerEnd included.",
139 UintegerValue (1),
141 MakeUintegerChecker<uint8_t> ())
142 .AddAttribute ("TxPowerEnd",
143 "Maximum available transmission level (dBm).",
144 DoubleValue (16.0206),
147 MakeDoubleChecker<double> ())
148 .AddAttribute ("TxPowerStart",
149 "Minimum available transmission level (dBm).",
150 DoubleValue (16.0206),
153 MakeDoubleChecker<double> ())
154 .AddAttribute ("RxNoiseFigure",
155 "Loss (dB) in the Signal-to-Noise-Ratio due to non-idealities in the receiver."
156 " According to Wikipedia (http://en.wikipedia.org/wiki/Noise_figure), this is "
157 "\"the difference in decibels (dB) between"
158 " the noise output of the actual receiver to the noise output of an "
159 " ideal receiver with the same overall gain and bandwidth when the receivers "
160 " are connected to sources at the standard noise temperature T0 (usually 290 K)\".",
161 DoubleValue (7),
163 MakeDoubleChecker<double> ())
164 .AddAttribute ("State",
165 "The state of the PHY layer.",
166 PointerValue (),
168 MakePointerChecker<WifiPhyStateHelper> ())
169 .AddAttribute ("ChannelSwitchDelay",
170 "Delay between two short frames transmitted on different frequencies.",
171 TimeValue (MicroSeconds (250)),
174 .AddAttribute ("Antennas",
175 "The number of antennas on the device.",
176 UintegerValue (1),
179 MakeUintegerChecker<uint8_t> (1, 8))
180 .AddAttribute ("MaxSupportedTxSpatialStreams",
181 "The maximum number of supported TX spatial streams."
182 "This parameter is only valuable for 802.11n/ac/ax STAs and APs.",
183 UintegerValue (1),
186 MakeUintegerChecker<uint8_t> (1, 8))
187 .AddAttribute ("MaxSupportedRxSpatialStreams",
188 "The maximum number of supported RX spatial streams."
189 "This parameter is only valuable for 802.11n/ac/ax STAs and APs.",
190 UintegerValue (1),
193 MakeUintegerChecker<uint8_t> (1, 8))
194 .AddAttribute ("ShortPlcpPreambleSupported",
195 "Whether or not short PHY preamble is supported."
196 "This parameter is only valuable for 802.11b STAs and APs."
197 "Note: 802.11g APs and STAs always support short PHY preamble.",
198 BooleanValue (false),
202 .AddAttribute ("FrameCaptureModel",
203 "Ptr to an object that implements the frame capture model",
204 PointerValue (),
206 MakePointerChecker <FrameCaptureModel> ())
207 .AddAttribute ("PreambleDetectionModel",
208 "Ptr to an object that implements the preamble detection model",
209 PointerValue (),
211 MakePointerChecker <PreambleDetectionModel> ())
212 .AddAttribute ("PostReceptionErrorModel",
213 "An optional packet error model can be added to the receive "
214 "packet process after any propagation-based (SNR-based) error "
215 "models have been applied. Typically this is used to force "
216 "specific packet drops, for testing purposes.",
217 PointerValue (),
219 MakePointerChecker<ErrorModel> ())
220 .AddAttribute ("Sifs",
221 "The duration of the Short Interframe Space. "
222 "NOTE that the default value is overwritten by the value defined "
223 "by the standard; if you want to set this attribute, you have to "
224 "do it after that the PHY object is initialized.",
228 .AddAttribute ("Slot",
229 "The duration of a slot. "
230 "NOTE that the default value is overwritten by the value defined "
231 "by the standard; if you want to set this attribute, you have to "
232 "do it after that the PHY object is initialized.",
236 .AddAttribute ("Pifs",
237 "The duration of the PCF Interframe Space. "
238 "NOTE that the default value is overwritten by the value defined "
239 "by the standard; if you want to set this attribute, you have to "
240 "do it after that the PHY object is initialized.",
244 .AddAttribute ("PowerDensityLimit",
245 "The mean equivalent isotropically radiated power density"
246 "limit (in dBm/MHz) set by regulators.",
247 DoubleValue (100.0), //set to a high value so as to have no effect
249 MakeDoubleChecker<double> ())
250 .AddTraceSource ("PhyTxBegin",
251 "Trace source indicating a packet "
252 "has begun transmitting over the channel medium",
254 "ns3::WifiPhy::PhyTxBeginTracedCallback")
255 .AddTraceSource ("PhyTxPsduBegin",
256 "Trace source indicating a PSDU "
257 "has begun transmitting over the channel medium",
259 "ns3::WifiPhy::PsduTxBeginCallback")
260 .AddTraceSource ("PhyTxEnd",
261 "Trace source indicating a packet "
262 "has been completely transmitted over the channel.",
264 "ns3::Packet::TracedCallback")
265 .AddTraceSource ("PhyTxDrop",
266 "Trace source indicating a packet "
267 "has been dropped by the device during transmission",
269 "ns3::Packet::TracedCallback")
270 .AddTraceSource ("PhyRxBegin",
271 "Trace source indicating a packet "
272 "has begun being received from the channel medium "
273 "by the device",
275 "ns3::WifiPhy::PhyRxBeginTracedCallback")
276 .AddTraceSource ("PhyRxPayloadBegin",
277 "Trace source indicating the reception of the "
278 "payload of a PPDU has begun",
280 "ns3::WifiPhy::PhyRxPayloadBeginTracedCallback")
281 .AddTraceSource ("PhyRxEnd",
282 "Trace source indicating a packet "
283 "has been completely received from the channel medium "
284 "by the device",
286 "ns3::Packet::TracedCallback")
287 .AddTraceSource ("PhyRxDrop",
288 "Trace source indicating a packet "
289 "has been dropped by the device during reception",
291 "ns3::Packet::TracedCallback")
292 .AddTraceSource ("MonitorSnifferRx",
293 "Trace source simulating a wifi device in monitor mode "
294 "sniffing all received frames",
296 "ns3::WifiPhy::MonitorSnifferRxTracedCallback")
297 .AddTraceSource ("MonitorSnifferTx",
298 "Trace source simulating the capability of a wifi device "
299 "in monitor mode to sniff all frames being transmitted",
301 "ns3::WifiPhy::MonitorSnifferTxTracedCallback")
302 ;
303 return tid;
304}
305
307 : m_txMpduReferenceNumber (0xffffffff),
308 m_rxMpduReferenceNumber (0xffffffff),
309 m_endPhyRxEvent (),
310 m_endTxEvent (),
311 m_currentEvent (0),
312 m_previouslyRxPpduUid (UINT64_MAX),
313 m_standard (WIFI_STANDARD_UNSPECIFIED),
315 m_sifs (Seconds (0)),
316 m_slot (Seconds (0)),
317 m_pifs (Seconds (0)),
318 m_ackTxTime (Seconds (0)),
319 m_blockAckTxTime (Seconds (0)),
320 m_powerRestricted (false),
321 m_channelAccessRequested (false),
322 m_txSpatialStreams (0),
323 m_rxSpatialStreams (0),
324 m_wifiRadioEnergyModel (0),
325 m_timeLastPreambleDetected (Seconds (0))
326{
327 NS_LOG_FUNCTION (this);
328 m_random = CreateObject<UniformRandomVariable> ();
329 m_state = CreateObject<WifiPhyStateHelper> ();
330}
331
333{
334 NS_LOG_FUNCTION (this);
335}
336
337void
339{
340 NS_LOG_FUNCTION (this);
343 for (auto & phyEntity : m_phyEntities)
344 {
345 phyEntity.second->CancelAllEvents ();
346 }
347 m_device = 0;
348 m_mobility = 0;
354 m_random = 0;
355 m_state = 0;
356 m_currentEvent = 0;
357 for (auto & preambleEvent : m_currentPreambleEvents)
358 {
359 preambleEvent.second = 0;
360 }
362
363 for (auto & phyEntity : m_phyEntities)
364 {
365 phyEntity.second = 0;
366 }
367 m_phyEntities.clear ();
368}
369
370std::map<WifiModulationClass, Ptr<PhyEntity> > &
372{
373 static std::map<WifiModulationClass, Ptr<PhyEntity> > g_staticPhyEntities;
374 return g_staticPhyEntities;
375}
376
379{
380 return m_state;
381}
382
383void
385{
386 m_state->SetReceiveOkCallback (callback);
387}
388
389void
391{
392 m_state->SetReceiveErrorCallback (callback);
393}
394
395void
397{
398 m_state->RegisterListener (listener);
399}
400
401void
403{
404 m_state->UnregisterListener (listener);
405}
406
407void
409{
411}
412
413void
415{
416 NS_LOG_FUNCTION (this << threshold);
417 m_rxSensitivityW = DbmToW (threshold);
418}
419
420double
422{
423 return WToDbm (m_rxSensitivityW);
424}
425
426void
428{
429 NS_LOG_FUNCTION (this << threshold);
430 m_ccaEdThresholdW = DbmToW (threshold);
431}
432
433double
435{
436 return WToDbm (m_ccaEdThresholdW);
437}
438
439void
440WifiPhy::SetRxNoiseFigure (double noiseFigureDb)
441{
442 NS_LOG_FUNCTION (this << noiseFigureDb);
443 m_interference.SetNoiseFigure (DbToRatio (noiseFigureDb));
445}
446
447void
449{
450 NS_LOG_FUNCTION (this << start);
452}
453
454double
456{
457 return m_txPowerBaseDbm;
458}
459
460void
462{
463 NS_LOG_FUNCTION (this << end);
464 m_txPowerEndDbm = end;
465}
466
467double
469{
470 return m_txPowerEndDbm;
471}
472
473void
475{
476 NS_LOG_FUNCTION (this << +n);
477 m_nTxPower = n;
478}
479
480uint8_t
482{
483 return m_nTxPower;
484}
485
486void
488{
489 NS_LOG_FUNCTION (this << gain);
490 m_txGainDb = gain;
491}
492
493double
495{
496 return m_txGainDb;
497}
498
499void
501{
502 NS_LOG_FUNCTION (this << gain);
503 m_rxGainDb = gain;
504}
505
506double
508{
509 return m_rxGainDb;
510}
511
512void
514{
515 NS_LOG_FUNCTION (this << enable);
516 m_shortPreamble = enable;
517}
518
519bool
521{
522 return m_shortPreamble;
523}
524
525void
527{
528 m_device = device;
529}
530
533{
534 return m_device;
535}
536
537void
539{
541}
542
545{
546 if (m_mobility != 0)
547 {
548 return m_mobility;
549 }
550 else
551 {
552 return m_device->GetNode ()->GetObject<MobilityModel> ();
553 }
554}
555
556void
558{
561}
562
563void
565{
566 NS_LOG_FUNCTION (this << em);
568}
569
570void
572{
573 m_frameCaptureModel = model;
574}
575
576void
578{
580}
581
582void
584{
585 m_wifiRadioEnergyModel = wifiRadioEnergyModel;
586}
587
588double
589WifiPhy::GetPowerDbm (uint8_t power) const
590{
592 NS_ASSERT (m_nTxPower > 0);
593 double dbm;
594 if (m_nTxPower > 1)
595 {
597 }
598 else
599 {
600 NS_ASSERT_MSG (m_txPowerBaseDbm == m_txPowerEndDbm, "cannot have TxPowerEnd != TxPowerStart with TxPowerLevels == 1");
601 dbm = m_txPowerBaseDbm;
602 }
603 return dbm;
604}
605
606Time
608{
610}
611
612double
613WifiPhy::CalculateSnr (const WifiTxVector& txVector, double ber) const
614{
615 return m_interference.GetErrorRateModel ()->CalculateSnr (txVector, ber);
616}
617
620{
621 const auto it = GetStaticPhyEntities ().find (modulation);
622 NS_ABORT_MSG_IF (it == GetStaticPhyEntities ().end (), "Unimplemented Wi-Fi modulation class");
623 return it->second;
624}
625
628{
629 const auto it = m_phyEntities.find (modulation);
630 NS_ABORT_MSG_IF (it == m_phyEntities.end (), "Unsupported Wi-Fi modulation class " << modulation);
631 return it->second;
632}
633
634void
636{
637 NS_LOG_FUNCTION (modulation);
638 NS_ASSERT_MSG (GetStaticPhyEntities ().find (modulation) == GetStaticPhyEntities ().end (), "The PHY entity has already been added. The setting should only be done once per modulation class");
639 GetStaticPhyEntities ()[modulation] = phyEntity;
640}
641
642void
644{
645 NS_LOG_FUNCTION (this << modulation);
646 NS_ABORT_MSG_IF (GetStaticPhyEntities ().find (modulation) == GetStaticPhyEntities ().end (), "Cannot add an unimplemented PHY to supported list. Update the former first.");
647 NS_ASSERT_MSG (m_phyEntities.find (modulation) == m_phyEntities.end (), "The PHY entity has already been added. The setting should only be done once per modulation class");
648 phyEntity->SetOwner (this);
649 m_phyEntities[modulation] = phyEntity;
650}
651
652void
654{
655 m_sifs = sifs;
656}
657
658Time
660{
661 return m_sifs;
662}
663
664void
666{
667 m_slot = slot;
668}
669
670Time
672{
673 return m_slot;
674}
675
676void
678{
679 m_pifs = pifs;
680}
681
682Time
684{
685 return m_pifs;
686}
687
688Time
690{
691 return m_ackTxTime;
692}
693
694Time
696{
697 return m_blockAckTxTime;
698}
699
700void
702{
703 NS_LOG_FUNCTION (this);
704 AddPhyEntity (WIFI_MOD_CLASS_OFDM, Create<OfdmPhy> ());
705
706 // See Table 17-21 "OFDM PHY characteristics" of 802.11-2016
707 SetSifs (MicroSeconds (16));
708 SetSlot (MicroSeconds (9));
709 SetPifs (GetSifs () + GetSlot ());
710 // See Table 10-5 "Determination of the EstimatedAckTxTime based on properties
711 // of the PPDU causing the EIFS" of 802.11-2016
713}
714
715void
717{
718 NS_LOG_FUNCTION (this);
719 Ptr<DsssPhy> phyEntity = Create<DsssPhy> ();
721 AddPhyEntity (WIFI_MOD_CLASS_DSSS, phyEntity); //when plain DSSS modes are used
722
723 // See Table 16-4 "HR/DSSS PHY characteristics" of 802.11-2016
724 SetSifs (MicroSeconds (10));
725 SetSlot (MicroSeconds (20));
726 SetPifs (GetSifs () + GetSlot ());
727 // See Table 10-5 "Determination of the EstimatedAckTxTime based on properties
728 // of the PPDU causing the EIFS" of 802.11-2016
730}
731
732void
734{
735 NS_LOG_FUNCTION (this);
736 // See Table 18-5 "ERP characteristics" of 802.11-2016
737 // Slot time defaults to the "long slot time" of 20 us in the standard
738 // according to mixed 802.11b/g deployments. Short slot time is enabled
739 // if the user sets the ShortSlotTimeSupported flag to true and when the BSS
740 // consists of only ERP STAs capable of supporting this option.
742 AddPhyEntity (WIFI_MOD_CLASS_ERP_OFDM, Create<ErpOfdmPhy> ());
743}
744
745void
747{
748 NS_LOG_FUNCTION (this);
749 if (GetChannelWidth () == 10)
750 {
752
753 // See Table 17-21 "OFDM PHY characteristics" of 802.11-2016
754 SetSifs (MicroSeconds (32));
755 SetSlot (MicroSeconds (13));
756 SetPifs (GetSifs () + GetSlot ());
758 }
759 else if (GetChannelWidth () == 5)
760 {
762
763 // See Table 17-21 "OFDM PHY characteristics" of 802.11-2016
764 SetSifs (MicroSeconds (64));
765 SetSlot (MicroSeconds (21));
766 SetPifs (GetSifs () + GetSlot ());
768 }
769 else
770 {
771 NS_FATAL_ERROR ("802.11p configured with a wrong channel width!");
772 }
773}
774
775void
777{
778 NS_LOG_FUNCTION (this);
780 {
782 }
783 else
784 {
786 }
788
789 // See Table 10-5 "Determination of the EstimatedAckTxTime based on properties
790 // of the PPDU causing the EIFS" of 802.11-2016
792}
793
794void
796{
797 NS_LOG_FUNCTION (this);
799 AddPhyEntity (WIFI_MOD_CLASS_VHT, Create<VhtPhy> ());
800}
801
802void
804{
805 NS_LOG_FUNCTION (this);
807 {
809 }
810 else
811 {
813 }
814 AddPhyEntity (WIFI_MOD_CLASS_HE, Create<HePhy> ());
815}
816
817void
819{
820 NS_LOG_FUNCTION (this << standard);
821
823 "Cannot change standard");
824
825 m_standard = standard;
826
828 {
829 NS_LOG_DEBUG ("Setting the operating channel first");
831 // return because we are called back by SetOperatingChannel
832 return;
833 }
834
835 // this function is called when changing PHY band, hence we have to delete
836 // the previous PHY entities
837 m_phyEntities.clear ();
838
839 switch (standard)
840 {
843 break;
846 break;
849 break;
852 break;
855 break;
858 break;
861 break;
863 default:
864 NS_ASSERT_MSG (false, "Unsupported standard");
865 break;
866 }
867}
868
871{
872 return m_band;
873}
874
875
878{
879 return m_standard;
880}
881
884{
885 return m_operatingChannel;
886}
887
888uint16_t
890{
892}
893
894uint8_t
896{
898}
899
900uint16_t
902{
904}
905
906uint8_t
908{
910}
911
912void
914{
915 // the generic operator<< for tuples does not give a pretty result
916 NS_LOG_FUNCTION (this << +std::get<0> (channelTuple) << std::get<1> (channelTuple)
917 << static_cast<WifiPhyBand> (std::get<2> (channelTuple))
918 << +std::get<3> (channelTuple));
919
920 m_channelSettings = channelTuple;
921
923 {
924 NS_LOG_DEBUG ("Channel information will be applied when a standard is configured");
925 return;
926 }
927
928 Time delay = Seconds (0);
929
930 if (IsInitialized ())
931 {
933 }
934
935 if (delay.IsStrictlyNegative ())
936 {
937 // switching channel is not possible now
938 return;
939 }
940 if (delay.IsStrictlyPositive ())
941 {
942 // switching channel has been postponed
943 void (WifiPhy::*fp) (const ChannelTuple&) = &WifiPhy::SetOperatingChannel;
944 Simulator::Schedule (delay, fp, this, channelTuple);
945 return;
946 }
947
948 // channel can be switched now.
950}
951
952Time
954{
955 m_powerRestricted = false;
957 m_currentEvent = 0;
959 if (!IsInitialized ())
960 {
961 //this is not channel switch, this is initialization
962 NS_LOG_DEBUG ("Before initialization, nothing to do");
963 return Seconds (0);
964 }
965
966 Time delay = Seconds (0);
967
969 switch (m_state->GetState ())
970 {
971 case WifiPhyState::RX:
972 NS_LOG_DEBUG ("drop packet because of channel switching while reception");
974 for (auto & phyEntity : m_phyEntities)
975 {
976 phyEntity.second->CancelAllEvents ();
977 }
978 break;
979 case WifiPhyState::TX:
980 NS_LOG_DEBUG ("channel switching postponed until end of current transmission");
981 delay = GetDelayUntilIdle ();
982 break;
986 for (auto & phyEntity : m_phyEntities)
987 {
988 phyEntity.second->CancelAllEvents ();
989 }
990 break;
992 NS_LOG_DEBUG ("channel switching ignored in sleep mode");
993 delay = Seconds (-1); // negative value to indicate switching not possible
994 break;
995 default:
996 NS_ASSERT (false);
997 break;
998 }
999
1000 return delay;
1001}
1002
1003void
1005{
1006 NS_LOG_FUNCTION (this);
1007
1008 // Update unspecified parameters with default values
1009 if (auto& [number, width, band, primary20] = m_channelSettings; true)
1010 {
1011 if (band == static_cast<int> (WIFI_PHY_BAND_UNSPECIFIED))
1012 {
1013 band = static_cast<int> (GetDefaultPhyBand (m_standard));
1014 }
1015 if (width == 0 && number == 0)
1016 {
1018 }
1019 if (number == 0)
1020 {
1022 }
1023 }
1024
1025 // We need to call SetStandard if this is the first time we set a channel or we
1026 // are changing PHY band. Checking if the new PHY band is different than the
1027 // previous one covers both cases because initially the PHY band is unspecified
1028 bool changingPhyBand = (static_cast<WifiPhyBand> (std::get<2> (m_channelSettings)) != m_band);
1029
1030 m_band = static_cast<WifiPhyBand> (std::get<2> (m_channelSettings));
1031
1032 NS_LOG_DEBUG ("switching channel");
1033 m_operatingChannel.Set (std::get<0> (m_channelSettings), 0, std::get<1> (m_channelSettings),
1036
1037 if (changingPhyBand)
1038 {
1040 }
1041
1043
1044 if (IsInitialized ())
1045 {
1046 // notify channel switching
1047 m_state->SwitchToChannelSwitching (GetChannelSwitchDelay ());
1049 /*
1050 * Needed here to be able to correctly sensed the medium for the first
1051 * time after the switching. The actual switching is not performed until
1052 * after m_channelSwitchDelay. Packets received during the switching
1053 * state are added to the event list and are employed later to figure
1054 * out the state of the medium after the switching.
1055 */
1056 }
1057}
1058
1059void
1061{
1062 NS_ASSERT_MSG (antennas > 0 && antennas <= 4, "unsupported number of antennas");
1063 m_numberOfAntennas = antennas;
1065}
1066
1067uint8_t
1069{
1070 return m_numberOfAntennas;
1071}
1072
1073void
1075{
1076 NS_ASSERT (streams <= GetNumberOfAntennas ());
1077 bool changed = (m_txSpatialStreams != streams);
1078 m_txSpatialStreams = streams;
1079 if (changed)
1080 {
1081 auto phyEntity = m_phyEntities.find (WIFI_MOD_CLASS_HT);
1082 if (phyEntity != m_phyEntities.end ())
1083 {
1084 Ptr<HtPhy> htPhy = DynamicCast<HtPhy> (phyEntity->second);
1085 if (htPhy)
1086 {
1087 htPhy->SetMaxSupportedNss (m_txSpatialStreams); //this is essential to have the right MCSs configured
1088 }
1089
1091 {
1093 }
1094 }
1095 }
1096}
1097
1098uint8_t
1100{
1101 return m_txSpatialStreams;
1102}
1103
1104void
1106{
1107 NS_ASSERT (streams <= GetNumberOfAntennas ());
1108 bool changed = (m_rxSpatialStreams != streams);
1109 m_rxSpatialStreams = streams;
1110 if (changed && !m_capabilitiesChangedCallback.IsNull ())
1111 {
1113 }
1114}
1115
1116uint8_t
1118{
1119 return m_rxSpatialStreams;
1120}
1121
1122std::list<uint8_t>
1124{
1125 std::list<uint8_t> list;
1126 for (const auto & phyEntity : m_phyEntities)
1127 {
1128 Ptr<HtPhy> htPhy = DynamicCast<HtPhy> (phyEntity.second);
1129 if (htPhy)
1130 {
1131 list.emplace_back (htPhy->GetBssMembershipSelector ());
1132 }
1133 }
1134 return list;
1135}
1136
1137void
1139{
1140 NS_LOG_FUNCTION (this << width);
1141 for (std::vector<uint32_t>::size_type i = 0; i != m_supportedChannelWidthSet.size (); i++)
1142 {
1143 if (m_supportedChannelWidthSet[i] == width)
1144 {
1145 return;
1146 }
1147 }
1148 NS_LOG_FUNCTION ("Adding " << width << " to supported channel width set");
1149 m_supportedChannelWidthSet.push_back (width);
1150}
1151
1152std::vector<uint16_t>
1154{
1156}
1157
1158void
1160{
1161 NS_LOG_FUNCTION (this);
1162 m_powerRestricted = false;
1164 switch (m_state->GetState ())
1165 {
1166 case WifiPhyState::TX:
1167 NS_LOG_DEBUG ("setting sleep mode postponed until end of current transmission");
1169 break;
1170 case WifiPhyState::RX:
1171 NS_LOG_DEBUG ("setting sleep mode postponed until end of current reception");
1173 break;
1175 NS_LOG_DEBUG ("setting sleep mode postponed until end of channel switching");
1177 break;
1179 case WifiPhyState::IDLE:
1180 NS_LOG_DEBUG ("setting sleep mode");
1181 m_state->SwitchToSleep ();
1182 break;
1184 NS_LOG_DEBUG ("already in sleep mode");
1185 break;
1186 default:
1187 NS_ASSERT (false);
1188 break;
1189 }
1190}
1191
1192void
1194{
1195 NS_LOG_FUNCTION (this);
1196 m_powerRestricted = false;
1200 for (auto & phyEntity : m_phyEntities)
1201 {
1202 phyEntity.second->CancelAllEvents ();
1203 }
1204 m_state->SwitchToOff ();
1205}
1206
1207void
1209{
1210 NS_LOG_FUNCTION (this);
1211 m_currentPreambleEvents.clear ();
1212 switch (m_state->GetState ())
1213 {
1214 case WifiPhyState::TX:
1215 case WifiPhyState::RX:
1216 case WifiPhyState::IDLE:
1219 {
1220 NS_LOG_DEBUG ("not in sleep mode, there is nothing to resume");
1221 break;
1222 }
1224 {
1225 NS_LOG_DEBUG ("resuming from sleep mode");
1227 m_state->SwitchFromSleep (delayUntilCcaEnd);
1228 break;
1229 }
1230 default:
1231 {
1232 NS_ASSERT (false);
1233 break;
1234 }
1235 }
1236}
1237
1238void
1240{
1241 NS_LOG_FUNCTION (this);
1242 switch (m_state->GetState ())
1243 {
1244 case WifiPhyState::TX:
1245 case WifiPhyState::RX:
1246 case WifiPhyState::IDLE:
1250 {
1251 NS_LOG_DEBUG ("not in off mode, there is nothing to resume");
1252 break;
1253 }
1254 case WifiPhyState::OFF:
1255 {
1256 NS_LOG_DEBUG ("resuming from off mode");
1258 m_state->SwitchFromOff (delayUntilCcaEnd);
1259 break;
1260 }
1261 default:
1262 {
1263 NS_ASSERT (false);
1264 break;
1265 }
1266 }
1267}
1268
1269Time
1271{
1272 return MicroSeconds (4);
1273}
1274
1275Time
1277{
1278 return MicroSeconds (4);
1279}
1280
1281Time
1282WifiPhy::GetPayloadDuration (uint32_t size, const WifiTxVector& txVector, WifiPhyBand band, MpduType mpdutype, uint16_t staId)
1283{
1284 uint32_t totalAmpduSize;
1285 double totalAmpduNumSymbols;
1286 return GetPayloadDuration (size, txVector, band, mpdutype, false, totalAmpduSize, totalAmpduNumSymbols, staId);
1287}
1288
1289Time
1291 bool incFlag, uint32_t &totalAmpduSize, double &totalAmpduNumSymbols,
1292 uint16_t staId)
1293{
1294 return GetStaticPhyEntity (txVector.GetModulationClass ())->GetPayloadDuration (size, txVector, band, mpdutype,
1295 incFlag, totalAmpduSize, totalAmpduNumSymbols,
1296 staId);
1297}
1298
1299Time
1301{
1302 return GetStaticPhyEntity (txVector.GetModulationClass ())->CalculatePhyPreambleAndHeaderDuration (txVector);
1303}
1304
1305Time
1306WifiPhy::CalculateTxDuration (uint32_t size, const WifiTxVector& txVector, WifiPhyBand band, uint16_t staId)
1307{
1308 Time duration = CalculatePhyPreambleAndHeaderDuration (txVector)
1309 + GetPayloadDuration (size, txVector, band, NORMAL_MPDU, staId);
1310 NS_ASSERT (duration.IsStrictlyPositive ());
1311 return duration;
1312}
1313
1314Time
1316{
1317 return CalculateTxDuration (GetWifiConstPsduMap (psdu, txVector), txVector, band);
1318}
1319
1320Time
1322{
1323 return GetStaticPhyEntity (txVector.GetModulationClass ())->CalculateTxDuration (psduMap, txVector, band);
1324}
1325
1328{
1329 return GetStaticPhyEntity (modulation)->GetMaxPsduSize ();
1330}
1331
1332void
1334{
1335 if (!m_phyTxBeginTrace.IsEmpty ())
1336 {
1337 for (auto const& psdu : psdus)
1338 {
1339 for (auto& mpdu : *PeekPointer (psdu.second))
1340 {
1341 m_phyTxBeginTrace (mpdu->GetProtocolDataUnit (), txPowerW);
1342 }
1343 }
1344 }
1345}
1346
1347void
1349{
1350 if (!m_phyTxEndTrace.IsEmpty ())
1351 {
1352 for (auto const& psdu : psdus)
1353 {
1354 for (auto& mpdu : *PeekPointer (psdu.second))
1355 {
1356 m_phyTxEndTrace (mpdu->GetProtocolDataUnit ());
1357 }
1358 }
1359 }
1360}
1361
1362void
1364{
1365 if (!m_phyTxDropTrace.IsEmpty ())
1366 {
1367 for (auto& mpdu : *PeekPointer (psdu))
1368 {
1369 m_phyTxDropTrace (mpdu->GetProtocolDataUnit ());
1370 }
1371 }
1372}
1373
1374void
1376{
1377 if (psdu && !m_phyRxBeginTrace.IsEmpty ())
1378 {
1379 for (auto& mpdu : *PeekPointer (psdu))
1380 {
1381 m_phyRxBeginTrace (mpdu->GetProtocolDataUnit (), rxPowersW);
1382 }
1383 }
1384}
1385
1386void
1388{
1389 if (psdu && !m_phyRxEndTrace.IsEmpty ())
1390 {
1391 for (auto& mpdu : *PeekPointer (psdu))
1392 {
1393 m_phyRxEndTrace (mpdu->GetProtocolDataUnit ());
1394 }
1395 }
1396}
1397
1398void
1400{
1401 if (psdu && !m_phyRxDropTrace.IsEmpty ())
1402 {
1403 for (auto& mpdu : *PeekPointer (psdu))
1404 {
1405 m_phyRxDropTrace (mpdu->GetProtocolDataUnit (), reason);
1406 }
1407 }
1408}
1409
1410void
1411WifiPhy::NotifyMonitorSniffRx (Ptr<const WifiPsdu> psdu, uint16_t channelFreqMhz, WifiTxVector txVector,
1412 SignalNoiseDbm signalNoise, std::vector<bool> statusPerMpdu, uint16_t staId)
1413{
1414 MpduInfo aMpdu;
1415 if (psdu->IsAggregate ())
1416 {
1417 //Expand A-MPDU
1418 NS_ASSERT_MSG (txVector.IsAggregation (), "TxVector with aggregate flag expected here according to PSDU");
1420 size_t nMpdus = psdu->GetNMpdus ();
1421 NS_ASSERT_MSG (statusPerMpdu.size () == nMpdus, "Should have one reception status per MPDU");
1422 if (!m_phyMonitorSniffRxTrace.IsEmpty ())
1423 {
1424 aMpdu.type = (psdu->IsSingle ()) ? SINGLE_MPDU : FIRST_MPDU_IN_AGGREGATE;
1425 for (size_t i = 0; i < nMpdus;)
1426 {
1427 if (statusPerMpdu.at (i)) //packet received without error, hand over to sniffer
1428 {
1429 m_phyMonitorSniffRxTrace (psdu->GetAmpduSubframe (i), channelFreqMhz, txVector, aMpdu, signalNoise, staId);
1430 }
1431 ++i;
1432 aMpdu.type = (i == (nMpdus - 1)) ? LAST_MPDU_IN_AGGREGATE : MIDDLE_MPDU_IN_AGGREGATE;
1433 }
1434 }
1435 }
1436 else
1437 {
1438 NS_ASSERT_MSG (statusPerMpdu.size () == 1, "Should have one reception status for normal MPDU");
1439 if (!m_phyMonitorSniffRxTrace.IsEmpty ())
1440 {
1441 aMpdu.type = NORMAL_MPDU;
1442 m_phyMonitorSniffRxTrace (psdu->GetPacket (), channelFreqMhz, txVector, aMpdu, signalNoise, staId);
1443 }
1444 }
1445}
1446
1447void
1448WifiPhy::NotifyMonitorSniffTx (Ptr<const WifiPsdu> psdu, uint16_t channelFreqMhz, WifiTxVector txVector, uint16_t staId)
1449{
1450 MpduInfo aMpdu;
1451 if (psdu->IsAggregate ())
1452 {
1453 //Expand A-MPDU
1454 NS_ASSERT_MSG (txVector.IsAggregation (), "TxVector with aggregate flag expected here according to PSDU");
1456 if (!m_phyMonitorSniffTxTrace.IsEmpty ())
1457 {
1458 size_t nMpdus = psdu->GetNMpdus ();
1459 aMpdu.type = (psdu->IsSingle ()) ? SINGLE_MPDU: FIRST_MPDU_IN_AGGREGATE;
1460 for (size_t i = 0; i < nMpdus;)
1461 {
1462 m_phyMonitorSniffTxTrace (psdu->GetAmpduSubframe (i), channelFreqMhz, txVector, aMpdu, staId);
1463 ++i;
1464 aMpdu.type = (i == (nMpdus - 1)) ? LAST_MPDU_IN_AGGREGATE : MIDDLE_MPDU_IN_AGGREGATE;
1465 }
1466 }
1467 }
1468 else
1469 {
1470 if (!m_phyMonitorSniffTxTrace.IsEmpty ())
1471 {
1472 aMpdu.type = NORMAL_MPDU;
1473 m_phyMonitorSniffTxTrace (psdu->GetPacket (), channelFreqMhz, txVector, aMpdu, staId);
1474 }
1475 }
1476}
1477
1480{
1481 return GetStaticPhyEntity (txVector.GetModulationClass ())->GetWifiConstPsduMap (psdu, txVector);
1482}
1483
1484void
1486{
1487 NS_LOG_FUNCTION (this << *psdu << txVector);
1488 Send (GetWifiConstPsduMap (psdu, txVector), txVector);
1489}
1490
1491void
1493{
1494 NS_LOG_FUNCTION (this << psdus << txVector);
1495 /* Transmission can happen if:
1496 * - we are syncing on a packet. It is the responsibility of the
1497 * MAC layer to avoid doing this but the PHY does nothing to
1498 * prevent it.
1499 * - we are idle
1500 */
1501 NS_ASSERT (!m_state->IsStateTx () && !m_state->IsStateSwitching ());
1503
1504 if (txVector.GetNssMax () > GetMaxSupportedTxSpatialStreams ())
1505 {
1506 NS_FATAL_ERROR ("Unsupported number of spatial streams!");
1507 }
1508
1509 if (m_state->IsStateSleep ())
1510 {
1511 NS_LOG_DEBUG ("Dropping packet because in sleep mode");
1512 for (auto const& psdu : psdus)
1513 {
1514 NotifyTxDrop (psdu.second);
1515 }
1516 return;
1517 }
1518
1519 Time txDuration = CalculateTxDuration (psdus, txVector, GetPhyBand ());
1520
1521 bool noEndPreambleDetectionEvent = true;
1522 for (const auto & it : m_phyEntities)
1523 {
1524 noEndPreambleDetectionEvent &= it.second->NoEndPreambleDetectionEvents ();
1525 }
1526 if (!noEndPreambleDetectionEvent || ((m_currentEvent != 0) && (m_currentEvent->GetEndTime () > (Simulator::Now () + m_state->GetDelayUntilIdle ()))))
1527 {
1529 //that packet will be noise _after_ the transmission.
1531 }
1532
1533 for (auto & it : m_phyEntities)
1534 {
1535 it.second->CancelRunningEndPreambleDetectionEvents ();
1536 }
1537 m_currentPreambleEvents.clear ();
1539
1541 {
1542 NS_LOG_DEBUG ("Transmitting with power restriction for " << txDuration.As (Time::NS));
1543 }
1544 else
1545 {
1546 NS_LOG_DEBUG ("Transmitting without power restriction for " << txDuration.As (Time::NS));
1547 }
1548
1549 if (m_state->GetState () == WifiPhyState::OFF)
1550 {
1551 NS_LOG_DEBUG ("Transmission canceled because device is OFF");
1552 return;
1553 }
1554
1555 Ptr<WifiPpdu> ppdu = GetPhyEntity (txVector.GetModulationClass ())->BuildPpdu (psdus, txVector, txDuration);
1556 m_previouslyRxPpduUid = UINT64_MAX; //reset (after creation of PPDU) to use it only once
1557
1558 double txPowerW = DbmToW (GetTxPowerForTransmission (ppdu) + GetTxGain ());
1559 NotifyTxBegin (psdus, txPowerW);
1560 if (!m_phyTxPsduBeginTrace.IsEmpty ())
1561 {
1562 m_phyTxPsduBeginTrace (psdus, txVector, txPowerW);
1563 }
1564 for (auto const& psdu : psdus)
1565 {
1566 NotifyMonitorSniffTx (psdu.second, GetFrequency (), txVector, psdu.first);
1567 }
1568 m_state->SwitchToTx (txDuration, psdus, GetPowerDbm (txVector.GetTxPowerLevel ()), txVector);
1569
1570 if (m_wifiRadioEnergyModel != 0 && m_wifiRadioEnergyModel->GetMaximumTimeInState (WifiPhyState::TX) < txDuration)
1571 {
1572 ppdu->SetTruncatedTx ();
1573 }
1574
1575 m_endTxEvent = Simulator::Schedule (txDuration, &WifiPhy::NotifyTxEnd, this, psdus); //TODO: fix for MU
1576
1577 StartTx (ppdu);
1578
1580 m_powerRestricted = false;
1581
1582 Simulator::Schedule (txDuration, &WifiPhy::Reset, this);
1583}
1584
1585uint64_t
1587{
1588 return m_previouslyRxPpduUid;
1589}
1590
1591void
1593{
1594 NS_LOG_FUNCTION (this);
1595 m_currentPreambleEvents.clear ();
1596 m_currentEvent = 0;
1597 for (auto & phyEntity : m_phyEntities)
1598 {
1599 phyEntity.second->CancelAllEvents ();
1600 }
1601}
1602
1603void
1605{
1606 WifiModulationClass modulation = ppdu->GetTxVector ().GetModulationClass ();
1607 auto it = m_phyEntities.find (modulation);
1608 if (it != m_phyEntities.end ())
1609 {
1610 it->second->StartReceivePreamble (ppdu, rxPowersW, rxDuration);
1611 }
1612 else
1613 {
1614 //TODO find a fallback PHY for receiving the PPDU (e.g. 11a for 11ax due to preamble structure)
1615 NS_LOG_DEBUG ("Unsupported modulation received (" << modulation << "), consider as noise");
1616 if (ppdu->GetTxDuration () > m_state->GetDelayUntilIdle ())
1617 {
1618 m_interference.Add (ppdu, ppdu->GetTxVector (), rxDuration, rxPowersW);
1620 }
1621 }
1622}
1623
1625WifiPhy::ConvertHeRuSubcarriers (uint16_t bandWidth, uint16_t guardBandwidth,
1626 HeRu::SubcarrierRange range, uint8_t bandIndex) const
1627{
1628 NS_ASSERT_MSG (false, "802.11ax can only be used with SpectrumWifiPhy");
1629 WifiSpectrumBand convertedSubcarriers;
1630 return convertedSubcarriers;
1631}
1632
1633void
1635{
1636 NS_LOG_FUNCTION (this);
1638 {
1639 m_powerRestricted = false;
1640 }
1641}
1642
1643void
1645{
1646 NS_LOG_FUNCTION (this << *event);
1647 NS_ASSERT (!IsStateRx ());
1649 m_currentEvent = 0;
1650 m_currentPreambleEvents.clear ();
1652}
1653
1654void
1656{
1657 NS_LOG_FUNCTION (this);
1659}
1660
1661bool
1663{
1664 for (const auto & phyEntity : m_phyEntities)
1665 {
1666 if (phyEntity.second->IsModeSupported (mode))
1667 {
1668 return true;
1669 }
1670 }
1671 return false;
1672}
1673
1676{
1677 //Start from oldest standards and move up (guaranteed by fact that WifModulationClass is ordered)
1678 for (const auto & phyEntity : m_phyEntities)
1679 {
1680 for (const auto & mode : *(phyEntity.second))
1681 {
1682 return mode;
1683 }
1684 }
1685 NS_ASSERT_MSG (false, "Should have found at least one default mode");
1686 return WifiMode ();
1687}
1688
1689bool
1690WifiPhy::IsMcsSupported (WifiModulationClass modulation, uint8_t mcs) const
1691{
1692 const auto phyEntity = m_phyEntities.find (modulation);
1693 if (phyEntity == m_phyEntities.end ())
1694 {
1695 return false;
1696 }
1697 return phyEntity->second->IsMcsSupported (mcs);
1698}
1699
1700std::list<WifiMode>
1702{
1703 std::list<WifiMode> list;
1704 for (const auto & phyEntity : m_phyEntities)
1705 {
1706 if (!phyEntity.second->HandlesMcsModes ()) //to exclude MCSs from search
1707 {
1708 for (const auto & mode : *(phyEntity.second))
1709 {
1710 list.emplace_back (mode);
1711 }
1712 }
1713 }
1714 return list;
1715}
1716
1717std::list<WifiMode>
1719{
1720 std::list<WifiMode> list;
1721 const auto phyEntity = m_phyEntities.find (modulation);
1722 if (phyEntity != m_phyEntities.end ())
1723 {
1724 if (!phyEntity->second->HandlesMcsModes ()) //to exclude MCSs from search
1725 {
1726 for (const auto & mode : *(phyEntity->second))
1727 {
1728 list.emplace_back (mode);
1729 }
1730 }
1731 }
1732 return list;
1733}
1734
1735uint16_t
1737{
1738 uint16_t numMcs = 0;
1739 for (const auto & phyEntity : m_phyEntities)
1740 {
1741 if (phyEntity.second->HandlesMcsModes ()) //to exclude non-MCS modes from search
1742 {
1743 numMcs += phyEntity.second->GetNumModes ();
1744 }
1745 }
1746 return numMcs;
1747}
1748
1749std::list<WifiMode>
1751{
1752 std::list<WifiMode> list;
1753 for (const auto & phyEntity : m_phyEntities)
1754 {
1755 if (phyEntity.second->HandlesMcsModes ()) //to exclude non-MCS modes from search
1756 {
1757 for (const auto & mode : *(phyEntity.second))
1758 {
1759 list.emplace_back (mode);
1760 }
1761 }
1762 }
1763 return list;
1764}
1765
1766std::list<WifiMode>
1768{
1769 std::list<WifiMode> list;
1770 auto phyEntity = m_phyEntities.find (modulation);
1771 if (phyEntity != m_phyEntities.end ())
1772 {
1773 if (phyEntity->second->HandlesMcsModes ()) //to exclude non-MCS modes from search
1774 {
1775 for (const auto & mode : *(phyEntity->second))
1776 {
1777 list.emplace_back (mode);
1778 }
1779 }
1780 }
1781 return list;
1782}
1783
1785WifiPhy::GetMcs (WifiModulationClass modulation, uint8_t mcs) const
1786{
1787 NS_ASSERT_MSG (IsMcsSupported (modulation, mcs), "Unsupported MCS");
1788 return m_phyEntities.at (modulation)->GetMcs (mcs);
1789}
1790
1791bool
1793{
1794 return m_state->IsStateCcaBusy ();
1795}
1796
1797bool
1799{
1800 return m_state->IsStateIdle ();
1801}
1802
1803bool
1805{
1806 return m_state->IsStateRx ();
1807}
1808
1809bool
1811{
1812 return m_state->IsStateTx ();
1813}
1814
1815bool
1817{
1818 return m_state->IsStateSwitching ();
1819}
1820
1821bool
1823{
1824 return m_state->IsStateSleep ();
1825}
1826
1827bool
1829{
1830 return m_state->IsStateOff ();
1831}
1832
1833Time
1835{
1836 return m_state->GetDelayUntilIdle ();
1837}
1838
1839Time
1841{
1842 return m_state->GetLastRxStartTime ();
1843}
1844
1845Time
1847{
1848 return m_state->GetLastRxEndTime ();
1849}
1850
1851void
1852WifiPhy::SwitchMaybeToCcaBusy (uint16_t channelWidth)
1853{
1854 NS_LOG_FUNCTION (this << channelWidth);
1855 //We are here because we have received the first bit of a packet and we are
1856 //not going to be able to synchronize on it
1857 //In this model, CCA becomes busy when the aggregation of all signals as
1858 //tracked by the InterferenceHelper class is higher than the CcaBusyThreshold
1859 Time delayUntilCcaEnd = m_interference.GetEnergyDuration (m_ccaEdThresholdW, GetPrimaryBand (channelWidth));
1860 if (!delayUntilCcaEnd.IsZero ())
1861 {
1862 NS_LOG_DEBUG ("Calling SwitchMaybeToCcaBusy for " << delayUntilCcaEnd.As (Time::S));
1863 m_state->SwitchMaybeToCcaBusy (delayUntilCcaEnd);
1864 }
1865}
1866
1867void
1869{
1870 NS_LOG_FUNCTION (this << reason);
1871 if (reason != OBSS_PD_CCA_RESET || m_currentEvent) //Otherwise abort has already been called previously
1872 {
1873 for (auto & phyEntity : m_phyEntities)
1874 {
1875 phyEntity.second->CancelAllEvents ();
1876 }
1878 {
1880 }
1882 if (!m_currentEvent)
1883 {
1884 return;
1885 }
1886 NotifyRxDrop (GetAddressedPsduInPpdu (m_currentEvent->GetPpdu ()), reason);
1887 if (reason == OBSS_PD_CCA_RESET)
1888 {
1889 m_state->SwitchFromRxAbort ();
1890 }
1891 for (auto it = m_currentPreambleEvents.begin (); it != m_currentPreambleEvents.end (); ++it)
1892 {
1893 if (it->second == m_currentEvent)
1894 {
1895 it = m_currentPreambleEvents.erase (it);
1896 break;
1897 }
1898 }
1899 m_currentEvent = 0;
1900 }
1901}
1902
1903void
1904WifiPhy::ResetCca (bool powerRestricted, double txPowerMaxSiso, double txPowerMaxMimo)
1905{
1906 NS_LOG_FUNCTION (this << powerRestricted << txPowerMaxSiso << txPowerMaxMimo);
1907 // This method might be called multiple times when receiving TB PPDUs with a BSS color
1908 // different than the one of the receiver. The first time this method is called, the call
1909 // to AbortCurrentReception sets m_currentEvent to 0. Therefore, we need to check whether
1910 // m_currentEvent is not 0 before executing the instructions below.
1911 if (m_currentEvent != 0)
1912 {
1913 m_powerRestricted = powerRestricted;
1914 m_txPowerMaxSiso = txPowerMaxSiso;
1915 m_txPowerMaxMimo = txPowerMaxMimo;
1916 NS_ASSERT ((m_currentEvent->GetEndTime () - Simulator::Now ()).IsPositive ());
1918 Simulator::ScheduleNow (&WifiPhy::AbortCurrentReception, this, OBSS_PD_CCA_RESET); //finish processing field first
1919 }
1920}
1921
1922double
1924{
1925 NS_LOG_FUNCTION (this << m_powerRestricted << ppdu);
1926 const WifiTxVector& txVector = ppdu->GetTxVector ();
1927 // Get transmit power before antenna gain
1928 double txPowerDbm;
1929 if (!m_powerRestricted)
1930 {
1931 txPowerDbm = GetPowerDbm (txVector.GetTxPowerLevel ());
1932 }
1933 else
1934 {
1935 if (txVector.GetNssMax () > 1)
1936 {
1937 txPowerDbm = std::min (m_txPowerMaxMimo, GetPowerDbm (txVector.GetTxPowerLevel ()));
1938 }
1939 else
1940 {
1941 txPowerDbm = std::min (m_txPowerMaxSiso, GetPowerDbm (txVector.GetTxPowerLevel ()));
1942 }
1943 }
1944
1945 //Apply power density constraint on EIRP
1946 uint16_t channelWidth = ppdu->GetTransmissionChannelWidth ();
1947 double txPowerDbmPerMhz = (txPowerDbm + GetTxGain ()) - RatioToDb (channelWidth); //account for antenna gain since EIRP
1948 NS_LOG_INFO ("txPowerDbm=" << txPowerDbm << " with txPowerDbmPerMhz=" << txPowerDbmPerMhz << " over " << channelWidth << " MHz");
1949 txPowerDbm = std::min (txPowerDbmPerMhz, m_powerDensityLimit) + RatioToDb (channelWidth);
1950 txPowerDbm -= GetTxGain (); //remove antenna gain since will be added right afterwards
1951 NS_LOG_INFO ("txPowerDbm=" << txPowerDbm << " after applying m_powerDensityLimit=" << m_powerDensityLimit);
1952 return txPowerDbm;
1953}
1954
1957{
1958 //TODO: wrapper. See if still needed
1959 return GetPhyEntity (ppdu->GetModulation ())->GetAddressedPsduInPpdu (ppdu);
1960}
1961
1962uint16_t
1964{
1965 if (ppdu == nullptr)
1966 {
1967 // Here because PHY was not receiving anything (e.g. resuming from OFF) nor expecting anything (e.g. sleep)
1968 // nor processing a Wi-Fi signal.
1969 return GetChannelWidth () >= 40 ? 20 : GetChannelWidth ();
1970 }
1971 return GetPhyEntity (ppdu->GetModulation ())->GetMeasurementChannelWidth (ppdu);
1972}
1973
1975WifiPhy::GetBand (uint16_t /*bandWidth*/, uint8_t /*bandIndex*/)
1976{
1977 WifiSpectrumBand band;
1978 band.first = 0;
1979 band.second = 0;
1980 return band;
1981}
1982
1984WifiPhy::GetPrimaryBand (uint16_t bandWidth)
1985{
1986 if (GetChannelWidth () % 20 != 0)
1987 {
1988 return GetBand (bandWidth);
1989 }
1990
1991 return GetBand (bandWidth, m_operatingChannel.GetPrimaryChannelIndex (bandWidth));
1992}
1993
1994int64_t
1996{
1997 NS_LOG_FUNCTION (this << stream);
1998 int64_t currentStream = stream;
1999 m_random->SetStream (currentStream++);
2000 currentStream += m_interference.GetErrorRateModel ()->AssignStreams (currentStream);
2001 return (currentStream - stream);
2002}
2003
2004std::ostream& operator<< (std::ostream& os, RxSignalInfo rxSignalInfo)
2005{
2006 os << "SNR:" << RatioToDb (rxSignalInfo.snr) << " dB"
2007 << ", RSSI:" << rxSignalInfo.rssi << " dBm";
2008 return os;
2009}
2010
2011uint8_t
2012WifiPhy::GetPrimaryChannelNumber (uint16_t primaryChannelWidth) const
2013{
2014 return m_operatingChannel.GetPrimaryChannelNumber (primaryChannelWidth, m_standard);
2015}
2016
2017} //namespace ns3
#define min(a, b)
Definition: 80211b.c:42
AttributeValue implementation for Boolean.
Definition: boolean.h:37
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1386
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:71
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
bool IsExpired(void) const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
Definition: event-id.cc:65
std::pair< int16_t, int16_t > SubcarrierRange
(lowest index, highest index) pair defining a subcarrier range
Definition: he-ru.h:53
void SetNoiseFigure(double value)
Set the noise figure.
void EraseEvents(void)
Erase all events.
void NotifyRxEnd(Time endTime)
Notify that RX has ended.
void SetErrorRateModel(const Ptr< ErrorRateModel > rate)
Set the error rate model for this interference helper.
Time GetEnergyDuration(double energyW, WifiSpectrumBand band)
Ptr< ErrorRateModel > GetErrorRateModel(void) const
Return the error rate model.
Ptr< Event > Add(Ptr< const WifiPpdu > ppdu, const WifiTxVector &txVector, Time duration, RxPowerWattPerChannelBand &rxPower, bool isStartOfdmaRxing=false)
Add the PPDU-related signal to interference helper.
void SetNumberOfReceiveAntennas(uint8_t rx)
Set the number of RX antennas in the receiver corresponding to this interference helper.
Keep track of the current position and velocity of an object.
A base class which provides memory management and object aggregation.
Definition: object.h:88
bool IsInitialized(void) const
Check if the object has been initialized.
Definition: object.cc:208
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
Hold objects of type Ptr<T>.
Definition: pointer.h:37
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition: simulator.h:587
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
Hold variables of type string.
Definition: string.h:41
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
bool IsStrictlyPositive(void) const
Exactly equivalent to t > 0.
Definition: nstime.h:332
@ S
second
Definition: nstime.h:114
@ NS
nanosecond
Definition: nstime.h:117
bool IsStrictlyNegative(void) const
Exactly equivalent to t < 0.
Definition: nstime.h:324
bool IsZero(void) const
Exactly equivalent to t == 0.
Definition: nstime.h:300
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:432
AttributeValue implementation for Time.
Definition: nstime.h:1308
bool IsEmpty() const
Checks if the Callbacks list is empty.
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Hold an unsigned integer type.
Definition: uinteger.h:44
represent a single transmission mode
Definition: wifi-mode.h:48
Ptr< Node > GetNode(void) const override
802.11 PHY layer model
Definition: wifi-phy.h:49
void SetNumberOfAntennas(uint8_t antennas)
Definition: wifi-phy.cc:1060
Ptr< WifiPhyStateHelper > m_state
Pointer to WifiPhyStateHelper.
Definition: wifi-phy.h:1136
double m_rxGainDb
Reception gain (dB)
Definition: wifi-phy.h:1358
Ptr< MobilityModel > m_mobility
Pointer to the mobility model.
Definition: wifi-phy.h:1377
bool IsStateIdle(void) const
Definition: wifi-phy.cc:1798
uint8_t m_txSpatialStreams
Number of supported TX spatial streams.
Definition: wifi-phy.h:1371
void Send(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector)
This function is a wrapper for the Send variant that accepts a WifiConstPsduMap as first argument.
Definition: wifi-phy.cc:1485
bool IsStateTx(void) const
Definition: wifi-phy.cc:1810
void StartReceivePreamble(Ptr< WifiPpdu > ppdu, RxPowerWattPerChannelBand &rxPowersW, Time rxDuration)
Start receiving the PHY preamble of a PPDU (i.e.
Definition: wifi-phy.cc:1604
Ptr< UniformRandomVariable > m_random
Provides uniform random variables.
Definition: wifi-phy.h:1135
uint8_t GetChannelNumber(void) const
Return current channel number.
Definition: wifi-phy.cc:895
Ptr< WifiRadioEnergyModel > m_wifiRadioEnergyModel
Wifi radio energy model.
Definition: wifi-phy.h:1381
virtual ~WifiPhy()
Definition: wifi-phy.cc:332
Time m_channelSwitchDelay
Time required to switch between channel.
Definition: wifi-phy.h:1374
std::list< WifiMode > GetMcsList(void) const
The WifiPhy::GetMcsList() method is used (e.g., by a WifiRemoteStationManager) to determine the set o...
Definition: wifi-phy.cc:1750
void SetCcaEdThreshold(double threshold)
Sets the CCA threshold (dBm).
Definition: wifi-phy.cc:427
TracedCallback< Ptr< const Packet >, WifiPhyRxfailureReason > m_phyRxDropTrace
The trace source fired when the PHY layer drops a packet it has received.
Definition: wifi-phy.h:1304
WifiPhyOperatingChannel m_operatingChannel
Operating channel.
Definition: wifi-phy.h:1346
TracedCallback< Ptr< const Packet > > m_phyTxDropTrace
The trace source fired when the PHY layer drops a packet as it tries to transmit it.
Definition: wifi-phy.h:1265
TracedCallback< Ptr< const Packet >, RxPowerWattPerChannelBand > m_phyRxBeginTrace
The trace source fired when a packet begins the reception process from the medium.
Definition: wifi-phy.h:1273
bool m_channelAccessRequested
Flag if channels access has been requested (used for OBSS_PD SR)
Definition: wifi-phy.h:1367
static Time GetPayloadDuration(uint32_t size, const WifiTxVector &txVector, WifiPhyBand band, MpduType mpdutype=NORMAL_MPDU, uint16_t staId=SU_STA_ID)
Definition: wifi-phy.cc:1282
TracedCallback< Ptr< const Packet >, double > m_phyTxBeginTrace
The trace source fired when a packet begins the transmission process on the medium.
Definition: wifi-phy.h:1242
Ptr< MobilityModel > GetMobility(void) const
Return the mobility model this PHY is associated with.
Definition: wifi-phy.cc:544
void SetMaxSupportedRxSpatialStreams(uint8_t streams)
Definition: wifi-phy.cc:1105
const WifiPhyOperatingChannel & GetOperatingChannel(void) const
Get a const reference to the operating channel.
Definition: wifi-phy.cc:883
Ptr< const WifiPsdu > GetAddressedPsduInPpdu(Ptr< const WifiPpdu > ppdu) const
Get the PSDU addressed to that PHY in a PPDU (useful for MU PPDU).
Definition: wifi-phy.cc:1956
bool GetShortPhyPreambleSupported(void) const
Return whether short PHY preamble is supported.
Definition: wifi-phy.cc:520
void NotifyTxEnd(WifiConstPsduMap psdus)
Public method used to fire a PhyTxEnd trace.
Definition: wifi-phy.cc:1348
std::map< std::pair< uint64_t, WifiPreamble >, Ptr< Event > > m_currentPreambleEvents
store event associated to a PPDU (that has a unique ID and preamble combination) whose preamble is be...
Definition: wifi-phy.h:1145
Time m_slot
Slot duration.
Definition: wifi-phy.h:1350
double m_powerDensityLimit
the power density limit (dBm/MHz)
Definition: wifi-phy.h:1362
WifiMode GetDefaultMode(void) const
Get the default WifiMode supported by the PHY.
Definition: wifi-phy.cc:1675
std::vector< uint16_t > GetSupportedChannelWidthSet(void) const
Definition: wifi-phy.cc:1153
bool IsStateRx(void) const
Definition: wifi-phy.cc:1804
void SetSifs(Time sifs)
Set the Short Interframe Space (SIFS) for this PHY.
Definition: wifi-phy.cc:653
WifiPhyBand GetPhyBand(void) const
Get the configured Wi-Fi band.
Definition: wifi-phy.cc:870
EventId m_endPhyRxEvent
the end of PHY receive event
Definition: wifi-phy.h:1141
double m_txPowerBaseDbm
Minimum transmission power (dBm)
Definition: wifi-phy.h:1359
Ptr< WifiPhyStateHelper > GetState(void) const
Return the WifiPhyStateHelper of this PHY.
Definition: wifi-phy.cc:378
Ptr< WifiNetDevice > GetDevice(void) const
Return the device this PHY is associated with.
Definition: wifi-phy.cc:532
void NotifyRxDrop(Ptr< const WifiPsdu > psdu, WifiPhyRxfailureReason reason)
Public method used to fire a PhyRxDrop trace.
Definition: wifi-phy.cc:1399
bool IsMcsSupported(WifiModulationClass modulation, uint8_t mcs) const
Check if the given MCS of the given modulation class is supported by the PHY.
Definition: wifi-phy.cc:1690
WifiStandard GetStandard(void) const
Get the configured Wi-Fi standard.
Definition: wifi-phy.cc:877
virtual void DoDispose(void)
Destructor implementation.
Definition: wifi-phy.cc:338
Time m_blockAckTxTime
estimated BlockAck TX time
Definition: wifi-phy.h:1353
uint8_t GetPrimaryChannelNumber(uint16_t primaryChannelWidth) const
Get channel number of the primary channel.
Definition: wifi-phy.cc:2012
void Configure80211a(void)
Configure WifiPhy with appropriate channel frequency and supported rates for 802.11a standard.
Definition: wifi-phy.cc:701
std::list< uint8_t > GetBssMembershipSelectorList(void) const
The WifiPhy::BssMembershipSelector() method is used (e.g., by a WifiRemoteStationManager) to determin...
Definition: wifi-phy.cc:1123
void ResetCca(bool powerRestricted, double txPowerMaxSiso=0, double txPowerMaxMimo=0)
Reset PHY to IDLE, with some potential TX power restrictions for the next transmission.
Definition: wifi-phy.cc:1904
double m_txPowerMaxMimo
MIMO maximum transmit power due to OBSS PD SR power restriction (dBm)
Definition: wifi-phy.h:1366
Time GetSlot(void) const
Return the slot duration for this PHY.
Definition: wifi-phy.cc:671
void AbortCurrentReception(WifiPhyRxfailureReason reason)
Due to newly arrived signal, the current reception cannot be continued and has to be aborted.
Definition: wifi-phy.cc:1868
Ptr< FrameCaptureModel > m_frameCaptureModel
Frame capture model.
Definition: wifi-phy.h:1379
TracedCallback< Ptr< const Packet > > m_phyRxEndTrace
The trace source fired when a packet ends the reception process from the medium.
Definition: wifi-phy.h:1297
void NotifyRxBegin(Ptr< const WifiPsdu > psdu, const RxPowerWattPerChannelBand &rxPowersW)
Public method used to fire a PhyRxBegin trace.
Definition: wifi-phy.cc:1375
void SetMaxSupportedTxSpatialStreams(uint8_t streams)
Definition: wifi-phy.cc:1074
uint16_t GetMeasurementChannelWidth(const Ptr< const WifiPpdu > ppdu) const
Return the channel width used to measure the RSSI.
Definition: wifi-phy.cc:1963
double GetTxPowerEnd(void) const
Return the maximum available transmission power level (dBm).
Definition: wifi-phy.cc:468
Time m_sifs
Short Interframe Space (SIFS) duration.
Definition: wifi-phy.h:1349
void SetReceiveErrorCallback(RxErrorCallback callback)
Definition: wifi-phy.cc:390
void ResetReceive(Ptr< Event > event)
Reset PHY at the end of the packet under reception after it has failed the PHY header.
Definition: wifi-phy.cc:1644
InterferenceHelper m_interference
the class handling interference computations
Definition: wifi-phy.h:1134
virtual void ConfigureStandard(WifiStandard standard)
Configure the PHY-level parameters for different Wi-Fi standard.
Definition: wifi-phy.cc:818
uint8_t GetMaxSupportedRxSpatialStreams(void) const
Definition: wifi-phy.cc:1117
void SetPostReceptionErrorModel(const Ptr< ErrorModel > em)
Attach a receive ErrorModel to the WifiPhy.
Definition: wifi-phy.cc:564
WifiMode GetMcs(WifiModulationClass modulation, uint8_t mcs) const
Get the WifiMode object corresponding to the given MCS of the given modulation class.
Definition: wifi-phy.cc:1785
uint8_t m_numberOfAntennas
Number of transmitters.
Definition: wifi-phy.h:1370
ChannelTuple m_channelSettings
Store operating channel settings until initialization.
Definition: wifi-phy.h:1345
static Time CalculateTxDuration(uint32_t size, const WifiTxVector &txVector, WifiPhyBand band, uint16_t staId=SU_STA_ID)
Definition: wifi-phy.cc:1306
Time GetLastRxStartTime(void) const
Return the start time of the last received packet.
Definition: wifi-phy.cc:1840
Time GetBlockAckTxTime(void) const
Return the estimated BlockAck TX time for this PHY.
Definition: wifi-phy.cc:695
void Configure80211p(void)
Configure WifiPhy with appropriate channel frequency and supported rates for 802.11p standard.
Definition: wifi-phy.cc:746
Time GetPifs(void) const
Return the PCF Interframe Space (PIFS) for this PHY.
Definition: wifi-phy.cc:683
static uint32_t GetMaxPsduSize(WifiModulationClass modulation)
Get the maximum PSDU size in bytes for the given modulation class.
Definition: wifi-phy.cc:1327
void NotifyTxBegin(WifiConstPsduMap psdus, double txPowerW)
Public method used to fire a PhyTxBegin trace.
Definition: wifi-phy.cc:1333
void Reset(void)
Reset data upon end of TX or RX.
Definition: wifi-phy.cc:1592
void SetShortPhyPreambleSupported(bool preamble)
Enable or disable short PHY preamble.
Definition: wifi-phy.cc:513
void SetNTxPower(uint8_t n)
Sets the number of transmission power levels available between the minimum level and the maximum leve...
Definition: wifi-phy.cc:474
static TypeId GetTypeId(void)
Get the type ID.
Definition: wifi-phy.cc:56
WifiPhyBand m_band
WifiPhyBand.
Definition: wifi-phy.h:1344
void Configure80211b(void)
Configure WifiPhy with appropriate channel frequency and supported rates for 802.11b standard.
Definition: wifi-phy.cc:716
void SetSleepMode(void)
Put in sleep mode.
Definition: wifi-phy.cc:1159
void SetRxSensitivity(double threshold)
Sets the receive sensitivity threshold (dBm).
Definition: wifi-phy.cc:414
uint8_t GetPrimary20Index(void) const
Definition: wifi-phy.cc:907
static const Ptr< const PhyEntity > GetStaticPhyEntity(WifiModulationClass modulation)
Get the implemented PHY entity corresponding to the modulation class.
Definition: wifi-phy.cc:619
uint8_t GetMaxSupportedTxSpatialStreams(void) const
Definition: wifi-phy.cc:1099
void Configure80211g(void)
Configure WifiPhy with appropriate channel frequency and supported rates for 802.11g standard.
Definition: wifi-phy.cc:733
TracedCallback< Ptr< const Packet >, uint16_t, WifiTxVector, MpduInfo, uint16_t > m_phyMonitorSniffTxTrace
A trace source that emulates a Wi-Fi device in monitor mode sniffing a packet being transmitted.
Definition: wifi-phy.h:1332
Time GetChannelSwitchDelay(void) const
Definition: wifi-phy.cc:607
virtual WifiSpectrumBand ConvertHeRuSubcarriers(uint16_t bandWidth, uint16_t guardBandwidth, HeRu::SubcarrierRange range, uint8_t bandIndex=0) const
Definition: wifi-phy.cc:1625
double m_txPowerMaxSiso
SISO maximum transmit power due to OBSS PD SR power restriction (dBm)
Definition: wifi-phy.h:1365
std::map< WifiModulationClass, Ptr< PhyEntity > > m_phyEntities
This map holds the supported PHY entities.
Definition: wifi-phy.h:1166
void AddPhyEntity(WifiModulationClass modulation, Ptr< PhyEntity > phyEntity)
Add the PHY entity to the map of supported PHY entities for the given modulation class for the WifiPh...
Definition: wifi-phy.cc:643
TracedCallback< Ptr< const Packet >, uint16_t, WifiTxVector, MpduInfo, SignalNoiseDbm, uint16_t > m_phyMonitorSniffRxTrace
A trace source that emulates a Wi-Fi device in monitor mode sniffing a packet being received.
Definition: wifi-phy.h:1318
Ptr< ErrorModel > m_postReceptionErrorModel
Error model for receive packet events.
Definition: wifi-phy.h:1382
double GetTxPowerStart(void) const
Return the minimum available transmission power level (dBm).
Definition: wifi-phy.cc:455
EventId m_endTxEvent
the end of transmit event
Definition: wifi-phy.h:1142
static WifiConstPsduMap GetWifiConstPsduMap(Ptr< const WifiPsdu > psdu, const WifiTxVector &txVector)
Get a WifiConstPsduMap from a PSDU and the TXVECTOR to use to send the PSDU.
Definition: wifi-phy.cc:1479
uint16_t GetNMcs(void) const
Definition: wifi-phy.cc:1736
void SetSlot(Time slot)
Set the slot duration for this PHY.
Definition: wifi-phy.cc:665
void SetOperatingChannel(const ChannelTuple &channelTuple)
If the standard for this object has not been set yet, store the given channel settings.
Definition: wifi-phy.cc:913
Ptr< Event > m_currentEvent
Hold the current event.
Definition: wifi-phy.h:1144
double m_ccaEdThresholdW
Clear channel assessment (CCA) threshold in watts.
Definition: wifi-phy.h:1356
void NotifyMonitorSniffTx(Ptr< const WifiPsdu > psdu, uint16_t channelFreqMhz, WifiTxVector txVector, uint16_t staId=SU_STA_ID)
Public method used to fire a MonitorSniffer trace for a wifi PSDU being transmitted.
Definition: wifi-phy.cc:1448
Ptr< PhyEntity > GetPhyEntity(WifiModulationClass modulation) const
Get the supported PHY entity corresponding to the modulation class, for the WifiPhy instance.
Definition: wifi-phy.cc:627
virtual WifiSpectrumBand GetBand(uint16_t bandWidth, uint8_t bandIndex=0)
Get the start band index and the stop band index for a given band.
Definition: wifi-phy.cc:1975
TracedCallback< Ptr< const Packet > > m_phyTxEndTrace
The trace source fired when a packet ends the transmission process on the medium.
Definition: wifi-phy.h:1257
void ResumeFromSleep(void)
Resume from sleep mode.
Definition: wifi-phy.cc:1208
uint64_t m_previouslyRxPpduUid
UID of the previously received PPDU, reset to UINT64_MAX upon transmission.
Definition: wifi-phy.h:1147
void Configure80211ac(void)
Configure WifiPhy with appropriate channel frequency and supported rates for 802.11ac standard.
Definition: wifi-phy.cc:795
uint32_t m_rxMpduReferenceNumber
A-MPDU reference number to identify all received subframes belonging to the same received A-MPDU.
Definition: wifi-phy.h:1139
void SetWifiRadioEnergyModel(const Ptr< WifiRadioEnergyModel > wifiRadioEnergyModel)
Sets the wifi radio energy model.
Definition: wifi-phy.cc:583
void SetDevice(const Ptr< WifiNetDevice > device)
Sets the device this PHY is associated with.
Definition: wifi-phy.cc:526
void NotifyChannelAccessRequested(void)
Notify the PHY that an access to the channel was requested.
Definition: wifi-phy.cc:1655
Ptr< PreambleDetectionModel > m_preambleDetectionModel
Preamble detection model.
Definition: wifi-phy.h:1380
uint8_t GetNumberOfAntennas(void) const
Definition: wifi-phy.cc:1068
void SwitchMaybeToCcaBusy(uint16_t channelWidth)
Check if PHY state should move to CCA busy state based on current state of interference tracker.
Definition: wifi-phy.cc:1852
void SetTxPowerEnd(double end)
Sets the maximum available transmission power level (dBm).
Definition: wifi-phy.cc:461
static std::map< WifiModulationClass, Ptr< PhyEntity > > & GetStaticPhyEntities(void)
Definition: wifi-phy.cc:371
static void AddStaticPhyEntity(WifiModulationClass modulation, Ptr< PhyEntity > phyEntity)
Add the PHY entity to the map of implemented PHY entities for the given modulation class.
Definition: wifi-phy.cc:635
void NotifyRxEnd(Ptr< const WifiPsdu > psdu)
Public method used to fire a PhyRxEnd trace.
Definition: wifi-phy.cc:1387
std::list< WifiMode > GetModeList(void) const
The WifiPhy::GetModeList() method is used (e.g., by a WifiRemoteStationManager) to determine the set ...
Definition: wifi-phy.cc:1701
TracedCallback< WifiConstPsduMap, WifiTxVector, double > m_phyTxPsduBeginTrace
The trace source fired when a PSDU map begins the transmission process on the medium.
Definition: wifi-phy.h:1249
double m_txGainDb
Transmission gain (dB)
Definition: wifi-phy.h:1357
std::vector< uint16_t > m_supportedChannelWidthSet
Supported channel width set (MHz)
Definition: wifi-phy.h:1347
WifiSpectrumBand GetPrimaryBand(uint16_t bandWidth)
If the operating channel width is a multiple of 20 MHz, return the start band index and the stop band...
Definition: wifi-phy.cc:1984
Time GetDelayUntilIdle(void)
Definition: wifi-phy.cc:1834
uint64_t GetPreviouslyRxPpduUid(void) const
Definition: wifi-phy.cc:1586
WifiStandard m_standard
WifiStandard.
Definition: wifi-phy.h:1343
double GetPowerDbm(uint8_t power) const
Get the power of the given power level in dBm.
Definition: wifi-phy.cc:589
uint8_t m_nTxPower
Number of available transmission power levels.
Definition: wifi-phy.h:1361
void SetPreambleDetectionModel(const Ptr< PreambleDetectionModel > preambleDetectionModel)
Sets the preamble detection model.
Definition: wifi-phy.cc:577
void SetPifs(Time pifs)
Set the PCF Interframe Space (PIFS) for this PHY.
Definition: wifi-phy.cc:677
Time GetSifs(void) const
Return the Short Interframe Space (SIFS) for this PHY.
Definition: wifi-phy.cc:659
static Time GetStartOfPacketDuration(const WifiTxVector &txVector)
Definition: wifi-phy.cc:1276
virtual void StartTx(Ptr< WifiPpdu > ppdu)=0
Time GetAckTxTime(void) const
Return the estimated Ack TX time for this PHY.
Definition: wifi-phy.cc:689
void UnregisterListener(WifiPhyListener *listener)
Definition: wifi-phy.cc:402
void SetRxGain(double gain)
Sets the reception gain (dB).
Definition: wifi-phy.cc:500
void SetMobility(const Ptr< MobilityModel > mobility)
assign a mobility model to this device
Definition: wifi-phy.cc:538
double GetRxGain(void) const
Return the reception gain (dB).
Definition: wifi-phy.cc:507
void SetTxGain(double gain)
Sets the transmission gain (dB).
Definition: wifi-phy.cc:487
uint8_t m_rxSpatialStreams
Number of supported RX spatial streams.
Definition: wifi-phy.h:1372
double m_txPowerEndDbm
Maximum transmission power (dBm)
Definition: wifi-phy.h:1360
void SetOffMode(void)
Put in off mode.
Definition: wifi-phy.cc:1193
double CalculateSnr(const WifiTxVector &txVector, double ber) const
Definition: wifi-phy.cc:613
void Configure80211n(void)
Configure WifiPhy with appropriate channel frequency and supported rates for 802.11n standard.
Definition: wifi-phy.cc:776
bool IsStateSwitching(void) const
Definition: wifi-phy.cc:1816
double GetTxGain(void) const
Return the transmission gain (dB).
Definition: wifi-phy.cc:494
uint8_t GetNTxPower(void) const
Return the number of available transmission power levels.
Definition: wifi-phy.cc:481
Time GetDelayUntilChannelSwitch(void)
Perform any actions necessary when user changes operating channel after initialization.
Definition: wifi-phy.cc:953
void EndReceiveInterBss(void)
For HE receptions only, check and possibly modify the transmit power restriction state at the end of ...
Definition: wifi-phy.cc:1634
double GetCcaEdThreshold(void) const
Return the CCA threshold (dBm).
Definition: wifi-phy.cc:434
double GetRxSensitivity(void) const
Return the receive sensitivity threshold (dBm).
Definition: wifi-phy.cc:421
void RegisterListener(WifiPhyListener *listener)
Definition: wifi-phy.cc:396
Ptr< WifiNetDevice > m_device
Pointer to the device.
Definition: wifi-phy.h:1376
bool IsStateSleep(void) const
Definition: wifi-phy.cc:1822
bool IsStateCcaBusy(void) const
Definition: wifi-phy.cc:1792
bool m_shortPreamble
Flag if short PHY preamble is supported.
Definition: wifi-phy.h:1369
Time m_pifs
PCF Interframe Space (PIFS) duration.
Definition: wifi-phy.h:1351
void SetRxNoiseFigure(double noiseFigureDb)
Sets the RX loss (dB) in the Signal-to-Noise-Ratio due to non-idealities in the receiver.
Definition: wifi-phy.cc:440
double GetTxPowerForTransmission(Ptr< const WifiPpdu > ppdu) const
Compute the transmit power for the next transmission.
Definition: wifi-phy.cc:1923
void SetCapabilitiesChangedCallback(Callback< void > callback)
Definition: wifi-phy.cc:408
void SetReceiveOkCallback(RxOkCallback callback)
Definition: wifi-phy.cc:384
void SetFrameCaptureModel(const Ptr< FrameCaptureModel > frameCaptureModel)
Sets the frame capture model.
Definition: wifi-phy.cc:571
void ResumeFromOff(void)
Resume from off mode.
Definition: wifi-phy.cc:1239
void Configure80211ax(void)
Configure WifiPhy with appropriate channel frequency and supported rates for 802.11ax standard.
Definition: wifi-phy.cc:803
bool m_powerRestricted
Flag whether transmit power is restricted by OBSS PD SR.
Definition: wifi-phy.h:1364
Callback< void > m_capabilitiesChangedCallback
Callback when PHY capabilities changed.
Definition: wifi-phy.h:1385
void AddSupportedChannelWidth(uint16_t width)
Definition: wifi-phy.cc:1138
void NotifyMonitorSniffRx(Ptr< const WifiPsdu > psdu, uint16_t channelFreqMhz, WifiTxVector txVector, SignalNoiseDbm signalNoise, std::vector< bool > statusPerMpdu, uint16_t staId=SU_STA_ID)
Public method used to fire a MonitorSniffer trace for a wifi PSDU being received.
Definition: wifi-phy.cc:1411
virtual void DoChannelSwitch(void)
Actually switch channel based on the stored channel settings.
Definition: wifi-phy.cc:1004
TracedCallback< WifiTxVector, Time > m_phyRxPayloadBeginTrace
The trace source fired when the reception of the PHY payload (PSDU) begins.
Definition: wifi-phy.h:1289
static Time GetPreambleDetectionDuration(void)
Definition: wifi-phy.cc:1270
std::tuple< uint8_t, uint16_t, int, uint8_t > ChannelTuple
Tuple identifying an operating channel.
Definition: wifi-phy.h:832
double m_rxSensitivityW
Receive sensitivity threshold in watts.
Definition: wifi-phy.h:1355
Time GetLastRxEndTime(void) const
Return the end time of the last received packet.
Definition: wifi-phy.cc:1846
uint16_t GetChannelWidth(void) const
Definition: wifi-phy.cc:901
bool IsStateOff(void) const
Definition: wifi-phy.cc:1828
void SetTxPowerStart(double start)
Sets the minimum available transmission power level (dBm).
Definition: wifi-phy.cc:448
virtual int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Definition: wifi-phy.cc:1995
static Time CalculatePhyPreambleAndHeaderDuration(const WifiTxVector &txVector)
Definition: wifi-phy.cc:1300
bool IsModeSupported(WifiMode mode) const
Check if the given WifiMode is supported by the PHY.
Definition: wifi-phy.cc:1662
uint16_t GetFrequency(void) const
Definition: wifi-phy.cc:889
Time m_ackTxTime
estimated Ack TX time
Definition: wifi-phy.h:1352
void NotifyTxDrop(Ptr< const WifiPsdu > psdu)
Public method used to fire a PhyTxDrop trace.
Definition: wifi-phy.cc:1363
void SetErrorRateModel(const Ptr< ErrorRateModel > rate)
Sets the error rate model.
Definition: wifi-phy.cc:557
receive notifications about PHY events.
Class that keeps track of all information about the current PHY operating channel.
uint8_t GetNumber(void) const
Return the channel number identifying the whole operating channel.
bool IsSet(void) const
Return true if a valid channel has been set, false otherwise.
uint8_t GetPrimaryChannelIndex(uint16_t primaryChannelWidth) const
If the operating channel width is a multiple of 20 MHz, return the index of the primary channel of th...
void SetPrimary20Index(uint8_t index)
Set the index of the primary 20 MHz channel (0 indicates the 20 MHz subchannel with the lowest center...
uint16_t GetWidth(void) const
Return the width of the whole operating channel (in MHz).
void Set(uint8_t number, uint16_t frequency, uint16_t width, WifiStandard standard, WifiPhyBand band)
Set the channel according to the specified parameters if a unique frequency channel matches the speci...
uint8_t GetPrimaryChannelNumber(uint16_t primaryChannelWidth, WifiStandard standard) const
Get channel number of the primary channel.
static uint8_t GetDefaultChannelNumber(uint16_t width, WifiStandard standard, WifiPhyBand band)
Get the default channel number of the given width and for the given standard and band.
uint16_t GetFrequency(void) const
Return the center frequency of the operating channel (in MHz).
std::size_t GetNMpdus(void) const
Return the number of MPDUs constituting the PSDU.
Definition: wifi-psdu.cc:319
Ptr< Packet > GetAmpduSubframe(std::size_t i) const
Get a copy of the i-th A-MPDU subframe (includes subframe header, MPDU, and possibly padding)
Definition: wifi-psdu.cc:290
bool IsAggregate(void) const
Return true if the PSDU is an S-MPDU or A-MPDU.
Definition: wifi-psdu.cc:81
bool IsSingle(void) const
Return true if the PSDU is an S-MPDU.
Definition: wifi-psdu.cc:75
Ptr< const Packet > GetPacket(void) const
Get the PSDU as a single packet.
Definition: wifi-psdu.cc:87
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
uint8_t GetTxPowerLevel(void) const
bool IsAggregation(void) const
Checks whether the PSDU contains A-MPDU.
uint8_t GetNssMax(void) const
WifiModulationClass GetModulationClass(void) const
Get the modulation class specified by this TXVECTOR.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
#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:88
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Definition: boolean.cc:121
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Definition: boolean.h:85
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition: double.h:42
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Definition: pointer.h:227
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition: nstime.h:1309
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:45
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1260
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
WifiStandard
Identifies the IEEE 802.11 specifications that a Wifi device can be configured to use.
WifiPhyRxfailureReason
Enumeration of the possible reception failure reasons.
WifiPhyBand
Identifies the PHY band.
Definition: wifi-phy-band.h:33
WifiModulationClass
This enumeration defines the modulation classes per (Table 10-6 "Modulation classes"; IEEE 802....
MpduType
The type of an MPDU.
@ WIFI_STANDARD_80211a
@ WIFI_STANDARD_80211p
@ WIFI_STANDARD_80211n
@ WIFI_STANDARD_80211g
@ WIFI_STANDARD_80211ax
@ WIFI_STANDARD_UNSPECIFIED
@ WIFI_STANDARD_80211ac
@ WIFI_STANDARD_80211b
@ OBSS_PD_CCA_RESET
@ RECEPTION_ABORTED_BY_TX
@ WIFI_PHY_BAND_6GHZ
The 6 GHz band.
Definition: wifi-phy-band.h:39
@ WIFI_PHY_BAND_UNSPECIFIED
Unspecified.
Definition: wifi-phy-band.h:41
@ WIFI_PHY_BAND_2_4GHZ
The 2.4 GHz band.
Definition: wifi-phy-band.h:35
@ WIFI_PHY_BAND_5GHZ
The 5 GHz band.
Definition: wifi-phy-band.h:37
@ WIFI_MOD_CLASS_OFDM
OFDM (Clause 17)
@ WIFI_MOD_CLASS_HR_DSSS
HR/DSSS (Clause 16)
@ WIFI_MOD_CLASS_HT
HT (Clause 19)
@ WIFI_MOD_CLASS_VHT
VHT (Clause 22)
@ WIFI_MOD_CLASS_HE
HE (Clause 27)
@ WIFI_MOD_CLASS_DSSS
DSSS (Clause 15)
@ WIFI_MOD_CLASS_ERP_OFDM
ERP-OFDM (18.4)
@ OFDM_PHY_10_MHZ
Definition: ofdm-phy.h:46
@ OFDM_PHY_5_MHZ
Definition: ofdm-phy.h:47
@ LAST_MPDU_IN_AGGREGATE
The MPDU is the last aggregate in an A-MPDU with multiple MPDUs.
@ NORMAL_MPDU
The MPDU is not part of an A-MPDU.
@ FIRST_MPDU_IN_AGGREGATE
The MPDU is the first aggregate in an A-MPDU with multiple MPDUs, but is not the last aggregate.
@ SINGLE_MPDU
The MPDU is a single MPDU.
@ MIDDLE_MPDU_IN_AGGREGATE
The MPDU is part of an A-MPDU with multiple MPDUs, but is neither the first nor the last aggregate.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
U * PeekPointer(const Ptr< U > &p)
Definition: ptr.h:415
double RatioToDb(double ratio)
Convert from ratio to dB.
Definition: wifi-utils.cc:49
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
double WToDbm(double w)
Convert from Watts to dBm.
Definition: wifi-utils.cc:43
std::pair< uint32_t, uint32_t > WifiSpectrumBand
typedef for a pair of start and stop sub-band indexes
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:139
double DbmToW(double dBm)
Convert from dBm to Watts.
Definition: wifi-utils.cc:37
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:536
std::map< WifiSpectrumBand, double > RxPowerWattPerChannelBand
A map of the received power (Watts) for each band.
Definition: phy-entity.h:75
WifiPhyBand GetDefaultPhyBand(WifiStandard standard)
Get the default PHY band for the given standard.
uint16_t GetDefaultChannelWidth(WifiStandard standard, WifiPhyBand band)
Get the default channel width for the given PHY standard and band.
double DbToRatio(double dB)
Convert from dB to ratio.
Definition: wifi-utils.cc:31
Ptr< const AttributeChecker > MakeEnumChecker(int v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.h:162
mobility
Definition: third.py:107
def start()
Definition: core.py:1853
#define list
MpduInfo structure.
Definition: phy-entity.h:60
MpduType type
type of MPDU
Definition: phy-entity.h:61
uint32_t mpduRefNumber
MPDU ref number.
Definition: phy-entity.h:62
RxSignalInfo structure containing info on the received signal.
Definition: phy-entity.h:67
double rssi
RSSI in dBm.
Definition: phy-entity.h:69
double snr
SNR in linear scale.
Definition: phy-entity.h:68
SignalNoiseDbm structure.
Definition: phy-entity.h:53
@ CCA_BUSY
The PHY layer has sense the medium busy through the CCA mechanism.
@ SWITCHING
The PHY layer is switching to other channel.
@ RX
The PHY layer is receiving a packet.
@ TX
The PHY layer is sending a packet.
@ OFF
The PHY layer is switched off.
@ SLEEP
The PHY layer is sleeping.
@ IDLE
The PHY layer is IDLE.
Declaration of ns3::WifiPpdu class and ns3::WifiConstPsduMap.