31 NS_LOG_COMPONENT_DEFINE(
"SatBbFrameContainer");
36 NS_OBJECT_ENSURE_REGISTERED(SatBbFrameContainer);
39 : m_totalDuration(Seconds(0)),
40 m_defaultBbFrameType(
SatEnums::NORMAL_FRAME)
42 NS_LOG_FUNCTION(
this);
43 NS_FATAL_ERROR(
"Default constructor of SatBbFrameContainer not supported.");
47 Ptr<SatBbFrameConf> conf)
48 : m_totalDuration(Seconds(0)),
50 m_maxSymbolRate(conf->GetSymbolRate())
52 NS_LOG_FUNCTION(
this);
54 for (std::vector<SatEnums::SatModcod_t>::const_iterator it = modcodsInUse.begin();
55 it != modcodsInUse.end();
58 std::pair<FrameContainer_t::iterator, bool> result =
59 m_container.insert(std::make_pair(*it, std::deque<Ptr<SatBbFrame>>()));
61 if (result.second ==
false)
63 NS_FATAL_ERROR(
"Queue for MODCOD: " << *it <<
" already exists!!!");
77 NS_LOG_FUNCTION(
this);
86 TypeId(
"ns3::SatBbFrameContainer")
88 .AddConstructor<SatBbFrameContainer>()
89 .AddTraceSource(
"BBFrameMergeTrace",
90 "Trace for merged BB Frames.",
92 "ns3::SatBbFrame::BbFrameMergeCallback");
99 NS_LOG_FUNCTION(
this);
103 if (priorityClass == 0)
107 else if (std::isnan(cno) ==
false)
118 NS_LOG_FUNCTION(
this);
120 uint32_t payloadBytes = 0;
122 if (priorityClass > 0)
141 NS_LOG_FUNCTION(
this);
145 if (priorityClass > 0)
149 bytesLeft -=
m_container.at(modcod).back()->GetSpaceUsedInBytes();
174 NS_LOG_FUNCTION(
this);
176 if (priorityClass > 0)
189 NS_LOG_FUNCTION(
this);
191 if (priorityClass > 0)
251 Ptr<SatBbFrame> nextFrame = NULL;
261 std::vector<std::deque<Ptr<SatBbFrame>>*> nonEmptyQueues;
265 if ((*it).second.empty() ==
false)
267 nonEmptyQueues.push_back(&it->second);
271 if (nonEmptyQueues.empty() ==
false)
273 std::random_shuffle(nonEmptyQueues.begin(), nonEmptyQueues.end());
275 nextFrame = (*nonEmptyQueues.begin())->front();
276 (*nonEmptyQueues.begin())->pop_front();
287 NS_LOG_FUNCTION(
this << modcod);
293 if (priorityClass > 0)
306 NS_FATAL_ERROR(
"BB Frame creation failed!!!");
314 for (FrameContainer_t::reverse_iterator itFromMerge =
m_container.rbegin();
319 if (itFromMerge->second.empty() ==
false)
323 double occupancy = itFromMerge->second.back()->GetOccupancy();
328 if (occupancy < m_bbFrameConf->GetBbFrameHighOccupancyThreshold())
332 double weightedOccupancy =
333 itFromMerge->second.back()->GetSpectralEfficiency(carrierBandwidthInHz) *
336 double maxNewOccupancyIfMerged =
338 Ptr<SatBbFrame> frameToMerge =
342 for (FrameContainer_t::reverse_iterator itToMerge =
343 ++FrameContainer_t::reverse_iterator(itFromMerge);
348 if (itToMerge->second.empty() ==
false)
354 double occupancy2 = itToMerge->second.back()->GetOccupancy();
356 if (occupancy2 < m_bbFrameConf->GetBbFrameLowOccupancyThreshold())
358 Ptr<SatBbFrame> frame = itFromMerge->second.back();
360 double newOccupancyIfMerged =
361 itToMerge->second.back()->GetOccupancyIfMerged(frame);
363 if (newOccupancyIfMerged > maxNewOccupancyIfMerged)
365 maxNewOccupancyIfMerged = newOccupancyIfMerged;
366 frameToMerge = itToMerge->second.back();
380 double newOccupancyIfMerged =
m_ctrlContainer.back()->GetOccupancyIfMerged(
381 itFromMerge->second.back());
383 if (newOccupancyIfMerged > maxNewOccupancyIfMerged)
385 maxNewOccupancyIfMerged = newOccupancyIfMerged;
394 double newWeightedOccupancyIfMerged =
395 frameToMerge->GetSpectralEfficiency(carrierBandwidthInHz) *
396 maxNewOccupancyIfMerged;
398 if (newWeightedOccupancyIfMerged > weightedOccupancy)
402 if (frameToMerge->MergeWithFrame(itFromMerge->second.back(),
406 itFromMerge->second.pop_back();
423 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
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.