27 #include "ns3/dsss-error-rate-model.h"
29 #include "ns3/pointer.h"
30 #include "ns3/string.h"
31 #include "ns3/uinteger.h"
50 TypeId(
"ns3::TableBasedErrorRateModel")
54 .AddAttribute(
"FallbackErrorRateModel",
55 "Ptr to the fallback error rate model to be used when no matching value "
56 "is found in a table",
59 MakePointerChecker<ErrorRateModel>())
60 .AddAttribute(
"SizeThreshold",
61 "Threshold in bytes over which the table for large size frames is used",
64 MakeUintegerChecker<uint64_t>());
83 double multiplier = std::round(std::pow(10.0, precision));
84 return std::floor(snr * multiplier + 0.5) / multiplier;
87 std::optional<uint8_t>
90 std::optional<uint8_t> mcs;
97 if (constellationSize == 2)
108 else if (constellationSize == 4)
119 else if (constellationSize == 16)
130 else if (constellationSize == 64)
154 uint8_t numRxAntennas,
156 uint16_t staId)
const
158 NS_LOG_FUNCTION(
this << mode << txVector << snr << nbits << +numRxAntennas << field << staId);
159 uint64_t size = std::max<uint64_t>(1, (nbits / 8));
168 NS_LOG_DEBUG(
"No MCS found for mode " << mode <<
": use fallback error rate model");
170 ->GetChunkSuccessRate(mode, txVector, snr, nbits, numRxAntennas, field, staId);
172 bool ldpc = txVector.
IsLdpc();
184 << +mcs <<
" in TableBasedErrorRateModel: use fallback error rate model");
186 ->GetChunkSuccessRate(mode, txVector, snr, nbits, numRxAntennas, field, staId);
191 const auto& itVector = errorTable[mcs];
192 auto itTable = std::find_if(itVector.cbegin(),
194 [&roundedSnr](
const std::pair<double, double>& element) {
195 return element.first == roundedSnr;
197 double minSnr = itVector.cbegin()->first;
198 double maxSnr = (--itVector.cend())->
first;
200 if (itTable == itVector.cend())
202 if (roundedSnr < minSnr)
206 else if (roundedSnr > maxSnr)
214 double previousSnr = 0.0;
215 double nextSnr = 0.0;
216 for (
auto i = itVector.cbegin(); i != itVector.cend(); ++i)
218 if (i->first < roundedSnr)
220 previousSnr = i->first;
230 per = a + (roundedSnr - previousSnr) * (b - a) / (nextSnr - previousSnr);
235 per = itTable->second;
241 if (size != tableSize)
244 per = (1.0 - std::pow((1 - per), (
static_cast<double>(size) / tableSize)));
the interface for Wifi's error models
Hold objects of type Ptr<T>.
Ptr< ErrorRateModel > m_fallbackErrorModel
Error rate model to fallback to if no value is found in the table.
~TableBasedErrorRateModel() override
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.
TableBasedErrorRateModel()
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.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
represent a single transmission mode
uint16_t GetConstellationSize() const
WifiModulationClass GetModulationClass() const
WifiCodeRate GetCodeRate() const
uint8_t GetMcsValue() const
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.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#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.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
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)
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.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
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 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
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
static const double SNR_PRECISION
precision for SNR
const uint16_t ERROR_TABLE_LDPC_FRAME_SIZE
reference size (bytes) for LDPC
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