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"
33
34namespace ns3 {
35
36static const double SNR_PRECISION = 2;
37static const double TABLED_BASED_ERROR_MODEL_PRECISION = 1e-5;
38
40
41NS_LOG_COMPONENT_DEFINE ("TableBasedErrorRateModel");
42
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
76double
77TableBasedErrorRateModel::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
84std::optional<uint8_t>
86{
87 std::optional<uint8_t> mcs;
88 WifiModulationClass modulationClass = mode.GetModulationClass ();
89 WifiCodeRate codeRate = mode.GetCodeRate ();
90 uint16_t constellationSize = mode.GetConstellationSize ();
91
92 if (modulationClass == WIFI_MOD_CLASS_OFDM || modulationClass == WIFI_MOD_CLASS_ERP_OFDM)
93 {
94 if (constellationSize == 2) // BPSK
95 {
96 if (codeRate == WIFI_CODE_RATE_1_2)
97 {
98 mcs = 0;
99 }
100 if (codeRate == WIFI_CODE_RATE_3_4)
101 {
102 // No MCS uses BPSK and a Coding Rate of 3/4
103 }
104 }
105 else if (constellationSize == 4) // QPSK
106 {
107 if (codeRate == WIFI_CODE_RATE_1_2)
108 {
109 mcs = 1;
110 }
111 else if (codeRate == WIFI_CODE_RATE_3_4)
112 {
113 mcs = 2;
114 }
115 }
116 else if (constellationSize == 16) // 16-QAM
117 {
118 if (codeRate == WIFI_CODE_RATE_1_2)
119 {
120 mcs = 3;
121 }
122 else if (codeRate == WIFI_CODE_RATE_3_4)
123 {
124 mcs = 4;
125 }
126 }
127 else if (constellationSize == 64) // 64-QAM
128 {
129 if (codeRate == WIFI_CODE_RATE_2_3)
130 {
131 mcs = 5;
132 }
133 else if (codeRate == WIFI_CODE_RATE_3_4)
134 {
135 mcs = 6;
136 }
137 }
138 }
139 else if (modulationClass >= WIFI_MOD_CLASS_HT)
140 {
141 mcs = mode.GetMcsValue ();
142 }
143 return mcs;
144}
145
146double
147TableBasedErrorRateModel::DoGetChunkSuccessRate (WifiMode mode, const WifiTxVector& txVector, double snr, uint64_t nbits, uint8_t numRxAntennas, WifiPpduField field, uint16_t staId) const
148{
149 NS_LOG_FUNCTION (this << mode << txVector << snr << nbits << +numRxAntennas << field << staId);
150 uint64_t size = std::max<uint64_t> (1, (nbits / 8));
151 double roundedSnr = RoundSnr (RatioToDb (snr), SNR_PRECISION);
152 uint8_t mcs;
153 if (auto ret = GetMcsForMode (mode); ret.has_value ())
154 {
155 mcs = ret.value ();
156 }
157 else
158 {
159 NS_LOG_DEBUG ("No MCS found for mode " << mode << ": use fallback error rate model");
160 return m_fallbackErrorModel->GetChunkSuccessRate (mode, txVector, snr, nbits, staId);
161 }
162 bool ldpc = txVector.IsLdpc ();
163 NS_LOG_FUNCTION (this << +mcs << roundedSnr << size << ldpc);
164
165 // HT: for MCS greater than 7, use 0 - 7 curves for data rate
167 {
168 mcs = mcs % 8;
169 }
170
172 {
173 NS_LOG_WARN ("Table missing for MCS: " << +mcs << " in TableBasedErrorRateModel: use fallback error rate model");
174 return m_fallbackErrorModel->GetChunkSuccessRate (mode, txVector, snr, nbits, staId);
175 }
176
177 auto errorTable = (ldpc ? AwgnErrorTableLdpc1458 : (size < m_threshold ? AwgnErrorTableBcc32 : AwgnErrorTableBcc1458));
178 const auto& itVector = errorTable[mcs];
179 auto itTable = std::find_if (itVector.cbegin (), itVector.cend (),
180 [&roundedSnr](const std::pair<double, double>& element) {
181 return element.first == roundedSnr;
182 });
183 double minSnr = itVector.cbegin ()->first;
184 double maxSnr = (--itVector.cend ())->first;
185 double per;
186 if (itTable == itVector.cend ())
187 {
188 if (roundedSnr < minSnr)
189 {
190 per = 1.0;
191 }
192 else if (roundedSnr > maxSnr)
193 {
194 per = 0.0;
195 }
196 else
197 {
198 double a = 0.0, b = 0.0, previousSnr = 0.0, nextSnr = 0.0;
199 for (auto i = itVector.cbegin (); i != itVector.cend (); ++i)
200 {
201 if (i->first < roundedSnr)
202 {
203 previousSnr = i->first;
204 a = i->second;
205 }
206 else
207 {
208 nextSnr = i->first;
209 b = i->second;
210 break;
211 }
212 }
213 per = a + (roundedSnr - previousSnr) * (b - a) / (nextSnr - previousSnr);
214 }
215 }
216 else
217 {
218 per = itTable->second;
219 }
220
222 if (size != tableSize)
223 {
224 // From IEEE document 11-14/0803r1 (Packet Length for Box 0 Calibration)
225 per = (1.0 - std::pow ((1 - per), (static_cast<double> (size) / tableSize)));
226 }
227
229 {
230 per = 0.0;
231 }
232
233 return 1.0 - per;
234}
235
236} //namespace ns3
the interface for Wifi's error models
Hold objects of type Ptr<T>.
Definition: pointer.h:37
Introspection did not find any typical Config paths.
Ptr< ErrorRateModel > m_fallbackErrorModel
Error rate model to fallback to if no value is found in the table.
static std::optional< uint8_t > GetMcsForMode(WifiMode mode)
Utility function to convert WifiMode to an MCS value.
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.
static TypeId GetTypeId(void)
Get the type ID.
double RoundSnr(double snr, double precision) const
Round SNR (in dB) to the specified precision.
uint64_t m_threshold
Threshold in bytes over which the table for large size frames is used.
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Hold an unsigned integer type.
Definition: uinteger.h:44
represent a single transmission mode
Definition: wifi-mode.h:48
uint16_t GetConstellationSize(void) const
Definition: wifi-mode.cc:133
uint8_t GetMcsValue(void) const
Definition: wifi-mode.cc:155
WifiModulationClass GetModulationClass() const
Definition: wifi-mode.cc:177
WifiCodeRate GetCodeRate(void) const
Definition: wifi-mode.cc:126
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
bool IsLdpc(void) const
Check if LDPC FEC coding is used or not.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Definition: pointer.h:227
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:45
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:265
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
WifiModulationClass
This enumeration defines the modulation classes per (Table 10-6 "Modulation classes"; IEEE 802....
WifiPpduField
The type of PPDU field (grouped for convenience)
@ WIFI_MOD_CLASS_OFDM
OFDM (Clause 17)
@ WIFI_MOD_CLASS_HT
HT (Clause 19)
@ WIFI_MOD_CLASS_ERP_OFDM
ERP-OFDM (18.4)
Definition: first.py:1
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static const SnrPerTable AwgnErrorTableBcc32[ERROR_TABLE_BCC_MAX_NUM_MCS]
AWGN error table for BCC with reference size of 32 bytes.
double RatioToDb(double ratio)
Convert from ratio to dB.
Definition: wifi-utils.cc:49
const uint16_t WIFI_CODE_RATE_3_4
3/4 coding rate
const uint16_t WIFI_CODE_RATE_1_2
1/2 coding rate
const uint8_t ERROR_TABLE_BCC_MAX_NUM_MCS
maximum number of MCSs for BCC
static const SnrPerTable AwgnErrorTableLdpc1458[ERROR_TABLE_LDPC_MAX_NUM_MCS]
AWGN error table for LDPC with reference size of 1458 bytes.
static const SnrPerTable AwgnErrorTableBcc1458[ERROR_TABLE_BCC_MAX_NUM_MCS]
AWGN error table for BCC with reference size of 1458 bytes.
const uint16_t WIFI_CODE_RATE_2_3
2/3 coding rate
const uint8_t ERROR_TABLE_LDPC_MAX_NUM_MCS
maximum number of MCSs for LDPC
const uint16_t ERROR_TABLE_BCC_LARGE_FRAME_SIZE
reference size (bytes) of large frames for BCC
uint16_t WifiCodeRate
These constants define the various convolutional coding rates used for the OFDM transmission modes in...
const uint16_t ERROR_TABLE_BCC_SMALL_FRAME_SIZE
reference size (bytes) of small frames for BCC
static const double TABLED_BASED_ERROR_MODEL_PRECISION
precision for PER
static const double SNR_PRECISION
precision for SNR
const uint16_t ERROR_TABLE_LDPC_FRAME_SIZE
reference size (bytes) for LDPC