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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Rediet <getachew.redieteab@orange.com>
7 * Sébastien Deronne <sebastien.deronne@gmail.com> (for logic ported from wifi-phy)
8 * Mathieu Lacage <mathieu.lacage@sophia.inria.fr> (for logic ported from wifi-phy)
9 */
10
11#include "erp-ofdm-phy.h"
12
13#include "erp-ofdm-ppdu.h"
14
15#include "ns3/assert.h"
16#include "ns3/log.h"
17#include "ns3/wifi-phy.h" //only used for static mode constructor
18#include "ns3/wifi-psdu.h"
19
20#include <array>
21
22#undef NS_LOG_APPEND_CONTEXT
23#define NS_LOG_APPEND_CONTEXT WIFI_PHY_NS_LOG_APPEND_CONTEXT(m_wifiPhy)
24
25namespace ns3
26{
27
28NS_LOG_COMPONENT_DEFINE("ErpOfdmPhy");
29
30/*******************************************************
31 * ERP-OFDM PHY (IEEE 802.11-2016, clause 18)
32 *******************************************************/
33
34// clang-format off
35
37 // Unique name Code rate Constellation size
38 { "ErpOfdmRate6Mbps", { WIFI_CODE_RATE_1_2, 2 } },
39 { "ErpOfdmRate9Mbps", { WIFI_CODE_RATE_3_4, 2 } },
40 { "ErpOfdmRate12Mbps", { WIFI_CODE_RATE_1_2, 4 } },
41 { "ErpOfdmRate18Mbps", { WIFI_CODE_RATE_3_4, 4 } },
42 { "ErpOfdmRate24Mbps", { WIFI_CODE_RATE_1_2, 16 } },
43 { "ErpOfdmRate36Mbps", { WIFI_CODE_RATE_3_4, 16 } },
44 { "ErpOfdmRate48Mbps", { WIFI_CODE_RATE_2_3, 64 } },
45 { "ErpOfdmRate54Mbps", { WIFI_CODE_RATE_3_4, 64 } }
46};
47
48/// ERP OFDM rates in bits per second
49static const std::array<uint64_t, 8> s_erpOfdmRatesBpsList =
50 { 6000000, 9000000, 12000000, 18000000,
51 24000000, 36000000, 48000000, 54000000};
52
53// clang-format on
54
55/**
56 * Get the array of possible ERP OFDM rates.
57 *
58 * \return the ERP OFDM rates in bits per second
59 */
60const std::array<uint64_t, 8>&
65
67 : OfdmPhy(OFDM_PHY_DEFAULT, false) // don't add OFDM modes to list
68{
69 NS_LOG_FUNCTION(this);
70 for (const auto& rate : GetErpOfdmRatesBpsList())
71 {
72 WifiMode mode = GetErpOfdmRate(rate);
73 NS_LOG_LOGIC("Add " << mode << " to list");
74 m_modeList.emplace_back(mode);
75 }
76}
77
82
89
90Time
92{
93 return MicroSeconds(16); // L-STF + L-LTF
94}
95
96Time
97ErpOfdmPhy::GetHeaderDuration(const WifiTxVector& /* txVector */) const
98{
99 return MicroSeconds(4); // L-SIG
100}
101
104 const WifiTxVector& txVector,
105 Time /* ppduDuration */)
106{
107 NS_LOG_FUNCTION(this << psdus << txVector);
108 return Create<ErpOfdmPpdu>(
109 psdus.begin()->second,
110 txVector,
112 m_wifiPhy->GetLatestPhyEntity()->ObtainNextUid(
113 txVector)); // use latest PHY entity to handle MU-RTS sent with non-HT rate
114}
115
116void
118{
119 for (const auto& rate : GetErpOfdmRatesBpsList())
120 {
121 GetErpOfdmRate(rate);
122 }
123}
124
127{
128 switch (rate)
129 {
130 case 6000000:
131 return GetErpOfdmRate6Mbps();
132 case 9000000:
133 return GetErpOfdmRate9Mbps();
134 case 12000000:
135 return GetErpOfdmRate12Mbps();
136 case 18000000:
137 return GetErpOfdmRate18Mbps();
138 case 24000000:
139 return GetErpOfdmRate24Mbps();
140 case 36000000:
141 return GetErpOfdmRate36Mbps();
142 case 48000000:
143 return GetErpOfdmRate48Mbps();
144 case 54000000:
145 return GetErpOfdmRate54Mbps();
146 default:
147 NS_ABORT_MSG("Inexistent rate (" << rate << " bps) requested for ERP-OFDM");
148 return WifiMode();
149 }
150}
151
152#define GET_ERP_OFDM_MODE(x, f) \
153 WifiMode ErpOfdmPhy::Get##x() \
154 { \
155 static WifiMode mode = CreateErpOfdmMode(#x, f); \
156 return mode; \
157 }
158
159GET_ERP_OFDM_MODE(ErpOfdmRate6Mbps, true)
160GET_ERP_OFDM_MODE(ErpOfdmRate9Mbps, false)
161GET_ERP_OFDM_MODE(ErpOfdmRate12Mbps, true)
162GET_ERP_OFDM_MODE(ErpOfdmRate18Mbps, false)
163GET_ERP_OFDM_MODE(ErpOfdmRate24Mbps, true)
164GET_ERP_OFDM_MODE(ErpOfdmRate36Mbps, false)
165GET_ERP_OFDM_MODE(ErpOfdmRate48Mbps, false)
166GET_ERP_OFDM_MODE(ErpOfdmRate54Mbps, false)
167#undef GET_ERP_OFDM_MODE
168
169WifiMode
170ErpOfdmPhy::CreateErpOfdmMode(std::string uniqueName, bool isMandatory)
171{
172 // Check whether uniqueName is in lookup table
173 const auto it = m_erpOfdmModulationLookupTable.find(uniqueName);
175 "ERP-OFDM mode cannot be created because it is not in the lookup table!");
176
177 return WifiModeFactory::CreateWifiMode(uniqueName,
179 isMandatory,
180 MakeBoundCallback(&GetCodeRate, uniqueName),
185}
186
188ErpOfdmPhy::GetCodeRate(const std::string& name)
189{
190 return m_erpOfdmModulationLookupTable.at(name).first;
191}
192
193uint16_t
194ErpOfdmPhy::GetConstellationSize(const std::string& name)
195{
196 return m_erpOfdmModulationLookupTable.at(name).second;
197}
198
199uint64_t
200ErpOfdmPhy::GetPhyRate(const std::string& name, MHz_u channelWidth)
201{
202 WifiCodeRate codeRate = GetCodeRate(name);
203 uint16_t constellationSize = GetConstellationSize(name);
204 uint64_t dataRate = OfdmPhy::CalculateDataRate(codeRate, constellationSize, channelWidth);
205 return OfdmPhy::CalculatePhyRate(codeRate, dataRate);
206}
207
208uint64_t
209ErpOfdmPhy::GetPhyRateFromTxVector(const WifiTxVector& txVector, uint16_t /* staId */)
210{
211 return GetPhyRate(txVector.GetMode().GetUniqueName(), txVector.GetChannelWidth());
212}
213
214uint64_t
215ErpOfdmPhy::GetDataRateFromTxVector(const WifiTxVector& txVector, uint16_t /* staId */)
216{
217 return GetDataRate(txVector.GetMode().GetUniqueName(), txVector.GetChannelWidth());
218}
219
220uint64_t
221ErpOfdmPhy::GetDataRate(const std::string& name, MHz_u channelWidth)
222{
223 WifiCodeRate codeRate = GetCodeRate(name);
224 uint16_t constellationSize = GetConstellationSize(name);
225 return OfdmPhy::CalculateDataRate(codeRate, constellationSize, channelWidth);
226}
227
228bool
230{
231 return true;
232}
233
236{
237 return 4095;
238}
239
240} // namespace ns3
241
242namespace
243{
244
245/**
246 * Constructor class for ERP-OFDM modes
247 */
258
259} // namespace
~ErpOfdmPhy() override
Destructor for ERP-OFDM PHY.
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...
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
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 WifiMode GetErpOfdmRate(uint64_t rate)
Return a WifiMode for ERP-OFDM corresponding to the provided rate.
static uint64_t GetPhyRate(const std::string &name, MHz_u channelWidth)
Return the PHY rate from the ERP-OFDM mode's unique name and the supplied parameters.
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.
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 uint64_t GetDataRate(const std::string &name, MHz_u channelWidth)
Return the data rate from the ERP-OFDM mode's unique name and the supplied parameters.
static WifiMode GetErpOfdmRate54Mbps()
Return a WifiMode for ERP-OFDM at 54 Mbps.
WifiMode GetHeaderMode(const WifiTxVector &txVector) const override
static WifiMode GetErpOfdmRate36Mbps()
Return a WifiMode for ERP-OFDM at 36 Mbps.
PHY entity for OFDM (11a)
Definition ofdm-phy.h:50
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:561
static uint64_t CalculateDataRate(WifiCodeRate codeRate, uint16_t constellationSize, MHz_u channelWidth)
Calculates data rate from the supplied parameters.
Definition ofdm-phy.cc:605
Ptr< WifiPhy > m_wifiPhy
Pointer to the owning WifiPhy.
Definition phy-entity.h:939
std::map< std::string, CodeRateConstellationSizePair > ModulationLookupTable
A modulation lookup table using unique name of modulation as key.
Definition phy-entity.h:539
std::list< WifiMode > m_modeList
the list of supported modes
Definition phy-entity.h:943
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
static WifiMode CreateWifiMode(std::string uniqueName, WifiModulationClass modClass, bool isMandatory, CodeRateCallback codeRateCallback, ConstellationSizeCallback constellationSizeCallback, PhyRateCallback phyRateCallback, DataRateCallback dataRateCallback, AllowedCallback isAllowedCallback)
Definition wifi-mode.cc:259
represent a single transmission mode
Definition wifi-mode.h:40
const std::string & GetUniqueName() const
Definition wifi-mode.cc:137
WifiModulationClass GetModulationClass() const
Definition wifi-mode.cc:174
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:795
const WifiPhyOperatingChannel & GetOperatingChannel() const
Get a const reference to the operating channel.
Definition wifi-phy.cc:1075
Ptr< PhyEntity > GetLatestPhyEntity() const
Get the latest PHY entity supported by this PHY instance.
Definition wifi-phy.cc:769
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.
MHz_u 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: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_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition abort.h:38
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#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:745
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1332
@ WIFI_MOD_CLASS_ERP_OFDM
ERP-OFDM (18.4)
@ OFDM_PHY_DEFAULT
Definition ofdm-phy.h:34
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.
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:684
const std::array< uint64_t, 8 > & GetErpOfdmRatesBpsList()
Get the array of possible ERP OFDM rates.
static const std::array< uint64_t, 8 > s_erpOfdmRatesBpsList
ERP OFDM rates in bits per second.
WifiCodeRate
These constants define the various convolutional coding rates used for the OFDM transmission modes in...
@ WIFI_CODE_RATE_2_3
2/3 coding rate
@ WIFI_CODE_RATE_1_2
1/2 coding rate
@ WIFI_CODE_RATE_3_4
3/4 coding rate