A Discrete-Event Network Simulator
API
wifi-phy-common.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
18 */
19
20#include "wifi-phy-common.h"
21
22#include "wifi-mode.h"
23#include "wifi-net-device.h"
24
25#include "ns3/he-configuration.h"
26#include "ns3/ht-configuration.h"
27
28namespace ns3
29{
30
31uint16_t
33{
34 uint16_t gi = 800;
36 {
37 Ptr<HeConfiguration> heConfiguration = device->GetHeConfiguration();
38 NS_ASSERT(heConfiguration); // If HE/EHT modulation is used, we should have a HE
39 // configuration attached
40 gi = static_cast<uint16_t>(heConfiguration->GetGuardInterval().GetNanoSeconds());
41 }
42 else if (mode.GetModulationClass() == WIFI_MOD_CLASS_HT ||
44 {
45 Ptr<HtConfiguration> htConfiguration = device->GetHtConfiguration();
46 NS_ASSERT(htConfiguration); // If HT/VHT modulation is used, we should have a HT
47 // configuration attached
48 gi = htConfiguration->GetShortGuardIntervalSupported() ? 400 : 800;
49 }
50 return gi;
51}
52
53uint16_t
54ConvertGuardIntervalToNanoSeconds(WifiMode mode, bool htShortGuardInterval, Time heGuardInterval)
55{
56 uint16_t gi;
58 {
59 gi = static_cast<uint16_t>(heGuardInterval.GetNanoSeconds());
60 }
61 else if (mode.GetModulationClass() == WIFI_MOD_CLASS_HT ||
63 {
64 gi = htShortGuardInterval ? 400 : 800;
65 }
66 else
67 {
68 gi = 800;
69 }
70 return gi;
71}
72
73uint16_t
74GetChannelWidthForTransmission(WifiMode mode, uint16_t maxAllowedChannelWidth)
75{
76 WifiModulationClass modulationClass = mode.GetModulationClass();
77 if (maxAllowedChannelWidth > 20 &&
78 (modulationClass == WifiModulationClass::WIFI_MOD_CLASS_OFDM // all non-HT OFDM control and
79 // management frames
80 || modulationClass ==
81 WifiModulationClass::WIFI_MOD_CLASS_ERP_OFDM)) // special case of beacons at 2.4 GHz
82 {
83 return 20;
84 }
85 // at 2.4 GHz basic rate can be non-ERP DSSS
86 if (modulationClass == WifiModulationClass::WIFI_MOD_CLASS_DSSS ||
88 {
89 return 22;
90 }
91 return maxAllowedChannelWidth;
92}
93
94uint16_t
96 uint16_t operatingChannelWidth,
97 uint16_t maxSupportedChannelWidth)
98{
100 (operatingChannelWidth < maxSupportedChannelWidth)
101 ? operatingChannelWidth
102 : maxSupportedChannelWidth);
103}
104
106GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
107{
108 if (modulation == WIFI_MOD_CLASS_EHT)
109 {
111 }
112 else if (modulation == WIFI_MOD_CLASS_HE)
113 {
114 return WIFI_PREAMBLE_HE_SU;
115 }
116 else if (modulation == WIFI_MOD_CLASS_DMG_CTRL)
117 {
119 }
120 else if (modulation == WIFI_MOD_CLASS_DMG_SC)
121 {
123 }
124 else if (modulation == WIFI_MOD_CLASS_DMG_OFDM)
125 {
127 }
128 else if (modulation == WIFI_MOD_CLASS_VHT)
129 {
131 }
132 else if (modulation == WIFI_MOD_CLASS_HT)
133 {
134 return WIFI_PREAMBLE_HT_MF; // HT_GF has been removed
135 }
136 else if (modulation == WIFI_MOD_CLASS_HR_DSSS &&
137 useShortPreamble) // ERP_DSSS is modeled through HR_DSSS (since same preamble and
138 // modulation)
139 {
140 return WIFI_PREAMBLE_SHORT;
141 }
142 else
143 {
144 return WIFI_PREAMBLE_LONG;
145 }
146}
147
148bool
150 WifiModulationClass modClassAnswer)
151{
152 switch (modClassReq)
153 {
155 return (modClassAnswer == WIFI_MOD_CLASS_DSSS);
157 return (modClassAnswer == WIFI_MOD_CLASS_DSSS || modClassAnswer == WIFI_MOD_CLASS_HR_DSSS);
159 return (modClassAnswer == WIFI_MOD_CLASS_DSSS || modClassAnswer == WIFI_MOD_CLASS_HR_DSSS ||
160 modClassAnswer == WIFI_MOD_CLASS_ERP_OFDM);
162 return (modClassAnswer == WIFI_MOD_CLASS_OFDM);
167 return true;
168 default:
169 NS_FATAL_ERROR("Modulation class not defined");
170 return false;
171 }
172}
173
174Time
176{
177 Time duration;
178
179 switch (preamble)
180 {
190 duration = MicroSeconds(5484);
191 break;
192 default:
193 duration = MicroSeconds(0);
194 break;
195 }
196 return duration;
197}
198
199bool
201{
202 return (IsDlMu(preamble) || IsUlMu(preamble));
203}
204
205bool
207{
208 return ((preamble == WIFI_PREAMBLE_HE_MU) || (preamble == WIFI_PREAMBLE_EHT_MU));
209}
210
211bool
213{
214 return ((preamble == WIFI_PREAMBLE_HE_TB) || (preamble == WIFI_PREAMBLE_EHT_TB));
215}
216
219{
221 switch (standard)
222 {
224 [[fallthrough]];
226 modulationClass = WIFI_MOD_CLASS_OFDM;
227 break;
229 modulationClass = WIFI_MOD_CLASS_DSSS;
230 break;
232 modulationClass = WIFI_MOD_CLASS_ERP_OFDM;
233 break;
235 modulationClass = WIFI_MOD_CLASS_HT;
236 break;
238 modulationClass = WIFI_MOD_CLASS_VHT;
239 break;
241 modulationClass = WIFI_MOD_CLASS_HE;
242 break;
244 modulationClass = WIFI_MOD_CLASS_EHT;
245 break;
247 [[fallthrough]];
248 default:
249 NS_ASSERT_MSG(false, "Unsupported standard " << standard);
250 break;
251 }
252 return modulationClass;
253}
254
255} // namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
int64_t GetNanoSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:417
represent a single transmission mode
Definition: wifi-mode.h:50
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:185
Ptr< HtConfiguration > GetHtConfiguration() const
Ptr< HeConfiguration > GetHeConfiguration() const
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#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:86
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:160
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1362
WifiStandard
Identifies the IEEE 802.11 specifications that a Wifi device can be configured to use.
WifiPreamble
The type of preamble to be used by an IEEE 802.11 transmission.
WifiModulationClass
This enumeration defines the modulation classes per (Table 10-6 "Modulation classes"; IEEE 802....
@ WIFI_STANDARD_80211a
@ WIFI_STANDARD_80211p
@ WIFI_STANDARD_80211be
@ WIFI_STANDARD_80211n
@ WIFI_STANDARD_80211g
@ WIFI_STANDARD_80211ax
@ WIFI_STANDARD_UNSPECIFIED
@ WIFI_STANDARD_80211ac
@ WIFI_STANDARD_80211b
@ WIFI_PREAMBLE_LONG
@ WIFI_PREAMBLE_EHT_TB
@ WIFI_PREAMBLE_HE_ER_SU
@ WIFI_PREAMBLE_HE_TB
@ WIFI_PREAMBLE_DMG_CTRL
@ WIFI_PREAMBLE_EHT_MU
@ WIFI_PREAMBLE_HE_MU
@ WIFI_PREAMBLE_HE_SU
@ WIFI_PREAMBLE_VHT_MU
@ WIFI_PREAMBLE_VHT_SU
@ WIFI_PREAMBLE_SHORT
@ WIFI_PREAMBLE_HT_MF
@ WIFI_PREAMBLE_DMG_SC
@ WIFI_PREAMBLE_DMG_OFDM
@ WIFI_MOD_CLASS_DMG_OFDM
DMG (Clause 21)
@ WIFI_MOD_CLASS_DMG_CTRL
DMG (Clause 21)
@ WIFI_MOD_CLASS_OFDM
OFDM (Clause 17)
@ WIFI_MOD_CLASS_HR_DSSS
HR/DSSS (Clause 16)
@ WIFI_MOD_CLASS_UNKNOWN
Modulation class unknown or unspecified.
@ WIFI_MOD_CLASS_DMG_SC
DMG (Clause 21)
@ WIFI_MOD_CLASS_HT
HT (Clause 19)
@ WIFI_MOD_CLASS_EHT
EHT (Clause 36)
@ WIFI_MOD_CLASS_VHT
VHT (Clause 22)
@ WIFI_MOD_CLASS_HE
HE (Clause 27)
@ WIFI_MOD_CLASS_DSSS
DSSS (Clause 15)
@ WIFI_MOD_CLASS_ERP_OFDM
ERP-OFDM (18.4)
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:850
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Time GetPpduMaxTime(WifiPreamble preamble)
Get the maximum PPDU duration (see Section 10.14 of 802.11-2016) for the PHY layers defining the aPPD...
bool IsAllowedControlAnswerModulationClass(WifiModulationClass modClassReq, WifiModulationClass modClassAnswer)
Return whether the modulation class of the selected mode for the control answer frame is allowed.
bool IsMu(WifiPreamble preamble)
Return true if a preamble corresponds to a multi-user transmission.
uint16_t GetChannelWidthForTransmission(WifiMode mode, uint16_t maxAllowedChannelWidth)
Return the channel width that is allowed based on the selected mode and the given maximum channel wid...
uint16_t ConvertGuardIntervalToNanoSeconds(WifiMode mode, const Ptr< WifiNetDevice > device)
Convert the guard interval to nanoseconds based on the WifiMode.
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
WifiModulationClass GetModulationClassForStandard(WifiStandard standard)
Return the modulation class corresponding to a given standard.
bool IsDlMu(WifiPreamble preamble)
Return true if a preamble corresponds to a downlink multi-user transmission.
bool IsUlMu(WifiPreamble preamble)
Return true if a preamble corresponds to a uplink multi-user transmission.
Declaration of the following enums: