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
27namespace ns3 {
28
29uint16_t
31{
32 uint16_t gi = 800;
34 {
35 Ptr<HeConfiguration> heConfiguration = device->GetHeConfiguration ();
36 NS_ASSERT (heConfiguration); //If HE/EHT 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
48uint16_t
49ConvertGuardIntervalToNanoSeconds (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
67uint16_t
68GetChannelWidthForTransmission (WifiMode mode, uint16_t maxAllowedChannelWidth)
69{
70 WifiModulationClass modulationClass = mode.GetModulationClass ();
71 if (maxAllowedChannelWidth > 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
80 {
81 return 22;
82 }
83 return maxAllowedChannelWidth;
84}
85
86uint16_t
87GetChannelWidthForTransmission (WifiMode mode, uint16_t operatingChannelWidth,
88 uint16_t maxSupportedChannelWidth)
89{
90 return GetChannelWidthForTransmission (mode, (operatingChannelWidth < maxSupportedChannelWidth)
91 ? operatingChannelWidth : maxSupportedChannelWidth);
92}
93
95GetPreambleForTransmission (WifiModulationClass modulation, bool useShortPreamble)
96{
97 if (modulation == WIFI_MOD_CLASS_EHT)
98 {
100 }
101 else if (modulation == WIFI_MOD_CLASS_HE)
102 {
103 return WIFI_PREAMBLE_HE_SU;
104 }
105 else if (modulation == WIFI_MOD_CLASS_DMG_CTRL)
106 {
108 }
109 else if (modulation == WIFI_MOD_CLASS_DMG_SC)
110 {
112 }
113 else if (modulation == WIFI_MOD_CLASS_DMG_OFDM)
114 {
116 }
117 else if (modulation == WIFI_MOD_CLASS_VHT)
118 {
120 }
121 else if (modulation == WIFI_MOD_CLASS_HT)
122 {
123 return WIFI_PREAMBLE_HT_MF; // HT_GF has been removed
124 }
125 else if (modulation == WIFI_MOD_CLASS_HR_DSSS && useShortPreamble) //ERP_DSSS is modeled through HR_DSSS (since same preamble and modulation)
126 {
127 return WIFI_PREAMBLE_SHORT;
128 }
129 else
130 {
131 return WIFI_PREAMBLE_LONG;
132 }
133}
134
135bool
137{
138 switch (modClassReq)
139 {
141 return (modClassAnswer == WIFI_MOD_CLASS_DSSS);
143 return (modClassAnswer == WIFI_MOD_CLASS_DSSS || modClassAnswer == WIFI_MOD_CLASS_HR_DSSS);
145 return (modClassAnswer == WIFI_MOD_CLASS_DSSS || modClassAnswer == WIFI_MOD_CLASS_HR_DSSS || modClassAnswer == WIFI_MOD_CLASS_ERP_OFDM);
147 return (modClassAnswer == WIFI_MOD_CLASS_OFDM);
152 return true;
153 default:
154 NS_FATAL_ERROR ("Modulation class not defined");
155 return false;
156 }
157}
158
159Time
161{
162 Time duration;
163
164 switch (preamble)
165 {
175 duration = MicroSeconds (5484);
176 break;
177 default:
178 duration = MicroSeconds (0);
179 break;
180 }
181 return duration;
182}
183
184bool
186{
187 return (IsDlMu (preamble) || IsUlMu (preamble));
188}
189
190bool
192{
193 return ((preamble == WIFI_PREAMBLE_HE_MU) || (preamble == WIFI_PREAMBLE_EHT_MU));
194}
195
196bool
198{
199 return ((preamble == WIFI_PREAMBLE_HE_TB) || (preamble == WIFI_PREAMBLE_EHT_TB));
200}
201
204{
206 switch (standard)
207 {
209 [[fallthrough]];
211 modulationClass = WIFI_MOD_CLASS_OFDM;
212 break;
214 modulationClass = WIFI_MOD_CLASS_DSSS;
215 break;
217 modulationClass = WIFI_MOD_CLASS_ERP_OFDM;
218 break;
220 modulationClass = WIFI_MOD_CLASS_HT;
221 break;
223 modulationClass = WIFI_MOD_CLASS_VHT;
224 break;
226 modulationClass = WIFI_MOD_CLASS_HE;
227 break;
229 modulationClass = WIFI_MOD_CLASS_EHT;
230 break;
232 [[fallthrough]];
233 default:
234 NS_ASSERT_MSG (false, "Unsupported standard " << standard);
235 break;
236 }
237 return modulationClass;
238}
239
240} //namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
int64_t GetNanoSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:392
represent a single transmission mode
Definition: wifi-mode.h:48
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:177
Ptr< HtConfiguration > GetHtConfiguration(void) const
Ptr< HeConfiguration > GetHeConfiguration(void) 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:67
#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:88
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1261
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:794
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: