A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
erp-ofdm-phy.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Orange Labs
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 * Authors: Rediet <getachew.redieteab@orange.com>
18 * Sébastien Deronne <sebastien.deronne@gmail.com> (for logic ported from wifi-phy)
19 * Mathieu Lacage <mathieu.lacage@sophia.inria.fr> (for logic ported from wifi-phy)
20 */
21
22#include "erp-ofdm-phy.h"
23
24#include "erp-ofdm-ppdu.h"
25
26#include "ns3/assert.h"
27#include "ns3/log.h"
28#include "ns3/wifi-phy.h" //only used for static mode constructor
29#include "ns3/wifi-psdu.h"
30
31#include <array>
32
33namespace ns3
34{
35
36NS_LOG_COMPONENT_DEFINE("ErpOfdmPhy");
37
38/*******************************************************
39 * ERP-OFDM PHY (IEEE 802.11-2016, clause 18)
40 *******************************************************/
41
42// clang-format off
43
45 // Unique name Code rate Constellation size
46 { "ErpOfdmRate6Mbps", { WIFI_CODE_RATE_1_2, 2 } },
47 { "ErpOfdmRate9Mbps", { WIFI_CODE_RATE_3_4, 2 } },
48 { "ErpOfdmRate12Mbps", { WIFI_CODE_RATE_1_2, 4 } },
49 { "ErpOfdmRate18Mbps", { WIFI_CODE_RATE_3_4, 4 } },
50 { "ErpOfdmRate24Mbps", { WIFI_CODE_RATE_1_2, 16 } },
51 { "ErpOfdmRate36Mbps", { WIFI_CODE_RATE_3_4, 16 } },
52 { "ErpOfdmRate48Mbps", { WIFI_CODE_RATE_2_3, 64 } },
53 { "ErpOfdmRate54Mbps", { WIFI_CODE_RATE_3_4, 64 } }
54};
55
57static const std::array<uint64_t, 8> s_erpOfdmRatesBpsList =
58 { 6000000, 9000000, 12000000, 18000000,
59 24000000, 36000000, 48000000, 54000000};
60
61// clang-format on
62
68const std::array<uint64_t, 8>&
70{
72};
73
75 : OfdmPhy(OFDM_PHY_DEFAULT, false) // don't add OFDM modes to list
76{
77 NS_LOG_FUNCTION(this);
78 for (const auto& rate : GetErpOfdmRatesBpsList())
79 {
80 WifiMode mode = GetErpOfdmRate(rate);
81 NS_LOG_LOGIC("Add " << mode << " to list");
82 m_modeList.emplace_back(mode);
83 }
84}
85
87{
88 NS_LOG_FUNCTION(this);
89}
90
93{
95 return GetErpOfdmRate6Mbps();
96}
97
98Time
100{
101 return MicroSeconds(16); // L-STF + L-LTF
102}
103
104Time
105ErpOfdmPhy::GetHeaderDuration(const WifiTxVector& /* txVector */) const
106{
107 return MicroSeconds(4); // L-SIG
108}
109
112 const WifiTxVector& txVector,
113 Time /* ppduDuration */)
114{
115 NS_LOG_FUNCTION(this << psdus << txVector);
116 return Create<ErpOfdmPpdu>(
117 psdus.begin()->second,
118 txVector,
120 txVector.GetChannelWidth()),
122 m_wifiPhy->GetLatestPhyEntity()->ObtainNextUid(
123 txVector)); // use latest PHY entity to handle MU-RTS sent with non-HT rate
124}
125
126void
128{
129 for (const auto& rate : GetErpOfdmRatesBpsList())
130 {
131 GetErpOfdmRate(rate);
132 }
133}
134
137{
138 switch (rate)
139 {
140 case 6000000:
141 return GetErpOfdmRate6Mbps();
142 case 9000000:
143 return GetErpOfdmRate9Mbps();
144 case 12000000:
145 return GetErpOfdmRate12Mbps();
146 case 18000000:
147 return GetErpOfdmRate18Mbps();
148 case 24000000:
149 return GetErpOfdmRate24Mbps();
150 case 36000000:
151 return GetErpOfdmRate36Mbps();
152 case 48000000:
153 return GetErpOfdmRate48Mbps();
154 case 54000000:
155 return GetErpOfdmRate54Mbps();
156 default:
157 NS_ABORT_MSG("Inexistent rate (" << rate << " bps) requested for ERP-OFDM");
158 return WifiMode();
159 }
160}
161
162#define GET_ERP_OFDM_MODE(x, f) \
163 WifiMode ErpOfdmPhy::Get##x() \
164 { \
165 static WifiMode mode = CreateErpOfdmMode(#x, f); \
166 return mode; \
167 };
168
169GET_ERP_OFDM_MODE(ErpOfdmRate6Mbps, true)
170GET_ERP_OFDM_MODE(ErpOfdmRate9Mbps, false)
171GET_ERP_OFDM_MODE(ErpOfdmRate12Mbps, true)
172GET_ERP_OFDM_MODE(ErpOfdmRate18Mbps, false)
173GET_ERP_OFDM_MODE(ErpOfdmRate24Mbps, true)
174GET_ERP_OFDM_MODE(ErpOfdmRate36Mbps, false)
175GET_ERP_OFDM_MODE(ErpOfdmRate48Mbps, false)
176GET_ERP_OFDM_MODE(ErpOfdmRate54Mbps, false)
177#undef GET_ERP_OFDM_MODE
178
179WifiMode
180ErpOfdmPhy::CreateErpOfdmMode(std::string uniqueName, bool isMandatory)
181{
182 // Check whether uniqueName is in lookup table
183 const auto it = m_erpOfdmModulationLookupTable.find(uniqueName);
185 "ERP-OFDM mode cannot be created because it is not in the lookup table!");
186
187 return WifiModeFactory::CreateWifiMode(uniqueName,
189 isMandatory,
190 MakeBoundCallback(&GetCodeRate, uniqueName),
195}
196
198ErpOfdmPhy::GetCodeRate(const std::string& name)
199{
200 return m_erpOfdmModulationLookupTable.at(name).first;
201}
202
203uint16_t
204ErpOfdmPhy::GetConstellationSize(const std::string& name)
205{
206 return m_erpOfdmModulationLookupTable.at(name).second;
207}
208
209uint64_t
210ErpOfdmPhy::GetPhyRate(const std::string& name, uint16_t channelWidth)
211{
212 WifiCodeRate codeRate = GetCodeRate(name);
213 uint16_t constellationSize = GetConstellationSize(name);
214 uint64_t dataRate = OfdmPhy::CalculateDataRate(codeRate, constellationSize, channelWidth);
215 return OfdmPhy::CalculatePhyRate(codeRate, dataRate);
216}
217
218uint64_t
219ErpOfdmPhy::GetPhyRateFromTxVector(const WifiTxVector& txVector, uint16_t /* staId */)
220{
221 return GetPhyRate(txVector.GetMode().GetUniqueName(), txVector.GetChannelWidth());
222}
223
224uint64_t
225ErpOfdmPhy::GetDataRateFromTxVector(const WifiTxVector& txVector, uint16_t /* staId */)
226{
227 return GetDataRate(txVector.GetMode().GetUniqueName(), txVector.GetChannelWidth());
228}
229
230uint64_t
231ErpOfdmPhy::GetDataRate(const std::string& name, uint16_t channelWidth)
232{
233 WifiCodeRate codeRate = GetCodeRate(name);
234 uint16_t constellationSize = GetConstellationSize(name);
235 return OfdmPhy::CalculateDataRate(codeRate, constellationSize, channelWidth);
236}
237
238bool
240{
241 return true;
242}
243
246{
247 return 4095;
248}
249
250} // namespace ns3
251
252namespace
253{
254
259{
260 public:
262 {
265 ns3::Create<ns3::ErpOfdmPhy>());
266 }
268
269} // namespace
~ErpOfdmPhy() override
Destructor for ERP-OFDM PHY.
Definition: erp-ofdm-phy.cc:86
static uint64_t GetPhyRateFromTxVector(const WifiTxVector &txVector, uint16_t staId)
Return the PHY rate corresponding to the supplied TXVECTOR.
static const ModulationLookupTable m_erpOfdmModulationLookupTable
lookup table to retrieve code rate and constellation size corresponding to a unique name of modulatio...
Definition: erp-ofdm-phy.h:212
static WifiCodeRate GetCodeRate(const std::string &name)
Return the WifiCodeRate from the ERP-OFDM mode's unique name using ModulationLookupTable.
Time GetPreambleDuration(const WifiTxVector &txVector) const override
Definition: erp-ofdm-phy.cc:99
Time GetHeaderDuration(const WifiTxVector &txVector) const override
static void InitializeModes()
Initialize all ERP-OFDM modes.
Ptr< WifiPpdu > BuildPpdu(const WifiConstPsduMap &psdus, const WifiTxVector &txVector, Time ppduDuration) override
Build amendment-specific PPDU.
static uint64_t GetDataRateFromTxVector(const WifiTxVector &txVector, uint16_t staId)
Return the data rate corresponding to the supplied TXVECTOR.
uint32_t GetMaxPsduSize() const override
Get the maximum PSDU size in bytes.
static uint64_t GetPhyRate(const std::string &name, uint16_t channelWidth)
Return the PHY rate from the ERP-OFDM mode's unique name and the supplied parameters.
static WifiMode GetErpOfdmRate(uint64_t rate)
Return a WifiMode for ERP-OFDM corresponding to the provided rate.
static bool IsAllowed(const WifiTxVector &txVector)
Check whether the combination in TXVECTOR is allowed.
static WifiMode GetErpOfdmRate6Mbps()
Return a WifiMode for ERP-OFDM at 6 Mbps.
ErpOfdmPhy()
Constructor for ERP-OFDM PHY.
Definition: erp-ofdm-phy.cc:74
static WifiMode GetErpOfdmRate18Mbps()
Return a WifiMode for ERP-OFDM at 18 Mbps.
static WifiMode GetErpOfdmRate24Mbps()
Return a WifiMode for ERP-OFDM at 24 Mbps.
static uint16_t GetConstellationSize(const std::string &name)
Return the constellation size from the ERP-OFDM mode's unique name using ModulationLookupTable.
static WifiMode GetErpOfdmRate12Mbps()
Return a WifiMode for ERP-OFDM at 12 Mbps.
static WifiMode CreateErpOfdmMode(std::string uniqueName, bool isMandatory)
Create an ERP-OFDM mode from a unique name, the unique name must already be contained inside Modulati...
static WifiMode GetErpOfdmRate9Mbps()
Return a WifiMode for ERP-OFDM at 9 Mbps.
static WifiMode GetErpOfdmRate48Mbps()
Return a WifiMode for ERP-OFDM at 48 Mbps.
static WifiMode GetErpOfdmRate54Mbps()
Return a WifiMode for ERP-OFDM at 54 Mbps.
WifiMode GetHeaderMode(const WifiTxVector &txVector) const override
Definition: erp-ofdm-phy.cc:92
static WifiMode GetErpOfdmRate36Mbps()
Return a WifiMode for ERP-OFDM at 36 Mbps.
static uint64_t GetDataRate(const std::string &name, uint16_t channelWidth)
Return the data rate from the ERP-OFDM mode's unique name and the supplied parameters.
PHY entity for OFDM (11a)
Definition: ofdm-phy.h:61
static uint64_t CalculateDataRate(WifiCodeRate codeRate, uint16_t constellationSize, uint16_t channelWidth)
Calculates data rate from the supplied parameters.
Definition: ofdm-phy.cc:614
static uint64_t CalculatePhyRate(WifiCodeRate codeRate, uint64_t dataRate)
Calculate the PHY rate in bps from code rate and data rate.
Definition: ofdm-phy.cc:570
Ptr< WifiPhy > m_wifiPhy
Pointer to the owning WifiPhy.
Definition: phy-entity.h:963
std::map< std::string, CodeRateConstellationSizePair > ModulationLookupTable
A modulation lookup table using unique name of modulation as key.
Definition: phy-entity.h:566
std::list< WifiMode > m_modeList
the list of supported modes
Definition: phy-entity.h:967
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
static WifiMode CreateWifiMode(std::string uniqueName, WifiModulationClass modClass, bool isMandatory, CodeRateCallback codeRateCallback, ConstellationSizeCallback constellationSizeCallback, PhyRateCallback phyRateCallback, DataRateCallback dataRateCallback, AllowedCallback isAllowedCallback)
Definition: wifi-mode.cc:270
represent a single transmission mode
Definition: wifi-mode.h:50
std::string GetUniqueName() const
Definition: wifi-mode.cc:148
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:185
WifiPhyBand GetPhyBand() const
Get the configured Wi-Fi band.
Definition: wifi-phy.cc:996
static void AddStaticPhyEntity(WifiModulationClass modulation, Ptr< PhyEntity > phyEntity)
Add the PHY entity to the map of implemented PHY entities for the given modulation class.
Definition: wifi-phy.cc:745
const WifiPhyOperatingChannel & GetOperatingChannel() const
Get a const reference to the operating channel.
Definition: wifi-phy.cc:1008
Ptr< PhyEntity > GetLatestPhyEntity() const
Get the latest PHY entity supported by this PHY instance.
Definition: wifi-phy.cc:719
uint16_t GetPrimaryChannelCenterFrequency(uint16_t primaryChannelWidth) const
Get the center frequency of the primary channel of the given width.
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
WifiMode GetMode(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the selected payload transmission mode.
uint16_t GetChannelWidth() const
#define GET_ERP_OFDM_MODE(x, f)
Declaration of ns3::ErpOfdmPhy class.
Declaration of ns3::ErpOfdmPpdu class.
#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_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:49
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
auto MakeBoundCallback(R(*fnPtr)(Args...), BArgs &&... bargs)
Make Callbacks with varying number of bound arguments.
Definition: callback.h:768
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1360
@ WIFI_MOD_CLASS_ERP_OFDM
ERP-OFDM (18.4)
@ OFDM_PHY_DEFAULT
Definition: ofdm-phy.h:45
class anonymous_namespace{erp-ofdm-phy.cc}::ConstructorErpOfdm g_constructor_erp_ofdm
the constructor for ERP-OFDM modes
Every class exported by the ns3 library is enclosed in the ns3 namespace.
const uint16_t WIFI_CODE_RATE_3_4
3/4 coding rate
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:707
const std::array< uint64_t, 8 > & GetErpOfdmRatesBpsList()
Get the array of possible ERP OFDM rates.
Definition: erp-ofdm-phy.cc:69
const uint16_t WIFI_CODE_RATE_1_2
1/2 coding rate
const uint16_t WIFI_CODE_RATE_2_3
2/3 coding rate
uint16_t WifiCodeRate
These constants define the various convolutional coding rates used for the OFDM transmission modes in...
static const std::array< uint64_t, 8 > s_erpOfdmRatesBpsList
ERP OFDM rates in bits per second.
Definition: erp-ofdm-phy.cc:57