A Discrete-Event Network Simulator
API
test-lte-handover-target.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013 Budiarto Herman
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Budiarto Herman <budiarto.herman@magister.fi>
18 *
19 */
20
21#include <ns3/boolean.h>
22#include <ns3/callback.h>
23#include <ns3/config.h>
24#include <ns3/data-rate.h>
25#include <ns3/double.h>
26#include <ns3/internet-stack-helper.h>
27#include <ns3/ipv4-address-helper.h>
28#include <ns3/ipv4-interface-container.h>
29#include <ns3/ipv4-static-routing-helper.h>
30#include <ns3/ipv4-static-routing.h>
31#include <ns3/log.h>
32#include <ns3/lte-enb-net-device.h>
33#include <ns3/lte-enb-phy.h>
34#include <ns3/lte-helper.h>
35#include <ns3/mobility-helper.h>
36#include <ns3/net-device-container.h>
37#include <ns3/node-container.h>
38#include <ns3/nstime.h>
39#include <ns3/point-to-point-epc-helper.h>
40#include <ns3/point-to-point-helper.h>
41#include <ns3/position-allocator.h>
42#include <ns3/simulator.h>
43#include <ns3/test.h>
44#include <ns3/uinteger.h>
45
46using namespace ns3;
47
48NS_LOG_COMPONENT_DEFINE("LteHandoverTargetTest");
49
65{
66 public:
85 LteHandoverTargetTestCase(std::string name,
86 Vector uePosition,
87 uint8_t gridSizeX,
88 uint8_t gridSizeY,
89 uint16_t sourceCellId,
90 uint16_t targetCellId,
91 std::string handoverAlgorithmType);
92
94
108 void HandoverStartCallback(std::string context,
109 uint64_t imsi,
110 uint16_t sourceCellId,
111 uint16_t rnti,
112 uint16_t targetCellId);
113
119
120 private:
125 void DoRun() override;
126
131 void DoTeardown() override;
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
147 Vector uePosition,
148 uint8_t gridSizeX,
149 uint8_t gridSizeY,
150 uint16_t sourceCellId,
151 uint16_t targetCellId,
152 std::string handoverAlgorithmType)
153 : TestCase(name),
154 m_uePosition(uePosition),
155 m_gridSizeX(gridSizeX),
156 m_gridSizeY(gridSizeY),
157 m_sourceCellId(sourceCellId),
158 m_targetCellId(targetCellId),
159 m_handoverAlgorithmType(handoverAlgorithmType),
160 m_sourceEnbDev(nullptr),
161 m_hasHandoverOccurred(false)
162{
163 NS_LOG_INFO(this << " name=" << name);
164
165 // SANITY CHECK
166
167 uint16_t nEnb = gridSizeX * gridSizeY;
168
169 if (sourceCellId > nEnb)
170 {
171 NS_FATAL_ERROR("Invalid source cell ID " << sourceCellId);
172 }
173
174 if (targetCellId > nEnb)
175 {
176 NS_FATAL_ERROR("Invalid target cell ID " << targetCellId);
177 }
178}
179
181{
182 NS_LOG_FUNCTION(this);
183}
184
185void
187 uint64_t imsi,
188 uint16_t sourceCellId,
189 uint16_t rnti,
190 uint16_t targetCellId)
191{
192 NS_LOG_FUNCTION(this << context << imsi << sourceCellId << rnti << targetCellId);
193
194 uint64_t timeNowMs = Simulator::Now().GetMilliSeconds();
195 NS_TEST_ASSERT_MSG_GT(timeNowMs, 500, "Handover occurred but too early");
196 NS_TEST_ASSERT_MSG_EQ(sourceCellId,
198 "Handover occurred but with wrong source cell");
199 NS_TEST_ASSERT_MSG_EQ(targetCellId,
201 "Handover occurred but with wrong target cell");
203}
204
205void
207{
208 NS_LOG_FUNCTION(this);
209
210 if (m_sourceEnbDev)
211 {
212 // set the Tx power to 1 dBm
214 NS_LOG_INFO("Shutting down cell " << m_sourceCellId);
216 phy->SetTxPower(1);
217 }
218}
219
220void
222{
223 NS_LOG_INFO(this << " " << GetName());
224
225 Config::SetDefault("ns3::LteEnbPhy::TxPower", DoubleValue(38)); // micro cell
226 Config::SetDefault("ns3::LteSpectrumPhy::CtrlErrorModelEnabled",
227 BooleanValue(false)); // disable control channel error model
228
229 Ptr<LteHelper> lteHelper = CreateObject<LteHelper>();
230 Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper>();
231 lteHelper->SetEpcHelper(epcHelper);
232 lteHelper->SetAttribute("PathlossModel", 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", UintegerValue(30));
239 lteHelper->SetHandoverAlgorithmAttribute("NeighbourCellOffset", UintegerValue(1));
240 }
241 else if (m_handoverAlgorithmType == "ns3::A3RsrpHandoverAlgorithm")
242 {
243 lteHelper->SetHandoverAlgorithmType("ns3::A3RsrpHandoverAlgorithm");
244 lteHelper->SetHandoverAlgorithmAttribute("Hysteresis", DoubleValue(1.5));
245 lteHelper->SetHandoverAlgorithmAttribute("TimeToTrigger", TimeValue(MilliSeconds(128)));
246 }
247 else
248 {
249 NS_FATAL_ERROR("Unknown handover algorithm " << m_handoverAlgorithmType);
250 }
251
252 // Create Nodes: eNodeB and UE
253 NodeContainer enbNodes;
254 NodeContainer ueNodes;
255 enbNodes.Create(m_gridSizeX * m_gridSizeY);
256 ueNodes.Create(1);
257
258 /*
259 * The size of the grid is determined by m_gridSizeX and m_gridSizeY. The
260 * following figure is the topology when m_gridSizeX = 4 and m_gridSizeY = 3.
261 *
262 * 9 -- 10 -- 11 -- 12
263 * | | | |
264 * | | | |
265 * 5 --- 6 --- 7 --- 8
266 * | | | |
267 * | | | |
268 * (0, 0, 0) ---> 1 --- 2 --- 3 --- 4
269 *
270 * The grid starts at (0, 0, 0) point on the bottom left corner. The distance
271 * between two adjacent eNodeBs is 130 m.
272 */
273
274 // Set up eNodeB position
275 MobilityHelper enbMobility;
276 enbMobility.SetPositionAllocator("ns3::GridPositionAllocator",
277 "MinX",
278 DoubleValue(0.0),
279 "MinY",
280 DoubleValue(0.0),
281 "DeltaX",
282 DoubleValue(130.0),
283 "DeltaY",
284 DoubleValue(130.0),
285 "GridWidth",
287 "LayoutType",
288 StringValue("RowFirst"));
289 enbMobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
290 enbMobility.Install(enbNodes);
291
292 // Setup UE position
293 Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
294 positionAlloc->Add(m_uePosition);
295 MobilityHelper ueMobility;
296 ueMobility.SetPositionAllocator(positionAlloc);
297 ueMobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
298 ueMobility.Install(ueNodes);
299
300 // Create P-GW node
301 Ptr<Node> pgw = epcHelper->GetPgwNode();
302
303 // Create a single RemoteHost
304 NodeContainer remoteHostContainer;
305 remoteHostContainer.Create(1);
306 Ptr<Node> remoteHost = remoteHostContainer.Get(0);
307 InternetStackHelper internet;
308 internet.Install(remoteHostContainer);
309
310 // Create the Internet
312 p2ph.SetDeviceAttribute("DataRate", DataRateValue(DataRate("100Gb/s")));
313 p2ph.SetDeviceAttribute("Mtu", UintegerValue(1500));
314 p2ph.SetChannelAttribute("Delay", TimeValue(Seconds(0.010)));
315 NetDeviceContainer internetDevices = p2ph.Install(pgw, remoteHost);
316 Ipv4AddressHelper ipv4h;
317 ipv4h.SetBase("1.0.0.0", "255.0.0.0");
318 Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign(internetDevices);
319
320 // Routing of the Internet Host (towards the LTE network)
321 Ipv4StaticRoutingHelper ipv4RoutingHelper;
322 Ptr<Ipv4StaticRouting> remoteHostStaticRouting =
323 ipv4RoutingHelper.GetStaticRouting(remoteHost->GetObject<Ipv4>());
324 remoteHostStaticRouting->AddNetworkRouteTo(Ipv4Address("7.0.0.0"), Ipv4Mask("255.0.0.0"), 1);
325
326 // Create Devices and install them in the Nodes (eNB and UE)
327 NetDeviceContainer enbDevs;
328 NetDeviceContainer ueDevs;
329 enbDevs = lteHelper->InstallEnbDevice(enbNodes);
330 ueDevs = lteHelper->InstallUeDevice(ueNodes);
331
332 // Install the IP stack on the UEs
333 internet.Install(ueNodes);
334 Ipv4InterfaceContainer ueIpIfaces;
335 ueIpIfaces = epcHelper->AssignUeIpv4Address(NetDeviceContainer(ueDevs));
336
337 // Assign IP address to UEs
338 for (uint32_t u = 0; u < ueNodes.GetN(); ++u)
339 {
340 Ptr<Node> ueNode = ueNodes.Get(u);
341 // Set the default gateway for the UE
342 Ptr<Ipv4StaticRouting> ueStaticRouting =
343 ipv4RoutingHelper.GetStaticRouting(ueNode->GetObject<Ipv4>());
344 ueStaticRouting->SetDefaultRoute(epcHelper->GetUeDefaultGatewayAddress(), 1);
345 }
346
347 // Add X2 interface
348 lteHelper->AddX2Interface(enbNodes);
349
350 // Connect to trace sources in all eNodeB
351 Config::Connect("/NodeList/*/DeviceList/*/LteEnbRrc/HandoverStart",
353
354 // Get the source eNodeB
355 Ptr<NetDevice> sourceEnb = enbDevs.Get(m_sourceCellId - 1);
356 m_sourceEnbDev = sourceEnb->GetObject<LteEnbNetDevice>();
359
360 // Attach UE to the source eNodeB
361 lteHelper->Attach(ueDevs.Get(0), sourceEnb);
362
363 // Schedule a "shutdown" of the source eNodeB
364 Simulator::Schedule(Seconds(0.5), &LteHandoverTargetTestCase::CellShutdownCallback, this);
365
366 // Run simulation
367 Simulator::Stop(Seconds(1));
368 Simulator::Run();
369 Simulator::Destroy();
370
371} // end of void LteX2HandoverTargetTestCase::DoRun ()
372
373void
375{
376 NS_LOG_FUNCTION(this);
377 NS_TEST_ASSERT_MSG_EQ(m_hasHandoverOccurred, true, "Handover did not occur");
378}
379
389{
390 public:
392};
393
395 : TestSuite("lte-handover-target", SYSTEM)
396{
397 // LogComponentEnable ("LteHandoverTargetTest", LOG_PREFIX_ALL);
398 // LogComponentEnable ("LteHandoverTargetTest", LOG_LEVEL_ALL);
399 // LogComponentEnable ("A2A4RsrqHandoverAlgorithm", LOG_PREFIX_ALL);
400 // LogComponentEnable ("A2A4RsrqHandoverAlgorithm", LOG_LEVEL_ALL);
401 // LogComponentEnable ("A3RsrpHandoverAlgorithm", LOG_PREFIX_ALL);
402 // LogComponentEnable ("A3RsrpHandoverAlgorithm", LOG_LEVEL_ALL);
403
404 /*
405 * 3 --- 4
406 * | |
407 * |o |
408 * 1 --- 2 o = UE
409 */
410 AddTestCase(new LteHandoverTargetTestCase("4 cells and A2-A4-RSRQ algorithm",
411 Vector(20, 40, 0),
412 2,
413 2,
414 1,
415 3,
416 "ns3::A2A4RsrqHandoverAlgorithm"),
417 TestCase::QUICK);
418 AddTestCase(new LteHandoverTargetTestCase("4 cells and strongest cell algorithm",
419 Vector(20, 40, 0),
420 2,
421 2,
422 1,
423 3,
424 "ns3::A3RsrpHandoverAlgorithm"),
425 TestCase::QUICK);
426
427 /*
428 * 4 --- 5 --- 6
429 * | |o |
430 * | | |
431 * 1 --- 2 --- 3 o = UE
432 */
433 AddTestCase(new LteHandoverTargetTestCase("6 cells and A2-A4-RSRQ algorithm",
434 Vector(150, 90, 0),
435 3,
436 2,
437 5,
438 2,
439 "ns3::A2A4RsrqHandoverAlgorithm"),
440 TestCase::EXTENSIVE);
441 AddTestCase(new LteHandoverTargetTestCase("6 cells and strongest cell algorithm",
442 Vector(150, 90, 0),
443 3,
444 2,
445 5,
446 2,
447 "ns3::A3RsrpHandoverAlgorithm"),
448 TestCase::EXTENSIVE);
449
450} // end of LteHandoverTargetTestSuite ()
451
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 DoTeardown() override
Called at the end of simulation and verifies that a handover has occurred in 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...
uint16_t m_targetCellId
target cell ID
void DoRun() override
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
AttributeValue implementation for DataRate.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
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:43
Access to the IPv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:79
holds a vector of std::pair of Ptr<Ipv4> and interface index.
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:258
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() 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:282
void SetHandoverAlgorithmAttribute(std::string n, const AttributeValue &v)
Set an attribute for the handover algorithm to be created.
Definition: lte-helper.cc:345
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Create a set of eNodeB devices.
Definition: lte-helper.cc:482
void SetHandoverAlgorithmType(std::string type)
Set the type of handover algorithm to be used by eNodeB devices.
Definition: lte-helper.cc:337
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:1044
NetDeviceContainer InstallUeDevice(NodeContainer c)
Create a set of UE devices.
Definition: lte-helper.cc:497
void AddX2Interface(NodeContainer enbNodes)
Create an X2 interface between all the eNBs in a given set.
Definition: lte-helper.cc:1318
Helper class used to assign positions and mobility models to nodes.
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
void SetMobilityModel(std::string type, Ts &&... args)
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.
Ptr< Node > GetPgwNode() const override
Get the PGW node.
Ipv4Address GetUeDefaultGatewayAddress() override
Ipv4InterfaceContainer AssignUeIpv4Address(NetDeviceContainer ueDevices) override
Assign IPv4 addresses to UE devices.
keep track of a set of node pointers.
uint32_t GetN() 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:258
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
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:42
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
std::string GetName() const
Definition: test.cc:377
A suite of tests to run.
Definition: test.h:1256
int64_t GetMilliSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:407
AttributeValue implementation for Time.
Definition: nstime.h:1425
Hold an unsigned integer type.
Definition: uinteger.h:45
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:66
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:891
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:975
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:160
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#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:275
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Definition: data-rate.h:328
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:296
#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:144
#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:874
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1350
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:691
phy
Definition: third.py:82
static LteHandoverTargetTestSuite g_lteHandoverTargetTestSuiteInstance