satellite-ut-handover-module.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2018 CNES
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathias Ettinger <mettinger@toulouse.viveris.fr>
19  */
20 
22 
23 #include "geo-coordinate.h"
25 
26 #include <ns3/log.h>
27 #include <ns3/simulator.h>
28 
29 NS_LOG_COMPONENT_DEFINE("SatUtHandoverModule");
30 
31 namespace ns3
32 {
33 
34 NS_OBJECT_ENSURE_REGISTERED(SatUtHandoverModule);
35 
36 TypeId
38 {
39  static TypeId tid =
40  TypeId("ns3::SatUtHandoverModule")
41  .SetParent<Object>()
42  .AddConstructor<SatUtHandoverModule>()
43  .AddAttribute("Timeout",
44  "Amount of time to wait before sending a new handover recommendation if "
45  "no TIM-U is received",
46  TimeValue(MilliSeconds(600)),
48  MakeTimeChecker())
49  .AddTraceSource("AntennaGainTrace",
50  "Trace antenna gains when checking for beam compliance",
51  MakeTraceSourceAccessor(&SatUtHandoverModule::m_antennaGainTrace),
52  "ns3::SatAntennaGainPattern::AntennaGainTrace");
53  return tid;
54 }
55 
56 TypeId
58 {
59  NS_LOG_FUNCTION(this);
60 
61  return GetTypeId();
62 }
63 
64 void
66 {
67  NS_LOG_FUNCTION(this);
68 
69  m_handoverCallback.Nullify();
70  m_antennaGainPatterns = NULL;
71 
72  Object::DoDispose();
73 }
74 
76  : m_antennaGainPatterns(NULL),
77  m_lastMessageSentAt(0),
78  m_repeatRequestTimeout(600),
79  m_hasPendingRequest(false),
80  m_askedBeamId(0)
81 {
82  NS_LOG_FUNCTION(this);
83 
84  NS_FATAL_ERROR("SatUtHandoverModule default constructor should not be used!");
85 }
86 
87 SatUtHandoverModule::SatUtHandoverModule(Ptr<SatAntennaGainPatternContainer> agpContainer)
88  : m_antennaGainPatterns(agpContainer),
89  m_askedBeamId(0)
90 {
91  NS_LOG_FUNCTION(this << agpContainer);
92 }
93 
95 {
96  NS_LOG_FUNCTION(this);
97 }
98 
99 void
101 {
102  NS_LOG_FUNCTION(this << &cb);
103 
104  m_handoverCallback = cb;
105 }
106 
107 uint32_t
109 {
110  return m_askedBeamId;
111 }
112 
113 bool
115 {
116  NS_LOG_FUNCTION(this << beamId);
117 
118  if (m_askedBeamId == beamId)
119  {
120  // In case TIM-U was received successfuly, the last asked beam should
121  // match the current beamId. So reset the timeout feature.
122  m_hasPendingRequest = false;
123  }
124 
125  Ptr<SatMobilityModel> mobilityModel = GetObject<SatMobilityModel>();
126  if (!mobilityModel)
127  {
128  NS_LOG_FUNCTION("Bailing out for lack of mobility model");
129  return false;
130  }
131 
132  // If current beam is still valid, do nothing
133  GeoCoordinate coords = mobilityModel->GetGeoPosition();
134  Ptr<SatAntennaGainPattern> agp = m_antennaGainPatterns->GetAntennaGainPattern(beamId);
135  Ptr<SatMobilityModel> mobility = m_antennaGainPatterns->GetAntennaMobility(satId);
136  if (agp->IsValidPosition(coords, m_antennaGainTrace, mobility))
137  {
138  NS_LOG_FUNCTION("Current beam is good, do nothing");
139  m_hasPendingRequest = false;
140  return false;
141  }
142 
143  // Current beam ID is no longer valid, check for better beam and ask for handover
144  uint32_t bestBeamId = m_askedBeamId;
145  if (!m_hasPendingRequest)
146  {
147  bestBeamId = m_antennaGainPatterns->GetBestBeamId(satId, coords, false);
148  }
149 
150  Time now = Simulator::Now();
151  if (bestBeamId != beamId &&
153  {
154  NS_LOG_FUNCTION("Sending handover recommendation for beam " << bestBeamId);
155  m_handoverCallback(bestBeamId);
156  m_lastMessageSentAt = now;
157  m_hasPendingRequest = true;
158  m_askedBeamId = bestBeamId;
159  return true;
160  }
161 
162  return false;
163 }
164 
165 } // namespace ns3
GeoCoordinate class is used to store and operate with geodetic coordinates.
Callback< void, uint32_t > HandoverRequestCallback
Handover recommendation message sending callback.
void SetHandoverRequestCallback(SatUtHandoverModule::HandoverRequestCallback cb)
Set the handover recommendation message sending callback.
~SatUtHandoverModule()
Destroy a SatUtHandoverModule.
bool CheckForHandoverRecommendation(uint32_t satId, uint32_t beamId)
Inspect whether or not the given beam is still suitable for the underlying mobility model.
virtual void DoDispose()
Dispose of this class instance.
SatUtHandoverModule()
Default constructor, which is not used.
HandoverRequestCallback m_handoverCallback
Ptr< SatAntennaGainPatternContainer > m_antennaGainPatterns
uint32_t GetAskedBeamId()
Get the best beam ID.
static TypeId GetTypeId(void)
Derived from Object.
TracedCallback< double > m_antennaGainTrace
virtual TypeId GetInstanceTypeId(void) const
Derived from Object.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.