A Discrete-Event Network Simulator
API
test-lte-handover-delay.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Magister Solutions
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  * Author: Budiarto Herman <budiarto.herman@magister.fi>
19  * Alexander Krotov <krotov@iitp.ru>
20  */
21 
22 #include <ns3/test.h>
23 
24 #include <ns3/log.h>
25 #include <ns3/nstime.h>
26 #include <ns3/callback.h>
27 #include <ns3/config.h>
28 #include <ns3/boolean.h>
29 #include <ns3/simulator.h>
30 
31 #include <ns3/node-container.h>
32 #include <ns3/net-device-container.h>
33 #include <ns3/ipv4-interface-container.h>
34 
35 #include <ns3/lte-helper.h>
36 #include <ns3/point-to-point-epc-helper.h>
37 #include <ns3/internet-stack-helper.h>
38 #include <ns3/point-to-point-helper.h>
39 #include <ns3/ipv4-address-helper.h>
40 #include <ns3/ipv4-static-routing-helper.h>
41 #include <ns3/mobility-helper.h>
42 
43 #include <ns3/data-rate.h>
44 #include <ns3/ipv4-static-routing.h>
45 #include <ns3/position-allocator.h>
46 
47 
48 using namespace ns3;
49 
50 NS_LOG_COMPONENT_DEFINE ("LteHandoverDelayTest");
51 
61 {
62 public:
72  LteHandoverDelayTestCase (uint8_t numberOfComponentCarriers, bool useIdealRrc, Time handoverTime,
73  Time delayThreshold, Time simulationDuration)
74  : TestCase ("Verifying that the time needed for handover is under a specified threshold"),
75  m_numberOfComponentCarriers (numberOfComponentCarriers),
76  m_useIdealRrc (useIdealRrc),
77  m_handoverTime (handoverTime),
78  m_delayThreshold (delayThreshold),
79  m_simulationDuration (simulationDuration),
80  m_ueHandoverStart (Seconds (0)),
81  m_enbHandoverStart (Seconds (0))
82  {}
83 
84 private:
85  virtual void DoRun (void);
86 
95  void UeHandoverStartCallback (std::string context, uint64_t imsi,
96  uint16_t cellid, uint16_t rnti, uint16_t targetCellId);
104  void UeHandoverEndOkCallback (std::string context, uint64_t imsi,
105  uint16_t cellid, uint16_t rnti);
114  void EnbHandoverStartCallback (std::string context, uint64_t imsi,
115  uint16_t cellid, uint16_t rnti, uint16_t targetCellId);
123  void EnbHandoverEndOkCallback (std::string context, uint64_t imsi,
124  uint16_t cellid, uint16_t rnti);
125 
131 
134 };
135 
136 
137 void
139 {
140  NS_LOG_INFO ("-----test case: ideal RRC = " << m_useIdealRrc << " handover time = "
141  << m_handoverTime.As (Time::S) << "-----");
142 
143  /*
144  * Helpers.
145  */
146  auto epcHelper = CreateObject<PointToPointEpcHelper> ();
147 
148  auto lteHelper = CreateObject<LteHelper> ();
149  lteHelper->SetEpcHelper (epcHelper);
150  lteHelper->SetAttribute ("UseIdealRrc", BooleanValue (m_useIdealRrc));
151  lteHelper->SetAttribute ("NumberOfComponentCarriers", UintegerValue (m_numberOfComponentCarriers));
152 
153  auto ccHelper = CreateObject<CcHelper> ();
154  ccHelper->SetUlEarfcn (100 + 18000);
155  ccHelper->SetDlEarfcn (100);
156  ccHelper->SetUlBandwidth (25);
157  ccHelper->SetDlBandwidth (25);
158  ccHelper->SetNumberOfComponentCarriers (m_numberOfComponentCarriers);
159 
160  /*
161  * Physical layer.
162  *
163  * eNodeB 0 UE eNodeB 1
164  *
165  * x ----------------------- x ----------------------- x
166  * 500 m 500 m
167  */
168  // Create nodes.
169  NodeContainer enbNodes;
170  enbNodes.Create (2);
171  auto ueNode = CreateObject<Node> ();
172 
173  // Setup mobility
174  auto posAlloc = CreateObject<ListPositionAllocator> ();
175  posAlloc->Add (Vector (0, 0, 0));
176  posAlloc->Add (Vector (1000, 0, 0));
177  posAlloc->Add (Vector (500, 0, 0));
178 
179  MobilityHelper mobilityHelper;
180  mobilityHelper.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
181  mobilityHelper.SetPositionAllocator (posAlloc);
182  mobilityHelper.Install (enbNodes);
183  mobilityHelper.Install (ueNode);
184 
185  /*
186  * Link layer.
187  */
188  auto enbDevs = lteHelper->InstallEnbDevice (enbNodes);
189  auto ueDev = lteHelper->InstallUeDevice (ueNode).Get (0);
190 
191  /*
192  * Network layer.
193  */
194  InternetStackHelper inetStackHelper;
195  inetStackHelper.Install (ueNode);
197  ueIfs = epcHelper->AssignUeIpv4Address (ueDev);
198 
199  // Setup traces.
200  Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/HandoverStart",
202  Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/HandoverEndOk",
204 
205  Config::Connect ("/NodeList/*/DeviceList/*/LteEnbRrc/HandoverStart",
207  Config::Connect ("/NodeList/*/DeviceList/*/LteEnbRrc/HandoverEndOk",
209 
210  // Prepare handover.
211  lteHelper->AddX2Interface (enbNodes);
212  lteHelper->Attach (ueDev, enbDevs.Get (0));
213  lteHelper->HandoverRequest (m_handoverTime, ueDev, enbDevs.Get (0), enbDevs.Get (1));
214 
215  // Run simulation.
216  Simulator::Stop (m_simulationDuration);
217  Simulator::Run ();
219 
220 } // end of void LteHandoverDelayTestCase::DoRun ()
221 
222 
223 void
225  uint64_t imsi, uint16_t cellid, uint16_t rnti, uint16_t targetCellId)
226 {
227  NS_LOG_FUNCTION (this << context);
228  m_ueHandoverStart = Simulator::Now ();
229 }
230 
231 void
233  uint64_t imsi, uint16_t cellid, uint16_t rnti)
234 {
235  NS_LOG_FUNCTION (this << context);
236  NS_ASSERT (m_ueHandoverStart > Seconds (0));
237  Time delay = Simulator::Now () - m_ueHandoverStart;
238 
239  NS_LOG_DEBUG (this << " UE delay = " << delay.As (Time::S));
240  NS_TEST_ASSERT_MSG_LT (delay, m_delayThreshold,
241  "UE handover delay is higher than the allowed threshold "
242  << "(ideal RRC = " << m_useIdealRrc
243  << " handover time = " << m_handoverTime.As (Time::S) << ")");
244 }
245 
246 
247 void
249  uint64_t imsi, uint16_t cellid, uint16_t rnti, uint16_t targetCellId)
250 {
251  NS_LOG_FUNCTION (this << context);
252  m_enbHandoverStart = Simulator::Now ();
253 }
254 
255 void
257  uint64_t imsi, uint16_t cellid, uint16_t rnti)
258 {
259  NS_LOG_FUNCTION (this << context);
260  NS_ASSERT (m_enbHandoverStart > Seconds (0));
261  Time delay = Simulator::Now () - m_enbHandoverStart;
262 
263  NS_LOG_DEBUG (this << " eNodeB delay = " << delay.As (Time::S));
264  NS_TEST_ASSERT_MSG_LT (delay, m_delayThreshold,
265  "eNodeB handover delay is higher than the allowed threshold "
266  << "(ideal RRC = " << m_useIdealRrc
267  << " handover time = " << m_handoverTime.As (Time::S) << ")");
268 }
269 
270 
271 
280 {
281 public:
283  : TestSuite ("lte-handover-delay", TestSuite::SYSTEM)
284  {
285  //LogComponentEnable ("LteHandoverDelayTest", LOG_PREFIX_TIME);
286  //LogComponentEnable ("LteHandoverDelayTest", LOG_DEBUG);
287  //LogComponentEnable ("LteHandoverDelayTest", LOG_INFO);
288 
289  // HANDOVER DELAY TEST CASES WITH IDEAL RRC (THRESHOLD = 0.005 sec)
290 
291  for (Time handoverTime = Seconds (0.100); handoverTime < Seconds (0.110);
292  handoverTime += Seconds (0.001))
293  {
294  // arguments: useIdealRrc, handoverTime, delayThreshold, simulationDuration
295  AddTestCase (
296  new LteHandoverDelayTestCase (1, true, handoverTime, Seconds (0.005),
297  Seconds (0.200)), TestCase::QUICK);
298  }
299 
300  // HANDOVER DELAY TEST CASES WITH REAL RRC (THRESHOLD = 0.020 sec)
301 
302  for (Time handoverTime = Seconds (0.100); handoverTime < Seconds (0.110);
303  handoverTime += Seconds (0.001))
304  {
305  // arguments: useIdealRrc, handoverTime, delayThreshold, simulationDuration
306  AddTestCase (
307  new LteHandoverDelayTestCase (1, false, handoverTime, Seconds (0.020),
308  Seconds (0.200)), TestCase::QUICK);
309  }
310  }
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
virtual void DoRun(void)
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 SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
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 Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:180
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
encapsulates test code
Definition: test.h:1154
@ QUICK
Fast test.
Definition: test.h:1159
A suite of tests to run.
Definition: test.h:1344
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
@ S
second
Definition: nstime.h:115
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:429
Hold an unsigned integer type.
Definition: uinteger.h:44
#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
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:920
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#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:281
#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:809
LteHandoverDelayTestSuite g_lteHandoverDelayTestSuite
the test suite
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1642