A Discrete-Event Network Simulator
API
lte-test-primary-cell-change.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Alexander Krotov
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: Alexander Krotov <krotov@iitp.ru>
18 *
19 */
20
22
23#include <ns3/boolean.h>
24#include <ns3/double.h>
25#include <ns3/friis-spectrum-propagation-loss.h>
26#include <ns3/integer.h>
27#include <ns3/internet-stack-helper.h>
28#include <ns3/ipv4-address-helper.h>
29#include <ns3/ipv4-interface-container.h>
30#include <ns3/ipv4-static-routing-helper.h>
31#include <ns3/log.h>
32#include <ns3/lte-enb-net-device.h>
33#include <ns3/lte-helper.h>
34#include <ns3/lte-ue-net-device.h>
35#include <ns3/lte-ue-rrc.h>
36#include <ns3/mobility-helper.h>
37#include <ns3/net-device-container.h>
38#include <ns3/node-container.h>
39#include <ns3/point-to-point-epc-helper.h>
40#include <ns3/point-to-point-helper.h>
41#include <ns3/simulator.h>
42
43using namespace ns3;
44
45NS_LOG_COMPONENT_DEFINE("LtePrimaryCellChangeTest");
46
47/*
48 * Test Suite
49 */
50
52 : TestSuite("lte-primary-cell-change", SYSTEM)
53{
54 // Test that handover from eNB to eNB with one carrier works within this framework.
55 AddTestCase(new LtePrimaryCellChangeTestCase("ideal RRC, RngRun=1", true, 1, 1, 0, 1),
56 TestCase::QUICK);
57 AddTestCase(new LtePrimaryCellChangeTestCase("real RRC, RngRun=1", false, 1, 1, 0, 1),
58 TestCase::QUICK);
59
60 // Test that handover between first carriers of eNBs works.
61 AddTestCase(new LtePrimaryCellChangeTestCase("ideal RRC, RngRun=1", true, 1, 2, 0, 2),
62 TestCase::QUICK);
63 AddTestCase(new LtePrimaryCellChangeTestCase("real RRC, RngRun=1", false, 1, 2, 0, 2),
64 TestCase::QUICK);
65
66 // Test that handover from second carrier of first eNB to first carrier of second eNB works.
67 AddTestCase(new LtePrimaryCellChangeTestCase("ideal RRC, RngRun=1", true, 1, 2, 1, 2),
68 TestCase::QUICK);
69 AddTestCase(new LtePrimaryCellChangeTestCase("real RRC, RngRun=1", false, 1, 2, 1, 2),
70 TestCase::QUICK);
71
72 // Test that handover from first carrier of first eNB to first carrier of second eNB works.
73 AddTestCase(new LtePrimaryCellChangeTestCase("ideal RRC, RngRun=1", true, 1, 2, 0, 3),
74 TestCase::QUICK);
75 AddTestCase(new LtePrimaryCellChangeTestCase("real RRC, RngRun=1", false, 1, 2, 0, 3),
76 TestCase::QUICK);
77
78 // Test that handover from second carrier of first eNB to second carrier of second eNB works.
79 AddTestCase(new LtePrimaryCellChangeTestCase("ideal RRC, RngRun=1", true, 1, 2, 1, 3),
80 TestCase::QUICK);
81 AddTestCase(new LtePrimaryCellChangeTestCase("real RRC, RngRun=1", false, 1, 2, 1, 3),
82 TestCase::QUICK);
83
84 // Test intra-eNB inter-frequency handover.
85 AddTestCase(new LtePrimaryCellChangeTestCase("ideal RRC, RngRun=1", true, 1, 2, 0, 1),
86 TestCase::QUICK);
87 AddTestCase(new LtePrimaryCellChangeTestCase("real RRC, RngRun=1", false, 1, 2, 0, 1),
88 TestCase::QUICK);
89 AddTestCase(new LtePrimaryCellChangeTestCase("ideal RRC, RngRun=1", true, 1, 2, 1, 0),
90 TestCase::QUICK);
91 AddTestCase(new LtePrimaryCellChangeTestCase("real RRC, RngRun=1", false, 1, 2, 1, 0),
92 TestCase::QUICK);
93 AddTestCase(new LtePrimaryCellChangeTestCase("ideal RRC, RngRun=1", true, 1, 4, 3, 1),
94 TestCase::QUICK);
95 AddTestCase(new LtePrimaryCellChangeTestCase("real RRC, RngRun=1", false, 1, 4, 3, 1),
96 TestCase::QUICK);
97} // end of LtePrimaryCellChangeTestSuite::LtePrimaryCellChangeTestSuite ()
98
100
101/*
102 * Test Case
103 */
104
106 bool isIdealRrc,
107 int64_t rngRun,
108 uint8_t numberOfComponentCarriers,
109 uint8_t sourceComponentCarrier,
110 uint8_t targetComponentCarrier)
111 : TestCase(name),
112 m_isIdealRrc{isIdealRrc},
113 m_rngRun{rngRun},
114 m_numberOfComponentCarriers{numberOfComponentCarriers},
115 m_sourceComponentCarrier{sourceComponentCarrier},
116 m_targetComponentCarrier{targetComponentCarrier}
117{
118 NS_LOG_FUNCTION(this << GetName());
119}
120
122{
123 NS_LOG_FUNCTION(this << GetName());
124}
125
126void
128{
129 NS_LOG_FUNCTION(this << GetName());
130
132
133 Config::SetDefault("ns3::LteEnbNetDevice::DlEarfcn", UintegerValue(100));
134 Config::SetDefault("ns3::LteEnbNetDevice::UlEarfcn", UintegerValue(100 + 18000));
135 Config::SetDefault("ns3::LteEnbNetDevice::DlBandwidth", UintegerValue(25));
136 Config::SetDefault("ns3::LteEnbNetDevice::UlBandwidth", UintegerValue(25));
137 Config::SetDefault("ns3::LteUeNetDevice::DlEarfcn", UintegerValue(100));
138
139 // Create helpers.
140 auto lteHelper = CreateObject<LteHelper>();
141 lteHelper->SetAttribute("PathlossModel",
143 lteHelper->SetAttribute("UseIdealRrc", BooleanValue(m_isIdealRrc));
144 lteHelper->SetAttribute("NumberOfComponentCarriers",
146
147 auto epcHelper = CreateObject<PointToPointEpcHelper>();
148 lteHelper->SetEpcHelper(epcHelper);
149
150 // Create nodes.
151 NodeContainer enbNodes;
152 enbNodes.Create(2);
153 auto ueNode = CreateObject<Node>();
154
156 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
157 mobility.Install(enbNodes);
158 mobility.Install(ueNode);
159
160 // Physical layer.
161 auto enbDevs = lteHelper->InstallEnbDevice(enbNodes);
162 auto ueDev = DynamicCast<LteUeNetDevice>(lteHelper->InstallUeDevice(ueNode).Get(0));
163
164 auto sourceEnbDev = DynamicCast<LteEnbNetDevice>(
166 auto targetEnbDev = DynamicCast<LteEnbNetDevice>(
168
169 // Network layer.
170 InternetStackHelper internet;
171 internet.Install(ueNode);
172 epcHelper->AssignUeIpv4Address(NetDeviceContainer(ueDev));
173
174 std::map<uint8_t, Ptr<ComponentCarrierUe>> ueCcMap = ueDev->GetCcMap();
175 ueDev->SetDlEarfcn(ueCcMap.at(m_sourceComponentCarrier)->GetDlEarfcn());
176
177 // Attach UE to specified component carrier
178 lteHelper->Attach(ueDev, sourceEnbDev, m_sourceComponentCarrier % m_numberOfComponentCarriers);
179
180 // Connect to trace sources in UEs
181 Config::Connect("/NodeList/*/DeviceList/*/LteUeRrc/StateTransition",
184 "/NodeList/*/DeviceList/*/LteUeRrc/ConnectionEstablished",
186
187 uint16_t targetCellId = targetEnbDev->GetCcMap()
189 ->GetCellId();
190
191 lteHelper->AddX2Interface(enbNodes);
192 lteHelper->HandoverRequest(Seconds(1.0), ueDev, sourceEnbDev, targetCellId);
193
194 // Run simulation.
195 Simulator::Stop(Seconds(2.0));
196 Simulator::Run();
197
198 uint16_t expectedCellId = targetCellId;
199 uint16_t actualCellId = ueDev->GetRrc()->GetCellId();
200 NS_TEST_ASSERT_MSG_EQ(expectedCellId,
201 actualCellId,
202 "IMSI " << ueDev->GetImsi() << " has attached to an unexpected cell");
203
204 NS_TEST_ASSERT_MSG_EQ(m_lastState.at(ueDev->GetImsi()),
205 LteUeRrc::CONNECTED_NORMALLY,
206 "UE " << ueDev->GetImsi() << " is not at CONNECTED_NORMALLY state");
207
208 // Destroy simulator.
209 Simulator::Destroy();
210} // end of void LtePrimaryCellChangeTestCase::DoRun ()
211
212void
214 uint64_t imsi,
215 uint16_t cellId,
216 uint16_t rnti,
217 LteUeRrc::State oldState,
218 LteUeRrc::State newState)
219{
220 NS_LOG_FUNCTION(this << imsi << cellId << rnti << oldState << newState);
221 m_lastState[imsi] = newState;
222}
223
224void
226 uint64_t imsi,
227 uint16_t cellId,
228 uint16_t rnti)
229{
230 NS_LOG_FUNCTION(this << imsi << cellId << rnti);
231}
Testing the handover procedure with multiple component carriers.
LtePrimaryCellChangeTestCase(std::string name, bool isIdealRrc, int64_t rngRun, uint8_t numberOfComponentCarriers, uint8_t sourceComponentCarrier, uint8_t targetComponentCarrier)
Creates an instance of the initial cell selection test case.
void StateTransitionCallback(std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti, LteUeRrc::State oldState, LteUeRrc::State newState)
State transition callback function.
uint8_t m_sourceComponentCarrier
source primary component carrier
void DoRun() override
Setup the simulation according to the configuration set by the class constructor, run it,...
void ConnectionEstablishedCallback(std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti)
Connection established callback function.
std::map< uint64_t, LteUeRrc::State > m_lastState
The current UE RRC state.
uint8_t m_targetComponentCarrier
target primary component carrier
bool m_isIdealRrc
whether the LTE is configured to use ideal RRC
uint8_t m_numberOfComponentCarriers
number of component carriers
Test suite for executing the primary cell change test cases.
AttributeValue implementation for Boolean.
Definition: boolean.h:37
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...
State
The states of the UE RRC entity.
Definition: lte-ue-rrc.h:102
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
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
AttributeValue implementation for TypeId.
Definition: type-id.h:600
Hold an unsigned integer type.
Definition: uinteger.h:45
void SetGlobal(std::string name, const AttributeValue &value)
Definition: config.cc:937
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_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_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
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
static LtePrimaryCellChangeTestSuite g_ltePrimaryCellChangeTestSuite
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
mobility
Definition: third.py:96