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 
52 // ERP OFDM rates in bits per second
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 
59 const std::array<uint64_t, 8>& GetErpOfdmRatesBpsList (void)
60 {
61  return s_erpOfdmRatesBpsList;
62 };
63 
65  : OfdmPhy (OFDM_PHY_DEFAULT, false) //don't add OFDM modes to list
66 {
67  NS_LOG_FUNCTION (this);
68  for (const auto & rate : GetErpOfdmRatesBpsList ())
69  {
70  WifiMode mode = GetErpOfdmRate (rate);
71  NS_LOG_LOGIC ("Add " << mode << " to list");
72  m_modeList.emplace_back (mode);
73  }
74 }
75 
77 {
78  NS_LOG_FUNCTION (this);
79 }
80 
82 ErpOfdmPhy::GetHeaderMode (const WifiTxVector& txVector) const
83 {
85  return GetErpOfdmRate6Mbps ();
86 }
87 
88 Time
89 ErpOfdmPhy::GetPreambleDuration (const WifiTxVector& /* txVector */) const
90 {
91  return MicroSeconds (16); //L-STF + L-LTF
92 }
93 
94 Time
95 ErpOfdmPhy::GetHeaderDuration (const WifiTxVector& /* txVector */) const
96 {
97  return MicroSeconds (4); //L-SIG
98 }
99 
101 ErpOfdmPhy::BuildPpdu (const WifiConstPsduMap & psdus, const WifiTxVector& txVector, Time /* ppduDuration */)
102 {
103  NS_LOG_FUNCTION (this << psdus << txVector);
104  return Create<ErpOfdmPpdu> (psdus.begin ()->second, txVector, m_wifiPhy->GetPhyBand (),
105  ObtainNextUid (txVector));
106 }
107 
108 void
110 {
111  for (const auto & rate : GetErpOfdmRatesBpsList ())
112  {
113  GetErpOfdmRate (rate);
114  }
115 }
116 
117 WifiMode
119 {
120  switch (rate)
121  {
122  case 6000000:
123  return GetErpOfdmRate6Mbps ();
124  case 9000000:
125  return GetErpOfdmRate9Mbps ();
126  case 12000000:
127  return GetErpOfdmRate12Mbps ();
128  case 18000000:
129  return GetErpOfdmRate18Mbps ();
130  case 24000000:
131  return GetErpOfdmRate24Mbps ();
132  case 36000000:
133  return GetErpOfdmRate36Mbps ();
134  case 48000000:
135  return GetErpOfdmRate48Mbps ();
136  case 54000000:
137  return GetErpOfdmRate54Mbps ();
138  default:
139  NS_ABORT_MSG ("Inexistent rate (" << rate << " bps) requested for ERP-OFDM");
140  return WifiMode ();
141  }
142 }
143 
144 #define GET_ERP_OFDM_MODE(x, f) \
145 WifiMode \
146 ErpOfdmPhy::Get ## x (void) \
147 { \
148  static WifiMode mode = CreateErpOfdmMode (#x, f); \
149  return mode; \
150 } \
151 
152 GET_ERP_OFDM_MODE (ErpOfdmRate6Mbps, true );
153 GET_ERP_OFDM_MODE (ErpOfdmRate9Mbps, false);
154 GET_ERP_OFDM_MODE (ErpOfdmRate12Mbps, true );
155 GET_ERP_OFDM_MODE (ErpOfdmRate18Mbps, false);
156 GET_ERP_OFDM_MODE (ErpOfdmRate24Mbps, true );
157 GET_ERP_OFDM_MODE (ErpOfdmRate36Mbps, false);
158 GET_ERP_OFDM_MODE (ErpOfdmRate48Mbps, false);
159 GET_ERP_OFDM_MODE (ErpOfdmRate54Mbps, false);
160 #undef GET_ERP_OFDM_MODE
161 
162 WifiMode
163 ErpOfdmPhy::CreateErpOfdmMode (std::string uniqueName, bool isMandatory)
164 {
165  // Check whether uniqueName is in lookup table
166  const auto it = m_erpOfdmModulationLookupTable.find (uniqueName);
167  NS_ASSERT_MSG (it != m_erpOfdmModulationLookupTable.end (), "ERP-OFDM mode cannot be created because it is not in the lookup table!");
168 
169  return WifiModeFactory::CreateWifiMode (uniqueName,
171  isMandatory,
172  MakeBoundCallback (&GetCodeRate, uniqueName),
174  MakeBoundCallback (&GetPhyRate, uniqueName),
176  MakeBoundCallback (&GetDataRate, uniqueName),
179 }
180 
182 ErpOfdmPhy::GetCodeRate (const std::string& name)
183 {
184  return m_erpOfdmModulationLookupTable.at (name).first;
185 }
186 
187 uint16_t
188 ErpOfdmPhy::GetConstellationSize (const std::string& name)
189 {
190  return m_erpOfdmModulationLookupTable.at (name).second;
191 }
192 
193 uint64_t
194 ErpOfdmPhy::GetPhyRate (const std::string& name, uint16_t channelWidth, uint16_t guardInterval, uint8_t nss)
195 {
196  WifiCodeRate codeRate = GetCodeRate (name);
197  uint16_t constellationSize = GetConstellationSize (name);
198  uint64_t dataRate = OfdmPhy::CalculateDataRate (codeRate, constellationSize, channelWidth, guardInterval, nss);
199  return OfdmPhy::CalculatePhyRate (codeRate, dataRate);
200 }
201 
202 uint64_t
203 ErpOfdmPhy::GetPhyRateFromTxVector (const WifiTxVector& txVector, uint16_t /* staId */)
204 {
205  return GetPhyRate (txVector.GetMode ().GetUniqueName (),
206  txVector.GetChannelWidth (),
207  txVector.GetGuardInterval (),
208  txVector.GetNss ());
209 }
210 
211 uint64_t
212 ErpOfdmPhy::GetDataRateFromTxVector (const WifiTxVector& txVector, uint16_t /* staId */)
213 {
214  return GetDataRate (txVector.GetMode ().GetUniqueName (),
215  txVector.GetChannelWidth (),
216  txVector.GetGuardInterval (),
217  txVector.GetNss ());
218 }
219 
220 uint64_t
221 ErpOfdmPhy::GetDataRate (const std::string& name, uint16_t channelWidth, uint16_t guardInterval, uint8_t nss)
222 {
223  WifiCodeRate codeRate = GetCodeRate (name);
224  uint16_t constellationSize = GetConstellationSize (name);
225  return OfdmPhy::CalculateDataRate (codeRate, constellationSize, channelWidth, guardInterval, nss);
226 }
227 
228 bool
229 ErpOfdmPhy::IsModeAllowed (uint16_t /* channelWidth */, uint8_t /* nss */)
230 {
231  return true;
232 }
233 
234 uint32_t
236 {
237  return 4095;
238 }
239 
240 } //namespace ns3
241 
242 namespace {
243 
247 static class ConstructorErpOfdm
248 {
249 public:
251  {
253  ns3::WifiPhy::AddStaticPhyEntity (ns3::WIFI_MOD_CLASS_ERP_OFDM, ns3::Create<ns3::ErpOfdmPhy> ());
254  }
256 
257 }
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
Definition: abort.h:50
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
const uint16_t WIFI_CODE_RATE_2_3
std::unordered_map< uint16_t, Ptr< const WifiPsdu > > WifiConstPsduMap
Map of const PSDUs indexed by STA-ID.
Definition: wifi-ppdu.h:38
WifiPhyBand GetPhyBand(void) const
Get the configured Wi-Fi band.
Definition: wifi-phy.cc:1122
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
Definition: callback.h:1703
static uint64_t GetDataRateFromTxVector(const WifiTxVector &txVector, uint16_t staId)
Return the data rate corresponding to the supplied TXVECTOR.
#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_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
static const std::array< uint64_t, 8 > s_erpOfdmRatesBpsList
Definition: erp-ofdm-phy.cc:53
static WifiMode GetErpOfdmRate36Mbps(void)
Return a WifiMode for ERP-OFDM at 36 Mbps.
uint16_t GetGuardInterval(void) const
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.
Time GetPreambleDuration(const WifiTxVector &txVector) const override
Definition: erp-ofdm-phy.cc:89
virtual uint32_t GetMaxPsduSize(void) const override
Get the maximum PSDU size in bytes (see Table 18-5 ERP characteristics of IEEE 802.11-2016)
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:47
std::map< std::string, CodeRateConstellationSizePair > ModulationLookupTable
A modulation lookup table using unique name of modulation as key.
Definition: phy-entity.h:509
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:518
const uint16_t WIFI_CODE_RATE_3_4
ErpOfdmPhy()
Constructor for ERP-OFDM PHY.
Definition: erp-ofdm-phy.cc:64
virtual ~ErpOfdmPhy()
Destructor for ERP-OFDM PHY.
Definition: erp-ofdm-phy.cc:76
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...
static uint16_t GetConstellationSize(const std::string &name)
Return the constellation size from the ERP-OFDM mode&#39;s unique name using ModulationLookupTable.
static bool IsModeAllowed(uint16_t channelWidth, uint8_t nss)
Check whether the combination of <WifiMode, channel width, NSS> is allowed.
static WifiMode GetErpOfdmRate18Mbps(void)
Return a WifiMode for ERP-OFDM at 18 Mbps.
static WifiMode GetErpOfdmRate12Mbps(void)
Return a WifiMode for ERP-OFDM at 12 Mbps.
Ptr< WifiPpdu > BuildPpdu(const WifiConstPsduMap &psdus, const WifiTxVector &txVector, Time ppduDuration) override
Build amendment-specific PPDU.
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&#39;s unique name and the supplied parameters.
virtual uint64_t ObtainNextUid(const WifiTxVector &txVector)
Obtain the next UID for the PPDU to transmit.
Definition: phy-entity.cc:1015
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:159
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:568
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
std::string GetUniqueName(void) const
Definition: wifi-mode.cc:122
uint16_t WifiCodeRate
These constants define the various convolutional coding rates used for the OFDM transmission modes in...
static WifiCodeRate GetCodeRate(const std::string &name)
Return the WifiCodeRate from the ERP-OFDM mode&#39;s unique name using ModulationLookupTable.
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
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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:884
static WifiMode GetErpOfdmRate24Mbps(void)
Return a WifiMode for ERP-OFDM at 24 Mbps.
PHY entity for OFDM (11a)This class is also used for the 10 MHz and 5 MHz bandwidth variants addressi...
Definition: ofdm-phy.h:60
#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
GET_ERP_OFDM_MODE(ErpOfdmRate6Mbps, true)
Constructor class for ERP-OFDM modes.
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&#39;s unique name and the supplied parameters.
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:224
static class anonymous_namespace{erp-ofdm-phy.cc}::ConstructorErpOfdm g_constructor_erp_ofdm
the constructor for ERP-OFDM modes
Time GetHeaderDuration(const WifiTxVector &txVector) const override
Definition: erp-ofdm-phy.cc:95
static WifiMode GetErpOfdmRate54Mbps(void)
Return a WifiMode for ERP-OFDM at 54 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...
Time MicroSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1305
static WifiMode GetErpOfdmRate9Mbps(void)
Return a WifiMode for ERP-OFDM at 9 Mbps.
uint16_t GetChannelWidth(void) const
Declaration of ns3::ErpOfdmPhy class.
WifiMode GetHeaderMode(const WifiTxVector &txVector) const override
Definition: erp-ofdm-phy.cc:82
Declaration of ns3::ErpOfdmPpdu class.
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
static WifiMode GetErpOfdmRate6Mbps(void)
Return a WifiMode for ERP-OFDM at 6 Mbps.
static void InitializeModes(void)
Initialize all ERP-OFDM modes.
static WifiMode GetErpOfdmRate(uint64_t rate)
Return a WifiMode for ERP-OFDM corresponding to the provided rate.
std::list< WifiMode > m_modeList
the list of supported modes
Definition: phy-entity.h:811
Ptr< WifiPhy > m_wifiPhy
Pointer to the owning WifiPhy.
Definition: phy-entity.h:808
const std::array< uint64_t, 8 > & GetErpOfdmRatesBpsList(void)
Definition: erp-ofdm-phy.cc:59
const uint16_t WIFI_CODE_RATE_1_2
static WifiMode GetErpOfdmRate48Mbps(void)
Return a WifiMode for ERP-OFDM at 48 Mbps.