29#include "ns3/boolean.h"
30#include "ns3/double.h"
33#include "ns3/nstime.h"
34#include "ns3/simulator.h"
43NS_LOG_COMPONENT_DEFINE(
"SatRequestManager");
75 NS_LOG_FUNCTION(
this);
85 NS_LOG_FUNCTION(
this << superFrameDuration.GetSeconds());
90 std::vector<std::deque<std::pair<Time, uint32_t>>>(
m_llsConf->GetDaServiceCount(),
91 std::deque<std::pair<Time, uint32_t>>());
100 Simulator::ScheduleWithContext(
m_nodeInfo->GetNodeId(),
114 TypeId(
"ns3::SatRequestManager")
116 .AddConstructor<SatRequestManager>()
117 .AddAttribute(
"EvaluationInterval",
118 "Evaluation interval time",
119 TimeValue(Seconds(0.1)),
122 .AddAttribute(
"CnoReportInterval",
123 "C/NO report interval time",
124 TimeValue(Seconds(1.1)),
127 .AddAttribute(
"RttEstimate",
128 "Round trip time estimate for request manager",
129 TimeValue(MilliSeconds(560)),
132 .AddAttribute(
"OverEstimationFactor",
133 "Over-estimation due to RLE and FPDU overhead.",
136 MakeDoubleChecker<double_t>())
137 .AddAttribute(
"EnableOnDemandEvaluation",
138 "Enable on-demand resource evaluation.",
141 MakeBooleanChecker())
142 .AddAttribute(
"GainValueK",
143 "Gain value K for RBDC calculation.",
146 MakeDoubleChecker<double_t>())
147 .AddAttribute(
"RbdcCapacityRequestAlgorithm",
148 "Algorithm to calculate RBDC capacity requests.",
150 MakeEnumAccessor<SatEnums::RbdcCapacityRequestAlgorithm_t>(
153 .AddAttribute(
"VbdcCapacityRequestAlgorithm",
154 "Algorithm to calculate VBDC capacity requests.",
156 MakeEnumAccessor<SatEnums::VbdcCapacityRequestAlgorithm_t>(
159 .AddTraceSource(
"CrTrace",
160 "Capacity request trace",
162 "ns3::SatRequestManager::CapacityRequestTraceCallback")
163 .AddTraceSource(
"CrTraceLog",
164 "Capacity request trace log",
166 "ns3::SatRequestManager::CapacityRequestTraceLogCallback")
167 .AddTraceSource(
"RbdcTrace",
168 "Trace for all sent RBDC capacity requests.",
170 "ns3::SatRequestManager::RbdcTraceCallback")
171 .AddTraceSource(
"VbdcTrace",
172 "Trace for all sent VBDC capacity requests.",
174 "ns3::SatRequestManager::VbdcTraceCallback")
175 .AddTraceSource(
"AvbdcTrace",
176 "Trace for all sent AVBDC capacity requests.",
178 "ns3::SatRequestManager::AvbdcTraceCallback");
185 NS_LOG_FUNCTION(
this);
190 it->second.Nullify();
207 NS_LOG_FUNCTION(
this << event << (uint32_t)(rcIndex));
211 NS_LOG_INFO(
"FIRST_BUFFERED_PKT event received from queue: " << (uint32_t)(rcIndex));
215 NS_LOG_INFO(
"Do on-demand CR evaluation for RC index: " << (uint32_t)(rcIndex));
225 NS_LOG_FUNCTION(
this);
236 NS_LOG_FUNCTION(
this);
238 NS_LOG_INFO(
"---Start request manager evaluation---");
246 if (ctrlMsgTxPossible)
256 Ptr<SatCrMessage> crMsg = CreateObject<SatCrMessage>();
259 for (uint8_t rc = 0; rc <
m_llsConf->GetDaServiceCount(); ++rc)
266 NS_LOG_INFO(
"Evaluating the needs for RC: " << (uint32_t)(rc));
267 NS_LOG_INFO(
"RC: " << (uint32_t)(rc)
269 NS_LOG_INFO(
"RC: " << (uint32_t)(rc)
271 NS_LOG_INFO(
"RC: " << (uint32_t)(rc) <<
" volume in: " << stats.
m_volumeInBytes
273 NS_LOG_INFO(
"RC: " << (uint32_t)(rc) <<
" volume out: " << stats.
m_volumeOutBytes
275 NS_LOG_INFO(
"RC: " << (uint32_t)(rc)
281 NS_LOG_INFO(
"Evaluating RBDC needs for RC: " << (uint32_t)(rc));
282 uint32_t rbdcRateKbps =
DoRbdc(rc, stats);
284 NS_LOG_INFO(
"Requested RBDC rate for RC: " << (uint32_t)(rc) <<
" is "
285 << rbdcRateKbps <<
" kbps");
287 if (rbdcRateKbps > 0)
292 std::stringstream ss;
293 ss << Simulator::Now().GetSeconds() <<
", " <<
m_nodeInfo->GetNodeId()
294 <<
", " <<
static_cast<uint32_t
>(rc) <<
", "
305 NS_LOG_INFO(
"Evaluation VBDC for RC: " << (uint32_t)(rc));
307 uint32_t vbdcBytes(0);
316 crMsg->AddControlElement(rc, cac, vbdcBytes);
321 std::stringstream ss;
322 ss << Simulator::Now().GetSeconds() <<
", " <<
m_nodeInfo->GetNodeId()
323 <<
", " <<
static_cast<uint32_t
>(rc) <<
", "
338 NS_LOG_INFO(
"Requested VBDC volume for RC: " << (uint32_t)(rc) <<
" is "
340 <<
" Bytes with CAC: " << cac);
346 NS_LOG_INFO(
"Evaluation RBDC+VBDC for RC: " << (uint32_t)(rc));
353 "Simultaneous RBDC and VBDC for one RC is not currently supported!");
358 NS_LOG_INFO(
"RBDC nor VBDC was configured for RC: " << (uint32_t)(rc));
367 if (crMsg->IsNotEmpty())
369 NS_LOG_INFO(
"Send CR");
378 NS_LOG_INFO(
"No transmission possibility, thus skipping CR evaluation!");
381 NS_LOG_INFO(
"---End request manager evaluation---");
387 NS_LOG_FUNCTION(
this << (uint32_t)(rcIndex) << &cb);
394 NS_LOG_FUNCTION(
this << &cb);
401 NS_LOG_FUNCTION(
this << &cb);
408 NS_LOG_FUNCTION(
this << &cb);
415 NS_LOG_FUNCTION(
this << address);
422 NS_LOG_FUNCTION(
this);
435 NS_LOG_FUNCTION(
this << satId << beamId << cno);
437 NS_LOG_INFO(
"C/No updated to request manager: " << cno);
453 NS_LOG_FUNCTION(
this);
461 NS_FATAL_ERROR(
"SatRequestManager::DoRbdc - Invalid RBDC algorithm!");
465 NS_FATAL_ERROR(
"SatRequestManager::DoRbdc - Invalid RBDC algorithm!");
472 NS_LOG_FUNCTION(
this << (uint32_t)(rc));
482 double thisRbdcInKbits = inRateKbps * duration.GetSeconds();
487 double queueOccupancy =
489 m_gainValueK * (queueSizeInKbits - thisRbdcInKbits - previousRbdcInKbits) /
490 duration.GetSeconds());
492 double reqRbdcKbps = inRateKbps + queueOccupancy;
494 NS_LOG_INFO(
"queueSizeInKbits: " << queueSizeInKbits <<
" thisRbdcInKbits: " << thisRbdcInKbits
495 <<
" previousRbdcInKbits " << previousRbdcInKbits);
497 NS_LOG_INFO(
"In rate: " << inRateKbps <<
" queueOccupancy: " << queueOccupancy);
500 if (
m_llsConf->GetDaConstantAssignmentProvided(rc))
503 if (reqRbdcKbps <= m_llsConf->GetDaConstantServiceRateInKbps(rc))
510 reqRbdcKbps -=
m_llsConf->GetDaConstantServiceRateInKbps(rc);
513 if (
m_llsConf->GetDaConstantServiceRateInKbps(rc) >
514 m_llsConf->GetDaMaximumServiceRateInKbps(rc))
516 NS_FATAL_ERROR(
"SatRequestManager::DoRbdcLegacy - configured CRA is bigger than "
517 "maximum RBDC for RC: "
522 if ((
m_llsConf->GetDaConstantServiceRateInKbps(rc) + reqRbdcKbps) >
523 m_llsConf->GetDaMaximumServiceRateInKbps(rc))
525 reqRbdcKbps =
m_llsConf->GetDaMaximumServiceRateInKbps(rc) -
526 m_llsConf->GetDaConstantServiceRateInKbps(rc);
530 else if (reqRbdcKbps >
m_llsConf->GetDaMaximumServiceRateInKbps(rc))
532 reqRbdcKbps =
m_llsConf->GetDaMaximumServiceRateInKbps(rc);
535 NS_LOG_INFO(
"RBDC bitrate after CRA as been taken off: " << reqRbdcKbps <<
" kbps");
539 NS_LOG_INFO(
"Quantized RBDC bitrate: " << crRbdcKbps <<
" kbps");
549 NS_LOG_FUNCTION(
this);
557 NS_FATAL_ERROR(
"SatRequestManager::DoVbdc - Invalid VBDC algorithm!");
561 NS_FATAL_ERROR(
"SatRequestManager::DoVbdc - Invalid VBDC algorithm!");
568 uint32_t& rcVbdcBytes)
570 NS_LOG_FUNCTION(
this << (uint32_t)(rc));
572 uint32_t vbdcBytes(0);
586 NS_LOG_INFO(
"VBDC volume in for RC: " << (uint32_t)(rc) <<
": " << stats.
m_volumeInBytes
604 rcVbdcBytes = vbdcBytes;
612 NS_LOG_FUNCTION(
this << (uint32_t)(rc));
616 uint32_t craBytes(0);
620 if (
m_llsConf->GetDaConstantAssignmentProvided(rc))
622 NS_LOG_INFO(
"CRA is enabled together with VBDC for RC: " << (uint32_t)(rc));
630 m_llsConf->GetDaConstantServiceRateInKbps(rc) * duration.GetSeconds()) /
635 if (craBytes < vbdcBytes)
637 vbdcBytes -= craBytes;
643 NS_LOG_INFO(
"Pending VBDC bytes: " << (uint32_t)(rc) <<
": " <<
m_pendingVbdcBytes.at(rc)
657 NS_LOG_FUNCTION(
this << (uint32_t)(rc));
659 uint32_t craBytes(0);
663 if (
m_llsConf->GetDaConstantAssignmentProvided(rc))
665 NS_LOG_INFO(
"CRA is enabled together with VBDC for RC: " << (uint32_t)(rc));
673 m_llsConf->GetDaConstantServiceRateInKbps(rc) * duration.GetSeconds()) /
678 if (craBytes < vbdcBytes)
680 vbdcBytes -= craBytes;
682 NS_LOG_INFO(
"VBDC volume after CRA for RC: " << (uint32_t)(rc) <<
": " << vbdcBytes
688 NS_LOG_INFO(
"Pending VBDC bytes: " << (uint32_t)(rc) <<
": " <<
m_pendingVbdcBytes.at(rc)
690 NS_LOG_INFO(
"VBDC volume after pending: " << (uint32_t)(rc) <<
": " << vbdcBytes
704 NS_LOG_FUNCTION(
this);
735 NS_LOG_FUNCTION(
this << (uint32_t)(rc));
742 for (std::deque<std::pair<Time, uint32_t>>::const_iterator it = cont.begin(); it != cont.end();
746 value += (*it).second;
749 NS_LOG_INFO(
"Pending RBDC sum for RC: " << (uint32_t)(rc) <<
" is " << value);
757 NS_LOG_FUNCTION(
this << (uint32_t)(rc) << kbps);
761 Time now = Simulator::Now();
762 std::pair<Time, uint32_t> item = std::make_pair(now, kbps);
770 NS_LOG_FUNCTION(
this << (uint32_t)(rc));
773 std::deque<std::pair<Time, uint32_t>>::const_iterator it = cont.begin();
775 while (it != cont.end())
792 NS_LOG_FUNCTION(
this);
794 for (uint8_t rc = 0; rc <
m_llsConf->GetDaServiceCount(); rc++)
803 NS_LOG_FUNCTION(
this << (uint32_t)(rc));
827 NS_LOG_FUNCTION(
this);
834 NS_LOG_INFO(
"Send C/N0 report to GW: " <<
m_gwAddress);
845 NS_FATAL_ERROR(
"Unable to send capacity request, since the Ctrl callback is NULL!");
856 NS_LOG_FUNCTION(
this);
863 if (ctrlMsgTxPossible &&
m_lastCno != NAN)
865 NS_LOG_INFO(
"Send C/No report to GW: " <<
m_gwAddress);
867 Ptr<SatCnoReportMessage> cnoReport = CreateObject<SatCnoReportMessage>();
877 NS_LOG_INFO(
"Send C/No report to SAT user: " <<
m_satAddress);
878 Ptr<SatCnoReportMessage> cnoReport = CreateObject<SatCnoReportMessage>();
894 NS_LOG_FUNCTION(
this << beamId);
899 NS_LOG_INFO(
"Send handover recommendation to GW: " <<
m_gwAddress);
901 Ptr<SatHandoverRecommendationMessage> hoRecommendation =
902 CreateObject<SatHandoverRecommendationMessage>();
903 hoRecommendation->SetRecommendedBeamId(beamId);
904 hoRecommendation->SetRecommendedSatId(satId);
913 NS_LOG_FUNCTION(
this);
919 NS_LOG_INFO(
"Send logon message to GW: " <<
m_gwAddress);
921 Ptr<SatLogonMessage> logonMessage = CreateObject<SatLogonMessage>();
935 NS_LOG_FUNCTION(
this << (uint32_t)(rcIndex) << bytes);
937 NS_LOG_INFO(
"TBTP resources assigned for RC: " << (uint32_t)(rcIndex) <<
" bytes: " << bytes);
945 NS_LOG_FUNCTION(
this);
947 for (uint32_t i = 0; i <
m_llsConf->GetDaServiceCount(); ++i)
956 NS_LOG_FUNCTION(
this << (uint32_t)(rc));
965 NS_LOG_FUNCTION(
this << (uint32_t)(index) << reqRbdcKbps);
967 uint32_t maxRbdc =
m_llsConf->GetDaMaximumServiceRateInKbps(index);
968 uint32_t quantValue(0);
971 if (reqRbdcKbps > maxRbdc)
977 for (uint32_t i = 0; i < 4; i++)
988 NS_FATAL_ERROR(
"Quantized value for RBDC not calculated!");
996 NS_LOG_FUNCTION(
this << (uint32_t)(index) << reqVbdcBytes);
998 uint32_t maxBacklogBytes =
1000 uint32_t quantValue(0);
1003 if (reqVbdcBytes > maxBacklogBytes)
1005 return maxBacklogBytes;
1009 for (uint32_t i = 0; i < 4; ++i)
1020 NS_FATAL_ERROR(
"Quantized value for VBDC not calculated!");
SatEnums class is for simplifying the use of enumerators in the satellite module.
SatCapacityAllocationCategory_t
Definition for different types of Capacity Request (CR) messages.
static std::string GetCapacityAllocationCategory(SatCapacityAllocationCategory_t cac)
SatRequestManager analyzes periodically or on-a-need-basis UT's buffer status for different RC indice...
Time m_superFrameDuration
Superframe duration used for updating the volume backlog persistence.
double m_overEstimationFactor
Over-estimation factor used for estimating a bit more resources than there are in the buffers.
SatEnums::RbdcCapacityRequestAlgorithm_t m_rbdcCapacityRequestAlgorithm
The RBDC capacity algorithm to use.
SatEnums::SatCapacityAllocationCategory_t DoVbdcLegacy(uint8_t rc, const SatQueue::QueueStats_t &stats, uint32_t &rcVbdcBytes)
Legacy algorithm to do VBDC calculation for a RC.
void Reset(uint8_t rc)
Reset RC index counters.
SendCtrlCallback m_ctrlCallback
Callback to send control messages.
PendingRbdcRequestsContainer_t m_pendingRbdcRequestsKbps
Key = RC index Value -> Key = Time when the request was sent Value -> Value = Requested bitrate or by...
void AssignedDaResources(uint8_t rcIndex, uint32_t bytes)
Sat UT MAC informs that certain amount of resources have been received in TBTP.
TracedCallback< uint32_t > m_aVbdcTrace
double m_lastSatelliteCno
The last received user link C/N0 information from lower layer in linear format.
void SetLogonMsgTxPossibleCallback(SatRequestManager::LogonMsgTxPossibleCallback cb)
Set the callback to check the possibility of sending a control message.
TracedCallback< std::string > m_crTraceLog
Trace callback used for CR tracing.
void SendLogonMessage()
Send a logon message to the gateway.
Ptr< SatLowerLayerServiceConf > m_llsConf
Lower layer services conf pointer, which holds the configurations for RCs and capacity allocation cat...
static TypeId GetTypeId(void)
inherited from Object
void ReceiveQueueEvent(SatQueue::QueueEvent_t event, uint8_t rcIndex)
Receive a queue event.
void RemoveOldEntriesFromPendingRbdcContainer(uint8_t rc)
Clean-up the pending RBDC container from old samples.
void Initialize(Ptr< SatLowerLayerServiceConf > llsConf, Time superFrameDuration)
Mac48Address m_gwAddress
GW address.
uint32_t GetVbdcBytes(uint8_t rc, const SatQueue::QueueStats_t &stats)
Calculate the needed VBDC bytes for a RC.
LogonMsgTxPossibleCallback m_logonMsgTxPossibleCallback
Callback to check from MAC if a logon msg may be transmitted in the near future.
uint16_t GetQuantizedRbdcValue(uint8_t index, uint16_t reqRbdcKbps) const
The RBDC value is signalled with 8 bits, which means that to be able to signal larger than 256 values...
void UpdatePendingRbdcCounters(uint8_t rc, uint32_t kbps)
Update the pending RBDC counters with new request information.
Callback< SatQueue::QueueStats_t, bool > QueueCallback
Callback to fetch queue statistics.
SatEnums::VbdcCapacityRequestAlgorithm_t m_vbdcCapacityRequestAlgorithm
The VBDC capacity algorithm to use.
void UpdatePendingVbdcCounters()
Update pending VBDC counters for all RCs.
Ptr< SatNodeInfo > m_nodeInfo
Node information.
virtual ~SatRequestManager()
Destructor for SatRequestManager.
uint32_t GetPendingRbdcSumKbps(uint8_t rc)
Calculate the pending RBDC requests related to a specific RC.
Callback< bool > CtrlMsgTxPossibleCallback
Callback to check whether control msg transmission is possible.
void DoPeriodicalEvaluation()
Periodically check the buffer status and whether a new CR is needed to be sent.
void SetCtrlMsgTxPossibleCallback(SatRequestManager::CtrlMsgTxPossibleCallback cb)
Set the callback to check the possibility of sending a control message.
SatEnums::SatCapacityAllocationCategory_t DoVbdc(uint8_t rc, const SatQueue::QueueStats_t &stats, uint32_t &rcVbdcBytes)
Do VBDC calculation for a RC.
static const uint32_t m_rbdcScalingFactors[4]
std::vector< uint32_t > m_pendingVbdcBytes
Pending VBDC counter for each RC index.
Mac48Address m_satAddress
SAT address.
void SetNodeInfo(Ptr< SatNodeInfo > nodeInfo)
Set the node info of this UT.
virtual void DoDispose()
Dispose of this class instance.
TracedCallback< uint32_t > m_rbdcTrace
Traced callbacks for all sent RBDC and VBDC capacity requests.
void SendCnoReport()
Send the C/N0 report message via txCallback to SatNetDevice.
void ResetAssignedResources()
Reset the assigned resources counter.
uint32_t GetAvbdcBytes(uint8_t rc, const SatQueue::QueueStats_t &stats)
Calculate the needed AVBDC bytes for a RC.
uint16_t GetQuantizedVbdcValue(uint8_t index, uint16_t reqVbdcBytes) const
The RBDC value is signalled with 8 bits, which means that to be able to signal larger than 256 values...
double m_gainValueK
Gain value K for the RBDC calculation.
Callback< bool, Ptr< SatControlMessage >, const Address & > SendCtrlCallback
Control message sending callback.
void DoEvaluation()
Do evaluation of the buffer status and decide whether or not to send CRs.
uint32_t DoRbdcLegacy(uint8_t rc, const SatQueue::QueueStats_t &stats)
Legacy algorithm to do RBDC calculation for a RC.
void AddQueueCallback(uint8_t rcIndex, SatRequestManager::QueueCallback cb)
Add a callback to fetch queue statistics.
EventId m_cnoReportEvent
Event id for the C/NO report.
uint32_t DoRbdc(uint8_t rc, const SatQueue::QueueStats_t &stats)
Do RBDC calculation for a RC.
static const uint32_t m_vbdcScalingFactors[4]
Time m_rttEstimate
Round trip time estimate.
TracedCallback< Time, Mac48Address, Ptr< SatCrMessage > > m_crTrace
Trace callback used for CR tracing.
TracedCallback< uint32_t > m_vbdcTrace
std::vector< uint32_t > m_assignedDaResourcesBytes
Dedicated assignments received within the previous superframe.
Time m_lastVbdcCrSent
Time when the last CR including VBDC request was sent.
double m_lastCno
The last received on E2E C/N0 information from lower layer in linear format.
Time m_cnoReportInterval
Interval to send C/N0 report.
void SetGwAddress(Mac48Address address)
Set the GW address needed for CR transmission.
bool m_forcedAvbdcUpdate
Flag indicating that UT should send a forced AVBDC request, since the volume backlog persistence shal...
void SendCapacityRequest(Ptr< SatCrMessage > crMsg)
Send the capacity request control msg via txCallback to SatNetDevice.
Time m_evaluationInterval
Interval to do the periodical CR evaluation.
double m_headerOffsetVbcd
Additional VBDC to add to take into account E2E header in regenerative LINK or NETWORK,...
bool m_enableOnDemandEvaluation
Enable on demand / ad hoc CR evaluation.
void CheckForVolumeBacklogPersistence()
Check whether VBDC volume backlog persistence shall expire and whether UT should update request by AV...
void SetHeaderOffsetVbdc(double headerOffsetVbcd)
Update the value of header offset.
CtrlMsgTxPossibleCallback m_ctrlMsgTxPossibleCallback
Callback to check from MAC if a control msg may be transmitted in the near future.
SatRequestManager()
Default constructor.
void CnoUpdated(uint32_t satId, uint32_t beamId, Address sourceMac, Address gwId, double cno, bool isSatelliteMac)
Update C/N0 information from lower layer.
void SetCtrlMsgCallback(SatRequestManager::SendCtrlCallback cb)
Set the control message sending callback.
CallbackContainer_t m_queueCallbacks
The queue enque/deque rate getter callback.
void SendHandoverRecommendation(uint32_t satId, uint32_t beamId)
Send a handover recommendation message to the gateway.
std::vector< Time > m_previousEvaluationTime
Time when CR evaluation was previously done.
Callback< bool > LogonMsgTxPossibleCallback
Callback to check whether logon msg transmission is possible.
constexpr uint32_t BITS_IN_KBIT
Number of bits consisting a kilobit.
constexpr uint32_t BITS_PER_BYTE
Number of bits in a byte.
constexpr uint32_t BYTES_IN_KBYTE
Number of bytes consisting a kilobyte.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
QueueStats_t definition for passing queue related statistics to any interested modules.
uint32_t m_volumeOutBytes
double m_outgoingRateKbps
double m_incomingRateKbps
uint32_t m_queueSizeBytes