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  }
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
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
const uint16_t WIFI_CODE_RATE_2_3
2/3 coding rate
static const SnrPerTable AwgnErrorTableBcc1458[ERROR_TABLE_BCC_MAX_NUM_MCS+1]
AWGN error table for BCC with reference size of 1458 bytes.
const uint8_t ERROR_TABLE_LDPC_MAX_NUM_MCS
maximum number of MCSs for LDPC
const uint8_t ERROR_TABLE_BCC_MAX_NUM_MCS
maximum number of MCSs for BCC
Ptr< ErrorRateModel > m_fallbackErrorModel
Error rate model to fallback to if no value is found in the table.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
const uint16_t ERROR_TABLE_LDPC_FRAME_SIZE
reference size (bytes) for LDPC
represent a single transmission modeA WifiMode is implemented by a single integer which is used to lo...
Definition: wifi-mode.h:47
const uint16_t WIFI_CODE_RATE_3_4
3/4 coding rate
bool IsLdpc(void) const
Check if LDPC FEC coding is used or not.
the interface for Wifi&#39;s error models
uint64_t m_threshold
Threshold in bytes over which the table for large size frames is used.
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
Introspection did not find any typical Config paths.
Hold an unsigned integer type.
Definition: uinteger.h:44
static const double SNR_PRECISION
precision for SNR
WifiPpduField
The type of PPDU field (grouped for convenience)
static const double TABLED_BASED_ERROR_MODEL_PRECISION
precision for PER
double RoundSnr(double snr, double precision) const
Round SNR (in dB) to the specified precision.
static TypeId GetTypeId(void)
Get the type ID.
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:159
static const SnrPerTable AwgnErrorTableLdpc1458[ERROR_TABLE_LDPC_MAX_NUM_MCS+1]
AWGN error table for LDPC with reference size of 1458 bytes.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Hold objects of type Ptr<T>.
Definition: pointer.h:36
const uint16_t ERROR_TABLE_BCC_SMALL_FRAME_SIZE
reference size (bytes) of small frames for BCC
uint16_t GetConstellationSize(void) const
Definition: wifi-mode.cc:115
double RatioToDb(double ratio)
Convert from ratio to dB.
Definition: wifi-utils.cc:53
static uint8_t GetMcsForMode(WifiMode mode)
Utility function to convert WifiMode to an MCS value.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:265
const uint16_t ERROR_TABLE_BCC_LARGE_FRAME_SIZE
reference size (bytes) of large frames for BCC
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.
WifiCodeRate GetCodeRate(void) const
Definition: wifi-mode.cc:108
Definition: first.py:1
uint8_t GetMcsValue(void) const
Definition: wifi-mode.cc:137
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
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
const uint16_t WIFI_CODE_RATE_1_2
1/2 coding rate
static const SnrPerTable AwgnErrorTableBcc32[ERROR_TABLE_BCC_MAX_NUM_MCS+1]
AWGN error table for BCC with reference size of 32 bytes.