A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
table-based-error-rate-model.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Rohan Patidar <rpatidar@uw.edu>
7 * Sébastien Deronne <sebastien.deronne@gmail.com>
8 */
9
11
12#include "wifi-tx-vector.h"
13#include "wifi-utils.h"
15
16#include "ns3/dsss-error-rate-model.h"
17#include "ns3/log.h"
18#include "ns3/pointer.h"
19#include "ns3/string.h"
20#include "ns3/uinteger.h"
21
22#include <algorithm>
23#include <cmath>
24
25namespace ns3
26{
27
28static const double SNR_PRECISION = 2; //!< precision for SNR
29static const double TABLED_BASED_ERROR_MODEL_PRECISION = 1e-5; //!< precision for PER
30
32
33NS_LOG_COMPONENT_DEFINE("TableBasedErrorRateModel");
34
37{
38 static TypeId tid =
39 TypeId("ns3::TableBasedErrorRateModel")
41 .SetGroupName("Wifi")
42 .AddConstructor<TableBasedErrorRateModel>()
43 .AddAttribute("FallbackErrorRateModel",
44 "Ptr to the fallback error rate model to be used when no matching value "
45 "is found in a table",
49 .AddAttribute("SizeThreshold",
50 "Threshold in bytes over which the table for large size frames is used",
51 UintegerValue(400),
54 return tid;
55}
56
61
67
68dB_u
69TableBasedErrorRateModel::RoundSnr(dB_u snr, double precision) const
70{
71 NS_LOG_FUNCTION(this << snr);
72 const auto multiplier = std::round(std::pow(10.0, precision));
73 return std::floor(snr * multiplier + 0.5) / multiplier;
74}
75
76std::optional<uint8_t>
78{
79 std::optional<uint8_t> mcs;
80 WifiModulationClass modulationClass = mode.GetModulationClass();
81 WifiCodeRate codeRate = mode.GetCodeRate();
82 uint16_t constellationSize = mode.GetConstellationSize();
83
84 if (modulationClass == WIFI_MOD_CLASS_OFDM || modulationClass == WIFI_MOD_CLASS_ERP_OFDM)
85 {
86 if (constellationSize == 2) // BPSK
87 {
88 if (codeRate == WIFI_CODE_RATE_1_2)
89 {
90 mcs = 0;
91 }
92 if (codeRate == WIFI_CODE_RATE_3_4)
93 {
94 // No MCS uses BPSK and a Coding Rate of 3/4
95 }
96 }
97 else if (constellationSize == 4) // QPSK
98 {
99 if (codeRate == WIFI_CODE_RATE_1_2)
100 {
101 mcs = 1;
102 }
103 else if (codeRate == WIFI_CODE_RATE_3_4)
104 {
105 mcs = 2;
106 }
107 }
108 else if (constellationSize == 16) // 16-QAM
109 {
110 if (codeRate == WIFI_CODE_RATE_1_2)
111 {
112 mcs = 3;
113 }
114 else if (codeRate == WIFI_CODE_RATE_3_4)
115 {
116 mcs = 4;
117 }
118 }
119 else if (constellationSize == 64) // 64-QAM
120 {
121 if (codeRate == WIFI_CODE_RATE_2_3)
122 {
123 mcs = 5;
124 }
125 else if (codeRate == WIFI_CODE_RATE_3_4)
126 {
127 mcs = 6;
128 }
129 }
130 }
131 else if (modulationClass >= WIFI_MOD_CLASS_HT)
132 {
133 mcs = mode.GetMcsValue();
134 }
135 return mcs;
136}
137
138double
140 const WifiTxVector& txVector,
141 double snr,
142 uint64_t nbits,
143 uint8_t numRxAntennas,
144 WifiPpduField field,
145 uint16_t staId) const
146{
147 NS_LOG_FUNCTION(this << mode << txVector << snr << nbits << +numRxAntennas << field << staId);
148 const auto size = std::max<uint64_t>(1, (nbits / 8)); // in bytes
149 const auto roundedSnr = RoundSnr(RatioToDb(snr), SNR_PRECISION);
150 uint8_t mcs;
151 if (auto ret = GetMcsForMode(mode); ret.has_value())
152 {
153 mcs = ret.value();
154 }
155 else
156 {
157 NS_LOG_DEBUG("No MCS found for mode " << mode << ": use fallback error rate model");
159 ->GetChunkSuccessRate(mode, txVector, snr, nbits, numRxAntennas, field, staId);
160 }
161 bool ldpc = txVector.IsLdpc();
162 NS_LOG_FUNCTION(this << +mcs << roundedSnr << size << ldpc);
163
164 // HT: for MCS greater than 7, use 0 - 7 curves for data rate
166 {
167 mcs = mcs % 8;
168 }
169
171 {
172 NS_LOG_WARN("Table missing for MCS: "
173 << +mcs << " in TableBasedErrorRateModel: use fallback error rate model");
175 ->GetChunkSuccessRate(mode, txVector, snr, nbits, numRxAntennas, field, staId);
176 }
177
178 auto errorTable = (ldpc ? AwgnErrorTableLdpc1458
180 const auto& itVector = errorTable[mcs];
181 auto itTable =
182 std::find_if(itVector.cbegin(), itVector.cend(), [&roundedSnr](const auto& element) {
183 return element.first == roundedSnr;
184 });
185 const auto minSnr = itVector.cbegin()->first;
186 const auto maxSnr = (--itVector.cend())->first;
187 double per;
188 if (itTable == itVector.cend())
189 {
190 if (roundedSnr < minSnr)
191 {
192 per = 1.0;
193 }
194 else if (roundedSnr > maxSnr)
195 {
196 per = 0.0;
197 }
198 else
199 {
200 double a = 0.0;
201 double b = 0.0;
202 dB_u previousSnr{0.0};
203 dB_u nextSnr{0.0};
204 for (auto i = itVector.cbegin(); i != itVector.cend(); ++i)
205 {
206 if (i->first < roundedSnr)
207 {
208 previousSnr = i->first;
209 a = i->second;
210 }
211 else
212 {
213 nextSnr = i->first;
214 b = i->second;
215 break;
216 }
217 }
218 per = a + (roundedSnr - previousSnr) * (b - a) / (nextSnr - previousSnr);
219 }
220 }
221 else
222 {
223 per = itTable->second;
224 }
225
226 uint16_t tableSize = (ldpc ? ERROR_TABLE_LDPC_FRAME_SIZE
229 if (size != tableSize)
230 {
231 // From IEEE document 11-14/0803r1 (Packet Length for Box 0 Calibration)
232 per = (1.0 - std::pow((1 - per), (static_cast<double>(size) / tableSize)));
233 }
234
236 {
237 per = 0.0;
238 }
239
240 return 1.0 - per;
241}
242
243} // namespace ns3
the interface for Wifi's error models
AttributeValue implementation for Pointer.
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()
Get the type ID.
dB_u RoundSnr(dB_u snr, double precision) const
Round SNR 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:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Hold an unsigned integer type.
Definition uinteger.h:34
represent a single transmission mode
Definition wifi-mode.h:40
uint16_t GetConstellationSize() const
Definition wifi-mode.cc:130
WifiModulationClass GetModulationClass() const
Definition wifi-mode.cc:174
WifiCodeRate GetCodeRate() const
Definition wifi-mode.cc:123
uint8_t GetMcsValue() const
Definition wifi-mode.cc:152
This class mimics the TXVECTOR which is to be passed to the PHY in order to define the parameters whi...
bool IsLdpc() const
Check if LDPC FEC coding is used or not.
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:248
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
Definition pointer.h:269
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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:250
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
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.
const SnrPerTable AwgnErrorTableLdpc1458[ERROR_TABLE_LDPC_MAX_NUM_MCS]
AWGN error table for LDPC with reference size of 1458 bytes.
const SnrPerTable AwgnErrorTableBcc1458[ERROR_TABLE_BCC_MAX_NUM_MCS]
AWGN error table for BCC with reference size of 1458 bytes.
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition uinteger.h:35
dB_u RatioToDb(double ratio)
Convert from ratio to dB.
Definition wifi-utils.cc:44
const uint8_t ERROR_TABLE_BCC_MAX_NUM_MCS
maximum number of MCSs for BCC
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
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
const SnrPerTable AwgnErrorTableBcc32[ERROR_TABLE_BCC_MAX_NUM_MCS]
AWGN error table for BCC with reference size of 32 bytes.
double dB_u
dB weak type
Definition wifi-units.h:28
WifiCodeRate
These constants define the various convolutional coding rates used for the OFDM transmission modes in...
@ WIFI_CODE_RATE_2_3
2/3 coding rate
@ WIFI_CODE_RATE_1_2
1/2 coding rate
@ WIFI_CODE_RATE_3_4
3/4 coding rate