35 NS_LOG_COMPONENT_DEFINE(
"SatBbFrameContainer");
40 NS_OBJECT_ENSURE_REGISTERED(SatBbFrameContainer);
43 : m_totalDuration(Seconds(0)),
44 m_defaultBbFrameType(
SatEnums::NORMAL_FRAME)
46 NS_LOG_FUNCTION(
this);
47 NS_FATAL_ERROR(
"Default constructor of SatBbFrameContainer not supported.");
51 Ptr<SatBbFrameConf> conf)
52 : m_totalDuration(Seconds(0)),
54 m_maxSymbolRate(conf->GetSymbolRate())
56 NS_LOG_FUNCTION(
this);
58 for (std::vector<SatEnums::SatModcod_t>::const_iterator it = modcodsInUse.begin();
59 it != modcodsInUse.end();
62 std::pair<FrameContainer_t::iterator, bool> result =
63 m_container.insert(std::make_pair(*it, std::deque<Ptr<SatBbFrame>>()));
65 if (result.second ==
false)
67 NS_FATAL_ERROR(
"Queue for MODCOD: " << *it <<
" already exists!!!");
81 NS_LOG_FUNCTION(
this);
90 TypeId(
"ns3::SatBbFrameContainer")
92 .AddConstructor<SatBbFrameContainer>()
93 .AddTraceSource(
"BBFrameMergeTrace",
94 "Trace for merged BB Frames.",
96 "ns3::SatBbFrame::BbFrameMergeCallback");
103 NS_LOG_FUNCTION(
this);
107 if (priorityClass == 0)
111 else if (std::isnan(cno) ==
false)
122 NS_LOG_FUNCTION(
this);
124 uint32_t payloadBytes = 0;
126 if (priorityClass > 0)
145 NS_LOG_FUNCTION(
this);
149 if (priorityClass > 0)
153 bytesLeft -=
m_container.at(modcod).back()->GetSpaceUsedInBytes();
178 NS_LOG_FUNCTION(
this);
180 if (priorityClass > 0)
193 NS_LOG_FUNCTION(
this);
195 if (priorityClass > 0)
255 NS_LOG_FUNCTION(
this);
267 Ptr<SatBbFrame> nextFrame =
nullptr;
277 std::vector<std::deque<Ptr<SatBbFrame>>*> nonEmptyQueues;
281 if ((*it).second.empty() ==
false)
283 nonEmptyQueues.push_back(&it->second);
287 if (nonEmptyQueues.empty() ==
false)
289 std::random_shuffle(nonEmptyQueues.begin(), nonEmptyQueues.end());
291 nextFrame = (*nonEmptyQueues.begin())->front();
292 (*nonEmptyQueues.begin())->pop_front();
303 NS_LOG_FUNCTION(
this << modcod);
307 if (frame !=
nullptr)
309 if (priorityClass > 0)
322 NS_FATAL_ERROR(
"BB Frame creation failed!!!");
330 for (FrameContainer_t::reverse_iterator itFromMerge =
m_container.rbegin();
335 if (itFromMerge->second.empty() ==
false)
339 double occupancy = itFromMerge->second.back()->GetOccupancy();
344 if (occupancy < m_bbFrameConf->GetBbFrameHighOccupancyThreshold())
348 double weightedOccupancy =
349 itFromMerge->second.back()->GetSpectralEfficiency(carrierBandwidthInHz) *
352 double maxNewOccupancyIfMerged =
354 Ptr<SatBbFrame> frameToMerge =
358 for (FrameContainer_t::reverse_iterator itToMerge =
359 ++FrameContainer_t::reverse_iterator(itFromMerge);
364 if (itToMerge->second.empty() ==
false)
370 double occupancy2 = itToMerge->second.back()->GetOccupancy();
372 if (occupancy2 < m_bbFrameConf->GetBbFrameLowOccupancyThreshold())
374 Ptr<SatBbFrame> frame = itFromMerge->second.back();
376 double newOccupancyIfMerged =
377 itToMerge->second.back()->GetOccupancyIfMerged(frame);
379 if (newOccupancyIfMerged > maxNewOccupancyIfMerged)
381 maxNewOccupancyIfMerged = newOccupancyIfMerged;
382 frameToMerge = itToMerge->second.back();
396 double newOccupancyIfMerged =
m_ctrlContainer.back()->GetOccupancyIfMerged(
397 itFromMerge->second.back());
399 if (newOccupancyIfMerged > maxNewOccupancyIfMerged)
401 maxNewOccupancyIfMerged = newOccupancyIfMerged;
410 double newWeightedOccupancyIfMerged =
411 frameToMerge->GetSpectralEfficiency(carrierBandwidthInHz) *
412 maxNewOccupancyIfMerged;
414 if (newWeightedOccupancyIfMerged > weightedOccupancy)
418 if (frameToMerge->MergeWithFrame(itFromMerge->second.back(),
422 itFromMerge->second.pop_back();
439 if (it->second.empty() ==
false)
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.