29 #include <ns3/boolean.h>
30 #include <ns3/double.h>
33 #include <ns3/nstime.h>
34 #include <ns3/simulator.h>
43 NS_LOG_COMPONENT_DEFINE(
"SatRequestManager");
48 NS_OBJECT_ENSURE_REGISTERED(SatRequestManager);
58 m_evaluationInterval(Seconds(0.1)),
59 m_cnoReportInterval(Seconds(0.0)),
61 m_rttEstimate(MilliSeconds(560)),
62 m_overEstimationFactor(1.1),
63 m_enableOnDemandEvaluation(false),
64 m_pendingRbdcRequestsKbps(),
66 m_previousEvaluationTime(),
67 m_lastVbdcCrSent(Seconds(0)),
68 m_superFrameDuration(Seconds(0)),
69 m_forcedAvbdcUpdate(false),
71 m_rbdcCapacityRequestAlgorithm(
SatEnums::CR_RBDC_LEGACY),
72 m_vbdcCapacityRequestAlgorithm(
SatEnums::CR_VBDC_LEGACY),
73 m_headerOffsetVbcd(1.0)
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);
193 NS_LOG_FUNCTION(
this);
198 it->second.Nullify();
215 NS_LOG_FUNCTION(
this << event << (uint32_t)(rcIndex));
219 NS_LOG_INFO(
"FIRST_BUFFERED_PKT event received from queue: " << (uint32_t)(rcIndex));
223 NS_LOG_INFO(
"Do on-demand CR evaluation for RC index: " << (uint32_t)(rcIndex));
233 NS_LOG_FUNCTION(
this);
244 NS_LOG_FUNCTION(
this);
246 NS_LOG_INFO(
"---Start request manager evaluation---");
254 if (ctrlMsgTxPossible)
264 Ptr<SatCrMessage> crMsg = CreateObject<SatCrMessage>();
267 for (uint8_t rc = 0; rc <
m_llsConf->GetDaServiceCount(); ++rc)
274 NS_LOG_INFO(
"Evaluating the needs for RC: " << (uint32_t)(rc));
275 NS_LOG_INFO(
"RC: " << (uint32_t)(rc)
277 NS_LOG_INFO(
"RC: " << (uint32_t)(rc)
279 NS_LOG_INFO(
"RC: " << (uint32_t)(rc) <<
" volume in: " << stats.
m_volumeInBytes
281 NS_LOG_INFO(
"RC: " << (uint32_t)(rc) <<
" volume out: " << stats.
m_volumeOutBytes
283 NS_LOG_INFO(
"RC: " << (uint32_t)(rc)
289 NS_LOG_INFO(
"Evaluating RBDC needs for RC: " << (uint32_t)(rc));
290 uint32_t rbdcRateKbps =
DoRbdc(rc, stats);
292 NS_LOG_INFO(
"Requested RBDC rate for RC: " << (uint32_t)(rc) <<
" is "
293 << rbdcRateKbps <<
" kbps");
295 if (rbdcRateKbps > 0)
300 std::stringstream ss;
301 ss << Simulator::Now().GetSeconds() <<
", " <<
m_nodeInfo->GetNodeId()
302 <<
", " <<
static_cast<uint32_t
>(rc) <<
", "
313 NS_LOG_INFO(
"Evaluation VBDC for RC: " << (uint32_t)(rc));
315 uint32_t vbdcBytes(0);
324 crMsg->AddControlElement(rc, cac, vbdcBytes);
329 std::stringstream ss;
330 ss << Simulator::Now().GetSeconds() <<
", " <<
m_nodeInfo->GetNodeId()
331 <<
", " <<
static_cast<uint32_t
>(rc) <<
", "
346 NS_LOG_INFO(
"Requested VBDC volume for RC: " << (uint32_t)(rc) <<
" is "
348 <<
" Bytes with CAC: " << cac);
354 NS_LOG_INFO(
"Evaluation RBDC+VBDC for RC: " << (uint32_t)(rc));
361 "Simultaneous RBDC and VBDC for one RC is not currently supported!");
366 NS_LOG_INFO(
"RBDC nor VBDC was configured for RC: " << (uint32_t)(rc));
375 if (crMsg->IsNotEmpty())
377 NS_LOG_INFO(
"Send CR");
386 NS_LOG_INFO(
"No transmission possibility, thus skipping CR evaluation!");
389 NS_LOG_INFO(
"---End request manager evaluation---");
395 NS_LOG_FUNCTION(
this << (uint32_t)(rcIndex) << &cb);
402 NS_LOG_FUNCTION(
this << &cb);
409 NS_LOG_FUNCTION(
this << &cb);
416 NS_LOG_FUNCTION(
this << &cb);
423 NS_LOG_FUNCTION(
this << address);
430 NS_LOG_FUNCTION(
this);
443 NS_LOG_FUNCTION(
this << satId << beamId << cno);
445 NS_LOG_INFO(
"C/No updated to request manager: " << cno);
461 NS_LOG_FUNCTION(
this);
469 NS_FATAL_ERROR(
"SatRequestManager::DoRbdc - Invalid RBDC algorithm!");
473 NS_FATAL_ERROR(
"SatRequestManager::DoRbdc - Invalid RBDC algorithm!");
480 NS_LOG_FUNCTION(
this << (uint32_t)(rc));
490 double thisRbdcInKbits = inRateKbps * duration.GetSeconds();
495 double queueOccupancy =
497 m_gainValueK * (queueSizeInKbits - thisRbdcInKbits - previousRbdcInKbits) /
498 duration.GetSeconds());
500 double reqRbdcKbps = inRateKbps + queueOccupancy;
502 NS_LOG_INFO(
"queueSizeInKbits: " << queueSizeInKbits <<
" thisRbdcInKbits: " << thisRbdcInKbits
503 <<
" previousRbdcInKbits " << previousRbdcInKbits);
505 NS_LOG_INFO(
"In rate: " << inRateKbps <<
" queueOccupancy: " << queueOccupancy);
508 if (
m_llsConf->GetDaConstantAssignmentProvided(rc))
511 if (reqRbdcKbps <= m_llsConf->GetDaConstantServiceRateInKbps(rc))
518 reqRbdcKbps -=
m_llsConf->GetDaConstantServiceRateInKbps(rc);
521 if (
m_llsConf->GetDaConstantServiceRateInKbps(rc) >
522 m_llsConf->GetDaMaximumServiceRateInKbps(rc))
524 NS_FATAL_ERROR(
"SatRequestManager::DoRbdcLegacy - configured CRA is bigger than "
525 "maximum RBDC for RC: "
530 if ((
m_llsConf->GetDaConstantServiceRateInKbps(rc) + reqRbdcKbps) >
531 m_llsConf->GetDaMaximumServiceRateInKbps(rc))
533 reqRbdcKbps =
m_llsConf->GetDaMaximumServiceRateInKbps(rc) -
534 m_llsConf->GetDaConstantServiceRateInKbps(rc);
538 else if (reqRbdcKbps >
m_llsConf->GetDaMaximumServiceRateInKbps(rc))
540 reqRbdcKbps =
m_llsConf->GetDaMaximumServiceRateInKbps(rc);
543 NS_LOG_INFO(
"RBDC bitrate after CRA as been taken off: " << reqRbdcKbps <<
" kbps");
547 NS_LOG_INFO(
"Quantized RBDC bitrate: " << crRbdcKbps <<
" kbps");
557 NS_LOG_FUNCTION(
this);
565 NS_FATAL_ERROR(
"SatRequestManager::DoVbdc - Invalid VBDC algorithm!");
569 NS_FATAL_ERROR(
"SatRequestManager::DoVbdc - Invalid VBDC algorithm!");
576 uint32_t& rcVbdcBytes)
578 NS_LOG_FUNCTION(
this << (uint32_t)(rc));
580 uint32_t vbdcBytes(0);
594 NS_LOG_INFO(
"VBDC volume in for RC: " << (uint32_t)(rc) <<
": " << stats.
m_volumeInBytes
612 rcVbdcBytes = vbdcBytes;
620 NS_LOG_FUNCTION(
this << (uint32_t)(rc));
624 uint32_t craBytes(0);
628 if (
m_llsConf->GetDaConstantAssignmentProvided(rc))
630 NS_LOG_INFO(
"CRA is enabled together with VBDC for RC: " << (uint32_t)(rc));
638 m_llsConf->GetDaConstantServiceRateInKbps(rc) * duration.GetSeconds()) /
643 if (craBytes < vbdcBytes)
645 vbdcBytes -= craBytes;
651 NS_LOG_INFO(
"Pending VBDC bytes: " << (uint32_t)(rc) <<
": " <<
m_pendingVbdcBytes.at(rc)
665 NS_LOG_FUNCTION(
this << (uint32_t)(rc));
667 uint32_t craBytes(0);
671 if (
m_llsConf->GetDaConstantAssignmentProvided(rc))
673 NS_LOG_INFO(
"CRA is enabled together with VBDC for RC: " << (uint32_t)(rc));
681 m_llsConf->GetDaConstantServiceRateInKbps(rc) * duration.GetSeconds()) /
686 if (craBytes < vbdcBytes)
688 vbdcBytes -= craBytes;
690 NS_LOG_INFO(
"VBDC volume after CRA for RC: " << (uint32_t)(rc) <<
": " << vbdcBytes
696 NS_LOG_INFO(
"Pending VBDC bytes: " << (uint32_t)(rc) <<
": " <<
m_pendingVbdcBytes.at(rc)
698 NS_LOG_INFO(
"VBDC volume after pending: " << (uint32_t)(rc) <<
": " << vbdcBytes
712 NS_LOG_FUNCTION(
this);
743 NS_LOG_FUNCTION(
this << (uint32_t)(rc));
750 for (std::deque<std::pair<Time, uint32_t>>::const_iterator it = cont.begin(); it != cont.end();
754 value += (*it).second;
757 NS_LOG_INFO(
"Pending RBDC sum for RC: " << (uint32_t)(rc) <<
" is " << value);
765 NS_LOG_FUNCTION(
this << (uint32_t)(rc) << kbps);
769 Time now = Simulator::Now();
770 std::pair<Time, uint32_t> item = std::make_pair(now, kbps);
778 NS_LOG_FUNCTION(
this << (uint32_t)(rc));
781 std::deque<std::pair<Time, uint32_t>>::const_iterator it = cont.begin();
783 while (it != cont.end())
800 NS_LOG_FUNCTION(
this);
802 for (uint8_t rc = 0; rc <
m_llsConf->GetDaServiceCount(); rc++)
811 NS_LOG_FUNCTION(
this << (uint32_t)(rc));
835 NS_LOG_FUNCTION(
this);
842 NS_LOG_INFO(
"Send C/N0 report to GW: " <<
m_gwAddress);
853 NS_FATAL_ERROR(
"Unable to send capacity request, since the Ctrl callback is NULL!");
864 NS_LOG_FUNCTION(
this);
871 if (ctrlMsgTxPossible &&
m_lastCno != NAN)
873 NS_LOG_INFO(
"Send C/No report to GW: " <<
m_gwAddress);
875 Ptr<SatCnoReportMessage> cnoReport = CreateObject<SatCnoReportMessage>();
885 NS_LOG_INFO(
"Send C/No report to SAT user: " <<
m_satAddress);
886 Ptr<SatCnoReportMessage> cnoReport = CreateObject<SatCnoReportMessage>();
902 NS_LOG_FUNCTION(
this << beamId);
907 NS_LOG_INFO(
"Send handover recommendation to GW: " <<
m_gwAddress);
909 Ptr<SatHandoverRecommendationMessage> hoRecommendation =
910 CreateObject<SatHandoverRecommendationMessage>();
911 hoRecommendation->SetRecommendedBeamId(beamId);
912 hoRecommendation->SetRecommendedSatId(satId);
921 NS_LOG_FUNCTION(
this);
927 NS_LOG_INFO(
"Send logon message to GW: " <<
m_gwAddress);
929 Ptr<SatLogonMessage> logonMessage = CreateObject<SatLogonMessage>();
943 NS_LOG_FUNCTION(
this << (uint32_t)(rcIndex) << bytes);
945 NS_LOG_INFO(
"TBTP resources assigned for RC: " << (uint32_t)(rcIndex) <<
" bytes: " << bytes);
953 NS_LOG_FUNCTION(
this);
955 for (uint32_t i = 0; i <
m_llsConf->GetDaServiceCount(); ++i)
964 NS_LOG_FUNCTION(
this << (uint32_t)(rc));
973 NS_LOG_FUNCTION(
this << (uint32_t)(index) << reqRbdcKbps);
975 uint32_t maxRbdc =
m_llsConf->GetDaMaximumServiceRateInKbps(index);
976 uint32_t quantValue(0);
979 if (reqRbdcKbps > maxRbdc)
985 for (uint32_t i = 0; i < 4; i++)
996 NS_FATAL_ERROR(
"Quantized value for RBDC not calculated!");
1004 NS_LOG_FUNCTION(
this << (uint32_t)(index) << reqVbdcBytes);
1006 uint32_t maxBacklogBytes =
1008 uint32_t quantValue(0);
1011 if (reqVbdcBytes > maxBacklogBytes)
1013 return maxBacklogBytes;
1017 for (uint32_t i = 0; i < 4; ++i)
1028 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.
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.
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