29 #include <ns3/address.h>
31 #include <ns3/packet.h>
37 NS_LOG_COMPONENT_DEFINE(
"SatNcc");
42 NS_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)),
78 NS_LOG_FUNCTION(
this);
84 : m_utHandoverDelay(Seconds(0.0)),
85 m_utTimeout(Seconds(10)),
89 NS_LOG_FUNCTION(
this);
94 NS_LOG_FUNCTION(
this);
100 NS_LOG_FUNCTION(
this);
116 NS_LOG_FUNCTION(
this << satId << beamId << sourceMac << cno);
120 m_beamSchedulers[std::make_pair(satId, beamId)]->UpdateSatelliteCno(sourceMac, cno);
124 m_beamSchedulers[std::make_pair(satId, beamId)]->UpdateUtCno(sourceMac, cno);
132 uint8_t allocationChannelId,
133 double averageNormalizedOfferedLoad)
135 NS_LOG_FUNCTION(
this << satId << beamId << carrierId << (uint32_t)allocationChannelId
136 << averageNormalizedOfferedLoad);
138 bool isLowRandomAccessLoad =
true;
139 std::map<std::tuple<uint32_t, uint32_t, uint8_t>,
bool>::iterator findResult;
140 std::pair<std::map<std::tuple<uint32_t, uint32_t, uint8_t>,
bool>::iterator,
bool> insertResult;
148 std::make_pair(std::make_tuple(satId, beamId, allocationChannelId),
149 isLowRandomAccessLoad));
151 if (!insertResult.second)
153 NS_FATAL_ERROR(
"SatNcc::DoRandomAccessDynamicLoadControl - Insert failed");
157 isLowRandomAccessLoad = insertResult.second;
162 isLowRandomAccessLoad = findResult->second;
165 NS_LOG_INFO(
"Beam: " << beamId <<
", carrier ID: " << carrierId
166 <<
", AC: " << (uint32_t)allocationChannelId
167 <<
" - Measuring the average normalized offered random access load: "
168 << averageNormalizedOfferedLoad);
170 std::map<uint8_t, double>::iterator itThreshold =
175 NS_FATAL_ERROR(
"SatNcc::DoRandomAccessDynamicLoadControl - Average normalized offered load "
176 "threshold not set for beam: "
177 << beamId <<
", carrier: " << carrierId
178 <<
", allocation channel: " << (uint32_t)allocationChannelId);
182 if (isLowRandomAccessLoad)
184 NS_LOG_INFO(
"Beam: " << beamId <<
", carrier ID: " << carrierId
185 <<
" - Currently low load in effect for allocation channel: "
186 << (uint32_t)allocationChannelId);
188 if (averageNormalizedOfferedLoad >= itThreshold->second)
190 std::map<uint8_t, uint16_t>::iterator it;
196 NS_FATAL_ERROR(
"SatNcc::DoRandomAccessDynamicLoadControl - High load backoff "
197 "probability not set for allocation channel: "
198 << (uint32_t)allocationChannelId);
201 uint16_t probability = it->second;
207 NS_FATAL_ERROR(
"SatNcc::DoRandomAccessDynamicLoadControl - High load backoff time "
208 "not set for allocation channel: "
209 << (uint32_t)allocationChannelId);
212 uint16_t time = it->second;
219 allocationChannelId);
221 NS_LOG_INFO(
"Beam: " << beamId <<
", carrier ID: " << carrierId
222 <<
", AC: " << (uint32_t)allocationChannelId
223 <<
" - Switching to HIGH LOAD back off parameterization");
232 NS_LOG_INFO(
"Beam: " << beamId <<
", carrier ID: " << carrierId
233 <<
" - Currently high load in effect for allocation channel: "
234 << (uint32_t)allocationChannelId);
237 if (averageNormalizedOfferedLoad < itThreshold->second)
239 std::map<uint8_t, uint16_t>::iterator it;
245 NS_FATAL_ERROR(
"SatNcc::DoRandomAccessDynamicLoadControl - Low load backoff "
246 "probability not set for allocation channel: "
247 << (uint32_t)allocationChannelId);
250 uint16_t probability = it->second;
256 NS_FATAL_ERROR(
"SatNcc::DoRandomAccessDynamicLoadControl - Low load backoff time "
257 "not set for allocation channel: "
258 << (uint32_t)allocationChannelId);
261 uint16_t time = it->second;
268 allocationChannelId);
270 NS_LOG_INFO(
"Beam: " << beamId <<
", carrier ID: " << carrierId
271 <<
", AC: " << (uint32_t)allocationChannelId
272 <<
" - Switching to LOW LOAD back off parameterization");
282 uint16_t backoffTime,
285 uint8_t allocationChannelId)
287 NS_LOG_FUNCTION(
this);
289 Ptr<SatRaMessage> raMsg = CreateObject<SatRaMessage>();
290 std::map<std::pair<uint32_t, uint32_t>, Ptr<SatBeamScheduler>>::iterator iterator =
295 NS_FATAL_ERROR(
"SatNcc::SendRaControlMessage - Beam scheduler not found");
299 raMsg->SetAllocationChannelId(allocationChannelId);
302 raMsg->SetBackoffProbability(backoffProbability);
303 raMsg->SetBackoffTime(backoffTime);
305 NS_LOG_INFO(
"Sending random access control message for AC: "
306 << (uint32_t)allocationChannelId <<
", backoff probability: " << backoffProbability
307 <<
", backoff time: " << backoffTime);
309 iterator->second->Send(raMsg);
315 NS_LOG_FUNCTION(
this << satId << beamId << utId << crMsg);
323 Ptr<SatNetDevice> gwNetDevice,
324 Ptr<SatOrbiterNetDevice> orbiterNetDevice,
327 Ptr<SatSuperframeSeq> seq,
328 uint32_t maxFrameSize,
332 NS_LOG_FUNCTION(
this << satId << beamId << gwNetDevice << orbiterNetDevice << &cb << &tbtpCb
333 << seq << maxFrameSize << satAddress << gwAddress);
335 Ptr<SatBeamScheduler> scheduler;
336 std::map<std::pair<uint32_t, uint32_t>, Ptr<SatBeamScheduler>>::iterator iterator =
341 NS_FATAL_ERROR(
"Beam tried to add, already added.");
344 scheduler = CreateObject<SatBeamScheduler>();
345 scheduler->Initialize(satId,
355 scheduler->SetSendTbtpCallback(tbtpCb);
359 m_beamSchedulers.insert(std::make_pair(std::make_pair(satId, beamId), scheduler));
367 Callback<void, uint32_t> setRaChannelCallback,
370 NS_LOG_FUNCTION(
this << utId << beamId);
372 std::map<std::pair<uint32_t, uint32_t>, Ptr<SatBeamScheduler>>::iterator iterator =
377 NS_FATAL_ERROR(
"Beam where tried to add, not found.");
380 if (!verifyExisting || !(
m_beamSchedulers[std::make_pair(satId, beamId)]->HasUt(utId)))
389 NS_LOG_FUNCTION(
this << utId << beamId);
399 uint16_t lowLoadBackOffProbability)
401 NS_LOG_FUNCTION(
this << (uint32_t)allocationChannelId << lowLoadBackOffProbability);
403 NS_LOG_INFO(
"AC: " << (uint32_t)allocationChannelId
404 <<
", low load backoff probability: " << lowLoadBackOffProbability);
410 uint16_t highLoadBackOffProbability)
412 NS_LOG_FUNCTION(
this << (uint32_t)allocationChannelId << highLoadBackOffProbability);
414 NS_LOG_INFO(
"AC: " << (uint32_t)allocationChannelId
415 <<
", high load backoff probability: " << highLoadBackOffProbability);
422 NS_LOG_FUNCTION(
this << (uint32_t)allocationChannelId << lowLoadBackOffTime);
424 NS_LOG_INFO(
"AC: " << (uint32_t)allocationChannelId
425 <<
", low load backoff time: " << lowLoadBackOffTime);
431 uint16_t highLoadBackOffTime)
433 NS_LOG_FUNCTION(
this << (uint32_t)allocationChannelId << highLoadBackOffTime);
435 NS_LOG_INFO(
"AC: " << (uint32_t)allocationChannelId
436 <<
", high load backoff time: " << highLoadBackOffTime);
444 NS_LOG_FUNCTION(
this << (uint32_t)allocationChannelId << threshold);
446 NS_LOG_INFO(
"AC: " << (uint32_t)allocationChannelId
447 <<
", average normalized offered load threshold: " << threshold);
451 Ptr<SatBeamScheduler>
454 NS_LOG_FUNCTION(
this << satId << beamId);
456 std::map<std::pair<uint32_t, uint32_t>, Ptr<SatBeamScheduler>>::const_iterator it =
476 NS_LOG_FUNCTION(
this << utId << srcSatId << srcBeamId << destSatId << destBeamId);
479 Ptr<SatBeamScheduler> destScheduler =
GetBeamScheduler(destSatId, destBeamId);
483 NS_FATAL_ERROR(
"Source beam not configured");
488 NS_FATAL_ERROR(
"Destination beam not configured");
491 srcScheduler->TransferUtToBeam(utId, destScheduler);
502 NS_LOG_FUNCTION(
this << utId << srcSatId << srcBeamId << destSatId << destBeamId);
505 Ptr<SatBeamScheduler> destination =
GetBeamScheduler(destSatId, destBeamId);
509 NS_FATAL_ERROR(
"Source beam does not exist!");
514 NS_LOG_WARN(
"Destination beam does not exist, cancel handover");
516 Ptr<SatTimuMessage> timuMsg = scheduler->CreateTimu();
517 scheduler->SendTo(timuMsg, utId);
519 else if (scheduler->HasUt(utId) && !destination->HasUt(utId))
521 NS_LOG_INFO(
"Performing handover!");
523 Ptr<SatTimuMessage> timuMsg = destination->CreateTimu();
524 scheduler->SendTo(timuMsg, utId);
535 else if (!scheduler->HasUt(utId) && destination->HasUt(utId))
537 NS_LOG_INFO(
"Handover already performed, sending back TIM-U just in case!");
539 Ptr<SatTimuMessage> timuMsg = destination->CreateTimu();
540 scheduler->SendTo(timuMsg, utId);
544 NS_FATAL_ERROR(
"Inconsistent handover state: UT is neither in source nor destination beam; "
552 NS_LOG_FUNCTION(
this << &cb);
560 NS_LOG_FUNCTION(
this << logonChannelId);
564 beamScheduler.second->ReserveLogonChannel(logonChannelId);
571 NS_LOG_FUNCTION(
this << utId << beamId);
573 std::tuple<Address, uint32_t, uint32_t>
id = std::make_tuple(utId, satId, beamId);
585 NS_LOG_FUNCTION(
this << useLogon);
593 NS_LOG_FUNCTION(
this << useLora);
597 for (std::pair<std::pair<uint32_t, uint32_t>, Ptr<SatBeamScheduler>> beamScheduler :
600 beamScheduler.second->SetUseLora(
m_useLora);
607 NS_LOG_FUNCTION(
this << utId);
609 std::tuple<Address, uint32_t, uint32_t>
id = std::make_tuple(utId, satId, beamId);
611 "UT address should be in map");
614 if (Simulator::Now() >= lastReceptionDate +
m_utTimeout)
621 Simulator::Schedule(lastReceptionDate +
m_utTimeout - Simulator::Now(),
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).
virtual TypeId GetInstanceTypeId(void) const
Get the type ID of instance.
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.