A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wifi-phy-common.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Sébastien Deronne <sebastien.deronne@gmail.com>
7 */
8
9#include "wifi-phy-common.h"
10
11#include "wifi-mode.h"
12#include "wifi-net-device.h"
13
14#include "ns3/he-configuration.h"
15#include "ns3/ht-configuration.h"
16
17namespace ns3
18{
19
20Time
22{
23 auto gi = NanoSeconds(800);
25 {
26 Ptr<HeConfiguration> heConfiguration = device->GetHeConfiguration();
27 NS_ASSERT(heConfiguration); // If HE/EHT modulation is used, we should have a HE
28 // configuration attached
29 gi = heConfiguration->GetGuardInterval();
30 }
31 else if (mode.GetModulationClass() == WIFI_MOD_CLASS_HT ||
33 {
34 Ptr<HtConfiguration> htConfiguration = device->GetHtConfiguration();
35 NS_ASSERT(htConfiguration); // If HT/VHT modulation is used, we should have a HT
36 // configuration attached
37 gi = NanoSeconds(htConfiguration->m_sgiSupported ? 400 : 800);
38 }
39 return gi;
40}
41
42Time
43GetGuardIntervalForMode(WifiMode mode, bool htShortGuardInterval, Time heGuardInterval)
44{
45 auto gi = NanoSeconds(800);
47 {
48 gi = heGuardInterval;
49 }
50 else if (mode.GetModulationClass() == WIFI_MOD_CLASS_HT ||
52 {
53 gi = NanoSeconds(htShortGuardInterval ? 400 : 800);
54 }
55 return gi;
56}
57
58WifiPreamble
59GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble /* = false */)
60{
61 if (modulation == WIFI_MOD_CLASS_EHT)
62 {
64 }
65 else if (modulation == WIFI_MOD_CLASS_HE)
66 {
68 }
69 else if (modulation == WIFI_MOD_CLASS_DMG_CTRL)
70 {
72 }
73 else if (modulation == WIFI_MOD_CLASS_DMG_SC)
74 {
76 }
77 else if (modulation == WIFI_MOD_CLASS_DMG_OFDM)
78 {
80 }
81 else if (modulation == WIFI_MOD_CLASS_VHT)
82 {
84 }
85 else if (modulation == WIFI_MOD_CLASS_HT)
86 {
87 return WIFI_PREAMBLE_HT_MF; // HT_GF has been removed
88 }
89 else if (modulation == WIFI_MOD_CLASS_HR_DSSS &&
90 useShortPreamble) // ERP_DSSS is modeled through HR_DSSS (since same preamble and
91 // modulation)
92 {
94 }
95 else
96 {
97 return WIFI_PREAMBLE_LONG;
98 }
99}
100
101WifiModulationClass
103{
104 switch (preamble)
105 {
107 return WIFI_MOD_CLASS_HT;
110 return WIFI_MOD_CLASS_VHT;
115 return WIFI_MOD_CLASS_HE;
118 return WIFI_MOD_CLASS_EHT;
119 default:
120 NS_ABORT_MSG("Unsupported preamble type: " << preamble);
121 }
123}
124
125bool
127 WifiModulationClass modClassAnswer)
128{
129 switch (modClassReq)
130 {
132 return (modClassAnswer == WIFI_MOD_CLASS_DSSS);
134 return (modClassAnswer == WIFI_MOD_CLASS_DSSS || modClassAnswer == WIFI_MOD_CLASS_HR_DSSS);
136 return (modClassAnswer == WIFI_MOD_CLASS_DSSS || modClassAnswer == WIFI_MOD_CLASS_HR_DSSS ||
137 modClassAnswer == WIFI_MOD_CLASS_ERP_OFDM);
139 return (modClassAnswer == WIFI_MOD_CLASS_OFDM);
144 return true;
145 default:
146 NS_FATAL_ERROR("Modulation class not defined");
147 return false;
148 }
149}
150
151Time
153{
154 Time duration;
155
156 switch (preamble)
157 {
167 duration = MicroSeconds(5484);
168 break;
169 default:
170 duration = MicroSeconds(0);
171 break;
172 }
173 return duration;
174}
175
176bool
178{
179 return (IsDlMu(preamble) || IsUlMu(preamble));
180}
181
182bool
184{
185 return ((preamble == WIFI_PREAMBLE_HE_MU) || (preamble == WIFI_PREAMBLE_EHT_MU));
186}
187
188bool
190{
191 return ((preamble == WIFI_PREAMBLE_HE_TB) || (preamble == WIFI_PREAMBLE_EHT_TB));
192}
193
194WifiModulationClass
196{
198 switch (standard)
199 {
201 [[fallthrough]];
203 modulationClass = WIFI_MOD_CLASS_OFDM;
204 break;
206 // Although two modulation classes are supported in 802.11b, return the
207 // numerically greater one defined in the WifiModulationClass enum.
208 // See issue #1095 for more explanation.
209 modulationClass = WIFI_MOD_CLASS_HR_DSSS;
210 break;
212 modulationClass = WIFI_MOD_CLASS_ERP_OFDM;
213 break;
215 modulationClass = WIFI_MOD_CLASS_HT;
216 break;
218 modulationClass = WIFI_MOD_CLASS_VHT;
219 break;
221 modulationClass = WIFI_MOD_CLASS_HE;
222 break;
224 modulationClass = WIFI_MOD_CLASS_EHT;
225 break;
227 [[fallthrough]];
228 default:
229 NS_ASSERT_MSG(false, "Unsupported standard " << standard);
230 break;
231 }
232 return modulationClass;
233}
234
235MHz_u
237{
238 switch (modulation)
239 {
242 return 22;
245 return 20;
247 return 40;
248 // NOLINTBEGIN(bugprone-branch-clone)
251 return 160;
253 return 160; // TODO update when 320 MHz channels are supported and remove clang-tidy guards
254 // NOLINTEND(bugprone-branch-clone)
255 default:
256 NS_ABORT_MSG("Unknown modulation class: " << modulation);
257 return 0;
258 }
259}
260
261MHz_u
263{
264 switch (width)
265 {
267 return 0;
269 return 20;
271 return 22;
273 return 5;
275 return 10;
277 return 40;
279 return 80;
282 return 160;
284 return 2160;
285 default:
286 NS_FATAL_ERROR("Unknown wifi channel width type " << width);
287 return 0;
288 }
289}
290
291bool
293{
294 return ((preamble == WIFI_PREAMBLE_EHT_MU) || (preamble == WIFI_PREAMBLE_EHT_TB));
295}
296
297} // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
represent a single transmission mode
Definition wifi-mode.h:40
WifiModulationClass GetModulationClass() const
Definition wifi-mode.cc:174
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#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:75
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition abort.h:38
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1368
Time NanoSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1380
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....
WifiChannelWidthType
Enumeration of the possible channel widths.
Definition wifi-types.h:22
@ 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:864
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 IsEht(WifiPreamble preamble)
Return true if a preamble corresponds to an EHT transmission.
Time GetGuardIntervalForMode(WifiMode mode, const Ptr< WifiNetDevice > device)
Get the guard interval for a given WifiMode.
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.
double MHz_u
MHz weak type.
Definition wifi-units.h:31
WifiModulationClass GetModulationClassForPreamble(WifiPreamble preamble)
Return the modulation class corresponding to the given preamble type.
MHz_u GetMaximumChannelWidth(WifiModulationClass modulation)
Get the maximum channel width allowed for the given modulation class.
MHz_u GetChannelWidthInMhz(WifiChannelWidthType width)
Get the total channel width for the channel width type.
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.
WifiPreamble GetPreambleForTransmission(WifiModulationClass modulation, bool useShortPreamble)
Return the preamble to be used for the transmission.
bool IsUlMu(WifiPreamble preamble)
Return true if a preamble corresponds to a uplink multi-user transmission.
Declaration of the following enums: