27#include "ns3/boolean.h"
28#include "ns3/double.h"
31#include "ns3/mac48-address.h"
32#include "ns3/nstime.h"
33#include "ns3/pointer.h"
34#include "ns3/simulator.h"
35#include "ns3/trace-source-accessor.h"
36#include "ns3/uinteger.h"
45NS_LOG_COMPONENT_DEFINE(
"SatFwdLinkScheduler");
54#ifdef SAT_FWD_LINK_SCHEDULER_PRINT_SORT_RESULT
56PrintSoContent(std::string context, std::vector<Ptr<SatSchedulingObject>>& so)
58 std::cout << context << std::endl;
60 for (std::vector<Ptr<SatSchedulingObject>>::const_iterator it = so.begin(); it != so.end();
63 std::cout <<
"So-Content (ptr, priority, load, hol): " << (*it) <<
", "
64 << (*it)->GetPriority() <<
", " << (*it)->GetBufferedBytes() <<
", "
65 << (*it)->GetHolDelay() << std::endl;
68 std::cout << std::endl;
75 return (
bool)(obj1->GetFlowId() < obj2->GetFlowId());
80 Ptr<SatSchedulingObject> obj2)
84 if (obj1->GetFlowId() == obj2->GetFlowId())
86 result = (bool)(obj1->GetBufferedBytes() > obj2->GetBufferedBytes());
94 Ptr<SatSchedulingObject> obj2)
98 if (obj1->GetFlowId() == obj2->GetFlowId())
100 result = (bool)(obj1->GetHolDelay() > obj2->GetHolDelay());
110 TypeId(
"ns3::SatFwdLinkScheduler")
112 .AddAttribute(
"Interval",
113 "The time for periodic scheduling",
114 TimeValue(MilliSeconds(20)),
117 .AddAttribute(
"BBFrameConf",
118 "BB Frame configuration for this scheduler.",
121 MakePointerChecker<SatBbFrameConf>())
122 .AddAttribute(
"DummyFrameSendingEnabled",
123 "Flag to tell, if dummy frames are sent or not.",
126 MakeBooleanChecker())
127 .AddAttribute(
"AdditionalSortCriteria",
128 "Sorting criteria after priority for scheduling objects from LLC.",
130 MakeEnumAccessor<SatFwdLinkScheduler::ScheduleSortingCriteria_t>(
138 .AddAttribute(
"CnoEstimationMode",
139 "Mode of the C/N0 estimator",
141 MakeEnumAccessor<SatCnoEstimator::EstimationMode_t>(
148 "AverageValueInWindow"))
149 .AddAttribute(
"CnoEstimationWindow",
150 "Time window for C/N0 estimation.",
151 TimeValue(Seconds(5000)),
156 "Scheduler symbol rate for a given packet",
158 "ns3::SatTypedefs::FwdLinkSchedulerSymbolRateCallback")
169 NS_LOG_FUNCTION(
this);
170 NS_FATAL_ERROR(
"Default constructor for SatFwdLinkScheduler not supported");
174 Mac48Address address,
175 double carrierBandwidthInHz)
182 NS_LOG_FUNCTION(
this << conf << address << carrierBandwidthInHz);
185 m_random = CreateObject<UniformRandomVariable>();
191 NS_LOG_FUNCTION(
this);
193 Object::NotifyConstructionCompleted();
200 NS_LOG_FUNCTION(
this);
206 NS_LOG_FUNCTION(
this);
216 NS_LOG_FUNCTION(
this << &cb);
223 NS_LOG_FUNCTION(
this << &cb);
230 NS_LOG_FUNCTION(
this << &cb);
237 NS_LOG_FUNCTION(
this << message << dest);
241std::pair<Ptr<SatBbFrame>,
const Time>
244 NS_FATAL_ERROR(
"SatFwdLinkScheduler::GetNextFrame: should not be here");
246 Ptr<SatBbFrame> f =
nullptr;
248 return std::make_pair(f,
m_bbFrameConf->GetDummyBbFrameDuration());
254 NS_LOG_FUNCTION(
this << utAddress << cnoEstimate);
262 std::pair<CnoEstimatorMap_t::const_iterator, bool> result =
266 if (result.second ==
false)
268 NS_FATAL_ERROR(
"Estimator cannot be added to container!!!");
272 it->second->AddSample(cnoEstimate);
278 NS_LOG_FUNCTION(
this);
293 NS_LOG_FUNCTION(
this);
295 NS_FATAL_ERROR(
"Must use subclasses");
301 NS_LOG_FUNCTION(
this);
312 NS_FATAL_ERROR(
"SatFwdLinkScheduler::GetSchedulingObjects: should not be here");
318 NS_LOG_FUNCTION(
this);
321 if ((so.empty() ==
false) && (so.size() > 1))
323#ifdef SAT_FWD_LINK_SCHEDULER_PRINT_SORT_RESULT
324 PrintSoContent(
"Before sort", so);
342 NS_FATAL_ERROR(
"Not supported sorting criteria!!!");
346#ifdef SAT_FWD_LINK_SCHEDULER_PRINT_SORT_RESULT
347 PrintSoContent(
"After sort", so);
355 NS_LOG_FUNCTION(
this << cno << frame);
361 if (modCod >= frame->GetModcod())
372 NS_LOG_FUNCTION(
this << ob);
380 cno = it->second->GetCnoEstimation();
389 NS_LOG_FUNCTION(
this);
391 Ptr<SatCnoEstimator> estimator =
nullptr;
402 NS_FATAL_ERROR(
"Not supported C/N0 estimation mode!!!");
SatCnoEstimator class defines interface for C/N0 estimators.
@ MINIMUM
Minimum value in the given window returned.
@ LAST
Last value in the given window returned.
@ AVERAGE
Average value in the given window returned.
SatModcod_t
Modulation scheme and coding rate for DVB-S2.
SatFwdLinkScheduler schedules BB frames for forward link.
TracedCallback< uint8_t, double > m_schedulingSymbolRateTrace
Traced callback for symbol rate, with flowId, requested Modcod info.
virtual void ScheduleBbFrames()=0
Schedule BB Frames.
static bool CompareSoPriorityLoad(Ptr< SatSchedulingObject > obj1, Ptr< SatSchedulingObject > obj2)
Compares to scheduling objects priorities and load.
SatCnoEstimator::EstimationMode_t m_cnoEstimatorMode
Mode used for C/N0 estimator.
SatFwdLinkScheduler::TxOpportunityCallback m_txOpportunityCallback
Callback to notify the txOpportunity to upper layer Returns a packet Attributes: payload in bytes.
double m_carrierBandwidthInHz
Carrier bandwidth in hertz where scheduler is associated to.
Time m_cnoEstimationWindow
Time window for C/N0 estimation.
void SetDummyFrameSendingEnabled(bool dummyFrameSendingEnabled)
Set the value of m_dummyFrameSendingEnabled.
CnoEstimatorMap_t m_cnoEstimatorContainer
C/N0 estimator per UT.
virtual void SendAndClearSymbolsSentStat()=0
Send stats and reset all the symbols sent count for each slice to zero.
ScheduleSortingCriteria_t m_additionalSortCriteria
Additional sorting criteria for scheduling objects received from LLC.
void DoDispose(void)
Do dispose actions.
void SortSchedulingObjects(std::vector< Ptr< SatSchedulingObject > > &so)
Sorts given scheduling objects according to configured sorting criteria.
virtual void ClearAllPackets()
Remove all packets being treated.
static TypeId GetTypeId(void)
Get the type ID.
void PeriodicTimerExpired()
Handles periodic timer timeouts.
Ptr< SatBbFrameConf > m_bbFrameConf
Configured BB Frame conf.
void SetSchedContextCallback(SatFwdLinkScheduler::SchedContextCallback cb)
Method to set Tx opportunity callback.
void CnoInfoUpdated(Mac48Address utAddress, double cnoEstimate)
Called when UT's C/N0 estimation is updated.
void GetSchedulingObjects(std::vector< Ptr< SatSchedulingObject > > &output)
Gets scheduling object in sorted order according to configured sorting criteria.
Callback< void, std::vector< Ptr< SatSchedulingObject > > & > SchedContextCallback
Callback to get scheduling contexts from upper layer.
bool m_dummyFrameSendingEnabled
Flag indicating if Dummy Frames are sent or not.
Mac48Address m_macAddress
MAC address of the this instance (node).
Callback< Ptr< Packet >, uint32_t, Mac48Address, uint8_t, uint32_t &, uint32_t & > TxOpportunityCallback
Callback to notify upper layer about Tx opportunity.
SatFwdLinkScheduler()
Construct a SatFwdLinkScheduler.
SatFwdLinkScheduler::SendControlMsgCallback m_sendControlMsgCallback
The control message sender callback.
Time GetDefaultFrameDuration() const
Return the BB frame duration of the default frame format, i.e.
Ptr< SatCnoEstimator > CreateCnoEstimator()
Create estimator for the UT according to set attributes.
Ptr< UniformRandomVariable > m_random
Random variable used in FWD link scheduling.
Time m_periodicInterval
The interval for periodic scheduling timer.
void SetSendControlMsgCallback(SatFwdLinkScheduler::SendControlMsgCallback cb)
Method to set the control message sender callback.
double GetSchedulingObjectCno(Ptr< SatSchedulingObject > ob)
virtual std::pair< Ptr< SatBbFrame >, const Time > GetNextFrame()
Get next frame to be transmitted.
bool CnoMatchWithFrame(double cno, Ptr< SatBbFrame > frame) const
Check if given estimated C/N0 match with given frame.
SatFwdLinkScheduler::SchedContextCallback m_schedContextCallback
The scheduling context getter callback.
static bool CompareSoPriorityHol(Ptr< SatSchedulingObject > obj1, Ptr< SatSchedulingObject > obj2)
Compares to scheduling objects priorities and HOL.
@ BUFFERING_DELAY_SORT
BUFFERING_DELAY_SORT.
@ BUFFERING_LOAD_SORT
BUFFERING_LOAD_SORT.
bool SendControlMsg(Ptr< SatControlMessage > message, const Address &dest) const
Method te send a control message to a destination.
~SatFwdLinkScheduler()
Destroy a SatFwdLinkScheduler.
static bool CompareSoFlowId(Ptr< SatSchedulingObject > obj1, Ptr< SatSchedulingObject > obj2)
Compares to scheduling objects priorities.
virtual void NotifyConstructionCompleted() override
Notifier called once the ObjectBase is fully constructed.
void SetTxOpportunityCallback(SatFwdLinkScheduler::TxOpportunityCallback cb)
Method to set Tx opportunity callback.
Callback< bool, Ptr< SatControlMessage >, const Address & > SendControlMsgCallback
Callback to notify upper layer about Tx opportunity.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.