A Discrete-Event Network Simulator
API
lte-test-secondary-cell-selection.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("LteSecondaryCellSelectionTest");
46
47/*
48 * Test Suite
49 */
50
52 : TestSuite("lte-secondary-cell-selection", SYSTEM)
53{
54 // REAL RRC PROTOCOL, either 2 or 4 UEs connecting to 2 or 4 component carriers
55
56 AddTestCase(new LteSecondaryCellSelectionTestCase("EPC, real RRC, RngRun=1", false, 1U, 2),
57 TestCase::QUICK);
58 AddTestCase(new LteSecondaryCellSelectionTestCase("EPC, real RRC, RngRun=1", false, 1U, 4),
59 TestCase::QUICK);
60
61 // IDEAL RRC PROTOCOL, either 2 or 4 UEs connecting to 2 or 4 component carriers
62
63 AddTestCase(new LteSecondaryCellSelectionTestCase("EPC, ideal RRC, RngRun=1", true, 1U, 2),
64 TestCase::QUICK);
65 AddTestCase(new LteSecondaryCellSelectionTestCase("EPC, ideal RRC, RngRun=1", true, 1U, 4),
66 TestCase::QUICK);
67
68} // end of LteSecondaryCellSelectionTestSuite::LteSecondaryCellSelectionTestSuite ()
69
75
76/*
77 * Test Case
78 */
79
81 std::string name,
82 bool isIdealRrc,
83 uint64_t rngRun,
84 uint8_t numberOfComponentCarriers)
85 : TestCase(name),
86 m_isIdealRrc(isIdealRrc),
87 m_rngRun(rngRun),
88 m_numberOfComponentCarriers(numberOfComponentCarriers)
89{
90 NS_LOG_FUNCTION(this << GetName());
91}
92
94{
95 NS_LOG_FUNCTION(this << GetName());
96}
97
98void
100{
101 NS_LOG_FUNCTION(this << GetName());
102
104
105 // Create helpers.
106 auto lteHelper = CreateObject<LteHelper>();
107 lteHelper->SetAttribute("PathlossModel",
109 lteHelper->SetAttribute("UseIdealRrc", BooleanValue(m_isIdealRrc));
110 lteHelper->SetAttribute("NumberOfComponentCarriers",
112
113 auto epcHelper = CreateObject<PointToPointEpcHelper>();
114 lteHelper->SetEpcHelper(epcHelper);
115
116 // Create nodes.
117 auto enbNode = CreateObject<Node>();
118 NodeContainer ueNodes;
120
122 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
123 mobility.Install(enbNode);
124 mobility.Install(ueNodes);
125
126 // Physical layer.
127 auto enbDev = DynamicCast<LteEnbNetDevice>(lteHelper->InstallEnbDevice(enbNode).Get(0));
128 auto ueDevs = lteHelper->InstallUeDevice(ueNodes);
129
130 // Network layer.
131 InternetStackHelper internet;
132 internet.Install(ueNodes);
133 epcHelper->AssignUeIpv4Address(ueDevs);
134
135 auto ueDev = DynamicCast<LteUeNetDevice>(ueDevs.Get(0));
136 std::map<uint8_t, Ptr<ComponentCarrierUe>> ueCcMap = ueDev->GetCcMap();
137 for (auto it : ueCcMap)
138 {
139 NS_LOG_DEBUG("Assign DL EARFCN " << it.second->GetDlEarfcn() << " to UE "
140 << ueDevs.Get(it.first)->GetNode()->GetId());
141 DynamicCast<LteUeNetDevice>(ueDevs.Get(it.first))->SetDlEarfcn(it.second->GetDlEarfcn());
142 }
143
144 // Enable Idle mode cell selection.
145 lteHelper->Attach(ueDevs);
146
147 // Connect to trace sources in UEs
149 "/NodeList/*/DeviceList/*/LteUeRrc/StateTransition",
152 "/NodeList/*/DeviceList/*/LteUeRrc/ConnectionEstablished",
154
155 // Run simulation.
156 Simulator::Stop(Seconds(2.0));
157 Simulator::Run();
158
159 for (auto& it : enbDev->GetCcMap())
160 {
161 ueDev = DynamicCast<LteUeNetDevice>(ueDevs.Get(it.first));
162 uint16_t expectedCellId = it.second->GetCellId();
163 uint16_t actualCellId = ueDev->GetRrc()->GetCellId();
164 NS_LOG_DEBUG("RNTI " << ueDev->GetRrc()->GetRnti()
165 << " attached to cell ID: " << actualCellId);
166 NS_TEST_ASSERT_MSG_EQ(expectedCellId,
167 actualCellId,
168 "IMSI " << ueDev->GetImsi() << " has attached to an unexpected cell");
169
170 NS_TEST_ASSERT_MSG_EQ(m_lastState.at(ueDev->GetImsi()),
171 LteUeRrc::CONNECTED_NORMALLY,
172 "UE " << ueDev->GetImsi() << " is not at CONNECTED_NORMALLY state");
173 }
174
175 // Destroy simulator.
176 Simulator::Destroy();
177} // end of void LteSecondaryCellSelectionTestCase::DoRun ()
178
179void
181 uint64_t imsi,
182 uint16_t cellId,
183 uint16_t rnti,
184 LteUeRrc::State oldState,
185 LteUeRrc::State newState)
186{
187 NS_LOG_FUNCTION(this << imsi << cellId << rnti << LteUeRrc::ToString(oldState)
188 << LteUeRrc::ToString(newState));
189 m_lastState[imsi] = newState;
190}
191
192void
194 uint64_t imsi,
195 uint16_t cellId,
196 uint16_t rnti)
197{
198 NS_LOG_FUNCTION(this << imsi << cellId << rnti);
199}
Testing the initial cell selection procedure by UE at IDLE state in the beginning of simulation with ...
void StateTransitionCallback(std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti, LteUeRrc::State oldState, LteUeRrc::State newState)
State transition callback function.
bool m_isIdealRrc
whether the LTE is configured to use ideal RRC
uint8_t m_numberOfComponentCarriers
number of component carriers
std::map< uint64_t, LteUeRrc::State > m_lastState
The current UE RRC state.
void ConnectionEstablishedCallback(std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti)
Connection established callback function.
LteSecondaryCellSelectionTestCase(std::string name, bool isIdealRrc, uint64_t rngRun, uint8_t numberOfComponentCarriers)
Creates an instance of the initial cell selection test case.
void DoRun() override
Setup the simulation according to the configuration set by the class constructor, run it,...
Test suite for executing the secondary cell selection 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.
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 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_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
static LteSecondaryCellSelectionTestSuite g_lteSecondaryCellSelectionTestSuite
Static variable for test initialization.
#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:1336
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