27 #include <ns3/boolean.h>
28 #include <ns3/double.h>
31 #include <ns3/uinteger.h>
41 NS_LOG_COMPONENT_DEFINE(
"SatWaveformConf");
50 m_modCod(
SatEnums::SAT_NONVALID_MODCOD),
53 m_preambleLengthInSymbols(0),
54 m_ebnoRequirement(0.0)
60 uint32_t modulatedBits,
63 uint32_t payloadBytes,
64 uint32_t lengthInSymbols,
65 uint32_t preambleLengthInSymbols)
67 m_modulatedBits(modulatedBits),
68 m_codingRate(codingRate),
70 m_payloadBytes(payloadBytes),
71 m_lengthInSymbols(lengthInSymbols),
72 m_preambleLengthInSymbols(preambleLengthInSymbols),
73 m_ebnoRequirement(0.0)
80 NS_LOG_FUNCTION(
this);
87 NS_LOG_FUNCTION(
this);
94 NS_LOG_FUNCTION(
this);
101 NS_LOG_FUNCTION(
this);
108 NS_LOG_FUNCTION(
this);
115 NS_LOG_FUNCTION(
this << symbolRateInBaud);
122 NS_LOG_FUNCTION(
this << symbolRateInBaud);
129 NS_LOG_FUNCTION(
this << carrierBandwidthInHz << symbolRateInBaud);
137 NS_LOG_FUNCTION(
this << symbolRateInBaud);
145 NS_LOG_FUNCTION(
this << symbolRateInBaud);
154 return cnoRequirement;
160 NS_LOG_FUNCTION(
this << ebnoRequirement);
167 NS_LOG_FUNCTION(
this << carrierBandwidthInHz << symbolRateInBaud);
174 <<
", SpectralEfficiency: "
184 m_targetBLER(0.00001),
189 m_burstLength(
SatEnums::UNKNOWN_BURST)
197 m_targetBLER(0.00001),
202 m_burstLength(
SatEnums::UNKNOWN_BURST)
204 NS_LOG_FUNCTION(
this);
207 ObjectBase::ConstructSelf(AttributeConstructionList());
222 NS_FATAL_ERROR(
"Incorrect choice of burst length.");
229 static TypeId tid = TypeId(
"ns3::SatWaveformConf")
231 .AddAttribute(
"TargetBLER",
232 "Block error rate target",
233 DoubleValue(0.00001),
235 MakeDoubleChecker<double>())
236 .AddAttribute(
"AcmEnabled",
240 MakeBooleanChecker())
241 .AddAttribute(
"DefaultWfId",
242 "Default waveform id",
245 MakeUintegerChecker<uint32_t>(1, 22))
246 .AddAttribute(
"BurstLength",
247 "Default burst length",
255 "ShortAndLongBurst"))
256 .AddConstructor<SatWaveformConf>();
263 NS_LOG_FUNCTION(
this);
270 NS_LOG_FUNCTION(
this);
276 NS_LOG_FUNCTION(
this << filePathName);
278 std::vector<uint32_t> wfIds;
281 std::ifstream* ifs =
new std::ifstream(filePathName.c_str(), std::ifstream::in);
287 filePathName =
"../../" + filePathName;
288 ifs =
new std::ifstream(filePathName.c_str(), std::ifstream::in);
292 NS_FATAL_ERROR(
"The file " << filePathName <<
" is not found.");
297 std::vector<double> rowVector;
300 int32_t wfIndex, modulatedBits, payloadBytes, durationInSymbols, preambleDurationInSymbols;
301 std::string sCodingRate;
306 while (std::getline(*ifs, line))
308 std::istringstream line_ss(line);
311 if (!(line_ss >> wfIndex >> modulatedBits >> sCodingRate >> payloadBytes >>
314 NS_FATAL_ERROR(
"SatWaveformConf::ReadFromFile - Waveform conf vector has unexpected "
315 "amount of elements!");
318 if (!(line_ss >> preambleDurationInSymbols))
320 preambleDurationInSymbols = 0;
324 wfIds.push_back(wfIndex);
327 std::istringstream ss(sCodingRate);
329 std::vector<uint32_t> output;
331 while (std::getline(ss, token,
'/'))
340 if (output.size() != 2)
342 NS_FATAL_ERROR(
"SatWaveformConf::ReadFromFile - Temp fraction vector has unexpected "
343 "amount of elements!");
346 double dCodingRate = double(output[0]) / output[1];
352 Ptr<SatWaveform> wf = Create<SatWaveform>(wfIndex,
358 preambleDurationInSymbols);
366 m_minWfId = *std::min_element(wfIds.begin(), wfIds.end());
367 m_maxWfId = *std::max_element(wfIds.begin(), wfIds.end());
373 NS_LOG_FUNCTION(
this);
375 for (std::map<uint32_t, Ptr<SatWaveform>>::iterator it =
m_waveforms.begin();
384 double ebnoRequirementDb = linkResults->GetEbNoDb(it->first,
m_targetBLER);
392 NS_LOG_FUNCTION(
this << wfId);
396 NS_FATAL_ERROR(
"SatWaveformConf::GetWaveform - unsupported waveform id: " << wfId);
410 "SatWaveformConf::GetDefaultWaveformId - unsupported waveform id: " <<
m_defaultWfId);
418 double symbolRateInBaud,
420 double& cnoThreshold,
421 uint32_t burstLength)
const
423 NS_LOG_FUNCTION(
this << cno << symbolRateInBaud << wfId << cnoThreshold << burstLength);
425 bool success =
false;
436 for (std::map<uint32_t, Ptr<SatWaveform>>::const_reverse_iterator rit =
m_waveforms.rbegin();
440 if (rit->second->GetBurstLengthInSymbols() == burstLength)
442 double cnoThr = rit->second->GetCNoThreshold(symbolRateInBaud);
447 cnoThreshold = cnoThr;
454 NS_LOG_INFO(
"Get best waveform in RTN link (ACM)! CNo: "
456 <<
", burst length: " << burstLength <<
", WF: " << wfId
465 NS_LOG_FUNCTION(
this << burstLength);
469 uint32_t payloadInBytes = std::numeric_limits<uint32_t>::max();
472 for (std::map<uint32_t, Ptr<SatWaveform>>::const_reverse_iterator rit =
m_waveforms.rbegin();
476 if (rit->second->GetBurstLengthInSymbols() == burstLength)
479 if (rit->second->GetPayloadInBytes() < payloadInBytes)
481 payloadInBytes = rit->second->GetPayloadInBytes();
494 NS_LOG_FUNCTION(
this << carrierBandwidthInHz << symbolRateInBaud);
496 for (std::map<uint32_t, Ptr<SatWaveform>>::const_iterator it =
m_waveforms.begin();
500 std::cout <<
"WaveformId: " << it->first <<
" ";
501 it->second->Dump(carrierBandwidthInHz, symbolRateInBaud);
508 NS_LOG_FUNCTION(
this << wfId);
512 NS_FATAL_ERROR(
"SatWaveformConf::GetModCod - unsupported waveform id: " << wfId);
515 std::map<uint32_t, Ptr<SatWaveform>>::const_iterator it =
m_waveforms.find(wfId);
523 NS_FATAL_ERROR(
"Waveform id: " << wfId <<
" not found in the waveform container!");
531 uint32_t codingRateNumerator,
532 uint32_t codingRateDenominator)
const
534 NS_LOG_FUNCTION(
this << modulatedBits << codingRateNumerator << codingRateDenominator);
536 switch (modulatedBits)
540 if (codingRateNumerator == 1 && codingRateDenominator == 3)
546 NS_FATAL_ERROR(
"Unsupported coding rate numerator: "
547 << codingRateNumerator <<
", denominator: " << codingRateDenominator);
553 if (codingRateNumerator == 1 && codingRateDenominator == 3)
557 else if (codingRateNumerator == 1 && codingRateDenominator == 2)
561 else if (codingRateNumerator == 2 && codingRateDenominator == 3)
565 else if (codingRateNumerator == 3 && codingRateDenominator == 4)
569 else if (codingRateNumerator == 5 && codingRateDenominator == 6)
575 NS_FATAL_ERROR(
"Unsupported coding rate numerator: "
576 << codingRateNumerator <<
", denominator: " << codingRateDenominator);
582 if (codingRateNumerator == 2 && codingRateDenominator == 3)
586 else if (codingRateNumerator == 3 && codingRateDenominator == 4)
590 else if (codingRateNumerator == 5 && codingRateDenominator == 6)
596 NS_FATAL_ERROR(
"Unsupported coding rate numerator: "
597 << codingRateNumerator <<
", denominator: " << codingRateDenominator);
603 if (codingRateNumerator == 3 && codingRateDenominator == 4)
607 else if (codingRateNumerator == 5 && codingRateDenominator == 6)
613 NS_FATAL_ERROR(
"Unsupported coding rate numerator: "
614 << codingRateNumerator <<
", denominator: " << codingRateDenominator);
620 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 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.