27#include "ns3/boolean.h"
28#include "ns3/double.h"
31#include "ns3/satellite-env-variables.h"
32#include "ns3/singleton.h"
33#include "ns3/uinteger.h"
46NS_LOG_COMPONENT_DEFINE(
"SatWaveformConf");
65 uint32_t modulatedBits,
68 uint32_t payloadBytes,
69 uint32_t lengthInSymbols,
70 uint32_t preambleLengthInSymbols)
85 NS_LOG_FUNCTION(
this);
92 NS_LOG_FUNCTION(
this);
99 NS_LOG_FUNCTION(
this);
106 NS_LOG_FUNCTION(
this);
113 NS_LOG_FUNCTION(
this);
120 NS_LOG_FUNCTION(
this << symbolRateInBaud);
127 NS_LOG_FUNCTION(
this << symbolRateInBaud);
134 NS_LOG_FUNCTION(
this << carrierBandwidthInHz << symbolRateInBaud);
142 NS_LOG_FUNCTION(
this << symbolRateInBaud);
150 NS_LOG_FUNCTION(
this << symbolRateInBaud);
159 return cnoRequirement;
165 NS_LOG_FUNCTION(
this << ebnoRequirement);
172 NS_LOG_FUNCTION(
this << carrierBandwidthInHz << symbolRateInBaud);
179 <<
", SpectralEfficiency: "
209 NS_LOG_FUNCTION(
this << directoryPathName);
213 NS_FATAL_ERROR(
"No such directory: " << directoryPathName);
216 std::string waveformsFilePathName = directoryPathName +
"/waveforms.txt";
217 std::string defaultWaveform = directoryPathName +
"/default_waveform.txt";
226 NS_LOG_FUNCTION(
this);
228 Object::NotifyConstructionCompleted();
243 NS_FATAL_ERROR(
"Incorrect choice of burst length.");
250 static TypeId tid = TypeId(
"ns3::SatWaveformConf")
252 .AddAttribute(
"TargetBLER",
253 "Block error rate target",
254 DoubleValue(0.00001),
256 MakeDoubleChecker<double>())
257 .AddAttribute(
"AcmEnabled",
261 MakeBooleanChecker())
262 .AddAttribute(
"BurstLength",
263 "Default burst length",
265 MakeEnumAccessor<SatEnums::SatWaveFormBurstLength_t>(
272 "ShortAndLongBurst"))
279 NS_LOG_FUNCTION(
this);
285 NS_LOG_FUNCTION(
this << filePathName);
288 std::ifstream* ifs =
new std::ifstream(filePathName.c_str(), std::ifstream::in);
294 filePathName =
"../../" + filePathName;
295 ifs =
new std::ifstream(filePathName.c_str(), std::ifstream::in);
299 NS_FATAL_ERROR(
"The file " << filePathName <<
" is not found.");
305 std::getline(*ifs, line);
306 std::istringstream line_ss(line);
309 NS_FATAL_ERROR(
"SatWaveformConf::ReadFromFileDefaultWaveform - Waveform conf vector has "
310 "unexpected amount of elements!");
317 NS_LOG_FUNCTION(
this << filePathName);
319 std::vector<uint32_t> wfIds;
322 std::ifstream* ifs =
new std::ifstream(filePathName.c_str(), std::ifstream::in);
328 filePathName =
"../../" + filePathName;
329 ifs =
new std::ifstream(filePathName.c_str(), std::ifstream::in);
333 NS_FATAL_ERROR(
"The file " << filePathName <<
" is not found.");
338 std::vector<double> rowVector;
341 int32_t wfIndex, modulatedBits, payloadBytes, durationInSymbols, preambleDurationInSymbols;
342 std::string sCodingRate;
347 while (std::getline(*ifs, line))
349 std::istringstream line_ss(line);
352 if (!(line_ss >> wfIndex >> modulatedBits >> sCodingRate >> payloadBytes >>
355 NS_FATAL_ERROR(
"SatWaveformConf::ReadFromFile - Waveform conf vector has unexpected "
356 "amount of elements!");
359 if (!(line_ss >> preambleDurationInSymbols))
361 preambleDurationInSymbols = 0;
365 wfIds.push_back(wfIndex);
368 std::istringstream ss(sCodingRate);
370 std::vector<uint32_t> output;
372 while (std::getline(ss, token,
'/'))
381 if (output.size() != 2)
383 NS_FATAL_ERROR(
"SatWaveformConf::ReadFromFile - Temp fraction vector has unexpected "
384 "amount of elements!");
387 double dCodingRate = double(output[0]) / output[1];
393 Ptr<SatWaveform> wf = Create<SatWaveform>(wfIndex,
399 preambleDurationInSymbols);
407 m_minWfId = *std::min_element(wfIds.begin(), wfIds.end());
408 m_maxWfId = *std::max_element(wfIds.begin(), wfIds.end());
414 NS_LOG_FUNCTION(
this);
416 for (std::map<uint32_t, Ptr<SatWaveform>>::iterator it =
m_waveforms.begin();
425 double ebnoRequirementDb = linkResults->GetEbNoDb(it->first,
m_targetBLER);
433 NS_LOG_FUNCTION(
this << wfId);
437 NS_FATAL_ERROR(
"SatWaveformConf::GetWaveform - unsupported waveform id: " << wfId);
451 "SatWaveformConf::GetDefaultWaveformId - unsupported waveform id: " <<
m_defaultWfId);
459 double symbolRateInBaud,
461 double& cnoThreshold,
462 uint32_t burstLength)
const
464 NS_LOG_FUNCTION(
this << cno << symbolRateInBaud << wfId << cnoThreshold << burstLength);
466 bool success =
false;
477 for (std::map<uint32_t, Ptr<SatWaveform>>::const_reverse_iterator rit =
m_waveforms.rbegin();
481 if (rit->second->GetBurstLengthInSymbols() == burstLength)
483 double cnoThr = rit->second->GetCNoThreshold(symbolRateInBaud);
488 cnoThreshold = cnoThr;
495 NS_LOG_INFO(
"Get best waveform in RTN link (ACM)! CNo: "
497 <<
", burst length: " << burstLength <<
", WF: " << wfId
506 NS_LOG_FUNCTION(
this << burstLength);
510 uint32_t payloadInBytes = std::numeric_limits<uint32_t>::max();
513 for (std::map<uint32_t, Ptr<SatWaveform>>::const_reverse_iterator rit =
m_waveforms.rbegin();
517 if (rit->second->GetBurstLengthInSymbols() == burstLength)
520 if (rit->second->GetPayloadInBytes() < payloadInBytes)
522 payloadInBytes = rit->second->GetPayloadInBytes();
535 NS_LOG_FUNCTION(
this << carrierBandwidthInHz << symbolRateInBaud);
537 for (std::map<uint32_t, Ptr<SatWaveform>>::const_iterator it =
m_waveforms.begin();
541 std::cout <<
"WaveformId: " << it->first <<
" ";
542 it->second->Dump(carrierBandwidthInHz, symbolRateInBaud);
549 NS_LOG_FUNCTION(
this << wfId);
553 NS_FATAL_ERROR(
"SatWaveformConf::GetModCod - unsupported waveform id: " << wfId);
556 std::map<uint32_t, Ptr<SatWaveform>>::const_iterator it =
m_waveforms.find(wfId);
564 NS_FATAL_ERROR(
"Waveform id: " << wfId <<
" not found in the waveform container!");
572 uint32_t codingRateNumerator,
573 uint32_t codingRateDenominator)
const
575 NS_LOG_FUNCTION(
this << modulatedBits << codingRateNumerator << codingRateDenominator);
577 switch (modulatedBits)
581 if (codingRateNumerator == 1 && codingRateDenominator == 3)
587 NS_FATAL_ERROR(
"Unsupported coding rate numerator: "
588 << codingRateNumerator <<
", denominator: " << codingRateDenominator);
594 if (codingRateNumerator == 1 && codingRateDenominator == 3)
598 else if (codingRateNumerator == 1 && codingRateDenominator == 2)
602 else if (codingRateNumerator == 2 && codingRateDenominator == 3)
606 else if (codingRateNumerator == 3 && codingRateDenominator == 4)
610 else if (codingRateNumerator == 5 && codingRateDenominator == 6)
616 NS_FATAL_ERROR(
"Unsupported coding rate numerator: "
617 << codingRateNumerator <<
", denominator: " << codingRateDenominator);
623 if (codingRateNumerator == 2 && codingRateDenominator == 3)
627 else if (codingRateNumerator == 3 && codingRateDenominator == 4)
631 else if (codingRateNumerator == 5 && codingRateDenominator == 6)
637 NS_FATAL_ERROR(
"Unsupported coding rate numerator: "
638 << codingRateNumerator <<
", denominator: " << codingRateDenominator);
644 if (codingRateNumerator == 3 && codingRateDenominator == 4)
648 else if (codingRateNumerator == 5 && codingRateDenominator == 6)
654 NS_FATAL_ERROR(
"Unsupported coding rate numerator: "
655 << codingRateNumerator <<
", denominator: " << codingRateDenominator);
661 NS_FATAL_ERROR(
"Unsupported modulated bits:" << modulatedBits);
SatEnums class is for simplifying the use of enumerators in the satellite module.
SatModcod_t
Modulation scheme and coding rate for DVB-S2.
@ SAT_MODCOD_16QAM_5_TO_6
@ SAT_MODCOD_16QAM_3_TO_4
static Ptr< SatEnvVariables > GetInstance()
static T DbToLinear(T db)
Converts decibels to linear.
static T LinearToDb(T linear)
Converts linear to decibels.
constexpr uint32_t BITS_PER_BYTE
Number of bits in a byte.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.