A Discrete-Event Network Simulator
API
test-lte-handover-target.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Budiarto Herman
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 
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/double.h>
30 #include <ns3/uinteger.h>
31 #include <ns3/simulator.h>
32 
33 #include <ns3/node-container.h>
34 #include <ns3/net-device-container.h>
35 #include <ns3/ipv4-interface-container.h>
36 
37 #include <ns3/lte-helper.h>
38 #include <ns3/point-to-point-epc-helper.h>
39 #include <ns3/internet-stack-helper.h>
40 #include <ns3/point-to-point-helper.h>
41 #include <ns3/ipv4-address-helper.h>
42 #include <ns3/ipv4-static-routing-helper.h>
43 #include <ns3/mobility-helper.h>
44 
45 #include <ns3/data-rate.h>
46 #include <ns3/ipv4-static-routing.h>
47 #include <ns3/position-allocator.h>
48 #include <ns3/lte-enb-net-device.h>
49 #include <ns3/lte-enb-phy.h>
50 
51 using namespace ns3;
52 
53 NS_LOG_COMPONENT_DEFINE ("LteHandoverTargetTest");
54 
67 {
68 public:
87  LteHandoverTargetTestCase (std::string name, Vector uePosition,
88  uint8_t gridSizeX, uint8_t gridSizeY,
89  uint16_t sourceCellId, uint16_t targetCellId,
90  std::string handoverAlgorithmType);
91 
92  virtual ~LteHandoverTargetTestCase ();
93 
101  void HandoverStartCallback (std::string context, uint64_t imsi,
102  uint16_t sourceCellId, uint16_t rnti,
103  uint16_t targetCellId);
104 
109  void CellShutdownCallback ();
110 
111 private:
116  virtual void DoRun ();
117 
122  virtual void DoTeardown ();
123 
124  // simulation parameters
125  Vector m_uePosition;
126  uint8_t m_gridSizeX;
127  uint8_t m_gridSizeY;
128  uint16_t m_sourceCellId;
129  uint16_t m_targetCellId;
131 
134 
135 }; // end of class LteHandoverTargetTestCase
136 
137 
138 LteHandoverTargetTestCase::LteHandoverTargetTestCase (std::string name, Vector uePosition,
139  uint8_t gridSizeX, uint8_t gridSizeY,
140  uint16_t sourceCellId, uint16_t targetCellId,
141  std::string handoverAlgorithmType)
142  : TestCase (name),
143  m_uePosition (uePosition),
144  m_gridSizeX (gridSizeX),
145  m_gridSizeY (gridSizeY),
146  m_sourceCellId (sourceCellId),
147  m_targetCellId (targetCellId),
148  m_handoverAlgorithmType (handoverAlgorithmType),
149  m_sourceEnbDev (0),
150  m_hasHandoverOccurred (false)
151 {
152  NS_LOG_INFO (this << " name=" << name);
153 
154  // SANITY CHECK
155 
156  uint16_t nEnb = gridSizeX * gridSizeY;
157 
158  if (sourceCellId > nEnb)
159  {
160  NS_FATAL_ERROR ("Invalid source cell ID " << sourceCellId);
161  }
162 
163  if (targetCellId > nEnb)
164  {
165  NS_FATAL_ERROR ("Invalid target cell ID " << targetCellId);
166  }
167 }
168 
169 
171 {
172  NS_LOG_FUNCTION (this);
173 }
174 
175 
176 void
177 LteHandoverTargetTestCase::HandoverStartCallback (std::string context, uint64_t imsi,
178  uint16_t sourceCellId, uint16_t rnti,
179  uint16_t targetCellId)
180 {
181  NS_LOG_FUNCTION (this << context << imsi << sourceCellId << rnti << targetCellId);
182 
183  uint64_t timeNowMs = Simulator::Now ().GetMilliSeconds ();
184  NS_TEST_ASSERT_MSG_GT (timeNowMs, 500,
185  "Handover occured but too early");
186  NS_TEST_ASSERT_MSG_EQ (sourceCellId, m_sourceCellId,
187  "Handover occured but with wrong source cell");
188  NS_TEST_ASSERT_MSG_EQ (targetCellId, m_targetCellId,
189  "Handover occured but with wrong target cell");
190  m_hasHandoverOccurred = true;
191 }
192 
193 
194 void
196 {
197  NS_LOG_FUNCTION (this);
198 
199  if (m_sourceEnbDev != 0)
200  {
201  // set the Tx power to 1 dBm
203  NS_LOG_INFO ("Shutting down cell " << m_sourceCellId);
205  phy->SetTxPower (1);
206  }
207 }
208 
209 
210 void
212 {
213  NS_LOG_INFO (this << " " << GetName ());
214 
215  Config::SetDefault ("ns3::LteEnbPhy::TxPower", DoubleValue (38)); // micro cell
216  Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled",
217  BooleanValue (false)); // disable control channel error model
218 
219  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
220  Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper> ();
221  lteHelper->SetEpcHelper (epcHelper);
222  lteHelper->SetAttribute ("PathlossModel",
223  StringValue ("ns3::FriisSpectrumPropagationLossModel"));
224  lteHelper->SetAttribute ("UseIdealRrc", BooleanValue (true));
225 
226  if (m_handoverAlgorithmType == "ns3::A2A4RsrqHandoverAlgorithm")
227  {
228  lteHelper->SetHandoverAlgorithmType ("ns3::A2A4RsrqHandoverAlgorithm");
229  lteHelper->SetHandoverAlgorithmAttribute ("ServingCellThreshold",
230  UintegerValue (30));
231  lteHelper->SetHandoverAlgorithmAttribute ("NeighbourCellOffset",
232  UintegerValue (1));
233  }
234  else if (m_handoverAlgorithmType == "ns3::A3RsrpHandoverAlgorithm")
235  {
236  lteHelper->SetHandoverAlgorithmType ("ns3::A3RsrpHandoverAlgorithm");
237  lteHelper->SetHandoverAlgorithmAttribute ("Hysteresis",
238  DoubleValue (1.5));
239  lteHelper->SetHandoverAlgorithmAttribute ("TimeToTrigger",
240  TimeValue (MilliSeconds (128)));
241  }
242  else
243  {
244  NS_FATAL_ERROR ("Unknown handover algorithm " << m_handoverAlgorithmType);
245  }
246 
247  // Create Nodes: eNodeB and UE
248  NodeContainer enbNodes;
249  NodeContainer ueNodes;
250  enbNodes.Create (m_gridSizeX * m_gridSizeY);
251  ueNodes.Create (1);
252 
253  /*
254  * The size of the grid is determined by m_gridSizeX and m_gridSizeY. The
255  * following figure is the topology when m_gridSizeX = 4 and m_gridSizeY = 3.
256  *
257  * 9 -- 10 -- 11 -- 12
258  * | | | |
259  * | | | |
260  * 5 --- 6 --- 7 --- 8
261  * | | | |
262  * | | | |
263  * (0, 0, 0) ---> 1 --- 2 --- 3 --- 4
264  *
265  * The grid starts at (0, 0, 0) point on the bottom left corner. The distance
266  * between two adjacent eNodeBs is 130 m.
267  */
268 
269  // Set up eNodeB position
270  MobilityHelper enbMobility;
271  enbMobility.SetPositionAllocator ("ns3::GridPositionAllocator",
272  "MinX", DoubleValue (0.0),
273  "MinY", DoubleValue (0.0),
274  "DeltaX", DoubleValue (130.0),
275  "DeltaY", DoubleValue (130.0),
276  "GridWidth", UintegerValue (m_gridSizeX),
277  "LayoutType", StringValue ("RowFirst"));
278  enbMobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
279  enbMobility.Install (enbNodes);
280 
281  // Setup UE position
282  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
283  positionAlloc->Add (m_uePosition);
284  MobilityHelper ueMobility;
285  ueMobility.SetPositionAllocator (positionAlloc);
286  ueMobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
287  ueMobility.Install (ueNodes);
288 
289  // Create P-GW node
290  Ptr<Node> pgw = epcHelper->GetPgwNode ();
291 
292  // Create a single RemoteHost
293  NodeContainer remoteHostContainer;
294  remoteHostContainer.Create (1);
295  Ptr<Node> remoteHost = remoteHostContainer.Get (0);
296  InternetStackHelper internet;
297  internet.Install (remoteHostContainer);
298 
299  // Create the Internet
300  PointToPointHelper p2ph;
301  p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
302  p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500));
303  p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010)));
304  NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
305  Ipv4AddressHelper ipv4h;
306  ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
307  Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices);
308 
309  // Routing of the Internet Host (towards the LTE network)
310  Ipv4StaticRoutingHelper ipv4RoutingHelper;
311  Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
312  remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1);
313 
314  // Create Devices and install them in the Nodes (eNB and UE)
315  NetDeviceContainer enbDevs;
316  NetDeviceContainer ueDevs;
317  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
318  ueDevs = lteHelper->InstallUeDevice (ueNodes);
319 
320  // Install the IP stack on the UEs
321  internet.Install (ueNodes);
322  Ipv4InterfaceContainer ueIpIfaces;
323  ueIpIfaces = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueDevs));
324 
325  // Assign IP address to UEs
326  for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
327  {
328  Ptr<Node> ueNode = ueNodes.Get (u);
329  // Set the default gateway for the UE
330  Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv4> ());
331  ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1);
332  }
333 
334  // Add X2 interface
335  lteHelper->AddX2Interface (enbNodes);
336 
337  // Connect to trace sources in all eNodeB
338  Config::Connect ("/NodeList/*/DeviceList/*/LteEnbRrc/HandoverStart",
340  this));
341 
342  // Get the source eNodeB
343  Ptr<NetDevice> sourceEnb = enbDevs.Get (m_sourceCellId - 1);
344  m_sourceEnbDev = sourceEnb->GetObject<LteEnbNetDevice> ();
345  NS_ASSERT (m_sourceEnbDev != 0);
347 
348  // Attach UE to the source eNodeB
349  lteHelper->Attach (ueDevs.Get (0), sourceEnb);
350 
351  // Schedule a "shutdown" of the source eNodeB
352  Simulator::Schedule (Seconds (0.5),
354 
355  // Run simulation
356  Simulator::Stop (Seconds (1));
357  Simulator::Run ();
358  Simulator::Destroy ();
359 
360 } // end of void LteX2HandoverTargetTestCase::DoRun ()
361 
362 
363 void
365 {
366  NS_LOG_FUNCTION (this);
367  NS_TEST_ASSERT_MSG_EQ (m_hasHandoverOccurred, true, "Handover did not occur");
368 }
369 
370 
371 
381 {
382 public:
384 };
385 
386 
388  : TestSuite ("lte-handover-target", SYSTEM)
389 {
390  // LogComponentEnable ("LteHandoverTargetTest", LOG_PREFIX_ALL);
391  // LogComponentEnable ("LteHandoverTargetTest", LOG_LEVEL_ALL);
392  // LogComponentEnable ("A2A4RsrqHandoverAlgorithm", LOG_PREFIX_ALL);
393  // LogComponentEnable ("A2A4RsrqHandoverAlgorithm", LOG_LEVEL_ALL);
394  // LogComponentEnable ("A3RsrpHandoverAlgorithm", LOG_PREFIX_ALL);
395  // LogComponentEnable ("A3RsrpHandoverAlgorithm", LOG_LEVEL_ALL);
396 
397  /*
398  * 3 --- 4
399  * | |
400  * |o |
401  * 1 --- 2 o = UE
402  */
403  AddTestCase (new LteHandoverTargetTestCase ("4 cells and A2-A4-RSRQ algorithm",
404  Vector (20, 40, 0), 2, 2, 1, 3,
405  "ns3::A2A4RsrqHandoverAlgorithm"),
406  TestCase::QUICK);
407  AddTestCase (new LteHandoverTargetTestCase ("4 cells and strongest cell algorithm",
408  Vector (20, 40, 0), 2, 2, 1, 3,
409  "ns3::A3RsrpHandoverAlgorithm"),
410  TestCase::QUICK);
411 
412  /*
413  * 4 --- 5 --- 6
414  * | |o |
415  * | | |
416  * 1 --- 2 --- 3 o = UE
417  */
418  AddTestCase (new LteHandoverTargetTestCase ("6 cells and A2-A4-RSRQ algorithm",
419  Vector (150, 90, 0), 3, 2, 5, 2,
420  "ns3::A2A4RsrqHandoverAlgorithm"),
421  TestCase::EXTENSIVE);
422  AddTestCase (new LteHandoverTargetTestCase ("6 cells and strongest cell algorithm",
423  Vector (150, 90, 0), 3, 2, 5, 2,
424  "ns3::A3RsrpHandoverAlgorithm"),
425  TestCase::EXTENSIVE);
426 
427 } // end of LteHandoverTargetTestSuite ()
428 
429 
Testing a handover algorithm, verifying that it selects the right target cell when more than one opti...
#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
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Create a set of eNodeB devices.
Definition: lte-helper.cc:382
holds a vector of std::pair of Ptr and interface index.
uint16_t GetCellId() const
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
Hold variables of type string.
Definition: string.h:41
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
A suite of tests to run.
Definition: test.h:1333
Ptr< LteEnbPhy > GetPhy(void) const
#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 Attach(NetDeviceContainer ueDevices)
Enables automatic attachment of a set of UE devices to a suitable cell using Idle mode initial cell s...
Definition: lte-helper.cc:716
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:903
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
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
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 SetHandoverAlgorithmType(std::string type)
Set the type of handover algorithm to be used by eNodeB devices.
Definition: lte-helper.cc:273
uint32_t GetN(void) const
Get the number of Ptr stored in this container.
Class for representing data rates.
Definition: data-rate.h:88
void CellShutdownCallback()
A trigger that can be scheduled to "shutdown" the cell pointed by m_sourceCellId by reducing its powe...
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
tuple phy
Definition: third.py:86
void SetHandoverAlgorithmAttribute(std::string n, const AttributeValue &v)
Set an attribute for the handover algorithm to be created.
Definition: lte-helper.cc:281
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
AttributeValue implementation for Time.
Definition: nstime.h:957
Hold an unsigned integer type.
Definition: uinteger.h:44
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition: test.h:161
holds a vector of ns3::NetDevice pointers
void HandoverStartCallback(std::string context, uint64_t imsi, uint16_t sourceCellId, uint16_t rnti, uint16_t targetCellId)
Triggers when an eNodeB starts a handover and then verifies that the handover has the right source an...
static LteHandoverTargetTestSuite g_lteHandoverTargetTestSuiteInstance
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
virtual void DoRun()
Run a simulation of a micro-cell network using the parameters provided to the constructor function...
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:835
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())
virtual void DoTeardown()
Called at the end of simulation and verifies that a handover has occurred in the simulation.
void SetTxPower(double pow)
Definition: lte-enb-phy.cc:304
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
void AddX2Interface(NodeContainer enbNodes)
Create an X2 interface between all the eNBs in a given set.
Definition: lte-helper.cc:976
Test suite lte-handover-target, verifying that handover algorithms are able to select the right targe...
Ptr< LteEnbNetDevice > m_sourceEnbDev
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
LteHandoverTargetTestCase(std::string name, Vector uePosition, uint8_t gridSizeX, uint8_t gridSizeY, uint16_t sourceCellId, uint16_t targetCellId, std::string handoverAlgorithmType)
Construct a new test case and providing input parameters for the simulation.
NetDeviceContainer InstallUeDevice(NodeContainer c)
Create a set of UE devices.
Definition: lte-helper.cc:397
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
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...
void SetEpcHelper(Ptr< EpcHelper > h)
Set the EpcHelper to be used to setup the EPC network in conjunction with the setup of the LTE radio ...
Definition: lte-helper.cc:218
Helper class that adds ns3::Ipv4StaticRouting objects.
AttributeValue implementation for DataRate.
Definition: data-rate.h:242
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:774
void Add(Vector v)
Add a position to the list of positions.
std::string GetName(void) const
Definition: test.cc:369
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:340
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...
#define NS_TEST_ASSERT_MSG_GT(actual, limit, msg)
Test that an actual value is greater than a limit and report and abort if not.
Definition: test.h:990
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:191
The eNodeB device implementation.
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:345
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.