A Discrete-Event Network Simulator
API
wifi-phy-common.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2021
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  * Author: S├ębastien Deronne <sebastien.deronne@gmail.com>
19  */
20 
21 #include "wifi-phy-common.h"
22 #include "wifi-mode.h"
23 #include "wifi-net-device.h"
24 #include "ns3/ht-configuration.h"
25 #include "ns3/he-configuration.h"
26 
27 namespace ns3 {
28 
29 uint16_t
31 {
32  uint16_t gi = 800;
34  {
35  Ptr<HeConfiguration> heConfiguration = device->GetHeConfiguration ();
36  NS_ASSERT (heConfiguration); //If HE modulation is used, we should have a HE configuration attached
37  gi = static_cast<uint16_t> (heConfiguration->GetGuardInterval ().GetNanoSeconds ());
38  }
40  {
41  Ptr<HtConfiguration> htConfiguration = device->GetHtConfiguration ();
42  NS_ASSERT (htConfiguration); //If HT/VHT modulation is used, we should have a HT configuration attached
43  gi = htConfiguration->GetShortGuardIntervalSupported () ? 400 : 800;
44  }
45  return gi;
46 }
47 
48 uint16_t
49 ConvertGuardIntervalToNanoSeconds (WifiMode mode, bool htShortGuardInterval, Time heGuardInterval)
50 {
51  uint16_t gi;
53  {
54  gi = static_cast<uint16_t> (heGuardInterval.GetNanoSeconds ());
55  }
57  {
58  gi = htShortGuardInterval ? 400 : 800;
59  }
60  else
61  {
62  gi = 800;
63  }
64  return gi;
65 }
66 
67 uint16_t
68 GetChannelWidthForTransmission (WifiMode mode, uint16_t maxSupportedChannelWidth)
69 {
70  WifiModulationClass modulationClass = mode.GetModulationClass ();
71  if (maxSupportedChannelWidth > 20
72  && (modulationClass == WifiModulationClass::WIFI_MOD_CLASS_OFDM // all non-HT OFDM control and management frames
73  || modulationClass == WifiModulationClass::WIFI_MOD_CLASS_ERP_OFDM)) // special case of beacons at 2.4 GHz
74  {
75  return 20;
76  }
77  //at 2.4 GHz basic rate can be non-ERP DSSS
78  if (modulationClass == WifiModulationClass::WIFI_MOD_CLASS_DSSS
79  || modulationClass == WifiModulationClass::WIFI_MOD_CLASS_HR_DSSS)
80  {
81  return 22;
82  }
83  return maxSupportedChannelWidth;
84 }
85 
87 GetPreambleForTransmission (WifiModulationClass modulation, bool useShortPreamble)
88 {
89  if (modulation == WIFI_MOD_CLASS_HE)
90  {
91  return WIFI_PREAMBLE_HE_SU;
92  }
93  else if (modulation == WIFI_MOD_CLASS_VHT)
94  {
95  return WIFI_PREAMBLE_VHT_SU;
96  }
97  else if (modulation == WIFI_MOD_CLASS_HT)
98  {
99  return WIFI_PREAMBLE_HT_MF; // HT_GF has been removed
100  }
101  else if (modulation == WIFI_MOD_CLASS_HR_DSSS && useShortPreamble) //ERP_DSSS is modeled through HR_DSSS (since same preamble and modulation)
102  {
103  return WIFI_PREAMBLE_SHORT;
104  }
105  else
106  {
107  return WIFI_PREAMBLE_LONG;
108  }
109 }
110 
111 bool
113 {
114  switch (modClassReq)
115  {
116  case WIFI_MOD_CLASS_DSSS:
117  return (modClassAnswer == WIFI_MOD_CLASS_DSSS);
119  return (modClassAnswer == WIFI_MOD_CLASS_DSSS || modClassAnswer == WIFI_MOD_CLASS_HR_DSSS);
121  return (modClassAnswer == WIFI_MOD_CLASS_DSSS || modClassAnswer == WIFI_MOD_CLASS_HR_DSSS || modClassAnswer == WIFI_MOD_CLASS_ERP_OFDM);
122  case WIFI_MOD_CLASS_OFDM:
123  return (modClassAnswer == WIFI_MOD_CLASS_OFDM);
124  case WIFI_MOD_CLASS_HT:
125  case WIFI_MOD_CLASS_VHT:
126  case WIFI_MOD_CLASS_HE:
127  return true;
128  default:
129  NS_FATAL_ERROR ("Modulation class not defined");
130  return false;
131  }
132 }
133 
134 Time
136 {
137  Time duration;
138 
139  switch (preamble)
140  {
141  case WIFI_PREAMBLE_HT_MF:
144  case WIFI_PREAMBLE_HE_SU:
146  case WIFI_PREAMBLE_HE_MU:
147  case WIFI_PREAMBLE_HE_TB:
148  duration = MicroSeconds (5484);
149  break;
150  default:
151  duration = MicroSeconds (0);
152  break;
153  }
154  return duration;
155 }
156 
157 bool
158 IsMu (WifiPreamble preamble)
159 {
160  return (IsDlMu (preamble) || IsUlMu (preamble));
161 }
162 
163 bool
165 {
166  return (preamble == WIFI_PREAMBLE_HE_MU);
167 }
168 
169 bool
171 {
172  return (preamble == WIFI_PREAMBLE_HE_TB);
173 }
174 
175 } //namespace ns3
NS_ASSERT
#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
ns3::WIFI_MOD_CLASS_ERP_OFDM
@ WIFI_MOD_CLASS_ERP_OFDM
ERP-OFDM (18.4)
Definition: wifi-phy-common.h:128
ns3::WifiNetDevice::GetHtConfiguration
Ptr< HtConfiguration > GetHtConfiguration(void) const
Definition: wifi-net-device.cc:456
ns3::IsMu
bool IsMu(WifiPreamble preamble)
Return true if a preamble corresponds to a multi-user transmission.
Definition: wifi-phy-common.cc:158
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::WIFI_MOD_CLASS_HT
@ WIFI_MOD_CLASS_HT
HT (Clause 19)
Definition: wifi-phy-common.h:130
ns3::WIFI_MOD_CLASS_HE
@ WIFI_MOD_CLASS_HE
HE (Clause 27)
Definition: wifi-phy-common.h:132
ns3::MicroSeconds
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1305
ns3::WIFI_PREAMBLE_VHT_SU
@ WIFI_PREAMBLE_VHT_SU
Definition: wifi-phy-common.h:72
ns3::WifiMode::GetModulationClass
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:159
wifi-phy-common.h
Declaration of the following enums:
ns3::WIFI_MOD_CLASS_OFDM
@ WIFI_MOD_CLASS_OFDM
OFDM (Clause 17)
Definition: wifi-phy-common.h:129
ns3::WIFI_PREAMBLE_HE_SU
@ WIFI_PREAMBLE_HE_SU
Definition: wifi-phy-common.h:74
ns3::WifiNetDevice::GetHeConfiguration
Ptr< HeConfiguration > GetHeConfiguration(void) const
Definition: wifi-net-device.cc:480
ns3::GetPpduMaxTime
Time GetPpduMaxTime(WifiPreamble preamble)
Get the maximum PPDU duration (see Section 10.14 of 802.11-2016) for the PHY layers defining the aPPD...
Definition: wifi-phy-common.cc:135
ns3::HtConfiguration::GetShortGuardIntervalSupported
bool GetShortGuardIntervalSupported(void) const
Definition: ht-configuration.cc:73
ns3::WIFI_MOD_CLASS_HR_DSSS
@ WIFI_MOD_CLASS_HR_DSSS
HR/DSSS (Clause 16)
Definition: wifi-phy-common.h:127
ns3::Ptr< WifiNetDevice >
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
ns3::WifiMode
represent a single transmission mode
Definition: wifi-mode.h:48
ns3::WIFI_PREAMBLE_HE_ER_SU
@ WIFI_PREAMBLE_HE_ER_SU
Definition: wifi-phy-common.h:75
wifi-net-device.h
ns3::ConvertGuardIntervalToNanoSeconds
uint16_t ConvertGuardIntervalToNanoSeconds(WifiMode mode, const Ptr< WifiNetDevice > device)
Convert the guard interval to nanoseconds based on the WifiMode.
Definition: wifi-phy-common.cc:30
ns3::WIFI_PREAMBLE_HE_MU
@ WIFI_PREAMBLE_HE_MU
Definition: wifi-phy-common.h:76
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::GetChannelWidthForTransmission
uint16_t GetChannelWidthForTransmission(WifiMode mode, uint16_t maxSupportedChannelWidth)
Return the channel width that corresponds to the selected mode (instead of letting the PHY's default ...
Definition: wifi-phy-common.cc:68
wifi-mode.h
ns3::Time::GetNanoSeconds
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:392
ns3::WIFI_PREAMBLE_VHT_MU
@ WIFI_PREAMBLE_VHT_MU
Definition: wifi-phy-common.h:73
ns3::WifiPreamble
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
Definition: wifi-phy-common.h:68
ns3::GetPreambleForTransmission
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
Definition: wifi-phy-common.cc:87
ns3::WIFI_PREAMBLE_LONG
@ WIFI_PREAMBLE_LONG
Definition: wifi-phy-common.h:69
ns3::IsUlMu
bool IsUlMu(WifiPreamble preamble)
Return true if a preamble corresponds to a uplink multi-user transmission.
Definition: wifi-phy-common.cc:170
ns3::TracedValueCallback::Time
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:813
ns3::IsAllowedControlAnswerModulationClass
bool IsAllowedControlAnswerModulationClass(WifiModulationClass modClassReq, WifiModulationClass modClassAnswer)
Return whether the modulation class of the selected mode for the control answer frame is allowed.
Definition: wifi-phy-common.cc:112
ns3::WIFI_MOD_CLASS_VHT
@ WIFI_MOD_CLASS_VHT
VHT (Clause 22)
Definition: wifi-phy-common.h:131
ns3::HeConfiguration::GetGuardInterval
Time GetGuardInterval(void) const
Definition: he-configuration.cc:182
ns3::WIFI_PREAMBLE_HE_TB
@ WIFI_PREAMBLE_HE_TB
Definition: wifi-phy-common.h:77
ns3::WIFI_PREAMBLE_HT_MF
@ WIFI_PREAMBLE_HT_MF
Definition: wifi-phy-common.h:71
ns3::WIFI_PREAMBLE_SHORT
@ WIFI_PREAMBLE_SHORT
Definition: wifi-phy-common.h:70
ns3::WIFI_MOD_CLASS_DSSS
@ WIFI_MOD_CLASS_DSSS
DSSS (Clause 15)
Definition: wifi-phy-common.h:126
ns3::WifiModulationClass
WifiModulationClass
This enumeration defines the modulation classes per (Table 10-6 "Modulation classes"; IEEE 802....
Definition: wifi-phy-common.h:122
ns3::IsDlMu
bool IsDlMu(WifiPreamble preamble)
Return true if a preamble corresponds to a downlink multi-user transmission.
Definition: wifi-phy-common.cc:164