29#include "ns3/address.h"
31#include "ns3/packet.h"
37NS_LOG_COMPONENT_DEFINE(
"SatNcc");
42NS_OBJECT_ENSURE_REGISTERED(
SatNcc);
50 .AddConstructor<SatNcc>()
54 .AddTraceSource(
"NccRx",
55 "Trace source indicating a CR has received by NCC",
57 "ns3::Packet::TracedCallback")
58 .AddTraceSource(
"NccTx",
59 "Trace source indicating a TBTP has sent by NCC",
61 "ns3::Packet::TracedCallback")
62 .AddAttribute(
"HandoverDelay",
63 "Delay between handover acceptance and effective information transfer",
64 TimeValue(Seconds(0.0)),
67 .AddAttribute(
"UtTimeout",
68 "Timeout to logoff a UT, if logon procedure is used",
69 TimeValue(Seconds(10)),
81 NS_LOG_FUNCTION(
this);
86 NS_LOG_FUNCTION(
this);
92 NS_LOG_FUNCTION(
this);
108 NS_LOG_FUNCTION(
this << satId << beamId << sourceMac << cno);
112 m_beamSchedulers[std::make_pair(satId, beamId)]->UpdateSatelliteCno(sourceMac, cno);
116 m_beamSchedulers[std::make_pair(satId, beamId)]->UpdateUtCno(sourceMac, cno);
124 uint8_t allocationChannelId,
125 double averageNormalizedOfferedLoad)
127 NS_LOG_FUNCTION(
this << satId << beamId << carrierId << (uint32_t)allocationChannelId
128 << averageNormalizedOfferedLoad);
130 bool isLowRandomAccessLoad =
true;
131 std::map<std::tuple<uint32_t, uint32_t, uint8_t>,
bool>::iterator findResult;
132 std::pair<std::map<std::tuple<uint32_t, uint32_t, uint8_t>,
bool>::iterator,
bool> insertResult;
140 std::make_pair(std::make_tuple(satId, beamId, allocationChannelId),
141 isLowRandomAccessLoad));
143 if (!insertResult.second)
145 NS_FATAL_ERROR(
"SatNcc::DoRandomAccessDynamicLoadControl - Insert failed");
149 isLowRandomAccessLoad = insertResult.second;
154 isLowRandomAccessLoad = findResult->second;
157 NS_LOG_INFO(
"Beam: " << beamId <<
", carrier ID: " << carrierId
158 <<
", AC: " << (uint32_t)allocationChannelId
159 <<
" - Measuring the average normalized offered random access load: "
160 << averageNormalizedOfferedLoad);
162 std::map<uint8_t, double>::iterator itThreshold =
167 NS_FATAL_ERROR(
"SatNcc::DoRandomAccessDynamicLoadControl - Average normalized offered load "
168 "threshold not set for beam: "
169 << beamId <<
", carrier: " << carrierId
170 <<
", allocation channel: " << (uint32_t)allocationChannelId);
174 if (isLowRandomAccessLoad)
176 NS_LOG_INFO(
"Beam: " << beamId <<
", carrier ID: " << carrierId
177 <<
" - Currently low load in effect for allocation channel: "
178 << (uint32_t)allocationChannelId);
180 if (averageNormalizedOfferedLoad >= itThreshold->second)
182 std::map<uint8_t, uint16_t>::iterator it;
188 NS_FATAL_ERROR(
"SatNcc::DoRandomAccessDynamicLoadControl - High load backoff "
189 "probability not set for allocation channel: "
190 << (uint32_t)allocationChannelId);
193 uint16_t probability = it->second;
199 NS_FATAL_ERROR(
"SatNcc::DoRandomAccessDynamicLoadControl - High load backoff time "
200 "not set for allocation channel: "
201 << (uint32_t)allocationChannelId);
204 uint16_t time = it->second;
211 allocationChannelId);
213 NS_LOG_INFO(
"Beam: " << beamId <<
", carrier ID: " << carrierId
214 <<
", AC: " << (uint32_t)allocationChannelId
215 <<
" - Switching to HIGH LOAD back off parameterization");
224 NS_LOG_INFO(
"Beam: " << beamId <<
", carrier ID: " << carrierId
225 <<
" - Currently high load in effect for allocation channel: "
226 << (uint32_t)allocationChannelId);
229 if (averageNormalizedOfferedLoad < itThreshold->second)
231 std::map<uint8_t, uint16_t>::iterator it;
237 NS_FATAL_ERROR(
"SatNcc::DoRandomAccessDynamicLoadControl - Low load backoff "
238 "probability not set for allocation channel: "
239 << (uint32_t)allocationChannelId);
242 uint16_t probability = it->second;
248 NS_FATAL_ERROR(
"SatNcc::DoRandomAccessDynamicLoadControl - Low load backoff time "
249 "not set for allocation channel: "
250 << (uint32_t)allocationChannelId);
253 uint16_t time = it->second;
260 allocationChannelId);
262 NS_LOG_INFO(
"Beam: " << beamId <<
", carrier ID: " << carrierId
263 <<
", AC: " << (uint32_t)allocationChannelId
264 <<
" - Switching to LOW LOAD back off parameterization");
274 uint16_t backoffTime,
277 uint8_t allocationChannelId)
279 NS_LOG_FUNCTION(
this);
281 Ptr<SatRaMessage> raMsg = CreateObject<SatRaMessage>();
282 std::map<std::pair<uint32_t, uint32_t>, Ptr<SatBeamScheduler>>::iterator iterator =
287 NS_FATAL_ERROR(
"SatNcc::SendRaControlMessage - Beam scheduler not found");
291 raMsg->SetAllocationChannelId(allocationChannelId);
294 raMsg->SetBackoffProbability(backoffProbability);
295 raMsg->SetBackoffTime(backoffTime);
297 NS_LOG_INFO(
"Sending random access control message for AC: "
298 << (uint32_t)allocationChannelId <<
", backoff probability: " << backoffProbability
299 <<
", backoff time: " << backoffTime);
301 iterator->second->Send(raMsg);
307 NS_LOG_FUNCTION(
this << satId << beamId << utId << crMsg);
315 Ptr<SatNetDevice> gwNetDevice,
316 Ptr<SatOrbiterNetDevice> orbiterNetDevice,
319 Ptr<SatSuperframeSeq> seq,
320 uint32_t maxFrameSize,
324 NS_LOG_FUNCTION(
this << satId << beamId << gwNetDevice << orbiterNetDevice << &cb << &tbtpCb
325 << seq << maxFrameSize << satAddress << gwAddress);
327 Ptr<SatBeamScheduler> scheduler;
328 std::map<std::pair<uint32_t, uint32_t>, Ptr<SatBeamScheduler>>::iterator iterator =
333 NS_FATAL_ERROR(
"Beam tried to add, already added.");
336 scheduler = CreateObject<SatBeamScheduler>();
337 scheduler->Initialize(satId,
347 scheduler->SetSendTbtpCallback(tbtpCb);
351 m_beamSchedulers.insert(std::make_pair(std::make_pair(satId, beamId), scheduler));
359 Callback<void, uint32_t> setRaChannelCallback,
362 NS_LOG_FUNCTION(
this << utId << beamId);
364 std::map<std::pair<uint32_t, uint32_t>, Ptr<SatBeamScheduler>>::iterator iterator =
369 NS_FATAL_ERROR(
"Beam where tried to add, not found.");
372 if (!verifyExisting || !(
m_beamSchedulers[std::make_pair(satId, beamId)]->HasUt(utId)))
381 NS_LOG_FUNCTION(
this << utId << beamId);
391 uint16_t lowLoadBackOffProbability)
393 NS_LOG_FUNCTION(
this << (uint32_t)allocationChannelId << lowLoadBackOffProbability);
395 NS_LOG_INFO(
"AC: " << (uint32_t)allocationChannelId
396 <<
", low load backoff probability: " << lowLoadBackOffProbability);
402 uint16_t highLoadBackOffProbability)
404 NS_LOG_FUNCTION(
this << (uint32_t)allocationChannelId << highLoadBackOffProbability);
406 NS_LOG_INFO(
"AC: " << (uint32_t)allocationChannelId
407 <<
", high load backoff probability: " << highLoadBackOffProbability);
414 NS_LOG_FUNCTION(
this << (uint32_t)allocationChannelId << lowLoadBackOffTime);
416 NS_LOG_INFO(
"AC: " << (uint32_t)allocationChannelId
417 <<
", low load backoff time: " << lowLoadBackOffTime);
423 uint16_t highLoadBackOffTime)
425 NS_LOG_FUNCTION(
this << (uint32_t)allocationChannelId << highLoadBackOffTime);
427 NS_LOG_INFO(
"AC: " << (uint32_t)allocationChannelId
428 <<
", high load backoff time: " << highLoadBackOffTime);
436 NS_LOG_FUNCTION(
this << (uint32_t)allocationChannelId << threshold);
438 NS_LOG_INFO(
"AC: " << (uint32_t)allocationChannelId
439 <<
", average normalized offered load threshold: " << threshold);
446 NS_LOG_FUNCTION(
this << satId << beamId);
448 std::map<std::pair<uint32_t, uint32_t>, Ptr<SatBeamScheduler>>::const_iterator it =
468 NS_LOG_FUNCTION(
this << utId << srcSatId << srcBeamId << destSatId << destBeamId);
471 Ptr<SatBeamScheduler> destScheduler =
GetBeamScheduler(destSatId, destBeamId);
475 NS_FATAL_ERROR(
"Source beam not configured");
480 NS_FATAL_ERROR(
"Destination beam not configured");
483 srcScheduler->TransferUtToBeam(utId, destScheduler);
494 NS_LOG_FUNCTION(
this << utId << srcSatId << srcBeamId << destSatId << destBeamId);
497 Ptr<SatBeamScheduler> destination =
GetBeamScheduler(destSatId, destBeamId);
501 NS_FATAL_ERROR(
"Source beam does not exist!");
506 NS_LOG_WARN(
"Destination beam does not exist, cancel handover");
508 Ptr<SatTimuMessage> timuMsg = scheduler->CreateTimu();
509 scheduler->SendTo(timuMsg, utId);
511 else if (scheduler->HasUt(utId) && !destination->HasUt(utId))
513 NS_LOG_INFO(
"Performing handover!");
515 Ptr<SatTimuMessage> timuMsg = destination->CreateTimu();
516 scheduler->SendTo(timuMsg, utId);
527 else if (!scheduler->HasUt(utId) && destination->HasUt(utId))
529 NS_LOG_INFO(
"Handover already performed, sending back TIM-U just in case!");
531 Ptr<SatTimuMessage> timuMsg = destination->CreateTimu();
532 scheduler->SendTo(timuMsg, utId);
536 NS_FATAL_ERROR(
"Inconsistent handover state: UT is neither in source nor destination beam; "
544 NS_LOG_FUNCTION(
this << &cb);
552 NS_LOG_FUNCTION(
this << logonChannelId);
556 beamScheduler.second->ReserveLogonChannel(logonChannelId);
563 NS_LOG_FUNCTION(
this << utId << beamId);
565 std::tuple<Address, uint32_t, uint32_t>
id = std::make_tuple(utId, satId, beamId);
577 NS_LOG_FUNCTION(
this << useLogon);
585 NS_LOG_FUNCTION(
this << useLora);
589 for (std::pair<std::pair<uint32_t, uint32_t>, Ptr<SatBeamScheduler>> beamScheduler :
592 beamScheduler.second->SetUseLora(
m_useLora);
599 NS_LOG_FUNCTION(
this << utId);
601 std::tuple<Address, uint32_t, uint32_t>
id = std::make_tuple(utId, satId, beamId);
603 "UT address should be in map");
606 if (Simulator::Now() >= lastReceptionDate +
m_utTimeout)
613 Simulator::Schedule(lastReceptionDate +
m_utTimeout - Simulator::Now(),
class for module NCC used as shared module among Gateways (GWs).
void SetUseLora(bool useLora)
Set if SNS-3 is used with Lora standard.
Callback< void, Address, Address, Address > UpdateRoutingCallback
Update routes and ARP tables on gateways after a terminal handover.
std::map< uint8_t, uint16_t > m_lowLoadBackOffProbability
Map for random access allocation channel specific low load backoff probabilities.
SatBeamScheduler::SendCtrlMsgCallback SendCallback
Define type SendCallback.
static TypeId GetTypeId(void)
Get the type ID.
void ReceiveControlBurst(Address utId, uint32_t satId, uint32_t beamId)
Function to call when a control burst has been received.
void ReserveLogonChannel(uint32_t logonChannelId)
Callback< void, Ptr< SatTbtpMessage > > SendTbtpCallback
void SetUseLogon(bool useLogon)
Set if logon is used in this simulation.
void AddUt(Ptr< SatLowerLayerServiceConf > llsConf, Address utId, uint32_t satId, uint32_t beamId, Callback< void, uint32_t > setRaChannelCallback, bool verifyExisting=false)
Function for adding the UT.
void RemoveUt(Address utId, uint32_t satId, uint32_t beamId)
Remove a UT.
void SetRandomAccessAverageNormalizedOfferedLoadThreshold(uint8_t allocationChannelId, double threshold)
Function for setting the random access allocation channel specific high load backoff probabilities.
void SetUpdateRoutingCallback(SatNcc::UpdateRoutingCallback cb)
Set the callback used to update routes and APR tables after a terminal handover.
std::map< std::pair< uint32_t, uint32_t >, Ptr< SatBeamScheduler > > m_beamSchedulers
The map containing beams in use (set).
std::map< std::tuple< uint32_t, uint32_t, uint8_t >, bool > m_isLowRandomAccessLoad
Map for keeping track of the load status of each random access allocation channel Tuple is (satId,...
SatNcc()
Construct a SatNcc.
void MoveUtBetweenBeams(Address utId, uint32_t srcSatId, uint32_t srcBeamId, uint32_t destSatId, uint32_t destBeamId)
Check if a terminal can be moved between two beams.
void AddBeam(uint32_t satId, uint32_t beamId, Ptr< SatNetDevice > gwNetDevice, Ptr< SatOrbiterNetDevice > orbiterNetDevice, SatNcc::SendCallback cb, SatNcc::SendTbtpCallback tbtpCb, Ptr< SatSuperframeSeq > seq, uint32_t maxFrameSizeInBytes, Address satAddress, Address gwAddress)
Function for adding the beam.
Time m_utTimeout
Timeout to logoff a UT, if logon procedure is used.
void SetRandomAccessLowLoadBackoffProbability(uint8_t allocationChannelId, uint16_t lowLoadBackOffProbability)
Function for setting the random access allocation channel specific high load backoff probabilities.
std::map< uint8_t, uint16_t > m_lowLoadBackOffTime
Map for random access allocation channel specific low load backoff time.
std::map< uint8_t, uint16_t > m_highLoadBackOffProbability
Map for random access allocation channel specific high load backoff probabilities.
void DoMoveUtBetweenBeams(Address utId, uint32_t srcSatId, uint32_t srcBeamId, uint32_t destSatId, uint32_t destBeamId)
Perform terminal handover on the terestrial network.
UpdateRoutingCallback m_updateRoutingCallback
Callback to update routing tables and ARP tables on gateways once a handover request has been accepte...
void UtCrReceived(uint32_t satId, uint32_t beamId, Address utId, Ptr< SatCrMessage > crMsg)
Capacity request receiver.
Ptr< SatBeamScheduler > GetBeamScheduler(uint32_t satId, uint32_t beamId) const
std::map< uint8_t, double > m_randomAccessAverageNormalizedOfferedLoadThreshold
Map for random access allocation channel specific load thresholds.
void DoRandomAccessDynamicLoadControl(uint32_t satId, uint32_t beamId, uint32_t carrierId, uint8_t allocationChannelId, double averageNormalizedOfferedLoad)
Function for adjusting the random access allocation channel specific load.
bool m_useLora
Flag indicating if lora standard is used.
bool m_useLogon
Flag indicating if logon procedure is used.
std::map< std::tuple< Address, uint32_t, uint32_t >, Time > m_lastControlBurstReception
List of reception time for all UTs.
void SetRandomAccessLowLoadBackoffTime(uint8_t allocationChannelId, uint16_t lowLoadBackOffTime)
Function for setting the random access allocation channel specific high load backoff time.
void UtCnoUpdated(uint32_t satId, uint32_t beamId, Address sourceMac, Address gwId, double cno, bool isSatelliteMac)
Update UT specific C/N0 information.
TracedCallback< Ptr< const Packet > > m_nccTxTrace
The trace source fired for TBTPs sent by the NCC.
~SatNcc()
Destroy a SatNcc.
void CreateRandomAccessLoadControlMessage(uint16_t backoffProbability, uint16_t backoffTime, uint32_t satId, uint32_t beamId, uint8_t allocationChannelId)
Function for creating the random access control message.
void CheckTimeout(Address utId, uint32_t satId, uint32_t beamId)
Check if a UT has not been receiving control bursts, and then need to logoff.
Time m_utHandoverDelay
Delay between handover acceptance and effective information transfer.
TracedCallback< Ptr< const Packet > > m_nccRxTrace
The trace source fired for Capacity Requests (CRs) received by the NCC.
std::map< uint8_t, uint16_t > m_highLoadBackOffTime
Map for random access allocation channel specific high load backoff time.
void SetRandomAccessHighLoadBackoffProbability(uint8_t allocationChannelId, uint16_t highLoadBackOffProbability)
Function for setting the random access allocation channel specific high load backoff probabilities.
void SetRandomAccessHighLoadBackoffTime(uint8_t allocationChannelId, uint16_t highLoadBackOffTime)
Function for setting the random access allocation channel specific high load backoff time.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.