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 "wifi-phy.h"
23 #include "wifi-phy-state-helper.h"
24 #include "ns3/simulator.h"
25 #include "ns3/log.h"
26 #include "ns3/boolean.h"
27 #include "ns3/double.h"
28 #include "ns3/uinteger.h"
29 #include "ns3/pointer.h"
30 #include "wifi-phy-tag.h"
31 #include "ampdu-tag.h"
32 #include "wifi-utils.h"
33 #include "frame-capture-model.h"
34 
35 namespace ns3 {
36 
37 NS_LOG_COMPONENT_DEFINE ("WifiPhy");
38 
39 /****************************************************************
40  * This destructor is needed.
41  ****************************************************************/
42 
44 {
45 }
46 
47 /****************************************************************
48  * The actual WifiPhy class
49  ****************************************************************/
50 
52 
62 {
63  // 802.11b uses width of 22, while OFDM modes use width of 20
64  { std::make_pair (1, WIFI_PHY_STANDARD_80211b), std::make_pair (2412, 22) },
65  { std::make_pair (1, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2412, 20) },
66  { std::make_pair (2, WIFI_PHY_STANDARD_80211b), std::make_pair (2417, 22) },
67  { std::make_pair (2, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2417, 20) },
68  { std::make_pair (3, WIFI_PHY_STANDARD_80211b), std::make_pair (2422, 22) },
69  { std::make_pair (3, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2422, 20) },
70  { std::make_pair (4, WIFI_PHY_STANDARD_80211b), std::make_pair (2427, 22) },
71  { std::make_pair (4, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2427, 20) },
72  { std::make_pair (5, WIFI_PHY_STANDARD_80211b), std::make_pair (2432, 22) },
73  { std::make_pair (5, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2432, 20) },
74  { std::make_pair (6, WIFI_PHY_STANDARD_80211b), std::make_pair (2437, 22) },
75  { std::make_pair (6, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2437, 20) },
76  { std::make_pair (7, WIFI_PHY_STANDARD_80211b), std::make_pair (2442, 22) },
77  { std::make_pair (7, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2442, 20) },
78  { std::make_pair (8, WIFI_PHY_STANDARD_80211b), std::make_pair (2447, 22) },
79  { std::make_pair (8, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2447, 20) },
80  { std::make_pair (9, WIFI_PHY_STANDARD_80211b), std::make_pair (2452, 22) },
81  { std::make_pair (9, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2452, 20) },
82  { std::make_pair (10, WIFI_PHY_STANDARD_80211b), std::make_pair (2457, 22) },
83  { std::make_pair (10, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2457, 20) },
84  { std::make_pair (11, WIFI_PHY_STANDARD_80211b), std::make_pair (2462, 22) },
85  { std::make_pair (11, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2462, 20) },
86  { std::make_pair (12, WIFI_PHY_STANDARD_80211b), std::make_pair (2467, 22) },
87  { std::make_pair (12, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2467, 20) },
88  { std::make_pair (13, WIFI_PHY_STANDARD_80211b), std::make_pair (2472, 22) },
89  { std::make_pair (13, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (2472, 20) },
90  // Only defined for 802.11b
91  { std::make_pair (14, WIFI_PHY_STANDARD_80211b), std::make_pair (2484, 22) },
92 
93  // Now the 5GHz channels; UNSPECIFIED for 802.11a/n/ac/ax channels
94  // 20 MHz channels
95  { std::make_pair (36, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5180, 20) },
96  { std::make_pair (40, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5200, 20) },
97  { std::make_pair (44, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5220, 20) },
98  { std::make_pair (48, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5240, 20) },
99  { std::make_pair (52, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5260, 20) },
100  { std::make_pair (56, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5280, 20) },
101  { std::make_pair (60, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5300, 20) },
102  { std::make_pair (64, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5320, 20) },
103  { std::make_pair (100, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5500, 20) },
104  { std::make_pair (104, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5520, 20) },
105  { std::make_pair (108, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5540, 20) },
106  { std::make_pair (112, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5560, 20) },
107  { std::make_pair (116, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5580, 20) },
108  { std::make_pair (120, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5600, 20) },
109  { std::make_pair (124, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5620, 20) },
110  { std::make_pair (128, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5640, 20) },
111  { std::make_pair (132, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5660, 20) },
112  { std::make_pair (136, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5680, 20) },
113  { std::make_pair (140, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5700, 20) },
114  { std::make_pair (144, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5720, 20) },
115  { std::make_pair (149, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5745, 20) },
116  { std::make_pair (153, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5765, 20) },
117  { std::make_pair (157, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5785, 20) },
118  { std::make_pair (161, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5805, 20) },
119  { std::make_pair (165, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5825, 20) },
120  // 40 MHz channels
121  { std::make_pair (38, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5190, 40) },
122  { std::make_pair (46, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5230, 40) },
123  { std::make_pair (54, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5230, 40) },
124  { std::make_pair (62, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5310, 40) },
125  { std::make_pair (102, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5510, 40) },
126  { std::make_pair (110, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5550, 40) },
127  { std::make_pair (118, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5590, 40) },
128  { std::make_pair (126, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5590, 40) },
129  { std::make_pair (134, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5670, 40) },
130  { std::make_pair (142, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5710, 40) },
131  { std::make_pair (151, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5755, 40) },
132  { std::make_pair (159, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5795, 40) },
133  // 80 MHz channels
134  { std::make_pair (42, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5210, 80) },
135  { std::make_pair (58, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5290, 80) },
136  { std::make_pair (106, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5530, 80) },
137  { std::make_pair (122, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5610, 80) },
138  { std::make_pair (138, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5690, 80) },
139  { std::make_pair (155, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5775, 80) },
140  // 160 MHz channels
141  { std::make_pair (50, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5250, 160) },
142  { std::make_pair (114, WIFI_PHY_STANDARD_UNSPECIFIED), std::make_pair (5570, 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<uint8_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),
184  MakeDoubleChecker<double> ())
185  .AddAttribute ("CcaMode1Threshold",
186  "The energy of a received signal should be higher than "
187  "this threshold (dbm) to allow the PHY layer to declare CCA BUSY state.",
188  DoubleValue (-99.0),
191  MakeDoubleChecker<double> ())
192  .AddAttribute ("TxGain",
193  "Transmission gain (dB).",
194  DoubleValue (0.0),
197  MakeDoubleChecker<double> ())
198  .AddAttribute ("RxGain",
199  "Reception gain (dB).",
200  DoubleValue (0.0),
203  MakeDoubleChecker<double> ())
204  .AddAttribute ("TxPowerLevels",
205  "Number of transmission power levels available between "
206  "TxPowerStart and TxPowerEnd included.",
207  UintegerValue (1),
209  MakeUintegerChecker<uint32_t> ())
210  .AddAttribute ("TxPowerEnd",
211  "Maximum available transmission level (dbm).",
212  DoubleValue (16.0206),
215  MakeDoubleChecker<double> ())
216  .AddAttribute ("TxPowerStart",
217  "Minimum available transmission level (dbm).",
218  DoubleValue (16.0206),
221  MakeDoubleChecker<double> ())
222  .AddAttribute ("RxNoiseFigure",
223  "Loss (dB) in the Signal-to-Noise-Ratio due to non-idealities in the receiver."
224  " According to Wikipedia (http://en.wikipedia.org/wiki/Noise_figure), this is "
225  "\"the difference in decibels (dB) between"
226  " the noise output of the actual receiver to the noise output of an "
227  " ideal receiver with the same overall gain and bandwidth when the receivers "
228  " are connected to sources at the standard noise temperature T0 (usually 290 K)\".",
229  DoubleValue (7),
232  MakeDoubleChecker<double> ())
233  .AddAttribute ("State",
234  "The state of the PHY layer.",
235  PointerValue (),
237  MakePointerChecker<WifiPhyStateHelper> ())
238  .AddAttribute ("ChannelSwitchDelay",
239  "Delay between two short frames transmitted on different frequencies.",
240  TimeValue (MicroSeconds (250)),
242  MakeTimeChecker ())
243  .AddAttribute ("TxAntennas",
244  "The number of supported Tx antennas.",
245  UintegerValue (1),
247  MakeUintegerChecker<uint8_t> (1, 8),
249  "Not used anymore.")
250  .AddAttribute ("RxAntennas",
251  "The number of supported Rx antennas.",
252  UintegerValue (1),
254  MakeUintegerChecker<uint8_t> (1, 8),
256  "Not used anymore.")
257  .AddAttribute ("Antennas",
258  "The number of antennas on the device.",
259  UintegerValue (1),
262  MakeUintegerChecker<uint8_t> (1, 8))
263  .AddAttribute ("MaxSupportedTxSpatialStreams",
264  "The maximum number of supported TX spatial streams."
265  "This parameter is only valuable for 802.11n/ac/ax STAs and APs.",
266  UintegerValue (1),
269  MakeUintegerChecker<uint8_t> (1, 8))
270  .AddAttribute ("MaxSupportedRxSpatialStreams",
271  "The maximum number of supported RX spatial streams."
272  "This parameter is only valuable for 802.11n/ac/ax STAs and APs.",
273  UintegerValue (1),
276  MakeUintegerChecker<uint8_t> (1, 8))
277  .AddAttribute ("ShortGuardEnabled",
278  "Whether or not short guard interval is enabled for HT/VHT transmissions."
279  "This parameter is only valuable for 802.11n/ac/ax STAs and APs.",
280  BooleanValue (false),
284  .AddAttribute ("GuardInterval",
285  "Whether 800ns, 1600ns or 3200ns guard interval is used for HE transmissions."
286  "This parameter is only valuable for 802.11ax STAs and APs.",
287  TimeValue (NanoSeconds (3200)),
290  MakeTimeChecker (NanoSeconds (400), NanoSeconds (3200)))
291  .AddAttribute ("LdpcEnabled",
292  "Whether or not LDPC is enabled (not supported yet!).",
293  BooleanValue (false),
297  .AddAttribute ("STBCEnabled",
298  "Whether or not STBC is enabled (not supported yet!).",
299  BooleanValue (false),
303  .AddAttribute ("GreenfieldEnabled",
304  "Whether or not Greenfield is enabled."
305  "This parameter is only valuable for 802.11n STAs and APs.",
306  BooleanValue (false),
310  .AddAttribute ("ShortPlcpPreambleSupported",
311  "Whether or not short PLCP preamble is supported."
312  "This parameter is only valuable for 802.11b STAs and APs."
313  "Note: 802.11g APs and STAs always support short PLCP preamble.",
314  BooleanValue (false),
318  .AddAttribute ("FrameCaptureModel",
319  "Ptr to an object that implements the frame capture model",
320  PointerValue (0), //StringValue ("ns3::SimpleFrameCaptureModel"),
323  MakePointerChecker <FrameCaptureModel>())
324  .AddTraceSource ("PhyTxBegin",
325  "Trace source indicating a packet "
326  "has begun transmitting over the channel medium",
328  "ns3::Packet::TracedCallback")
329  .AddTraceSource ("PhyTxEnd",
330  "Trace source indicating a packet "
331  "has been completely transmitted over the channel. "
332  "NOTE: the only official WifiPhy implementation "
333  "available to this date never fires "
334  "this trace source.",
336  "ns3::Packet::TracedCallback")
337  .AddTraceSource ("PhyTxDrop",
338  "Trace source indicating a packet "
339  "has been dropped by the device during transmission",
341  "ns3::Packet::TracedCallback")
342  .AddTraceSource ("PhyRxBegin",
343  "Trace source indicating a packet "
344  "has begun being received from the channel medium "
345  "by the device",
347  "ns3::Packet::TracedCallback")
348  .AddTraceSource ("PhyRxEnd",
349  "Trace source indicating a packet "
350  "has been completely received from the channel medium "
351  "by the device",
353  "ns3::Packet::TracedCallback")
354  .AddTraceSource ("PhyRxDrop",
355  "Trace source indicating a packet "
356  "has been dropped by the device during reception",
358  "ns3::Packet::TracedCallback")
359  .AddTraceSource ("MonitorSnifferRx",
360  "Trace source simulating a wifi device in monitor mode "
361  "sniffing all received frames",
363  "ns3::WifiPhy::MonitorSnifferRxTracedCallback")
364  .AddTraceSource ("MonitorSnifferTx",
365  "Trace source simulating the capability of a wifi device "
366  "in monitor mode to sniff all frames being transmitted",
368  "ns3::WifiPhy::MonitorSnifferTxTracedCallback")
369  ;
370  return tid;
371 }
372 
374  : m_mpdusNum (0),
375  m_plcpSuccess (false),
376  m_txMpduReferenceNumber (0xffffffffffffffff),
377  m_rxMpduReferenceNumber (0xffffffffffffffff),
378  m_endRxEvent (),
379  m_endPlcpRxEvent (),
380  m_standard (WIFI_PHY_STANDARD_UNSPECIFIED),
381  m_isConstructed (false),
382  m_channelCenterFrequency (0),
383  m_initialFrequency (0),
384  m_frequencyChannelNumberInitialized (false),
385  m_channelNumber (0),
386  m_initialChannelNumber (0),
387  m_totalAmpduSize (0),
388  m_totalAmpduNumSymbols (0),
389  m_currentEvent (0)
390 {
391  NS_LOG_FUNCTION (this);
394  m_random = CreateObject<UniformRandomVariable> ();
395  m_state = CreateObject<WifiPhyStateHelper> ();
396 }
397 
399 {
400  NS_LOG_FUNCTION (this);
401 }
402 
403 void
405 {
406  NS_LOG_FUNCTION (this);
407  m_device = 0;
408  m_mobility = 0;
409  m_state = 0;
410  m_deviceRateSet.clear ();
411  m_deviceMcsSet.clear ();
412 }
413 
414 void
416 {
417  NS_LOG_FUNCTION (this);
418  m_isConstructed = true;
420  {
421  NS_LOG_DEBUG ("Frequency already initialized");
422  return;
423  }
425 }
426 
427 void
429 {
430  m_state->SetReceiveOkCallback (callback);
431 }
432 
433 void
435 {
436  m_state->SetReceiveErrorCallback (callback);
437 }
438 
439 void
441 {
442  m_state->RegisterListener (listener);
443 }
444 
445 void
447 {
448  m_state->UnregisterListener (listener);
449 }
450 
451 void
453 {
454  NS_LOG_FUNCTION (this);
455 
456  NS_ASSERT_MSG (m_frequencyChannelNumberInitialized == false, "Initialization called twice");
457 
458  // If frequency has been set to a non-zero value during attribute
459  // construction phase, the frequency and channel width will drive the
460  // initial configuration. If frequency has not been set, but both
461  // standard and channel number have been set, that pair will instead
462  // drive the configuration, and frequency and channel number will be
463  // aligned
464  if (m_initialFrequency != 0)
465  {
467  }
469  {
471  }
473  {
474  NS_FATAL_ERROR ("Error, ChannelNumber " << (uint16_t)GetChannelNumber () << " was set by user, but neither a standard nor a frequency");
475  }
477 }
478 
479 void
480 WifiPhy::SetEdThreshold (double threshold)
481 {
482  NS_LOG_FUNCTION (this << threshold);
483  m_edThresholdW = DbmToW (threshold);
484 }
485 
486 double
488 {
489  return m_edThresholdW;
490 }
491 
492 double
494 {
495  return WToDbm (m_edThresholdW);
496 }
497 
498 void
500 {
501  NS_LOG_FUNCTION (this << threshold);
502  m_ccaMode1ThresholdW = DbmToW (threshold);
503 }
504 
505 double
507 {
508  return WToDbm (m_ccaMode1ThresholdW);
509 }
510 
511 void
512 WifiPhy::SetRxNoiseFigure (double noiseFigureDb)
513 {
514  NS_LOG_FUNCTION (this << noiseFigureDb);
515  m_interference.SetNoiseFigure (DbToRatio (noiseFigureDb));
517 }
518 
519 double
521 {
523 }
524 
525 void
527 {
528  NS_LOG_FUNCTION (this << start);
530 }
531 
532 double
534 {
535  return m_txPowerBaseDbm;
536 }
537 
538 void
540 {
541  NS_LOG_FUNCTION (this << end);
542  m_txPowerEndDbm = end;
543 }
544 
545 double
547 {
548  return m_txPowerEndDbm;
549 }
550 
551 void
553 {
554  NS_LOG_FUNCTION (this << n);
555  m_nTxPower = n;
556 }
557 
558 uint32_t
560 {
561  return m_nTxPower;
562 }
563 
564 void
565 WifiPhy::SetTxGain (double gain)
566 {
567  NS_LOG_FUNCTION (this << gain);
568  m_txGainDb = gain;
569 }
570 
571 double
572 WifiPhy::GetTxGain (void) const
573 {
574  return m_txGainDb;
575 }
576 
577 void
578 WifiPhy::SetRxGain (double gain)
579 {
580  NS_LOG_FUNCTION (this << gain);
581  m_rxGainDb = gain;
582 }
583 
584 double
585 WifiPhy::GetRxGain (void) const
586 {
587  return m_rxGainDb;
588 }
589 
590 void
591 WifiPhy::SetLdpc (bool ldpc)
592 {
593  NS_LOG_FUNCTION (this << ldpc);
594  m_ldpc = ldpc;
595 }
596 
597 bool
598 WifiPhy::GetLdpc (void) const
599 {
600  return m_ldpc;
601 }
602 
603 void
604 WifiPhy::SetStbc (bool stbc)
605 {
606  NS_LOG_FUNCTION (this << stbc);
607  m_stbc = stbc;
608 }
609 
610 bool
611 WifiPhy::GetStbc (void) const
612 {
613  return m_stbc;
614 }
615 
616 void
617 WifiPhy::SetGreenfield (bool greenfield)
618 {
619  NS_LOG_FUNCTION (this << greenfield);
620  m_greenfield = greenfield;
621 }
622 
623 bool
625 {
626  return m_greenfield;
627 }
628 
629 void
630 WifiPhy::SetShortGuardInterval (bool shortGuardInterval)
631 {
632  NS_LOG_FUNCTION (this << shortGuardInterval);
633  m_shortGuardInterval = shortGuardInterval;
634 }
635 
636 bool
638 {
639  return m_shortGuardInterval;
640 }
641 
642 void
644 {
645  NS_LOG_FUNCTION (this << guardInterval);
646  NS_ASSERT (guardInterval == NanoSeconds (800) || guardInterval == NanoSeconds (1600) || guardInterval == NanoSeconds (3200));
647  m_guardInterval = guardInterval;
648 }
649 
650 Time
652 {
653  return m_guardInterval;
654 }
655 
656 void
658 {
659  NS_LOG_FUNCTION (this << enable);
660  m_shortPreamble = enable;
661 }
662 
663 bool
665 {
666  return m_shortPreamble;
667 }
668 
669 void
671 {
672  m_device = device;
673 }
674 
676 WifiPhy::GetDevice (void) const
677 {
678  return m_device;
679 }
680 
681 void
683 {
685 }
686 
689 {
690  if (m_mobility != 0)
691  {
692  return m_mobility;
693  }
694  else
695  {
696  return m_device->GetNode ()->GetObject<MobilityModel> ();
697  }
698 }
699 
700 void
702 {
705 }
706 
709 {
711 }
712 
713 void
715 {
716  m_frameCaptureModel = model;
717 }
718 
721 {
722  return m_frameCaptureModel;
723 }
724 
725 double
726 WifiPhy::GetPowerDbm (uint8_t power) const
727 {
729  NS_ASSERT (m_nTxPower > 0);
730  double dbm;
731  if (m_nTxPower > 1)
732  {
733  dbm = m_txPowerBaseDbm + power * (m_txPowerEndDbm - m_txPowerBaseDbm) / (m_nTxPower - 1);
734  }
735  else
736  {
737  NS_ASSERT_MSG (m_txPowerBaseDbm == m_txPowerEndDbm, "cannot have TxPowerEnd != TxPowerStart with TxPowerLevels == 1");
738  dbm = m_txPowerBaseDbm;
739  }
740  return dbm;
741 }
742 
743 Time
745 {
746  return m_channelSwitchDelay;
747 }
748 
749 double
750 WifiPhy::CalculateSnr (WifiTxVector txVector, double ber) const
751 {
752  return m_interference.GetErrorRateModel ()->CalculateSnr (txVector, ber);
753 }
754 
755 void
757 {
758  NS_LOG_FUNCTION (this << standard);
759  switch (standard)
760  {
762  SetChannelWidth (20);
763  SetFrequency (5180);
764  // Channel number should be aligned by SetFrequency () to 36
765  NS_ASSERT (GetChannelNumber () == 36);
766  break;
768  SetChannelWidth (22);
769  SetFrequency (2412);
770  // Channel number should be aligned by SetFrequency () to 1
771  NS_ASSERT (GetChannelNumber () == 1);
772  break;
774  SetChannelWidth (20);
775  SetFrequency (2412);
776  // Channel number should be aligned by SetFrequency () to 1
777  NS_ASSERT (GetChannelNumber () == 1);
778  break;
780  SetChannelWidth (10);
781  SetFrequency (5860);
782  // Channel number should be aligned by SetFrequency () to 172
783  NS_ASSERT (GetChannelNumber () == 172);
784  break;
786  SetChannelWidth (5);
787  SetFrequency (5860);
788  // Channel number should be aligned by SetFrequency () to 0
789  NS_ASSERT (GetChannelNumber () == 0);
790  break;
792  SetChannelWidth (20);
793  SetFrequency (5180);
794  // Channel number should be aligned by SetFrequency () to 36
795  NS_ASSERT (GetChannelNumber () == 36);
796  break;
798  SetChannelWidth (20);
799  SetFrequency (2412);
800  // Channel number should be aligned by SetFrequency () to 1
801  NS_ASSERT (GetChannelNumber () == 1);
802  break;
804  SetChannelWidth (20);
805  SetFrequency (5180);
806  // Channel number should be aligned by SetFrequency () to 36
807  NS_ASSERT (GetChannelNumber () == 36);
808  break;
810  SetChannelWidth (80);
811  SetFrequency (5210);
812  // Channel number should be aligned by SetFrequency () to 42
813  NS_ASSERT (GetChannelNumber () == 42);
814  break;
816  SetChannelWidth (20);
817  SetFrequency (2412);
818  // Channel number should be aligned by SetFrequency () to 1
819  NS_ASSERT (GetChannelNumber () == 1);
820  break;
822  SetChannelWidth (80);
823  SetFrequency (5210);
824  // Channel number should be aligned by SetFrequency () to 42
825  NS_ASSERT (GetChannelNumber () == 42);
826  break;
828  NS_LOG_WARN ("Configuring unspecified standard; performing no action");
829  break;
830  default:
831  NS_ASSERT (false);
832  break;
833  }
834 }
835 
836 void
838 {
839  NS_LOG_FUNCTION (this);
840 
849 }
850 
851 void
853 {
854  NS_LOG_FUNCTION (this);
855 
860 }
861 
862 void
864 {
865  NS_LOG_FUNCTION (this);
866  Configure80211b ();
867 
876 }
877 
878 void
880 {
881  NS_LOG_FUNCTION (this);
882 
891 }
892 
893 void
895 {
896  NS_LOG_FUNCTION (this);
897 
906 }
907 
908 void
910 {
911  NS_LOG_FUNCTION (this);
912 
918 }
919 
920 void
922 {
923  NS_LOG_FUNCTION (this);
924 
925  bool htFound = false;
926  for (std::vector<uint32_t>::size_type i = 0; i < m_bssMembershipSelectorSet.size (); i++)
927  {
929  {
930  htFound = true;
931  break;
932  }
933  }
934  if (htFound)
935  {
936  // erase all HtMcs modes from deviceMcsSet
937  size_t index = m_deviceMcsSet.size () - 1;
938  for (std::vector<WifiMode>::reverse_iterator rit = m_deviceMcsSet.rbegin (); rit != m_deviceMcsSet.rend (); ++rit, --index)
939  {
940  if (m_deviceMcsSet[index].GetModulationClass () == WIFI_MOD_CLASS_HT)
941  {
942  m_deviceMcsSet.erase (m_deviceMcsSet.begin () + index);
943  }
944  }
945  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs0 ());
946  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs1 ());
947  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs2 ());
948  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs3 ());
949  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs4 ());
950  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs5 ());
951  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs6 ());
952  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs7 ());
954  {
955  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs8 ());
956  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs9 ());
957  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs10 ());
958  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs11 ());
959  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs12 ());
960  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs13 ());
961  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs14 ());
962  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs15 ());
963  }
965  {
966  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs16 ());
967  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs17 ());
968  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs18 ());
969  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs19 ());
970  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs20 ());
971  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs21 ());
972  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs22 ());
973  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs23 ());
974  }
976  {
977  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs24 ());
978  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs25 ());
979  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs26 ());
980  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs27 ());
981  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs28 ());
982  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs29 ());
983  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs30 ());
984  m_deviceMcsSet.push_back (WifiPhy::GetHtMcs31 ());
985  }
986  }
987 }
988 
989 void
991 {
992  NS_LOG_FUNCTION (this);
993  if (Is2_4Ghz (GetFrequency ()))
994  {
995  Configure80211b ();
996  Configure80211g ();
997  }
998  if (Is5Ghz (GetFrequency ()))
999  {
1000  Configure80211a ();
1001  }
1002  m_bssMembershipSelectorSet.push_back (HT_PHY);
1004 }
1005 
1006 void
1008 {
1009  NS_LOG_FUNCTION (this);
1010  Configure80211n ();
1011 
1012  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs0 ());
1013  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs1 ());
1014  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs2 ());
1015  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs3 ());
1016  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs4 ());
1017  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs5 ());
1018  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs6 ());
1019  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs7 ());
1020  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs8 ());
1021  m_deviceMcsSet.push_back (WifiPhy::GetVhtMcs9 ());
1022 
1023  m_bssMembershipSelectorSet.push_back (VHT_PHY);
1024 }
1025 
1026 void
1028 {
1029  NS_LOG_FUNCTION (this);
1030  Configure80211n ();
1031  if (Is5Ghz (GetFrequency ()))
1032  {
1033  Configure80211ac ();
1034  }
1035  m_deviceMcsSet.push_back (WifiPhy::GetHeMcs0 ());
1036  m_deviceMcsSet.push_back (WifiPhy::GetHeMcs1 ());
1037  m_deviceMcsSet.push_back (WifiPhy::GetHeMcs2 ());
1038  m_deviceMcsSet.push_back (WifiPhy::GetHeMcs3 ());
1039  m_deviceMcsSet.push_back (WifiPhy::GetHeMcs4 ());
1040  m_deviceMcsSet.push_back (WifiPhy::GetHeMcs5 ());
1041  m_deviceMcsSet.push_back (WifiPhy::GetHeMcs6 ());
1042  m_deviceMcsSet.push_back (WifiPhy::GetHeMcs7 ());
1043  m_deviceMcsSet.push_back (WifiPhy::GetHeMcs8 ());
1044  m_deviceMcsSet.push_back (WifiPhy::GetHeMcs9 ());
1045  m_deviceMcsSet.push_back (WifiPhy::GetHeMcs10 ());
1046  m_deviceMcsSet.push_back (WifiPhy::GetHeMcs11 ());
1047 
1048  m_bssMembershipSelectorSet.push_back (HE_PHY);
1049 }
1050 
1051 bool
1052 WifiPhy::DefineChannelNumber (uint8_t channelNumber, WifiPhyStandard standard, uint16_t frequency, uint8_t channelWidth)
1053 {
1054  NS_LOG_FUNCTION (this << (uint16_t)channelNumber << standard << frequency << (uint16_t)channelWidth);
1055  ChannelNumberStandardPair p = std::make_pair (channelNumber, standard);
1056  ChannelToFrequencyWidthMap::const_iterator it;
1057  it = m_channelToFrequencyWidth.find (p);
1058  if (it != m_channelToFrequencyWidth.end ())
1059  {
1060  NS_LOG_DEBUG ("channel number/standard already defined; returning false");
1061  return false;
1062  }
1063  FrequencyWidthPair f = std::make_pair (frequency, channelWidth);
1065  return true;
1066 }
1067 
1068 uint8_t
1069 WifiPhy::FindChannelNumberForFrequencyWidth (uint16_t frequency, uint8_t width) const
1070 {
1071  NS_LOG_FUNCTION (this << frequency << (uint16_t)width);
1072  bool found = false;
1073  FrequencyWidthPair f = std::make_pair (frequency, width);
1074  ChannelToFrequencyWidthMap::const_iterator it = m_channelToFrequencyWidth.begin ();
1075  while (it != m_channelToFrequencyWidth.end ())
1076  {
1077  if (it->second == f)
1078  {
1079  found = true;
1080  break;
1081  }
1082  ++it;
1083  }
1084  if (found)
1085  {
1086  NS_LOG_DEBUG ("Found, returning " << it->first.first);
1087  return (it->first.first);
1088  }
1089  else
1090  {
1091  NS_LOG_DEBUG ("Not found, returning 0");
1092  return 0;
1093  }
1094 }
1095 
1096 void
1098 {
1099  NS_LOG_FUNCTION (this << standard);
1100  // If the user has configured both Frequency and ChannelNumber, Frequency
1101  // takes precedence
1102  if (GetFrequency () != 0)
1103  {
1104  // If Frequency is already set, then see whether a ChannelNumber can
1105  // be found that matches Frequency and ChannelWidth. If so, configure
1106  // the ChannelNumber to that channel number. If not, set ChannelNumber to zero.
1107  NS_LOG_DEBUG ("Frequency set; checking whether a channel number corresponds");
1108  uint8_t channelNumberSearched = FindChannelNumberForFrequencyWidth (GetFrequency (), GetChannelWidth ());
1109  if (channelNumberSearched)
1110  {
1111  NS_LOG_DEBUG ("Channel number found; setting to " << (uint16_t)channelNumberSearched);
1112  SetChannelNumber (channelNumberSearched);
1113  }
1114  else
1115  {
1116  NS_LOG_DEBUG ("Channel number not found; setting to zero");
1117  SetChannelNumber (0);
1118  }
1119  }
1120  else if (GetChannelNumber () != 0)
1121  {
1122  // If the channel number is known for this particular standard or for
1123  // the unspecified standard, configure using the known values;
1124  // otherwise, this is a configuration error
1125  NS_LOG_DEBUG ("Configuring for channel number " << (uint16_t)GetChannelNumber ());
1127  if (f.first == 0)
1128  {
1129  // the specific pair of number/standard is not known
1130  NS_LOG_DEBUG ("Falling back to check WIFI_PHY_STANDARD_UNSPECIFIED");
1132  }
1133  if (f.first == 0)
1134  {
1135  NS_FATAL_ERROR ("Error, ChannelNumber " << (uint16_t)GetChannelNumber () << " is unknown for this standard");
1136  }
1137  else
1138  {
1139  NS_LOG_DEBUG ("Setting frequency to " << f.first << "; width to " << (uint16_t)f.second);
1140  SetFrequency (f.first);
1141  SetChannelWidth (f.second);
1142  }
1143  }
1144 }
1145 
1146 void
1148 {
1149  NS_LOG_FUNCTION (this << standard);
1150  m_standard = standard;
1151  m_isConstructed = true;
1153  {
1155  }
1156  if (GetFrequency () == 0 && GetChannelNumber () == 0)
1157  {
1158  ConfigureDefaultsForStandard (standard);
1159  }
1160  else
1161  {
1162  // The user has configured either (or both) Frequency or ChannelNumber
1163  ConfigureChannelForStandard (standard);
1164  }
1165  switch (standard)
1166  {
1168  Configure80211a ();
1169  break;
1171  Configure80211b ();
1172  break;
1174  Configure80211g ();
1175  break;
1178  break;
1181  break;
1183  ConfigureHolland ();
1184  break;
1186  Configure80211n ();
1187  break;
1189  Configure80211n ();
1190  break;
1192  Configure80211ac ();
1193  break;
1195  Configure80211ax ();
1196  break;
1198  Configure80211ax ();
1199  break;
1200  default:
1201  NS_ASSERT (false);
1202  break;
1203  }
1204 }
1205 
1208 {
1209  return m_standard;
1210 }
1211 
1212 void
1213 WifiPhy::SetFrequency (uint16_t frequency)
1214 {
1215  NS_LOG_FUNCTION (this << frequency);
1216  if (m_isConstructed == false)
1217  {
1218  NS_LOG_DEBUG ("Saving frequency configuration for initialization");
1219  m_initialFrequency = frequency;
1220  return;
1221  }
1222  if (GetFrequency () == frequency)
1223  {
1224  NS_LOG_DEBUG ("No frequency change requested");
1225  return;
1226  }
1227  if (frequency == 0)
1228  {
1229  DoFrequencySwitch (0);
1230  NS_LOG_DEBUG ("Setting frequency and channel number to zero");
1232  m_channelNumber = 0;
1233  return;
1234  }
1235  // If the user has configured both Frequency and ChannelNumber, Frequency
1236  // takes precedence. Lookup the channel number corresponding to the
1237  // requested frequency.
1238  uint8_t nch = FindChannelNumberForFrequencyWidth (frequency, GetChannelWidth ());
1239  if (nch != 0)
1240  {
1241  NS_LOG_DEBUG ("Setting frequency " << frequency << " corresponds to channel " << (uint16_t)nch);
1242  if (DoFrequencySwitch (frequency))
1243  {
1244  NS_LOG_DEBUG ("Channel frequency switched to " << frequency << "; channel number to " << (uint16_t)nch);
1245  m_channelCenterFrequency = frequency;
1246  m_channelNumber = nch;
1247  }
1248  else
1249  {
1250  NS_LOG_DEBUG ("Suppressing reassignment of frequency");
1251  }
1252  }
1253  else
1254  {
1255  NS_LOG_DEBUG ("Channel number is unknown for frequency " << frequency);
1256  if (DoFrequencySwitch (frequency))
1257  {
1258  NS_LOG_DEBUG ("Channel frequency switched to " << frequency << "; channel number to " << 0);
1259  m_channelCenterFrequency = frequency;
1260  m_channelNumber = 0;
1261  }
1262  else
1263  {
1264  NS_LOG_DEBUG ("Suppressing reassignment of frequency");
1265  }
1266  }
1267 }
1268 
1269 uint16_t
1271 {
1272  return m_channelCenterFrequency;
1273 }
1274 
1275 bool
1276 WifiPhy::Is2_4Ghz (double frequency)
1277 {
1278  if (frequency >= 2400 && frequency <= 2500)
1279  {
1280  return true;
1281  }
1282  return false;
1283 }
1284 
1285 bool
1286 WifiPhy::Is5Ghz (double frequency)
1287 {
1288  if (frequency >= 5000 && frequency <= 6000)
1289  {
1290  return true;
1291  }
1292  return false;
1293 }
1294 
1295 void
1296 WifiPhy::SetChannelWidth (uint8_t channelwidth)
1297 {
1298  NS_ASSERT_MSG (channelwidth == 5 || channelwidth == 10 || channelwidth == 20 || channelwidth == 22 || channelwidth == 40 || channelwidth == 80 || channelwidth == 160, "wrong channel width value");
1299  m_channelWidth = channelwidth;
1300  AddSupportedChannelWidth (channelwidth);
1301 }
1302 
1303 uint8_t
1305 {
1306  return m_channelWidth;
1307 }
1308 
1309 void
1311 {
1312  NS_ASSERT_MSG (antennas > 0 && antennas <= 4, "unsupported number of antennas");
1313  m_numberOfAntennas = antennas;
1315 }
1316 
1317 uint8_t
1319 {
1320  return m_numberOfAntennas;
1321 }
1322 
1323 void
1325 {
1326  NS_ASSERT (streams <= GetNumberOfAntennas ());
1327  m_txSpatialStreams = streams;
1329 }
1330 
1331 uint8_t
1333 {
1334  return m_txSpatialStreams;
1335 }
1336 
1337 void
1339 {
1340  NS_ASSERT (streams <= GetNumberOfAntennas ());
1341  m_rxSpatialStreams = streams;
1342 }
1343 
1344 uint8_t
1346 {
1347  return m_rxSpatialStreams;
1348 }
1349 
1350 uint32_t
1352 {
1353  return m_bssMembershipSelectorSet.size ();
1354 }
1355 
1356 uint32_t
1357 WifiPhy::GetBssMembershipSelector (uint32_t selector) const
1358 {
1359  return m_bssMembershipSelectorSet[selector];
1360 }
1361 
1364 {
1365  uint32_t id = GetBssMembershipSelector (selector);
1366  WifiModeList supportedmodes;
1367  if (id == HT_PHY || id == VHT_PHY || id == HE_PHY)
1368  {
1369  //mandatory MCS 0 to 7
1370  supportedmodes.push_back (WifiPhy::GetHtMcs0 ());
1371  supportedmodes.push_back (WifiPhy::GetHtMcs1 ());
1372  supportedmodes.push_back (WifiPhy::GetHtMcs2 ());
1373  supportedmodes.push_back (WifiPhy::GetHtMcs3 ());
1374  supportedmodes.push_back (WifiPhy::GetHtMcs4 ());
1375  supportedmodes.push_back (WifiPhy::GetHtMcs5 ());
1376  supportedmodes.push_back (WifiPhy::GetHtMcs6 ());
1377  supportedmodes.push_back (WifiPhy::GetHtMcs7 ());
1378  }
1379  if (id == VHT_PHY || id == HE_PHY)
1380  {
1381  //mandatory MCS 0 to 9
1382  supportedmodes.push_back (WifiPhy::GetVhtMcs0 ());
1383  supportedmodes.push_back (WifiPhy::GetVhtMcs1 ());
1384  supportedmodes.push_back (WifiPhy::GetVhtMcs2 ());
1385  supportedmodes.push_back (WifiPhy::GetVhtMcs3 ());
1386  supportedmodes.push_back (WifiPhy::GetVhtMcs4 ());
1387  supportedmodes.push_back (WifiPhy::GetVhtMcs5 ());
1388  supportedmodes.push_back (WifiPhy::GetVhtMcs6 ());
1389  supportedmodes.push_back (WifiPhy::GetVhtMcs7 ());
1390  supportedmodes.push_back (WifiPhy::GetVhtMcs8 ());
1391  supportedmodes.push_back (WifiPhy::GetVhtMcs9 ());
1392  }
1393  if (id == HE_PHY)
1394  {
1395  //mandatory MCS 0 to 11
1396  supportedmodes.push_back (WifiPhy::GetHeMcs0 ());
1397  supportedmodes.push_back (WifiPhy::GetHeMcs1 ());
1398  supportedmodes.push_back (WifiPhy::GetHeMcs2 ());
1399  supportedmodes.push_back (WifiPhy::GetHeMcs3 ());
1400  supportedmodes.push_back (WifiPhy::GetHeMcs4 ());
1401  supportedmodes.push_back (WifiPhy::GetHeMcs5 ());
1402  supportedmodes.push_back (WifiPhy::GetHeMcs6 ());
1403  supportedmodes.push_back (WifiPhy::GetHeMcs7 ());
1404  supportedmodes.push_back (WifiPhy::GetHeMcs8 ());
1405  supportedmodes.push_back (WifiPhy::GetHeMcs9 ());
1406  supportedmodes.push_back (WifiPhy::GetHeMcs10 ());
1407  supportedmodes.push_back (WifiPhy::GetHeMcs11 ());
1408  }
1409  return supportedmodes;
1410 }
1411 
1412 void
1414 {
1415  NS_LOG_FUNCTION (this << (uint16_t)width);
1416  for (std::vector<uint32_t>::size_type i = 0; i != m_supportedChannelWidthSet.size (); i++)
1417  {
1418  if (m_supportedChannelWidthSet[i] == width)
1419  {
1420  return;
1421  }
1422  }
1423  NS_LOG_FUNCTION ("Adding " << (uint16_t)width << " to supported channel width set");
1424  m_supportedChannelWidthSet.push_back (width);
1425 }
1426 
1427 std::vector<uint8_t>
1429 {
1431 }
1432 
1435 {
1436  ChannelNumberStandardPair p = std::make_pair (channelNumber, standard);
1438  return f;
1439 }
1440 
1441 void
1443 {
1444  NS_LOG_FUNCTION (this << (uint16_t)nch);
1445  if (m_isConstructed == false)
1446  {
1447  NS_LOG_DEBUG ("Saving channel number configuration for initialization");
1448  m_initialChannelNumber = nch;
1449  return;
1450  }
1451  if (GetChannelNumber () == nch)
1452  {
1453  NS_LOG_DEBUG ("No channel change requested");
1454  return;
1455  }
1456  if (nch == 0)
1457  {
1458  // This case corresponds to when there is not a known channel
1459  // number for the requested frequency. There is no need to call
1460  // DoChannelSwitch () because DoFrequencySwitch () should have been
1461  // called by the client
1462  NS_LOG_DEBUG ("Setting channel number to zero");
1463  m_channelNumber = 0;
1464  return;
1465  }
1466 
1467  // First make sure that the channel number is defined for the standard
1468  // in use
1470  if (f.first == 0)
1471  {
1473  }
1474  if (f.first != 0)
1475  {
1476  if (DoChannelSwitch (nch))
1477  {
1478  NS_LOG_DEBUG ("Setting frequency to " << f.first << "; width to " << (uint16_t)f.second);
1479  m_channelCenterFrequency = f.first;
1480  SetChannelWidth (f.second);
1481  m_channelNumber = nch;
1482  }
1483  else
1484  {
1485  // Subclass may have suppressed (e.g. waiting for state change)
1486  NS_LOG_DEBUG ("Channel switch suppressed");
1487  }
1488  }
1489  else
1490  {
1491  NS_FATAL_ERROR ("Frequency not found for channel number " << nch);
1492  }
1493 }
1494 
1495 uint8_t
1497 {
1498  return m_channelNumber;
1499 }
1500 
1501 bool
1503 {
1504  if (!IsInitialized ())
1505  {
1506  //this is not channel switch, this is initialization
1507  NS_LOG_DEBUG ("initialize to channel " << (uint16_t)nch);
1508  return true;
1509  }
1510 
1512  switch (m_state->GetState ())
1513  {
1514  case WifiPhy::RX:
1515  NS_LOG_DEBUG ("drop packet because of channel switching while reception");
1517  m_endRxEvent.Cancel ();
1518  goto switchChannel;
1519  break;
1520  case WifiPhy::TX:
1521  NS_LOG_DEBUG ("channel switching postponed until end of current transmission");
1523  break;
1524  case WifiPhy::CCA_BUSY:
1525  case WifiPhy::IDLE:
1526  goto switchChannel;
1527  break;
1528  case WifiPhy::SLEEP:
1529  NS_LOG_DEBUG ("channel switching ignored in sleep mode");
1530  break;
1531  default:
1532  NS_ASSERT (false);
1533  break;
1534  }
1535 
1536  return false;
1537 
1538 switchChannel:
1539 
1540  NS_LOG_DEBUG ("switching channel " << (uint16_t)GetChannelNumber () << " -> " << (uint16_t)nch);
1541  m_state->SwitchToChannelSwitching (GetChannelSwitchDelay ());
1543  /*
1544  * Needed here to be able to correctly sensed the medium for the first
1545  * time after the switching. The actual switching is not performed until
1546  * after m_channelSwitchDelay. Packets received during the switching
1547  * state are added to the event list and are employed later to figure
1548  * out the state of the medium after the switching.
1549  */
1550  return true;
1551 }
1552 
1553 bool
1554 WifiPhy::DoFrequencySwitch (uint16_t frequency)
1555 {
1556  if (!IsInitialized ())
1557  {
1558  //this is not channel switch, this is initialization
1559  NS_LOG_DEBUG ("start at frequency " << frequency);
1560  return true;
1561  }
1562 
1564  switch (m_state->GetState ())
1565  {
1566  case WifiPhy::RX:
1567  NS_LOG_DEBUG ("drop packet because of channel/frequency switching while reception");
1569  m_endRxEvent.Cancel ();
1570  goto switchFrequency;
1571  break;
1572  case WifiPhy::TX:
1573  NS_LOG_DEBUG ("channel/frequency switching postponed until end of current transmission");
1575  break;
1576  case WifiPhy::CCA_BUSY:
1577  case WifiPhy::IDLE:
1578  goto switchFrequency;
1579  break;
1580  case WifiPhy::SLEEP:
1581  NS_LOG_DEBUG ("frequency switching ignored in sleep mode");
1582  break;
1583  default:
1584  NS_ASSERT (false);
1585  break;
1586  }
1587 
1588  return false;
1589 
1590 switchFrequency:
1591 
1592  NS_LOG_DEBUG ("switching frequency " << GetFrequency () << " -> " << frequency);
1593  m_state->SwitchToChannelSwitching (GetChannelSwitchDelay ());
1595  /*
1596  * Needed here to be able to correctly sensed the medium for the first
1597  * time after the switching. The actual switching is not performed until
1598  * after m_channelSwitchDelay. Packets received during the switching
1599  * state are added to the event list and are employed later to figure
1600  * out the state of the medium after the switching.
1601  */
1602  return true;
1603 }
1604 
1605 void
1607 {
1608  NS_LOG_FUNCTION (this);
1609  switch (m_state->GetState ())
1610  {
1611  case WifiPhy::TX:
1612  NS_LOG_DEBUG ("setting sleep mode postponed until end of current transmission");
1614  break;
1615  case WifiPhy::RX:
1616  NS_LOG_DEBUG ("setting sleep mode postponed until end of current reception");
1618  break;
1619  case WifiPhy::SWITCHING:
1620  NS_LOG_DEBUG ("setting sleep mode postponed until end of channel switching");
1622  break;
1623  case WifiPhy::CCA_BUSY:
1624  case WifiPhy::IDLE:
1625  NS_LOG_DEBUG ("setting sleep mode");
1626  m_state->SwitchToSleep ();
1627  break;
1628  case WifiPhy::SLEEP:
1629  NS_LOG_DEBUG ("already in sleep mode");
1630  break;
1631  default:
1632  NS_ASSERT (false);
1633  break;
1634  }
1635 }
1636 
1637 void
1639 {
1640  NS_LOG_FUNCTION (this);
1641  switch (m_state->GetState ())
1642  {
1643  case WifiPhy::TX:
1644  case WifiPhy::RX:
1645  case WifiPhy::IDLE:
1646  case WifiPhy::CCA_BUSY:
1647  case WifiPhy::SWITCHING:
1648  {
1649  NS_LOG_DEBUG ("not in sleep mode, there is nothing to resume");
1650  break;
1651  }
1652  case WifiPhy::SLEEP:
1653  {
1654  NS_LOG_DEBUG ("resuming from sleep mode");
1656  m_state->SwitchFromSleep (delayUntilCcaEnd);
1657  break;
1658  }
1659  default:
1660  {
1661  NS_ASSERT (false);
1662  break;
1663  }
1664  }
1665 }
1666 
1667 WifiMode
1669 {
1670  return WifiPhy::GetHtMcs0 ();
1671 }
1672 
1673 WifiMode
1675 {
1676  return WifiPhy::GetVhtMcs0 ();
1677 }
1678 
1679 WifiMode
1681 {
1682  return WifiPhy::GetHeMcs0 ();
1683 }
1684 
1685 Time
1687 {
1688  uint8_t Ndltf, Neltf;
1689  //We suppose here that STBC = 0.
1690  //If STBC > 0, we need a different mapping between Nss and Nltf (IEEE 802.11n-2012 standard, page 1682).
1691  if (txVector.GetNss () < 3)
1692  {
1693  Ndltf = txVector.GetNss ();
1694  }
1695  else if (txVector.GetNss () < 5)
1696  {
1697  Ndltf = 4;
1698  }
1699  else if (txVector.GetNss () < 7)
1700  {
1701  Ndltf = 6;
1702  }
1703  else
1704  {
1705  Ndltf = 8;
1706  }
1707 
1708  if (txVector.GetNess () < 3)
1709  {
1710  Neltf = txVector.GetNess ();
1711  }
1712  else
1713  {
1714  Neltf = 4;
1715  }
1716 
1717  switch (txVector.GetPreambleType ())
1718  {
1719  case WIFI_PREAMBLE_HT_MF:
1720  return MicroSeconds (4 + (4 * Ndltf) + (4 * Neltf));
1721  case WIFI_PREAMBLE_HT_GF:
1722  return MicroSeconds ((4 * Ndltf) + (4 * Neltf));
1723  case WIFI_PREAMBLE_VHT:
1724  return MicroSeconds (4 + (4 * Ndltf));
1725  case WIFI_PREAMBLE_HE_SU:
1726  return MicroSeconds (4 + (8 * Ndltf));
1727  default:
1728  return MicroSeconds (0);
1729  }
1730 }
1731 
1732 Time
1734 {
1735  switch (preamble)
1736  {
1737  case WIFI_PREAMBLE_HT_MF:
1738  case WIFI_PREAMBLE_HT_GF:
1739  //HT-SIG
1740  return MicroSeconds (8);
1741  default:
1742  //no HT-SIG for non HT
1743  return MicroSeconds (0);
1744  }
1745 }
1746 
1747 Time
1749 {
1750  switch (preamble)
1751  {
1752  case WIFI_PREAMBLE_VHT:
1753  case WIFI_PREAMBLE_HE_SU:
1754  //VHT-SIG-A1 and HE-SIG-A1
1755  return MicroSeconds (4);
1756  default:
1757  // no SIG-A1
1758  return MicroSeconds (0);
1759  }
1760 }
1761 
1762 Time
1764 {
1765  switch (preamble)
1766  {
1767  case WIFI_PREAMBLE_VHT:
1768  case WIFI_PREAMBLE_HE_SU:
1769  //VHT-SIG-A2 and HE-SIG-A2
1770  return MicroSeconds (4);
1771  default:
1772  // no SIG-A2
1773  return MicroSeconds (0);
1774  }
1775 }
1776 
1777 Time
1779 {
1780  switch (preamble)
1781  {
1782  case WIFI_PREAMBLE_VHT:
1783  //VHT-SIG-B
1784  return MicroSeconds (4);
1785  case WIFI_PREAMBLE_HE_SU:
1786  //HE-SIG-B: MU not supported so HE-SIG-B not used
1787  return MicroSeconds (0);
1788  default:
1789  // no SIG-B
1790  return MicroSeconds (0);
1791  }
1792 }
1793 
1794 WifiMode
1796 {
1797  switch (txVector.GetMode ().GetModulationClass ())
1798  {
1799  case WIFI_MOD_CLASS_OFDM:
1800  case WIFI_MOD_CLASS_HT:
1801  case WIFI_MOD_CLASS_VHT:
1802  case WIFI_MOD_CLASS_HE:
1803  switch (txVector.GetChannelWidth ())
1804  {
1805  case 5:
1807  case 10:
1809  case 20:
1810  case 40:
1811  case 80:
1812  case 160:
1813  default:
1814  //(Section 18.3.2 "PLCP frame format"; IEEE Std 802.11-2012)
1815  //actually this is only the first part of the PlcpHeader,
1816  //because the last 16 bits of the PlcpHeader are using the
1817  //same mode of the payload
1818  return WifiPhy::GetOfdmRate6Mbps ();
1819  }
1821  return WifiPhy::GetErpOfdmRate6Mbps ();
1822  case WIFI_MOD_CLASS_DSSS:
1824  if (txVector.GetPreambleType () == WIFI_PREAMBLE_LONG || txVector.GetMode () == WifiPhy::GetDsssRate1Mbps ())
1825  {
1826  //(Section 16.2.3 "PLCP field definitions" and Section 17.2.2.2 "Long PPDU format"; IEEE Std 802.11-2012)
1827  return WifiPhy::GetDsssRate1Mbps ();
1828  }
1829  else //WIFI_PREAMBLE_SHORT
1830  {
1831  //(Section 17.2.2.3 "Short PPDU format"; IEEE Std 802.11-2012)
1832  return WifiPhy::GetDsssRate2Mbps ();
1833  }
1834  default:
1835  NS_FATAL_ERROR ("unsupported modulation class");
1836  return WifiMode ();
1837  }
1838 }
1839 
1840 Time
1842 {
1843  WifiPreamble preamble = txVector.GetPreambleType ();
1844  if (preamble == WIFI_PREAMBLE_NONE)
1845  {
1846  return MicroSeconds (0);
1847  }
1848  switch (txVector.GetMode ().GetModulationClass ())
1849  {
1850  case WIFI_MOD_CLASS_OFDM:
1851  {
1852  switch (txVector.GetChannelWidth ())
1853  {
1854  case 20:
1855  default:
1856  //(Section 18.3.3 "PLCP preamble (SYNC))" and Figure 18-4 "OFDM training structure"; IEEE Std 802.11-2012)
1857  //also (Section 18.3.2.4 "Timing related parameters" Table 18-5 "Timing-related parameters"; IEEE Std 802.11-2012)
1858  //We return the duration of the SIGNAL field only, since the
1859  //SERVICE field (which strictly speaking belongs to the PLCP
1860  //header, see Section 18.3.2 and Figure 18-1) is sent using the
1861  //payload mode.
1862  return MicroSeconds (4);
1863  case 10:
1864  //(Section 18.3.2.4 "Timing related parameters" Table 18-5 "Timing-related parameters"; IEEE Std 802.11-2012)
1865  return MicroSeconds (8);
1866  case 5:
1867  //(Section 18.3.2.4 "Timing related parameters" Table 18-5 "Timing-related parameters"; IEEE Std 802.11-2012)
1868  return MicroSeconds (16);
1869  }
1870  }
1871  case WIFI_MOD_CLASS_HT:
1872  {
1873  //L-SIG
1874  //IEEE 802.11n Figure 20.1
1875  switch (preamble)
1876  {
1877  case WIFI_PREAMBLE_HT_MF:
1878  default:
1879  return MicroSeconds (4);
1880  case WIFI_PREAMBLE_HT_GF:
1881  return MicroSeconds (0);
1882  }
1883  }
1885  case WIFI_MOD_CLASS_VHT:
1886  //L-SIG
1887  return MicroSeconds (4);
1888  case WIFI_MOD_CLASS_HE:
1889  //LSIG + R-LSIG
1890  return MicroSeconds (8);
1891  case WIFI_MOD_CLASS_DSSS:
1893  if ((preamble == WIFI_PREAMBLE_SHORT) && (txVector.GetMode ().GetDataRate (22) > 1000000))
1894  {
1895  //(Section 17.2.2.3 "Short PPDU format" and Figure 17-2 "Short PPDU format"; IEEE Std 802.11-2012)
1896  return MicroSeconds (24);
1897  }
1898  else //WIFI_PREAMBLE_LONG
1899  {
1900  //(Section 17.2.2.2 "Long PPDU format" and Figure 17-1 "Short PPDU format"; IEEE Std 802.11-2012)
1901  return MicroSeconds (48);
1902  }
1903  default:
1904  NS_FATAL_ERROR ("unsupported modulation class");
1905  return MicroSeconds (0);
1906  }
1907 }
1908 
1909 Time
1911 {
1912  WifiPreamble preamble = txVector.GetPreambleType ();
1913  if (preamble == WIFI_PREAMBLE_NONE)
1914  {
1915  return MicroSeconds (0);
1916  }
1917  switch (txVector.GetMode ().GetModulationClass ())
1918  {
1919  case WIFI_MOD_CLASS_OFDM:
1920  {
1921  switch (txVector.GetChannelWidth ())
1922  {
1923  case 20:
1924  default:
1925  //(Section 18.3.3 "PLCP preamble (SYNC))" Figure 18-4 "OFDM training structure"
1926  //also Section 18.3.2.3 "Modulation-dependent parameters" Table 18-4 "Modulation-dependent parameters"; IEEE Std 802.11-2012)
1927  return MicroSeconds (16);
1928  case 10:
1929  //(Section 18.3.3 "PLCP preamble (SYNC))" Figure 18-4 "OFDM training structure"
1930  //also Section 18.3.2.3 "Modulation-dependent parameters" Table 18-4 "Modulation-dependent parameters"; IEEE Std 802.11-2012)
1931  return MicroSeconds (32);
1932  case 5:
1933  //(Section 18.3.3 "PLCP preamble (SYNC))" Figure 18-4 "OFDM training structure"
1934  //also Section 18.3.2.3 "Modulation-dependent parameters" Table 18-4 "Modulation-dependent parameters"; IEEE Std 802.11-2012)
1935  return MicroSeconds (64);
1936  }
1937  }
1938  case WIFI_MOD_CLASS_HT:
1939  case WIFI_MOD_CLASS_VHT:
1940  case WIFI_MOD_CLASS_HE:
1941  //L-STF + L-LTF
1942  return MicroSeconds (16);
1944  return MicroSeconds (16);
1945  case WIFI_MOD_CLASS_DSSS:
1947  if ((preamble == WIFI_PREAMBLE_SHORT) && (txVector.GetMode ().GetDataRate (22) > 1000000))
1948  {
1949  //(Section 17.2.2.3 "Short PPDU format)" Figure 17-2 "Short PPDU format"; IEEE Std 802.11-2012)
1950  return MicroSeconds (72);
1951  }
1952  else //WIFI_PREAMBLE_LONG
1953  {
1954  //(Section 17.2.2.2 "Long PPDU format)" Figure 17-1 "Long PPDU format"; IEEE Std 802.11-2012)
1955  return MicroSeconds (144);
1956  }
1957  default:
1958  NS_FATAL_ERROR ("unsupported modulation class");
1959  return MicroSeconds (0);
1960  }
1961 }
1962 
1963 Time
1964 WifiPhy::GetPayloadDuration (uint32_t size, WifiTxVector txVector, uint16_t frequency)
1965 {
1966  return GetPayloadDuration (size, txVector, frequency, NORMAL_MPDU, 0);
1967 }
1968 
1969 Time
1970 WifiPhy::GetPayloadDuration (uint32_t size, WifiTxVector txVector, uint16_t frequency, MpduType mpdutype, uint8_t incFlag)
1971 {
1972  WifiMode payloadMode = txVector.GetMode ();
1973  WifiPreamble preamble = txVector.GetPreambleType ();
1974  NS_LOG_FUNCTION (size << payloadMode);
1975 
1976  double stbc = 1;
1977  if (txVector.IsStbc ()
1978  && (payloadMode.GetModulationClass () == WIFI_MOD_CLASS_HT
1979  || payloadMode.GetModulationClass () == WIFI_MOD_CLASS_VHT))
1980  {
1981  stbc = 2;
1982  }
1983 
1984  double Nes = 1;
1985  //todo: improve logic to reduce the number of if cases
1986  //todo: extend to NSS > 4 for VHT rates
1987  if (payloadMode.GetUniqueName () == "HtMcs21"
1988  || payloadMode.GetUniqueName () == "HtMcs22"
1989  || payloadMode.GetUniqueName () == "HtMcs23"
1990  || payloadMode.GetUniqueName () == "HtMcs28"
1991  || payloadMode.GetUniqueName () == "HtMcs29"
1992  || payloadMode.GetUniqueName () == "HtMcs30"
1993  || payloadMode.GetUniqueName () == "HtMcs31")
1994  {
1995  Nes = 2;
1996  }
1997  if (payloadMode.GetModulationClass () == WIFI_MOD_CLASS_VHT)
1998  {
1999  if (txVector.GetChannelWidth () == 40
2000  && txVector.GetNss () == 3
2001  && payloadMode.GetMcsValue () >= 8)
2002  {
2003  Nes = 2;
2004  }
2005  if (txVector.GetChannelWidth () == 80
2006  && txVector.GetNss () == 2
2007  && payloadMode.GetMcsValue () >= 7)
2008  {
2009  Nes = 2;
2010  }
2011  if (txVector.GetChannelWidth () == 80
2012  && txVector.GetNss () == 3
2013  && payloadMode.GetMcsValue () >= 7)
2014  {
2015  Nes = 2;
2016  }
2017  if (txVector.GetChannelWidth () == 80
2018  && txVector.GetNss () == 3
2019  && payloadMode.GetMcsValue () == 9)
2020  {
2021  Nes = 3;
2022  }
2023  if (txVector.GetChannelWidth () == 80
2024  && txVector.GetNss () == 4
2025  && payloadMode.GetMcsValue () >= 4)
2026  {
2027  Nes = 2;
2028  }
2029  if (txVector.GetChannelWidth () == 80
2030  && txVector.GetNss () == 4
2031  && payloadMode.GetMcsValue () >= 7)
2032  {
2033  Nes = 3;
2034  }
2035  if (txVector.GetChannelWidth () == 160
2036  && payloadMode.GetMcsValue () >= 7)
2037  {
2038  Nes = 2;
2039  }
2040  if (txVector.GetChannelWidth () == 160
2041  && txVector.GetNss () == 2
2042  && payloadMode.GetMcsValue () >= 4)
2043  {
2044  Nes = 2;
2045  }
2046  if (txVector.GetChannelWidth () == 160
2047  && txVector.GetNss () == 2
2048  && payloadMode.GetMcsValue () >= 7)
2049  {
2050  Nes = 3;
2051  }
2052  if (txVector.GetChannelWidth () == 160
2053  && txVector.GetNss () == 3
2054  && payloadMode.GetMcsValue () >= 3)
2055  {
2056  Nes = 2;
2057  }
2058  if (txVector.GetChannelWidth () == 160
2059  && txVector.GetNss () == 3
2060  && payloadMode.GetMcsValue () >= 5)
2061  {
2062  Nes = 3;
2063  }
2064  if (txVector.GetChannelWidth () == 160
2065  && txVector.GetNss () == 3
2066  && payloadMode.GetMcsValue () >= 7)
2067  {
2068  Nes = 4;
2069  }
2070  if (txVector.GetChannelWidth () == 160
2071  && txVector.GetNss () == 4
2072  && payloadMode.GetMcsValue () >= 2)
2073  {
2074  Nes = 2;
2075  }
2076  if (txVector.GetChannelWidth () == 160
2077  && txVector.GetNss () == 4
2078  && payloadMode.GetMcsValue () >= 4)
2079  {
2080  Nes = 3;
2081  }
2082  if (txVector.GetChannelWidth () == 160
2083  && txVector.GetNss () == 4
2084  && payloadMode.GetMcsValue () >= 5)
2085  {
2086  Nes = 4;
2087  }
2088  if (txVector.GetChannelWidth () == 160
2089  && txVector.GetNss () == 4
2090  && payloadMode.GetMcsValue () >= 7)
2091  {
2092  Nes = 6;
2093  }
2094  }
2095 
2096  Time symbolDuration = Seconds (0);
2097  switch (payloadMode.GetModulationClass ())
2098  {
2099  case WIFI_MOD_CLASS_OFDM:
2101  {
2102  //(Section 18.3.2.4 "Timing related parameters" Table 18-5 "Timing-related parameters"; IEEE Std 802.11-2012
2103  //corresponds to T_{SYM} in the table)
2104  switch (txVector.GetChannelWidth ())
2105  {
2106  case 20:
2107  default:
2108  symbolDuration = MicroSeconds (4);
2109  break;
2110  case 10:
2111  symbolDuration = MicroSeconds (8);
2112  break;
2113  case 5:
2114  symbolDuration = MicroSeconds (16);
2115  break;
2116  }
2117  break;
2118  }
2119  case WIFI_MOD_CLASS_HT:
2120  case WIFI_MOD_CLASS_VHT:
2121  {
2122  //if short GI data rate is used then symbol duration is 3.6us else symbol duration is 4us
2123  //In the future has to create a stationmanager that only uses these data rates if sender and receiver support GI
2124  uint16_t gi = txVector.GetGuardInterval ();
2125  NS_ASSERT (gi == 400 || gi == 800);
2126  symbolDuration = NanoSeconds (3200 + gi);
2127  }
2128  break;
2129  case WIFI_MOD_CLASS_HE:
2130  {
2131  //if short GI data rate is used then symbol duration is 3.6us else symbol duration is 4us
2132  //In the future has to create a stationmanager that only uses these data rates if sender and receiver support GI
2133  uint16_t gi = txVector.GetGuardInterval ();
2134  NS_ASSERT (gi == 800 || gi == 1600 || gi == 3200);
2135  symbolDuration = NanoSeconds (12800 + gi);
2136  }
2137  break;
2138  default:
2139  break;
2140  }
2141 
2142  double numDataBitsPerSymbol = payloadMode.GetDataRate (txVector) * symbolDuration.GetNanoSeconds () / 1e9;
2143 
2144  double numSymbols = 0;
2145  if (mpdutype == MPDU_IN_AGGREGATE && preamble != WIFI_PREAMBLE_NONE)
2146  {
2147  //First packet in an A-MPDU
2148  numSymbols = (stbc * (16 + size * 8.0 + 6 * Nes) / (stbc * numDataBitsPerSymbol));
2149  if (incFlag == 1)
2150  {
2151  m_totalAmpduSize += size;
2152  m_totalAmpduNumSymbols += numSymbols;
2153  }
2154  }
2155  else if (mpdutype == MPDU_IN_AGGREGATE && preamble == WIFI_PREAMBLE_NONE)
2156  {
2157  //consecutive packets in an A-MPDU
2158  numSymbols = (stbc * size * 8.0) / (stbc * numDataBitsPerSymbol);
2159  if (incFlag == 1)
2160  {
2161  m_totalAmpduSize += size;
2162  m_totalAmpduNumSymbols += numSymbols;
2163  }
2164  }
2165  else if (mpdutype == LAST_MPDU_IN_AGGREGATE && preamble == WIFI_PREAMBLE_NONE)
2166  {
2167  //last packet in an A-MPDU
2168  uint32_t totalAmpduSize = m_totalAmpduSize + size;
2169  numSymbols = lrint (stbc * ceil ((16 + totalAmpduSize * 8.0 + 6 * Nes) / (stbc * numDataBitsPerSymbol)));
2170  NS_ASSERT (m_totalAmpduNumSymbols <= numSymbols);
2171  numSymbols -= m_totalAmpduNumSymbols;
2172  if (incFlag == 1)
2173  {
2174  m_totalAmpduSize = 0;
2176  }
2177  }
2178  else if (mpdutype == NORMAL_MPDU && preamble != WIFI_PREAMBLE_NONE)
2179  {
2180  //Not an A-MPDU
2181  numSymbols = lrint (stbc * ceil ((16 + size * 8.0 + 6.0 * Nes) / (stbc * numDataBitsPerSymbol)));
2182  }
2183  else
2184  {
2185  NS_FATAL_ERROR ("Wrong combination of preamble and packet type");
2186  }
2187 
2188  switch (payloadMode.GetModulationClass ())
2189  {
2190  case WIFI_MOD_CLASS_OFDM:
2192  {
2193  //Add signal extension for ERP PHY
2194  if (payloadMode.GetModulationClass () == WIFI_MOD_CLASS_ERP_OFDM)
2195  {
2196  return FemtoSeconds (numSymbols * symbolDuration.GetFemtoSeconds ()) + MicroSeconds (6);
2197  }
2198  else
2199  {
2200  return FemtoSeconds (numSymbols * symbolDuration.GetFemtoSeconds ());
2201  }
2202  }
2203  case WIFI_MOD_CLASS_HT:
2204  case WIFI_MOD_CLASS_VHT:
2205  {
2206  if (payloadMode.GetModulationClass () == WIFI_MOD_CLASS_HT && Is2_4Ghz (frequency)
2207  && ((mpdutype == NORMAL_MPDU && preamble != WIFI_PREAMBLE_NONE)
2208  || (mpdutype == LAST_MPDU_IN_AGGREGATE && preamble == WIFI_PREAMBLE_NONE))) //at 2.4 GHz
2209  {
2210  return FemtoSeconds (numSymbols * symbolDuration.GetFemtoSeconds ()) + MicroSeconds (6);
2211  }
2212  else //at 5 GHz
2213  {
2214  return FemtoSeconds (numSymbols * symbolDuration.GetFemtoSeconds ());
2215  }
2216  }
2217  case WIFI_MOD_CLASS_HE:
2218  {
2219  if (Is2_4Ghz (frequency)
2220  && ((mpdutype == NORMAL_MPDU && preamble != WIFI_PREAMBLE_NONE)
2221  || (mpdutype == LAST_MPDU_IN_AGGREGATE && preamble == WIFI_PREAMBLE_NONE))) //at 2.4 GHz
2222  {
2223  return FemtoSeconds (numSymbols * symbolDuration.GetFemtoSeconds ()) + MicroSeconds (6);
2224  }
2225  else //at 5 GHz
2226  {
2227  return FemtoSeconds (numSymbols * symbolDuration.GetFemtoSeconds ());
2228  }
2229  }
2230  case WIFI_MOD_CLASS_DSSS:
2232  return MicroSeconds (lrint (ceil ((size * 8.0) / (payloadMode.GetDataRate (22) / 1.0e6))));
2233  default:
2234  NS_FATAL_ERROR ("unsupported modulation class");
2235  return MicroSeconds (0);
2236  }
2237 }
2238 
2239 Time
2241 {
2242  WifiPreamble preamble = txVector.GetPreambleType ();
2243  Time duration = GetPlcpPreambleDuration (txVector)
2244  + GetPlcpHeaderDuration (txVector)
2245  + GetPlcpHtSigHeaderDuration (preamble)
2246  + GetPlcpSigA1Duration (preamble)
2247  + GetPlcpSigA2Duration (preamble)
2248  + GetPlcpTrainingSymbolDuration (txVector)
2249  + GetPlcpSigBDuration (preamble);
2250  return duration;
2251 }
2252 
2253 Time
2254 WifiPhy::CalculateTxDuration (uint32_t size, WifiTxVector txVector, uint16_t frequency, MpduType mpdutype, uint8_t incFlag)
2255 {
2256  Time duration = CalculatePlcpPreambleAndHeaderDuration (txVector)
2257  + GetPayloadDuration (size, txVector, frequency, mpdutype, incFlag);
2258  return duration;
2259 }
2260 
2261 Time
2262 WifiPhy::CalculateTxDuration (uint32_t size, WifiTxVector txVector, uint16_t frequency)
2263 {
2264  return CalculateTxDuration (size, txVector, frequency, NORMAL_MPDU, 0);
2265 }
2266 
2267 void
2269 {
2270  m_phyTxBeginTrace (packet);
2271 }
2272 
2273 void
2275 {
2276  m_phyTxEndTrace (packet);
2277 }
2278 
2279 void
2281 {
2282  m_phyTxDropTrace (packet);
2283 }
2284 
2285 void
2287 {
2288  m_phyRxBeginTrace (packet);
2289 }
2290 
2291 void
2293 {
2294  m_phyRxEndTrace (packet);
2295 }
2296 
2297 void
2299 {
2300  m_phyRxDropTrace (packet);
2301 }
2302 
2303 void
2304 WifiPhy::NotifyMonitorSniffRx (Ptr<const Packet> packet, uint16_t channelFreqMhz, WifiTxVector txVector, MpduInfo aMpdu, SignalNoiseDbm signalNoise)
2305 {
2306  m_phyMonitorSniffRxTrace (packet, channelFreqMhz, txVector, aMpdu, signalNoise);
2307 }
2308 
2309 void
2310 WifiPhy::NotifyMonitorSniffTx (Ptr<const Packet> packet, uint16_t channelFreqMhz, WifiTxVector txVector, MpduInfo aMpdu)
2311 {
2312  m_phyMonitorSniffTxTrace (packet, channelFreqMhz, txVector, aMpdu);
2313 }
2314 
2315 void
2317 {
2318  NS_LOG_FUNCTION (this << packet << txVector.GetMode ()
2319  << txVector.GetMode ().GetDataRate (txVector)
2320  << txVector.GetPreambleType ()
2321  << (uint16_t)txVector.GetTxPowerLevel ()
2322  << (uint16_t)mpdutype);
2323  /* Transmission can happen if:
2324  * - we are syncing on a packet. It is the responsability of the
2325  * MAC layer to avoid doing this but the PHY does nothing to
2326  * prevent it.
2327  * - we are idle
2328  */
2329  NS_ASSERT (!m_state->IsStateTx () && !m_state->IsStateSwitching ());
2330 
2331  if (txVector.GetNss () > GetMaxSupportedTxSpatialStreams ())
2332  {
2333  NS_FATAL_ERROR ("Unsupported number of spatial streams!");
2334  }
2335 
2336  if (m_state->IsStateSleep ())
2337  {
2338  NS_LOG_DEBUG ("Dropping packet because in sleep mode");
2339  NotifyTxDrop (packet);
2340  return;
2341  }
2342 
2343  Time txDuration = CalculateTxDuration (packet->GetSize (), txVector, GetFrequency (), mpdutype, 1);
2344  NS_ASSERT (txDuration.IsStrictlyPositive ());
2345 
2346  if (m_state->IsStateRx ())
2347  {
2349  m_endRxEvent.Cancel ();
2351  }
2352  NotifyTxBegin (packet);
2353  if ((mpdutype == MPDU_IN_AGGREGATE) && (txVector.GetPreambleType () != WIFI_PREAMBLE_NONE))
2354  {
2355  //send the first MPDU in an MPDU
2357  }
2358  MpduInfo aMpdu;
2359  aMpdu.type = mpdutype;
2361  NotifyMonitorSniffTx (packet, GetFrequency (), txVector, aMpdu);
2362  m_state->SwitchToTx (txDuration, packet, GetPowerDbm (txVector.GetTxPowerLevel ()), txVector);
2363 
2364  Ptr<Packet> newPacket = packet->Copy (); // obtain non-const Packet
2365  WifiPhyTag oldtag;
2366  newPacket->RemovePacketTag (oldtag);
2367  WifiPhyTag tag (txVector, mpdutype);
2368  newPacket->AddPacketTag (tag);
2369 
2370  StartTx (newPacket, txVector, txDuration);
2371 }
2372 
2373 void
2374 WifiPhy::StartReceivePreambleAndHeader (Ptr<Packet> packet, double rxPowerW, Time rxDuration)
2375 {
2376  //This function should be later split to check separately whether plcp preamble and plcp header can be successfully received.
2377  //Note: plcp preamble reception is not yet modeled.
2378  NS_LOG_FUNCTION (this << packet << WToDbm (rxPowerW) << rxDuration);
2379  Time endRx = Simulator::Now () + rxDuration;
2380 
2381  WifiPhyTag tag;
2382  bool found = packet->RemovePacketTag (tag);
2383  if (!found)
2384  {
2385  NS_FATAL_ERROR ("Received Wi-Fi Signal with no WifiPhyTag");
2386  return;
2387  }
2388 
2389  WifiTxVector txVector = tag.GetWifiTxVector ();
2390 
2391  if (txVector.GetMode ().GetModulationClass () == WIFI_MOD_CLASS_HT
2392  && (txVector.GetNss () != (1 + (txVector.GetMode ().GetMcsValue () / 8))))
2393  {
2394  NS_FATAL_ERROR ("MCS value does not match NSS value: MCS = " << (uint16_t)txVector.GetMode ().GetMcsValue () << ", NSS = " << (uint16_t)txVector.GetNss ());
2395  }
2396 
2398  event = m_interference.Add (packet,
2399  txVector,
2400  rxDuration,
2401  rxPowerW);
2402 
2403  if (txVector.GetNss () > GetMaxSupportedRxSpatialStreams ())
2404  {
2405  NS_LOG_DEBUG ("drop packet because not enough RX antennas");
2406  NotifyRxDrop (packet);
2407  m_plcpSuccess = false;
2408  if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ())
2409  {
2410  //that packet will be noise _after_ the transmission of the
2411  //currently-transmitted packet.
2413  return;
2414  }
2415  }
2416 
2417  MpduType mpdutype = tag.GetMpduType ();
2418  switch (m_state->GetState ())
2419  {
2420  case WifiPhy::SWITCHING:
2421  NS_LOG_DEBUG ("drop packet because of channel switching");
2422  NotifyRxDrop (packet);
2423  m_plcpSuccess = false;
2424  /*
2425  * Packets received on the upcoming channel are added to the event list
2426  * during the switching state. This way the medium can be correctly sensed
2427  * when the device listens to the channel for the first time after the
2428  * switching e.g. after channel switching, the channel may be sensed as
2429  * busy due to other devices' tramissions started before the end of
2430  * the switching.
2431  */
2432  if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ())
2433  {
2434  //that packet will be noise _after_ the completion of the
2435  //channel switching.
2437  return;
2438  }
2439  break;
2440  case WifiPhy::RX:
2441  NS_ASSERT (m_currentEvent != 0);
2442  if (m_frameCaptureModel != 0 &&
2443  m_frameCaptureModel->CaptureNewFrame(m_currentEvent, event))
2444  {
2446  NS_LOG_DEBUG ("Switch to new packet");
2447  StartRx (packet, txVector, mpdutype, rxPowerW, rxDuration, event);
2448  }
2449  else
2450  {
2451  NS_LOG_DEBUG ("drop packet because already in Rx (power=" <<
2452  rxPowerW << "W)");
2453  NotifyRxDrop (packet);
2454  if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ())
2455  {
2456  //that packet will be noise _after_ the reception of the
2457  //currently-received packet.
2459  return;
2460  }
2461  }
2462  break;
2463  case WifiPhy::TX:
2464  NS_LOG_DEBUG ("drop packet because already in Tx (power=" <<
2465  rxPowerW << "W)");
2466  NotifyRxDrop (packet);
2467  if (endRx > Simulator::Now () + m_state->GetDelayUntilIdle ())
2468  {
2469  //that packet will be noise _after_ the transmission of the
2470  //currently-transmitted packet.
2472  return;
2473  }
2474  break;
2475  case WifiPhy::CCA_BUSY:
2476  case WifiPhy::IDLE:
2477  StartRx (packet, txVector, mpdutype, rxPowerW, rxDuration, event);
2478  break;
2479  case WifiPhy::SLEEP:
2480  NS_LOG_DEBUG ("drop packet because in sleep mode");
2481  NotifyRxDrop (packet);
2482  m_plcpSuccess = false;
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,
2507 {
2508  NS_LOG_FUNCTION (this << packet << txVector.GetMode () << txVector.GetPreambleType () << (uint16_t)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 = RatioToDb (event->GetRxPowerW ()) + 30;
2562  signalNoise.noise = RatioToDb (event->GetRxPowerW () / snrPer.snr) + 30;
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  uint8_t chWidth = txVector.GetChannelWidth ();
3482  uint8_t nss = txVector.GetNss ();
3483  std::string modeName = txVector.GetMode ().GetUniqueName ();
3484 
3485  if (chWidth == 20)
3486  {
3487  if (nss != 3 && nss != 6)
3488  {
3489  return (modeName != "VhtMcs9");
3490  }
3491  }
3492  else if (chWidth == 80)
3493  {
3494  if (nss == 3 || nss == 7)
3495  {
3496  return (modeName != "VhtMcs6");
3497  }
3498  else if (nss == 6)
3499  {
3500  return (modeName != "VhtMcs9");
3501  }
3502  }
3503  else if (chWidth == 160)
3504  {
3505  if (nss == 3)
3506  {
3507  return (modeName != "VhtMcs9");
3508  }
3509  }
3510 
3511  return true;
3512 }
3513 
3514 bool
3516 {
3517  for (uint32_t i = 0; i < GetNModes (); i++)
3518  {
3519  if (mode == GetMode (i))
3520  {
3521  return true;
3522  }
3523  }
3524  return false;
3525 }
3526 
3527 bool
3529 {
3530  for (uint32_t i = 0; i < GetNMcs (); i++)
3531  {
3532  if (mcs == GetMcs (i))
3533  {
3534  return true;
3535  }
3536  }
3537  return false;
3538 }
3539 
3540 uint32_t
3542 {
3543  return m_deviceRateSet.size ();
3544 }
3545 
3546 WifiMode
3547 WifiPhy::GetMode (uint32_t mode) const
3548 {
3549  return m_deviceRateSet[mode];
3550 }
3551 
3552 uint8_t
3553 WifiPhy::GetNMcs (void) const
3554 {
3555  return m_deviceMcsSet.size ();
3556 }
3557 
3558 WifiMode
3559 WifiPhy::GetMcs (uint8_t mcs) const
3560 {
3561  return m_deviceMcsSet[mcs];
3562 }
3563 
3564 bool
3566 {
3567  return m_state->IsStateCcaBusy ();
3568 }
3569 
3570 bool
3572 {
3573  return m_state->IsStateIdle ();
3574 }
3575 
3576 bool
3578 {
3579  return m_state->IsStateBusy ();
3580 }
3581 
3582 bool
3584 {
3585  return m_state->IsStateRx ();
3586 }
3587 
3588 bool
3590 {
3591  return m_state->IsStateTx ();
3592 }
3593 
3594 bool
3596 {
3597  return m_state->IsStateSwitching ();
3598 }
3599 
3600 bool
3602 {
3603  return m_state->IsStateSleep ();
3604 }
3605 
3606 Time
3608 {
3609  return m_state->GetStateDuration ();
3610 }
3611 
3612 Time
3614 {
3615  return m_state->GetDelayUntilIdle ();
3616 }
3617 
3618 Time
3620 {
3621  return m_state->GetLastRxStartTime ();
3622 }
3623 
3624 void
3626 {
3627  NS_LOG_FUNCTION (this);
3628  //We are here because we have received the first bit of a packet and we are
3629  //not going to be able to synchronize on it
3630  //In this model, CCA becomes busy when the aggregation of all signals as
3631  //tracked by the InterferenceHelper class is higher than the CcaBusyThreshold
3632 
3634  if (!delayUntilCcaEnd.IsZero ())
3635  {
3636  NS_LOG_DEBUG ("Calling SwitchMaybeToCcaBusy for " << delayUntilCcaEnd.As (Time::S));
3637  m_state->SwitchMaybeToCcaBusy (delayUntilCcaEnd);
3638  }
3639 }
3640 
3641 void
3643 {
3644  NS_LOG_FUNCTION (this);
3645  if (m_endPlcpRxEvent.IsRunning ())
3646  {
3648  }
3649  if (m_endRxEvent.IsRunning ())
3650  {
3651  m_endRxEvent.Cancel ();
3652  }
3653  NotifyRxDrop (m_currentEvent->GetPacket ());
3655  m_state->SwitchFromRxAbort ();
3656  m_currentEvent = 0;
3657 }
3658 
3659 void
3660 WifiPhy::StartRx (Ptr<Packet> packet, WifiTxVector txVector, MpduType mpdutype, double rxPowerW, Time rxDuration, Ptr<InterferenceHelper::Event> event)
3661 {
3662  NS_LOG_FUNCTION (this << packet << txVector << (uint16_t)mpdutype << rxPowerW << rxDuration);
3663  if (rxPowerW > GetEdThresholdW ()) //checked here, no need to check in the payload reception (current implementation assumes constant rx power over the packet duration)
3664  {
3665  AmpduTag ampduTag;
3666  WifiPreamble preamble = txVector.GetPreambleType ();
3667  if (preamble == WIFI_PREAMBLE_NONE && (m_mpdusNum == 0 || m_plcpSuccess == false))
3668  {
3669  m_plcpSuccess = false;
3670  m_mpdusNum = 0;
3671  NS_LOG_DEBUG ("drop packet because no PLCP preamble/header has been received");
3672  NotifyRxDrop (packet);
3674  return;
3675  }
3676  else if (preamble != WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum == 0)
3677  {
3678  //received the first MPDU in an MPDU
3679  m_mpdusNum = ampduTag.GetRemainingNbOfMpdus ();
3681  }
3682  else if (preamble == WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum > 0)
3683  {
3684  //received the other MPDUs that are part of the A-MPDU
3685  if (ampduTag.GetRemainingNbOfMpdus () < (m_mpdusNum - 1))
3686  {
3687  NS_LOG_DEBUG ("Missing MPDU from the A-MPDU " << m_mpdusNum - ampduTag.GetRemainingNbOfMpdus ());
3688  m_mpdusNum = ampduTag.GetRemainingNbOfMpdus ();
3689  }
3690  else
3691  {
3692  m_mpdusNum--;
3693  }
3694  }
3695  else if (preamble != WIFI_PREAMBLE_NONE && packet->PeekPacketTag (ampduTag) && m_mpdusNum > 0)
3696  {
3697  NS_LOG_DEBUG ("New A-MPDU started while " << m_mpdusNum << " MPDUs from previous are lost");
3698  m_mpdusNum = ampduTag.GetRemainingNbOfMpdus ();
3699  }
3700  else if (preamble != WIFI_PREAMBLE_NONE && m_mpdusNum > 0 )
3701  {
3702  NS_LOG_DEBUG ("Didn't receive the last MPDUs from an A-MPDU " << m_mpdusNum);
3703  m_mpdusNum = 0;
3704  }
3705 
3706  NS_LOG_DEBUG ("sync to signal (power=" << rxPowerW << "W)");
3707  m_currentEvent = event;
3708  m_state->SwitchToRx (rxDuration);
3710  NotifyRxBegin (packet);
3712 
3713  if (preamble != WIFI_PREAMBLE_NONE)
3714  {
3716  Time preambleAndHeaderDuration = CalculatePlcpPreambleAndHeaderDuration (txVector);
3717  m_endPlcpRxEvent = Simulator::Schedule (preambleAndHeaderDuration, &WifiPhy::StartReceivePacket, this,
3718  packet, txVector, mpdutype, event);
3719  }
3720 
3723  packet, preamble, mpdutype, event);
3724  }
3725  else
3726  {
3727  NS_LOG_DEBUG ("drop packet because signal power too Small (" <<
3728  rxPowerW << "<" << GetEdThresholdW () << ")");
3729  NotifyRxDrop (packet);
3730  m_plcpSuccess = false;
3732  }
3733 }
3734 
3735 int64_t
3736 WifiPhy::AssignStreams (int64_t stream)
3737 {
3738  NS_LOG_FUNCTION (this << stream);
3739  m_random->SetStream (stream);
3740  return 1;
3741 }
3742 
3743 std::ostream& operator<< (std::ostream& os, WifiPhy::State state)
3744 {
3745  switch (state)
3746  {
3747  case WifiPhy::IDLE:
3748  return (os << "IDLE");
3749  case WifiPhy::CCA_BUSY:
3750  return (os << "CCA_BUSY");
3751  case WifiPhy::TX:
3752  return (os << "TX");
3753  case WifiPhy::RX:
3754  return (os << "RX");
3755  case WifiPhy::SWITCHING:
3756  return (os << "SWITCHING");
3757  case WifiPhy::SLEEP:
3758  return (os << "SLEEP");
3759  default:
3760  NS_FATAL_ERROR ("Invalid WifiPhy state");
3761  return (os << "INVALID");
3762  }
3763 }
3764 
3765 } //namespace ns3
3766 
3767 namespace {
3768 
3772 static class Constructor
3773 {
3774 public:
3776  {
3867  }
3868 } g_constructor;
3869 
3870 }
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:74
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:1851
Ptr< NetDevice > m_device
Pointer to the device.
Definition: wifi-phy.h:1978
static WifiMode GetErpOfdmRate24Mbps()
Return a WifiMode for ERP-OFDM at 24Mbps.
Definition: wifi-phy.cc:2694
static WifiMode GetDsssRate11Mbps()
Return a WifiMode for DSSS at 11Mbps.
Definition: wifi-phy.cc:2631
uint8_t GetChannelNumber(void) const
Return current channel number.
Definition: wifi-phy.cc:1496
uint16_t GetGuardInterval(void) const
double signal
in dBm
Definition: wifi-phy.h:69
uint32_t GetNBssMembershipSelectors(void) const
The WifiPhy::NBssMembershipSelectors() method is used (e.g., by a WifiRemoteStationManager) to determ...
Definition: wifi-phy.cc:1351
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:644
static WifiMode GetErpOfdmRate36Mbps()
Return a WifiMode for ERP-OFDM at 36Mbps.
Definition: wifi-phy.cc:2706
A struct for both SNR and PER.
bool IsStateBusy(void)
Definition: wifi-phy.cc:3577
Ptr< InterferenceHelper::Event > Add(Ptr< const Packet > packet, WifiTxVector txVector, Time duration, double rxPower)
Add the packet-related signal to interference helper.
The MPDU is not part of an A-MPDU.
Definition: wifi-phy.h:59
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.
uint8_t m_channelNumber
Operating channel number.
Definition: wifi-phy.h:1971
double m_rxGainDb
Reception gain (dB)
Definition: wifi-phy.h:1947
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
double GetTxGain(void) const
Return the transmission gain (dB).
Definition: wifi-phy.cc:572
double GetRxNoiseFigure(void) const
Return the RX noise figure (dBm).
Definition: wifi-phy.cc:520
void SetShortPlcpPreambleSupported(bool preamble)
Enable or disable short PLCP preamble.
Definition: wifi-phy.cc:657
AttributeValue implementation for Boolean.
Definition: boolean.h:36
bool IsMcsSupported(WifiMode mcs) const
Check if the given WifiMode is supported by the PHY.
Definition: wifi-phy.cc:3528
void SetNumberOfReceiveAntennas(uint8_t rx)
Set the number of RX antennas in the receiver corresponding to this interference helper.
Ptr< ErrorRateModel > GetErrorRateModel(void) const
Return the error rate model.
static WifiMode GetOfdmRate9Mbps()
Return a WifiMode for OFDM at 9Mbps.
Definition: wifi-phy.cc:2757
HT PHY for the 5 GHz band (clause 20)
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
uint8_t GetRemainingNbOfMpdus(void) const
Definition: ampdu-tag.cc:109
std::vector< uint8_t > m_supportedChannelWidthSet
Supported channel width.
Definition: wifi-phy.h:1970
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:1880
double m_txGainDb
Transmission gain (dB)
Definition: wifi-phy.h:1946
#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
virtual ~WifiPhy()
Definition: wifi-phy.cc:398
void SetLdpc(bool ldpc)
Enable or disable LDPC.
Definition: wifi-phy.cc:591
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:1952
void ResumeFromSleep(void)
Resume from sleep mode.
Definition: wifi-phy.cc:1638
bool GetGreenfield(void) const
Return whether Greenfield is supported.
Definition: wifi-phy.cc:624
static WifiMode GetHeMcs5()
Return MCS 5 from HE MCS values.
Definition: wifi-phy.cc:3423
802.11 PHY layer model
Definition: wifi-phy.h:164
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:565
The PHY layer has sense the medium busy through the CCA mechanism.
Definition: wifi-phy.h:180
void Configure80211ax(void)
Configure WifiPhy with appropriate channel frequency and supported rates for 802.11ax standard...
Definition: wifi-phy.cc:1027
double DbmToW(double dBm)
Convert from dBm to Watts.
Definition: wifi-utils.cc:41
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:404
bool IsZero(void) const
Definition: nstime.h:274
def start()
Definition: core.py:1790
void AddPacketTag(const Tag &tag) const
Add a packet tag.
Definition: packet.cc:814
void SetStbc(bool stbc)
Enable or disable STBC.
Definition: wifi-phy.cc:604
static Time GetPlcpHtSigHeaderDuration(WifiPreamble preamble)
Definition: wifi-phy.cc:1733
static WifiMode GetVhtMcs5()
Return MCS 5 from VHT MCS values.
Definition: wifi-phy.cc:3341
static WifiMode GetHtMcs22()
Return MCS 22 from HT MCS values.
Definition: wifi-phy.cc:3218
std::vector< uint32_t > m_bssMembershipSelectorSet
the BSS membership selector set
Definition: wifi-phy.h:1935
static WifiMode GetHtMcs14()
Return MCS 14 from HT MCS values.
Definition: wifi-phy.cc:3154
uint8_t GetMaxSupportedRxSpatialStreams(void) const
Definition: wifi-phy.cc:1345
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:1859
void EndReceive(Ptr< Packet > packet, WifiPreamble preamble, MpduType mpdutype, Ptr< InterferenceHelper::Event > event)
The last bit of the packet has arrived.
Definition: wifi-phy.cc:2541
#define HE_PHY
Definition: wifi-phy.h:38
void SetReceiveErrorCallback(RxErrorCallback callback)
Definition: wifi-phy.cc:434
static WifiMode GetHtMcs31()
Return MCS 31 from HT MCS values.
Definition: wifi-phy.cc:3290
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
uint8_t m_channelWidth
Channel width.
Definition: wifi-phy.h:1942
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:201
void SetErrorRateModel(const Ptr< ErrorRateModel > rate)
Set the error rate model for this interference helper.
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:2374
The MPDU is the last aggregate in an A-MPDU.
Definition: wifi-phy.h:63
Ptr< ErrorRateModel > GetErrorRateModel(void) const
Return the error rate model this PHY is using.
Definition: wifi-phy.cc:708
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
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:796
#define NS_UNUSED(x)
Mark a local variable as unused.
Definition: unused.h:36
second
Definition: nstime.h:114
OFDM PHY for the 5 GHz band (Clause 17 with 10 MHz channel bandwidth)
The PHY layer is sleeping.
Definition: wifi-phy.h:196
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 GetShortGuardInterval(void) const
Return whether short guard interval is supported.
Definition: wifi-phy.cc:637
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:682
void UnregisterListener(WifiPhyListener *listener)
Definition: wifi-phy.cc:446
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:512
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
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:2316
void ConfigureHolland(void)
Configure WifiPhy with appropriate channel frequency and supported rates for holland.
Definition: wifi-phy.cc:909
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:65
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:3553
void NotifyTxDrop(Ptr< const Packet > packet)
Public method used to fire a PhyTxDrop trace.
Definition: wifi-phy.cc:2280
uint64_t m_rxMpduReferenceNumber
A-MPDU reference number to identify all received subframes belonging to the same received A-MPDU...
Definition: wifi-phy.h:1693
int64_t GetFemtoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:361
HT PHY for the 2.4 GHz band (clause 20)
void SetGreenfield(bool greenfield)
Enable or disable Greenfield support.
Definition: wifi-phy.cc:617
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:879
HR/DSSS PHY (Clause 18)
Definition: wifi-mode.h:48
static WifiMode GetHtMcs8()
Return MCS 8 from HT MCS values.
Definition: wifi-phy.cc:3106
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:2268
virtual void SetFrequency(uint16_t freq)
Definition: wifi-phy.cc:1213
Ptr< FrameCaptureModel > GetFrameCaptureModel(void) const
Return the frame capture model this PHY is using.
Definition: wifi-phy.cc:720
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
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:1894
uint16_t GetFrequency(void) const
Definition: wifi-phy.cc:1270
std::vector< uint8_t > GetSupportedChannelWidthSet(void) const
Definition: wifi-phy.cc:1428
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:97
bool IsModeSupported(WifiMode mode) const
Check if the given WifiMode is supported by the PHY.
Definition: wifi-phy.cc:3515
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:1972
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 GetStbc(void) const
Return whether STBC is supported.
Definition: wifi-phy.cc:611
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:756
uint32_t GetBssMembershipSelector(uint32_t selector) const
The WifiPhy::BssMembershipSelector() method is used (e.g., by a WifiRemoteStationManager) to determin...
Definition: wifi-phy.cc:1357
static Time GetPlcpSigA1Duration(WifiPreamble preamble)
Definition: wifi-phy.cc:1748
uint8_t GetTxPowerLevel(void) const
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:1933
uint8_t GetChannelWidth(void) const
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:1939
void SetDevice(const Ptr< NetDevice > device)
Sets the device this PHY is associated with.
Definition: wifi-phy.cc:670
static WifiMode GetHtMcs16()
Return MCS 16 from HT MCS values.
Definition: wifi-phy.cc:3170
static WifiMode GetErpOfdmRate54Mbps()
Return a WifiMode for ERP-OFDM at 54Mbps.
Definition: wifi-phy.cc:2730
bool GetLdpc(void) const
Return if LDPC is supported.
Definition: wifi-phy.cc:598
uint16_t m_mpdusNum
carries the number of expected mpdus that are part of an A-MPDU
Definition: wifi-phy.h:1690
static bool Is2_4Ghz(double frequency)
Definition: wifi-phy.cc:1276
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
void NotifyRxDrop(Ptr< const Packet > packet)
Public method used to fire a PhyRxDrop trace.
Definition: wifi-phy.cc:2298
Time CalculateTxDuration(uint32_t size, WifiTxVector txVector, uint16_t frequency)
Definition: wifi-phy.cc:2262
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.
void SetNTxPower(uint32_t n)
Sets the number of transmission power levels available between the minimum level and the maximum leve...
Definition: wifi-phy.cc:552
static ChannelToFrequencyWidthMap m_channelToFrequencyWidth
the channel to frequency width map
Definition: wifi-phy.h:1968
double GetPowerDbm(uint8_t power) const
Get the power of the given power level in dBm.
Definition: wifi-phy.cc:726
double GetEdThreshold(void) const
Return the energy detection threshold (dBm).
Definition: wifi-phy.cc:493
WifiPhyStandard
Identifies the PHY specification that a Wifi device is configured to use.
bool PeekPacketTag(Tag &tag) const
Search a matching tag and call Tag::Deserialize if it is found.
Definition: packet.cc:836
static Time GetPlcpSigA2Duration(WifiPreamble preamble)
Definition: wifi-phy.cc:1763
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:1554
void SetFrameCaptureModel(const Ptr< FrameCaptureModel > rate)
Sets the frame capture model.
Definition: wifi-phy.cc:714
static WifiMode GetHtMcs2()
Return MCS 2 from HT MCS values.
Definition: wifi-phy.cc:3058
tuple mobility
Definition: third.py:101
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:1375
Ptr< MobilityModel > m_mobility
Pointer to the mobility model.
Definition: wifi-phy.h:1979
virtual void StartTx(Ptr< Packet > packet, WifiTxVector txVector, Time txDuration)=0
AttributeValue implementation for Time.
Definition: nstime.h:1055
static Time GetPlcpPreambleDuration(WifiTxVector txVector)
Definition: wifi-phy.cc:1910
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1017
receive notifications about phy events.
Definition: wifi-phy.h:83
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:1843
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:2304
bool m_shortPreamble
Flag if short PLCP preamble is supported.
Definition: wifi-phy.h:1956
bool IsStateTx(void)
Definition: wifi-phy.cc:3589
bool IsStrictlyPositive(void) const
Definition: nstime.h:294
static WifiMode GetHeMcs3()
Return MCS 3 from HE MCS values.
Definition: wifi-phy.cc:3407
static Time GetPlcpSigBDuration(WifiPreamble preamble)
Definition: wifi-phy.cc:1778
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:681
The PHY layer is IDLE.
Definition: wifi-phy.h:176
EventId m_endPlcpRxEvent
the end PLCP receive event
Definition: wifi-phy.h:1696
static WifiMode GetHtMcs12()
Return MCS 12 from HT MCS values.
Definition: wifi-phy.cc:3138
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:2240
void SetTxPowerEnd(double end)
Sets the maximum available transmission power level (dBm).
Definition: wifi-phy.cc:539
uint64_t GetDataRate(uint8_t channelWidth, uint16_t guardInterval, uint8_t nss) const
Definition: wifi-mode.cc:143
uint8_t GetNess(void) const
Time GetGuardInterval(void) const
Definition: wifi-phy.cc:651
static WifiMode GetOfdmRate12MbpsBW10MHz()
Return a WifiMode for OFDM at 12Mbps with 10MHz channel spacing.
Definition: wifi-phy.cc:2892
static WifiMode GetHeMcs11()
Return MCS 11 from HE MCS values.
Definition: wifi-phy.cc:3471
HT PHY (Clause 20)
Definition: wifi-mode.h:58
struct InterferenceHelper::SnrPer CalculatePlcpHeaderSnrPer(Ptr< InterferenceHelper::Event > event)
Calculate the SNIR at the start of the plcp header and accumulate all SNIR changes in the snir vector...
Time GetDelayUntilIdle(void)
Definition: wifi-phy.cc:3613
uint8_t GetMcsValue(void) const
Definition: wifi-mode.cc:465
std::string GetUniqueName(void) const
Definition: wifi-mode.cc:450
The PHY layer is receiving a packet.
Definition: wifi-phy.h:188
TracedCallback< Ptr< const Packet > > m_phyRxDropTrace
The trace source fired when the phy layer drops a packet it has received.
Definition: wifi-phy.h:1866
uint8_t m_numberOfTransmitters
Number of transmitters (DEPRECATED)
Definition: wifi-phy.h:1960
double m_edThresholdW
Energy detection threshold in watts.
Definition: wifi-phy.h:1944
void Configure80211_5Mhz()
Configure WifiPhy with appropriate channel frequency and supported rates for 802.11a standard with 5M...
Definition: wifi-phy.cc:894
void StartReceivePacket(Ptr< Packet > packet, WifiTxVector txVector, MpduType mpdutype, Ptr< InterferenceHelper::Event > event)
Starting receiving the payload of a packet (i.e.
Definition: wifi-phy.cc:2503
virtual ~WifiPhyListener()
Definition: wifi-phy.cc:43
uint64_t mpduRefNumber
MPDU ref number.
Definition: wifi-phy.h:77
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
Attribute or trace source is deprecated; user is warned.
Definition: type-id.h:72
void NotifyRxBegin(Ptr< const Packet > packet)
Public method used to fire a PhyRxBegin trace.
Definition: wifi-phy.cc:2286
The PHY layer is sending a packet.
Definition: wifi-phy.h:184
static WifiMode GetOfdmRate18Mbps()
Return a WifiMode for OFDM at 18Mbps.
Definition: wifi-phy.cc:2781
uint32_t GetNModes(void) const
The WifiPhy::GetNModes() and WifiPhy::GetMode() methods are used (e.g., by a WifiRemoteStationManager...
Definition: wifi-phy.cc:3541
static WifiMode GetOfdmRate9MbpsBW10MHz()
Return a WifiMode for OFDM at 9Mbps with 10MHz channel spacing.
Definition: wifi-phy.cc:2880
bool IsStbc(void) const
Check if STBC is used or not.
static WifiMode GetOfdmRate12MbpsBW5MHz()
Return a WifiMode for OFDM at 12Mbps with 5MHz channel spacing.
Definition: wifi-phy.cc:3015
WifiModeList GetMembershipSelectorModes(uint32_t selector)
The WifiPhy::GetMembershipSelectorModes() method is used (e.g., by a WifiRemoteStationManager) to det...
Definition: wifi-phy.cc:1363
The PHY layer is switching to other channel.
Definition: wifi-phy.h:192
void AbortCurrentReception(void)
Due to newly arrived signal, the current reception cannot be continued and has to be aborted...
Definition: wifi-phy.cc:3642
TracedCallback< Ptr< const Packet > > m_phyTxBeginTrace
The trace source fired when a packet begins the transmission process on the medium.
Definition: wifi-phy.h:1827
uint32_t GetNTxPower(void) const
Return the number of available transmission power levels.
Definition: wifi-phy.cc:559
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:701
Time GetEnergyDuration(double energyW) const
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
Ptr< Packet > Copy(void) const
performs a COW copy of the packet.
Definition: packet.cc:121
static WifiMode GetHeMcs9()
Return MCS 9 from HE MCS values.
Definition: wifi-phy.cc:3455
double f(double x, void *params)
Definition: 80211b.c:72
static WifiMode GetHtMcs0()
Return MCS 0 from HT MCS values.
Definition: wifi-phy.cc:3042
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:3559
struct InterferenceHelper::SnrPer CalculatePlcpPayloadSnrPer(Ptr< InterferenceHelper::Event > event)
Calculate the SNIR at the start of the plcp payload and accumulate all SNIR changes in the snir vecto...
static TypeId GetTypeId(void)
Get the type ID.
Definition: wifi-phy.cc:155
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.
virtual void SetChannelWidth(uint8_t channelwidth)
Definition: wifi-phy.cc:1296
Hold objects of type Ptr.
Definition: pointer.h:36
double GetTxPowerEnd(void) const
Return the maximum available transmission power level (dBm).
Definition: wifi-phy.cc:546
Time m_guardInterval
Supported HE guard interval.
Definition: wifi-phy.h:1958
bool IsStateIdle(void)
Definition: wifi-phy.cc:3571
static bool IsValidTxVector(WifiTxVector txVector)
The standard disallows certain combinations of WifiMode, number of spatial streams, and channel widths.
Definition: wifi-phy.cc:3479
void EraseEvents(void)
Erase all events.
uint64_t m_txMpduReferenceNumber
A-MPDU reference number to identify all transmitted subframes belonging to the same received A-MPDU...
Definition: wifi-phy.h:1692
static WifiMode GetOfdmRate24Mbps()
Return a WifiMode for OFDM at 24Mbps.
Definition: wifi-phy.cc:2793
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Definition: boolean.cc:121
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)
std::pair< uint16_t, uint8_t > FrequencyWidthPair
A pair of a center Frequency and a ChannelWidth.
Definition: wifi-phy.h:648
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:630
static WifiMode GetHeMcs0()
Return MCS 0 from HE MCS values.
Definition: wifi-phy.cc:3383
double CalculateSnr(WifiTxVector txVector, double ber) const
Definition: wifi-phy.cc:750
bool IsInitialized(void) const
Check if the object has been initialized.
Definition: object.cc:208
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:1338
void SetCcaMode1Threshold(double threshold)
Sets the CCA threshold (dBm).
Definition: wifi-phy.cc:499
Time GetLastRxStartTime(void) const
Return the start time of the last received packet.
Definition: wifi-phy.cc:3619
static WifiMode GetVhtMcs2()
Return MCS 2 from VHT MCS values.
Definition: wifi-phy.cc:3317
FrequencyWidthPair GetFrequencyWidthForChannelNumberStandard(uint8_t channelNumber, WifiPhyStandard standard) const
Lookup frequency/width pair for channelNumber/standard pair.
Definition: wifi-phy.cc:1434
virtual void SetChannelNumber(uint8_t id)
Set channel number.
Definition: wifi-phy.cc:1442
bool IsStateCcaBusy(void)
Definition: wifi-phy.cc:3565
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:1007
virtual void DoInitialize(void)
Initialize() implementation.
Definition: wifi-phy.cc:415
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:1056
double WToDbm(double w)
Convert from Watts to dBm.
Definition: wifi-utils.cc:48
std::vector< WifiMode > WifiModeList
In various parts of the code, folk are interested in maintaining a list of transmission modes...
Definition: wifi-mode.h:251
WifiPhyStandard m_standard
WifiPhyStandard.
Definition: wifi-phy.h:1937
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
void SetGuardInterval(Time guardInterval)
Definition: wifi-phy.cc:643
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:2274
Ptr< UniformRandomVariable > m_random
Provides uniform random variables.
Definition: wifi-phy.h:1687
double DbToRatio(double dB)
Convert from dB to ratio.
Definition: wifi-utils.cc:34
Time GetStateDuration(void)
Definition: wifi-phy.cc:3607
uint8_t m_txSpatialStreams
Number of supported TX spatial streams.
Definition: wifi-phy.h:1964
uint8_t GetMaxSupportedTxSpatialStreams(void) const
Definition: wifi-phy.cc:1332
double RatioToDb(double ratio)
Convert from ratio to dB.
Definition: wifi-utils.cc:54
void InitializeFrequencyChannelNumber(void)
post-construction setting of frequency and/or channel number
Definition: wifi-phy.cc:452
WifiPreamble GetPreambleType(void) const
Ptr< FrameCaptureModel > m_frameCaptureModel
Frame capture model.
Definition: wifi-phy.h:1982
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:90
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
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:353
Ptr< NetDevice > GetDevice(void) const
Return the device this PHY is associated with.
Definition: wifi-phy.cc:676
void SetRxGain(double gain)
Sets the reception gain (dB).
Definition: wifi-phy.cc:578
uint8_t GetChannelWidth(void) const
Definition: wifi-phy.cc:1304
void Configure80211b(void)
Configure WifiPhy with appropriate channel frequency and supported rates for 802.11b standard...
Definition: wifi-phy.cc:852
No explicit coding (e.g., DSSS rates)
Definition: wifi-mode.h:75
WifiTxVector GetWifiTxVector(void) const
Getter for WifiTxVector parameter.
Definition: wifi-phy-tag.cc:76
void SetReceiveOkCallback(RxOkCallback callback)
Definition: wifi-phy.cc:428
static WifiMode GetErpOfdmRate6Mbps()
Return a WifiMode for ERP-OFDM at 6Mbps.
Definition: wifi-phy.cc:2646
void RegisterListener(WifiPhyListener *listener)
Definition: wifi-phy.cc:440
void ConfigureChannelForStandard(WifiPhyStandard standard)
Configure the PHY-level parameters for different Wi-Fi standard.
Definition: wifi-phy.cc:1097
static bool Is5Ghz(double frequency)
Definition: wifi-phy.cc:1286
uint8_t GetNss(void) const
void SetMaxSupportedTxSpatialStreams(uint8_t streams)
Definition: wifi-phy.cc:1324
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:1691
bool m_greenfield
Flag if GreenField format is supported.
Definition: wifi-phy.h:1954
TimeWithUnit As(const enum Unit unit) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:388
EventId m_endRxEvent
the end reeive event
Definition: wifi-phy.h:1695
bool IsStateSleep(void)
Definition: wifi-phy.cc:3601
Ptr< WifiPhyStateHelper > m_state
Pointer to WifiPhyStateHelper.
Definition: wifi-phy.h:1688
void SetEdThreshold(double threshold)
Sets the energy detection threshold (dBm).
Definition: wifi-phy.cc:480
void NotifyRxEnd(Ptr< const Packet > packet)
Public method used to fire a PhyRxEnd trace.
Definition: wifi-phy.cc:2292
void Configure80211n(void)
Configure WifiPhy with appropriate channel frequency and supported rates for 802.11n standard...
Definition: wifi-phy.cc:990
void SetTxPowerStart(double start)
Sets the minimum available transmission power level (dBm).
Definition: wifi-phy.cc:526
double m_txPowerBaseDbm
Minimum transmission power (dBm)
Definition: wifi-phy.h:1948
void NotifyRxEnd()
Notify that RX has ended.
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:261
bool IsStateSwitching(void)
Definition: wifi-phy.cc:3595
SignalNoiseDbm structure.
Definition: wifi-phy.h:67
bool m_frequencyChannelNumberInitialized
Store initialization state.
Definition: wifi-phy.h:1941
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:1686
bool RemovePacketTag(Tag &tag)
Remove a packet tag.
Definition: packet.cc:821
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:1938
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:269
void ConfigureHtDeviceMcsSet(void)
Configure the device Mcs set with the appropriate HtMcs modes for the number of available transmit sp...
Definition: wifi-phy.cc:921
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:993
OFDM PHY (Clause 17)
Definition: wifi-mode.h:56
static WifiMode GetVhtPlcpHeaderMode()
Definition: wifi-phy.cc:1674
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:1976
static WifiMode GetHtMcs28()
Return MCS 28 from HT MCS values.
Definition: wifi-phy.cc:3266
static WifiMode GetHtMcs9()
Return MCS 9 from HT MCS values.
Definition: wifi-phy.cc:3114
Ptr< MobilityModel > GetMobility(void) const
Return the mobility model this PHY is associated with.
Definition: wifi-phy.cc:688
Time GetChannelSwitchDelay(void) const
Definition: wifi-phy.cc:744
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:35
void Configure80211g(void)
Configure WifiPhy with appropriate channel frequency and supported rates for 802.11g standard...
Definition: wifi-phy.cc:863
static WifiMode GetHePlcpHeaderMode()
Definition: wifi-phy.cc:1680
bool DefineChannelNumber(uint8_t channelNumber, WifiPhyStandard standard, uint16_t frequency, uint8_t channelWidth)
Add a channel definition to the WifiPhy.
Definition: wifi-phy.cc:1052
void SetSleepMode(void)
Put in sleep mode.
Definition: wifi-phy.cc:1606
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:1975
double noise
in dBm
Definition: wifi-phy.h:70
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1009
void StartRx(Ptr< Packet > packet, WifiTxVector txVector, MpduType mpdutype, double rxPowerW, Time rxDuration, Ptr< InterferenceHelper::Event > event)
Starting receiving the packet after having detected the medium is idle or after a reception switch...
Definition: wifi-phy.cc:3660
WifiModeList m_deviceRateSet
This vector holds the set of transmission modes that this WifiPhy(-derived class) can support...
Definition: wifi-phy.h:1932
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:2310
Time GetPayloadDuration(uint32_t size, WifiTxVector txVector, uint16_t frequency)
Definition: wifi-phy.cc:1964
void SetNumberOfAntennas(uint8_t antennas)
Definition: wifi-phy.cc:1310
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:1033
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:40
virtual void ConfigureStandard(WifiPhyStandard standard)
Configure the PHY-level parameters for different Wi-Fi standard.
Definition: wifi-phy.cc:1147
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:487
void AddSupportedChannelWidth(uint8_t channelwidth)
Definition: wifi-phy.cc:1413
static WifiMode GetOfdmRate6MbpsBW10MHz()
Return a WifiMode for OFDM at 6Mbps with 10MHz channel spacing.
Definition: wifi-phy.cc:2868
double GetEdThresholdW(void) const
Return the energy detection threshold.
Definition: wifi-phy.cc:487
WifiMode GetMode(void) const
double m_txPowerEndDbm
Maximum transmission power (dBm)
Definition: wifi-phy.h:1949
uint8_t GetNumberOfAntennas(void) const
Definition: wifi-phy.cc:1318
#define VHT_PHY
Definition: wifi-phy.h:39
The MPDU is part of an A-MPDU, but is not the last aggregate.
Definition: wifi-phy.h:61
bool GetShortPlcpPreambleSupported(void) const
Return whether short PLCP preamble is supported.
Definition: wifi-phy.cc:664
State
The state of the PHY layer.
Definition: wifi-phy.h:171
double GetNoiseFigure(void) const
Return the noise figure.
static WifiMode GetPlcpHeaderMode(WifiTxVector txVector)
Definition: wifi-phy.cc:1795
static Time GetPlcpTrainingSymbolDuration(WifiTxVector txVector)
Definition: wifi-phy.cc:1686
Ptr< InterferenceHelper::Event > m_currentEvent
Hold the current event.
Definition: wifi-phy.h:1981
This class can be used to hold variables of floating point type such as 'double' or 'float'...
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:76
Time m_channelSwitchDelay
Time required to switch between channel.
Definition: wifi-phy.h:1974
bool IsStateRx(void)
Definition: wifi-phy.cc:3583
static WifiMode GetOfdmRate13_5MbpsBW5MHz()
Return a WifiMode for OFDM at 13.5Mbps with 5MHz channel spacing.
Definition: wifi-phy.cc:3027
double m_ccaMode1ThresholdW
Clear channel assessment (CCA) threshold in watts.
Definition: wifi-phy.h:1945
double GetCcaMode1Threshold(void) const
Return the CCA threshold (dBm).
Definition: wifi-phy.cc:506
bool IsExpired(void) const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
Definition: event-id.cc:59
uint8_t FindChannelNumberForFrequencyWidth(uint16_t frequency, uint8_t width) const
Look for channel number matching the frequency and width.
Definition: wifi-phy.cc:1069
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:719
uint8_t m_numberOfAntennas
Number of transmitters.
Definition: wifi-phy.h:1963
static Time GetPlcpHeaderDuration(WifiTxVector txVector)
Definition: wifi-phy.cc:1841
a unique identifier for an interface.
Definition: type-id.h:58
MpduType
This enumeration defines the type of an MPDU.
Definition: wifi-phy.h:56
static WifiMode GetHtMcs15()
Return MCS 15 from HT MCS values.
Definition: wifi-phy.cc:3162
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914
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:1965
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:3625
bool m_shortGuardInterval
Flag if HT/VHT short guard interval is supported.
Definition: wifi-phy.h:1955
WifiPhyStandard GetStandard(void) const
Get the configured Wi-Fi standard.
Definition: wifi-phy.cc:1207
double GetRxGain(void) const
Return the reception gain (dB).
Definition: wifi-phy.cc:585
HE PHY (Clause 26)
Definition: wifi-mode.h:62
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:3736
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:1668
double GetTxPowerStart(void) const
Return the minimum available transmission power level (dBm).
Definition: wifi-phy.cc:533
static WifiMode GetOfdmRate4_5MbpsBW5MHz()
Return a WifiMode for OFDM at 4.5Mbps with 5MHz channel spacing.
Definition: wifi-phy.cc:2979
uint32_t m_nTxPower
Number of available transmission power levels.
Definition: wifi-phy.h:1950
bool m_stbc
Flag if STBC is used.
Definition: wifi-phy.h:1953
MpduType GetMpduType(void) const
Getter for mpduType parameter.
Definition: wifi-phy-tag.cc:82
void Configure80211a(void)
Configure WifiPhy with appropriate channel frequency and supported rates for 802.11a standard...
Definition: wifi-phy.cc:837
uint8_t m_numberOfReceivers
Number of receivers (DEPRECATED)
Definition: wifi-phy.h:1961
std::map< ChannelNumberStandardPair, FrequencyWidthPair > ChannelToFrequencyWidthMap
channel to frequency width map typedef
Definition: wifi-phy.h:1967
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:1835
uint16_t m_initialFrequency
Store frequency until initialization.
Definition: wifi-phy.h:1940
WifiMode GetMode(uint32_t mode) const
The WifiPhy::GetNModes() and WifiPhy::GetMode() methods are used (e.g., by a WifiRemoteStationManager...
Definition: wifi-phy.cc:3547
bool DoChannelSwitch(uint8_t id)
The default implementation does nothing and returns true.
Definition: wifi-phy.cc:1502