36NS_LOG_COMPONENT_DEFINE(
"SatBbFrameContainer");
47 NS_LOG_FUNCTION(
this);
48 NS_FATAL_ERROR(
"Default constructor of SatBbFrameContainer not supported.");
52 Ptr<SatBbFrameConf> conf)
57 NS_LOG_FUNCTION(
this);
59 for (std::vector<SatEnums::SatModcod_t>::const_iterator it = modcodsInUse.begin();
60 it != modcodsInUse.end();
63 std::pair<FrameContainer_t::iterator, bool> result =
64 m_container.insert(std::make_pair(*it, std::deque<Ptr<SatBbFrame>>()));
66 if (result.second ==
false)
68 NS_FATAL_ERROR(
"Queue for MODCOD: " << *it <<
" already exists!!!");
82 NS_LOG_FUNCTION(
this);
91 TypeId(
"ns3::SatBbFrameContainer")
93 .AddConstructor<SatBbFrameContainer>()
94 .AddTraceSource(
"BBFrameMergeTrace",
95 "Trace for merged BB Frames.",
97 "ns3::SatBbFrame::BbFrameMergeCallback");
104 NS_LOG_FUNCTION(
this);
108 if (priorityClass == 0)
112 else if (std::isnan(cno) ==
false)
123 NS_LOG_FUNCTION(
this);
125 uint32_t payloadBytes = 0;
127 if (priorityClass > 0)
146 NS_LOG_FUNCTION(
this);
150 if (priorityClass > 0)
154 bytesLeft -=
m_container.at(modcod).back()->GetSpaceUsedInBytes();
179 NS_LOG_FUNCTION(
this);
181 if (priorityClass > 0)
194 NS_LOG_FUNCTION(
this);
196 if (priorityClass > 0)
256 NS_LOG_FUNCTION(
this);
268 Ptr<SatBbFrame> nextFrame =
nullptr;
278 std::vector<std::deque<Ptr<SatBbFrame>>*> nonEmptyQueues;
282 if ((*it).second.empty() ==
false)
284 nonEmptyQueues.push_back(&it->second);
288 if (nonEmptyQueues.empty() ==
false)
290 std::default_random_engine rng = std::default_random_engine{};
291 std::shuffle(nonEmptyQueues.begin(), nonEmptyQueues.end(), rng);
293 nextFrame = (*nonEmptyQueues.begin())->front();
294 (*nonEmptyQueues.begin())->pop_front();
305 NS_LOG_FUNCTION(
this << modcod);
309 if (frame !=
nullptr)
311 if (priorityClass > 0)
324 NS_FATAL_ERROR(
"BB Frame creation failed!!!");
332 for (FrameContainer_t::reverse_iterator itFromMerge =
m_container.rbegin();
337 if (itFromMerge->second.empty() ==
false)
341 double occupancy = itFromMerge->second.back()->GetOccupancy();
346 if (occupancy < m_bbFrameConf->GetBbFrameHighOccupancyThreshold())
350 double weightedOccupancy =
351 itFromMerge->second.back()->GetSpectralEfficiency(carrierBandwidthInHz) *
354 double maxNewOccupancyIfMerged =
356 Ptr<SatBbFrame> frameToMerge =
360 for (FrameContainer_t::reverse_iterator itToMerge =
361 ++FrameContainer_t::reverse_iterator(itFromMerge);
366 if (itToMerge->second.empty() ==
false)
372 double occupancy2 = itToMerge->second.back()->GetOccupancy();
374 if (occupancy2 < m_bbFrameConf->GetBbFrameLowOccupancyThreshold())
376 Ptr<SatBbFrame> frame = itFromMerge->second.back();
378 double newOccupancyIfMerged =
379 itToMerge->second.back()->GetOccupancyIfMerged(frame);
381 if (newOccupancyIfMerged > maxNewOccupancyIfMerged)
383 maxNewOccupancyIfMerged = newOccupancyIfMerged;
384 frameToMerge = itToMerge->second.back();
398 double newOccupancyIfMerged =
m_ctrlContainer.back()->GetOccupancyIfMerged(
399 itFromMerge->second.back());
401 if (newOccupancyIfMerged > maxNewOccupancyIfMerged)
403 maxNewOccupancyIfMerged = newOccupancyIfMerged;
412 double newWeightedOccupancyIfMerged =
413 frameToMerge->GetSpectralEfficiency(carrierBandwidthInHz) *
414 maxNewOccupancyIfMerged;
416 if (newWeightedOccupancyIfMerged > weightedOccupancy)
420 if (frameToMerge->MergeWithFrame(itFromMerge->second.back(),
424 itFromMerge->second.pop_back();
441 if (it->second.empty() ==
false)
BB Frame container class.
virtual ~SatBbFrameContainer()
Destructor.
Ptr< SatBbFrameConf > m_bbFrameConf
static TypeId GetTypeId(void)
Get the type ID.
uint32_t GetMaxFramePayloadInBytes(uint32_t priorityClass, SatEnums::SatModcod_t modcod)
Get maximum payload bytes of a frame with the given priority class and MODCOD.
uint32_t GetBytesLeftInTailFrame(uint32_t priorityClass, SatEnums::SatModcod_t modcod)
Get bytes left in last frame of the queue with the given priority class and MODCOD.
void SetMaxSymbolRate(uint32_t maxSymbolRate)
Set the maximum symbol rate of this container, used for time-slicing.
uint32_t GetMaxSymbolRate()
Set the maximum symbol rate of this container, used for time-slicing.
Time GetTotalDuration() const
Get total transmission duration of the frames in container.
void MergeBbFrames(double carrierBandwidthInHz)
FrameContainer_t m_container
Ptr< SatBbFrame > GetNextFrame()
Get next frame from container to transmit.
TracedCallback< Ptr< SatBbFrame >, Ptr< SatBbFrame > > m_bbFrameMergeTrace
Trace for merged BB frames.
uint32_t GetFrameSymbols(SatEnums::SatModcod_t modcod)
Get the total number of symbols, incuding headers, when creating a new BBFrame.
bool IsEmpty(uint32_t priorityClass, SatEnums::SatModcod_t modcod)
Indicates if the container for a ModCod and priority is empty (no BBFrame).
std::deque< Ptr< SatBbFrame > > m_ctrlContainer
void CreateFrameToTail(uint32_t priorityClass, SatEnums::SatModcod_t modcod)
Create short or normal frame according to MODCOD and member m_bbFrameUsageMode.
void AddData(uint32_t priorityClass, SatEnums::SatModcod_t modcod, Ptr< Packet > data)
Add data according to given priority class and MODCOD to container.
SatEnums::SatBbFrameType_t m_defaultBbFrameType
void ClearAllFrames()
Remove all frames in containers.
SatBbFrameContainer()
Default constructor for SatBbFrameContainer not supported.
SatEnums::SatModcod_t GetModcod(uint32_t priorityClass, double cno)
Get maximum MODCOD with the given priority class and C/N0.
SatEnums class is for simplifying the use of enumerators in the satellite module.
SatModcod_t
Modulation scheme and coding rate for DVB-S2.
@ SHORT_AND_NORMAL_FRAMES
SHORT_AND_NORMAL_FRAMES.
@ SHORT_FRAMES
SHORT_FRAMES.
constexpr uint32_t BITS_PER_BYTE
Number of bits in a byte.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.