A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lte-test-secondary-cell-handover.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Alexander Krotov
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Alexander Krotov <krotov@iitp.ru>
7 *
8 */
9
10#include <ns3/boolean.h>
11#include <ns3/double.h>
12#include <ns3/friis-spectrum-propagation-loss.h>
13#include <ns3/integer.h>
14#include <ns3/internet-stack-helper.h>
15#include <ns3/log.h>
16#include <ns3/lte-enb-net-device.h>
17#include <ns3/lte-helper.h>
18#include <ns3/lte-ue-net-device.h>
19#include <ns3/lte-ue-rrc.h>
20#include <ns3/mobility-helper.h>
21#include <ns3/point-to-point-epc-helper.h>
22#include <ns3/simulator.h>
23#include <ns3/test.h>
24
25using namespace ns3;
26
27NS_LOG_COMPONENT_DEFINE("LteSecondaryCellHandoverTest");
28
29/**
30 * \ingroup lte-test
31 *
32 * \brief Test measurement-based handover to secondary cell.
33 */
34
36{
37 public:
38 /**
39 * \brief Creates an instance of the measurement-based secondary cell handover test case.
40 * \param name name of the test case
41 * \param useIdealRrc if true, simulation uses Ideal RRC protocol, otherwise
42 * simulation uses Real RRC protocol
43 */
44
45 LteSecondaryCellHandoverTestCase(std::string name, bool useIdealRrc);
46
47 /**
48 * \brief Shutdown cellId by reducing its power to 1 dBm.
49 * \param cellId ID of the cell to shutdown
50 */
51 void ShutdownCell(uint32_t cellId);
52
53 /**
54 * \brief Callback method indicating start of UE handover
55 * \param imsi The IMSI
56 * \param sourceCellId The source cell ID
57 * \param rnti The RNTI
58 * \param targetCellId The target cell ID
59 */
60 void UeHandoverStartCallback(uint64_t imsi,
61 uint16_t sourceCellId,
62 uint16_t rnti,
63 uint16_t targetCellId);
64
65 private:
66 /**
67 * \brief Run a simulation.
68 */
69 void DoRun() override;
70
71 /**
72 * \brief Verify that handover has occurred during the simulation.
73 */
74 void DoTeardown() override;
75
76 bool m_useIdealRrc; ///< whether LTE is configured to use ideal RRC
77 uint8_t m_numberOfComponentCarriers; ///< Number of component carriers
78
79 Ptr<LteEnbNetDevice> m_sourceEnbDev; ///< Source eNB device
80
81 bool m_hasUeHandoverStarted; ///< true if UE started handover
82};
83
85 bool useIdealRrc)
86 : TestCase{name},
87 m_useIdealRrc{useIdealRrc},
88 m_numberOfComponentCarriers{2},
89 m_hasUeHandoverStarted{false}
90{
91}
92
93void
95{
96 Ptr<LteEnbPhy> phy = m_sourceEnbDev->GetPhy(cellId - 1);
97 phy->SetTxPower(1);
98}
99
100void
102 uint16_t sourceCellId,
103 uint16_t rnti,
104 uint16_t targetCellId)
105{
106 NS_LOG_FUNCTION(this << imsi << sourceCellId << rnti << targetCellId);
108}
109
110void
112{
113 NS_LOG_FUNCTION(this << GetName());
114
115 Config::SetDefault("ns3::LteEnbNetDevice::DlEarfcn", UintegerValue(100));
116 Config::SetDefault("ns3::LteEnbNetDevice::UlEarfcn", UintegerValue(100 + 18000));
117 Config::SetDefault("ns3::LteEnbNetDevice::DlBandwidth", UintegerValue(25));
118 Config::SetDefault("ns3::LteEnbNetDevice::UlBandwidth", UintegerValue(25));
119 Config::SetDefault("ns3::LteUeNetDevice::DlEarfcn", UintegerValue(100));
120
121 // Create helpers.
122 auto lteHelper = CreateObject<LteHelper>();
123 lteHelper->SetAttribute("PathlossModel",
125 lteHelper->SetAttribute("UseIdealRrc", BooleanValue(m_useIdealRrc));
126 lteHelper->SetAttribute("NumberOfComponentCarriers",
128
129 // Configure handover algorithm.
130 lteHelper->SetHandoverAlgorithmType("ns3::A3RsrpHandoverAlgorithm");
131 lteHelper->SetHandoverAlgorithmAttribute("Hysteresis", DoubleValue(1.5));
132 lteHelper->SetHandoverAlgorithmAttribute("TimeToTrigger", TimeValue(MilliSeconds(128)));
133
134 auto epcHelper = CreateObject<PointToPointEpcHelper>();
135 lteHelper->SetEpcHelper(epcHelper);
136
137 // Create nodes.
138 auto enbNode = CreateObject<Node>();
139 auto ueNode = CreateObject<Node>();
140
141 // Setup node mobility.
142 MobilityHelper mobility;
143 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
144 mobility.Install(enbNode);
145 mobility.Install(ueNode);
146
147 // Physical layer.
148 m_sourceEnbDev = DynamicCast<LteEnbNetDevice>(lteHelper->InstallEnbDevice(enbNode).Get(0));
149 auto ueDevs = lteHelper->InstallUeDevice(ueNode);
150 auto ueDev = DynamicCast<LteUeNetDevice>(ueDevs.Get(0));
151
152 // Network layer.
153 InternetStackHelper internet;
154 internet.Install(ueNode);
155 epcHelper->AssignUeIpv4Address(NetDeviceContainer(ueDev));
156
157 uint16_t sourceCellId = m_sourceEnbDev->GetCellId();
160 this,
161 sourceCellId);
162
163 // Setup traces.
164 ueDev->GetRrc()->TraceConnectWithoutContext(
165 "HandoverStart",
167
168 std::map<uint8_t, Ptr<ComponentCarrierUe>> ueCcMap = ueDev->GetCcMap();
169 ueDev->SetDlEarfcn(ueCcMap.at(0)->GetDlEarfcn());
170 lteHelper->Attach(ueDev, m_sourceEnbDev, 0);
171
172 // Run simulation.
176}
177
178void
184
185/**
186 * \ingroup lte-test
187 *
188 * \brief LTE measurement-based handover to secondary cell test suite.
189 */
195
197 : TestSuite{"lte-secondary-cell-handover", Type::SYSTEM}
198{
199 AddTestCase(new LteSecondaryCellHandoverTestCase("Ideal RRC", true), TestCase::Duration::QUICK);
200 AddTestCase(new LteSecondaryCellHandoverTestCase("Real RRC", false), TestCase::Duration::QUICK);
201}
202
203/**
204 * \ingroup lte-test
205 * Static variable for test initialization
206 */
Test measurement-based handover to secondary cell.
void UeHandoverStartCallback(uint64_t imsi, uint16_t sourceCellId, uint16_t rnti, uint16_t targetCellId)
Callback method indicating start of UE handover.
bool m_useIdealRrc
whether LTE is configured to use ideal RRC
Ptr< LteEnbNetDevice > m_sourceEnbDev
Source eNB device.
void ShutdownCell(uint32_t cellId)
Shutdown cellId by reducing its power to 1 dBm.
LteSecondaryCellHandoverTestCase(std::string name, bool useIdealRrc)
Creates an instance of the measurement-based secondary cell handover test case.
uint8_t m_numberOfComponentCarriers
Number of component carriers.
void DoTeardown() override
Verify that handover has occurred during the simulation.
bool m_hasUeHandoverStarted
true if UE started handover
LTE measurement-based handover to secondary cell test suite.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
aggregate IP/TCP/UDP functionality to existing Nodes.
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
std::string GetName() const
Definition test.cc:367
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
Hold an unsigned integer type.
Definition uinteger.h:34
void SetDefault(std::string name, const AttributeValue &value)
Definition config.cc:883
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
static LteSecondaryCellHandoverTestSuite g_lteSecondaryCellHandoverTestSuiteInstance
Static variable for test initialization.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#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:134
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1320
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:684
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580