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>
46 NS_LOG_COMPONENT_DEFINE(
"SatWaveformConf");
55 m_modCod(
SatEnums::SAT_NONVALID_MODCOD),
58 m_preambleLengthInSymbols(0),
59 m_ebnoRequirement(0.0)
65 uint32_t modulatedBits,
68 uint32_t payloadBytes,
69 uint32_t lengthInSymbols,
70 uint32_t preambleLengthInSymbols)
72 m_modulatedBits(modulatedBits),
73 m_codingRate(codingRate),
75 m_payloadBytes(payloadBytes),
76 m_lengthInSymbols(lengthInSymbols),
77 m_preambleLengthInSymbols(preambleLengthInSymbols),
78 m_ebnoRequirement(0.0)
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: "
189 m_targetBLER(0.00001),
194 m_burstLength(
SatEnums::UNKNOWN_BURST)
202 m_targetBLER(0.00001),
207 m_burstLength(
SatEnums::UNKNOWN_BURST)
209 NS_LOG_FUNCTION(
this);
211 ObjectBase::ConstructSelf(AttributeConstructionList());
213 if (!Singleton<SatEnvVariables>::Get()->IsValidDirectory(directoryPathName))
215 NS_FATAL_ERROR(
"No such directory: " << directoryPathName);
218 std::string waveformsFilePathName = directoryPathName +
"/waveforms.txt";
219 std::string defaultWaveform = directoryPathName +
"/default_waveform.txt";
237 NS_FATAL_ERROR(
"Incorrect choice of burst length.");
244 static TypeId tid = TypeId(
"ns3::SatWaveformConf")
246 .AddAttribute(
"TargetBLER",
247 "Block error rate target",
248 DoubleValue(0.00001),
250 MakeDoubleChecker<double>())
251 .AddAttribute(
"AcmEnabled",
255 MakeBooleanChecker())
256 .AddAttribute(
"BurstLength",
257 "Default burst length",
259 MakeEnumAccessor<SatEnums::SatWaveFormBurstLength_t>(
266 "ShortAndLongBurst"))
267 .AddConstructor<SatWaveformConf>();
274 NS_LOG_FUNCTION(
this);
281 NS_LOG_FUNCTION(
this);
287 NS_LOG_FUNCTION(
this << filePathName);
290 std::ifstream* ifs =
new std::ifstream(filePathName.c_str(), std::ifstream::in);
296 filePathName =
"../../" + filePathName;
297 ifs =
new std::ifstream(filePathName.c_str(), std::ifstream::in);
301 NS_FATAL_ERROR(
"The file " << filePathName <<
" is not found.");
307 std::getline(*ifs, line);
308 std::istringstream line_ss(line);
311 NS_FATAL_ERROR(
"SatWaveformConf::ReadFromFileDefaultWaveform - Waveform conf vector has "
312 "unexpected amount of elements!");
319 NS_LOG_FUNCTION(
this << filePathName);
321 std::vector<uint32_t> wfIds;
324 std::ifstream* ifs =
new std::ifstream(filePathName.c_str(), std::ifstream::in);
330 filePathName =
"../../" + filePathName;
331 ifs =
new std::ifstream(filePathName.c_str(), std::ifstream::in);
335 NS_FATAL_ERROR(
"The file " << filePathName <<
" is not found.");
340 std::vector<double> rowVector;
343 int32_t wfIndex, modulatedBits, payloadBytes, durationInSymbols, preambleDurationInSymbols;
344 std::string sCodingRate;
349 while (std::getline(*ifs, line))
351 std::istringstream line_ss(line);
354 if (!(line_ss >> wfIndex >> modulatedBits >> sCodingRate >> payloadBytes >>
357 NS_FATAL_ERROR(
"SatWaveformConf::ReadFromFile - Waveform conf vector has unexpected "
358 "amount of elements!");
361 if (!(line_ss >> preambleDurationInSymbols))
363 preambleDurationInSymbols = 0;
367 wfIds.push_back(wfIndex);
370 std::istringstream ss(sCodingRate);
372 std::vector<uint32_t> output;
374 while (std::getline(ss, token,
'/'))
383 if (output.size() != 2)
385 NS_FATAL_ERROR(
"SatWaveformConf::ReadFromFile - Temp fraction vector has unexpected "
386 "amount of elements!");
389 double dCodingRate = double(output[0]) / output[1];
395 Ptr<SatWaveform> wf = Create<SatWaveform>(wfIndex,
401 preambleDurationInSymbols);
409 m_minWfId = *std::min_element(wfIds.begin(), wfIds.end());
410 m_maxWfId = *std::max_element(wfIds.begin(), wfIds.end());
416 NS_LOG_FUNCTION(
this);
418 for (std::map<uint32_t, Ptr<SatWaveform>>::iterator it =
m_waveforms.begin();
427 double ebnoRequirementDb = linkResults->GetEbNoDb(it->first,
m_targetBLER);
435 NS_LOG_FUNCTION(
this << wfId);
439 NS_FATAL_ERROR(
"SatWaveformConf::GetWaveform - unsupported waveform id: " << wfId);
453 "SatWaveformConf::GetDefaultWaveformId - unsupported waveform id: " <<
m_defaultWfId);
461 double symbolRateInBaud,
463 double& cnoThreshold,
464 uint32_t burstLength)
const
466 NS_LOG_FUNCTION(
this << cno << symbolRateInBaud << wfId << cnoThreshold << burstLength);
468 bool success =
false;
479 for (std::map<uint32_t, Ptr<SatWaveform>>::const_reverse_iterator rit =
m_waveforms.rbegin();
483 if (rit->second->GetBurstLengthInSymbols() == burstLength)
485 double cnoThr = rit->second->GetCNoThreshold(symbolRateInBaud);
490 cnoThreshold = cnoThr;
497 NS_LOG_INFO(
"Get best waveform in RTN link (ACM)! CNo: "
499 <<
", burst length: " << burstLength <<
", WF: " << wfId
508 NS_LOG_FUNCTION(
this << burstLength);
512 uint32_t payloadInBytes = std::numeric_limits<uint32_t>::max();
515 for (std::map<uint32_t, Ptr<SatWaveform>>::const_reverse_iterator rit =
m_waveforms.rbegin();
519 if (rit->second->GetBurstLengthInSymbols() == burstLength)
522 if (rit->second->GetPayloadInBytes() < payloadInBytes)
524 payloadInBytes = rit->second->GetPayloadInBytes();
537 NS_LOG_FUNCTION(
this << carrierBandwidthInHz << symbolRateInBaud);
539 for (std::map<uint32_t, Ptr<SatWaveform>>::const_iterator it =
m_waveforms.begin();
543 std::cout <<
"WaveformId: " << it->first <<
" ";
544 it->second->Dump(carrierBandwidthInHz, symbolRateInBaud);
551 NS_LOG_FUNCTION(
this << wfId);
555 NS_FATAL_ERROR(
"SatWaveformConf::GetModCod - unsupported waveform id: " << wfId);
558 std::map<uint32_t, Ptr<SatWaveform>>::const_iterator it =
m_waveforms.find(wfId);
566 NS_FATAL_ERROR(
"Waveform id: " << wfId <<
" not found in the waveform container!");
574 uint32_t codingRateNumerator,
575 uint32_t codingRateDenominator)
const
577 NS_LOG_FUNCTION(
this << modulatedBits << codingRateNumerator << codingRateDenominator);
579 switch (modulatedBits)
583 if (codingRateNumerator == 1 && codingRateDenominator == 3)
589 NS_FATAL_ERROR(
"Unsupported coding rate numerator: "
590 << codingRateNumerator <<
", denominator: " << codingRateDenominator);
596 if (codingRateNumerator == 1 && codingRateDenominator == 3)
600 else if (codingRateNumerator == 1 && codingRateDenominator == 2)
604 else if (codingRateNumerator == 2 && codingRateDenominator == 3)
608 else if (codingRateNumerator == 3 && codingRateDenominator == 4)
612 else if (codingRateNumerator == 5 && codingRateDenominator == 6)
618 NS_FATAL_ERROR(
"Unsupported coding rate numerator: "
619 << codingRateNumerator <<
", denominator: " << codingRateDenominator);
625 if (codingRateNumerator == 2 && codingRateDenominator == 3)
629 else if (codingRateNumerator == 3 && codingRateDenominator == 4)
633 else if (codingRateNumerator == 5 && codingRateDenominator == 6)
639 NS_FATAL_ERROR(
"Unsupported coding rate numerator: "
640 << codingRateNumerator <<
", denominator: " << codingRateDenominator);
646 if (codingRateNumerator == 3 && codingRateDenominator == 4)
650 else if (codingRateNumerator == 5 && codingRateDenominator == 6)
656 NS_FATAL_ERROR(
"Unsupported coding rate numerator: "
657 << codingRateNumerator <<
", denominator: " << codingRateDenominator);
663 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.