A Discrete-Event Network Simulator
API
a2-a4-rsrq-handover-algorithm.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4  * Copyright (c) 2013 Budiarto Herman
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Original work authors (from lte-enb-rrc.cc):
20  * - Nicola Baldo <nbaldo@cttc.es>
21  * - Marco Miozzo <mmiozzo@cttc.es>
22  * - Manuel Requena <manuel.requena@cttc.es>
23  *
24  * Converted to handover algorithm interface by:
25  * - Budiarto Herman <budiarto.herman@magister.fi>
26  */
27 
29 #include <ns3/log.h>
30 #include <ns3/uinteger.h>
31 
32 namespace ns3 {
33 
34 NS_LOG_COMPONENT_DEFINE ("A2A4RsrqHandoverAlgorithm");
35 
36 NS_OBJECT_ENSURE_REGISTERED (A2A4RsrqHandoverAlgorithm);
37 
38 
40 // Handover Management SAP forwarder
42 
43 
45  : m_a2MeasId (0),
46  m_a4MeasId (0),
47  m_servingCellThreshold (30),
48  m_neighbourCellOffset (1),
49  m_handoverManagementSapUser (0)
50 {
51  NS_LOG_FUNCTION (this);
53 }
54 
55 
57 {
58  NS_LOG_FUNCTION (this);
59 }
60 
61 
62 TypeId
64 {
65  static TypeId tid = TypeId ("ns3::A2A4RsrqHandoverAlgorithm")
67  .SetGroupName("Lte")
68  .AddConstructor<A2A4RsrqHandoverAlgorithm> ()
69  .AddAttribute ("ServingCellThreshold",
70  "If the RSRQ of the serving cell is worse than this "
71  "threshold, neighbour cells are consider for handover. "
72  "Expressed in quantized range of [0..34] as per Section "
73  "9.1.7 of 3GPP TS 36.133.",
74  UintegerValue (30),
76  MakeUintegerChecker<uint8_t> (0, 34))
77  .AddAttribute ("NeighbourCellOffset",
78  "Minimum offset between the serving and the best neighbour "
79  "cell to trigger the handover. Expressed in quantized "
80  "range of [0..34] as per Section 9.1.7 of 3GPP TS 36.133.",
81  UintegerValue (1),
83  MakeUintegerChecker<uint8_t> ())
84  ;
85  return tid;
86 }
87 
88 
89 void
91 {
92  NS_LOG_FUNCTION (this << s);
94 }
95 
96 
99 {
100  NS_LOG_FUNCTION (this);
102 }
103 
104 
105 void
107 {
108  NS_LOG_FUNCTION (this);
109 
110  NS_LOG_LOGIC (this << " requesting Event A2 measurements"
111  << " (threshold=" << (uint16_t) m_servingCellThreshold << ")");
112  LteRrcSap::ReportConfigEutra reportConfigA2;
115  reportConfigA2.threshold1.range = m_servingCellThreshold;
119 
120  NS_LOG_LOGIC (this << " requesting Event A4 measurements"
121  << " (threshold=0)");
122  LteRrcSap::ReportConfigEutra reportConfigA4;
125  reportConfigA4.threshold1.range = 0; // intentionally very low threshold
129 
131 }
132 
133 
134 void
136 {
137  NS_LOG_FUNCTION (this);
139 }
140 
141 
142 void
144  LteRrcSap::MeasResults measResults)
145 {
146  NS_LOG_FUNCTION (this << rnti << (uint16_t) measResults.measId);
147 
148  if (measResults.measId == m_a2MeasId)
149  {
151  "Invalid UE measurement report");
152  EvaluateHandover (rnti, measResults.rsrqResult);
153  }
154  else if (measResults.measId == m_a4MeasId)
155  {
156  if (measResults.haveMeasResultNeighCells
157  && !measResults.measResultListEutra.empty ())
158  {
159  for (std::list <LteRrcSap::MeasResultEutra>::iterator it = measResults.measResultListEutra.begin ();
160  it != measResults.measResultListEutra.end ();
161  ++it)
162  {
163  NS_ASSERT_MSG (it->haveRsrqResult == true,
164  "RSRQ measurement is missing from cellId " << it->physCellId);
165  UpdateNeighbourMeasurements (rnti, it->physCellId, it->rsrqResult);
166  }
167  }
168  else
169  {
170  NS_LOG_WARN (this << " Event A4 received without measurement results from neighbouring cells");
171  }
172  }
173  else
174  {
175  NS_LOG_WARN ("Ignoring measId " << (uint16_t) measResults.measId);
176  }
177 
178 } // end of DoReportUeMeas
179 
180 
181 void
183  uint8_t servingCellRsrq)
184 {
185  NS_LOG_FUNCTION (this << rnti << (uint16_t) servingCellRsrq);
186 
187  MeasurementTable_t::iterator it1;
188  it1 = m_neighbourCellMeasures.find (rnti);
189 
190  if (it1 == m_neighbourCellMeasures.end ())
191  {
192  NS_LOG_WARN ("Skipping handover evaluation for RNTI " << rnti << " because neighbour cells information is not found");
193  }
194  else
195  {
196  // Find the best neighbour cell (eNB)
197  NS_LOG_LOGIC ("Number of neighbour cells = " << it1->second.size ());
198  uint16_t bestNeighbourCellId = 0;
199  uint8_t bestNeighbourRsrq = 0;
200  MeasurementRow_t::iterator it2;
201  for (it2 = it1->second.begin (); it2 != it1->second.end (); ++it2)
202  {
203  if ((it2->second->m_rsrq > bestNeighbourRsrq)
204  && IsValidNeighbour (it2->first))
205  {
206  bestNeighbourCellId = it2->first;
207  bestNeighbourRsrq = it2->second->m_rsrq;
208  }
209  }
210 
211  // Trigger Handover, if needed
212  if (bestNeighbourCellId > 0)
213  {
214  NS_LOG_LOGIC ("Best neighbour cellId " << bestNeighbourCellId);
215 
216  if ((bestNeighbourRsrq - servingCellRsrq) >= m_neighbourCellOffset)
217  {
218  NS_LOG_LOGIC ("Trigger Handover to cellId " << bestNeighbourCellId);
219  NS_LOG_LOGIC ("target cell RSRQ " << (uint16_t) bestNeighbourRsrq);
220  NS_LOG_LOGIC ("serving cell RSRQ " << (uint16_t) servingCellRsrq);
221 
222  // Inform eNodeB RRC about handover
224  bestNeighbourCellId);
225  }
226  }
227 
228  } // end of else of if (it1 == m_neighbourCellMeasures.end ())
229 
230 } // end of EvaluateMeasurementReport
231 
232 
233 bool
235 {
236  NS_LOG_FUNCTION (this << cellId);
237 
244  return true;
245 }
246 
247 
248 void
250  uint16_t cellId,
251  uint8_t rsrq)
252 {
253  NS_LOG_FUNCTION (this << rnti << cellId << (uint16_t) rsrq);
254  MeasurementTable_t::iterator it1;
255  it1 = m_neighbourCellMeasures.find (rnti);
256 
257  if (it1 == m_neighbourCellMeasures.end ())
258  {
259  // insert a new UE entry
260  MeasurementRow_t row;
261  std::pair<MeasurementTable_t::iterator, bool> ret;
262  ret = m_neighbourCellMeasures.insert (std::pair<uint16_t, MeasurementRow_t> (rnti, row));
263  NS_ASSERT (ret.second);
264  it1 = ret.first;
265  }
266 
267  NS_ASSERT (it1 != m_neighbourCellMeasures.end ());
268  Ptr<UeMeasure> neighbourCellMeasures;
269  std::map<uint16_t, Ptr<UeMeasure> >::iterator it2;
270  it2 = it1->second.find (cellId);
271 
272  if (it2 != it1->second.end ())
273  {
274  neighbourCellMeasures = it2->second;
275  neighbourCellMeasures->m_cellId = cellId;
276  neighbourCellMeasures->m_rsrp = 0;
277  neighbourCellMeasures->m_rsrq = rsrq;
278  }
279  else
280  {
281  // insert a new cell entry
282  neighbourCellMeasures = Create<UeMeasure> ();
283  neighbourCellMeasures->m_cellId = cellId;
284  neighbourCellMeasures->m_rsrp = 0;
285  neighbourCellMeasures->m_rsrq = rsrq;
286  it1->second[cellId] = neighbourCellMeasures;
287  }
288 
289 } // end of UpdateNeighbourMeasurements
290 
291 
292 } // end of namespace ns3
enum ns3::LteRrcSap::ThresholdEutra::@63 choice
Threshold enumeration.
virtual void DoInitialize(void)
Initialize() implementation.
Definition: object.cc:353
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
The abstract base class of a handover algorithm that operates using the Handover Management SAP inter...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
MeasurementTable_t m_neighbourCellMeasures
Table of measurement reports from all UEs.
virtual void SetLteHandoverManagementSapUser(LteHandoverManagementSapUser *s)
Set the "user" part of the Handover Management SAP interface that this handover algorithm instance wi...
LteHandoverManagementSapProvider * m_handoverManagementSapProvider
Receive API calls from the eNodeB RRC instance.
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
std::list< MeasResultEutra > measResultListEutra
measure result list eutra
Definition: lte-rrc-sap.h:677
ThresholdEutra threshold1
Threshold for event A1, A2, A4, and A5.
Definition: lte-rrc-sap.h:374
Specifies criteria for triggering of an E-UTRA measurement reporting event.
Definition: lte-rrc-sap.h:354
virtual LteHandoverManagementSapProvider * GetLteHandoverManagementSapProvider()
Export the "provider" part of the Handover Management SAP interface.
virtual void TriggerHandover(uint16_t rnti, uint16_t targetCellId)=0
Instruct the eNodeB RRC entity to prepare a handover.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
A2A4RsrqHandoverAlgorithm()
Creates an A2-A4-RSRQ handover algorithm instance.
Handover algorithm implementation based on RSRQ measurements, Event A2 and Event A4.
enum ns3::LteRrcSap::ReportConfigEutra::@66 triggerQuantity
Trigger type enumeration.
Reference Signal Received Quality.
Definition: lte-rrc-sap.h:400
uint8_t m_neighbourCellOffset
The NeighbourCellOffset attribute.
bool IsValidNeighbour(uint16_t cellId)
Determines if a neighbour cell is a valid destination for handover.
void DoReportUeMeas(uint16_t rnti, LteRrcSap::MeasResults measResults)
Implementation of LteHandoverManagementSapProvider::ReportUeMeas.
static TypeId GetTypeId()
Get the type ID.
MeasResults structure.
Definition: lte-rrc-sap.h:671
LteHandoverManagementSapUser * m_handoverManagementSapUser
Interface to the eNodeB RRC instance.
virtual void DoInitialize()
Initialize() implementation.
Hold an unsigned integer type.
Definition: uinteger.h:44
Template for the implementation of the LteHandoverManagementSapProvider as a member of an owner class...
enum ns3::LteRrcSap::ReportConfigEutra::@68 reportInterval
Report interval enumeration.
enum ns3::LteRrcSap::ReportConfigEutra::@65 eventId
Event enumeration.
uint8_t m_servingCellThreshold
The ServingCellThreshold attribute.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool haveMeasResultNeighCells
have measure result neighbor cells
Definition: lte-rrc-sap.h:676
uint8_t range
Value range used in RSRP/RSRQ threshold.
Definition: lte-rrc-sap.h:350
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
uint8_t m_a2MeasId
The expected measurement identity for A2 measurements.
uint8_t measId
measure ID
Definition: lte-rrc-sap.h:673
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:262
Service Access Point (SAP) offered by the handover algorithm instance to the eNodeB RRC instance...
void UpdateNeighbourMeasurements(uint16_t rnti, uint16_t cellId, uint8_t rsrq)
Called when Event A4 is reported, then update the measurements table.
virtual uint8_t AddUeMeasReportConfigForHandover(LteRrcSap::ReportConfigEutra reportConfig)=0
Request a certain reporting configuration to be fulfilled by the UEs attached to the eNodeB entity...
RSRQ is used for the threshold.
Definition: lte-rrc-sap.h:348
std::map< uint16_t, Ptr< UeMeasure > > MeasurementRow_t
Measurements reported by a UE for several cells.
Event A4: Neighbour becomes better than absolute threshold.
Definition: lte-rrc-sap.h:369
void EvaluateHandover(uint16_t rnti, uint8_t servingCellRsrq)
Called when Event A2 is detected, then trigger a handover if needed.
uint8_t rsrqResult
RSRQ result.
Definition: lte-rrc-sap.h:675
uint8_t m_a4MeasId
The expected measurement identity for A4 measurements.
Event A2: Serving becomes worse than absolute threshold.
Definition: lte-rrc-sap.h:367
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:45
virtual void DoDispose()
Destructor implementation.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
Service Access Point (SAP) offered by the eNodeB RRC instance to the handover algorithm instance...