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 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Original work authors (from lte-enb-rrc.cc):
8 * Nicola Baldo <nbaldo@cttc.es>
9 * Marco Miozzo <mmiozzo@cttc.es>
10 * Manuel Requena <manuel.requena@cttc.es>
11 *
12 * Converted to handover algorithm interface by:
13 * Budiarto Herman <budiarto.herman@magister.fi>
14 */
15
17
18#include <ns3/log.h>
19#include <ns3/uinteger.h>
20
21#include <algorithm>
22
23namespace ns3
24{
25
26NS_LOG_COMPONENT_DEFINE("A2A4RsrqHandoverAlgorithm");
27
28NS_OBJECT_ENSURE_REGISTERED(A2A4RsrqHandoverAlgorithm);
29
30///////////////////////////////////////////
31// Handover Management SAP forwarder
32///////////////////////////////////////////
33
35 : m_servingCellThreshold(30),
36 m_neighbourCellOffset(1),
37 m_handoverManagementSapUser(nullptr)
38{
39 NS_LOG_FUNCTION(this);
42}
43
48
51{
52 static TypeId tid =
53 TypeId("ns3::A2A4RsrqHandoverAlgorithm")
55 .SetGroupName("Lte")
56 .AddConstructor<A2A4RsrqHandoverAlgorithm>()
57 .AddAttribute("ServingCellThreshold",
58 "If the RSRQ of the serving cell is worse than this "
59 "threshold, neighbour cells are consider for handover. "
60 "Expressed in quantized range of [0..34] as per Section "
61 "9.1.7 of 3GPP TS 36.133.",
62 UintegerValue(30),
65 .AddAttribute("NeighbourCellOffset",
66 "Minimum offset between the serving and the best neighbour "
67 "cell to trigger the handover. Expressed in quantized "
68 "range of [0..34] as per Section 9.1.7 of 3GPP TS 36.133.",
72 return tid;
73}
74
75void
81
88
89void
91{
92 NS_LOG_FUNCTION(this);
93
94 NS_LOG_LOGIC(this << " requesting Event A2 measurements"
95 << " (threshold=" << (uint16_t)m_servingCellThreshold << ")");
96 LteRrcSap::ReportConfigEutra reportConfigA2;
103
104 NS_LOG_LOGIC(this << " requesting Event A4 measurements"
105 << " (threshold=0)");
106 LteRrcSap::ReportConfigEutra reportConfigA4;
109 reportConfigA4.threshold1.range = 0; // intentionally very low threshold
113
115}
116
117void
123
124void
126{
127 NS_LOG_FUNCTION(this << rnti << (uint16_t)measResults.measId);
128
129 if (std::find(begin(m_a2MeasIds), end(m_a2MeasIds), measResults.measId) !=
130 std::end(m_a2MeasIds))
131 {
133 "Invalid UE measurement report");
135 }
136 else if (std::find(begin(m_a4MeasIds), end(m_a4MeasIds), measResults.measId) !=
137 std::end(m_a4MeasIds))
138 {
139 if (measResults.haveMeasResultNeighCells && !measResults.measResultListEutra.empty())
140 {
141 for (auto it = measResults.measResultListEutra.begin();
142 it != measResults.measResultListEutra.end();
143 ++it)
144 {
145 NS_ASSERT_MSG(it->haveRsrqResult == true,
146 "RSRQ measurement is missing from cellId " << it->physCellId);
147 UpdateNeighbourMeasurements(rnti, it->physCellId, it->rsrqResult);
148 }
149 }
150 else
151 {
153 this << " Event A4 received without measurement results from neighbouring cells");
154 }
155 }
156 else
157 {
158 NS_LOG_WARN("Ignoring measId " << (uint16_t)measResults.measId);
159 }
160
161} // end of DoReportUeMeas
162
163void
164A2A4RsrqHandoverAlgorithm::EvaluateHandover(uint16_t rnti, uint8_t servingCellRsrq)
165{
166 NS_LOG_FUNCTION(this << rnti << (uint16_t)servingCellRsrq);
167
168 auto it1 = m_neighbourCellMeasures.find(rnti);
169
170 if (it1 == m_neighbourCellMeasures.end())
171 {
172 NS_LOG_WARN("Skipping handover evaluation for RNTI "
173 << rnti << " because neighbour cells information is not found");
174 }
175 else
176 {
177 // Find the best neighbour cell (eNB)
178 NS_LOG_LOGIC("Number of neighbour cells = " << it1->second.size());
179 uint16_t bestNeighbourCellId = 0;
180 uint8_t bestNeighbourRsrq = 0;
181 for (auto it2 = it1->second.begin(); it2 != it1->second.end(); ++it2)
182 {
183 if ((it2->second->m_rsrq > bestNeighbourRsrq) && IsValidNeighbour(it2->first))
184 {
185 bestNeighbourCellId = it2->first;
186 bestNeighbourRsrq = it2->second->m_rsrq;
187 }
188 }
189
190 // Trigger Handover, if needed
191 if (bestNeighbourCellId > 0)
192 {
193 NS_LOG_LOGIC("Best neighbour cellId " << bestNeighbourCellId);
194
195 if ((bestNeighbourRsrq - servingCellRsrq) >= m_neighbourCellOffset)
196 {
197 NS_LOG_LOGIC("Trigger Handover to cellId " << bestNeighbourCellId);
198 NS_LOG_LOGIC("target cell RSRQ " << (uint16_t)bestNeighbourRsrq);
199 NS_LOG_LOGIC("serving cell RSRQ " << (uint16_t)servingCellRsrq);
200
201 // Inform eNodeB RRC about handover
202 m_handoverManagementSapUser->TriggerHandover(rnti, bestNeighbourCellId);
203 }
204 }
205
206 } // end of else of if (it1 == m_neighbourCellMeasures.end ())
207
208} // end of EvaluateMeasurementReport
209
210bool
212{
213 NS_LOG_FUNCTION(this << cellId);
214
215 /**
216 * @todo In the future, this function can be expanded to validate whether the
217 * neighbour cell is a valid target cell, e.g., taking into account the
218 * NRT in ANR and whether it is a CSG cell with closed access.
219 */
220
221 return true;
222}
223
224void
225A2A4RsrqHandoverAlgorithm::UpdateNeighbourMeasurements(uint16_t rnti, uint16_t cellId, uint8_t rsrq)
226{
227 NS_LOG_FUNCTION(this << rnti << cellId << (uint16_t)rsrq);
228 auto it1 = m_neighbourCellMeasures.find(rnti);
229
230 if (it1 == m_neighbourCellMeasures.end())
231 {
232 // insert a new UE entry
234 auto ret = m_neighbourCellMeasures.insert(std::pair<uint16_t, MeasurementRow_t>(rnti, row));
235 NS_ASSERT(ret.second);
236 it1 = ret.first;
237 }
238
240 Ptr<UeMeasure> neighbourCellMeasures;
241 auto it2 = it1->second.find(cellId);
242
243 if (it2 != it1->second.end())
244 {
245 neighbourCellMeasures = it2->second;
246 neighbourCellMeasures->m_cellId = cellId;
247 neighbourCellMeasures->m_rsrp = 0;
248 neighbourCellMeasures->m_rsrq = rsrq;
249 }
250 else
251 {
252 // insert a new cell entry
253 neighbourCellMeasures = Create<UeMeasure>();
254 neighbourCellMeasures->m_cellId = cellId;
255 neighbourCellMeasures->m_rsrp = 0;
256 neighbourCellMeasures->m_rsrq = rsrq;
257 it1->second[cellId] = neighbourCellMeasures;
258 }
259
260} // end of UpdateNeighbourMeasurements
261
262} // 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:440
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Hold an unsigned integer type.
Definition uinteger.h:34
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#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:75
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition uinteger.h:35
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#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:250
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t rsrqResult
the RSRQ result
MeasResults structure.
uint8_t measId
measure ID
bool haveMeasResultNeighCells
have measure result neighbor cells
std::list< MeasResultEutra > measResultListEutra
measure result list eutra
MeasResultPCell measResultPCell
measurement result primary cell
Specifies criteria for triggering of an E-UTRA measurement reporting event.
enum ns3::LteRrcSap::ReportConfigEutra::@62 eventId
Event enumeration.
@ RSRQ
Reference Signal Received Quality.
@ EVENT_A2
Event A2: Serving becomes worse than absolute threshold.
@ EVENT_A4
Event A4: Neighbour becomes better than absolute threshold.
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.
@ THRESHOLD_RSRQ
RSRQ is used for the threshold.
enum ns3::LteRrcSap::ThresholdEutra::@60 choice
Threshold enumeration.
uint8_t range
Value range used in RSRP/RSRQ threshold.