A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("A2A4RsrqHandoverAlgorithm");
33 
34 
35 namespace ns3 {
36 
37 NS_OBJECT_ENSURE_REGISTERED (A2A4RsrqHandoverAlgorithm);
38 
39 
41 // Handover Management SAP forwarder
43 
44 
46  : m_a2MeasId (0),
47  m_a4MeasId (0),
48  m_servingCellThreshold (30),
49  m_neighbourCellOffset (1),
50  m_handoverManagementSapUser (0)
51 {
52  NS_LOG_FUNCTION (this);
54 }
55 
56 
58 {
59  NS_LOG_FUNCTION (this);
60 }
61 
62 
63 TypeId
65 {
66  static TypeId tid = TypeId ("ns3::A2A4RsrqHandoverAlgorithm")
68  .AddConstructor<A2A4RsrqHandoverAlgorithm> ()
69  .AddAttribute ("ServingCellThreshold",
70  "If the RSRQ of the serving cell is worse than this threshold, "
71  "neighbour cells are consider for handover",
72  UintegerValue (30),
74  MakeUintegerChecker<uint8_t> (0, 34)) // RSRQ range is [0..34] as per Section 9.1.7 of 3GPP TS 36.133
75  .AddAttribute ("NeighbourCellOffset",
76  "Minimum offset between serving and best neighbour cell to trigger the Handover",
77  UintegerValue (1),
79  MakeUintegerChecker<uint8_t> ())
80  ;
81  return tid;
82 }
83 
84 
85 void
87 {
88  NS_LOG_FUNCTION (this << s);
90 }
91 
92 
95 {
96  NS_LOG_FUNCTION (this);
98 }
99 
100 
101 void
103 {
104  NS_LOG_FUNCTION (this);
105 
106  NS_LOG_LOGIC (this << " requesting Event A2 measurements"
107  << " (threshold=" << (uint16_t) m_servingCellThreshold << ")");
108  LteRrcSap::ReportConfigEutra reportConfigA2;
111  reportConfigA2.threshold1.range = m_servingCellThreshold;
115 
116  NS_LOG_LOGIC (this << " requesting Event A4 measurements"
117  << " (threshold=0)");
118  LteRrcSap::ReportConfigEutra reportConfigA4;
121  reportConfigA4.threshold1.range = 0; // intentionally very low threshold
125 
127 }
128 
129 
130 void
132 {
133  NS_LOG_FUNCTION (this);
135 }
136 
137 
138 void
140  LteRrcSap::MeasResults measResults)
141 {
142  NS_LOG_FUNCTION (this << rnti << (uint16_t) measResults.measId);
143 
144  if (measResults.measId == m_a2MeasId)
145  {
147  "Invalid UE measurement report");
148  EvaluateHandover (rnti, measResults.rsrqResult);
149  }
150  else if (measResults.measId == m_a4MeasId)
151  {
152  if (measResults.haveMeasResultNeighCells
153  && !measResults.measResultListEutra.empty ())
154  {
155  for (std::list <LteRrcSap::MeasResultEutra>::iterator it = measResults.measResultListEutra.begin ();
156  it != measResults.measResultListEutra.end ();
157  ++it)
158  {
159  NS_ASSERT_MSG (it->haveRsrqResult == true,
160  "RSRQ measurement is missing from cellId " << it->physCellId);
161  UpdateNeighbourMeasurements (rnti, it->physCellId, it->rsrqResult);
162  }
163  }
164  else
165  {
166  NS_LOG_WARN (this << " Event A4 received without measurement results from neighbouring cells");
167  }
168  }
169  else
170  {
171  NS_LOG_WARN ("Ignoring measId " << (uint16_t) measResults.measId);
172  }
173 
174 } // end of DoReportUeMeas
175 
176 
177 void
179  uint8_t servingCellRsrq)
180 {
181  NS_LOG_FUNCTION (this << rnti << (uint16_t) servingCellRsrq);
182 
183  MeasurementTable_t::iterator it1;
184  it1 = m_neighbourCellMeasures.find (rnti);
185 
186  if (it1 == m_neighbourCellMeasures.end ())
187  {
188  NS_LOG_WARN ("Skipping handover evaluation for RNTI " << rnti << " because neighbour cells information is not found");
189  }
190  else
191  {
192  // Find the best neighbour cell (eNB)
193  NS_LOG_LOGIC ("Number of neighbour cells = " << it1->second.size ());
194  uint16_t bestNeighbourCellId = 0;
195  uint8_t bestNeighbourRsrq = 0;
196  MeasurementRow_t::iterator it2;
197  for (it2 = it1->second.begin (); it2 != it1->second.end (); ++it2)
198  {
199  if ((it2->second->m_rsrq > bestNeighbourRsrq)
200  && IsValidNeighbour (it2->first))
201  {
202  bestNeighbourCellId = it2->first;
203  bestNeighbourRsrq = it2->second->m_rsrq;
204  }
205  }
206 
207  // Trigger Handover, if needed
208  if (bestNeighbourCellId > 0)
209  {
210  NS_LOG_LOGIC ("Best neighbour cellId " << bestNeighbourCellId);
211 
212  if ((bestNeighbourRsrq - servingCellRsrq) >= m_neighbourCellOffset)
213  {
214  NS_LOG_LOGIC ("Trigger Handover to cellId " << bestNeighbourCellId);
215  NS_LOG_LOGIC ("target cell RSRQ " << (uint16_t) bestNeighbourRsrq);
216  NS_LOG_LOGIC ("serving cell RSRQ " << (uint16_t) servingCellRsrq);
217 
218  // Inform eNodeB RRC about handover
220  bestNeighbourCellId);
221  }
222  }
223 
224  } // end of else of if (it1 == m_neighbourCellMeasures.end ())
225 
226 } // end of EvaluateMeasurementReport
227 
228 
229 bool
231 {
232  NS_LOG_FUNCTION (this << cellId);
233 
240  return true;
241 }
242 
243 
244 void
246  uint16_t cellId,
247  uint8_t rsrq)
248 {
249  NS_LOG_FUNCTION (this << rnti << cellId << (uint16_t) rsrq);
250  MeasurementTable_t::iterator it1;
251  it1 = m_neighbourCellMeasures.find (rnti);
252 
253  if (it1 == m_neighbourCellMeasures.end ())
254  {
255  // insert a new UE entry
256  MeasurementRow_t row;
257  std::pair<MeasurementTable_t::iterator, bool> ret;
258  ret = m_neighbourCellMeasures.insert (std::pair<uint16_t, MeasurementRow_t> (rnti, row));
259  NS_ASSERT (ret.second);
260  it1 = ret.first;
261  }
262 
263  NS_ASSERT (it1 != m_neighbourCellMeasures.end ());
264  Ptr<UeMeasure> neighbourCellMeasures;
265  std::map<uint16_t, Ptr<UeMeasure> >::iterator it2;
266  it2 = it1->second.find (cellId);
267 
268  if (it2 != it1->second.end ())
269  {
270  neighbourCellMeasures = it2->second;
271  neighbourCellMeasures->m_cellId = cellId;
272  neighbourCellMeasures->m_rsrp = 0;
273  neighbourCellMeasures->m_rsrq = rsrq;
274  }
275  else
276  {
277  // insert a new cell entry
278  neighbourCellMeasures = Create<UeMeasure> ();
279  neighbourCellMeasures->m_cellId = cellId;
280  neighbourCellMeasures->m_rsrp = 0;
281  neighbourCellMeasures->m_rsrq = rsrq;
282  it1->second[cellId] = neighbourCellMeasures;
283  }
284 
285 } // end of UpdateNeighbourMeasurements
286 
287 
288 } // end of namespace ns3
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
#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...
Reference Signal Received Quality.
Definition: lte-rrc-sap.h:300
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
virtual void SetLteHandoverManagementSapUser(LteHandoverManagementSapUser *s)
Set the "user" part of the Handover Management SAP interface that this handover algorithm instance wi...
LteHandoverManagementSapProvider * m_handoverManagementSapProvider
std::list< MeasResultEutra > measResultListEutra
Definition: lte-rrc-sap.h:519
ThresholdEutra threshold1
Threshold for event A1, A2, A4, and A5.
Definition: lte-rrc-sap.h:276
Specifies criteria for triggering of an E-UTRA measurement reporting event.
Definition: lte-rrc-sap.h:258
virtual LteHandoverManagementSapProvider * GetLteHandoverManagementSapProvider()
Export the "provider" part of the Handover Management SAP interface.
enum ns3::LteRrcSap::ReportConfigEutra::@72 eventId
Choice of E-UTRA event triggered reporting criteria.
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:61
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
A2A4RsrqHandoverAlgorithm()
Creates an A2-A4-RSRQ handover algorithm instance.
enum ns3::LteRrcSap::ReportConfigEutra::@76 reportInterval
Indicates the interval between periodical reports.
Event A2: Serving becomes worse than absolute threshold.
Definition: lte-rrc-sap.h:269
Event A4: Neighbour becomes better than absolute threshold.
Definition: lte-rrc-sap.h:271
void DoReportUeMeas(uint16_t rnti, LteRrcSap::MeasResults measResults)
Implementation of LteHandoverManagementSapProvider::ReportUeMeas.
LteHandoverManagementSapUser * m_handoverManagementSapUser
virtual void DoInitialize()
This method is called only once by Object::Initialize.
RSRQ is used for the threshold.
Definition: lte-rrc-sap.h:252
Hold an unsigned integer type.
Definition: uinteger.h:46
Ptr< SampleEmitter > s
Template for the implementation of the LteHandoverManagementSapProvider as a member of an owner class...
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:233
enum ns3::LteRrcSap::ThresholdEutra::@70 choice
uint8_t range
Value range used in RSRP/RSRQ threshold.
Definition: lte-rrc-sap.h:254
#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:84
enum ns3::LteRrcSap::ReportConfigEutra::@74 triggerQuantity
The quantities used to evaluate the triggering condition for the event, see 3GPP TS 36...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:203
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)
virtual uint8_t AddUeMeasReportConfigForHandover(LteRrcSap::ReportConfigEutra reportConfig)=0
Request a certain reporting configuration to be fulfilled by the UEs attached to the eNodeB entity...
std::map< uint16_t, Ptr< UeMeasure > > MeasurementRow_t
void EvaluateHandover(uint16_t rnti, uint8_t servingCellRsrq)
virtual void DoDispose()
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
Service Access Point (SAP) offered by the eNodeB RRC instance to the handover algorithm instance...
virtual void DoInitialize(void)
This method is called only once by Object::Initialize.
Definition: object.cc:342