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 "ns3/simulator.h"
23 #include "ns3/log.h"
24 #include "ns3/pointer.h"
25 #include "ns3/mobility-model.h"
26 #include "ns3/random-variable-stream.h"
27 #include "wifi-phy.h"
28 #include "wifi-phy-tag.h"
29 #include "ampdu-tag.h"
30 #include "wifi-utils.h"
31 #include "frame-capture-model.h"
33 #include "error-rate-model.h"
34 
35 namespace ns3 {
36 
37 NS_LOG_COMPONENT_DEFINE ("WifiPhy");
38 
39 /****************************************************************
40  * The actual WifiPhy class
41  ****************************************************************/
42 
44 
54 {
55  // 802.11b uses width of 22, while OFDM modes use width of 20
56  { std::make_pair (1, WIFI_PHY_STANDARD_80211b), std::make_pair (2412, 22) },
57  { std::make_pair (1, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2412, 20) },
58  { std::make_pair (2, WIFI_PHY_STANDARD_80211b), std::make_pair (2417, 22) },
59  { std::make_pair (2, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2417, 20) },
60  { std::make_pair (3, WIFI_PHY_STANDARD_80211b), std::make_pair (2422, 22) },
61  { std::make_pair (3, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2422, 20) },
62  { std::make_pair (4, WIFI_PHY_STANDARD_80211b), std::make_pair (2427, 22) },
63  { std::make_pair (4, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2427, 20) },
64  { std::make_pair (5, WIFI_PHY_STANDARD_80211b), std::make_pair (2432, 22) },
65  { std::make_pair (5, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2432, 20) },
66  { std::make_pair (6, WIFI_PHY_STANDARD_80211b), std::make_pair (2437, 22) },
67  { std::make_pair (6, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2437, 20) },
68  { std::make_pair (7, WIFI_PHY_STANDARD_80211b), std::make_pair (2442, 22) },
69  { std::make_pair (7, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2442, 20) },
70  { std::make_pair (8, WIFI_PHY_STANDARD_80211b), std::make_pair (2447, 22) },
71  { std::make_pair (8, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2447, 20) },
72  { std::make_pair (9, WIFI_PHY_STANDARD_80211b), std::make_pair (2452, 22) },
73  { std::make_pair (9, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2452, 20) },
74  { std::make_pair (10, WIFI_PHY_STANDARD_80211b), std::make_pair (2457, 22) },
75  { std::make_pair (10, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2457, 20) },
76  { std::make_pair (11, WIFI_PHY_STANDARD_80211b), std::make_pair (2462, 22) },
77  { std::make_pair (11, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2462, 20) },
78  { std::make_pair (12, WIFI_PHY_STANDARD_80211b), std::make_pair (2467, 22) },
79  { std::make_pair (12, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2467, 20) },
80  { std::make_pair (13, WIFI_PHY_STANDARD_80211b), std::make_pair (2472, 22) },
81  { std::make_pair (13, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2472, 20) },
82  // Only defined for 802.11b
83  { std::make_pair (14, WIFI_PHY_STANDARD_80211b), std::make_pair (2484, 22) },
84 
85  // Now the 5GHz channels; UNSPECIFIED for 802.11a/n/ac/ax channels
86  // 20 MHz channels
87  { std::make_pair (36, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5180, 20) },
88  { std::make_pair (40, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5200, 20) },
89  { std::make_pair (44, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5220, 20) },
90  { std::make_pair (48, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5240, 20) },
91  { std::make_pair (52, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5260, 20) },
92  { std::make_pair (56, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5280, 20) },
93  { std::make_pair (60, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5300, 20) },
94  { std::make_pair (64, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5320, 20) },
95  { std::make_pair (100, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5500, 20) },
96  { std::make_pair (104, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5520, 20) },
97  { std::make_pair (108, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5540, 20) },
98  { std::make_pair (112, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5560, 20) },
99  { std::make_pair (116, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5580, 20) },
100  { std::make_pair (120, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5600, 20) },
101  { std::make_pair (124, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5620, 20) },
102  { std::make_pair (128, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5640, 20) },
103  { std::make_pair (132, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5660, 20) },
104  { std::make_pair (136, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5680, 20) },
105  { std::make_pair (140, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5700, 20) },
106  { std::make_pair (144, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5720, 20) },
107  { std::make_pair (149, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5745, 20) },
108  { std::make_pair (153, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5765, 20) },
109  { std::make_pair (157, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5785, 20) },
110  { std::make_pair (161, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5805, 20) },
111  { std::make_pair (165, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5825, 20) },
112  { std::make_pair (169, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5845, 20) },
113  { std::make_pair (173, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5865, 20) },
114  { std::make_pair (177, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5885, 20) },
115  { std::make_pair (181, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5905, 20) },
116  // 40 MHz channels
117  { std::make_pair (38, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5190, 40) },
118  { std::make_pair (46, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5230, 40) },
119  { std::make_pair (54, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5230, 40) },
120  { std::make_pair (62, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5310, 40) },
121  { std::make_pair (102, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5510, 40) },
122  { std::make_pair (110, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5550, 40) },
123  { std::make_pair (118, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5590, 40) },
124  { std::make_pair (126, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5590, 40) },
125  { std::make_pair (134, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5670, 40) },
126  { std::make_pair (142, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5710, 40) },
127  { std::make_pair (151, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5755, 40) },
128  { std::make_pair (159, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5795, 40) },
129  { std::make_pair (167, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5835, 40) },
130  { std::make_pair (175, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5875, 40) },
131  // 80 MHz channels
132  { std::make_pair (42, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5210, 80) },
133  { std::make_pair (58, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5290, 80) },
134  { std::make_pair (106, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5530, 80) },
135  { std::make_pair (122, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5610, 80) },
136  { std::make_pair (138, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5690, 80) },
137  { std::make_pair (155, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5775, 80) },
138  { std::make_pair (171, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5855, 80) },
139  // 160 MHz channels
140  { std::make_pair (50, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5250, 160) },
141  { std::make_pair (114, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5570, 160) },
142  { std::make_pair (163, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5815, 160) },
143 
144  // 802.11p (10 MHz channels at the 5.855-5.925 band
145  { std::make_pair (172, WIFI_PHY_STANDARD_80211_10MHZ), std::make_pair (5860, 10) },
146  { std::make_pair (174, WIFI_PHY_STANDARD_80211_10MHZ), std::make_pair (5870, 10) },
147  { std::make_pair (176, WIFI_PHY_STANDARD_80211_10MHZ), std::make_pair (5880, 10) },
148  { std::make_pair (178, WIFI_PHY_STANDARD_80211_10MHZ), std::make_pair (5890, 10) },
149  { std::make_pair (180, WIFI_PHY_STANDARD_80211_10MHZ), std::make_pair (5900, 10) },
150  { std::make_pair (182, WIFI_PHY_STANDARD_80211_10MHZ), std::make_pair (5910, 10) },
151  { std::make_pair (184, WIFI_PHY_STANDARD_80211_10MHZ), std::make_pair (5920, 10) }
152 };
153 
154 TypeId
156 {
157  static TypeId tid = TypeId ("ns3::WifiPhy")
158  .SetParent<Object> ()
159  .SetGroupName ("Wifi")
160  .AddAttribute ("Frequency",
161  "The operating center frequency (MHz)",
162  UintegerValue (0),
165  MakeUintegerChecker<uint16_t> ())
166  .AddAttribute ("ChannelWidth",
167  "Whether 5MHz, 10MHz, 20MHz, 22MHz, 40MHz, 80 MHz or 160 MHz.",
168  UintegerValue (20),
171  MakeUintegerChecker<uint16_t> (5, 160))
172  .AddAttribute ("ChannelNumber",
173  "If set to non-zero defined value, will control Frequency and ChannelWidth assignment",
174  UintegerValue (0),
177  MakeUintegerChecker<uint8_t> (0, 196))
178  .AddAttribute ("EnergyDetectionThreshold",
179  "The energy of a received signal should be higher than "
180  "this threshold (dbm) to allow the PHY layer to detect the signal.",
181  DoubleValue (-96.0),
183  MakeDoubleChecker<double> ())
184  .AddAttribute ("CcaMode1Threshold",
185  "The energy of a received signal should be higher than "
186  "this threshold (dbm) to allow the PHY layer to declare CCA BUSY state.",
187  DoubleValue (-99.0),
190  MakeDoubleChecker<double> ())
191  .AddAttribute ("TxGain",
192  "Transmission gain (dB).",
193  DoubleValue (0.0),
196  MakeDoubleChecker<double> ())
197  .AddAttribute ("RxGain",
198  "Reception gain (dB).",
199  DoubleValue (0.0),
202  MakeDoubleChecker<double> ())
203  .AddAttribute ("TxPowerLevels",
204  "Number of transmission power levels available between "
205  "TxPowerStart and TxPowerEnd included.",
206  UintegerValue (1),
208  MakeUintegerChecker<uint8_t> ())
209  .AddAttribute ("TxPowerEnd",
210  "Maximum available transmission level (dbm).",
211  DoubleValue (16.0206),
214  MakeDoubleChecker<double> ())
215  .AddAttribute ("TxPowerStart",
216  "Minimum available transmission level (dbm).",
217  DoubleValue (16.0206),
220  MakeDoubleChecker<double> ())
221  .AddAttribute ("RxNoiseFigure",
222  "Loss (dB) in the Signal-to-Noise-Ratio due to non-idealities in the receiver."
223  " According to Wikipedia (http://en.wikipedia.org/wiki/Noise_figure), this is "
224  "\"the difference in decibels (dB) between"
225  " the noise output of the actual receiver to the noise output of an "
226  " ideal receiver with the same overall gain and bandwidth when the receivers "
227  " are connected to sources at the standard noise temperature T0 (usually 290 K)\".",
228  DoubleValue (7),
230  MakeDoubleChecker<double> ())
231  .AddAttribute ("State",
232  "The state of the PHY layer.",
233  PointerValue (),
235  MakePointerChecker<WifiPhyStateHelper> ())
236  .AddAttribute ("ChannelSwitchDelay",
237  "Delay between two short frames transmitted on different frequencies.",
238  TimeValue (MicroSeconds (250)),
240  MakeTimeChecker ())
241  .AddAttribute ("Antennas",
242  "The number of antennas on the device.",
243  UintegerValue (1),
246  MakeUintegerChecker<uint8_t> (1, 8))
247  .AddAttribute ("MaxSupportedTxSpatialStreams",
248  "The maximum number of supported TX spatial streams."
249  "This parameter is only valuable for 802.11n/ac/ax STAs and APs.",
250  UintegerValue (1),
253  MakeUintegerChecker<uint8_t> (1, 8))
254  .AddAttribute ("MaxSupportedRxSpatialStreams",
255  "The maximum number of supported RX spatial streams."
256  "This parameter is only valuable for 802.11n/ac/ax STAs and APs.",
257  UintegerValue (1),
260  MakeUintegerChecker<uint8_t> (1, 8))
261  .AddAttribute ("ShortGuardEnabled",
262  "Whether or not short guard interval is enabled for HT/VHT transmissions."
263  "This parameter is only valuable for 802.11n/ac/ax STAs and APs.",
264  BooleanValue (false),
268  .AddAttribute ("GuardInterval",
269  "Whether 800ns, 1600ns or 3200ns guard interval is used for HE transmissions."
270  "This parameter is only valuable for 802.11ax STAs and APs.",
271  TimeValue (NanoSeconds (3200)),
274  MakeTimeChecker (NanoSeconds (400), NanoSeconds (3200)))
275  .AddAttribute ("LdpcEnabled",
276  "Whether or not LDPC is enabled (not supported yet!).",
277  BooleanValue (false),
281  .AddAttribute ("STBCEnabled",
282  "Whether or not STBC is enabled (not supported yet!).",
283  BooleanValue (false),
287  .AddAttribute ("GreenfieldEnabled",
288  "Whether or not Greenfield is enabled."
289  "This parameter is only valuable for 802.11n STAs and APs.",
290  BooleanValue (false),
294  .AddAttribute ("ShortPlcpPreambleSupported",
295  "Whether or not short PLCP preamble is supported."
296  "This parameter is only valuable for 802.11b STAs and APs."
297  "Note: 802.11g APs and STAs always support short PLCP preamble.",
298  BooleanValue (false),
302  .AddAttribute ("FrameCaptureModel",
303  "Ptr to an object that implements the frame capture model",
304  PointerValue (),
306  MakePointerChecker <FrameCaptureModel> ())
307  .AddTraceSource ("PhyTxBegin",
308  "Trace source indicating a packet "
309  "has begun transmitting over the channel medium",
311  "ns3::Packet::TracedCallback")
312  .AddTraceSource ("PhyTxEnd",
313  "Trace source indicating a packet "
314  "has been completely transmitted over the channel. "
315  "NOTE: the only official WifiPhy implementation "
316  "available to this date never fires "
317  "this trace source.",
319  "ns3::Packet::TracedCallback")
320  .AddTraceSource ("PhyTxDrop",
321  "Trace source indicating a packet "
322  "has been dropped by the device during transmission",
324  "ns3::Packet::TracedCallback")
325  .AddTraceSource ("PhyRxBegin",
326  "Trace source indicating a packet "
327  "has begun being received from the channel medium "
328  "by the device",
330  "ns3::Packet::TracedCallback")
331  .AddTraceSource ("PhyRxEnd",
332  "Trace source indicating a packet "
333  "has been completely received from the channel medium "
334  "by the device",
336  "ns3::Packet::TracedCallback")
337  .AddTraceSource ("PhyRxDrop",
338  "Trace source indicating a packet "
339  "has been dropped by the device during reception",
341  "ns3::Packet::TracedCallback")
342  .AddTraceSource ("MonitorSnifferRx",
343  "Trace source simulating a wifi device in monitor mode "
344  "sniffing all received frames",
346  "ns3::WifiPhy::MonitorSnifferRxTracedCallback")
347  .AddTraceSource ("MonitorSnifferTx",
348  "Trace source simulating the capability of a wifi device "
349  "in monitor mode to sniff all frames being transmitted",
351  "ns3::WifiPhy::MonitorSnifferTxTracedCallback")
352  ;
353  return tid;
354 }
355 
357  : m_mpdusNum (0),
358  m_plcpSuccess (false),
359  m_txMpduReferenceNumber (0xffffffff),
360  m_rxMpduReferenceNumber (0xffffffff),
361  m_endRxEvent (),
362  m_endPlcpRxEvent (),
363  m_standard (WIFI_PHY_STANDARD_UNSPECIFIED),
364  m_isConstructed (false),
365  m_channelCenterFrequency (0),
366  m_initialFrequency (0),
367  m_frequencyChannelNumberInitialized (false),
368  m_channelWidth (0),
369  m_txSpatialStreams (0),
370  m_rxSpatialStreams (0),
371  m_channelNumber (0),
372  m_initialChannelNumber (0),
373  m_totalAmpduSize (0),
374  m_totalAmpduNumSymbols (0),
375  m_currentEvent (0),
376  m_wifiRadioEnergyModel (0)
377 {
378  NS_LOG_FUNCTION (this);
379  m_random = CreateObject<UniformRandomVariable> ();
380  m_state = CreateObject<WifiPhyStateHelper> ();
381 }
382 
384 {
385  NS_LOG_FUNCTION (this);
386 }
387 
388 void
390 {
391  NS_LOG_FUNCTION (this);
392  m_device = 0;
393  m_mobility = 0;
394  m_state = 0;
396  m_deviceRateSet.clear ();
397  m_deviceMcsSet.clear ();
398 }
399 
400 void
402 {
403  NS_LOG_FUNCTION (this);
404  m_isConstructed = true;
406  {
407  NS_LOG_DEBUG ("Frequency already initialized");
408  return;
409  }
411 }
412 
413 void
415 {
416  m_state->SetReceiveOkCallback (callback);
417 }
418 
419 void
421 {
422  m_state->SetReceiveErrorCallback (callback);
423 }
424 
425 void
427 {
428  m_state->RegisterListener (listener);
429 }
430 
431 void
433 {
434  m_state->UnregisterListener (listener);
435 }
436 
437 void
439 {
441 }
442 
443 void
445 {
446  NS_LOG_FUNCTION (this);
447 
448  NS_ASSERT_MSG (m_frequencyChannelNumberInitialized == false, "Initialization called twice");
449 
450  // If frequency has been set to a non-zero value during attribute
451  // construction phase, the frequency and channel width will drive the
452  // initial configuration. If frequency has not been set, but both
453  // standard and channel number have been set, that pair will instead
454  // drive the configuration, and frequency and channel number will be
455  // aligned
456  if (m_initialFrequency != 0)
457  {
459  }
461  {
463  }
465  {
466  NS_FATAL_ERROR ("Error, ChannelNumber " << +GetChannelNumber () << " was set by user, but neither a standard nor a frequency");
467  }
469 }
470 
471 void
472 WifiPhy::SetEdThreshold (double threshold)
473 {
474  NS_LOG_FUNCTION (this << threshold);
475  m_edThresholdW = DbmToW (threshold);
476 }
477 
478 double
480 {
481  return WToDbm (m_edThresholdW);
482 }
483 
484 void
486 {
487  NS_LOG_FUNCTION (this << threshold);
488  m_ccaMode1ThresholdW = DbmToW (threshold);
489 }
490 
491 double
493 {
494  return WToDbm (m_ccaMode1ThresholdW);
495 }
496 
497 void
498 WifiPhy::SetRxNoiseFigure (double noiseFigureDb)
499 {
500  NS_LOG_FUNCTION (this << noiseFigureDb);
501  m_interference.SetNoiseFigure (DbToRatio (noiseFigureDb));
503 }
504 
505 void
507 {
508  NS_LOG_FUNCTION (this << start);
510 }
511 
512 double
514 {
515  return m_txPowerBaseDbm;
516 }
517 
518 void
520 {
521  NS_LOG_FUNCTION (this << end);
522  m_txPowerEndDbm = end;
523 }
524 
525 double
527 {
528  return m_txPowerEndDbm;
529 }
530 
531 void
533 {
534  NS_LOG_FUNCTION (this << +n);
535  m_nTxPower = n;
536 }
537 
538 uint8_t
540 {
541  return m_nTxPower;
542 }
543 
544 void
545 WifiPhy::SetTxGain (double gain)
546 {
547  NS_LOG_FUNCTION (this << gain);
548  m_txGainDb = gain;
549 }
550 
551 double
552 WifiPhy::GetTxGain (void) const
553 {
554  return m_txGainDb;
555 }
556 
557 void
558 WifiPhy::SetRxGain (double gain)
559 {
560  NS_LOG_FUNCTION (this << gain);
561  m_rxGainDb = gain;
562 }
563 
564 double
565 WifiPhy::GetRxGain (void) const
566 {
567  return m_rxGainDb;
568 }
569 
570 void
571 WifiPhy::SetLdpc (bool ldpc)
572 {
573  NS_LOG_FUNCTION (this << ldpc);
574  m_ldpc = ldpc;
575 }
576 
577 bool
578 WifiPhy::GetLdpc (void) const
579 {
580  return m_ldpc;
581 }
582 
583 void
584 WifiPhy::SetStbc (bool stbc)
585 {
586  NS_LOG_FUNCTION (this << stbc);
587  m_stbc = stbc;
588 }
589 
590 bool
591 WifiPhy::GetStbc (void) const
592 {
593  return m_stbc;
594 }
595 
596 void
597 WifiPhy::SetGreenfield (bool greenfield)
598 {
599  NS_LOG_FUNCTION (this << greenfield);
600  m_greenfield = greenfield;
601 }
602 
603 bool
605 {
606  return m_greenfield;
607 }
608 
609 void
610 WifiPhy::SetShortGuardInterval (bool shortGuardInterval)
611 {
612  NS_LOG_FUNCTION (this << shortGuardInterval);
613  m_shortGuardInterval = shortGuardInterval;
614 }
615 
616 bool
618 {
619  return m_shortGuardInterval;
620 }
621 
622 void
624 {
625  NS_LOG_FUNCTION (this << guardInterval);
626  NS_ASSERT (guardInterval == NanoSeconds (800) || guardInterval == NanoSeconds (1600) || guardInterval == NanoSeconds (3200));
627  m_guardInterval = guardInterval;
628 }
629 
630 Time
632 {
633  return m_guardInterval;
634 }
635 
636 void
638 {
639  NS_LOG_FUNCTION (this << enable);
640  m_shortPreamble = enable;
641 }
642 
643 bool
645 {
646  return m_shortPreamble;
647 }
648 
649 void
651 {
652  m_device = device;
653 }
654 
656 WifiPhy::GetDevice (void) const
657 {
658  return m_device;
659 }
660 
661 void
663 {
665 }
666 
669 {
670  if (m_mobility != 0)
671  {
672  return m_mobility;
673  }
674  else
675  {
676  return m_device->GetNode ()->GetObject<MobilityModel> ();
677  }
678 }
679 
680 void
682 {
685 }
686 
687 void
689 {
690  m_frameCaptureModel = model;
691 }
692 
693 void
695 {
696  m_wifiRadioEnergyModel = wifiRadioEnergyModel;
697 }
698 
699 double
700 WifiPhy::GetPowerDbm (uint8_t power) const
701 {
703  NS_ASSERT (m_nTxPower > 0);
704  double dbm;
705  if (m_nTxPower > 1)
706  {
707  dbm = m_txPowerBaseDbm + power * (m_txPowerEndDbm - m_txPowerBaseDbm) / (m_nTxPower - 1);
708  }
709  else
710  {
711  NS_ASSERT_MSG (m_txPowerBaseDbm == m_txPowerEndDbm, "cannot have TxPowerEnd != TxPowerStart with TxPowerLevels == 1");
712  dbm = m_txPowerBaseDbm;
713  }
714  return dbm;
715 }
716 
717 Time
719 {
720  return m_channelSwitchDelay;
721 }
722 
723 double
724 WifiPhy::CalculateSnr (WifiTxVector txVector, double ber) const
725 {
726  return m_interference.GetErrorRateModel ()->CalculateSnr (txVector, ber);
727 }
728 
729 void
731 {
732  NS_LOG_FUNCTION (this << standard);
733  switch (standard)
734  {
736  SetChannelWidth (20);
737  SetFrequency (5180);
738  // Channel number should be aligned by SetFrequency () to 36
739  NS_ASSERT (GetChannelNumber () == 36);
740  break;
742  SetChannelWidth (22);
743  SetFrequency (2412);
744  // Channel number should be aligned by SetFrequency () to 1
745  NS_ASSERT (GetChannelNumber () == 1);
746  break;
748  SetChannelWidth (20);
749  SetFrequency (2412);
750  // Channel number should be aligned by SetFrequency () to 1
751  NS_ASSERT (GetChannelNumber () == 1);
752  break;
754  SetChannelWidth (10);
755  SetFrequency (5860);
756  // Channel number should be aligned by SetFrequency () to 172
757  NS_ASSERT (GetChannelNumber () == 172);
758  break;
760  SetChannelWidth (5);
761  SetFrequency (5860);
762  // Channel number should be aligned by SetFrequency () to 0
763  NS_ASSERT (GetChannelNumber () == 0);
764  break;
766  SetChannelWidth (20);
767  SetFrequency (5180);
768  // Channel number should be aligned by SetFrequency () to 36
769  NS_ASSERT (GetChannelNumber () == 36);
770  break;
772  SetChannelWidth (20);
773  SetFrequency (2412);
774  // Channel number should be aligned by SetFrequency () to 1
775  NS_ASSERT (GetChannelNumber () == 1);
776  break;
778  SetChannelWidth (20);
779  SetFrequency (5180);
780  // Channel number should be aligned by SetFrequency () to 36
781  NS_ASSERT (GetChannelNumber () == 36);
782  break;
784  SetChannelWidth (80);
785  SetFrequency (5210);
786  // Channel number should be aligned by SetFrequency () to 42
787  NS_ASSERT (GetChannelNumber () == 42);
788  break;
790  SetChannelWidth (20);
791  SetFrequency (2412);
792  // Channel number should be aligned by SetFrequency () to 1
793  NS_ASSERT (GetChannelNumber () == 1);
794  break;
796  SetChannelWidth (80);
797  SetFrequency (5210);
798  // Channel number should be aligned by SetFrequency () to 42
799  NS_ASSERT (GetChannelNumber () == 42);
800  break;
802  default:
803  NS_LOG_WARN ("Configuring unspecified standard; performing no action");
804  break;
805  }
806 }
807 
808 void
810 {
811  NS_LOG_FUNCTION (this);
812 
821 }
822 
823 void
825 {
826  NS_LOG_FUNCTION (this);
827 
832 }
833 
834 void
836 {
837  NS_LOG_FUNCTION (this);
838  Configure80211b ();
839 
848 }
849 
850 void
852 {
853  NS_LOG_FUNCTION (this);
854 
863 }
864 
865 void
867 {
868  NS_LOG_FUNCTION (this);
869 
878 }
879 
880 void
882 {
883  NS_LOG_FUNCTION (this);
884 
890 }
891 
892 void
894 {
895  NS_LOG_FUNCTION (this);
896 
897  bool htFound = false;
898  for (std::vector<uint8_t>::size_type i = 0; i < m_bssMembershipSelectorSet.size (); i++)
899  {
901  {
902  htFound = true;
903  break;
904  }
905  }
906  if (htFound)
907  {
908  // erase all HtMcs modes from deviceMcsSet
909  std::size_t index = m_deviceMcsSet.size () - 1;
910  for (std::vector<WifiMode>::reverse_iterator rit = m_deviceMcsSet.rbegin (); rit != m_deviceMcsSet.rend (); ++rit, --index)
911  {
912  if (m_deviceMcsSet[index].GetModulationClass () == WIFI_MOD_CLASS_HT)
913  {
914  m_deviceMcsSet.erase (m_deviceMcsSet.begin () + index);
915  }
916  }
917  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs0 ());
918  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs1 ());
919  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs2 ());
920  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs3 ());
921  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs4 ());
922  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs5 ());
923  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs6 ());
924  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs7 ());
926  {
927  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs8 ());
928  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs9 ());
929  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs10 ());
930  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs11 ());
931  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs12 ());
932  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs13 ());
933  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs14 ());
934  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs15 ());
935  }
937  {
938  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs16 ());
939  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs17 ());
940  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs18 ());
941  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs19 ());
942  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs20 ());
943  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs21 ());
944  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs22 ());
945  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs23 ());
946  }
948  {
949  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs24 ());
950  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs25 ());
951  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs26 ());
952  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs27 ());
953  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs28 ());
954  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs29 ());
955  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs30 ());
956  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs31 ());
957  }
958  }
959 }
960 
961 void
963 {
964  NS_LOG_FUNCTION (this);
965  if (Is2_4Ghz (GetFrequency ()))
966  {
967  Configure80211b ();
968  Configure80211g ();
969  }
970  if (Is5Ghz (GetFrequency ()))
971  {
972  Configure80211a ();
973  }
976 }
977 
978 void
980 {
981  NS_LOG_FUNCTION (this);
982  Configure80211n ();
983 
984  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs0 ());
985  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs1 ());
986  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs2 ());
987  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs3 ());
988  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs4 ());
989  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs5 ());
990  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs6 ());
991  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs7 ());
992  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs8 ());
993  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs9 ());
994 
996 }
997 
998 void
1000 {
1001  NS_LOG_FUNCTION (this);
1002  Configure80211n ();
1003  if (Is5Ghz (GetFrequency ()))
1004  {
1005  Configure80211ac ();
1006  }
1007  m_deviceMcsSet.push_back (WifiPhy::GetHeMcs0 ());
1008  m_deviceMcsSet.push_back (WifiPhy::GetHeMcs1 ());
1009  m_deviceMcsSet.push_back (WifiPhy::GetHeMcs2 ());
1010  m_deviceMcsSet.push_back (WifiPhy::GetHeMcs3 ());
1011  m_deviceMcsSet.push_back (WifiPhy::GetHeMcs4 ());
1012  m_deviceMcsSet.push_back (WifiPhy::GetHeMcs5 ());
1013  m_deviceMcsSet.push_back (WifiPhy::GetHeMcs6 ());
1014  m_deviceMcsSet.push_back (WifiPhy::GetHeMcs7 ());
1015  m_deviceMcsSet.push_back (WifiPhy::GetHeMcs8 ());
1016  m_deviceMcsSet.push_back (WifiPhy::GetHeMcs9 ());
1017  m_deviceMcsSet.push_back (WifiPhy::GetHeMcs10 ());
1018  m_deviceMcsSet.push_back (WifiPhy::GetHeMcs11 ());
1019 
1020  m_bssMembershipSelectorSet.push_back (HE_PHY);
1021 }
1022 
1023 bool
1024 WifiPhy::DefineChannelNumber (uint8_t channelNumber, WifiPhyStandard standard, uint16_t frequency, uint16_t channelWidth)
1025 {
1026  NS_LOG_FUNCTION (this << +channelNumber << standard << frequency << channelWidth);
1027  ChannelNumberStandardPair p = std::make_pair (channelNumber, standard);
1028  ChannelToFrequencyWidthMap::const_iterator it;
1029  it = m_channelToFrequencyWidth.find (p);
1030  if (it != m_channelToFrequencyWidth.end ())
1031  {
1032  NS_LOG_DEBUG ("channel number/standard already defined; returning false");
1033  return false;
1034  }
1035  FrequencyWidthPair f = std::make_pair (frequency, channelWidth);
1037  return true;
1038 }
1039 
1040 uint8_t
1041 WifiPhy::FindChannelNumberForFrequencyWidth (uint16_t frequency, uint16_t width) const
1042 {
1043  NS_LOG_FUNCTION (this << frequency << width);
1044  bool found = false;
1045  FrequencyWidthPair f = std::make_pair (frequency, width);
1046  ChannelToFrequencyWidthMap::const_iterator it = m_channelToFrequencyWidth.begin ();
1047  while (it != m_channelToFrequencyWidth.end ())
1048  {
1049  if (it->second == f)
1050  {
1051  found = true;
1052  break;
1053  }
1054  ++it;
1055  }
1056  if (found)
1057  {
1058  NS_LOG_DEBUG ("Found, returning " << +it->first.first);
1059  return (it->first.first);
1060  }
1061  else
1062  {
1063  NS_LOG_DEBUG ("Not found, returning 0");
1064  return 0;
1065  }
1066 }
1067 
1068 void
1070 {
1071  NS_LOG_FUNCTION (this << standard);
1072  // If the user has configured both Frequency and ChannelNumber, Frequency
1073  // takes precedence
1074  if (GetFrequency () != 0)
1075  {
1076  // If Frequency is already set, then see whether a ChannelNumber can
1077  // be found that matches Frequency and ChannelWidth. If so, configure
1078  // the ChannelNumber to that channel number. If not, set ChannelNumber to zero.
1079  NS_LOG_DEBUG ("Frequency set; checking whether a channel number corresponds");
1080  uint8_t channelNumberSearched = FindChannelNumberForFrequencyWidth (GetFrequency (), GetChannelWidth ());
1081  if (channelNumberSearched)
1082  {
1083  NS_LOG_DEBUG ("Channel number found; setting to " << +channelNumberSearched);
1084  SetChannelNumber (channelNumberSearched);
1085  }
1086  else
1087  {
1088  NS_LOG_DEBUG ("Channel number not found; setting to zero");
1089  SetChannelNumber (0);
1090  }
1091  }
1092  else if (GetChannelNumber () != 0)
1093  {
1094  // If the channel number is known for this particular standard or for
1095  // the unspecified standard, configure using the known values;
1096  // otherwise, this is a configuration error
1097  NS_LOG_DEBUG ("Configuring for channel number " << +GetChannelNumber ());
1099  if (f.first == 0)
1100  {
1101  // the specific pair of number/standard is not known
1102  NS_LOG_DEBUG ("Falling back to check WIFI_PHY_STANDARD_UNSPECIFIED");
1104  }
1105  if (f.first == 0)
1106  {
1107  NS_FATAL_ERROR ("Error, ChannelNumber " << +GetChannelNumber () << " is unknown for this standard");
1108  }
1109  else
1110  {
1111  NS_LOG_DEBUG ("Setting frequency to " << f.first << "; width to " << +f.second);
1112  SetFrequency (f.first);
1113  SetChannelWidth (f.second);
1114  }
1115  }
1116 }
1117 
1118 void
1120 {
1121  NS_LOG_FUNCTION (this << standard);
1122  m_standard = standard;
1123  m_isConstructed = true;
1125  {
1127  }
1128  if (GetFrequency () == 0 && GetChannelNumber () == 0)
1129  {
1130  ConfigureDefaultsForStandard (standard);
1131  }
1132  else
1133  {
1134  // The user has configured either (or both) Frequency or ChannelNumber
1135  ConfigureChannelForStandard (standard);
1136  }
1137  switch (standard)
1138  {
1140  Configure80211a ();
1141  break;
1143  Configure80211b ();
1144  break;
1146  Configure80211g ();
1147  break;
1150  break;
1153  break;
1155  ConfigureHolland ();
1156  break;
1158  Configure80211n ();
1159  break;
1161  Configure80211n ();
1162  break;
1164  Configure80211ac ();
1165  break;
1167  Configure80211ax ();
1168  break;
1170  Configure80211ax ();
1171  break;
1173  default:
1174  NS_ASSERT (false);
1175  break;
1176  }
1177 }
1178 
1181 {
1182  return m_standard;
1183 }
1184 
1185 void
1186 WifiPhy::SetFrequency (uint16_t frequency)
1187 {
1188  NS_LOG_FUNCTION (this << frequency);
1189  if (m_isConstructed == false)
1190  {
1191  NS_LOG_DEBUG ("Saving frequency configuration for initialization");
1192  m_initialFrequency = frequency;
1193  return;
1194  }
1195  if (GetFrequency () == frequency)
1196  {
1197  NS_LOG_DEBUG ("No frequency change requested");
1198  return;
1199  }
1200  if (frequency == 0)
1201  {
1202  DoFrequencySwitch (0);
1203  NS_LOG_DEBUG ("Setting frequency and channel number to zero");
1205  m_channelNumber = 0;
1206  return;
1207  }
1208  // If the user has configured both Frequency and ChannelNumber, Frequency
1209  // takes precedence. Lookup the channel number corresponding to the
1210  // requested frequency.
1211  uint8_t nch = FindChannelNumberForFrequencyWidth (frequency, GetChannelWidth ());
1212  if (nch != 0)
1213  {
1214  NS_LOG_DEBUG ("Setting frequency " << frequency << " corresponds to channel " << +nch);
1215  if (DoFrequencySwitch (frequency))
1216  {
1217  NS_LOG_DEBUG ("Channel frequency switched to " << frequency << "; channel number to " << +nch);
1218  m_channelCenterFrequency = frequency;
1219  m_channelNumber = nch;
1220  }
1221  else
1222  {
1223  NS_LOG_DEBUG ("Suppressing reassignment of frequency");
1224  }
1225  }
1226  else
1227  {
1228  NS_LOG_DEBUG ("Channel number is unknown for frequency " << frequency);
1229  if (DoFrequencySwitch (frequency))
1230  {
1231  NS_LOG_DEBUG ("Channel frequency switched to " << frequency << "; channel number to " << 0);
1232  m_channelCenterFrequency = frequency;
1233  m_channelNumber = 0;
1234  }
1235  else
1236  {
1237  NS_LOG_DEBUG ("Suppressing reassignment of frequency");
1238  }
1239  }
1240 }
1241 
1242 uint16_t
1244 {
1245  return m_channelCenterFrequency;
1246 }
1247 
1248 void
1249 WifiPhy::SetChannelWidth (uint16_t channelwidth)
1250 {
1251  NS_LOG_FUNCTION (this << channelwidth);
1252  NS_ASSERT_MSG (channelwidth == 5 || channelwidth == 10 || channelwidth == 20 || channelwidth == 22 || channelwidth == 40 || channelwidth == 80 || channelwidth == 160, "wrong channel width value");
1253  bool changed = (m_channelWidth == channelwidth);
1254  m_channelWidth = channelwidth;
1255  AddSupportedChannelWidth (channelwidth);
1256  if (changed && !m_capabilitiesChangedCallback.IsNull ())
1257  {
1259  }
1260 }
1261 
1262 uint16_t
1264 {
1265  return m_channelWidth;
1266 }
1267 
1268 void
1270 {
1271  NS_ASSERT_MSG (antennas > 0 && antennas <= 4, "unsupported number of antennas");
1272  m_numberOfAntennas = antennas;
1274 }
1275 
1276 uint8_t
1278 {
1279  return m_numberOfAntennas;
1280 }
1281 
1282 void
1284 {
1285  NS_ASSERT (streams <= GetNumberOfAntennas ());
1286  bool changed = (m_txSpatialStreams == streams);
1287  m_txSpatialStreams = streams;
1289  if (changed && !m_capabilitiesChangedCallback.IsNull ())
1290  {
1292  }
1293 }
1294 
1295 uint8_t
1297 {
1298  return m_txSpatialStreams;
1299 }
1300 
1301 void
1303 {
1304  NS_ASSERT (streams <= GetNumberOfAntennas ());
1305  bool changed = (m_rxSpatialStreams == streams);
1306  m_rxSpatialStreams = streams;
1307  if (changed && !m_capabilitiesChangedCallback.IsNull ())
1308  {
1310  }
1311 }
1312 
1313 uint8_t
1315 {
1316  return m_rxSpatialStreams;
1317 }
1318 
1319 uint8_t
1321 {
1322  return static_cast<uint8_t> (m_bssMembershipSelectorSet.size ());
1323 }
1324 
1325 uint8_t
1326 WifiPhy::GetBssMembershipSelector (uint8_t selector) const
1327 {
1328  return m_bssMembershipSelectorSet[selector];
1329 }
1330 
1331 void
1333 {
1334  NS_LOG_FUNCTION (this << width);
1335  for (std::vector<uint32_t>::size_type i = 0; i != m_supportedChannelWidthSet.size (); i++)
1336  {
1337  if (m_supportedChannelWidthSet[i] == width)
1338  {
1339  return;
1340  }
1341  }
1342  NS_LOG_FUNCTION ("Adding " << width << " to supported channel width set");
1343  m_supportedChannelWidthSet.push_back (width);
1344 }
1345 
1346 std::vector<uint16_t>
1348 {
1350 }
1351 
1354 {
1355  ChannelNumberStandardPair p = std::make_pair (channelNumber, standard);
1357  return f;
1358 }
1359 
1360 void
1362 {
1363  NS_LOG_FUNCTION (this << +nch);
1364  if (m_isConstructed == false)
1365  {
1366  NS_LOG_DEBUG ("Saving channel number configuration for initialization");
1367  m_initialChannelNumber = nch;
1368  return;
1369  }
1370  if (GetChannelNumber () == nch)
1371  {
1372  NS_LOG_DEBUG ("No channel change requested");
1373  return;
1374  }
1375  if (nch == 0)
1376  {
1377  // This case corresponds to when there is not a known channel
1378  // number for the requested frequency. There is no need to call
1379  // DoChannelSwitch () because DoFrequencySwitch () should have been
1380  // called by the client
1381  NS_LOG_DEBUG ("Setting channel number to zero");
1382  m_channelNumber = 0;
1383  return;
1384  }
1385 
1386  // First make sure that the channel number is defined for the standard
1387  // in use
1389  if (f.first == 0)
1390  {
1392  }
1393  if (f.first != 0)
1394  {
1395  if (DoChannelSwitch (nch))
1396  {
1397  NS_LOG_DEBUG ("Setting frequency to " << f.first << "; width to " << +f.second);
1398  m_channelCenterFrequency = f.first;
1399  SetChannelWidth (f.second);
1400  m_channelNumber = nch;
1401  }
1402  else
1403  {
1404  // Subclass may have suppressed (e.g. waiting for state change)
1405  NS_LOG_DEBUG ("Channel switch suppressed");
1406  }
1407  }
1408  else
1409  {
1410  NS_FATAL_ERROR ("Frequency not found for channel number " << +nch);
1411  }
1412 }
1413 
1414 uint8_t
1416 {
1417  return m_channelNumber;
1418 }
1419 
1420 bool
1422 {
1423  if (!IsInitialized ())
1424  {
1425  //this is not channel switch, this is initialization
1426  NS_LOG_DEBUG ("initialize to channel " << +nch);
1427  return true;
1428  }
1429 
1431  switch (m_state->GetState ())
1432  {
1433  case WifiPhyState::RX:
1434  NS_LOG_DEBUG ("drop packet because of channel switching while reception");
1436  m_endRxEvent.Cancel ();
1437  goto switchChannel;
1438  break;
1439  case WifiPhyState::TX:
1440  NS_LOG_DEBUG ("channel switching postponed until end of current transmission");
1442  break;
1444  case WifiPhyState::IDLE:
1445  goto switchChannel;
1446  break;
1447  case WifiPhyState::SLEEP:
1448  NS_LOG_DEBUG ("channel switching ignored in sleep mode");
1449  break;
1450  default:
1451  NS_ASSERT (false);
1452  break;
1453  }
1454 
1455  return false;
1456 
1457 switchChannel:
1458 
1459  NS_LOG_DEBUG ("switching channel " << +GetChannelNumber () << " -> " << +nch);
1460  m_state->SwitchToChannelSwitching (GetChannelSwitchDelay ());
1462  /*
1463  * Needed here to be able to correctly sensed the medium for the first
1464  * time after the switching. The actual switching is not performed until
1465  * after m_channelSwitchDelay. Packets received during the switching
1466  * state are added to the event list and are employed later to figure
1467  * out the state of the medium after the switching.
1468  */
1469  return true;
1470 }
1471 
1472 bool
1473 WifiPhy::DoFrequencySwitch (uint16_t frequency)
1474 {
1475  if (!IsInitialized ())
1476  {
1477  //this is not channel switch, this is initialization
1478  NS_LOG_DEBUG ("start at frequency " << frequency);
1479  return true;
1480  }
1481 
1483  switch (m_state->GetState ())
1484  {
1485  case WifiPhyState::RX:
1486  NS_LOG_DEBUG ("drop packet because of channel/frequency switching while reception");
1488  m_endRxEvent.Cancel ();
1489  goto switchFrequency;
1490  break;
1491  case WifiPhyState::TX:
1492  NS_LOG_DEBUG ("channel/frequency switching postponed until end of current transmission");
1494  break;
1496  case WifiPhyState::IDLE:
1497  goto switchFrequency;
1498  break;
1499  case WifiPhyState::SLEEP:
1500  NS_LOG_DEBUG ("frequency switching ignored in sleep mode");
1501  break;
1502  default:
1503  NS_ASSERT (false);
1504  break;
1505  }
1506 
1507  return false;
1508 
1509 switchFrequency:
1510 
1511  NS_LOG_DEBUG ("switching frequency " << GetFrequency () << " -> " << frequency);
1512  m_state->SwitchToChannelSwitching (GetChannelSwitchDelay ());
1514  /*
1515  * Needed here to be able to correctly sensed the medium for the first
1516  * time after the switching. The actual switching is not performed until
1517  * after m_channelSwitchDelay. Packets received during the switching
1518  * state are added to the event list and are employed later to figure
1519  * out the state of the medium after the switching.
1520  */
1521  return true;
1522 }
1523 
1524 void
1526 {
1527  NS_LOG_FUNCTION (this);
1528  switch (m_state->GetState ())
1529  {
1530  case WifiPhyState::TX:
1531  NS_LOG_DEBUG ("setting sleep mode postponed until end of current transmission");
1533  break;
1534  case WifiPhyState::RX:
1535  NS_LOG_DEBUG ("setting sleep mode postponed until end of current reception");
1537  break;
1539  NS_LOG_DEBUG ("setting sleep mode postponed until end of channel switching");
1541  break;
1543  case WifiPhyState::IDLE:
1544  NS_LOG_DEBUG ("setting sleep mode");
1545  m_state->SwitchToSleep ();
1546  break;
1547  case WifiPhyState::SLEEP:
1548  NS_LOG_DEBUG ("already in sleep mode");
1549  break;
1550  default:
1551  NS_ASSERT (false);
1552  break;
1553  }
1554 }
1555 
1556 void
1558 {
1559  NS_LOG_FUNCTION (this);
1560  switch (m_state->GetState ())
1561  {
1562  case WifiPhyState::RX:
1564  m_endRxEvent.Cancel ();
1565  case WifiPhyState::TX:
1568  case WifiPhyState::IDLE:
1569  case WifiPhyState::SLEEP:
1570  m_state->SwitchToOff ();
1571  break;
1572  default:
1573  NS_ASSERT (false);
1574  break;
1575  }
1576 }
1577 
1578 void
1580 {
1581  NS_LOG_FUNCTION (this);
1582  switch (m_state->GetState ())
1583  {
1584  case WifiPhyState::TX:
1585  case WifiPhyState::RX:
1586  case WifiPhyState::IDLE:
1589  {
1590  NS_LOG_DEBUG ("not in sleep mode, there is nothing to resume");
1591  break;
1592  }
1593  case WifiPhyState::SLEEP:
1594  {
1595  NS_LOG_DEBUG ("resuming from sleep mode");
1597  m_state->SwitchFromSleep (delayUntilCcaEnd);
1598  break;
1599  }
1600  default:
1601  {
1602  NS_ASSERT (false);
1603  break;
1604  }
1605  }
1606 }
1607 
1608 void
1610 {
1611  NS_LOG_FUNCTION (this);
1612  switch (m_state->GetState ())
1613  {
1614  case WifiPhyState::TX:
1615  case WifiPhyState::RX:
1616  case WifiPhyState::IDLE:
1619  case WifiPhyState::SLEEP:
1620  {
1621  NS_LOG_DEBUG ("not in off mode, there is nothing to resume");
1622  break;
1623  }
1624  case WifiPhyState::OFF:
1625  {
1626  NS_LOG_DEBUG ("resuming from off mode");
1628  m_state->SwitchFromOff (delayUntilCcaEnd);
1629  break;
1630  }
1631  default:
1632  {
1633  NS_ASSERT (false);
1634  break;
1635  }
1636  }
1637 }
1638 
1639 WifiMode
1641 {
1642  return WifiPhy::GetHtMcs0 ();
1643 }
1644 
1645 WifiMode
1647 {
1648  return WifiPhy::GetVhtMcs0 ();
1649 }
1650 
1651 WifiMode
1653 {
1654  return WifiPhy::GetHeMcs0 ();
1655 }
1656 
1657 Time
1659 {
1660  uint8_t Ndltf, Neltf;
1661  //We suppose here that STBC = 0.
1662  //If STBC > 0, we need a different mapping between Nss and Nltf (IEEE 802.11n-2012 standard, page 1682).
1663  if (txVector.GetNss () < 3)
1664  {
1665  Ndltf = txVector.GetNss ();
1666  }
1667  else if (txVector.GetNss () < 5)
1668  {
1669  Ndltf = 4;
1670  }
1671  else if (txVector.GetNss () < 7)
1672  {
1673  Ndltf = 6;
1674  }
1675  else
1676  {
1677  Ndltf = 8;
1678  }
1679 
1680  if (txVector.GetNess () < 3)
1681  {
1682  Neltf = txVector.GetNess ();
1683  }
1684  else
1685  {
1686  Neltf = 4;
1687  }
1688 
1689  switch (txVector.GetPreambleType ())
1690  {
1691  case WIFI_PREAMBLE_HT_MF:
1692  return MicroSeconds (4 + (4 * Ndltf) + (4 * Neltf));
1693  case WIFI_PREAMBLE_HT_GF:
1694  return MicroSeconds ((4 * Ndltf) + (4 * Neltf));
1695  case WIFI_PREAMBLE_VHT:
1696  return MicroSeconds (4 + (4 * Ndltf));
1697  case WIFI_PREAMBLE_HE_SU:
1698  return MicroSeconds (4 + (8 * Ndltf));
1699  default:
1700  return MicroSeconds (0);
1701  }
1702 }
1703 
1704 Time
1706 {
1707  switch (preamble)
1708  {
1709  case WIFI_PREAMBLE_HT_MF:
1710  case WIFI_PREAMBLE_HT_GF:
1711  //HT-SIG
1712  return MicroSeconds (8);
1713  default:
1714  //no HT-SIG for non HT
1715  return MicroSeconds (0);
1716  }
1717 }
1718 
1719 Time
1721 {
1722  switch (preamble)
1723  {
1724  case WIFI_PREAMBLE_VHT:
1725  case WIFI_PREAMBLE_HE_SU:
1726  //VHT-SIG-A1 and HE-SIG-A1
1727  return MicroSeconds (4);
1728  default:
1729  // no SIG-A1
1730  return MicroSeconds (0);
1731  }
1732 }
1733 
1734 Time
1736 {
1737  switch (preamble)
1738  {
1739  case WIFI_PREAMBLE_VHT:
1740  case WIFI_PREAMBLE_HE_SU:
1741  //VHT-SIG-A2 and HE-SIG-A2
1742  return MicroSeconds (4);
1743  default:
1744  // no SIG-A2
1745  return MicroSeconds (0);
1746  }
1747 }
1748 
1749 Time
1751 {
1752  switch (preamble)
1753  {
1754  case WIFI_PREAMBLE_VHT:
1755  //VHT-SIG-B
1756  return MicroSeconds (4);
1757  case WIFI_PREAMBLE_HE_SU:
1758  //HE-SIG-B: MU not supported so HE-SIG-B not used
1759  return MicroSeconds (0);
1760  default:
1761  // no SIG-B
1762  return MicroSeconds (0);
1763  }
1764 }
1765 
1766 WifiMode
1768 {
1769  switch (txVector.GetMode ().GetModulationClass ())
1770  {
1771  case WIFI_MOD_CLASS_OFDM:
1772  case WIFI_MOD_CLASS_HT:
1773  case WIFI_MOD_CLASS_VHT:
1774  case WIFI_MOD_CLASS_HE:
1775  switch (txVector.GetChannelWidth ())
1776  {
1777  case 5:
1779  case 10:
1781  case 20:
1782  case 40:
1783  case 80:
1784  case 160:
1785  default:
1786  //(Section 18.3.2 "PLCP frame format"; IEEE Std 802.11-2012)
1787  //actually this is only the first part of the PlcpHeader,
1788  //because the last 16 bits of the PlcpHeader are using the
1789  //same mode of the payload
1790  return WifiPhy::GetOfdmRate6Mbps ();
1791  }
1793  return WifiPhy::GetErpOfdmRate6Mbps ();
1794  case WIFI_MOD_CLASS_DSSS:
1796  if (txVector.GetPreambleType () == WIFI_PREAMBLE_LONG || txVector.GetMode () == WifiPhy::GetDsssRate1Mbps ())
1797  {
1798  //(Section 16.2.3 "PLCP field definitions" and Section 17.2.2.2 "Long PPDU format"; IEEE Std 802.11-2012)
1799  return WifiPhy::GetDsssRate1Mbps ();
1800  }
1801  else //WIFI_PREAMBLE_SHORT
1802  {
1803  //(Section 17.2.2.3 "Short PPDU format"; IEEE Std 802.11-2012)
1804  return WifiPhy::GetDsssRate2Mbps ();
1805  }
1806  default:
1807  NS_FATAL_ERROR ("unsupported modulation class");
1808  return WifiMode ();
1809  }
1810 }
1811 
1812 Time
1814 {
1815  WifiPreamble preamble = txVector.GetPreambleType ();
1816  if (preamble == WIFI_PREAMBLE_NONE)
1817  {
1818  return MicroSeconds (0);
1819  }
1820  switch (txVector.GetMode ().GetModulationClass ())
1821  {
1822  case WIFI_MOD_CLASS_OFDM:
1823  {
1824  switch (txVector.GetChannelWidth ())
1825  {
1826  case 20:
1827  default:
1828  //(Section 18.3.3 "PLCP preamble (SYNC))" and Figure 18-4 "OFDM training structure"; IEEE Std 802.11-2012)
1829  //also (Section 18.3.2.4 "Timing related parameters" Table 18-5 "Timing-related parameters"; IEEE Std 802.11-2012)
1830  //We return the duration of the SIGNAL field only, since the
1831  //SERVICE field (which strictly speaking belongs to the PLCP
1832  //header, see Section 18.3.2 and Figure 18-1) is sent using the
1833  //payload mode.
1834  return MicroSeconds (4);
1835  case 10:
1836  //(Section 18.3.2.4 "Timing related parameters" Table 18-5 "Timing-related parameters"; IEEE Std 802.11-2012)
1837  return MicroSeconds (8);
1838  case 5:
1839  //(Section 18.3.2.4 "Timing related parameters" Table 18-5 "Timing-related parameters"; IEEE Std 802.11-2012)
1840  return MicroSeconds (16);
1841  }
1842  }
1843  case WIFI_MOD_CLASS_HT:
1844  {
1845  //L-SIG
1846  //IEEE 802.11n Figure 20.1
1847  switch (preamble)
1848  {
1849  case WIFI_PREAMBLE_HT_MF:
1850  default:
1851  return MicroSeconds (4);
1852  case WIFI_PREAMBLE_HT_GF:
1853  return MicroSeconds (0);
1854  }
1855  }
1857  case WIFI_MOD_CLASS_VHT:
1858  //L-SIG
1859  return MicroSeconds (4);
1860  case WIFI_MOD_CLASS_HE:
1861  //LSIG + R-LSIG
1862  return MicroSeconds (8);
1863  case WIFI_MOD_CLASS_DSSS:
1865  if ((preamble == WIFI_PREAMBLE_SHORT) && (txVector.GetMode ().GetDataRate (22) > 1000000))
1866  {
1867  //(Section 17.2.2.3 "Short PPDU format" and Figure 17-2 "Short PPDU format"; IEEE Std 802.11-2012)
1868  return MicroSeconds (24);
1869  }
1870  else //WIFI_PREAMBLE_LONG
1871  {
1872  //(Section 17.2.2.2 "Long PPDU format" and Figure 17-1 "Short PPDU format"; IEEE Std 802.11-2012)
1873  return MicroSeconds (48);
1874  }
1875  default:
1876  NS_FATAL_ERROR ("unsupported modulation class");
1877  return MicroSeconds (0);
1878  }
1879 }
1880 
1881 Time
1883 {
1884  WifiPreamble preamble = txVector.GetPreambleType ();
1885  if (preamble == WIFI_PREAMBLE_NONE)
1886  {
1887  return MicroSeconds (0);
1888  }
1889  switch (txVector.GetMode ().GetModulationClass ())
1890  {
1891  case WIFI_MOD_CLASS_OFDM:
1892  {
1893  switch (txVector.GetChannelWidth ())
1894  {
1895  case 20:
1896  default:
1897  //(Section 18.3.3 "PLCP preamble (SYNC))" Figure 18-4 "OFDM training structure"
1898  //also Section 18.3.2.3 "Modulation-dependent parameters" Table 18-4 "Modulation-dependent parameters"; IEEE Std 802.11-2012)
1899  return MicroSeconds (16);
1900  case 10:
1901  //(Section 18.3.3 "PLCP preamble (SYNC))" Figure 18-4 "OFDM training structure"
1902  //also Section 18.3.2.3 "Modulation-dependent parameters" Table 18-4 "Modulation-dependent parameters"; IEEE Std 802.11-2012)
1903  return MicroSeconds (32);
1904  case 5:
1905  //(Section 18.3.3 "PLCP preamble (SYNC))" Figure 18-4 "OFDM training structure"
1906  //also Section 18.3.2.3 "Modulation-dependent parameters" Table 18-4 "Modulation-dependent parameters"; IEEE Std 802.11-2012)
1907  return MicroSeconds (64);
1908  }
1909  }
1910  case WIFI_MOD_CLASS_HT:
1911  case WIFI_MOD_CLASS_VHT:
1912  case WIFI_MOD_CLASS_HE:
1913  //L-STF + L-LTF
1914  return MicroSeconds (16);
1916  return MicroSeconds (16);
1917  case WIFI_MOD_CLASS_DSSS:
1919  if ((preamble == WIFI_PREAMBLE_SHORT) && (txVector.GetMode ().GetDataRate (22) > 1000000))
1920  {
1921  //(Section 17.2.2.3 "Short PPDU format)" Figure 17-2 "Short PPDU format"; IEEE Std 802.11-2012)
1922  return MicroSeconds (72);
1923  }
1924  else //WIFI_PREAMBLE_LONG
1925  {
1926  //(Section 17.2.2.2 "Long PPDU format)" Figure 17-1 "Long PPDU format"; IEEE Std 802.11-2012)
1927  return MicroSeconds (144);
1928  }
1929  default:
1930  NS_FATAL_ERROR ("unsupported modulation class");
1931  return MicroSeconds (0);
1932  }
1933 }
1934 
1935 Time
1936 WifiPhy::GetPayloadDuration (uint32_t size, WifiTxVector txVector, uint16_t frequency)
1937 {
1938  return GetPayloadDuration (size, txVector, frequency, NORMAL_MPDU, 0);
1939 }
1940 
1941 Time
1942 WifiPhy::GetPayloadDuration (uint32_t size, WifiTxVector txVector, uint16_t frequency, MpduType mpdutype, uint8_t incFlag)
1943 {
1944  WifiMode payloadMode = txVector.GetMode ();
1945  WifiPreamble preamble = txVector.GetPreambleType ();
1946  NS_LOG_FUNCTION (size << payloadMode);
1947 
1948  double stbc = 1;
1949  if (txVector.IsStbc ()
1950  && (payloadMode.GetModulationClass () == WIFI_MOD_CLASS_HT
1951  || payloadMode.GetModulationClass () == WIFI_MOD_CLASS_VHT))
1952  {
1953  stbc = 2;
1954  }
1955 
1956  double Nes = 1;
1957  //todo: improve logic to reduce the number of if cases
1958  //todo: extend to NSS > 4 for VHT rates
1959  if (payloadMode == GetHtMcs21()
1960  || payloadMode == GetHtMcs22 ()
1961  || payloadMode == GetHtMcs23 ()
1962  || payloadMode == GetHtMcs28 ()
1963  || payloadMode == GetHtMcs29 ()
1964  || payloadMode == GetHtMcs30 ()
1965  || payloadMode == GetHtMcs31 ())
1966  {
1967  Nes = 2;
1968  }
1969  if (payloadMode.GetModulationClass () == WIFI_MOD_CLASS_VHT)
1970  {
1971  if (txVector.GetChannelWidth () == 40
1972  && txVector.GetNss () == 3
1973  && payloadMode.GetMcsValue () >= 8)
1974  {
1975  Nes = 2;
1976  }
1977  if (txVector.GetChannelWidth () == 80
1978  && txVector.GetNss () == 2
1979  && payloadMode.GetMcsValue () >= 7)
1980  {
1981  Nes = 2;
1982  }
1983  if (txVector.GetChannelWidth () == 80
1984  && txVector.GetNss () == 3
1985  && payloadMode.GetMcsValue () >= 7)
1986  {
1987  Nes = 2;
1988  }
1989  if (txVector.GetChannelWidth () == 80
1990  && txVector.GetNss () == 3
1991  && payloadMode.GetMcsValue () == 9)
1992  {
1993  Nes = 3;
1994  }
1995  if (txVector.GetChannelWidth () == 80
1996  && txVector.GetNss () == 4
1997  && payloadMode.GetMcsValue () >= 4)
1998  {
1999  Nes = 2;
2000  }
2001  if (txVector.GetChannelWidth () == 80
2002  && txVector.GetNss () == 4
2003  && payloadMode.GetMcsValue () >= 7)
2004  {
2005  Nes = 3;
2006  }
2007  if (txVector.GetChannelWidth () == 160
2008  && payloadMode.GetMcsValue () >= 7)
2009  {
2010  Nes = 2;
2011  }
2012  if (txVector.GetChannelWidth () == 160
2013  && txVector.GetNss () == 2
2014  && payloadMode.GetMcsValue () >= 4)
2015  {
2016  Nes = 2;
2017  }
2018  if (txVector.GetChannelWidth () == 160
2019  && txVector.GetNss () == 2
2020  && payloadMode.GetMcsValue () >= 7)
2021  {
2022  Nes = 3;
2023  }
2024  if (txVector.GetChannelWidth () == 160
2025  && txVector.GetNss () == 3
2026  && payloadMode.GetMcsValue () >= 3)
2027  {
2028  Nes = 2;
2029  }
2030  if (txVector.GetChannelWidth () == 160
2031  && txVector.GetNss () == 3
2032  && payloadMode.GetMcsValue () >= 5)
2033  {
2034  Nes = 3;
2035  }
2036  if (txVector.GetChannelWidth () == 160
2037  && txVector.GetNss () == 3
2038  && payloadMode.GetMcsValue () >= 7)
2039  {
2040  Nes = 4;
2041  }
2042  if (txVector.GetChannelWidth () == 160
2043  && txVector.GetNss () == 4
2044  && payloadMode.GetMcsValue () >= 2)
2045  {
2046  Nes = 2;
2047  }
2048  if (txVector.GetChannelWidth () == 160
2049  && txVector.GetNss () == 4
2050  && payloadMode.GetMcsValue () >= 4)
2051  {
2052  Nes = 3;
2053  }
2054  if (txVector.GetChannelWidth () == 160
2055  && txVector.GetNss () == 4
2056  && payloadMode.GetMcsValue () >= 5)
2057  {
2058  Nes = 4;
2059  }
2060  if (txVector.GetChannelWidth () == 160
2061  && txVector.GetNss () == 4
2062  && payloadMode.GetMcsValue () >= 7)
2063  {
2064  Nes = 6;
2065  }
2066  }
2067 
2068  Time symbolDuration = Seconds (0);
2069  switch (payloadMode.GetModulationClass ())
2070  {
2071  case WIFI_MOD_CLASS_OFDM:
2073  {
2074  //(Section 18.3.2.4 "Timing related parameters" Table 18-5 "Timing-related parameters"; IEEE Std 802.11-2012
2075  //corresponds to T_{SYM} in the table)
2076  switch (txVector.GetChannelWidth ())
2077  {
2078  case 20:
2079  default:
2080  symbolDuration = MicroSeconds (4);
2081  break;
2082  case 10:
2083  symbolDuration = MicroSeconds (8);
2084  break;
2085  case 5:
2086  symbolDuration = MicroSeconds (16);
2087  break;
2088  }
2089  break;
2090  }
2091  case WIFI_MOD_CLASS_HT:
2092  case WIFI_MOD_CLASS_VHT:
2093  {
2094  //if short GI data rate is used then symbol duration is 3.6us else symbol duration is 4us
2095  //In the future has to create a stationmanager that only uses these data rates if sender and receiver support GI
2096  uint16_t gi = txVector.GetGuardInterval ();
2097  NS_ASSERT (gi == 400 || gi == 800);
2098  symbolDuration = NanoSeconds (3200 + gi);
2099  }
2100  break;
2101  case WIFI_MOD_CLASS_HE:
2102  {
2103  //if short GI data rate is used then symbol duration is 3.6us else symbol duration is 4us
2104  //In the future has to create a stationmanager that only uses these data rates if sender and receiver support GI
2105  uint16_t gi = txVector.GetGuardInterval ();
2106  NS_ASSERT (gi == 800 || gi == 1600 || gi == 3200);
2107  symbolDuration = NanoSeconds (12800 + gi);
2108  }
2109  break;
2110  default:
2111  break;
2112  }
2113 
2114  double numDataBitsPerSymbol = payloadMode.GetDataRate (txVector) * symbolDuration.GetNanoSeconds () / 1e9;
2115 
2116  double numSymbols = 0;
2117  if (mpdutype == MPDU_IN_AGGREGATE && preamble != WIFI_PREAMBLE_NONE)
2118  {
2119  //First packet in an A-MPDU
2120  numSymbols = (stbc * (16 + size * 8.0 + 6 * Nes) / (stbc * numDataBitsPerSymbol));
2121  if (incFlag == 1)
2122  {
2123  m_totalAmpduSize += size;
2124  m_totalAmpduNumSymbols += numSymbols;
2125  }
2126  }
2127  else if (mpdutype == MPDU_IN_AGGREGATE && preamble == WIFI_PREAMBLE_NONE)
2128  {
2129  //consecutive packets in an A-MPDU
2130  numSymbols = (stbc * size * 8.0) / (stbc * numDataBitsPerSymbol);
2131  if (incFlag == 1)
2132  {
2133  m_totalAmpduSize += size;
2134  m_totalAmpduNumSymbols += numSymbols;
2135  }
2136  }
2137  else if (mpdutype == LAST_MPDU_IN_AGGREGATE && preamble == WIFI_PREAMBLE_NONE)
2138  {
2139  //last packet in an A-MPDU
2140  uint32_t totalAmpduSize = m_totalAmpduSize + size;
2141  numSymbols = lrint (stbc * ceil ((16 + totalAmpduSize * 8.0 + 6 * Nes) / (stbc * numDataBitsPerSymbol)));
2142  NS_ASSERT (m_totalAmpduNumSymbols <= numSymbols);
2143  numSymbols -= m_totalAmpduNumSymbols;
2144  if (incFlag == 1)
2145  {
2146  m_totalAmpduSize = 0;
2148  }
2149  }
2150  else if (mpdutype == NORMAL_MPDU && preamble != WIFI_PREAMBLE_NONE)
2151  {
2152  //Not an A-MPDU
2153  // The number of OFDM symbols in the data field when BCC encoding
2154  // is used is given in equation 19-32 of the IEEE 802.11-2016 standard.
2155  numSymbols = lrint (stbc * ceil ((16 + size * 8.0 + 6.0 * Nes) / (stbc * numDataBitsPerSymbol)));
2156  }
2157  else
2158  {
2159  NS_FATAL_ERROR ("Wrong combination of preamble and packet type");
2160  }
2161 
2162  switch (payloadMode.GetModulationClass ())
2163  {
2164  case WIFI_MOD_CLASS_OFDM:
2166  {
2167  //Add signal extension for ERP PHY
2168  if (payloadMode.GetModulationClass () == WIFI_MOD_CLASS_ERP_OFDM)
2169  {
2170  return FemtoSeconds (static_cast<uint64_t> (numSymbols * symbolDuration.GetFemtoSeconds ())) + MicroSeconds (6);
2171  }
2172  else
2173  {
2174  return FemtoSeconds (static_cast<uint64_t> (numSymbols * symbolDuration.GetFemtoSeconds ()));
2175  }
2176  }
2177  case WIFI_MOD_CLASS_HT:
2178  case WIFI_MOD_CLASS_VHT:
2179  {
2180  if (payloadMode.GetModulationClass () == WIFI_MOD_CLASS_HT && Is2_4Ghz (frequency)
2181  && ((mpdutype == NORMAL_MPDU && preamble != WIFI_PREAMBLE_NONE)
2182  || (mpdutype == LAST_MPDU_IN_AGGREGATE && preamble == WIFI_PREAMBLE_NONE))) //at 2.4 GHz
2183  {
2184  return FemtoSeconds (static_cast<uint64_t> (numSymbols * symbolDuration.GetFemtoSeconds ())) + MicroSeconds (6);
2185  }
2186  else //at 5 GHz
2187  {
2188  return FemtoSeconds (static_cast<uint64_t> (numSymbols * symbolDuration.GetFemtoSeconds ()));
2189  }
2190  }
2191  case WIFI_MOD_CLASS_HE:
2192  {
2193  if (Is2_4Ghz (frequency)
2194  && ((mpdutype == NORMAL_MPDU && preamble != WIFI_PREAMBLE_NONE)
2195  || (mpdutype == LAST_MPDU_IN_AGGREGATE && preamble == WIFI_PREAMBLE_NONE))) //at 2.4 GHz
2196  {
2197  return FemtoSeconds (static_cast<uint64_t> (numSymbols * symbolDuration.GetFemtoSeconds ())) + MicroSeconds (6);
2198  }
2199  else //at 5 GHz
2200  {
2201  return FemtoSeconds (static_cast<uint64_t> (numSymbols * symbolDuration.GetFemtoSeconds ()));
2202  }
2203  }
2204  case WIFI_MOD_CLASS_DSSS:
2206  return MicroSeconds (lrint (ceil ((size * 8.0) / (payloadMode.GetDataRate (22) / 1.0e6))));
2207  default:
2208  NS_FATAL_ERROR ("unsupported modulation class");
2209  return MicroSeconds (0);
2210  }
2211 }
2212 
2213 Time
2215 {
2216  WifiPreamble preamble = txVector.GetPreambleType ();
2217  Time duration = GetPlcpPreambleDuration (txVector)
2218  + GetPlcpHeaderDuration (txVector)
2219  + GetPlcpHtSigHeaderDuration (preamble)
2220  + GetPlcpSigA1Duration (preamble)
2221  + GetPlcpSigA2Duration (preamble)
2222  + GetPlcpTrainingSymbolDuration (txVector)
2223  + GetPlcpSigBDuration (preamble);
2224  return duration;
2225 }
2226 
2227 Time
2228 WifiPhy::CalculateTxDuration (uint32_t size, WifiTxVector txVector, uint16_t frequency, MpduType mpdutype, uint8_t incFlag)
2229 {
2230  Time duration = CalculatePlcpPreambleAndHeaderDuration (txVector)
2231  + GetPayloadDuration (size, txVector, frequency, mpdutype, incFlag);
2232  return duration;
2233 }
2234 
2235 Time
2236 WifiPhy::CalculateTxDuration (uint32_t size, WifiTxVector txVector, uint16_t frequency)
2237 {
2238  return CalculateTxDuration (size, txVector, frequency, NORMAL_MPDU, 0);
2239 }
2240 
2241 void
2243 {
2244  m_phyTxBeginTrace (packet);
2245 }
2246 
2247 void
2249 {
2250  m_phyTxEndTrace (packet);
2251 }
2252 
2253 void
2255 {
2256  m_phyTxDropTrace (packet);
2257 }
2258 
2259 void
2261 {
2262  m_phyRxBeginTrace (packet);
2263 }
2264 
2265 void
2267 {
2268  m_phyRxEndTrace (packet);
2269 }
2270 
2271 void
2273 {
2274  m_phyRxDropTrace (packet);
2275 }
2276 
2277 void
2278 WifiPhy::NotifyMonitorSniffRx (Ptr<const Packet> packet, uint16_t channelFreqMhz, WifiTxVector txVector, MpduInfo aMpdu, SignalNoiseDbm signalNoise)
2279 {
2280  m_phyMonitorSniffRxTrace (packet, channelFreqMhz, txVector, aMpdu, signalNoise);
2281 }
2282 
2283 void
2284 WifiPhy::NotifyMonitorSniffTx (Ptr<const Packet> packet, uint16_t channelFreqMhz, WifiTxVector txVector, MpduInfo aMpdu)
2285 {
2286  m_phyMonitorSniffTxTrace (packet, channelFreqMhz, txVector, aMpdu);
2287 }
2288 
2289 void
2291 {
2292  NS_LOG_FUNCTION (this << packet << txVector.GetMode ()
2293  << txVector.GetMode ().GetDataRate (txVector)
2294  << txVector.GetPreambleType ()
2295  << +txVector.GetTxPowerLevel ()
2296  << +mpdutype);
2297  /* Transmission can happen if:
2298  * - we are syncing on a packet. It is the responsibility of the
2299  * MAC layer to avoid doing this but the PHY does nothing to
2300  * prevent it.
2301  * - we are idle
2302  */
2303  NS_ASSERT (!m_state->IsStateTx () && !m_state->IsStateSwitching ());
2304 
2305  if (txVector.GetNss () > GetMaxSupportedTxSpatialStreams ())
2306  {
2307  NS_FATAL_ERROR ("Unsupported number of spatial streams!");
2308  }
2309 
2310  if (m_state->IsStateSleep ())
2311  {
2312  NS_LOG_DEBUG ("Dropping packet because in sleep mode");
2313  NotifyTxDrop (packet);
2314  return;
2315  }
2316 
2317  Time txDuration = CalculateTxDuration (packet->GetSize (), txVector, GetFrequency (), mpdutype, 1);
2318  NS_ASSERT (txDuration.IsStrictlyPositive ());
2319 
2320  if (m_state->IsStateRx ())
2321  {
2323  m_endRxEvent.Cancel ();
2325  }
2326  NotifyTxBegin (packet);
2327  if ((mpdutype == MPDU_IN_AGGREGATE) && (txVector.GetPreambleType () != WIFI_PREAMBLE_NONE))
2328  {
2329  //send the first MPDU in an MPDU
2331  }
2332  MpduInfo aMpdu;
2333  aMpdu.type = mpdutype;
2335  NotifyMonitorSniffTx (packet, GetFrequency (), txVector, aMpdu);
2336  m_state->SwitchToTx (txDuration, packet, GetPowerDbm (txVector.GetTxPowerLevel ()), txVector);
2337 
2338  Ptr<Packet> newPacket = packet->Copy (); // obtain non-const Packet
2339  WifiPhyTag oldtag;
2340  newPacket->RemovePacketTag (oldtag);
2341  if (m_state->GetState () == WifiPhyState::OFF)
2342  {
2343  NS_LOG_DEBUG ("Transmission canceled because device is OFF");
2344  return;
2345  }
2346  uint8_t isFrameComplete = 1;
2347  if (m_wifiRadioEnergyModel != 0 && m_wifiRadioEnergyModel->GetMaximumTimeInState (WifiPhyState::TX) < txDuration)
2348  {
2349  isFrameComplete = 0;
2350  }
2351  WifiPhyTag tag (txVector, mpdutype, isFrameComplete);
2352  newPacket->AddPacketTag (tag);
2353 
2354  StartTx (newPacket, txVector, txDuration);
2355 }
2356 
2357 void
2358 WifiPhy::StartReceivePreambleAndHeader (Ptr<Packet> packet, double rxPowerW, Time rxDuration)
2359 {
2360  WifiPhyTag tag;
2361  bool found = packet->RemovePacketTag (tag);
2362  if (!found)
2363  {
2364  NS_FATAL_ERROR ("Received Wi-Fi Signal with no WifiPhyTag");
2365  return;
2366  }
2367 
2368  WifiTxVector txVector = tag.GetWifiTxVector ();
2369  Ptr<Event> event;
2370  event = m_interference.Add (packet,
2371  txVector,
2372  rxDuration,
2373  rxPowerW);
2374 
2375  //This function should be later split to check separately whether plcp preamble and plcp header can be successfully received.
2376  //Note: plcp preamble reception is not yet modeled.
2377  if (m_state->GetState () == WifiPhyState::OFF)
2378  {
2379  NS_LOG_DEBUG ("Cannot start RX because device is OFF");
2380  return;
2381  }
2382 
2383  NS_LOG_FUNCTION (this << packet << WToDbm (rxPowerW) << rxDuration);
2384 
2385  if (tag.GetFrameComplete () == 0)
2386  {
2387  NS_LOG_DEBUG ("drop packet because of incomplete frame");
2388  NotifyRxDrop (packet);
2389  m_plcpSuccess = false;
2390  return;
2391  }
2392 
2393  if (txVector.GetMode ().GetModulationClass () == WIFI_MOD_CLASS_HT
2394  && (txVector.GetNss () != (1 + (txVector.GetMode ().GetMcsValue () / 8))))
2395  {
2396  NS_FATAL_ERROR ("MCS value does not match NSS value: MCS = " << +txVector.GetMode ().GetMcsValue () << ", NSS = " << +txVector.GetNss ());
2397  }
2398 
2399  Time endRx = Simulator::Now () + rxDuration;
2400  if (txVector.GetNss () > GetMaxSupportedRxSpatialStreams ())
2401  {
2402  NS_LOG_DEBUG ("drop packet because not enough RX antennas");
2403  NotifyRxDrop (packet);
2404  m_plcpSuccess = false;
2405  if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ())
2406  {
2407  //that packet will be noise _after_ the transmission of the
2408  //currently-transmitted packet.
2410  return;
2411  }
2412  }
2413 
2414  MpduType mpdutype = tag.GetMpduType ();
2415  switch (m_state->GetState ())
2416  {
2418  NS_LOG_DEBUG ("drop packet because of channel switching");
2419  NotifyRxDrop (packet);
2420  m_plcpSuccess = false;
2421  /*
2422  * Packets received on the upcoming channel are added to the event list
2423  * during the switching state. This way the medium can be correctly sensed
2424  * when the device listens to the channel for the first time after the
2425  * switching e.g. after channel switching, the channel may be sensed as
2426  * busy due to other devices' tramissions started before the end of
2427  * the switching.
2428  */
2429  if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ())
2430  {
2431  //that packet will be noise _after_ the completion of the
2432  //channel switching.
2434  return;
2435  }
2436  break;
2437  case WifiPhyState::RX:
2438  NS_ASSERT (m_currentEvent != 0);
2439  if (m_frameCaptureModel != 0
2440  && m_frameCaptureModel->CaptureNewFrame (m_currentEvent, event))
2441  {
2443  NS_LOG_DEBUG ("Switch to new packet");
2444  StartRx (packet, txVector, mpdutype, rxPowerW, rxDuration, event);
2445  }
2446  else
2447  {
2448  NS_LOG_DEBUG ("drop packet because already in Rx (power=" <<
2449  rxPowerW << "W)");
2450  NotifyRxDrop (packet);
2451  if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ())
2452  {
2453  //that packet will be noise _after_ the reception of the
2454  //currently-received packet.
2456  return;
2457  }
2458  }
2459  break;
2460  case WifiPhyState::TX:
2461  NS_LOG_DEBUG ("drop packet because already in Tx (power=" <<
2462  rxPowerW << "W)");
2463  NotifyRxDrop (packet);
2464  if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ())
2465  {
2466  //that packet will be noise _after_ the transmission of the
2467  //currently-transmitted packet.
2469  return;
2470  }
2471  break;
2473  case WifiPhyState::IDLE:
2474  StartRx (packet, txVector, mpdutype, rxPowerW, rxDuration, event);
2475  break;
2476  case WifiPhyState::SLEEP:
2477  NS_LOG_DEBUG ("drop packet because in sleep mode");
2478  NotifyRxDrop (packet);
2479  m_plcpSuccess = false;
2480  break;
2481  default:
2482  NS_FATAL_ERROR ("Invalid WifiPhy state.");
2483  break;
2484  }
2485 }
2486 
2487 void
2489 {
2490  //We are here because we have received the first bit of a packet and we are
2491  //not going to be able to synchronize on it
2492  //In this model, CCA becomes busy when the aggregation of all signals as
2493  //tracked by the InterferenceHelper class is higher than the CcaBusyThreshold
2494 
2496  if (!delayUntilCcaEnd.IsZero ())
2497  {
2498  m_state->SwitchMaybeToCcaBusy (delayUntilCcaEnd);
2499  }
2500 }
2501 
2502 void
2504  WifiTxVector txVector,
2505  MpduType mpdutype,
2506  Ptr<Event> event)
2507 {
2508  NS_LOG_FUNCTION (this << packet << txVector.GetMode () << txVector.GetPreambleType () << +mpdutype);
2509  NS_ASSERT (IsStateRx ());
2511  WifiMode txMode = txVector.GetMode ();
2512 
2514  snrPer = m_interference.CalculatePlcpHeaderSnrPer (event);
2515 
2516  NS_LOG_DEBUG ("snr(dB)=" << RatioToDb (snrPer.snr) << ", per=" << snrPer.per);
2517 
2518  if (m_random->GetValue () > snrPer.per) //plcp reception succeeded
2519  {
2520  if (IsModeSupported (txMode) || IsMcsSupported (txMode))
2521  {
2522  NS_LOG_DEBUG ("receiving plcp payload"); //endReceive is already scheduled
2523  m_plcpSuccess = true;
2524  }
2525  else //mode is not allowed
2526  {
2527  NS_LOG_DEBUG ("drop packet because it was sent using an unsupported mode (" << txMode << ")");
2528  NotifyRxDrop (packet);
2529  m_plcpSuccess = false;
2530  }
2531  }
2532  else //plcp reception failed
2533  {
2534  NS_LOG_DEBUG ("drop packet because plcp preamble/header reception failed");
2535  NotifyRxDrop (packet);
2536  m_plcpSuccess = false;
2537  }
2538 }
2539 
2540 void
2542 {
2543  NS_LOG_FUNCTION (this << packet << event);
2544  NS_ASSERT (IsStateRx ());
2545  NS_ASSERT (event->GetEndTime () == Simulator::Now ());
2546 
2548  snrPer = m_interference.CalculatePlcpPayloadSnrPer (event);
2550  m_currentEvent = 0;
2551 
2552  if (m_plcpSuccess == true)
2553  {
2554  NS_LOG_DEBUG ("mode=" << (event->GetPayloadMode ().GetDataRate (event->GetTxVector ())) <<
2555  ", snr(dB)=" << RatioToDb (snrPer.snr) << ", per=" << snrPer.per << ", size=" << packet->GetSize ());
2556 
2557  if (m_random->GetValue () > snrPer.per)
2558  {
2559  NotifyRxEnd (packet);
2560  SignalNoiseDbm signalNoise;
2561  signalNoise.signal = WToDbm (event->GetRxPowerW ());
2562  signalNoise.noise = WToDbm (event->GetRxPowerW () / snrPer.snr);
2563  MpduInfo aMpdu;
2564  aMpdu.type = mpdutype;
2565  aMpdu.mpduRefNumber = m_rxMpduReferenceNumber;
2566  NotifyMonitorSniffRx (packet, GetFrequency (), event->GetTxVector (), aMpdu, signalNoise);
2567  m_state->SwitchFromRxEndOk (packet, snrPer.snr, event->GetTxVector ());
2568  }
2569  else
2570  {
2571  /* failure. */
2572  NotifyRxDrop (packet);
2573  m_state->SwitchFromRxEndError (packet, snrPer.snr);
2574  }
2575  }
2576  else
2577  {
2578  m_state->SwitchFromRxEndError (packet, snrPer.snr);
2579  }
2580 
2581  if (preamble == WIFI_PREAMBLE_NONE && mpdutype == LAST_MPDU_IN_AGGREGATE)
2582  {
2583  m_plcpSuccess = false;
2584  }
2585 
2586 }
2587 
2588 
2589 // Clause 15 rates (DSSS)
2590 
2591 WifiMode
2593 {
2594  static WifiMode mode =
2595  WifiModeFactory::CreateWifiMode ("DsssRate1Mbps",
2597  true,
2599  2);
2600  return mode;
2601 }
2602 
2603 WifiMode
2605 {
2606  static WifiMode mode =
2607  WifiModeFactory::CreateWifiMode ("DsssRate2Mbps",
2609  true,
2611  4);
2612  return mode;
2613 }
2614 
2615 
2616 // Clause 18 rates (HR/DSSS)
2617 
2618 WifiMode
2620 {
2621  static WifiMode mode =
2622  WifiModeFactory::CreateWifiMode ("DsssRate5_5Mbps",
2624  true,
2626  16);
2627  return mode;
2628 }
2629 
2630 WifiMode
2632 {
2633  static WifiMode mode =
2634  WifiModeFactory::CreateWifiMode ("DsssRate11Mbps",
2636  true,
2638  256);
2639  return mode;
2640 }
2641 
2642 
2643 // Clause 19.5 rates (ERP-OFDM)
2644 
2645 WifiMode
2647 {
2648  static WifiMode mode =
2649  WifiModeFactory::CreateWifiMode ("ErpOfdmRate6Mbps",
2651  true,
2653  2);
2654  return mode;
2655 }
2656 
2657 WifiMode
2659 {
2660  static WifiMode mode =
2661  WifiModeFactory::CreateWifiMode ("ErpOfdmRate9Mbps",
2663  false,
2665  2);
2666  return mode;
2667 }
2668 
2669 WifiMode
2671 {
2672  static WifiMode mode =
2673  WifiModeFactory::CreateWifiMode ("ErpOfdmRate12Mbps",
2675  true,
2677  4);
2678  return mode;
2679 }
2680 
2681 WifiMode
2683 {
2684  static WifiMode mode =
2685  WifiModeFactory::CreateWifiMode ("ErpOfdmRate18Mbps",
2687  false,
2689  4);
2690  return mode;
2691 }
2692 
2693 WifiMode
2695 {
2696  static WifiMode mode =
2697  WifiModeFactory::CreateWifiMode ("ErpOfdmRate24Mbps",
2699  true,
2701  16);
2702  return mode;
2703 }
2704 
2705 WifiMode
2707 {
2708  static WifiMode mode =
2709  WifiModeFactory::CreateWifiMode ("ErpOfdmRate36Mbps",
2711  false,
2713  16);
2714  return mode;
2715 }
2716 
2717 WifiMode
2719 {
2720  static WifiMode mode =
2721  WifiModeFactory::CreateWifiMode ("ErpOfdmRate48Mbps",
2723  false,
2725  64);
2726  return mode;
2727 }
2728 
2729 WifiMode
2731 {
2732  static WifiMode mode =
2733  WifiModeFactory::CreateWifiMode ("ErpOfdmRate54Mbps",
2735  false,
2737  64);
2738  return mode;
2739 }
2740 
2741 
2742 // Clause 17 rates (OFDM)
2743 
2744 WifiMode
2746 {
2747  static WifiMode mode =
2748  WifiModeFactory::CreateWifiMode ("OfdmRate6Mbps",
2750  true,
2752  2);
2753  return mode;
2754 }
2755 
2756 WifiMode
2758 {
2759  static WifiMode mode =
2760  WifiModeFactory::CreateWifiMode ("OfdmRate9Mbps",
2762  false,
2764  2);
2765  return mode;
2766 }
2767 
2768 WifiMode
2770 {
2771  static WifiMode mode =
2772  WifiModeFactory::CreateWifiMode ("OfdmRate12Mbps",
2774  true,
2776  4);
2777  return mode;
2778 }
2779 
2780 WifiMode
2782 {
2783  static WifiMode mode =
2784  WifiModeFactory::CreateWifiMode ("OfdmRate18Mbps",
2786  false,
2788  4);
2789  return mode;
2790 }
2791 
2792 WifiMode
2794 {
2795  static WifiMode mode =
2796  WifiModeFactory::CreateWifiMode ("OfdmRate24Mbps",
2798  true,
2800  16);
2801  return mode;
2802 }
2803 
2804 WifiMode
2806 {
2807  static WifiMode mode =
2808  WifiModeFactory::CreateWifiMode ("OfdmRate36Mbps",
2810  false,
2812  16);
2813  return mode;
2814 }
2815 
2816 WifiMode
2818 {
2819  static WifiMode mode =
2820  WifiModeFactory::CreateWifiMode ("OfdmRate48Mbps",
2822  false,
2824  64);
2825  return mode;
2826 }
2827 
2828 WifiMode
2830 {
2831  static WifiMode mode =
2832  WifiModeFactory::CreateWifiMode ("OfdmRate54Mbps",
2834  false,
2836  64);
2837  return mode;
2838 }
2839 
2840 
2841 // 10 MHz channel rates
2842 
2843 WifiMode
2845 {
2846  static WifiMode mode =
2847  WifiModeFactory::CreateWifiMode ("OfdmRate3MbpsBW10MHz",
2849  true,
2851  2);
2852  return mode;
2853 }
2854 
2855 WifiMode
2857 {
2858  static WifiMode mode =
2859  WifiModeFactory::CreateWifiMode ("OfdmRate4_5MbpsBW10MHz",
2861  false,
2863  2);
2864  return mode;
2865 }
2866 
2867 WifiMode
2869 {
2870  static WifiMode mode =
2871  WifiModeFactory::CreateWifiMode ("OfdmRate6MbpsBW10MHz",
2873  true,
2875  4);
2876  return mode;
2877 }
2878 
2879 WifiMode
2881 {
2882  static WifiMode mode =
2883  WifiModeFactory::CreateWifiMode ("OfdmRate9MbpsBW10MHz",
2885  false,
2887  4);
2888  return mode;
2889 }
2890 
2891 WifiMode
2893 {
2894  static WifiMode mode =
2895  WifiModeFactory::CreateWifiMode ("OfdmRate12MbpsBW10MHz",
2897  true,
2899  16);
2900  return mode;
2901 }
2902 
2903 WifiMode
2905 {
2906  static WifiMode mode =
2907  WifiModeFactory::CreateWifiMode ("OfdmRate18MbpsBW10MHz",
2909  false,
2911  16);
2912  return mode;
2913 }
2914 
2915 WifiMode
2917 {
2918  static WifiMode mode =
2919  WifiModeFactory::CreateWifiMode ("OfdmRate24MbpsBW10MHz",
2921  false,
2923  64);
2924  return mode;
2925 }
2926 
2927 WifiMode
2929 {
2930  static WifiMode mode =
2931  WifiModeFactory::CreateWifiMode ("OfdmRate27MbpsBW10MHz",
2933  false,
2935  64);
2936  return mode;
2937 }
2938 
2939 
2940 // 5 MHz channel rates
2941 
2942 WifiMode
2944 {
2945  static WifiMode mode =
2946  WifiModeFactory::CreateWifiMode ("OfdmRate1_5MbpsBW5MHz",
2948  true,
2950  2);
2951  return mode;
2952 }
2953 
2954 WifiMode
2956 {
2957  static WifiMode mode =
2958  WifiModeFactory::CreateWifiMode ("OfdmRate2_25MbpsBW5MHz",
2960  false,
2962  2);
2963  return mode;
2964 }
2965 
2966 WifiMode
2968 {
2969  static WifiMode mode =
2970  WifiModeFactory::CreateWifiMode ("OfdmRate3MbpsBW5MHz",
2972  true,
2974  4);
2975  return mode;
2976 }
2977 
2978 WifiMode
2980 {
2981  static WifiMode mode =
2982  WifiModeFactory::CreateWifiMode ("OfdmRate4_5MbpsBW5MHz",
2984  false,
2986  4);
2987  return mode;
2988 }
2989 
2990 WifiMode
2992 {
2993  static WifiMode mode =
2994  WifiModeFactory::CreateWifiMode ("OfdmRate6MbpsBW5MHz",
2996  true,
2998  16);
2999  return mode;
3000 }
3001 
3002 WifiMode
3004 {
3005  static WifiMode mode =
3006  WifiModeFactory::CreateWifiMode ("OfdmRate9MbpsBW5MHz",
3008  false,
3010  16);
3011  return mode;
3012 }
3013 
3014 WifiMode
3016 {
3017  static WifiMode mode =
3018  WifiModeFactory::CreateWifiMode ("OfdmRate12MbpsBW5MHz",
3020  false,
3022  64);
3023  return mode;
3024 }
3025 
3026 WifiMode
3028 {
3029  static WifiMode mode =
3030  WifiModeFactory::CreateWifiMode ("OfdmRate13_5MbpsBW5MHz",
3032  false,
3034  64);
3035  return mode;
3036 }
3037 
3038 
3039 // Clause 20
3040 
3041 WifiMode
3043 {
3044  static WifiMode mcs =
3046  return mcs;
3047 }
3048 
3049 WifiMode
3051 {
3052  static WifiMode mcs =
3054  return mcs;
3055 }
3056 
3057 WifiMode
3059 {
3060  static WifiMode mcs =
3062  return mcs;
3063 }
3064 
3065 WifiMode
3067 {
3068  static WifiMode mcs =
3070  return mcs;
3071 }
3072 
3073 WifiMode
3075 {
3076  static WifiMode mcs =
3078  return mcs;
3079 }
3080 
3081 WifiMode
3083 {
3084  static WifiMode mcs =
3086  return mcs;
3087 }
3088 
3089 WifiMode
3091 {
3092  static WifiMode mcs =
3094  return mcs;
3095 }
3096 
3097 WifiMode
3099 {
3100  static WifiMode mcs =
3102  return mcs;
3103 }
3104 
3105 WifiMode
3107 {
3108  static WifiMode mcs =
3110  return mcs;
3111 }
3112 
3113 WifiMode
3115 {
3116  static WifiMode mcs =
3118  return mcs;
3119 }
3120 
3121 WifiMode
3123 {
3124  static WifiMode mcs =
3126  return mcs;
3127 }
3128 
3129 WifiMode
3131 {
3132  static WifiMode mcs =
3134  return mcs;
3135 }
3136 
3137 WifiMode
3139 {
3140  static WifiMode mcs =
3142  return mcs;
3143 }
3144 
3145 WifiMode
3147 {
3148  static WifiMode mcs =
3150  return mcs;
3151 }
3152 
3153 WifiMode
3155 {
3156  static WifiMode mcs =
3158  return mcs;
3159 }
3160 
3161 WifiMode
3163 {
3164  static WifiMode mcs =
3166  return mcs;
3167 }
3168 
3169 WifiMode
3171 {
3172  static WifiMode mcs =
3174  return mcs;
3175 }
3176 
3177 WifiMode
3179 {
3180  static WifiMode mcs =
3182  return mcs;
3183 }
3184 
3185 WifiMode
3187 {
3188  static WifiMode mcs =
3190  return mcs;
3191 }
3192 
3193 WifiMode
3195 {
3196  static WifiMode mcs =
3198  return mcs;
3199 }
3200 
3201 WifiMode
3203 {
3204  static WifiMode mcs =
3206  return mcs;
3207 }
3208 
3209 WifiMode
3211 {
3212  static WifiMode mcs =
3214  return mcs;
3215 }
3216 
3217 WifiMode
3219 {
3220  static WifiMode mcs =
3222  return mcs;
3223 }
3224 
3225 WifiMode
3227 {
3228  static WifiMode mcs =
3230  return mcs;
3231 }
3232 
3233 WifiMode
3235 {
3236  static WifiMode mcs =
3238  return mcs;
3239 }
3240 
3241 WifiMode
3243 {
3244  static WifiMode mcs =
3246  return mcs;
3247 }
3248 
3249 WifiMode
3251 {
3252  static WifiMode mcs =
3254  return mcs;
3255 }
3256 
3257 WifiMode
3259 {
3260  static WifiMode mcs =
3262  return mcs;
3263 }
3264 
3265 WifiMode
3267 {
3268  static WifiMode mcs =
3270  return mcs;
3271 }
3272 
3273 WifiMode
3275 {
3276  static WifiMode mcs =
3278  return mcs;
3279 }
3280 
3281 WifiMode
3283 {
3284  static WifiMode mcs =
3286  return mcs;
3287 }
3288 
3289 WifiMode
3291 {
3292  static WifiMode mcs =
3294  return mcs;
3295 }
3296 
3297 
3298 // Clause 22
3299 
3300 WifiMode
3302 {
3303  static WifiMode mcs =
3305  return mcs;
3306 }
3307 
3308 WifiMode
3310 {
3311  static WifiMode mcs =
3313  return mcs;
3314 }
3315 
3316 WifiMode
3318 {
3319  static WifiMode mcs =
3321  return mcs;
3322 }
3323 
3324 WifiMode
3326 {
3327  static WifiMode mcs =
3329  return mcs;
3330 }
3331 
3332 WifiMode
3334 {
3335  static WifiMode mcs =
3337  return mcs;
3338 }
3339 
3340 WifiMode
3342 {
3343  static WifiMode mcs =
3345  return mcs;
3346 }
3347 
3348 WifiMode
3350 {
3351  static WifiMode mcs =
3353  return mcs;
3354 }
3355 
3356 WifiMode
3358 {
3359  static WifiMode mcs =
3361  return mcs;
3362 }
3363 
3364 WifiMode
3366 {
3367  static WifiMode mcs =
3369  return mcs;
3370 }
3371 
3372 WifiMode
3374 {
3375  static WifiMode mcs =
3377  return mcs;
3378 }
3379 
3380 // Clause 26
3381 
3382 WifiMode
3384 {
3385  static WifiMode mcs =
3387  return mcs;
3388 }
3389 
3390 WifiMode
3392 {
3393  static WifiMode mcs =
3395  return mcs;
3396 }
3397 
3398 WifiMode
3400 {
3401  static WifiMode mcs =
3403  return mcs;
3404 }
3405 
3406 WifiMode
3408 {
3409  static WifiMode mcs =
3411  return mcs;
3412 }
3413 
3414 WifiMode
3416 {
3417  static WifiMode mcs =
3419  return mcs;
3420 }
3421 
3422 WifiMode
3424 {
3425  static WifiMode mcs =
3427  return mcs;
3428 }
3429 
3430 WifiMode
3432 {
3433  static WifiMode mcs =
3435  return mcs;
3436 }
3437 
3438 WifiMode
3440 {
3441  static WifiMode mcs =
3443  return mcs;
3444 }
3445 
3446 WifiMode
3448 {
3449  static WifiMode mcs =
3451  return mcs;
3452 }
3453 
3454 WifiMode
3456 {
3457  static WifiMode mcs =
3459  return mcs;
3460 }
3461 
3462 WifiMode
3464 {
3465  static WifiMode mcs =
3467  return mcs;
3468 }
3469 
3470 WifiMode
3472 {
3473  static WifiMode mcs =
3475  return mcs;
3476 }
3477 
3478 bool
3480 {
3481  for (uint8_t i = 0; i < GetNModes (); i++)
3482  {
3483  if (mode == GetMode (i))
3484  {
3485  return true;
3486  }
3487  }
3488  return false;
3489 }
3490 
3491 bool
3493 {
3494  for (uint8_t i = 0; i < GetNMcs (); i++)
3495  {
3496  if (mcs == GetMcs (i))
3497  {
3498  return true;
3499  }
3500  }
3501  return false;
3502 }
3503 
3504 uint8_t
3506 {
3507  return static_cast<uint8_t> (m_deviceRateSet.size ());
3508 }
3509 
3510 WifiMode
3511 WifiPhy::GetMode (uint8_t mode) const
3512 {
3513  return m_deviceRateSet[mode];
3514 }
3515 
3516 uint8_t
3517 WifiPhy::GetNMcs (void) const
3518 {
3519  return static_cast<uint8_t> (m_deviceMcsSet.size ());
3520 }
3521 
3522 WifiMode
3523 WifiPhy::GetMcs (uint8_t mcs) const
3524 {
3525  return m_deviceMcsSet[mcs];
3526 }
3527 
3528 bool
3530 {
3531  return m_state->IsStateCcaBusy ();
3532 }
3533 
3534 bool
3536 {
3537  return m_state->IsStateIdle ();
3538 }
3539 
3540 bool
3542 {
3543  return m_state->IsStateRx ();
3544 }
3545 
3546 bool
3548 {
3549  return m_state->IsStateTx ();
3550 }
3551 
3552 bool
3554 {
3555  return m_state->IsStateSwitching ();
3556 }
3557 
3558 bool
3560 {
3561  return m_state->IsStateSleep ();
3562 }
3563 
3564 bool
3566 {
3567  return m_state->IsStateOff ();
3568 }
3569 
3570 Time
3572 {
3573  return m_state->GetDelayUntilIdle ();
3574 }
3575 
3576 Time
3578 {
3579  return m_state->GetLastRxStartTime ();
3580 }
3581 
3582 void
3584 {
3585  NS_LOG_FUNCTION (this);
3586  //We are here because we have received the first bit of a packet and we are
3587  //not going to be able to synchronize on it
3588  //In this model, CCA becomes busy when the aggregation of all signals as
3589  //tracked by the InterferenceHelper class is higher than the CcaBusyThreshold
3590 
3592  if (!delayUntilCcaEnd.IsZero ())
3593  {
3594  NS_LOG_DEBUG ("Calling SwitchMaybeToCcaBusy for " << delayUntilCcaEnd.As (Time::S));
3595  m_state->SwitchMaybeToCcaBusy (delayUntilCcaEnd);
3596  }
3597 }
3598 
3599 void
3601 {
3602  NS_LOG_FUNCTION (this);
3603  if (m_endPlcpRxEvent.IsRunning ())
3604  {
3606  }
3607  if (m_endRxEvent.IsRunning ())
3608  {
3609  m_endRxEvent.Cancel ();
3610  }
3611  NotifyRxDrop (m_currentEvent->GetPacket ());
3613  m_state->SwitchFromRxAbort ();
3614  m_currentEvent = 0;
3615 }
3616 
3617 void
3618 WifiPhy::StartRx (Ptr<Packet> packet, WifiTxVector txVector, MpduType mpdutype, double rxPowerW, Time rxDuration, Ptr<Event> event)
3619 {
3620  NS_LOG_FUNCTION (this << packet << txVector << +mpdutype << rxPowerW << rxDuration);
3621  if (rxPowerW > m_edThresholdW) //checked here, no need to check in the payload reception (current implementation assumes constant rx power over the packet duration)
3622  {
3623  AmpduTag ampduTag;
3624  WifiPreamble preamble = txVector.GetPreambleType ();
3625  if (preamble == WIFI_PREAMBLE_NONE && (m_mpdusNum == 0 || m_plcpSuccess == false))
3626  {
3627  m_plcpSuccess = false;
3628  m_mpdusNum = 0;
3629  NS_LOG_DEBUG ("drop packet because no PLCP preamble/header has been received");
3630  NotifyRxDrop (packet);
3632  return;
3633  }
3634  else if (preamble != WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum == 0)
3635  {
3636  //received the first MPDU in an MPDU
3637  m_mpdusNum = ampduTag.GetRemainingNbOfMpdus ();
3639  }
3640  else if (preamble == WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum > 0)
3641  {
3642  //received the other MPDUs that are part of the A-MPDU
3643  if (ampduTag.GetRemainingNbOfMpdus () < (m_mpdusNum - 1))
3644  {
3645  NS_LOG_DEBUG ("Missing MPDU from the A-MPDU " << m_mpdusNum - ampduTag.GetRemainingNbOfMpdus ());
3646  m_mpdusNum = ampduTag.GetRemainingNbOfMpdus ();
3647  }
3648  else
3649  {
3650  m_mpdusNum--;
3651  }
3652  }
3653  else if (preamble != WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum > 0)
3654  {
3655  NS_LOG_DEBUG ("New A-MPDU started while " << m_mpdusNum << " MPDUs from previous are lost");
3656  m_mpdusNum = ampduTag.GetRemainingNbOfMpdus ();
3657  }
3658  else if (preamble != WIFI_PREAMBLE_NONE && m_mpdusNum > 0 )
3659  {
3660  NS_LOG_DEBUG ("Didn't receive the last MPDUs from an A-MPDU " << m_mpdusNum);
3661  m_mpdusNum = 0;
3662  }
3663 
3664  NS_LOG_DEBUG ("sync to signal (power=" << rxPowerW << "W)");
3665  m_currentEvent = event;
3666  m_state->SwitchToRx (rxDuration);
3668  NotifyRxBegin (packet);
3670 
3671  if (preamble != WIFI_PREAMBLE_NONE)
3672  {
3674  Time preambleAndHeaderDuration = CalculatePlcpPreambleAndHeaderDuration (txVector);
3675  m_endPlcpRxEvent = Simulator::Schedule (preambleAndHeaderDuration, &WifiPhy::StartReceivePacket, this,
3676  packet, txVector, mpdutype, event);
3677  }
3678 
3681  packet, preamble, mpdutype, event);
3682  }
3683  else
3684  {
3685  NS_LOG_DEBUG ("drop packet because signal power too Small (" <<
3686  rxPowerW << "<" << m_edThresholdW << ")");
3687  NotifyRxDrop (packet);
3688  m_plcpSuccess = false;
3690  }
3691 }
3692 
3693 int64_t
3694 WifiPhy::AssignStreams (int64_t stream)
3695 {
3696  NS_LOG_FUNCTION (this << stream);
3697  m_random->SetStream (stream);
3698  return 1;
3699 }
3700 
3701 std::ostream& operator<< (std::ostream& os, WifiPhyState state)
3702 {
3703  switch (state)
3704  {
3705  case WifiPhyState::IDLE:
3706  return (os << "IDLE");
3708  return (os << "CCA_BUSY");
3709  case WifiPhyState::TX:
3710  return (os << "TX");
3711  case WifiPhyState::RX:
3712  return (os << "RX");
3714  return (os << "SWITCHING");
3715  case WifiPhyState::SLEEP:
3716  return (os << "SLEEP");
3717  case WifiPhyState::OFF:
3718  return (os << "OFF");
3719  default:
3720  NS_FATAL_ERROR ("Invalid WifiPhy state");
3721  return (os << "INVALID");
3722  }
3723 }
3724 
3725 } //namespace ns3
3726 
3727 namespace {
3728 
3732 static class Constructor
3733 {
3734 public:
3736  {
3827  }
3828 } g_constructor;
3829 
3830 }
static class anonymous_namespace{wifi-phy.cc}::Constructor g_constructor
the constructor
ERP-OFDM PHY (Clause 19, Section 19.5)
MpduInfo structure.
Definition: wifi-phy.h:53
static WifiMode GetVhtMcs6()
Return MCS 6 from VHT MCS values.
Definition: wifi-phy.cc:3349
static WifiMode GetOfdmRate9MbpsBW5MHz()
Return a WifiMode for OFDM at 9Mbps with 5MHz channel spacing.
Definition: wifi-phy.cc:3003
TracedCallback< Ptr< const Packet > > m_phyRxBeginTrace
The trace source fired when a packet begins the reception process from the medium.
Definition: wifi-phy.h:1663
Ptr< NetDevice > m_device
Pointer to the device.
Definition: wifi-phy.h:1787
static WifiMode GetErpOfdmRate24Mbps()
Return a WifiMode for ERP-OFDM at 24Mbps.
Definition: wifi-phy.cc:2694
uint8_t GetNTxPower(void) const
Return the number of available transmission power levels.
Definition: wifi-phy.cc:539
uint32_t m_txMpduReferenceNumber
A-MPDU reference number to identify all transmitted subframes belonging to the same received A-MPDU...
Definition: wifi-phy.h:1504
bool IsStateSwitching(void) const
Definition: wifi-phy.cc:3553
static WifiMode GetDsssRate11Mbps()
Return a WifiMode for DSSS at 11Mbps.
Definition: wifi-phy.cc:2631
bool IsStateOff(void) const
Definition: wifi-phy.cc:3565
double signal
in dBm
Definition: wifi-phy.h:48
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
static WifiMode GetHeMcs7()
Return MCS 7 from HE MCS values.
Definition: wifi-phy.cc:3439
std::pair< uint8_t, WifiPhyStandard > ChannelNumberStandardPair
A pair of a ChannelNumber and WifiPhyStandard.
Definition: wifi-phy.h:495
static WifiMode GetErpOfdmRate36Mbps()
Return a WifiMode for ERP-OFDM at 36Mbps.
Definition: wifi-phy.cc:2706
Signal event for a packet.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
OFDM PHY for the 5 GHz band (Clause 17 with 5 MHz channel bandwidth)
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
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:532
uint8_t m_channelNumber
Operating channel number.
Definition: wifi-phy.h:1780
double m_rxGainDb
Reception gain (dB)
Definition: wifi-phy.h:1759
bool DefineChannelNumber(uint8_t channelNumber, WifiPhyStandard standard, uint16_t frequency, uint16_t channelWidth)
Add a channel definition to the WifiPhy.
Definition: wifi-phy.cc:1024
static WifiMode GetVhtMcs8()
Return MCS 8 from VHT MCS values.
Definition: wifi-phy.cc:3365
ERP-OFDM PHY (19.5)
Definition: wifi-mode.h:54
void SetShortPlcpPreambleSupported(bool preamble)
Enable or disable short PLCP preamble.
Definition: wifi-phy.cc:637
AttributeValue implementation for Boolean.
Definition: boolean.h:36
void SetNumberOfReceiveAntennas(uint8_t rx)
Set the number of RX antennas in the receiver corresponding to this interference helper.
double GetRxGain(void) const
Return the reception gain (dB).
Definition: wifi-phy.cc:565
bool IsModeSupported(WifiMode mode) const
Check if the given WifiMode is supported by the PHY.
Definition: wifi-phy.cc:3479
static WifiMode GetOfdmRate9Mbps()
Return a WifiMode for OFDM at 9Mbps.
Definition: wifi-phy.cc:2757
HT PHY for the 5 GHz band (clause 20)
Ptr< ErrorRateModel > GetErrorRateModel(void) const
Return the error rate model.
static WifiMode GetOfdmRate18MbpsBW10MHz()
Return a WifiMode for OFDM at 18Mbps with 10MHz channel spacing.
Definition: wifi-phy.cc:2904
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
static WifiMode GetOfdmRate27MbpsBW10MHz()
Return a WifiMode for OFDM at 27Mbps with 10MHz channel spacing.
Definition: wifi-phy.cc:2928
TracedCallback< Ptr< const Packet >, uint16_t, WifiTxVector, MpduInfo, SignalNoiseDbm > m_phyMonitorSniffRxTrace
A trace source that emulates a wifi device in monitor mode sniffing a packet being received...
Definition: wifi-phy.h:1692
double m_txGainDb
Transmission gain (dB)
Definition: wifi-phy.h:1758
WifiMode GetMcs(uint8_t mcs) const
The WifiPhy::GetMcs() method is used (e.g., by a WifiRemoteStationManager) to determine the set of tr...
Definition: wifi-phy.cc:3523
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
static WifiMode GetOfdmRate3MbpsBW5MHz()
Return a WifiMode for OFDM at 3Mbps with 5MHz channel spacing.
Definition: wifi-phy.cc:2967
static WifiMode GetVhtMcs0()
Return MCS 0 from VHT MCS values.
Definition: wifi-phy.cc:3301
void MaybeCcaBusyDuration(void)
Eventually switch to CCA busy.
Definition: wifi-phy.cc:2488
WifiPhyStandard GetStandard(void) const
Get the configured Wi-Fi standard.
Definition: wifi-phy.cc:1180
virtual ~WifiPhy()
Definition: wifi-phy.cc:383
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:831
void SetLdpc(bool ldpc)
Enable or disable LDPC.
Definition: wifi-phy.cc:571
static WifiMode GetDsssRate1Mbps()
Return a WifiMode for DSSS at 1Mbps.
Definition: wifi-phy.cc:2592
bool m_ldpc
Flag if LDPC is used.
Definition: wifi-phy.h:1764
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
void ResumeFromOff(void)
Resume from off mode.
Definition: wifi-phy.cc:1609
void ResumeFromSleep(void)
Resume from sleep mode.
Definition: wifi-phy.cc:1579
bool GetShortGuardInterval(void) const
Return whether short guard interval is supported.
Definition: wifi-phy.cc:617
WifiTxVector GetWifiTxVector(void) const
Getter for WifiTxVector parameter.
Definition: wifi-phy-tag.cc:80
bool GetGreenfield(void) const
Return whether Greenfield is supported.
Definition: wifi-phy.cc:604
static WifiMode GetHeMcs5()
Return MCS 5 from HE MCS values.
Definition: wifi-phy.cc:3423
static WifiMode GetErpOfdmRate18Mbps()
Return a WifiMode for ERP-OFDM at 18Mbps.
Definition: wifi-phy.cc:2682
void SetTxGain(double gain)
Sets the transmission gain (dB).
Definition: wifi-phy.cc:545
void Configure80211ax(void)
Configure WifiPhy with appropriate channel frequency and supported rates for 802.11ax standard...
Definition: wifi-phy.cc:999
double DbmToW(double dBm)
Convert from dBm to Watts.
Definition: wifi-utils.cc:38
static WifiMode GetHtMcs7()
Return MCS 7 from HT MCS values.
Definition: wifi-phy.cc:3098
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: boolean.h:84
virtual void DoDispose(void)
Destructor implementation.
Definition: wifi-phy.cc:389
def start()
Definition: core.py:1844
bool Is2_4Ghz(double frequency)
Definition: wifi-utils.cc:56
void SetStbc(bool stbc)
Enable or disable STBC.
Definition: wifi-phy.cc:584
static Time GetPlcpHtSigHeaderDuration(WifiPreamble preamble)
Definition: wifi-phy.cc:1705
static WifiMode GetVhtMcs5()
Return MCS 5 from VHT MCS values.
Definition: wifi-phy.cc:3341
uint8_t GetNBssMembershipSelectors(void) const
The WifiPhy::NBssMembershipSelectors() method is used (e.g., by a WifiRemoteStationManager) to determ...
Definition: wifi-phy.cc:1320
The PHY layer is sleeping.
static WifiMode GetHtMcs22()
Return MCS 22 from HT MCS values.
Definition: wifi-phy.cc:3218
static WifiMode GetHtMcs14()
Return MCS 14 from HT MCS values.
Definition: wifi-phy.cc:3154
static WifiMode GetOfdmRate12Mbps()
Return a WifiMode for OFDM at 12Mbps.
Definition: wifi-phy.cc:2769
TracedCallback< Ptr< const Packet > > m_phyRxEndTrace
The trace source fired when a packet ends the reception process from the medium.
Definition: wifi-phy.h:1671
#define HE_PHY
Definition: wifi-phy.h:33
bool IsStateCcaBusy(void) const
Definition: wifi-phy.cc:3529
void SetReceiveErrorCallback(RxErrorCallback callback)
Definition: wifi-phy.cc:420
static WifiMode GetHtMcs31()
Return MCS 31 from HT MCS values.
Definition: wifi-phy.cc:3290
void StartRx(Ptr< Packet > packet, WifiTxVector txVector, MpduType mpdutype, double rxPowerW, Time rxDuration, Ptr< Event > event)
Starting receiving the packet after having detected the medium is idle or after a reception switch...
Definition: wifi-phy.cc:3618
static WifiMode GetHtMcs21()
Return MCS 21 from HT MCS values.
Definition: wifi-phy.cc:3210
#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
bool IsInitialized(void) const
Check if the object has been initialized.
Definition: object.cc:208
static WifiMode GetHtMcs30()
Return MCS 30 from HT MCS values.
Definition: wifi-phy.cc:3282
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
void SetErrorRateModel(const Ptr< ErrorRateModel > rate)
Set the error rate model for this interference helper.
std::vector< uint8_t > m_bssMembershipSelectorSet
the BSS membership selector set
Definition: wifi-phy.h:1747
HE PHY for the 2.4 GHz band (clause 26)
static WifiMode GetHtMcs10()
Return MCS 10 from HT MCS values.
Definition: wifi-phy.cc:3122
void StartReceivePreambleAndHeader(Ptr< Packet > packet, double rxPowerW, Time rxDuration)
Starting receiving the plcp of a packet (i.e.
Definition: wifi-phy.cc:2358
static WifiMode GetHtMcs26()
Return MCS 26 from HT MCS values.
Definition: wifi-phy.cc:3250
static WifiMode GetOfdmRate1_5MbpsBW5MHz()
Return a WifiMode for OFDM at 1.5Mbps with 5MHz channel spacing.
Definition: wifi-phy.cc:2943
OFDM PHY for the 5 GHz band (Clause 17 with 10 MHz channel bandwidth)
MpduType GetMpduType(void) const
Getter for mpduType parameter.
Definition: wifi-phy-tag.cc:86
static WifiMode GetHtMcs17()
Return MCS 17 from HT MCS values.
Definition: wifi-phy.cc:3178
static WifiMode GetHtMcs24()
Return MCS 24 from HT MCS values.
Definition: wifi-phy.cc:3234
bool IsStbc(void) const
Check if STBC is used or not.
static WifiMode GetOfdmRate4_5MbpsBW10MHz()
Return a WifiMode for OFDM at 4.5Mbps with 10MHz channel spacing.
Definition: wifi-phy.cc:2856
static WifiMode GetOfdmRate54Mbps()
Return a WifiMode for OFDM at 54Mbps.
Definition: wifi-phy.cc:2829
void SetMobility(const Ptr< MobilityModel > mobility)
assign a mobility model to this device
Definition: wifi-phy.cc:662
void UnregisterListener(WifiPhyListener *listener)
Definition: wifi-phy.cc:432
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:498
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
bool IsStrictlyPositive(void) const
Definition: nstime.h:308
static WifiMode GetHeMcs4()
Return MCS 4 from HE MCS values.
Definition: wifi-phy.cc:3415
void SendPacket(Ptr< const Packet > packet, WifiTxVector txVector, MpduType mpdutype=NORMAL_MPDU)
Definition: wifi-phy.cc:2290
uint8_t GetNess(void) const
void ConfigureHolland(void)
Configure WifiPhy with appropriate channel frequency and supported rates for holland.
Definition: wifi-phy.cc:881
bool IsStateIdle(void) const
Definition: wifi-phy.cc:3535
uint16_t GetGuardInterval(void) const
bool Is5Ghz(double frequency)
Definition: wifi-utils.cc:62
void NotifyTxDrop(Ptr< const Packet > packet)
Public method used to fire a PhyTxDrop trace.
Definition: wifi-phy.cc:2254
HT PHY for the 2.4 GHz band (clause 20)
void SetGreenfield(bool greenfield)
Enable or disable Greenfield support.
Definition: wifi-phy.cc:597
VHT PHY (Clause 22)
Definition: wifi-mode.h:60
void Configure80211_10Mhz(void)
Configure WifiPhy with appropriate channel frequency and supported rates for 802.11a standard with 10...
Definition: wifi-phy.cc:851
TimeWithUnit As(const enum Unit unit) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:388
HR/DSSS PHY (Clause 18)
Definition: wifi-mode.h:48
std::pair< uint16_t, uint16_t > FrequencyWidthPair
A pair of a center Frequency and a ChannelWidth.
Definition: wifi-phy.h:499
static WifiMode GetHtMcs8()
Return MCS 8 from HT MCS values.
Definition: wifi-phy.cc:3106
uint8_t m_nTxPower
Number of available transmission power levels.
Definition: wifi-phy.h:1762
static WifiMode GetHtMcs18()
Return MCS 18 from HT MCS values.
Definition: wifi-phy.cc:3186
void NotifyTxBegin(Ptr< const Packet > packet)
Public method used to fire a PhyTxBegin trace.
Definition: wifi-phy.cc:2242
virtual void SetFrequency(uint16_t freq)
Definition: wifi-phy.cc:1186
static WifiMode GetVhtMcs4()
Return MCS 4 from VHT MCS values.
Definition: wifi-phy.cc:3333
static WifiMode GetHtMcs27()
Return MCS 27 from HT MCS values.
Definition: wifi-phy.cc:3258
void SetFrameCaptureModel(const Ptr< FrameCaptureModel > frameCaptureModel)
Sets the frame capture model.
Definition: wifi-phy.cc:688
TracedCallback< Ptr< const Packet >, uint16_t, WifiTxVector, MpduInfo > m_phyMonitorSniffTxTrace
A trace source that emulates a wifi device in monitor mode sniffing a packet being transmitted...
Definition: wifi-phy.h:1706
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
double GetEdThreshold(void) const
Return the energy detection threshold (dBm).
Definition: wifi-phy.cc:479
static WifiMode GetOfdmRate36Mbps()
Return a WifiMode for OFDM at 36Mbps.
Definition: wifi-phy.cc:2805
uint8_t m_initialChannelNumber
Initial channel number.
Definition: wifi-phy.h:1781
static WifiMode GetVhtMcs7()
Return MCS 7 from VHT MCS values.
Definition: wifi-phy.cc:3357
static WifiMode GetOfdmRate6MbpsBW5MHz()
Return a WifiMode for OFDM at 6Mbps with 5MHz channel spacing.
Definition: wifi-phy.cc:2991
bool IsStateSleep(void) const
Definition: wifi-phy.cc:3559
bool IsExpired(void) const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
Definition: event-id.cc:59
bool GetStbc(void) const
Return whether STBC is supported.
Definition: wifi-phy.cc:591
static WifiMode GetVhtMcs3()
Return MCS 3 from VHT MCS values.
Definition: wifi-phy.cc:3325
void ConfigureDefaultsForStandard(WifiPhyStandard standard)
Configure the PHY-level parameters for different Wi-Fi standard.
Definition: wifi-phy.cc:730
static Time GetPlcpSigA1Duration(WifiPreamble preamble)
Definition: wifi-phy.cc:1720
MpduType
The type of an MPDU.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
WifiModeList m_deviceMcsSet
the device MCS set
Definition: wifi-phy.h:1745
mobility
Definition: third.py:101
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:446
uint16_t m_channelCenterFrequency
Center frequency in MHz.
Definition: wifi-phy.h:1751
void SetDevice(const Ptr< NetDevice > device)
Sets the device this PHY is associated with.
Definition: wifi-phy.cc:650
struct InterferenceHelper::SnrPer CalculatePlcpHeaderSnrPer(Ptr< Event > event) const
Calculate the SNIR at the start of the plcp header and accumulate all SNIR changes in the snir vector...
bool GetShortPlcpPreambleSupported(void) const
Return whether short PLCP preamble is supported.
Definition: wifi-phy.cc:644
static WifiMode GetHtMcs16()
Return MCS 16 from HT MCS values.
Definition: wifi-phy.cc:3170
uint16_t GetChannelWidth(void) const
Definition: wifi-phy.cc:1263
static WifiMode GetErpOfdmRate54Mbps()
Return a WifiMode for ERP-OFDM at 54Mbps.
Definition: wifi-phy.cc:2730
WifiPreamble GetPreambleType(void) const
uint16_t m_mpdusNum
carries the number of expected mpdus that are part of an A-MPDU
Definition: wifi-phy.h:1502
void AddSupportedChannelWidth(uint16_t channelwidth)
Definition: wifi-phy.cc:1332
static WifiMode GetHtMcs29()
Return MCS 29 from HT MCS values.
Definition: wifi-phy.cc:3274
static WifiMode GetHtMcs11()
Return MCS 11 from HT MCS values.
Definition: wifi-phy.cc:3130
uint8_t GetNMcs(void) const
The WifiPhy::GetNMcs() method is used (e.g., by a WifiRemoteStationManager) to determine the set of t...
Definition: wifi-phy.cc:3517
void NotifyRxDrop(Ptr< const Packet > packet)
Public method used to fire a PhyRxDrop trace.
Definition: wifi-phy.cc:2272
Time CalculateTxDuration(uint32_t size, WifiTxVector txVector, uint16_t frequency)
Definition: wifi-phy.cc:2236
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
Definition: wifi-preamble.h:30
Keep track of the current position and velocity of an object.
static ChannelToFrequencyWidthMap m_channelToFrequencyWidth
the channel to frequency width map
Definition: wifi-phy.h:1777
WifiPhyStandard
Identifies the PHY specification that a Wifi device is configured to use.
The MPDU is not part of an A-MPDU.
static Time GetPlcpSigA2Duration(WifiPreamble preamble)
Definition: wifi-phy.cc:1735
HE PHY for the 5 GHz band (clause 26)
bool DoFrequencySwitch(uint16_t frequency)
The default implementation does nothing and returns true.
Definition: wifi-phy.cc:1473
static WifiMode GetHtMcs2()
Return MCS 2 from HT MCS values.
Definition: wifi-phy.cc:3058
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: pointer.h:220
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1381
Ptr< MobilityModel > m_mobility
Pointer to the mobility model.
Definition: wifi-phy.h:1788
bool IsZero(void) const
Definition: nstime.h:288
virtual void StartTx(Ptr< Packet > packet, WifiTxVector txVector, Time txDuration)=0
AttributeValue implementation for Time.
Definition: nstime.h:1076
bool GetLdpc(void) const
Return if LDPC is supported.
Definition: wifi-phy.cc:578
static Time GetPlcpPreambleDuration(WifiTxVector txVector)
Definition: wifi-phy.cc:1882
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1038
receive notifications about phy events.
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:1655
void NotifyMonitorSniffRx(Ptr< const Packet > packet, uint16_t channelFreqMhz, WifiTxVector txVector, MpduInfo aMpdu, SignalNoiseDbm signalNoise)
Public method used to fire a MonitorSniffer trace for a wifi packet being received.
Definition: wifi-phy.cc:2278
Time GetEnergyDuration(double energyW) const
bool m_shortPreamble
Flag if short PLCP preamble is supported.
Definition: wifi-phy.h:1768
Ptr< Event > Add(Ptr< const Packet > packet, WifiTxVector txVector, Time duration, double rxPower)
Add the packet-related signal to interference helper.
static WifiMode GetHeMcs3()
Return MCS 3 from HE MCS values.
Definition: wifi-phy.cc:3407
static Time GetPlcpSigBDuration(WifiPreamble preamble)
Definition: wifi-phy.cc:1750
Hold an unsigned integer type.
Definition: uinteger.h:44
static WifiMode CreateWifiMode(std::string uniqueName, WifiModulationClass modClass, bool isMandatory, WifiCodeRate codingRate, uint16_t constellationSize)
Definition: wifi-mode.cc:694
EventId m_endPlcpRxEvent
the end PLCP receive event
Definition: wifi-phy.h:1508
static WifiMode GetHtMcs12()
Return MCS 12 from HT MCS values.
Definition: wifi-phy.cc:3138
Ptr< WifiRadioEnergyModel > m_wifiRadioEnergyModel
Wifi radio energy model.
Definition: wifi-phy.h:1792
static WifiMode GetErpOfdmRate48Mbps()
Return a WifiMode for ERP-OFDM at 48Mbps.
Definition: wifi-phy.cc:2718
static Time CalculatePlcpPreambleAndHeaderDuration(WifiTxVector txVector)
Definition: wifi-phy.cc:2214
void SetTxPowerEnd(double end)
Sets the maximum available transmission power level (dBm).
Definition: wifi-phy.cc:519
static WifiMode GetOfdmRate12MbpsBW10MHz()
Return a WifiMode for OFDM at 12Mbps with 10MHz channel spacing.
Definition: wifi-phy.cc:2892
WifiMode GetMode(void) const
static WifiMode GetHeMcs11()
Return MCS 11 from HE MCS values.
Definition: wifi-phy.cc:3471
The PHY layer has sense the medium busy through the CCA mechanism.
HT PHY (Clause 20)
Definition: wifi-mode.h:58
Time GetDelayUntilIdle(void)
Definition: wifi-phy.cc:3571
uint32_t m_rxMpduReferenceNumber
A-MPDU reference number to identify all received subframes belonging to the same received A-MPDU...
Definition: wifi-phy.h:1505
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received.
Definition: wifi-phy.h:1678
double m_edThresholdW
Energy detection threshold in watts.
Definition: wifi-phy.h:1756
void Configure80211_5Mhz()
Configure WifiPhy with appropriate channel frequency and supported rates for 802.11a standard with 5M...
Definition: wifi-phy.cc:866
FrequencyWidthPair GetFrequencyWidthForChannelNumberStandard(uint8_t channelNumber, WifiPhyStandard standard) const
Lookup frequency/width pair for channelNumber/standard pair.
Definition: wifi-phy.cc:1353
The aim of the AmpduTag is to provide means for a MAC to specify that a packet includes A-MPDU since ...
Definition: ampdu-tag.h:36
double CalculateSnr(WifiTxVector txVector, double ber) const
Definition: wifi-phy.cc:724
void NotifyRxBegin(Ptr< const Packet > packet)
Public method used to fire a PhyRxBegin trace.
Definition: wifi-phy.cc:2260
static WifiMode GetOfdmRate18Mbps()
Return a WifiMode for OFDM at 18Mbps.
Definition: wifi-phy.cc:2781
void SetCapabilitiesChangedCallback(Callback< void > callback)
Definition: wifi-phy.cc:438
void SetOffMode(void)
Put in off mode.
Definition: wifi-phy.cc:1557
static WifiMode GetOfdmRate9MbpsBW10MHz()
Return a WifiMode for OFDM at 9Mbps with 10MHz channel spacing.
Definition: wifi-phy.cc:2880
static WifiMode GetOfdmRate12MbpsBW5MHz()
Return a WifiMode for OFDM at 12Mbps with 5MHz channel spacing.
Definition: wifi-phy.cc:3015
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:500
void AbortCurrentReception(void)
Due to newly arrived signal, the current reception cannot be continued and has to be aborted...
Definition: wifi-phy.cc:3600
TracedCallback< Ptr< const Packet > > m_phyTxBeginTrace
The trace source fired when a packet begins the transmission process on the medium.
Definition: wifi-phy.h:1639
double GetPowerDbm(uint8_t power) const
Get the power of the given power level in dBm.
Definition: wifi-phy.cc:700
static WifiMode GetVhtMcs1()
Return MCS 1 from VHT MCS values.
Definition: wifi-phy.cc:3309
This is intended to be the configuration used in this paper: Gavin Holland, Nitin Vaidya and Paramvir...
static WifiMode GetOfdmRate48Mbps()
Return a WifiMode for OFDM at 48Mbps.
Definition: wifi-phy.cc:2817
void SetErrorRateModel(const Ptr< ErrorRateModel > rate)
Sets the error rate model.
Definition: wifi-phy.cc:681
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
static WifiMode GetHeMcs9()
Return MCS 9 from HE MCS values.
Definition: wifi-phy.cc:3455
The MPDU is part of an A-MPDU, but is not the last aggregate.
double f(double x, void *params)
Definition: 80211b.c:70
static WifiMode GetHtMcs0()
Return MCS 0 from HT MCS values.
Definition: wifi-phy.cc:3042
uint8_t GetRemainingNbOfMpdus(void) const
Definition: ampdu-tag.cc:89
Ptr< MobilityModel > GetMobility(void) const
Return the mobility model this PHY is associated with.
Definition: wifi-phy.cc:668
static TypeId GetTypeId(void)
Get the type ID.
Definition: wifi-phy.cc:155
Time GetChannelSwitchDelay(void) const
Definition: wifi-phy.cc:718
OFDM PHY for the 5 GHz band (Clause 17)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void NotifyRxStart()
Notify that RX has started.
Hold objects of type Ptr<T>.
Definition: pointer.h:36
void SetWifiRadioEnergyModel(const Ptr< WifiRadioEnergyModel > wifiRadioEnergyModel)
Sets the wifi radio energy model.
Definition: wifi-phy.cc:694
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:367
Time m_guardInterval
Supported HE guard interval.
Definition: wifi-phy.h:1770
void EraseEvents(void)
Erase all events.
uint16_t GetFrequency(void) const
Definition: wifi-phy.cc:1243
The PHY layer is IDLE.
uint8_t GetNumberOfAntennas(void) const
Definition: wifi-phy.cc:1277
static WifiMode GetOfdmRate24Mbps()
Return a WifiMode for OFDM at 24Mbps.
Definition: wifi-phy.cc:2793
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Definition: boolean.cc:121
virtual void SetChannelWidth(uint16_t channelwidth)
Definition: wifi-phy.cc:1249
WifiPhyState
The state of the PHY layer.
static WifiMode GetHeMcs1()
Return MCS 1 from HE MCS values.
Definition: wifi-phy.cc:3391
DSSS PHY (Clause 15) and HR/DSSS PHY (Clause 18)
static WifiMode GetHtMcs13()
Return MCS 13 from HT MCS values.
Definition: wifi-phy.cc:3146
void SetShortGuardInterval(bool shortGuardInterval)
Enable or disable support for HT/VHT short guard interval.
Definition: wifi-phy.cc:610
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
static WifiMode GetHeMcs0()
Return MCS 0 from HE MCS values.
Definition: wifi-phy.cc:3383
struct InterferenceHelper::SnrPer CalculatePlcpPayloadSnrPer(Ptr< Event > event) const
Calculate the SNIR at the start of the plcp payload and accumulate all SNIR changes in the snir vecto...
static WifiMode GetHeMcs10()
Return MCS 10 from HE MCS values.
Definition: wifi-phy.cc:3463
double GetValue(double min, double max)
Get the next random value, as a double in the specified range .
static WifiMode GetHtMcs20()
Return MCS 20 from HT MCS values.
Definition: wifi-phy.cc:3202
static WifiMode GetHeMcs2()
Return MCS 2 from HE MCS values.
Definition: wifi-phy.cc:3399
static WifiMode GetHtMcs5()
Return MCS 5 from HT MCS values.
Definition: wifi-phy.cc:3082
void SetMaxSupportedRxSpatialStreams(uint8_t streams)
Definition: wifi-phy.cc:1302
void SetCcaMode1Threshold(double threshold)
Sets the CCA threshold (dBm).
Definition: wifi-phy.cc:485
static WifiMode GetVhtMcs2()
Return MCS 2 from VHT MCS values.
Definition: wifi-phy.cc:3317
virtual void SetChannelNumber(uint8_t id)
Set channel number.
Definition: wifi-phy.cc:1361
static WifiMode GetDsssRate5_5Mbps()
Return a WifiMode for DSSS at 5.5Mbps.
Definition: wifi-phy.cc:2619
void Configure80211ac(void)
Configure WifiPhy with appropriate channel frequency and supported rates for 802.11ac standard...
Definition: wifi-phy.cc:979
virtual void DoInitialize(void)
Initialize() implementation.
Definition: wifi-phy.cc:401
static WifiMode GetOfdmRate2_25MbpsBW5MHz()
Return a WifiMode for OFDM at 2.25Mbps with 5MHz channel spacing.
Definition: wifi-phy.cc:2955
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: nstime.h:1077
double WToDbm(double w)
Convert from Watts to dBm.
Definition: wifi-utils.cc:44
uint8_t GetChannelNumber(void) const
Return current channel number.
Definition: wifi-phy.cc:1415
WifiPhyStandard m_standard
WifiPhyStandard.
Definition: wifi-phy.h:1749
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
void SetGuardInterval(Time guardInterval)
Definition: wifi-phy.cc:623
uint8_t FindChannelNumberForFrequencyWidth(uint16_t frequency, uint16_t width) const
Look for channel number matching the frequency and width.
Definition: wifi-phy.cc:1041
static WifiMode GetErpOfdmRate9Mbps()
Return a WifiMode for ERP-OFDM at 9Mbps.
Definition: wifi-phy.cc:2658
void NotifyTxEnd(Ptr< const Packet > packet)
Public method used to fire a PhyTxEnd trace.
Definition: wifi-phy.cc:2248
Ptr< UniformRandomVariable > m_random
Provides uniform random variables.
Definition: wifi-phy.h:1499
double DbToRatio(double dB)
Convert from dB to ratio.
Definition: wifi-utils.cc:32
uint8_t m_txSpatialStreams
Number of supported TX spatial streams.
Definition: wifi-phy.h:1773
double GetTxPowerStart(void) const
Return the minimum available transmission power level (dBm).
Definition: wifi-phy.cc:513
double RatioToDb(double ratio)
Convert from ratio to dB.
Definition: wifi-utils.cc:50
void InitializeFrequencyChannelNumber(void)
post-construction setting of frequency and/or channel number
Definition: wifi-phy.cc:444
std::vector< uint16_t > GetSupportedChannelWidthSet(void) const
Definition: wifi-phy.cc:1347
uint8_t GetNModes(void) const
The WifiPhy::GetNModes() and WifiPhy::GetMode() methods are used (e.g., by a WifiRemoteStationManager...
Definition: wifi-phy.cc:3505
Ptr< FrameCaptureModel > m_frameCaptureModel
Frame capture model.
Definition: wifi-phy.h:1791
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: double.h:42
void SetRxGain(double gain)
Sets the reception gain (dB).
Definition: wifi-phy.cc:558
void Configure80211b(void)
Configure WifiPhy with appropriate channel frequency and supported rates for 802.11b standard...
Definition: wifi-phy.cc:824
No explicit coding (e.g., DSSS rates)
Definition: wifi-mode.h:75
void EndReceive(Ptr< Packet > packet, WifiPreamble preamble, MpduType mpdutype, Ptr< Event > event)
The last bit of the packet has arrived.
Definition: wifi-phy.cc:2541
void SetReceiveOkCallback(RxOkCallback callback)
Definition: wifi-phy.cc:414
WifiMode GetMode(uint8_t mode) const
The WifiPhy::GetNModes() and WifiPhy::GetMode() methods are used (e.g., by a WifiRemoteStationManager...
Definition: wifi-phy.cc:3511
uint16_t m_channelWidth
Channel width.
Definition: wifi-phy.h:1754
uint8_t GetBssMembershipSelector(uint8_t selector) const
The WifiPhy::BssMembershipSelector() method is used (e.g., by a WifiRemoteStationManager) to determin...
Definition: wifi-phy.cc:1326
static WifiMode GetErpOfdmRate6Mbps()
Return a WifiMode for ERP-OFDM at 6Mbps.
Definition: wifi-phy.cc:2646
uint8_t GetFrameComplete(void) const
Getter for frameComplete parameter.
Definition: wifi-phy-tag.cc:92
void RegisterListener(WifiPhyListener *listener)
Definition: wifi-phy.cc:426
bool IsStateTx(void) const
Definition: wifi-phy.cc:3547
void ConfigureChannelForStandard(WifiPhyStandard standard)
Configure the PHY-level parameters for different Wi-Fi standard.
Definition: wifi-phy.cc:1069
void SetMaxSupportedTxSpatialStreams(uint8_t streams)
Definition: wifi-phy.cc:1283
The PHY layer is sending a packet.
static WifiMode GetErpOfdmRate12Mbps()
Return a WifiMode for ERP-OFDM at 12Mbps.
Definition: wifi-phy.cc:2670
bool m_plcpSuccess
Flag if the PLCP of the packet or the first MPDU in an A-MPDU has been received.
Definition: wifi-phy.h:1503
bool m_greenfield
Flag if GreenField format is supported.
Definition: wifi-phy.h:1766
EventId m_endRxEvent
the end reeive event
Definition: wifi-phy.h:1507
Ptr< WifiPhyStateHelper > m_state
Pointer to WifiPhyStateHelper.
Definition: wifi-phy.h:1500
void SetEdThreshold(double threshold)
Sets the energy detection threshold (dBm).
Definition: wifi-phy.cc:472
void NotifyRxEnd(Ptr< const Packet > packet)
Public method used to fire a PhyRxEnd trace.
Definition: wifi-phy.cc:2266
void Configure80211n(void)
Configure WifiPhy with appropriate channel frequency and supported rates for 802.11n standard...
Definition: wifi-phy.cc:962
void SetTxPowerStart(double start)
Sets the minimum available transmission power level (dBm).
Definition: wifi-phy.cc:506
double m_txPowerBaseDbm
Minimum transmission power (dBm)
Definition: wifi-phy.h:1760
bool IsMcsSupported(WifiMode mcs) const
Check if the given WifiMode is supported by the PHY.
Definition: wifi-phy.cc:3492
void NotifyRxEnd()
Notify that RX has ended.
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:852
void SetNoiseFigure(double value)
Set the noise figure.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:262
SignalNoiseDbm structure.
Definition: wifi-phy.h:46
uint32_t mpduRefNumber
MPDU ref number.
Definition: wifi-phy.h:56
bool m_frequencyChannelNumberInitialized
Store initialization state.
Definition: wifi-phy.h:1753
static WifiMode GetHtMcs19()
Return MCS 19 from HT MCS values.
Definition: wifi-phy.cc:3194
InterferenceHelper m_interference
Pointer to InterferenceHelper.
Definition: wifi-phy.h:1498
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Definition: packet.cc:859
static WifiMode GetHtMcs6()
Return MCS 6 from HT MCS values.
Definition: wifi-phy.cc:3090
bool m_isConstructed
true when ready to set frequency
Definition: wifi-phy.h:1750
double GetCcaMode1Threshold(void) const
Return the CCA threshold (dBm).
Definition: wifi-phy.cc:492
void StartReceivePacket(Ptr< Packet > packet, WifiTxVector txVector, MpduType mpdutype, Ptr< Event > event)
Starting receiving the payload of a packet (i.e.
Definition: wifi-phy.cc:2503
The MPDU is the last aggregate in an A-MPDU.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:270
void ConfigureHtDeviceMcsSet(void)
Configure the device Mcs set with the appropriate HtMcs modes for the number of available transmit sp...
Definition: wifi-phy.cc:893
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
The PHY layer is receiving a packet.
OFDM PHY (Clause 17)
Definition: wifi-mode.h:56
static WifiMode GetVhtPlcpHeaderMode()
Definition: wifi-phy.cc:1646
double m_totalAmpduNumSymbols
Number of symbols previously transmitted for the MPDUs in an A-MPDU, used for the computation of the ...
Definition: wifi-phy.h:1785
static WifiMode GetHtMcs28()
Return MCS 28 from HT MCS values.
Definition: wifi-phy.cc:3266
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:65
double GetTxPowerEnd(void) const
Return the maximum available transmission power level (dBm).
Definition: wifi-phy.cc:526
static WifiMode GetHtMcs9()
Return MCS 9 from HT MCS values.
Definition: wifi-phy.cc:3114
static WifiMode GetHtMcs4()
Return MCS 4 from HT MCS values.
Definition: wifi-phy.cc:3074
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
static WifiMode GetHtMcs25()
Return MCS 25 from HT MCS values.
Definition: wifi-phy.cc:3242
static WifiMode GetHeMcs8()
Return MCS 8 from HE MCS values.
Definition: wifi-phy.cc:3447
Tag for WifiTxVector and WifiPreamble information to be embedded in outgoing transmissions as a Packe...
Definition: wifi-phy-tag.h:36
The PHY layer is switched off.
void Configure80211g(void)
Configure WifiPhy with appropriate channel frequency and supported rates for 802.11g standard...
Definition: wifi-phy.cc:835
static WifiMode GetHePlcpHeaderMode()
Definition: wifi-phy.cc:1652
Ptr< NetDevice > GetDevice(void) const
Return the device this PHY is associated with.
Definition: wifi-phy.cc:656
uint8_t GetTxPowerLevel(void) const
double GetTxGain(void) const
Return the transmission gain (dB).
Definition: wifi-phy.cc:552
The PHY layer is switching to other channel.
void SetSleepMode(void)
Put in sleep mode.
Definition: wifi-phy.cc:1525
uint32_t m_totalAmpduSize
Total size of the previously transmitted MPDUs in an A-MPDU, used for the computation of the number o...
Definition: wifi-phy.h:1784
double noise
in dBm
Definition: wifi-phy.h:49
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1030
WifiModeList m_deviceRateSet
This vector holds the set of transmission modes that this WifiPhy(-derived class) can support...
Definition: wifi-phy.h:1744
void NotifyMonitorSniffTx(Ptr< const Packet > packet, uint16_t channelFreqMhz, WifiTxVector txVector, MpduInfo aMpdu)
Public method used to fire a MonitorSniffer trace for a wifi packet being transmitted.
Definition: wifi-phy.cc:2284
Time GetPayloadDuration(uint32_t size, WifiTxVector txVector, uint16_t frequency)
Definition: wifi-phy.cc:1936
void SetNumberOfAntennas(uint8_t antennas)
Definition: wifi-phy.cc:1269
uint16_t GetChannelWidth(void) const
second
Definition: nstime.h:114
static WifiMode GetHtMcs1()
Return MCS 1 from HT MCS values.
Definition: wifi-phy.cc:3050
static WifiMode GetHtMcs23()
Return MCS 23 from HT MCS values.
Definition: wifi-phy.cc:3226
A base class which provides memory management and object aggregation.
Definition: object.h:87
Time FemtoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1054
static WifiMode GetDsssRate2Mbps()
Return a WifiMode for DSSS at 2Mbps.
Definition: wifi-phy.cc:2604
static WifiMode GetVhtMcs9()
Return MCS 9 from VHT MCS values.
Definition: wifi-phy.cc:3373
#define HT_PHY
Definition: wifi-phy.h:35
virtual void ConfigureStandard(WifiPhyStandard standard)
Configure the PHY-level parameters for different Wi-Fi standard.
Definition: wifi-phy.cc:1119
static WifiMode GetOfdmRate6MbpsBW10MHz()
Return a WifiMode for OFDM at 6Mbps with 10MHz channel spacing.
Definition: wifi-phy.cc:2868
int64_t GetFemtoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:375
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Definition: packet.cc:874
double m_txPowerEndDbm
Maximum transmission power (dBm)
Definition: wifi-phy.h:1761
#define VHT_PHY
Definition: wifi-phy.h:34
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1270
static WifiMode GetPlcpHeaderMode(WifiTxVector txVector)
Definition: wifi-phy.cc:1767
static Time GetPlcpTrainingSymbolDuration(WifiTxVector txVector)
Definition: wifi-phy.cc:1658
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
static WifiMode GetOfdmRate24MbpsBW10MHz()
Return a WifiMode for OFDM at 24Mbps with 10MHz channel spacing.
Definition: wifi-phy.cc:2916
MpduType type
type
Definition: wifi-phy.h:55
Time m_channelSwitchDelay
Time required to switch between channel.
Definition: wifi-phy.h:1783
static WifiMode GetOfdmRate13_5MbpsBW5MHz()
Return a WifiMode for OFDM at 13.5Mbps with 5MHz channel spacing.
Definition: wifi-phy.cc:3027
uint8_t GetMcsValue(void) const
Definition: wifi-mode.cc:478
double m_ccaMode1ThresholdW
Clear channel assessment (CCA) threshold in watts.
Definition: wifi-phy.h:1757
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: uinteger.h:45
static WifiMode CreateWifiMcs(std::string uniqueName, uint8_t mcsValue, WifiModulationClass modClass)
Definition: wifi-mode.cc:732
uint8_t m_numberOfAntennas
Number of transmitters.
Definition: wifi-phy.h:1772
static Time GetPlcpHeaderDuration(WifiTxVector txVector)
Definition: wifi-phy.cc:1813
uint8_t GetMaxSupportedTxSpatialStreams(void) const
Definition: wifi-phy.cc:1296
a unique identifier for an interface.
Definition: type-id.h:58
static WifiMode GetHtMcs15()
Return MCS 15 from HT MCS values.
Definition: wifi-phy.cc:3162
Ptr< Event > m_currentEvent
Hold the current event.
Definition: wifi-phy.h:1790
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
Time GetLastRxStartTime(void) const
Return the start time of the last received packet.
Definition: wifi-phy.cc:3577
bool IsStateRx(void) const
Definition: wifi-phy.cc:3541
static WifiMode GetHtMcs3()
Return MCS 3 from HT MCS values.
Definition: wifi-phy.cc:3066
uint8_t m_rxSpatialStreams
Number of supported RX spatial streams.
Definition: wifi-phy.h:1774
std::vector< uint16_t > m_supportedChannelWidthSet
Supported channel width.
Definition: wifi-phy.h:1779
static WifiMode GetOfdmRate6Mbps()
Return a WifiMode for OFDM at 6Mbps.
Definition: wifi-phy.cc:2745
void SwitchMaybeToCcaBusy(void)
Check if Phy state should move to CCA busy state based on current state of interference tracker...
Definition: wifi-phy.cc:3583
bool m_shortGuardInterval
Flag if HT/VHT short guard interval is supported.
Definition: wifi-phy.h:1767
HE PHY (Clause 26)
Definition: wifi-mode.h:62
uint64_t GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:156
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:3694
DSSS PHY (Clause 15)
Definition: wifi-mode.h:46
static WifiMode GetHeMcs6()
Return MCS 6 from HE MCS values.
Definition: wifi-phy.cc:3431
static WifiMode GetHtPlcpHeaderMode()
Definition: wifi-phy.cc:1640
static WifiMode GetOfdmRate4_5MbpsBW5MHz()
Return a WifiMode for OFDM at 4.5Mbps with 5MHz channel spacing.
Definition: wifi-phy.cc:2979
uint8_t GetNss(void) const
bool m_stbc
Flag if STBC is used.
Definition: wifi-phy.h:1765
Callback< void > m_capabilitiesChangedCallback
Callback when PHY capabilities changed.
Definition: wifi-phy.h:1794
void Configure80211a(void)
Configure WifiPhy with appropriate channel frequency and supported rates for 802.11a standard...
Definition: wifi-phy.cc:809
uint8_t GetMaxSupportedRxSpatialStreams(void) const
Definition: wifi-phy.cc:1314
std::map< ChannelNumberStandardPair, FrequencyWidthPair > ChannelToFrequencyWidthMap
channel to frequency width map typedef
Definition: wifi-phy.h:1776
static WifiMode GetOfdmRate3MbpsBW10MHz()
Return a WifiMode for OFDM at 3Mbps with 10MHz channel spacing.
Definition: wifi-phy.cc:2844
TracedCallback< Ptr< const Packet > > m_phyTxEndTrace
The trace source fired when a packet ends the transmission process on the medium. ...
Definition: wifi-phy.h:1647
uint16_t m_initialFrequency
Store frequency until initialization.
Definition: wifi-phy.h:1752
bool DoChannelSwitch(uint8_t id)
The default implementation does nothing and returns true.
Definition: wifi-phy.cc:1421
Time GetGuardInterval(void) const
Definition: wifi-phy.cc:631