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  */
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 using namespace ns3;
48 
49 NS_LOG_COMPONENT_DEFINE("LteHandoverDelayTest");
50 
51 /*
52  * HANDOVER DELAY TEST CASE
53  */
54 
56 {
57 public:
58  LteHandoverDelayTestCase (bool useIdealRrc, Time handoverTime,
59  Time delayThreshold, Time simulationDuration)
60  : TestCase ("Verifying that the time needed for handover is under a specified threshold"),
61  m_useIdealRrc (useIdealRrc),
62  m_handoverTime (handoverTime),
63  m_delayThreshold (delayThreshold),
64  m_simulationDuration (simulationDuration),
65  m_ueHandoverStart (Seconds (0)),
66  m_enbHandoverStart (Seconds (0))
67  {
68  }
69 private:
70  virtual void DoRun (void);
71 
72  void UeHandoverStartCallback (std::string context, uint64_t imsi,
73  uint16_t cellid, uint16_t rnti, uint16_t targetCellId);
74  void UeHandoverEndOkCallback (std::string context, uint64_t imsi,
75  uint16_t cellid, uint16_t rnti);
76  void EnbHandoverStartCallback (std::string context, uint64_t imsi,
77  uint16_t cellid, uint16_t rnti, uint16_t targetCellId);
78  void EnbHandoverEndOkCallback (std::string context, uint64_t imsi,
79  uint16_t cellid, uint16_t rnti);
80 
85 
88 };
89 
90 
91 void
93 {
94  NS_LOG_INFO ("-----test case: ideal RRC = " << m_useIdealRrc
95  << " handover time = " << m_handoverTime.GetSeconds () << "-----");
96 
97  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
98  Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper> ();
99  lteHelper->SetEpcHelper (epcHelper);
100  lteHelper->SetAttribute ("UseIdealRrc", BooleanValue(m_useIdealRrc));
101 
102  // SETUP A REMOTE HOST
103 
104  NodeContainer remoteHosts;
105  remoteHosts.Create (1);
106  InternetStackHelper inetStackHelper;
107  inetStackHelper.Install (remoteHosts);
108 
109  // SETUP POINT-TO-POINT CONNECTION BETWEEN REMOTE HOST AND EPC
110 
111  PointToPointHelper p2pHelper;
112  p2pHelper.SetDeviceAttribute ("DataRate",
113  DataRateValue (DataRate ("100Gb/s")));
114  p2pHelper.SetDeviceAttribute ("Mtu", UintegerValue (1500));
115  p2pHelper.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010)));
116 
117  NetDeviceContainer inetDevs = p2pHelper.Install (epcHelper->GetPgwNode (),
118  remoteHosts.Get (0));
119 
120  Ipv4AddressHelper addrHelper;
121  addrHelper.SetBase ("10.1.1.0", "255.255.255.0");
122  Ipv4InterfaceContainer inetIfs;
123  inetIfs = addrHelper.Assign (inetDevs);
124 
125  // SETUP ROUTING
126 
127  Ipv4StaticRoutingHelper ipRoutingHelper;
128  Ptr<Ipv4StaticRouting> remoteHostRouting =
129  ipRoutingHelper.GetStaticRouting (remoteHosts.Get (0)->GetObject<Ipv4> ());
130  remoteHostRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"),
131  Ipv4Mask ("255.0.0.0"), 1);
132 
133  // CREATE NODES
134 
135  NodeContainer enbNodes;
136  NodeContainer ueNodes;
137  enbNodes.Create (2);
138  ueNodes.Create (1);
139 
147  // SETUP MOBILITY
148 
149  Ptr<ListPositionAllocator> posAlloc = CreateObject<ListPositionAllocator> ();
150  posAlloc->Add (Vector (0, 0, 0));
151  posAlloc->Add (Vector (1000, 0, 0));
152  posAlloc->Add (Vector (500, 0, 0));
153 
154  MobilityHelper mobilityHelper;
155  mobilityHelper.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
156  mobilityHelper.SetPositionAllocator (posAlloc);
157  mobilityHelper.Install (enbNodes);
158  mobilityHelper.Install (ueNodes);
159 
160  // SETUP LTE DEVICES
161 
162  NetDeviceContainer enbDevs;
163  NetDeviceContainer ueDevs;
164  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
165  ueDevs = lteHelper->InstallUeDevice (ueNodes);
166 
167  // SETUP INTERNET IN UE
168 
169  inetStackHelper.Install(ueNodes);
171  ueIfs = epcHelper->AssignUeIpv4Address (ueDevs);
172 
173  // SETUP DEFAULT GATEWAY FOR UE
174 
175  Ptr<Ipv4StaticRouting> ueStaticRouting =
176  ipRoutingHelper.GetStaticRouting (ueNodes.Get (0)->GetObject<Ipv4> ());
177  ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (),
178  1);
179 
180  // INSTALLING TRACES
181 
182  Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/HandoverStart",
184  Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/HandoverEndOk",
186 
187  Config::Connect ("/NodeList/*/DeviceList/*/LteEnbRrc/HandoverStart",
189  Config::Connect ("/NodeList/*/DeviceList/*/LteEnbRrc/HandoverEndOk",
191 
192  // SIMULATION
193 
194  lteHelper->AddX2Interface (enbNodes);
195  lteHelper->Attach (ueDevs.Get(0), enbDevs.Get(0));
196  lteHelper->HandoverRequest (m_handoverTime, ueDevs.Get (0), enbDevs.Get (0),
197  enbDevs.Get (1));
198  // disable error model in dl ctrl channel
199  //Config::Set ("/NodeList/*/DeviceList/*/LteUePhy/DlSpectrumPhy/CtrlErrorModelEnabled",
200  // BooleanValue (false));
201  Simulator::Stop (m_simulationDuration);
202  Simulator::Run ();
204 
205 } // end of void LteHandoverDelayTestCase::DoRun ()
206 
207 
208 void
210  uint64_t imsi, uint16_t cellid, uint16_t rnti, uint16_t targetCellId)
211 {
212  NS_LOG_FUNCTION (this << context);
213  m_ueHandoverStart = Simulator::Now ();
214 }
215 
216 void
218  uint64_t imsi, uint16_t cellid, uint16_t rnti)
219 {
220  NS_LOG_FUNCTION (this << context);
221  NS_ASSERT (m_ueHandoverStart > Seconds (0));
222  Time delay = Simulator::Now () - m_ueHandoverStart;
223  NS_LOG_DEBUG (this << " UE delay = " << delay.GetSeconds ());
224  NS_TEST_ASSERT_MSG_LT (delay.GetSeconds (), m_delayThreshold.GetSeconds (),
225  "UE handover delay is higher than the allowed threshold "
226  << "(ideal RRC = " << m_useIdealRrc
227  << " handover time = " << m_handoverTime.GetSeconds () << ")");
228 }
229 
230 
231 void
233  uint64_t imsi, uint16_t cellid, uint16_t rnti, uint16_t targetCellId)
234 {
235  NS_LOG_FUNCTION (this << context);
236  m_enbHandoverStart = Simulator::Now ();
237 }
238 
239 void
241  uint64_t imsi, uint16_t cellid, uint16_t rnti)
242 {
243  NS_LOG_FUNCTION (this << context);
244  NS_ASSERT (m_enbHandoverStart > Seconds (0));
245  Time delay = Simulator::Now () - m_enbHandoverStart;
246  NS_LOG_DEBUG (this << " eNodeB delay = " << delay.GetSeconds ());
247  NS_TEST_ASSERT_MSG_LT (delay.GetSeconds (), m_delayThreshold.GetSeconds (),
248  "eNodeB handover delay is higher than the allowed threshold "
249  << "(ideal RRC = " << m_useIdealRrc
250  << " handover time = " << m_handoverTime.GetSeconds () << ")");
251 }
252 
253 
254 
255 /*
256  * TEST SUITE
257  */
258 
260 {
261 public:
263  : TestSuite ("lte-handover-delay", TestSuite::SYSTEM)
264  {
265  //LogComponentEnable ("LteHandoverDelayTest", LOG_PREFIX_TIME);
266  //LogComponentEnable ("LteHandoverDelayTest", LOG_DEBUG);
267  //LogComponentEnable ("LteHandoverDelayTest", LOG_INFO);
268 
269  // HANDOVER DELAY TEST CASES WITH IDEAL RRC (THRESHOLD = 0.005 sec)
270 
271  for (Time handoverTime = Seconds (0.100); handoverTime < Seconds (0.110);
272  handoverTime += Seconds (0.001))
273  {
274  // arguments: useIdealRrc, handoverTime, delayThreshold, simulationDuration
275  AddTestCase (
276  new LteHandoverDelayTestCase (true, handoverTime, Seconds (0.005),
277  Seconds (0.200)), TestCase::QUICK);
278  }
279 
280  // HANDOVER DELAY TEST CASES WITH REAL RRC (THRESHOLD = 0.020 sec)
281 
282  for (Time handoverTime = Seconds (0.100); handoverTime < Seconds (0.110);
283  handoverTime += Seconds (0.001))
284  {
285  // arguments: useIdealRrc, handoverTime, delayThreshold, simulationDuration
286  AddTestCase (
287  new LteHandoverDelayTestCase (false, handoverTime, Seconds (0.020),
288  Seconds (0.200)), TestCase::QUICK);
289  }
290  }
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:34
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< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:462
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:257
Fast test.
Definition: test.h:1152
A suite of tests to run.
Definition: test.h:1333
#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:201
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
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:244
Build a set of PointToPointNetDevice objects.
encapsulates test code
Definition: test.h:1147
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
void EnbHandoverEndOkCallback(std::string context, uint64_t imsi, uint16_t cellid, uint16_t rnti)
Class for representing data rates.
Definition: data-rate.h:88
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
AttributeValue implementation for Time.
Definition: nstime.h:957
Hold an unsigned integer type.
Definition: uinteger.h:44
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:1489
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:835
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:165
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:76
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:224
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.
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:40
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.
AttributeValue implementation for DataRate.
Definition: data-rate.h:242
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:209
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:236
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
void Add(Vector v)
Add a position to the list of positions.
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)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:191
#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:804
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.