28 #include <ns3/simulator.h>
29 #include <ns3/uinteger.h>
35 NS_LOG_COMPONENT_DEFINE(
"SatHandoverModule");
40 NS_OBJECT_ENSURE_REGISTERED(SatHandoverModule);
46 TypeId(
"ns3::SatHandoverModule")
48 .AddConstructor<SatHandoverModule>()
49 .AddAttribute(
"Timeout",
50 "Amount of time to wait before sending a new handover recommendation if "
51 "no TIM-U is received",
52 TimeValue(MilliSeconds(1000)),
55 .AddAttribute(
"HandoverDecisionAlgorithm",
56 "Algorithm to use for handovers",
58 MakeEnumAccessor<SatHandoverModule::HandoverDecisionAlgorithm_t>(
61 .AddAttribute(
"NumberClosestSats",
62 "Number of satellites to consider when using algorithm SAT_N_CLOSEST_SAT",
65 MakeUintegerChecker<uint32_t>())
66 .AddTraceSource(
"AntennaGainTrace",
67 "Trace antenna gains when checking for beam compliance",
69 "ns3::SatAntennaGainPattern::AntennaGainTrace");
76 NS_LOG_FUNCTION(
this);
84 NS_LOG_FUNCTION(
this);
93 : m_antennaGainPatterns(nullptr),
94 m_lastMessageSentAt(0),
95 m_repeatRequestTimeout(600),
96 m_hasPendingRequest(false),
100 NS_LOG_FUNCTION(
this);
102 NS_FATAL_ERROR(
"SatHandoverModule default constructor should not be used!");
106 NodeContainer satellites,
107 Ptr<SatAntennaGainPatternContainer> agpContainer)
108 : m_handoverDecisionAlgorithm(SAT_N_CLOSEST_SAT),
109 m_numberClosestSats(1),
111 m_satellites(satellites),
112 m_antennaGainPatterns(agpContainer),
113 m_lastMessageSentAt(0),
114 m_repeatRequestTimeout(600),
115 m_hasPendingRequest(false),
119 NS_LOG_FUNCTION(
this << agpContainer);
124 NS_LOG_FUNCTION(
this);
130 NS_LOG_FUNCTION(
this << &cb);
150 NS_LOG_FUNCTION(
this);
158 NS_LOG_FUNCTION(
this << satId << beamId);
160 Time now = Simulator::Now();
166 Ptr<SatMobilityModel> mobilityModel = GetObject<SatMobilityModel>();
169 NS_LOG_FUNCTION(
"Bailing out for lack of mobility model");
179 NS_LOG_FUNCTION(
"Current beam is good, do nothing");
194 bestSatId = bestSatAndBeam.first;
195 bestBeamId = bestSatAndBeam.second;
199 NS_FATAL_ERROR(
"Incorrect handover decision algorithm");
203 if ((bestSatId != satId || bestBeamId != beamId) &&
206 NS_LOG_FUNCTION(
"Sending handover recommendation for beam " << bestBeamId <<
" on sat "
220 std::vector<uint32_t>
223 NS_LOG_FUNCTION(
this << numberOfSats);
225 std::map<double, uint32_t> satellites;
235 satellites.emplace(distance, i);
238 std::vector<uint32_t> closest;
240 for (
auto&& [dist, satId] : satellites)
242 if (i++ < numberOfSats)
244 closest.push_back(satId);
255 std::pair<uint32_t, uint32_t>
258 NS_LOG_FUNCTION(
this << coords);
262 uint32_t bestSatId = satellites[0];
268 for (uint32_t i = 1; i < satellites.size(); i++)
278 bestSatId = satellites[i];
284 return std::make_pair(bestSatId, bestBeamId);
GeoCoordinate class is used to store and operate with geodetic coordinates.
void HandoverFinished()
Method to call when a handover has been performed.
HandoverDecisionAlgorithm_t m_handoverDecisionAlgorithm
Algorithm used to detect if handover is needed.
uint32_t GetAskedBeamId()
Get the best beam ID.
~SatHandoverModule()
Destroy a SatHandoverModule.
void SetHandoverRequestCallback(SatHandoverModule::HandoverRequestCallback cb)
Set the handover recommendation message sending callback.
HandoverRequestCallback m_handoverCallback
virtual TypeId GetInstanceTypeId(void) const
Derived from Object.
SatHandoverModule()
Default constructor, which is not used.
bool CheckForHandoverRecommendation(uint32_t satId, uint32_t beamId)
Inspect whether or not the given beam is still suitable for the underlying mobility model.
Time m_repeatRequestTimeout
virtual void DoDispose()
Dispose of this class instance.
NodeContainer m_satellites
std::pair< uint32_t, uint32_t > AlgorithmNClosest(GeoCoordinate coords)
Handover algorithm choosing best beam between N closest satellites.
TracedCallback< double > m_antennaGainTrace
Ptr< SatAntennaGainPatternContainer > m_antennaGainPatterns
uint32_t GetAskedSatId()
Get the best sat ID.
uint32_t m_numberClosestSats
Number of satellites to consider when using algorithm SAT_N_CLOSEST_SAT.
std::vector< uint32_t > GetNClosestSats(uint32_t numberOfSats)
Get the N closest satellites to the UT node.
static TypeId GetTypeId(void)
Derived from Object.
Callback< void, uint32_t, uint32_t > HandoverRequestCallback
Handover recommendation message sending callback.
Keep track of the current position and velocity of an object in satellite network.
double GetDistanceFrom(Ptr< const SatMobilityModel > position) const
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
Ptr< SatMobilityModel > satMobility