A Discrete-Event Network Simulator
API
test-lte-handover-delay.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Magister Solutions
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Budiarto Herman <budiarto.herman@magister.fi>
18  * Alexander Krotov <krotov@iitp.ru>
19  */
20 
21 #include <ns3/boolean.h>
22 #include <ns3/callback.h>
23 #include <ns3/config.h>
24 #include <ns3/data-rate.h>
25 #include <ns3/internet-stack-helper.h>
26 #include <ns3/ipv4-address-helper.h>
27 #include <ns3/ipv4-interface-container.h>
28 #include <ns3/ipv4-static-routing-helper.h>
29 #include <ns3/ipv4-static-routing.h>
30 #include <ns3/log.h>
31 #include <ns3/lte-helper.h>
32 #include <ns3/mobility-helper.h>
33 #include <ns3/net-device-container.h>
34 #include <ns3/node-container.h>
35 #include <ns3/nstime.h>
36 #include <ns3/point-to-point-epc-helper.h>
37 #include <ns3/point-to-point-helper.h>
38 #include <ns3/position-allocator.h>
39 #include <ns3/simulator.h>
40 #include <ns3/test.h>
41 
42 using namespace ns3;
43 
44 NS_LOG_COMPONENT_DEFINE("LteHandoverDelayTest");
45 
54 {
55  public:
65  LteHandoverDelayTestCase(uint8_t numberOfComponentCarriers,
66  bool useIdealRrc,
67  Time handoverTime,
68  Time delayThreshold,
69  Time simulationDuration)
70  : TestCase("Verifying that the time needed for handover is under a specified threshold"),
71  m_numberOfComponentCarriers(numberOfComponentCarriers),
72  m_useIdealRrc(useIdealRrc),
73  m_handoverTime(handoverTime),
74  m_delayThreshold(delayThreshold),
75  m_simulationDuration(simulationDuration),
76  m_ueHandoverStart(Seconds(0)),
77  m_enbHandoverStart(Seconds(0))
78  {
79  }
80 
81  private:
82  void DoRun() override;
83 
92  void UeHandoverStartCallback(std::string context,
93  uint64_t imsi,
94  uint16_t cellid,
95  uint16_t rnti,
96  uint16_t targetCellId);
104  void UeHandoverEndOkCallback(std::string context,
105  uint64_t imsi,
106  uint16_t cellid,
107  uint16_t rnti);
116  void EnbHandoverStartCallback(std::string context,
117  uint64_t imsi,
118  uint16_t cellid,
119  uint16_t rnti,
120  uint16_t targetCellId);
128  void EnbHandoverEndOkCallback(std::string context,
129  uint64_t imsi,
130  uint16_t cellid,
131  uint16_t rnti);
132 
138 
141 };
142 
143 void
145 {
146  NS_LOG_INFO("-----test case: ideal RRC = " << m_useIdealRrc << " handover time = "
147  << m_handoverTime.As(Time::S) << "-----");
148 
149  /*
150  * Helpers.
151  */
152  auto epcHelper = CreateObject<PointToPointEpcHelper>();
153 
154  auto lteHelper = CreateObject<LteHelper>();
155  lteHelper->SetEpcHelper(epcHelper);
156  lteHelper->SetAttribute("UseIdealRrc", BooleanValue(m_useIdealRrc));
157  lteHelper->SetAttribute("NumberOfComponentCarriers",
158  UintegerValue(m_numberOfComponentCarriers));
159 
160  auto ccHelper = CreateObject<CcHelper>();
161  ccHelper->SetUlEarfcn(100 + 18000);
162  ccHelper->SetDlEarfcn(100);
163  ccHelper->SetUlBandwidth(25);
164  ccHelper->SetDlBandwidth(25);
165  ccHelper->SetNumberOfComponentCarriers(m_numberOfComponentCarriers);
166 
167  /*
168  * Physical layer.
169  *
170  * eNodeB 0 UE eNodeB 1
171  *
172  * x ----------------------- x ----------------------- x
173  * 500 m 500 m
174  */
175  // Create nodes.
176  NodeContainer enbNodes;
177  enbNodes.Create(2);
178  auto ueNode = CreateObject<Node>();
179 
180  // Setup mobility
181  auto posAlloc = CreateObject<ListPositionAllocator>();
182  posAlloc->Add(Vector(0, 0, 0));
183  posAlloc->Add(Vector(1000, 0, 0));
184  posAlloc->Add(Vector(500, 0, 0));
185 
186  MobilityHelper mobilityHelper;
187  mobilityHelper.SetMobilityModel("ns3::ConstantPositionMobilityModel");
188  mobilityHelper.SetPositionAllocator(posAlloc);
189  mobilityHelper.Install(enbNodes);
190  mobilityHelper.Install(ueNode);
191 
192  /*
193  * Link layer.
194  */
195  auto enbDevs = lteHelper->InstallEnbDevice(enbNodes);
196  auto ueDev = lteHelper->InstallUeDevice(ueNode).Get(0);
197 
198  /*
199  * Network layer.
200  */
201  InternetStackHelper inetStackHelper;
202  inetStackHelper.Install(ueNode);
204  ueIfs = epcHelper->AssignUeIpv4Address(ueDev);
205 
206  // Setup traces.
207  Config::Connect("/NodeList/*/DeviceList/*/LteUeRrc/HandoverStart",
209  Config::Connect("/NodeList/*/DeviceList/*/LteUeRrc/HandoverEndOk",
211 
212  Config::Connect("/NodeList/*/DeviceList/*/LteEnbRrc/HandoverStart",
214  Config::Connect("/NodeList/*/DeviceList/*/LteEnbRrc/HandoverEndOk",
216 
217  // Prepare handover.
218  lteHelper->AddX2Interface(enbNodes);
219  lteHelper->Attach(ueDev, enbDevs.Get(0));
220  lteHelper->HandoverRequest(m_handoverTime, ueDev, enbDevs.Get(0), enbDevs.Get(1));
221 
222  // Run simulation.
223  Simulator::Stop(m_simulationDuration);
224  Simulator::Run();
226 
227 } // end of void LteHandoverDelayTestCase::DoRun ()
228 
229 void
231  uint64_t imsi,
232  uint16_t cellid,
233  uint16_t rnti,
234  uint16_t targetCellId)
235 {
236  NS_LOG_FUNCTION(this << context);
237  m_ueHandoverStart = Simulator::Now();
238 }
239 
240 void
242  uint64_t imsi,
243  uint16_t cellid,
244  uint16_t rnti)
245 {
246  NS_LOG_FUNCTION(this << context);
247  NS_ASSERT(m_ueHandoverStart > Seconds(0));
248  Time delay = Simulator::Now() - m_ueHandoverStart;
249 
250  NS_LOG_DEBUG(this << " UE delay = " << delay.As(Time::S));
251  NS_TEST_ASSERT_MSG_LT(delay,
252  m_delayThreshold,
253  "UE handover delay is higher than the allowed threshold "
254  << "(ideal RRC = " << m_useIdealRrc
255  << " handover time = " << m_handoverTime.As(Time::S) << ")");
256 }
257 
258 void
260  uint64_t imsi,
261  uint16_t cellid,
262  uint16_t rnti,
263  uint16_t targetCellId)
264 {
265  NS_LOG_FUNCTION(this << context);
266  m_enbHandoverStart = Simulator::Now();
267 }
268 
269 void
271  uint64_t imsi,
272  uint16_t cellid,
273  uint16_t rnti)
274 {
275  NS_LOG_FUNCTION(this << context);
276  NS_ASSERT(m_enbHandoverStart > Seconds(0));
277  Time delay = Simulator::Now() - m_enbHandoverStart;
278 
279  NS_LOG_DEBUG(this << " eNodeB delay = " << delay.As(Time::S));
280  NS_TEST_ASSERT_MSG_LT(delay,
281  m_delayThreshold,
282  "eNodeB handover delay is higher than the allowed threshold "
283  << "(ideal RRC = " << m_useIdealRrc
284  << " handover time = " << m_handoverTime.As(Time::S) << ")");
285 }
286 
294 {
295  public:
297  : TestSuite("lte-handover-delay", TestSuite::SYSTEM)
298  {
299  // LogComponentEnable ("LteHandoverDelayTest", LOG_PREFIX_TIME);
300  // LogComponentEnable ("LteHandoverDelayTest", LOG_DEBUG);
301  // LogComponentEnable ("LteHandoverDelayTest", LOG_INFO);
302 
303  // HANDOVER DELAY TEST CASES WITH IDEAL RRC (THRESHOLD = 0.005 sec)
304 
305  for (Time handoverTime = Seconds(0.100); handoverTime < Seconds(0.110);
306  handoverTime += Seconds(0.001))
307  {
308  // arguments: useIdealRrc, handoverTime, delayThreshold, simulationDuration
309  AddTestCase(
310  new LteHandoverDelayTestCase(1, true, handoverTime, Seconds(0.005), Seconds(0.200)),
312  AddTestCase(
313  new LteHandoverDelayTestCase(2, true, handoverTime, Seconds(0.005), Seconds(0.200)),
315  AddTestCase(
316  new LteHandoverDelayTestCase(4, true, handoverTime, Seconds(0.005), Seconds(0.200)),
318  }
319 
320  // HANDOVER DELAY TEST CASES WITH REAL RRC (THRESHOLD = 0.020 sec)
321 
322  for (Time handoverTime = Seconds(0.100); handoverTime < Seconds(0.110);
323  handoverTime += Seconds(0.001))
324  {
325  // arguments: useIdealRrc, handoverTime, delayThreshold, simulationDuration
326  AddTestCase(new LteHandoverDelayTestCase(1,
327  false,
328  handoverTime,
329  Seconds(0.020),
330  Seconds(0.200)),
332  AddTestCase(new LteHandoverDelayTestCase(2,
333  false,
334  handoverTime,
335  Seconds(0.020),
336  Seconds(0.200)),
338  AddTestCase(new LteHandoverDelayTestCase(4,
339  false,
340  handoverTime,
341  Seconds(0.020),
342  Seconds(0.200)),
344  }
345  }
Verifying that the time needed for handover is under a specified threshold.
void EnbHandoverStartCallback(std::string context, uint64_t imsi, uint16_t cellid, uint16_t rnti, uint16_t targetCellId)
ENB handover start callback function.
Time m_simulationDuration
the simulation duration
void DoRun() override
Implementation to actually run this TestCase.
uint8_t m_numberOfComponentCarriers
Number of component carriers.
void UeHandoverEndOkCallback(std::string context, uint64_t imsi, uint16_t cellid, uint16_t rnti)
UE handover end OK callback function.
void UeHandoverStartCallback(std::string context, uint64_t imsi, uint16_t cellid, uint16_t rnti, uint16_t targetCellId)
UE handover start callback function.
Time m_delayThreshold
the delay threshold
void EnbHandoverEndOkCallback(std::string context, uint64_t imsi, uint16_t cellid, uint16_t rnti)
ENB handover end OK callback function.
Time m_ueHandoverStart
UE handover start time.
LteHandoverDelayTestCase(uint8_t numberOfComponentCarriers, bool useIdealRrc, Time handoverTime, Time delayThreshold, Time simulationDuration)
Constructor.
Time m_enbHandoverStart
ENB handover start time.
Lte Handover Delay Test Suite.
AttributeValue implementation for Boolean.
Definition: boolean.h:37
aggregate IP/TCP/UDP functionality to existing Nodes.
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Helper class used to assign positions and mobility models to nodes.
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
void SetMobilityModel(std::string type, Ts &&... args)
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:140
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:199
static void Run()
Run the simulation.
Definition: simulator.cc:176
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:184
encapsulates test code
Definition: test.h:1060
@ QUICK
Fast test.
Definition: test.h:1065
A suite of tests to run.
Definition: test.h:1256
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:417
@ S
second
Definition: nstime.h:116
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
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:975
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
LteHandoverDelayTestSuite g_lteHandoverDelayTestSuite
the test suite
#define NS_TEST_ASSERT_MSG_LT(actual, limit, msg)
Test that an actual value is less than a limit and report and abort if not.
Definition: test.h:709
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1336
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:707