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:
71  LteHandoverDelayTestCase (uint8_t numberOfComponentCarriers, bool useIdealRrc, Time handoverTime,
72  Time delayThreshold, Time simulationDuration)
73  : TestCase ("Verifying that the time needed for handover is under a specified threshold"),
74  m_numberOfComponentCarriers (numberOfComponentCarriers),
75  m_useIdealRrc (useIdealRrc),
76  m_handoverTime (handoverTime),
77  m_delayThreshold (delayThreshold),
78  m_simulationDuration (simulationDuration),
79  m_ueHandoverStart (Seconds (0)),
80  m_enbHandoverStart (Seconds (0))
81  {
82  }
83 private:
84  virtual void DoRun (void);
85 
94  void UeHandoverStartCallback (std::string context, uint64_t imsi,
95  uint16_t cellid, uint16_t rnti, uint16_t targetCellId);
103  void UeHandoverEndOkCallback (std::string context, uint64_t imsi,
104  uint16_t cellid, uint16_t rnti);
113  void EnbHandoverStartCallback (std::string context, uint64_t imsi,
114  uint16_t cellid, uint16_t rnti, uint16_t targetCellId);
122  void EnbHandoverEndOkCallback (std::string context, uint64_t imsi,
123  uint16_t cellid, uint16_t rnti);
124 
130 
133 };
134 
135 
136 void
138 {
139  NS_LOG_INFO ("-----test case: ideal RRC = " << m_useIdealRrc
140  << " handover time = " << m_handoverTime.GetSeconds () << "-----");
141 
142  /*
143  * Helpers.
144  */
145  auto epcHelper = CreateObject<PointToPointEpcHelper> ();
146 
147  auto lteHelper = CreateObject<LteHelper> ();
148  lteHelper->SetEpcHelper (epcHelper);
149  lteHelper->SetAttribute ("UseIdealRrc", BooleanValue (m_useIdealRrc));
150  lteHelper->SetAttribute ("NumberOfComponentCarriers", UintegerValue (m_numberOfComponentCarriers));
151 
152  auto ccHelper = CreateObject<CcHelper> ();
153  ccHelper->SetUlEarfcn (100 + 18000);
154  ccHelper->SetDlEarfcn (100);
155  ccHelper->SetUlBandwidth (25);
156  ccHelper->SetDlBandwidth (25);
157  ccHelper->SetNumberOfComponentCarriers (m_numberOfComponentCarriers);
158 
159  /*
160  * Physical layer.
161  *
162  * eNodeB 0 UE eNodeB 1
163  *
164  * x ----------------------- x ----------------------- x
165  * 500 m 500 m
166  */
167  // Create nodes.
168  NodeContainer enbNodes;
169  enbNodes.Create (2);
170  auto ueNode = CreateObject<Node> ();
171 
172  // Setup mobility
173  auto posAlloc = CreateObject<ListPositionAllocator> ();
174  posAlloc->Add (Vector (0, 0, 0));
175  posAlloc->Add (Vector (1000, 0, 0));
176  posAlloc->Add (Vector (500, 0, 0));
177 
178  MobilityHelper mobilityHelper;
179  mobilityHelper.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
180  mobilityHelper.SetPositionAllocator (posAlloc);
181  mobilityHelper.Install (enbNodes);
182  mobilityHelper.Install (ueNode);
183 
184  /*
185  * Link layer.
186  */
187  auto enbDevs = lteHelper->InstallEnbDevice (enbNodes);
188  auto ueDev = lteHelper->InstallUeDevice (ueNode).Get (0);
189 
190  /*
191  * Network layer.
192  */
193  InternetStackHelper inetStackHelper;
194  inetStackHelper.Install (ueNode);
196  ueIfs = epcHelper->AssignUeIpv4Address (ueDev);
197 
198  // Setup traces.
199  Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/HandoverStart",
201  Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/HandoverEndOk",
203 
204  Config::Connect ("/NodeList/*/DeviceList/*/LteEnbRrc/HandoverStart",
206  Config::Connect ("/NodeList/*/DeviceList/*/LteEnbRrc/HandoverEndOk",
208 
209  // Prepare handover.
210  lteHelper->AddX2Interface (enbNodes);
211  lteHelper->Attach (ueDev, enbDevs.Get(0));
212  lteHelper->HandoverRequest (m_handoverTime, ueDev, enbDevs.Get (0), enbDevs.Get (1));
213 
214  // Run simulation.
215  Simulator::Stop (m_simulationDuration);
216  Simulator::Run ();
218 
219 } // end of void LteHandoverDelayTestCase::DoRun ()
220 
221 
222 void
224  uint64_t imsi, uint16_t cellid, uint16_t rnti, uint16_t targetCellId)
225 {
226  NS_LOG_FUNCTION (this << context);
227  m_ueHandoverStart = Simulator::Now ();
228 }
229 
230 void
232  uint64_t imsi, uint16_t cellid, uint16_t rnti)
233 {
234  NS_LOG_FUNCTION (this << context);
235  NS_ASSERT (m_ueHandoverStart > Seconds (0));
236  Time delay = Simulator::Now () - m_ueHandoverStart;
237  NS_LOG_DEBUG (this << " UE delay = " << delay.GetSeconds ());
238  NS_TEST_ASSERT_MSG_LT (delay.GetSeconds (), m_delayThreshold.GetSeconds (),
239  "UE handover delay is higher than the allowed threshold "
240  << "(ideal RRC = " << m_useIdealRrc
241  << " handover time = " << m_handoverTime.GetSeconds () << ")");
242 }
243 
244 
245 void
247  uint64_t imsi, uint16_t cellid, uint16_t rnti, uint16_t targetCellId)
248 {
249  NS_LOG_FUNCTION (this << context);
250  m_enbHandoverStart = Simulator::Now ();
251 }
252 
253 void
255  uint64_t imsi, uint16_t cellid, uint16_t rnti)
256 {
257  NS_LOG_FUNCTION (this << context);
258  NS_ASSERT (m_enbHandoverStart > Seconds (0));
259  Time delay = Simulator::Now () - m_enbHandoverStart;
260  NS_LOG_DEBUG (this << " eNodeB delay = " << delay.GetSeconds ());
261  NS_TEST_ASSERT_MSG_LT (delay.GetSeconds (), m_delayThreshold.GetSeconds (),
262  "eNodeB handover delay is higher than the allowed threshold "
263  << "(ideal RRC = " << m_useIdealRrc
264  << " handover time = " << m_handoverTime.GetSeconds () << ")");
265 }
266 
267 
268 
277 {
278 public:
280  : TestSuite ("lte-handover-delay", TestSuite::SYSTEM)
281  {
282  //LogComponentEnable ("LteHandoverDelayTest", LOG_PREFIX_TIME);
283  //LogComponentEnable ("LteHandoverDelayTest", LOG_DEBUG);
284  //LogComponentEnable ("LteHandoverDelayTest", LOG_INFO);
285 
286  // HANDOVER DELAY TEST CASES WITH IDEAL RRC (THRESHOLD = 0.005 sec)
287 
288  for (Time handoverTime = Seconds (0.100); handoverTime < Seconds (0.110);
289  handoverTime += Seconds (0.001))
290  {
291  // arguments: useIdealRrc, handoverTime, delayThreshold, simulationDuration
292  AddTestCase (
293  new LteHandoverDelayTestCase (1, true, handoverTime, Seconds (0.005),
294  Seconds (0.200)), TestCase::QUICK);
295  }
296 
297  // HANDOVER DELAY TEST CASES WITH REAL RRC (THRESHOLD = 0.020 sec)
298 
299  for (Time handoverTime = Seconds (0.100); handoverTime < Seconds (0.110);
300  handoverTime += Seconds (0.001))
301  {
302  // arguments: useIdealRrc, handoverTime, delayThreshold, simulationDuration
303  AddTestCase (
304  new LteHandoverDelayTestCase (1, false, handoverTime, Seconds (0.020),
305  Seconds (0.200)), TestCase::QUICK);
306  }
307  }
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
AttributeValue implementation for Boolean.
Definition: boolean.h:36
holds a vector of std::pair of Ptr<Ipv4> and interface index.
Lte Handover Delay Test Suite.
A suite of tests to run.
Definition: test.h:1342
#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
static void Run(void)
Run the simulation.
Definition: simulator.cc:226
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
void EnbHandoverStartCallback(std::string context, uint64_t imsi, uint16_t cellid, uint16_t rnti, uint16_t targetCellId)
ENB handover start callback function.
aggregate IP/TCP/UDP functionality to existing Nodes.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:278
encapsulates test code
Definition: test.h:1155
void EnbHandoverEndOkCallback(std::string context, uint64_t imsi, uint16_t cellid, uint16_t rnti)
ENB handover end OK callback function.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
LteHandoverDelayTestSuite g_lteHandoverDelayTestSuite
the test suite
Hold an unsigned integer type.
Definition: uinteger.h:44
virtual void DoRun(void)
Implementation to actually run this TestCase.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
Time m_enbHandoverStart
ENB handover start time.
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:843
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:190
Verifying that the time needed for handover is under a specified threshold.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
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(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:249
Time m_delayThreshold
the delay threshold
Fast test.
Definition: test.h:1160
Helper class used to assign positions and mobility models to nodes.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:234
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:270
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1007
Time m_ueHandoverStart
UE handover start time.
void UeHandoverStartCallback(std::string context, uint64_t imsi, uint16_t cellid, uint16_t rnti, uint16_t targetCellId)
UE handover start callback function.
void UeHandoverEndOkCallback(std::string context, uint64_t imsi, uint16_t cellid, uint16_t rnti)
UE handover end OK callback function.
Time m_simulationDuration
the simulation duration
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
LteHandoverDelayTestCase(uint8_t numberOfComponentCarriers, bool useIdealRrc, Time handoverTime, Time delayThreshold, Time simulationDuration)
Constructor.
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
#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:811