A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  */
20 
21 #include <ns3/test.h>
22 
23 #include <ns3/log.h>
24 #include <ns3/nstime.h>
25 #include <ns3/callback.h>
26 #include <ns3/config.h>
27 #include <ns3/boolean.h>
28 #include <ns3/simulator.h>
29 
30 #include <ns3/node-container.h>
31 #include <ns3/net-device-container.h>
32 #include <ns3/ipv4-interface-container.h>
33 
34 #include <ns3/lte-helper.h>
35 #include <ns3/point-to-point-epc-helper.h>
36 #include <ns3/internet-stack-helper.h>
37 #include <ns3/point-to-point-helper.h>
38 #include <ns3/ipv4-address-helper.h>
39 #include <ns3/ipv4-static-routing-helper.h>
40 #include <ns3/mobility-helper.h>
41 
42 #include <ns3/data-rate.h>
43 #include <ns3/ipv4-static-routing.h>
44 #include <ns3/position-allocator.h>
45 
46 
47 NS_LOG_COMPONENT_DEFINE("LteHandoverDelayTest");
48 
49 using namespace ns3;
50 
51 
52 /*
53  * HANDOVER DELAY TEST CASE
54  */
55 
57 {
58 public:
59  LteHandoverDelayTestCase (bool useIdealRrc, Time handoverTime,
60  Time delayThreshold, Time simulationDuration)
61  : TestCase ("Verifying that the time needed for handover is under a specified threshold"),
62  m_useIdealRrc (useIdealRrc),
63  m_handoverTime (handoverTime),
64  m_delayThreshold (delayThreshold),
65  m_simulationDuration (simulationDuration),
66  m_ueHandoverStart (Seconds (0)),
67  m_enbHandoverStart (Seconds (0))
68  {
69  }
70 private:
71  virtual void DoRun (void);
72 
73  void UeHandoverStartCallback (std::string context, uint64_t imsi,
74  uint16_t cellid, uint16_t rnti, uint16_t targetCellId);
75  void UeHandoverEndOkCallback (std::string context, uint64_t imsi,
76  uint16_t cellid, uint16_t rnti);
77  void EnbHandoverStartCallback (std::string context, uint64_t imsi,
78  uint16_t cellid, uint16_t rnti, uint16_t targetCellId);
79  void EnbHandoverEndOkCallback (std::string context, uint64_t imsi,
80  uint16_t cellid, uint16_t rnti);
81 
86 
89 };
90 
91 
92 void
94 {
95  NS_LOG_INFO ("-----test case: ideal RRC = " << m_useIdealRrc
96  << " handover time = " << m_handoverTime.GetSeconds () << "-----");
97 
98  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
99  Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper> ();
100  lteHelper->SetEpcHelper (epcHelper);
101  lteHelper->SetAttribute ("UseIdealRrc", BooleanValue(m_useIdealRrc));
102 
103  // SETUP A REMOTE HOST
104 
105  NodeContainer remoteHosts;
106  remoteHosts.Create (1);
107  InternetStackHelper inetStackHelper;
108  inetStackHelper.Install (remoteHosts);
109 
110  // SETUP POINT-TO-POINT CONNECTION BETWEEN REMOTE HOST AND EPC
111 
112  PointToPointHelper p2pHelper;
113  p2pHelper.SetDeviceAttribute ("DataRate",
114  DataRateValue (DataRate ("100Gb/s")));
115  p2pHelper.SetDeviceAttribute ("Mtu", UintegerValue (1500));
116  p2pHelper.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010)));
117 
118  NetDeviceContainer inetDevs = p2pHelper.Install (epcHelper->GetPgwNode (),
119  remoteHosts.Get (0));
120 
121  Ipv4AddressHelper addrHelper;
122  addrHelper.SetBase ("10.1.1.0", "255.255.255.0");
123  Ipv4InterfaceContainer inetIfs;
124  inetIfs = addrHelper.Assign (inetDevs);
125 
126  // SETUP ROUTING
127 
128  Ipv4StaticRoutingHelper ipRoutingHelper;
129  Ptr<Ipv4StaticRouting> remoteHostRouting =
130  ipRoutingHelper.GetStaticRouting (remoteHosts.Get (0)->GetObject<Ipv4> ());
131  remoteHostRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"),
132  Ipv4Mask ("255.0.0.0"), 1);
133 
134  // CREATE NODES
135 
136  NodeContainer enbNodes;
137  NodeContainer ueNodes;
138  enbNodes.Create (2);
139  ueNodes.Create (1);
140 
148  // SETUP MOBILITY
149 
150  Ptr<ListPositionAllocator> posAlloc = CreateObject<ListPositionAllocator> ();
151  posAlloc->Add (Vector (0, 0, 0));
152  posAlloc->Add (Vector (1000, 0, 0));
153  posAlloc->Add (Vector (500, 0, 0));
154 
155  MobilityHelper mobilityHelper;
156  mobilityHelper.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
157  mobilityHelper.SetPositionAllocator (posAlloc);
158  mobilityHelper.Install (enbNodes);
159  mobilityHelper.Install (ueNodes);
160 
161  // SETUP LTE DEVICES
162 
163  NetDeviceContainer enbDevs;
164  NetDeviceContainer ueDevs;
165  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
166  ueDevs = lteHelper->InstallUeDevice (ueNodes);
167 
168  // SETUP INTERNET IN UE
169 
170  inetStackHelper.Install(ueNodes);
172  ueIfs = epcHelper->AssignUeIpv4Address (ueDevs);
173 
174  // SETUP DEFAULT GATEWAY FOR UE
175 
176  Ptr<Ipv4StaticRouting> ueStaticRouting =
177  ipRoutingHelper.GetStaticRouting (ueNodes.Get (0)->GetObject<Ipv4> ());
178  ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (),
179  1);
180 
181  // INSTALLING TRACES
182 
183  Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/HandoverStart",
185  Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/HandoverEndOk",
187 
188  Config::Connect ("/NodeList/*/DeviceList/*/LteEnbRrc/HandoverStart",
190  Config::Connect ("/NodeList/*/DeviceList/*/LteEnbRrc/HandoverEndOk",
192 
193  // SIMULATION
194 
195  lteHelper->AddX2Interface (enbNodes);
196  lteHelper->Attach (ueDevs.Get(0), enbDevs.Get(0));
197  lteHelper->HandoverRequest (m_handoverTime, ueDevs.Get (0), enbDevs.Get (0),
198  enbDevs.Get (1));
199  // disable error model in dl ctrl channel
200  //Config::Set ("/NodeList/*/DeviceList/*/LteUePhy/DlSpectrumPhy/CtrlErrorModelEnabled",
201  // BooleanValue (false));
202  Simulator::Stop (m_simulationDuration);
203  Simulator::Run ();
205 
206 } // end of void LteHandoverDelayTestCase::DoRun ()
207 
208 
209 void
211  uint64_t imsi, uint16_t cellid, uint16_t rnti, uint16_t targetCellId)
212 {
213  NS_LOG_FUNCTION (this << context);
214  m_ueHandoverStart = Simulator::Now ();
215 }
216 
217 void
219  uint64_t imsi, uint16_t cellid, uint16_t rnti)
220 {
221  NS_LOG_FUNCTION (this << context);
222  NS_ASSERT (m_ueHandoverStart > Seconds (0));
223  Time delay = Simulator::Now () - m_ueHandoverStart;
224  NS_LOG_DEBUG (this << " UE delay = " << delay.GetSeconds ());
225  NS_TEST_ASSERT_MSG_LT (delay.GetSeconds (), m_delayThreshold.GetSeconds (),
226  "UE handover delay is higher than the allowed threshold "
227  << "(ideal RRC = " << m_useIdealRrc
228  << " handover time = " << m_handoverTime.GetSeconds () << ")");
229 }
230 
231 
232 void
234  uint64_t imsi, uint16_t cellid, uint16_t rnti, uint16_t targetCellId)
235 {
236  NS_LOG_FUNCTION (this << context);
237  m_enbHandoverStart = Simulator::Now ();
238 }
239 
240 void
242  uint64_t imsi, uint16_t cellid, uint16_t rnti)
243 {
244  NS_LOG_FUNCTION (this << context);
245  NS_ASSERT (m_enbHandoverStart > Seconds (0));
246  Time delay = Simulator::Now () - m_enbHandoverStart;
247  NS_LOG_DEBUG (this << " eNodeB delay = " << delay.GetSeconds ());
248  NS_TEST_ASSERT_MSG_LT (delay.GetSeconds (), m_delayThreshold.GetSeconds (),
249  "eNodeB handover delay is higher than the allowed threshold "
250  << "(ideal RRC = " << m_useIdealRrc
251  << " handover time = " << m_handoverTime.GetSeconds () << ")");
252 }
253 
254 
255 
256 /*
257  * TEST SUITE
258  */
259 
261 {
262 public:
264  : TestSuite ("lte-handover-delay", TestSuite::SYSTEM)
265  {
266  //LogComponentEnable ("LteHandoverDelayTest", LOG_PREFIX_TIME);
267  //LogComponentEnable ("LteHandoverDelayTest", LOG_DEBUG);
268  //LogComponentEnable ("LteHandoverDelayTest", LOG_INFO);
269 
270  // HANDOVER DELAY TEST CASES WITH IDEAL RRC (THRESHOLD = 0.005 sec)
271 
272  for (Time handoverTime = Seconds (0.100); handoverTime < Seconds (0.110);
273  handoverTime += Seconds (0.001))
274  {
275  // arguments: useIdealRrc, handoverTime, delayThreshold, simulationDuration
276  AddTestCase (
277  new LteHandoverDelayTestCase (true, handoverTime, Seconds (0.005),
278  Seconds (0.200)), TestCase::QUICK);
279  }
280 
281  // HANDOVER DELAY TEST CASES WITH REAL RRC (THRESHOLD = 0.020 sec)
282 
283  for (Time handoverTime = Seconds (0.100); handoverTime < Seconds (0.110);
284  handoverTime += Seconds (0.001))
285  {
286  // arguments: useIdealRrc, handoverTime, delayThreshold, simulationDuration
287  AddTestCase (
288  new LteHandoverDelayTestCase (false, handoverTime, Seconds (0.020),
289  Seconds (0.200)), TestCase::QUICK);
290  }
291  }
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Hold a bool native type.
Definition: boolean.h:38
holds a vector of std::pair of Ptr and interface index.
void SetDefaultRoute(Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a default route to the static routing table.
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
NetDeviceContainer Install(NodeContainer c)
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:222
A suite of tests to run.
Definition: test.h:1105
#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
static void Run(void)
Run the simulation until one of:
Definition: simulator.cc:157
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
void EnbHandoverStartCallback(std::string context, uint64_t imsi, uint16_t cellid, uint16_t rnti, uint16_t targetCellId)
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:223
Build a set of PointToPointNetDevice objects.
encapsulates test code
Definition: test.h:929
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:728
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
a 3d vector
Definition: vector.h:31
void EnbHandoverEndOkCallback(std::string context, uint64_t imsi, uint16_t cellid, uint16_t rnti)
Class for representing data rates.
Definition: data-rate.h:71
double GetSeconds(void) const
Definition: nstime.h:272
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
hold objects of type ns3::Time
Definition: nstime.h:1008
Hold an unsigned integer type.
Definition: uinteger.h:46
virtual void DoRun(void)
Implementation to actually run this TestCase.
holds a vector of ns3::NetDevice pointers
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1242
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
Access to the Ipv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:76
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 time".
Definition: simulator.cc:180
LteHandoverDelayTestSuite g_lteHandoverDelayTestSuite
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
Fast test.
Definition: test.h:937
Helper class used to assign positions and mobility models to nodes.
void AddNetworkRouteTo(Ipv4Address network, Ipv4Mask networkMask, Ipv4Address nextHop, uint32_t interface, uint32_t metric=0)
Add a network route to the static routing table.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
LteHandoverDelayTestCase(bool useIdealRrc, Time handoverTime, Time delayThreshold, Time simulationDuration)
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Ptr< Ipv4StaticRouting > GetStaticRouting(Ptr< Ipv4 > ipv4) const
Try and find the static routing protocol as either the main routing protocol or in the list of routin...
Helper class that adds ns3::Ipv4StaticRouting objects.
hold objects of type ns3::DataRate
static void Stop(void)
If an event invokes this method, it will be the last event scheduled by the Simulator::run method bef...
Definition: simulator.cc:165
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:213
void UeHandoverStartCallback(std::string context, uint64_t imsi, uint16_t cellid, uint16_t rnti, uint16_t targetCellId)
void UeHandoverEndOkCallback(std::string context, uint64_t imsi, uint16_t cellid, uint16_t rnti)
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
void SetAttribute(std::string name, const AttributeValue &value)
Definition: object-base.cc:176
Ptr< T > GetObject(void) const
Definition: object.h:362
#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:753
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.