29 #include <ns3/boolean.h>
30 #include <ns3/double.h>
33 #include <ns3/nstime.h>
34 #include <ns3/simulator.h>
38 NS_LOG_COMPONENT_DEFINE(
"SatRequestManager");
43 NS_OBJECT_ENSURE_REGISTERED(SatRequestManager);
53 m_evaluationInterval(Seconds(0.1)),
54 m_cnoReportInterval(Seconds(0.0)),
56 m_rttEstimate(MilliSeconds(560)),
57 m_overEstimationFactor(1.1),
58 m_enableOnDemandEvaluation(false),
59 m_pendingRbdcRequestsKbps(),
61 m_previousEvaluationTime(),
62 m_lastVbdcCrSent(Seconds(0)),
63 m_superFrameDuration(Seconds(0)),
64 m_forcedAvbdcUpdate(false),
66 m_rbdcCapacityRequestAlgorithm(
SatEnums::CR_RBDC_LEGACY),
67 m_vbdcCapacityRequestAlgorithm(
SatEnums::CR_VBDC_LEGACY),
68 m_headerOffsetVbcd(1.0)
70 NS_LOG_FUNCTION(
this);
80 NS_LOG_FUNCTION(
this << superFrameDuration.GetSeconds());
85 std::vector<std::deque<std::pair<Time, uint32_t>>>(
m_llsConf->GetDaServiceCount(),
86 std::deque<std::pair<Time, uint32_t>>());
95 Simulator::ScheduleWithContext(
m_nodeInfo->GetNodeId(),
109 TypeId(
"ns3::SatRequestManager")
111 .AddConstructor<SatRequestManager>()
112 .AddAttribute(
"EvaluationInterval",
113 "Evaluation interval time",
114 TimeValue(Seconds(0.1)),
117 .AddAttribute(
"CnoReportInterval",
118 "C/NO report interval time",
119 TimeValue(Seconds(1.1)),
122 .AddAttribute(
"RttEstimate",
123 "Round trip time estimate for request manager",
124 TimeValue(MilliSeconds(560)),
127 .AddAttribute(
"OverEstimationFactor",
128 "Over-estimation due to RLE and FPDU overhead.",
131 MakeDoubleChecker<double_t>())
132 .AddAttribute(
"EnableOnDemandEvaluation",
133 "Enable on-demand resource evaluation.",
136 MakeBooleanChecker())
137 .AddAttribute(
"GainValueK",
138 "Gain value K for RBDC calculation.",
141 MakeDoubleChecker<double_t>())
142 .AddAttribute(
"RbdcCapacityRequestAlgorithm",
143 "Algorithm to calculate RBDC capacity requests.",
147 .AddAttribute(
"VbdcCapacityRequestAlgorithm",
148 "Algorithm to calculate VBDC capacity requests.",
152 .AddTraceSource(
"CrTrace",
153 "Capacity request trace",
155 "ns3::SatRequestManager::CapacityRequestTraceCallback")
156 .AddTraceSource(
"CrTraceLog",
157 "Capacity request trace log",
159 "ns3::SatRequestManager::CapacityRequestTraceLogCallback")
160 .AddTraceSource(
"RbdcTrace",
161 "Trace for all sent RBDC capacity requests.",
163 "ns3::SatRequestManager::RbdcTraceCallback")
164 .AddTraceSource(
"VbdcTrace",
165 "Trace for all sent VBDC capacity requests.",
167 "ns3::SatRequestManager::VbdcTraceCallback")
168 .AddTraceSource(
"AvbdcTrace",
169 "Trace for all sent AVBDC capacity requests.",
171 "ns3::SatRequestManager::AvbdcTraceCallback");
178 NS_LOG_FUNCTION(
this);
186 NS_LOG_FUNCTION(
this);
191 it->second.Nullify();
208 NS_LOG_FUNCTION(
this << event << (uint32_t)(rcIndex));
212 NS_LOG_INFO(
"FIRST_BUFFERED_PKT event received from queue: " << (uint32_t)(rcIndex));
216 NS_LOG_INFO(
"Do on-demand CR evaluation for RC index: " << (uint32_t)(rcIndex));
226 NS_LOG_FUNCTION(
this);
237 NS_LOG_FUNCTION(
this);
239 NS_LOG_INFO(
"---Start request manager evaluation---");
247 if (ctrlMsgTxPossible)
257 Ptr<SatCrMessage> crMsg = CreateObject<SatCrMessage>();
260 for (uint8_t rc = 0; rc <
m_llsConf->GetDaServiceCount(); ++rc)
267 NS_LOG_INFO(
"Evaluating the needs for RC: " << (uint32_t)(rc));
268 NS_LOG_INFO(
"RC: " << (uint32_t)(rc)
270 NS_LOG_INFO(
"RC: " << (uint32_t)(rc)
272 NS_LOG_INFO(
"RC: " << (uint32_t)(rc) <<
" volume in: " << stats.
m_volumeInBytes
274 NS_LOG_INFO(
"RC: " << (uint32_t)(rc) <<
" volume out: " << stats.
m_volumeOutBytes
276 NS_LOG_INFO(
"RC: " << (uint32_t)(rc)
282 NS_LOG_INFO(
"Evaluating RBDC needs for RC: " << (uint32_t)(rc));
283 uint32_t rbdcRateKbps =
DoRbdc(rc, stats);
285 NS_LOG_INFO(
"Requested RBDC rate for RC: " << (uint32_t)(rc) <<
" is "
286 << rbdcRateKbps <<
" kbps");
288 if (rbdcRateKbps > 0)
293 std::stringstream ss;
294 ss << Simulator::Now().GetSeconds() <<
", " <<
m_nodeInfo->GetNodeId()
295 <<
", " <<
static_cast<uint32_t
>(rc) <<
", "
306 NS_LOG_INFO(
"Evaluation VBDC for RC: " << (uint32_t)(rc));
308 uint32_t vbdcBytes(0);
317 crMsg->AddControlElement(rc, cac, vbdcBytes);
322 std::stringstream ss;
323 ss << Simulator::Now().GetSeconds() <<
", " <<
m_nodeInfo->GetNodeId()
324 <<
", " <<
static_cast<uint32_t
>(rc) <<
", "
339 NS_LOG_INFO(
"Requested VBDC volume for RC: " << (uint32_t)(rc) <<
" is "
341 <<
" Bytes with CAC: " << cac);
347 NS_LOG_INFO(
"Evaluation RBDC+VBDC for RC: " << (uint32_t)(rc));
354 "Simultaneous RBDC and VBDC for one RC is not currently supported!");
359 NS_LOG_INFO(
"RBDC nor VBDC was configured for RC: " << (uint32_t)(rc));
368 if (crMsg->IsNotEmpty())
370 NS_LOG_INFO(
"Send CR");
379 NS_LOG_INFO(
"No transmission possibility, thus skipping CR evaluation!");
382 NS_LOG_INFO(
"---End request manager evaluation---");
388 NS_LOG_FUNCTION(
this << (uint32_t)(rcIndex) << &cb);
395 NS_LOG_FUNCTION(
this << &cb);
402 NS_LOG_FUNCTION(
this << &cb);
409 NS_LOG_FUNCTION(
this << &cb);
416 NS_LOG_FUNCTION(
this << address);
423 NS_LOG_FUNCTION(
this);
436 NS_LOG_FUNCTION(
this << satId << beamId << cno);
438 NS_LOG_INFO(
"C/No updated to request manager: " << cno);
454 NS_LOG_FUNCTION(
this);
462 NS_FATAL_ERROR(
"SatRequestManager::DoRbdc - Invalid RBDC algorithm!");
466 NS_FATAL_ERROR(
"SatRequestManager::DoRbdc - Invalid RBDC algorithm!");
473 NS_LOG_FUNCTION(
this << (uint32_t)(rc));
483 double thisRbdcInKbits = inRateKbps * duration.GetSeconds();
488 double queueOccupancy =
490 m_gainValueK * (queueSizeInKbits - thisRbdcInKbits - previousRbdcInKbits) /
491 duration.GetSeconds());
493 double reqRbdcKbps = inRateKbps + queueOccupancy;
495 NS_LOG_INFO(
"queueSizeInKbits: " << queueSizeInKbits <<
" thisRbdcInKbits: " << thisRbdcInKbits
496 <<
" previousRbdcInKbits " << previousRbdcInKbits);
498 NS_LOG_INFO(
"In rate: " << inRateKbps <<
" queueOccupancy: " << queueOccupancy);
501 if (
m_llsConf->GetDaConstantAssignmentProvided(rc))
504 if (reqRbdcKbps <= m_llsConf->GetDaConstantServiceRateInKbps(rc))
511 reqRbdcKbps -=
m_llsConf->GetDaConstantServiceRateInKbps(rc);
514 if (
m_llsConf->GetDaConstantServiceRateInKbps(rc) >
515 m_llsConf->GetDaMaximumServiceRateInKbps(rc))
517 NS_FATAL_ERROR(
"SatRequestManager::DoRbdcLegacy - configured CRA is bigger than "
518 "maximum RBDC for RC: "
523 if ((
m_llsConf->GetDaConstantServiceRateInKbps(rc) + reqRbdcKbps) >
524 m_llsConf->GetDaMaximumServiceRateInKbps(rc))
526 reqRbdcKbps =
m_llsConf->GetDaMaximumServiceRateInKbps(rc) -
527 m_llsConf->GetDaConstantServiceRateInKbps(rc);
531 else if (reqRbdcKbps >
m_llsConf->GetDaMaximumServiceRateInKbps(rc))
533 reqRbdcKbps =
m_llsConf->GetDaMaximumServiceRateInKbps(rc);
536 NS_LOG_INFO(
"RBDC bitrate after CRA as been taken off: " << reqRbdcKbps <<
" kbps");
540 NS_LOG_INFO(
"Quantized RBDC bitrate: " << crRbdcKbps <<
" kbps");
550 NS_LOG_FUNCTION(
this);
558 NS_FATAL_ERROR(
"SatRequestManager::DoVbdc - Invalid VBDC algorithm!");
562 NS_FATAL_ERROR(
"SatRequestManager::DoVbdc - Invalid VBDC algorithm!");
569 uint32_t& rcVbdcBytes)
571 NS_LOG_FUNCTION(
this << (uint32_t)(rc));
573 uint32_t vbdcBytes(0);
587 NS_LOG_INFO(
"VBDC volume in for RC: " << (uint32_t)(rc) <<
": " << stats.
m_volumeInBytes
605 rcVbdcBytes = vbdcBytes;
613 NS_LOG_FUNCTION(
this << (uint32_t)(rc));
617 uint32_t craBytes(0);
621 if (
m_llsConf->GetDaConstantAssignmentProvided(rc))
623 NS_LOG_INFO(
"CRA is enabled together with VBDC for RC: " << (uint32_t)(rc));
631 m_llsConf->GetDaConstantServiceRateInKbps(rc) * duration.GetSeconds()) /
636 if (craBytes < vbdcBytes)
638 vbdcBytes -= craBytes;
644 NS_LOG_INFO(
"Pending VBDC bytes: " << (uint32_t)(rc) <<
": " <<
m_pendingVbdcBytes.at(rc)
658 NS_LOG_FUNCTION(
this << (uint32_t)(rc));
660 uint32_t craBytes(0);
664 if (
m_llsConf->GetDaConstantAssignmentProvided(rc))
666 NS_LOG_INFO(
"CRA is enabled together with VBDC for RC: " << (uint32_t)(rc));
674 m_llsConf->GetDaConstantServiceRateInKbps(rc) * duration.GetSeconds()) /
679 if (craBytes < vbdcBytes)
681 vbdcBytes -= craBytes;
683 NS_LOG_INFO(
"VBDC volume after CRA for RC: " << (uint32_t)(rc) <<
": " << vbdcBytes
689 NS_LOG_INFO(
"Pending VBDC bytes: " << (uint32_t)(rc) <<
": " <<
m_pendingVbdcBytes.at(rc)
691 NS_LOG_INFO(
"VBDC volume after pending: " << (uint32_t)(rc) <<
": " << vbdcBytes
705 NS_LOG_FUNCTION(
this);
736 NS_LOG_FUNCTION(
this << (uint32_t)(rc));
743 for (std::deque<std::pair<Time, uint32_t>>::const_iterator it = cont.begin(); it != cont.end();
747 value += (*it).second;
750 NS_LOG_INFO(
"Pending RBDC sum for RC: " << (uint32_t)(rc) <<
" is " << value);
758 NS_LOG_FUNCTION(
this << (uint32_t)(rc) << kbps);
762 Time now = Simulator::Now();
763 std::pair<Time, uint32_t> item = std::make_pair(now, kbps);
771 NS_LOG_FUNCTION(
this << (uint32_t)(rc));
774 std::deque<std::pair<Time, uint32_t>>::const_iterator it = cont.begin();
776 while (it != cont.end())
793 NS_LOG_FUNCTION(
this);
795 for (uint8_t rc = 0; rc <
m_llsConf->GetDaServiceCount(); rc++)
804 NS_LOG_FUNCTION(
this << (uint32_t)(rc));
828 NS_LOG_FUNCTION(
this);
835 NS_LOG_INFO(
"Send C/N0 report to GW: " <<
m_gwAddress);
846 NS_FATAL_ERROR(
"Unable to send capacity request, since the Ctrl callback is NULL!");
857 NS_LOG_FUNCTION(
this);
864 if (ctrlMsgTxPossible &&
m_lastCno != NAN)
866 NS_LOG_INFO(
"Send C/No report to GW: " <<
m_gwAddress);
868 Ptr<SatCnoReportMessage> cnoReport = CreateObject<SatCnoReportMessage>();
878 NS_LOG_INFO(
"Send C/No report to SAT user: " <<
m_satAddress);
879 Ptr<SatCnoReportMessage> cnoReport = CreateObject<SatCnoReportMessage>();
895 NS_LOG_FUNCTION(
this << beamId);
900 NS_LOG_INFO(
"Send handover recommendation to GW: " <<
m_gwAddress);
902 Ptr<SatHandoverRecommendationMessage> hoRecommendation =
903 CreateObject<SatHandoverRecommendationMessage>();
904 hoRecommendation->SetRecommendedBeamId(beamId);
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)
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.
void SendHandoverRecommendation(uint32_t beamId)
Send a handover recommendation message to the gateway.
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.
virtual TypeId GetInstanceTypeId(void) const
Get the type ID of instance.
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.
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