A Discrete-Event Network Simulator
API
table-based-error-rate-model.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2020 University of Washington
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: Rohan Patidar <rpatidar@uw.edu>
19  * Sébastien Deronne <sebastien.deronne@gmail.com>
20  */
21 
22 #include <cmath>
23 #include <algorithm>
24 #include "ns3/log.h"
25 #include "ns3/string.h"
26 #include "ns3/pointer.h"
27 #include "ns3/uinteger.h"
29 #include "wifi-utils.h"
30 #include "wifi-tx-vector.h"
31 #include "ns3/dsss-error-rate-model.h"
32 #include "yans-error-rate-model.h"
33 
34 namespace ns3 {
35 
36 static const double SNR_PRECISION = 2;
37 static const double TABLED_BASED_ERROR_MODEL_PRECISION = 1e-5;
38 
40 
41 NS_LOG_COMPONENT_DEFINE ("TableBasedErrorRateModel");
42 
43 TypeId
45 {
46  static TypeId tid = TypeId ("ns3::TableBasedErrorRateModel")
48  .SetGroupName ("Wifi")
49  .AddConstructor<TableBasedErrorRateModel> ()
50  .AddAttribute ("FallbackErrorRateModel",
51  "Ptr to the fallback error rate model to be used when no matching value is found in a table",
52  PointerValue (CreateObject<YansErrorRateModel> ()),
54  MakePointerChecker <ErrorRateModel> ())
55  .AddAttribute ("SizeThreshold",
56  "Threshold in bytes over which the table for large size frames is used",
57  UintegerValue (400),
59  MakeUintegerChecker<uint64_t> ())
60  ;
61  return tid;
62 }
63 
65 {
66  NS_LOG_FUNCTION (this);
67 }
68 
70 {
71  NS_LOG_FUNCTION (this);
73 }
74 
75 
76 double
77 TableBasedErrorRateModel::RoundSnr (double snr, double precision) const
78 {
79  NS_LOG_FUNCTION (this << snr);
80  double multiplier = std::round (std::pow (10.0, precision));
81  return std::floor (snr * multiplier + 0.5) / multiplier;
82 }
83 
84 uint8_t
86 {
87  uint8_t mcs = 0xff; // Initialize to invalid mcs
89  {
90  if (mode.GetConstellationSize () == 2)
91  {
92  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
93  {
94  mcs = 0;
95  }
96  if (mode.GetCodeRate () == WIFI_CODE_RATE_3_4)
97  {
98  mcs = 1;
99  }
100  }
101  else if (mode.GetConstellationSize () == 4)
102  {
103  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
104  {
105  mcs = 2;
106  }
107  else if (mode.GetCodeRate () == WIFI_CODE_RATE_3_4)
108  {
109  mcs = 3;
110  }
111  }
112  else if (mode.GetConstellationSize () == 16)
113  {
114  if (mode.GetCodeRate () == WIFI_CODE_RATE_1_2)
115  {
116  mcs = 4;
117  }
118  else if (mode.GetCodeRate () == WIFI_CODE_RATE_3_4)
119  {
120  mcs = 5;
121  }
122  }
123  else if (mode.GetConstellationSize () == 64)
124  {
125  if (mode.GetCodeRate () == WIFI_CODE_RATE_2_3)
126  {
127  mcs = 6;
128  }
129  else if (mode.GetCodeRate () == WIFI_CODE_RATE_3_4)
130  {
131  mcs = 7;
132  }
133  }
134  }
135  else if (mode.GetModulationClass () >= WIFI_MOD_CLASS_HT)
136  {
137  mcs = mode.GetMcsValue ();
138  }
139  NS_ABORT_MSG_IF (mcs == 0xff, "Error, MCS value for mode not found");
140  return mcs;
141 }
142 
143 double
144 TableBasedErrorRateModel::DoGetChunkSuccessRate (WifiMode mode, const WifiTxVector& txVector, double snr, uint64_t nbits, uint8_t numRxAntennas, WifiPpduField field, uint16_t staId) const
145 {
146  NS_LOG_FUNCTION (this << mode << txVector << snr << nbits << +numRxAntennas << field << staId);
147  uint64_t size = std::max<uint64_t> (1, (nbits / 8));
148  double roundedSnr = RoundSnr (RatioToDb (snr), SNR_PRECISION);
149  uint8_t mcs = GetMcsForMode (mode);
150  bool ldpc = txVector.IsLdpc ();
151  NS_LOG_FUNCTION (this << +mcs << roundedSnr << size << ldpc);
152 
153  // HT: for mcs greater than 7, use 0 - 7 curves for data rate
154  if (mode.GetModulationClass () == WIFI_MOD_CLASS_HT)
155  {
156  mcs = mcs % 8;
157  }
158 
160  {
161  NS_LOG_WARN ("Table missing for MCS: " << +mcs << " in TableBasedErrorRateModel: use fallback error rate model");
162  return m_fallbackErrorModel->GetChunkSuccessRate (mode, txVector, snr, nbits, staId);
163  }
164 
165  auto errorTable = (ldpc ? AwgnErrorTableLdpc1458 : (size < m_threshold ? AwgnErrorTableBcc32 : AwgnErrorTableBcc1458));
166  auto itVector = errorTable[mcs];
167  auto itTable = std::find_if (itVector.begin(), itVector.end(),
168  [&roundedSnr](const std::pair<double, double>& element) {
169  return element.first == roundedSnr;
170  });
171  double minSnr = itVector.begin ()->first;
172  double maxSnr = (--itVector.end ())->first;
173  double per;
174  if (itTable == itVector.end ())
175  {
176  if (roundedSnr < minSnr)
177  {
178  per = 1.0;
179  }
180  else if (roundedSnr > maxSnr)
181  {
182  per = 0.0;
183  }
184  else
185  {
186  double a = 0.0, b = 0.0, previousSnr = 0.0, nextSnr = 0.0;
187  for (auto i = itVector.begin (); i != itVector.end (); ++i)
188  {
189  if (i->first < roundedSnr)
190  {
191  previousSnr = i->first;
192  a = i->second;
193  }
194  else
195  {
196  nextSnr = i->first;
197  b = i->second;
198  break;
199  }
200  }
201  per = a + (roundedSnr - previousSnr) * (b - a) / (nextSnr - previousSnr);
202  }
203  }
204  else
205  {
206  per = itTable->second;
207  }
208 
210  if (size != tableSize)
211  {
212  // From IEEE document 11-14/0803r1 (Packet Length for Box 0 Calibration)
213  per = (1.0 - std::pow ((1 - per), (static_cast<double> (size) / tableSize)));
214  }
215 
217  {
218  per = 0.0;
219  }
220 
221  return 1.0 - per;
222 }
223 
224 } //namespace ns3
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::TableBasedErrorRateModel::RoundSnr
double RoundSnr(double snr, double precision) const
Round SNR (in dB) to the specified precision.
Definition: table-based-error-rate-model.cc:77
first
Definition: first.py:1
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
ns3::WIFI_MOD_CLASS_ERP_OFDM
@ WIFI_MOD_CLASS_ERP_OFDM
ERP-OFDM (18.4)
Definition: wifi-phy-common.h:128
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::WIFI_MOD_CLASS_HT
@ WIFI_MOD_CLASS_HT
HT (Clause 19)
Definition: wifi-phy-common.h:130
ns3::TableBasedErrorRateModel::GetMcsForMode
static uint8_t GetMcsForMode(WifiMode mode)
Utility function to convert WifiMode to an MCS value.
Definition: table-based-error-rate-model.cc:85
ns3::WifiTxVector::IsLdpc
bool IsLdpc(void) const
Check if LDPC FEC coding is used or not.
Definition: wifi-tx-vector.cc:220
ns3::WifiMode::GetCodeRate
WifiCodeRate GetCodeRate(void) const
Definition: wifi-mode.cc:108
ns3::TableBasedErrorRateModel::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: table-based-error-rate-model.cc:44
ns3::ERROR_TABLE_BCC_LARGE_FRAME_SIZE
const uint16_t ERROR_TABLE_BCC_LARGE_FRAME_SIZE
reference size (bytes) of large frames for BCC
Definition: error-rate-tables.h:32
NS_LOG_WARN
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:265
ns3::WifiMode::GetModulationClass
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:159
ns3::PointerValue
Hold objects of type Ptr<T>.
Definition: pointer.h:37
ns3::WIFI_MOD_CLASS_OFDM
@ WIFI_MOD_CLASS_OFDM
OFDM (Clause 17)
Definition: wifi-phy-common.h:129
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::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::ERROR_TABLE_BCC_SMALL_FRAME_SIZE
const uint16_t ERROR_TABLE_BCC_SMALL_FRAME_SIZE
reference size (bytes) of small frames for BCC
Definition: error-rate-tables.h:31
ns3::TableBasedErrorRateModel::DoGetChunkSuccessRate
double DoGetChunkSuccessRate(WifiMode mode, const WifiTxVector &txVector, double snr, uint64_t nbits, uint8_t numRxAntennas, WifiPpduField field, uint16_t staId) const override
A pure virtual method that must be implemented in the subclass.
Definition: table-based-error-rate-model.cc:144
ns3::AwgnErrorTableLdpc1458
static const SnrPerTable AwgnErrorTableLdpc1458[ERROR_TABLE_LDPC_MAX_NUM_MCS+1]
AWGN error table for LDPC with reference size of 1458 bytes.
Definition: error-rate-tables.h:186
ns3::WifiMode
represent a single transmission mode
Definition: wifi-mode.h:48
ns3::ERROR_TABLE_BCC_MAX_NUM_MCS
const uint8_t ERROR_TABLE_BCC_MAX_NUM_MCS
maximum number of MCSs for BCC
Definition: error-rate-tables.h:34
wifi-tx-vector.h
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::TABLED_BASED_ERROR_MODEL_PRECISION
static const double TABLED_BASED_ERROR_MODEL_PRECISION
precision for PER
Definition: table-based-error-rate-model.cc:37
ns3::TableBasedErrorRateModel::m_fallbackErrorModel
Ptr< ErrorRateModel > m_fallbackErrorModel
Error rate model to fallback to if no value is found in the table.
Definition: table-based-error-rate-model.h:81
ns3::ErrorRateModel
the interface for Wifi's error models
Definition: error-rate-model.h:35
table-based-error-rate-model.h
NS_ABORT_MSG_IF
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
ns3::AwgnErrorTableBcc32
static const SnrPerTable AwgnErrorTableBcc32[ERROR_TABLE_BCC_MAX_NUM_MCS+1]
AWGN error table for BCC with reference size of 32 bytes.
Definition: error-rate-tables.h:41
ns3::WifiPpduField
WifiPpduField
The type of PPDU field (grouped for convenience)
Definition: wifi-phy-common.h:171
ns3::MakePointerAccessor
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: pointer.h:227
ns3::RatioToDb
double RatioToDb(double ratio)
Convert from ratio to dB.
Definition: wifi-utils.cc:49
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::ERROR_TABLE_LDPC_MAX_NUM_MCS
const uint8_t ERROR_TABLE_LDPC_MAX_NUM_MCS
maximum number of MCSs for LDPC
Definition: error-rate-tables.h:35
wifi-utils.h
yans-error-rate-model.h
ns3::TableBasedErrorRateModel::TableBasedErrorRateModel
TableBasedErrorRateModel()
Definition: table-based-error-rate-model.cc:64
ns3::TableBasedErrorRateModel::m_threshold
uint64_t m_threshold
Threshold in bytes over which the table for large size frames is used.
Definition: table-based-error-rate-model.h:83
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::UintegerValue
Hold an unsigned integer type.
Definition: uinteger.h:44
ns3::SNR_PRECISION
static const double SNR_PRECISION
precision for SNR
Definition: table-based-error-rate-model.cc:36
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::MakeUintegerAccessor
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: uinteger.h:45
ns3::ERROR_TABLE_LDPC_FRAME_SIZE
const uint16_t ERROR_TABLE_LDPC_FRAME_SIZE
reference size (bytes) for LDPC
Definition: error-rate-tables.h:33
ns3::TableBasedErrorRateModel::~TableBasedErrorRateModel
~TableBasedErrorRateModel()
Definition: table-based-error-rate-model.cc:69
ns3::TableBasedErrorRateModel
Introspection did not find any typical Config paths.
Definition: table-based-error-rate-model.h:39
ns3::WifiMode::GetConstellationSize
uint16_t GetConstellationSize(void) const
Definition: wifi-mode.cc:115
ns3::AwgnErrorTableBcc1458
static const SnrPerTable AwgnErrorTableBcc1458[ERROR_TABLE_BCC_MAX_NUM_MCS+1]
AWGN error table for BCC with reference size of 1458 bytes.
Definition: error-rate-tables.h:119
ns3::WifiMode::GetMcsValue
uint8_t GetMcsValue(void) const
Definition: wifi-mode.cc:137