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
51using namespace ns3;
52
53NS_LOG_COMPONENT_DEFINE ("LteHandoverTargetTest");
54
70{
71public:
90 LteHandoverTargetTestCase (std::string name, Vector uePosition,
91 uint8_t gridSizeX, uint8_t gridSizeY,
92 uint16_t sourceCellId, uint16_t targetCellId,
93 std::string handoverAlgorithmType);
94
96
110 void HandoverStartCallback (std::string context, uint64_t imsi,
111 uint16_t sourceCellId, uint16_t rnti,
112 uint16_t targetCellId);
113
118 void CellShutdownCallback ();
119
120private:
125 virtual void DoRun ();
126
131 virtual void DoTeardown ();
132
133 // simulation parameters
135 uint8_t m_gridSizeX;
136 uint8_t m_gridSizeY;
137 uint16_t m_sourceCellId;
138 uint16_t m_targetCellId;
140
143
144}; // end of class LteHandoverTargetTestCase
145
146
148 uint8_t gridSizeX, uint8_t gridSizeY,
149 uint16_t sourceCellId, uint16_t targetCellId,
150 std::string handoverAlgorithmType)
151 : TestCase (name),
152 m_uePosition (uePosition),
153 m_gridSizeX (gridSizeX),
154 m_gridSizeY (gridSizeY),
155 m_sourceCellId (sourceCellId),
156 m_targetCellId (targetCellId),
157 m_handoverAlgorithmType (handoverAlgorithmType),
158 m_sourceEnbDev (0),
159 m_hasHandoverOccurred (false)
160{
161 NS_LOG_INFO (this << " name=" << name);
162
163 // SANITY CHECK
164
165 uint16_t nEnb = gridSizeX * gridSizeY;
166
167 if (sourceCellId > nEnb)
168 {
169 NS_FATAL_ERROR ("Invalid source cell ID " << sourceCellId);
170 }
171
172 if (targetCellId > nEnb)
173 {
174 NS_FATAL_ERROR ("Invalid target cell ID " << targetCellId);
175 }
176}
177
178
180{
181 NS_LOG_FUNCTION (this);
182}
183
184
185void
186LteHandoverTargetTestCase::HandoverStartCallback (std::string context, uint64_t imsi,
187 uint16_t sourceCellId, uint16_t rnti,
188 uint16_t targetCellId)
189{
190 NS_LOG_FUNCTION (this << context << imsi << sourceCellId << rnti << targetCellId);
191
192 uint64_t timeNowMs = Simulator::Now ().GetMilliSeconds ();
193 NS_TEST_ASSERT_MSG_GT (timeNowMs, 500,
194 "Handover occurred but too early");
196 "Handover occurred but with wrong source cell");
198 "Handover occurred but with wrong target cell");
200}
201
202
203void
205{
206 NS_LOG_FUNCTION (this);
207
208 if (m_sourceEnbDev != 0)
209 {
210 // set the Tx power to 1 dBm
212 NS_LOG_INFO ("Shutting down cell " << m_sourceCellId);
214 phy->SetTxPower (1);
215 }
216}
217
218
219void
221{
222 NS_LOG_INFO (this << " " << GetName ());
223
224 Config::SetDefault ("ns3::LteEnbPhy::TxPower", DoubleValue (38)); // micro cell
225 Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled",
226 BooleanValue (false)); // disable control channel error model
227
228 Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
229 Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper> ();
230 lteHelper->SetEpcHelper (epcHelper);
231 lteHelper->SetAttribute ("PathlossModel",
232 StringValue ("ns3::FriisSpectrumPropagationLossModel"));
233 lteHelper->SetAttribute ("UseIdealRrc", BooleanValue (true));
234
235 if (m_handoverAlgorithmType == "ns3::A2A4RsrqHandoverAlgorithm")
236 {
237 lteHelper->SetHandoverAlgorithmType ("ns3::A2A4RsrqHandoverAlgorithm");
238 lteHelper->SetHandoverAlgorithmAttribute ("ServingCellThreshold",
239 UintegerValue (30));
240 lteHelper->SetHandoverAlgorithmAttribute ("NeighbourCellOffset",
241 UintegerValue (1));
242 }
243 else if (m_handoverAlgorithmType == "ns3::A3RsrpHandoverAlgorithm")
244 {
245 lteHelper->SetHandoverAlgorithmType ("ns3::A3RsrpHandoverAlgorithm");
246 lteHelper->SetHandoverAlgorithmAttribute ("Hysteresis",
247 DoubleValue (1.5));
248 lteHelper->SetHandoverAlgorithmAttribute ("TimeToTrigger",
249 TimeValue (MilliSeconds (128)));
250 }
251 else
252 {
253 NS_FATAL_ERROR ("Unknown handover algorithm " << m_handoverAlgorithmType);
254 }
255
256 // Create Nodes: eNodeB and UE
257 NodeContainer enbNodes;
258 NodeContainer ueNodes;
259 enbNodes.Create (m_gridSizeX * m_gridSizeY);
260 ueNodes.Create (1);
261
262 /*
263 * The size of the grid is determined by m_gridSizeX and m_gridSizeY. The
264 * following figure is the topology when m_gridSizeX = 4 and m_gridSizeY = 3.
265 *
266 * 9 -- 10 -- 11 -- 12
267 * | | | |
268 * | | | |
269 * 5 --- 6 --- 7 --- 8
270 * | | | |
271 * | | | |
272 * (0, 0, 0) ---> 1 --- 2 --- 3 --- 4
273 *
274 * The grid starts at (0, 0, 0) point on the bottom left corner. The distance
275 * between two adjacent eNodeBs is 130 m.
276 */
277
278 // Set up eNodeB position
279 MobilityHelper enbMobility;
280 enbMobility.SetPositionAllocator ("ns3::GridPositionAllocator",
281 "MinX", DoubleValue (0.0),
282 "MinY", DoubleValue (0.0),
283 "DeltaX", DoubleValue (130.0),
284 "DeltaY", DoubleValue (130.0),
285 "GridWidth", UintegerValue (m_gridSizeX),
286 "LayoutType", StringValue ("RowFirst"));
287 enbMobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
288 enbMobility.Install (enbNodes);
289
290 // Setup UE position
291 Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
292 positionAlloc->Add (m_uePosition);
293 MobilityHelper ueMobility;
294 ueMobility.SetPositionAllocator (positionAlloc);
295 ueMobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
296 ueMobility.Install (ueNodes);
297
298 // Create P-GW node
299 Ptr<Node> pgw = epcHelper->GetPgwNode ();
300
301 // Create a single RemoteHost
302 NodeContainer remoteHostContainer;
303 remoteHostContainer.Create (1);
304 Ptr<Node> remoteHost = remoteHostContainer.Get (0);
305 InternetStackHelper internet;
306 internet.Install (remoteHostContainer);
307
308 // Create the Internet
310 p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
311 p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500));
312 p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010)));
313 NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
314 Ipv4AddressHelper ipv4h;
315 ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
316 Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices);
317
318 // Routing of the Internet Host (towards the LTE network)
319 Ipv4StaticRoutingHelper ipv4RoutingHelper;
320 Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
321 remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1);
322
323 // Create Devices and install them in the Nodes (eNB and UE)
324 NetDeviceContainer enbDevs;
325 NetDeviceContainer ueDevs;
326 enbDevs = lteHelper->InstallEnbDevice (enbNodes);
327 ueDevs = lteHelper->InstallUeDevice (ueNodes);
328
329 // Install the IP stack on the UEs
330 internet.Install (ueNodes);
331 Ipv4InterfaceContainer ueIpIfaces;
332 ueIpIfaces = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueDevs));
333
334 // Assign IP address to UEs
335 for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
336 {
337 Ptr<Node> ueNode = ueNodes.Get (u);
338 // Set the default gateway for the UE
339 Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv4> ());
340 ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1);
341 }
342
343 // Add X2 interface
344 lteHelper->AddX2Interface (enbNodes);
345
346 // Connect to trace sources in all eNodeB
347 Config::Connect ("/NodeList/*/DeviceList/*/LteEnbRrc/HandoverStart",
349 this));
350
351 // Get the source eNodeB
352 Ptr<NetDevice> sourceEnb = enbDevs.Get (m_sourceCellId - 1);
356
357 // Attach UE to the source eNodeB
358 lteHelper->Attach (ueDevs.Get (0), sourceEnb);
359
360 // Schedule a "shutdown" of the source eNodeB
361 Simulator::Schedule (Seconds (0.5),
363
364 // Run simulation
365 Simulator::Stop (Seconds (1));
366 Simulator::Run ();
367 Simulator::Destroy ();
368
369} // end of void LteX2HandoverTargetTestCase::DoRun ()
370
371
372void
374{
375 NS_LOG_FUNCTION (this);
376 NS_TEST_ASSERT_MSG_EQ (m_hasHandoverOccurred, true, "Handover did not occur");
377}
378
379
380
390{
391public:
393};
394
395
397 : TestSuite ("lte-handover-target", SYSTEM)
398{
399 // LogComponentEnable ("LteHandoverTargetTest", LOG_PREFIX_ALL);
400 // LogComponentEnable ("LteHandoverTargetTest", LOG_LEVEL_ALL);
401 // LogComponentEnable ("A2A4RsrqHandoverAlgorithm", LOG_PREFIX_ALL);
402 // LogComponentEnable ("A2A4RsrqHandoverAlgorithm", LOG_LEVEL_ALL);
403 // LogComponentEnable ("A3RsrpHandoverAlgorithm", LOG_PREFIX_ALL);
404 // LogComponentEnable ("A3RsrpHandoverAlgorithm", LOG_LEVEL_ALL);
405
406 /*
407 * 3 --- 4
408 * | |
409 * |o |
410 * 1 --- 2 o = UE
411 */
412 AddTestCase (new LteHandoverTargetTestCase ("4 cells and A2-A4-RSRQ algorithm",
413 Vector (20, 40, 0), 2, 2, 1, 3,
414 "ns3::A2A4RsrqHandoverAlgorithm"),
415 TestCase::QUICK);
416 AddTestCase (new LteHandoverTargetTestCase ("4 cells and strongest cell algorithm",
417 Vector (20, 40, 0), 2, 2, 1, 3,
418 "ns3::A3RsrpHandoverAlgorithm"),
419 TestCase::QUICK);
420
421 /*
422 * 4 --- 5 --- 6
423 * | |o |
424 * | | |
425 * 1 --- 2 --- 3 o = UE
426 */
427 AddTestCase (new LteHandoverTargetTestCase ("6 cells and A2-A4-RSRQ algorithm",
428 Vector (150, 90, 0), 3, 2, 5, 2,
429 "ns3::A2A4RsrqHandoverAlgorithm"),
430 TestCase::EXTENSIVE);
431 AddTestCase (new LteHandoverTargetTestCase ("6 cells and strongest cell algorithm",
432 Vector (150, 90, 0), 3, 2, 5, 2,
433 "ns3::A3RsrpHandoverAlgorithm"),
434 TestCase::EXTENSIVE);
435
436} // end of LteHandoverTargetTestSuite ()
437
438
Testing a handover algorithm, verifying that it selects the right target cell when more than one opti...
Ptr< LteEnbNetDevice > m_sourceEnbDev
source ENB device
std::string m_handoverAlgorithmType
handover algorithm type
bool m_hasHandoverOccurred
has handover occurred?
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.
void CellShutdownCallback()
A trigger that can be scheduled to "shutdown" the cell pointed by m_sourceCellId by reducing its powe...
uint16_t m_sourceCellId
source cell ID
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...
virtual void DoTeardown()
Called at the end of simulation and verifies that a handover has occurred in the simulation.
uint16_t m_targetCellId
target cell ID
virtual void DoRun()
Run a simulation of a micro-cell network using the parameters provided to the constructor function.
Test suite lte-handover-target, verifying that handover algorithms are able to select the right targe...
AttributeValue implementation for Boolean.
Definition: boolean.h:37
Class for representing data rates.
Definition: data-rate.h:89
AttributeValue implementation for DataRate.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
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...
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:41
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:77
holds a vector of std::pair of Ptr<Ipv4> and interface index.
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:256
Helper class that adds ns3::Ipv4StaticRouting objects.
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...
The eNodeB device implementation.
Ptr< LteEnbPhy > GetPhy(void) const
uint16_t GetCellId() const
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:272
void SetHandoverAlgorithmAttribute(std::string n, const AttributeValue &v)
Set an attribute for the handover algorithm to be created.
Definition: lte-helper.cc:335
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Create a set of eNodeB devices.
Definition: lte-helper.cc:474
void SetHandoverAlgorithmType(std::string type)
Set the type of handover algorithm to be used by eNodeB devices.
Definition: lte-helper.cc:327
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:959
NetDeviceContainer InstallUeDevice(NodeContainer c)
Create a set of UE devices.
Definition: lte-helper.cc:489
void AddX2Interface(NodeContainer enbNodes)
Create an X2 interface between all the eNBs in a given set.
Definition: lte-helper.cc:1220
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...
holds a vector of ns3::NetDevice pointers
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
virtual Ipv4Address GetUeDefaultGatewayAddress()
virtual Ptr< Node > GetPgwNode() const
Get the PGW node.
virtual Ipv4InterfaceContainer AssignUeIpv4Address(NetDeviceContainer ueDevices)
Assign IPv4 addresses to UE devices.
keep track of a set of node pointers.
uint32_t GetN(void) const
Get the number of Ptr<Node> stored in this container.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:256
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
Build a set of PointToPointNetDevice objects.
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
NetDeviceContainer Install(NodeContainer c)
Hold variables of type string.
Definition: string.h:41
encapsulates test code
Definition: test.h:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
std::string GetName(void) const
Definition: test.cc:370
A suite of tests to run.
Definition: test.h:1188
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:383
AttributeValue implementation for Time.
Definition: nstime.h:1308
Hold an unsigned integer type.
Definition: uinteger.h:44
Vector3D Vector
Vector alias typedef for compatibility with mobility models.
Definition: vector.h:324
#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 SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:849
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:920
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#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
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
#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:141
#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:825
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1252
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:1648
phy
Definition: third.py:93
static LteHandoverTargetTestSuite g_lteHandoverTargetTestSuiteInstance