A Discrete-Event Network Simulator
API
erp-ofdm-phy.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2020 Orange Labs
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  * Authors: Rediet <getachew.redieteab@orange.com>
19  * S├ębastien Deronne <sebastien.deronne@gmail.com> (for logic ported from wifi-phy)
20  * Mathieu Lacage <mathieu.lacage@sophia.inria.fr> (for logic ported from wifi-phy)
21  */
22 
23 #include <array>
24 #include "erp-ofdm-phy.h"
25 #include "erp-ofdm-ppdu.h"
26 #include "ns3/wifi-psdu.h"
27 #include "ns3/wifi-phy.h" //only used for static mode constructor
28 #include "ns3/log.h"
29 #include "ns3/assert.h"
30 
31 namespace ns3 {
32 
33 NS_LOG_COMPONENT_DEFINE ("ErpOfdmPhy");
34 
35 /*******************************************************
36  * ERP-OFDM PHY (IEEE 802.11-2016, clause 18)
37  *******************************************************/
38 
39 /* *NS_CHECK_STYLE_OFF* */
41  // Unique name Code rate Constellation size
42  { "ErpOfdmRate6Mbps", { WIFI_CODE_RATE_1_2, 2 } },
43  { "ErpOfdmRate9Mbps", { WIFI_CODE_RATE_3_4, 2 } },
44  { "ErpOfdmRate12Mbps", { WIFI_CODE_RATE_1_2, 4 } },
45  { "ErpOfdmRate18Mbps", { WIFI_CODE_RATE_3_4, 4 } },
46  { "ErpOfdmRate24Mbps", { WIFI_CODE_RATE_1_2, 16 } },
47  { "ErpOfdmRate36Mbps", { WIFI_CODE_RATE_3_4, 16 } },
48  { "ErpOfdmRate48Mbps", { WIFI_CODE_RATE_2_3, 64 } },
49  { "ErpOfdmRate54Mbps", { WIFI_CODE_RATE_3_4, 64 } }
50 };
51 
53 static const std::array<uint64_t, 8> s_erpOfdmRatesBpsList =
54  { 6000000, 9000000, 12000000, 18000000,
55  24000000, 36000000, 48000000, 54000000};
56 
57 /* *NS_CHECK_STYLE_ON* */
58 
64 const std::array<uint64_t, 8>& GetErpOfdmRatesBpsList (void)
65 {
66  return s_erpOfdmRatesBpsList;
67 };
68 
70  : OfdmPhy (OFDM_PHY_DEFAULT, false) //don't add OFDM modes to list
71 {
72  NS_LOG_FUNCTION (this);
73  for (const auto & rate : GetErpOfdmRatesBpsList ())
74  {
75  WifiMode mode = GetErpOfdmRate (rate);
76  NS_LOG_LOGIC ("Add " << mode << " to list");
77  m_modeList.emplace_back (mode);
78  }
79 }
80 
82 {
83  NS_LOG_FUNCTION (this);
84 }
85 
87 ErpOfdmPhy::GetHeaderMode (const WifiTxVector& txVector) const
88 {
90  return GetErpOfdmRate6Mbps ();
91 }
92 
93 Time
94 ErpOfdmPhy::GetPreambleDuration (const WifiTxVector& /* txVector */) const
95 {
96  return MicroSeconds (16); //L-STF + L-LTF
97 }
98 
99 Time
100 ErpOfdmPhy::GetHeaderDuration (const WifiTxVector& /* txVector */) const
101 {
102  return MicroSeconds (4); //L-SIG
103 }
104 
106 ErpOfdmPhy::BuildPpdu (const WifiConstPsduMap & psdus, const WifiTxVector& txVector, Time /* ppduDuration */)
107 {
108  NS_LOG_FUNCTION (this << psdus << txVector);
109  return Create<ErpOfdmPpdu> (psdus.begin ()->second, txVector, m_wifiPhy->GetPhyBand (),
110  ObtainNextUid (txVector));
111 }
112 
113 void
115 {
116  for (const auto & rate : GetErpOfdmRatesBpsList ())
117  {
118  GetErpOfdmRate (rate);
119  }
120 }
121 
122 WifiMode
124 {
125  switch (rate)
126  {
127  case 6000000:
128  return GetErpOfdmRate6Mbps ();
129  case 9000000:
130  return GetErpOfdmRate9Mbps ();
131  case 12000000:
132  return GetErpOfdmRate12Mbps ();
133  case 18000000:
134  return GetErpOfdmRate18Mbps ();
135  case 24000000:
136  return GetErpOfdmRate24Mbps ();
137  case 36000000:
138  return GetErpOfdmRate36Mbps ();
139  case 48000000:
140  return GetErpOfdmRate48Mbps ();
141  case 54000000:
142  return GetErpOfdmRate54Mbps ();
143  default:
144  NS_ABORT_MSG ("Inexistent rate (" << rate << " bps) requested for ERP-OFDM");
145  return WifiMode ();
146  }
147 }
148 
149 #define GET_ERP_OFDM_MODE(x, f) \
150 WifiMode \
151 ErpOfdmPhy::Get ## x (void) \
152 { \
153  static WifiMode mode = CreateErpOfdmMode (#x, f); \
154  return mode; \
155 }; \
156 
157 GET_ERP_OFDM_MODE (ErpOfdmRate6Mbps, true)
158 GET_ERP_OFDM_MODE (ErpOfdmRate9Mbps, false)
159 GET_ERP_OFDM_MODE (ErpOfdmRate12Mbps, true)
160 GET_ERP_OFDM_MODE (ErpOfdmRate18Mbps, false)
161 GET_ERP_OFDM_MODE (ErpOfdmRate24Mbps, true)
162 GET_ERP_OFDM_MODE (ErpOfdmRate36Mbps, false)
163 GET_ERP_OFDM_MODE (ErpOfdmRate48Mbps, false)
164 GET_ERP_OFDM_MODE (ErpOfdmRate54Mbps, false)
165 #undef GET_ERP_OFDM_MODE
166 
167 WifiMode
168 ErpOfdmPhy::CreateErpOfdmMode (std::string uniqueName, bool isMandatory)
169 {
170  // Check whether uniqueName is in lookup table
171  const auto it = m_erpOfdmModulationLookupTable.find (uniqueName);
172  NS_ASSERT_MSG (it != m_erpOfdmModulationLookupTable.end (), "ERP-OFDM mode cannot be created because it is not in the lookup table!");
173 
174  return WifiModeFactory::CreateWifiMode (uniqueName,
176  isMandatory,
177  MakeBoundCallback (&GetCodeRate, uniqueName),
179  MakeBoundCallback (&GetPhyRate, uniqueName),
181  MakeBoundCallback (&GetDataRate, uniqueName),
184 }
185 
187 ErpOfdmPhy::GetCodeRate (const std::string& name)
188 {
189  return m_erpOfdmModulationLookupTable.at (name).first;
190 }
191 
192 uint16_t
193 ErpOfdmPhy::GetConstellationSize (const std::string& name)
194 {
195  return m_erpOfdmModulationLookupTable.at (name).second;
196 }
197 
198 uint64_t
199 ErpOfdmPhy::GetPhyRate (const std::string& name, uint16_t channelWidth, uint16_t guardInterval, uint8_t nss)
200 {
201  WifiCodeRate codeRate = GetCodeRate (name);
202  uint16_t constellationSize = GetConstellationSize (name);
203  uint64_t dataRate = OfdmPhy::CalculateDataRate (codeRate, constellationSize, channelWidth, guardInterval, nss);
204  return OfdmPhy::CalculatePhyRate (codeRate, dataRate);
205 }
206 
207 uint64_t
208 ErpOfdmPhy::GetPhyRateFromTxVector (const WifiTxVector& txVector, uint16_t /* staId */)
209 {
210  return GetPhyRate (txVector.GetMode ().GetUniqueName (),
211  txVector.GetChannelWidth (),
212  txVector.GetGuardInterval (),
213  txVector.GetNss ());
214 }
215 
216 uint64_t
217 ErpOfdmPhy::GetDataRateFromTxVector (const WifiTxVector& txVector, uint16_t /* staId */)
218 {
219  return GetDataRate (txVector.GetMode ().GetUniqueName (),
220  txVector.GetChannelWidth (),
221  txVector.GetGuardInterval (),
222  txVector.GetNss ());
223 }
224 
225 uint64_t
226 ErpOfdmPhy::GetDataRate (const std::string& name, uint16_t channelWidth, uint16_t guardInterval, uint8_t nss)
227 {
228  WifiCodeRate codeRate = GetCodeRate (name);
229  uint16_t constellationSize = GetConstellationSize (name);
230  return OfdmPhy::CalculateDataRate (codeRate, constellationSize, channelWidth, guardInterval, nss);
231 }
232 
233 bool
234 ErpOfdmPhy::IsModeAllowed (uint16_t /* channelWidth */, uint8_t /* nss */)
235 {
236  return true;
237 }
238 
239 uint32_t
241 {
242  return 4095;
243 }
244 
245 } //namespace ns3
246 
247 namespace {
248 
252 static class ConstructorErpOfdm
253 {
254 public:
256  {
258  ns3::WifiPhy::AddStaticPhyEntity (ns3::WIFI_MOD_CLASS_ERP_OFDM, ns3::Create<ns3::ErpOfdmPhy> ());
259  }
261 
262 }
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
NS_ASSERT
#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
erp-ofdm-ppdu.h
Declaration of ns3::ErpOfdmPpdu class.
ns3::WIFI_MOD_CLASS_ERP_OFDM
@ WIFI_MOD_CLASS_ERP_OFDM
ERP-OFDM (18.4)
Definition: wifi-phy-common.h:128
ns3::ErpOfdmPhy::GetConstellationSize
static uint16_t GetConstellationSize(const std::string &name)
Return the constellation size from the ERP-OFDM mode's unique name using ModulationLookupTable.
Definition: erp-ofdm-phy.cc:193
ns3::ErpOfdmPhy::GetPreambleDuration
Time GetPreambleDuration(const WifiTxVector &txVector) const override
Definition: erp-ofdm-phy.cc:94
ns3::PhyEntity::m_modeList
std::list< WifiMode > m_modeList
the list of supported modes
Definition: phy-entity.h:786
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::OfdmPhy::CalculatePhyRate
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:523
ns3::MicroSeconds
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1305
ns3::ErpOfdmPhy::GetErpOfdmRate36Mbps
static WifiMode GetErpOfdmRate36Mbps(void)
Return a WifiMode for ERP-OFDM at 36 Mbps.
anonymous_namespace{erp-ofdm-phy.cc}::ConstructorErpOfdm::ConstructorErpOfdm
ConstructorErpOfdm()
Definition: erp-ofdm-phy.cc:255
ns3::ErpOfdmPhy::GetHeaderDuration
Time GetHeaderDuration(const WifiTxVector &txVector) const override
Definition: erp-ofdm-phy.cc:100
ns3::WifiMode::GetModulationClass
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:159
anonymous_namespace{erp-ofdm-phy.cc}::ConstructorErpOfdm
Constructor class for ERP-OFDM modes.
Definition: erp-ofdm-phy.cc:253
ns3::ErpOfdmPhy::GetErpOfdmRate48Mbps
static WifiMode GetErpOfdmRate48Mbps(void)
Return a WifiMode for ERP-OFDM at 48 Mbps.
ns3::ErpOfdmPhy::GetErpOfdmRate24Mbps
static WifiMode GetErpOfdmRate24Mbps(void)
Return a WifiMode for ERP-OFDM at 24 Mbps.
ns3::WifiTxVector
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
Definition: wifi-tx-vector.h:71
ns3::WifiConstPsduMap
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
Definition: he-frame-exchange-manager.h:43
ns3::WifiPhy::AddStaticPhyEntity
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:886
ns3::ErpOfdmPhy::GetPhyRate
static uint64_t GetPhyRate(const std::string &name, uint16_t channelWidth, uint16_t guardInterval, uint8_t nss)
Return the PHY rate from the ERP-OFDM mode's unique name and the supplied parameters.
Definition: erp-ofdm-phy.cc:199
ns3::s_erpOfdmRatesBpsList
static const std::array< uint64_t, 8 > s_erpOfdmRatesBpsList
ERP OFDM rates in bits per second.
Definition: erp-ofdm-phy.cc:53
ns3::ErpOfdmPhy::GetCodeRate
static WifiCodeRate GetCodeRate(const std::string &name)
Return the WifiCodeRate from the ERP-OFDM mode's unique name using ModulationLookupTable.
Definition: erp-ofdm-phy.cc:187
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::WifiCodeRate
uint16_t WifiCodeRate
These constants define the various convolutional coding rates used for the OFDM transmission modes in...
Definition: wifi-phy-common.h:45
ns3::ErpOfdmPhy::ErpOfdmPhy
ErpOfdmPhy()
Constructor for ERP-OFDM PHY.
Definition: erp-ofdm-phy.cc:69
ns3::WifiMode
represent a single transmission mode
Definition: wifi-mode.h:48
ns3::ErpOfdmPhy::GetErpOfdmRate
static WifiMode GetErpOfdmRate(uint64_t rate)
Return a WifiMode for ERP-OFDM corresponding to the provided rate.
Definition: erp-ofdm-phy.cc:123
ns3::WifiModeFactory::CreateWifiMode
static WifiMode CreateWifiMode(std::string uniqueName, WifiModulationClass modClass, bool isMandatory, CodeRateCallback codeRateCallback, ConstellationSizeCallback constellationSizeCallback, PhyRateCallback phyRateCallback, PhyRateFromTxVectorCallback phyRateFromTxVectorCallback, DataRateCallback dataRateCallback, DataRateFromTxVectorCallback dataRateFromTxVectorCallback, ModeAllowedCallback isModeAllowedCallback)
Definition: wifi-mode.cc:242
ns3::ErpOfdmPhy::~ErpOfdmPhy
virtual ~ErpOfdmPhy()
Destructor for ERP-OFDM PHY.
Definition: erp-ofdm-phy.cc:81
ns3::ErpOfdmPhy::InitializeModes
static void InitializeModes(void)
Initialize all ERP-OFDM modes.
Definition: erp-ofdm-phy.cc:114
ns3::PhyEntity::m_wifiPhy
Ptr< WifiPhy > m_wifiPhy
Pointer to the owning WifiPhy.
Definition: phy-entity.h:783
ns3::WIFI_CODE_RATE_2_3
const uint16_t WIFI_CODE_RATE_2_3
2/3 coding rate
Definition: wifi-phy-common.h:59
ns3::ErpOfdmPhy::GetHeaderMode
WifiMode GetHeaderMode(const WifiTxVector &txVector) const override
Definition: erp-ofdm-phy.cc:87
ns3::WifiMode::GetUniqueName
std::string GetUniqueName(void) const
Definition: wifi-mode.cc:122
ns3::WifiPhy::GetPhyBand
WifiPhyBand GetPhyBand(void) const
Get the configured Wi-Fi band.
Definition: wifi-phy.cc:1124
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::ErpOfdmPhy::GetErpOfdmRate54Mbps
static WifiMode GetErpOfdmRate54Mbps(void)
Return a WifiMode for ERP-OFDM at 54 Mbps.
NS_ASSERT_MSG
#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
ns3::WifiTxVector::GetChannelWidth
uint16_t GetChannelWidth(void) const
Definition: wifi-tx-vector.cc:154
ns3::ErpOfdmPhy::CreateErpOfdmMode
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...
Definition: erp-ofdm-phy.cc:168
ns3::ErpOfdmPhy::GetErpOfdmRate6Mbps
static WifiMode GetErpOfdmRate6Mbps(void)
Return a WifiMode for ERP-OFDM at 6 Mbps.
ns3::ErpOfdmPhy::GetErpOfdmRate9Mbps
static WifiMode GetErpOfdmRate9Mbps(void)
Return a WifiMode for ERP-OFDM at 9 Mbps.
ns3::OfdmPhy
PHY entity for OFDM (11a)
Definition: ofdm-phy.h:61
ns3::MakeCallback
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1642
NS_LOG_LOGIC
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
ns3::WIFI_CODE_RATE_1_2
const uint16_t WIFI_CODE_RATE_1_2
1/2 coding rate
Definition: wifi-phy-common.h:58
ns3::ErpOfdmPhy::BuildPpdu
Ptr< WifiPpdu > BuildPpdu(const WifiConstPsduMap &psdus, const WifiTxVector &txVector, Time ppduDuration) override
Build amendment-specific PPDU.
Definition: erp-ofdm-phy.cc:106
ns3::ErpOfdmPhy::GetDataRate
static uint64_t GetDataRate(const std::string &name, uint16_t channelWidth, uint16_t guardInterval, uint8_t nss)
Return the data rate from the ERP-OFDM mode's unique name and the supplied parameters.
Definition: erp-ofdm-phy.cc:226
ns3::ErpOfdmPhy::GetPhyRateFromTxVector
static uint64_t GetPhyRateFromTxVector(const WifiTxVector &txVector, uint16_t staId)
Return the PHY rate corresponding to the supplied TXVECTOR.
Definition: erp-ofdm-phy.cc:208
ns3::WifiTxVector::GetGuardInterval
uint16_t GetGuardInterval(void) const
Definition: wifi-tx-vector.cc:160
ns3::OfdmPhy::CalculateDataRate
static uint64_t CalculateDataRate(WifiCodeRate codeRate, uint16_t constellationSize, uint16_t channelWidth, uint16_t guardInterval, uint8_t nss)
Calculates data rate from the supplied parameters.
Definition: ofdm-phy.cc:573
ns3::ErpOfdmPhy::GetDataRateFromTxVector
static uint64_t GetDataRateFromTxVector(const WifiTxVector &txVector, uint16_t staId)
Return the data rate corresponding to the supplied TXVECTOR.
Definition: erp-ofdm-phy.cc:217
ns3::WifiTxVector::GetNss
uint8_t GetNss(uint16_t staId=SU_STA_ID) const
If this TX vector is associated with an SU PPDU, return the number of spatial streams.
Definition: wifi-tx-vector.cc:172
ns3::ErpOfdmPhy::GetMaxPsduSize
uint32_t GetMaxPsduSize(void) const override
Get the maximum PSDU size in bytes.
Definition: erp-ofdm-phy.cc:240
GET_ERP_OFDM_MODE
#define GET_ERP_OFDM_MODE(x, f)
Definition: erp-ofdm-phy.cc:149
ns3::MakeBoundCallback
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
Definition: callback.h:1703
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
ns3::PhyEntity::ModulationLookupTable
std::map< std::string, CodeRateConstellationSizePair > ModulationLookupTable
A modulation lookup table using unique name of modulation as key.
Definition: phy-entity.h:487
ns3::ErpOfdmPhy::IsModeAllowed
static bool IsModeAllowed(uint16_t channelWidth, uint8_t nss)
Check whether the combination of <WifiMode, channel width, NSS> is allowed.
Definition: erp-ofdm-phy.cc:234
ns3::OFDM_PHY_DEFAULT
@ OFDM_PHY_DEFAULT
Definition: ofdm-phy.h:45
anonymous_namespace{erp-ofdm-phy.cc}::g_constructor_erp_ofdm
static class anonymous_namespace{erp-ofdm-phy.cc}::ConstructorErpOfdm g_constructor_erp_ofdm
the constructor for ERP-OFDM modes
ns3::WIFI_CODE_RATE_3_4
const uint16_t WIFI_CODE_RATE_3_4
3/4 coding rate
Definition: wifi-phy-common.h:60
ns3::GetErpOfdmRatesBpsList
const std::array< uint64_t, 8 > & GetErpOfdmRatesBpsList(void)
Get the array of possible ERP OFDM rates.
Definition: erp-ofdm-phy.cc:64
ns3::ErpOfdmPhy::GetErpOfdmRate18Mbps
static WifiMode GetErpOfdmRate18Mbps(void)
Return a WifiMode for ERP-OFDM at 18 Mbps.
ns3::WifiTxVector::GetMode
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.
Definition: wifi-tx-vector.cc:112
ns3::ErpOfdmPhy::GetErpOfdmRate12Mbps
static WifiMode GetErpOfdmRate12Mbps(void)
Return a WifiMode for ERP-OFDM at 12 Mbps.
ns3::PhyEntity::ObtainNextUid
virtual uint64_t ObtainNextUid(const WifiTxVector &txVector)
Obtain the next UID for the PPDU to transmit.
Definition: phy-entity.cc:1019
erp-ofdm-phy.h
Declaration of ns3::ErpOfdmPhy class.
NS_ABORT_MSG
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:50
ns3::ErpOfdmPhy::m_erpOfdmModulationLookupTable
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:215