29 #include <ns3/address.h>
31 #include <ns3/packet.h>
33 NS_LOG_COMPONENT_DEFINE(
"SatNcc");
38 NS_OBJECT_ENSURE_REGISTERED(SatNcc);
46 .AddConstructor<SatNcc>()
50 .AddTraceSource(
"NccRx",
51 "Trace source indicating a CR has received by NCC",
53 "ns3::Packet::TracedCallback")
54 .AddTraceSource(
"NccTx",
55 "Trace source indicating a TBTP has sent by NCC",
57 "ns3::Packet::TracedCallback")
58 .AddAttribute(
"HandoverDelay",
59 "Delay between handover acceptance and effective information transfer",
60 TimeValue(Seconds(0.0)),
63 .AddAttribute(
"UtTimeout",
64 "Timeout to logoff a UT, if logon procedure is used",
65 TimeValue(Seconds(10)),
74 NS_LOG_FUNCTION(
this);
80 : m_utHandoverDelay(Seconds(0.0)),
81 m_utTimeout(Seconds(10)),
85 NS_LOG_FUNCTION(
this);
90 NS_LOG_FUNCTION(
this);
96 NS_LOG_FUNCTION(
this);
112 NS_LOG_FUNCTION(
this << satId << beamId << sourceMac << cno);
116 m_beamSchedulers[std::make_pair(satId, beamId)]->UpdateSatelliteCno(sourceMac, cno);
120 m_beamSchedulers[std::make_pair(satId, beamId)]->UpdateUtCno(sourceMac, cno);
128 uint8_t allocationChannelId,
129 double averageNormalizedOfferedLoad)
131 NS_LOG_FUNCTION(
this << satId << beamId << carrierId << (uint32_t)allocationChannelId
132 << averageNormalizedOfferedLoad);
134 bool isLowRandomAccessLoad =
true;
135 std::map<std::tuple<uint32_t, uint32_t, uint8_t>,
bool>::iterator findResult;
136 std::pair<std::map<std::tuple<uint32_t, uint32_t, uint8_t>,
bool>::iterator,
bool> insertResult;
144 std::make_pair(std::make_tuple(satId, beamId, allocationChannelId),
145 isLowRandomAccessLoad));
147 if (!insertResult.second)
149 NS_FATAL_ERROR(
"SatNcc::DoRandomAccessDynamicLoadControl - Insert failed");
153 isLowRandomAccessLoad = insertResult.second;
158 isLowRandomAccessLoad = findResult->second;
161 NS_LOG_INFO(
"Beam: " << beamId <<
", carrier ID: " << carrierId
162 <<
", AC: " << (uint32_t)allocationChannelId
163 <<
" - Measuring the average normalized offered random access load: "
164 << averageNormalizedOfferedLoad);
166 std::map<uint8_t, double>::iterator itThreshold =
171 NS_FATAL_ERROR(
"SatNcc::DoRandomAccessDynamicLoadControl - Average normalized offered load "
172 "threshold not set for beam: "
173 << beamId <<
", carrier: " << carrierId
174 <<
", allocation channel: " << (uint32_t)allocationChannelId);
178 if (isLowRandomAccessLoad)
180 NS_LOG_INFO(
"Beam: " << beamId <<
", carrier ID: " << carrierId
181 <<
" - Currently low load in effect for allocation channel: "
182 << (uint32_t)allocationChannelId);
184 if (averageNormalizedOfferedLoad >= itThreshold->second)
186 std::map<uint8_t, uint16_t>::iterator it;
192 NS_FATAL_ERROR(
"SatNcc::DoRandomAccessDynamicLoadControl - High load backoff "
193 "probability not set for allocation channel: "
194 << (uint32_t)allocationChannelId);
197 uint16_t probability = it->second;
203 NS_FATAL_ERROR(
"SatNcc::DoRandomAccessDynamicLoadControl - High load backoff time "
204 "not set for allocation channel: "
205 << (uint32_t)allocationChannelId);
208 uint16_t time = it->second;
215 allocationChannelId);
217 NS_LOG_INFO(
"Beam: " << beamId <<
", carrier ID: " << carrierId
218 <<
", AC: " << (uint32_t)allocationChannelId
219 <<
" - Switching to HIGH LOAD back off parameterization");
228 NS_LOG_INFO(
"Beam: " << beamId <<
", carrier ID: " << carrierId
229 <<
" - Currently high load in effect for allocation channel: "
230 << (uint32_t)allocationChannelId);
233 if (averageNormalizedOfferedLoad < itThreshold->second)
235 std::map<uint8_t, uint16_t>::iterator it;
241 NS_FATAL_ERROR(
"SatNcc::DoRandomAccessDynamicLoadControl - Low load backoff "
242 "probability not set for allocation channel: "
243 << (uint32_t)allocationChannelId);
246 uint16_t probability = it->second;
252 NS_FATAL_ERROR(
"SatNcc::DoRandomAccessDynamicLoadControl - Low load backoff time "
253 "not set for allocation channel: "
254 << (uint32_t)allocationChannelId);
257 uint16_t time = it->second;
264 allocationChannelId);
266 NS_LOG_INFO(
"Beam: " << beamId <<
", carrier ID: " << carrierId
267 <<
", AC: " << (uint32_t)allocationChannelId
268 <<
" - Switching to LOW LOAD back off parameterization");
278 uint16_t backoffTime,
281 uint8_t allocationChannelId)
283 NS_LOG_FUNCTION(
this);
285 Ptr<SatRaMessage> raMsg = CreateObject<SatRaMessage>();
286 std::map<std::pair<uint32_t, uint32_t>, Ptr<SatBeamScheduler>>::iterator iterator =
291 NS_FATAL_ERROR(
"SatNcc::SendRaControlMessage - Beam scheduler not found");
295 raMsg->SetAllocationChannelId(allocationChannelId);
298 raMsg->SetBackoffProbability(backoffProbability);
299 raMsg->SetBackoffTime(backoffTime);
301 NS_LOG_INFO(
"Sending random access control message for AC: "
302 << (uint32_t)allocationChannelId <<
", backoff probability: " << backoffProbability
303 <<
", backoff time: " << backoffTime);
305 iterator->second->Send(raMsg);
311 NS_LOG_FUNCTION(
this << satId << beamId << utId << crMsg);
321 Ptr<SatSuperframeSeq> seq,
322 uint32_t maxFrameSize,
325 NS_LOG_FUNCTION(
this << satId << beamId << &cb);
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(beamId, cb, seq, maxFrameSize, gwAddress);
339 scheduler->SetSendTbtpCallback(tbtpCb);
341 m_beamSchedulers.insert(std::make_pair(std::make_pair(satId, beamId), scheduler));
349 Callback<void, uint32_t> setRaChannelCallback,
352 NS_LOG_FUNCTION(
this << utId << beamId);
354 std::map<std::pair<uint32_t, uint32_t>, Ptr<SatBeamScheduler>>::iterator iterator =
359 NS_FATAL_ERROR(
"Beam where tried to add, not found.");
362 if (!verifyExisting || !(
m_beamSchedulers[std::make_pair(satId, beamId)]->HasUt(utId)))
371 NS_LOG_FUNCTION(
this << utId << beamId);
381 uint16_t lowLoadBackOffProbability)
383 NS_LOG_FUNCTION(
this << (uint32_t)allocationChannelId << lowLoadBackOffProbability);
385 NS_LOG_INFO(
"AC: " << (uint32_t)allocationChannelId
386 <<
", low load backoff probability: " << lowLoadBackOffProbability);
392 uint16_t highLoadBackOffProbability)
394 NS_LOG_FUNCTION(
this << (uint32_t)allocationChannelId << highLoadBackOffProbability);
396 NS_LOG_INFO(
"AC: " << (uint32_t)allocationChannelId
397 <<
", high load backoff probability: " << highLoadBackOffProbability);
404 NS_LOG_FUNCTION(
this << (uint32_t)allocationChannelId << lowLoadBackOffTime);
406 NS_LOG_INFO(
"AC: " << (uint32_t)allocationChannelId
407 <<
", low load backoff time: " << lowLoadBackOffTime);
413 uint16_t highLoadBackOffTime)
415 NS_LOG_FUNCTION(
this << (uint32_t)allocationChannelId << highLoadBackOffTime);
417 NS_LOG_INFO(
"AC: " << (uint32_t)allocationChannelId
418 <<
", high load backoff time: " << highLoadBackOffTime);
426 NS_LOG_FUNCTION(
this << (uint32_t)allocationChannelId << threshold);
428 NS_LOG_INFO(
"AC: " << (uint32_t)allocationChannelId
429 <<
", average normalized offered load threshold: " << threshold);
433 Ptr<SatBeamScheduler>
436 NS_LOG_FUNCTION(
this << satId << beamId);
438 std::map<std::pair<uint32_t, uint32_t>, Ptr<SatBeamScheduler>>::const_iterator it =
454 NS_LOG_FUNCTION(
this << utId << satId << srcBeamId << destBeamId);
459 if (!srcScheduler || !destScheduler)
461 NS_FATAL_ERROR(
"Source or destination beam not configured");
464 srcScheduler->TransferUtToBeam(utId, destScheduler);
471 NS_LOG_FUNCTION(
this << utId << satId << srcBeamId << destBeamId);
478 NS_FATAL_ERROR(
"Source beam does not exist!");
483 NS_LOG_WARN(
"Destination beam does not exist, cancel handover");
485 Ptr<SatTimuMessage> timuMsg = scheduler->CreateTimu();
486 scheduler->SendTo(timuMsg, utId);
488 else if (scheduler->HasUt(utId) && !destination->HasUt(utId))
490 NS_LOG_INFO(
"Performing handover!");
492 Ptr<SatTimuMessage> timuMsg = destination->CreateTimu();
493 scheduler->SendTo(timuMsg, utId);
503 else if (!scheduler->HasUt(utId) && destination->HasUt(utId))
505 NS_LOG_INFO(
"Handover already performed, sending back TIM-U just in case!");
507 Ptr<SatTimuMessage> timuMsg = destination->CreateTimu();
508 scheduler->SendTo(timuMsg, utId);
512 NS_FATAL_ERROR(
"Inconsistent handover state: UT is neither in source nor destination beam; "
520 NS_LOG_FUNCTION(
this << &cb);
528 NS_LOG_FUNCTION(
this << logonChannelId);
532 beamScheduler.second->ReserveLogonChannel(logonChannelId);
539 NS_LOG_FUNCTION(
this << utId << beamId);
541 std::tuple<Address, uint32_t, uint32_t>
id = std::make_tuple(utId, satId, beamId);
553 NS_LOG_FUNCTION(
this << useLogon);
561 NS_LOG_FUNCTION(
this << useLora);
569 NS_LOG_FUNCTION(
this << utId);
571 std::tuple<Address, uint32_t, uint32_t>
id = std::make_tuple(utId, satId, beamId);
573 "UT address should be in map");
576 if (Simulator::Now() >= lastReceptionDate +
m_utTimeout)
583 Simulator::Schedule(lastReceptionDate +
m_utTimeout - Simulator::Now(),
void SetUseLora(bool useLora)
Set if SNS-3 is used with Lora standard.
void DoMoveUtBetweenBeams(Address utId, uint32_t satId, uint32_t srcBeamId, uint32_t destBeamId)
Perform terminal handover on the terestrial network.
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.
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.
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 MoveUtBetweenBeams(Address utId, uint32_t satId, uint32_t srcBeamId, uint32_t destBeamId)
Check if a terminal can be moved between two beams.
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.
void AddBeam(uint32_t satId, uint32_t beamId, SatNcc::SendCallback cb, SatNcc::SendTbtpCallback tbtpCb, Ptr< SatSuperframeSeq > seq, uint32_t maxFrameSizeInBytes, Address gwAddress)
Function for adding the beam.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.