A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
a2-a4-rsrq-handover-algorithm.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 * Copyright (c) 2013 Budiarto Herman
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 * Original work authors (from lte-enb-rrc.cc):
19 * - Nicola Baldo <nbaldo@cttc.es>
20 * - Marco Miozzo <mmiozzo@cttc.es>
21 * - Manuel Requena <manuel.requena@cttc.es>
22 *
23 * Converted to handover algorithm interface by:
24 * - Budiarto Herman <budiarto.herman@magister.fi>
25 */
26
28
29#include <ns3/log.h>
30#include <ns3/uinteger.h>
31
32#include <algorithm>
33
34namespace ns3
35{
36
37NS_LOG_COMPONENT_DEFINE("A2A4RsrqHandoverAlgorithm");
38
39NS_OBJECT_ENSURE_REGISTERED(A2A4RsrqHandoverAlgorithm);
40
42// Handover Management SAP forwarder
44
46 : m_servingCellThreshold(30),
47 m_neighbourCellOffset(1),
48 m_handoverManagementSapUser(nullptr)
49{
50 NS_LOG_FUNCTION(this);
53}
54
56{
57 NS_LOG_FUNCTION(this);
58}
59
62{
63 static TypeId tid =
64 TypeId("ns3::A2A4RsrqHandoverAlgorithm")
66 .SetGroupName("Lte")
67 .AddConstructor<A2A4RsrqHandoverAlgorithm>()
68 .AddAttribute("ServingCellThreshold",
69 "If the RSRQ of the serving cell is worse than this "
70 "threshold, neighbour cells are consider for handover. "
71 "Expressed in quantized range of [0..34] as per Section "
72 "9.1.7 of 3GPP TS 36.133.",
73 UintegerValue(30),
75 MakeUintegerChecker<uint8_t>(0, 34))
76 .AddAttribute("NeighbourCellOffset",
77 "Minimum offset between the serving and the best neighbour "
78 "cell to trigger the handover. Expressed in quantized "
79 "range of [0..34] as per Section 9.1.7 of 3GPP TS 36.133.",
82 MakeUintegerChecker<uint8_t>());
83 return tid;
84}
85
86void
88{
89 NS_LOG_FUNCTION(this << s);
91}
92
95{
96 NS_LOG_FUNCTION(this);
98}
99
100void
102{
103 NS_LOG_FUNCTION(this);
104
105 NS_LOG_LOGIC(this << " requesting Event A2 measurements"
106 << " (threshold=" << (uint16_t)m_servingCellThreshold << ")");
107 LteRrcSap::ReportConfigEutra reportConfigA2;
110 reportConfigA2.threshold1.range = m_servingCellThreshold;
114
115 NS_LOG_LOGIC(this << " requesting Event A4 measurements"
116 << " (threshold=0)");
117 LteRrcSap::ReportConfigEutra reportConfigA4;
120 reportConfigA4.threshold1.range = 0; // intentionally very low threshold
124
126}
127
128void
130{
131 NS_LOG_FUNCTION(this);
133}
134
135void
137{
138 NS_LOG_FUNCTION(this << rnti << (uint16_t)measResults.measId);
139
140 if (std::find(begin(m_a2MeasIds), end(m_a2MeasIds), measResults.measId) !=
141 std::end(m_a2MeasIds))
142 {
144 "Invalid UE measurement report");
146 }
147 else if (std::find(begin(m_a4MeasIds), end(m_a4MeasIds), measResults.measId) !=
148 std::end(m_a4MeasIds))
149 {
150 if (measResults.haveMeasResultNeighCells && !measResults.measResultListEutra.empty())
151 {
152 for (std::list<LteRrcSap::MeasResultEutra>::iterator it =
153 measResults.measResultListEutra.begin();
154 it != measResults.measResultListEutra.end();
155 ++it)
156 {
157 NS_ASSERT_MSG(it->haveRsrqResult == true,
158 "RSRQ measurement is missing from cellId " << it->physCellId);
159 UpdateNeighbourMeasurements(rnti, it->physCellId, it->rsrqResult);
160 }
161 }
162 else
163 {
165 this << " Event A4 received without measurement results from neighbouring cells");
166 }
167 }
168 else
169 {
170 NS_LOG_WARN("Ignoring measId " << (uint16_t)measResults.measId);
171 }
172
173} // end of DoReportUeMeas
174
175void
176A2A4RsrqHandoverAlgorithm::EvaluateHandover(uint16_t rnti, uint8_t servingCellRsrq)
177{
178 NS_LOG_FUNCTION(this << rnti << (uint16_t)servingCellRsrq);
179
180 MeasurementTable_t::iterator it1;
181 it1 = m_neighbourCellMeasures.find(rnti);
182
183 if (it1 == m_neighbourCellMeasures.end())
184 {
185 NS_LOG_WARN("Skipping handover evaluation for RNTI "
186 << rnti << " because neighbour cells information is not found");
187 }
188 else
189 {
190 // Find the best neighbour cell (eNB)
191 NS_LOG_LOGIC("Number of neighbour cells = " << it1->second.size());
192 uint16_t bestNeighbourCellId = 0;
193 uint8_t bestNeighbourRsrq = 0;
194 MeasurementRow_t::iterator it2;
195 for (it2 = it1->second.begin(); it2 != it1->second.end(); ++it2)
196 {
197 if ((it2->second->m_rsrq > bestNeighbourRsrq) && IsValidNeighbour(it2->first))
198 {
199 bestNeighbourCellId = it2->first;
200 bestNeighbourRsrq = it2->second->m_rsrq;
201 }
202 }
203
204 // Trigger Handover, if needed
205 if (bestNeighbourCellId > 0)
206 {
207 NS_LOG_LOGIC("Best neighbour cellId " << bestNeighbourCellId);
208
209 if ((bestNeighbourRsrq - servingCellRsrq) >= m_neighbourCellOffset)
210 {
211 NS_LOG_LOGIC("Trigger Handover to cellId " << bestNeighbourCellId);
212 NS_LOG_LOGIC("target cell RSRQ " << (uint16_t)bestNeighbourRsrq);
213 NS_LOG_LOGIC("serving cell RSRQ " << (uint16_t)servingCellRsrq);
214
215 // Inform eNodeB RRC about handover
216 m_handoverManagementSapUser->TriggerHandover(rnti, bestNeighbourCellId);
217 }
218 }
219
220 } // end of else of if (it1 == m_neighbourCellMeasures.end ())
221
222} // end of EvaluateMeasurementReport
223
224bool
226{
227 NS_LOG_FUNCTION(this << cellId);
228
235 return true;
236}
237
238void
239A2A4RsrqHandoverAlgorithm::UpdateNeighbourMeasurements(uint16_t rnti, uint16_t cellId, uint8_t rsrq)
240{
241 NS_LOG_FUNCTION(this << rnti << cellId << (uint16_t)rsrq);
242 MeasurementTable_t::iterator it1;
243 it1 = m_neighbourCellMeasures.find(rnti);
244
245 if (it1 == m_neighbourCellMeasures.end())
246 {
247 // insert a new UE entry
249 std::pair<MeasurementTable_t::iterator, bool> ret;
250 ret = m_neighbourCellMeasures.insert(std::pair<uint16_t, MeasurementRow_t>(rnti, row));
251 NS_ASSERT(ret.second);
252 it1 = ret.first;
253 }
254
256 Ptr<UeMeasure> neighbourCellMeasures;
257 std::map<uint16_t, Ptr<UeMeasure>>::iterator it2;
258 it2 = it1->second.find(cellId);
259
260 if (it2 != it1->second.end())
261 {
262 neighbourCellMeasures = it2->second;
263 neighbourCellMeasures->m_cellId = cellId;
264 neighbourCellMeasures->m_rsrp = 0;
265 neighbourCellMeasures->m_rsrq = rsrq;
266 }
267 else
268 {
269 // insert a new cell entry
270 neighbourCellMeasures = Create<UeMeasure>();
271 neighbourCellMeasures->m_cellId = cellId;
272 neighbourCellMeasures->m_rsrp = 0;
273 neighbourCellMeasures->m_rsrq = rsrq;
274 it1->second[cellId] = neighbourCellMeasures;
275 }
276
277} // end of UpdateNeighbourMeasurements
278
279} // end of namespace ns3
Handover algorithm implementation based on RSRQ measurements, Event A2 and Event A4.
static TypeId GetTypeId()
Get the type ID.
LteHandoverManagementSapUser * m_handoverManagementSapUser
Interface to the eNodeB RRC instance.
friend class MemberLteHandoverManagementSapProvider< A2A4RsrqHandoverAlgorithm >
let the forwarder class access the protected and private members
std::map< uint16_t, Ptr< UeMeasure > > MeasurementRow_t
Measurements reported by a UE for several cells.
void DoInitialize() override
Initialize() implementation.
A2A4RsrqHandoverAlgorithm()
Creates an A2-A4-RSRQ handover algorithm instance.
LteHandoverManagementSapProvider * GetLteHandoverManagementSapProvider() override
Export the "provider" part of the Handover Management SAP interface.
LteHandoverManagementSapProvider * m_handoverManagementSapProvider
Receive API calls from the eNodeB RRC instance.
bool IsValidNeighbour(uint16_t cellId)
Determines if a neighbour cell is a valid destination for handover.
std::vector< uint8_t > m_a2MeasIds
The expected measurement identities for A2 measurements.
void UpdateNeighbourMeasurements(uint16_t rnti, uint16_t cellId, uint8_t rsrq)
Called when Event A4 is reported, then update the measurements table.
void DoDispose() override
Destructor implementation.
void SetLteHandoverManagementSapUser(LteHandoverManagementSapUser *s) override
Set the "user" part of the Handover Management SAP interface that this handover algorithm instance wi...
void EvaluateHandover(uint16_t rnti, uint8_t servingCellRsrq)
Called when Event A2 is detected, then trigger a handover if needed.
MeasurementTable_t m_neighbourCellMeasures
Table of measurement reports from all UEs.
uint8_t m_servingCellThreshold
The ServingCellThreshold attribute.
void DoReportUeMeas(uint16_t rnti, LteRrcSap::MeasResults measResults) override
Implementation of LteHandoverManagementSapProvider::ReportUeMeas.
std::vector< uint8_t > m_a4MeasIds
The expected measurement identities for A4 measurements.
uint8_t m_neighbourCellOffset
The NeighbourCellOffset attribute.
The abstract base class of a handover algorithm that operates using the Handover Management SAP inter...
Service Access Point (SAP) offered by the handover algorithm instance to the eNodeB RRC instance.
Service Access Point (SAP) offered by the eNodeB RRC instance to the handover algorithm instance.
virtual void TriggerHandover(uint16_t rnti, uint16_t targetCellId)=0
Instruct the eNodeB RRC entity to prepare a handover.
virtual std::vector< uint8_t > AddUeMeasReportConfigForHandover(LteRrcSap::ReportConfigEutra reportConfig)=0
Request a certain reporting configuration to be fulfilled by the UEs attached to the eNodeB entity.
virtual void DoInitialize()
Initialize() implementation.
Definition: object.cc:360
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:936
Hold an unsigned integer type.
Definition: uinteger.h:45
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition: uinteger.h:46
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:261
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t rsrqResult
the RSRQ result
Definition: lte-rrc-sap.h:675
MeasResults structure.
Definition: lte-rrc-sap.h:717
uint8_t measId
measure ID
Definition: lte-rrc-sap.h:718
bool haveMeasResultNeighCells
have measure result neighbor cells
Definition: lte-rrc-sap.h:720
std::list< MeasResultEutra > measResultListEutra
measure result list eutra
Definition: lte-rrc-sap.h:721
MeasResultPCell measResultPCell
measurement result primary cell
Definition: lte-rrc-sap.h:719
Specifies criteria for triggering of an E-UTRA measurement reporting event.
Definition: lte-rrc-sap.h:373
enum ns3::LteRrcSap::ReportConfigEutra::@62 eventId
Event enumeration.
@ RSRQ
Reference Signal Received Quality.
Definition: lte-rrc-sap.h:426
@ EVENT_A2
Event A2: Serving becomes worse than absolute threshold.
Definition: lte-rrc-sap.h:385
@ EVENT_A4
Event A4: Neighbour becomes better than absolute threshold.
Definition: lte-rrc-sap.h:387
enum ns3::LteRrcSap::ReportConfigEutra::@65 reportInterval
Report interval enumeration.
enum ns3::LteRrcSap::ReportConfigEutra::@63 triggerQuantity
Trigger type enumeration.
ThresholdEutra threshold1
Threshold for event A1, A2, A4, and A5.
Definition: lte-rrc-sap.h:393
@ THRESHOLD_RSRQ
RSRQ is used for the threshold.
Definition: lte-rrc-sap.h:365
enum ns3::LteRrcSap::ThresholdEutra::@60 choice
Threshold enumeration.
uint8_t range
Value range used in RSRP/RSRQ threshold.
Definition: lte-rrc-sap.h:368