A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lte-test-primary-cell-change.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
11
12#include <ns3/boolean.h>
13#include <ns3/double.h>
14#include <ns3/friis-spectrum-propagation-loss.h>
15#include <ns3/integer.h>
16#include <ns3/internet-stack-helper.h>
17#include <ns3/ipv4-address-helper.h>
18#include <ns3/ipv4-interface-container.h>
19#include <ns3/ipv4-static-routing-helper.h>
20#include <ns3/log.h>
21#include <ns3/lte-enb-net-device.h>
22#include <ns3/lte-helper.h>
23#include <ns3/lte-ue-net-device.h>
24#include <ns3/lte-ue-rrc.h>
25#include <ns3/mobility-helper.h>
26#include <ns3/net-device-container.h>
27#include <ns3/node-container.h>
28#include <ns3/point-to-point-epc-helper.h>
29#include <ns3/point-to-point-helper.h>
30#include <ns3/simulator.h>
31
32using namespace ns3;
33
34NS_LOG_COMPONENT_DEFINE("LtePrimaryCellChangeTest");
35
36/*
37 * Test Suite
38 */
39
41 : TestSuite("lte-primary-cell-change", Type::SYSTEM)
42{
43 // Test that handover from eNB to eNB with one carrier works within this framework.
44 AddTestCase(new LtePrimaryCellChangeTestCase("ideal RRC, RngRun=1", true, 1, 1, 0, 1),
45 TestCase::Duration::QUICK);
46 AddTestCase(new LtePrimaryCellChangeTestCase("real RRC, RngRun=1", false, 1, 1, 0, 1),
47 TestCase::Duration::QUICK);
48
49 // Test that handover between first carriers of eNBs works.
50 AddTestCase(new LtePrimaryCellChangeTestCase("ideal RRC, RngRun=1", true, 1, 2, 0, 2),
51 TestCase::Duration::QUICK);
52 AddTestCase(new LtePrimaryCellChangeTestCase("real RRC, RngRun=1", false, 1, 2, 0, 2),
53 TestCase::Duration::QUICK);
54
55 // Test that handover from second carrier of first eNB to first carrier of second eNB works.
56 AddTestCase(new LtePrimaryCellChangeTestCase("ideal RRC, RngRun=1", true, 1, 2, 1, 2),
57 TestCase::Duration::QUICK);
58 AddTestCase(new LtePrimaryCellChangeTestCase("real RRC, RngRun=1", false, 1, 2, 1, 2),
59 TestCase::Duration::QUICK);
60
61 // Test that handover from first carrier of first eNB to first carrier of second eNB works.
62 AddTestCase(new LtePrimaryCellChangeTestCase("ideal RRC, RngRun=1", true, 1, 2, 0, 3),
63 TestCase::Duration::QUICK);
64 AddTestCase(new LtePrimaryCellChangeTestCase("real RRC, RngRun=1", false, 1, 2, 0, 3),
65 TestCase::Duration::QUICK);
66
67 // Test that handover from second carrier of first eNB to second carrier of second eNB works.
68 AddTestCase(new LtePrimaryCellChangeTestCase("ideal RRC, RngRun=1", true, 1, 2, 1, 3),
69 TestCase::Duration::QUICK);
70 AddTestCase(new LtePrimaryCellChangeTestCase("real RRC, RngRun=1", false, 1, 2, 1, 3),
71 TestCase::Duration::QUICK);
72
73 // Test intra-eNB inter-frequency handover.
74 AddTestCase(new LtePrimaryCellChangeTestCase("ideal RRC, RngRun=1", true, 1, 2, 0, 1),
75 TestCase::Duration::QUICK);
76 AddTestCase(new LtePrimaryCellChangeTestCase("real RRC, RngRun=1", false, 1, 2, 0, 1),
77 TestCase::Duration::QUICK);
78 AddTestCase(new LtePrimaryCellChangeTestCase("ideal RRC, RngRun=1", true, 1, 2, 1, 0),
79 TestCase::Duration::QUICK);
80 AddTestCase(new LtePrimaryCellChangeTestCase("real RRC, RngRun=1", false, 1, 2, 1, 0),
81 TestCase::Duration::QUICK);
82 AddTestCase(new LtePrimaryCellChangeTestCase("ideal RRC, RngRun=1", true, 1, 4, 3, 1),
83 TestCase::Duration::QUICK);
84 AddTestCase(new LtePrimaryCellChangeTestCase("real RRC, RngRun=1", false, 1, 4, 3, 1),
85 TestCase::Duration::QUICK);
86} // end of LtePrimaryCellChangeTestSuite::LtePrimaryCellChangeTestSuite ()
87
88/**
89 * @ingroup lte-test
90 * Static variable for test initialization
91 */
93
94/*
95 * Test Case
96 */
97
99 bool isIdealRrc,
100 int64_t rngRun,
101 uint8_t numberOfComponentCarriers,
102 uint8_t sourceComponentCarrier,
103 uint8_t targetComponentCarrier)
104 : TestCase(name),
105 m_isIdealRrc{isIdealRrc},
106 m_rngRun{rngRun},
107 m_numberOfComponentCarriers{numberOfComponentCarriers},
108 m_sourceComponentCarrier{sourceComponentCarrier},
109 m_targetComponentCarrier{targetComponentCarrier}
110{
111 NS_LOG_FUNCTION(this << GetName());
112}
113
118
119void
121{
122 NS_LOG_FUNCTION(this << GetName());
123
125
126 Config::SetDefault("ns3::LteEnbNetDevice::DlEarfcn", UintegerValue(100));
127 Config::SetDefault("ns3::LteEnbNetDevice::UlEarfcn", UintegerValue(100 + 18000));
128 Config::SetDefault("ns3::LteEnbNetDevice::DlBandwidth", UintegerValue(25));
129 Config::SetDefault("ns3::LteEnbNetDevice::UlBandwidth", UintegerValue(25));
130 Config::SetDefault("ns3::LteUeNetDevice::DlEarfcn", UintegerValue(100));
131
132 // Create helpers.
133 auto lteHelper = CreateObject<LteHelper>();
134 lteHelper->SetAttribute("PathlossModel",
136 lteHelper->SetAttribute("UseIdealRrc", BooleanValue(m_isIdealRrc));
137 lteHelper->SetAttribute("NumberOfComponentCarriers",
139
140 auto epcHelper = CreateObject<PointToPointEpcHelper>();
141 lteHelper->SetEpcHelper(epcHelper);
142
143 // Create nodes.
144 NodeContainer enbNodes;
145 enbNodes.Create(2);
146 auto ueNode = CreateObject<Node>();
147
148 MobilityHelper mobility;
149 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
150 mobility.Install(enbNodes);
151 mobility.Install(ueNode);
152
153 // Physical layer.
154 auto enbDevs = lteHelper->InstallEnbDevice(enbNodes);
155 auto ueDev = DynamicCast<LteUeNetDevice>(lteHelper->InstallUeDevice(ueNode).Get(0));
156
157 auto sourceEnbDev = DynamicCast<LteEnbNetDevice>(
159 auto targetEnbDev = DynamicCast<LteEnbNetDevice>(
161
162 // Network layer.
163 InternetStackHelper internet;
164 internet.Install(ueNode);
165 epcHelper->AssignUeIpv4Address(NetDeviceContainer(ueDev));
166
167 std::map<uint8_t, Ptr<ComponentCarrierUe>> ueCcMap = ueDev->GetCcMap();
168 ueDev->SetDlEarfcn(ueCcMap.at(m_sourceComponentCarrier)->GetDlEarfcn());
169
170 // Attach UE to specified component carrier
171 lteHelper->Attach(ueDev, sourceEnbDev, m_sourceComponentCarrier % m_numberOfComponentCarriers);
172
173 // Connect to trace sources in UEs
174 Config::Connect("/NodeList/*/DeviceList/*/LteUeRrc/StateTransition",
177 "/NodeList/*/DeviceList/*/LteUeRrc/ConnectionEstablished",
179
180 uint16_t targetCellId = targetEnbDev->GetCcMap()
182 ->GetCellId();
183
184 lteHelper->AddX2Interface(enbNodes);
185 lteHelper->HandoverRequest(Seconds(1), ueDev, sourceEnbDev, targetCellId);
186
187 // Run simulation.
190
191 uint16_t expectedCellId = targetCellId;
192 uint16_t actualCellId = ueDev->GetRrc()->GetCellId();
193 NS_TEST_ASSERT_MSG_EQ(expectedCellId,
194 actualCellId,
195 "IMSI " << ueDev->GetImsi() << " has attached to an unexpected cell");
196
197 NS_TEST_ASSERT_MSG_EQ(m_lastState.at(ueDev->GetImsi()),
199 "UE " << ueDev->GetImsi() << " is not at CONNECTED_NORMALLY state");
200
201 // Destroy simulator.
203} // end of void LtePrimaryCellChangeTestCase::DoRun ()
204
205void
207 uint64_t imsi,
208 uint16_t cellId,
209 uint16_t rnti,
210 LteUeRrc::State oldState,
211 LteUeRrc::State newState)
212{
213 NS_LOG_FUNCTION(this << imsi << cellId << rnti << oldState << newState);
214 m_lastState[imsi] = newState;
215}
216
217void
219 uint64_t imsi,
220 uint16_t cellId,
221 uint16_t rnti)
222{
223 NS_LOG_FUNCTION(this << imsi << cellId << rnti);
224}
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:26
aggregate IP/TCP/UDP functionality to existing Nodes.
State
The states of the UE RRC entity.
Definition lte-ue-rrc.h:89
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.
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
AttributeValue implementation for TypeId.
Definition type-id.h:617
Hold an unsigned integer type.
Definition uinteger.h:34
void SetGlobal(std::string name, const AttributeValue &value)
Definition config.cc:929
void SetDefault(std::string name, const AttributeValue &value)
Definition config.cc:883
void Connect(std::string path, const CallbackBase &cb)
Definition config.cc:967
#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 LtePrimaryCellChangeTestSuite g_ltePrimaryCellChangeTestSuite
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:1344
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