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
71
72/*
73 * Test Case
74 */
75
77 std::string name,
78 bool isIdealRrc,
79 uint64_t rngRun,
80 uint8_t numberOfComponentCarriers)
81 : TestCase(name),
82 m_isIdealRrc(isIdealRrc),
83 m_rngRun(rngRun),
84 m_numberOfComponentCarriers(numberOfComponentCarriers)
85{
86 NS_LOG_FUNCTION(this << GetName());
87}
88
90{
91 NS_LOG_FUNCTION(this << GetName());
92}
93
94void
96{
97 NS_LOG_FUNCTION(this << GetName());
98
100
101 // Create helpers.
102 auto lteHelper = CreateObject<LteHelper>();
103 lteHelper->SetAttribute("PathlossModel",
105 lteHelper->SetAttribute("UseIdealRrc", BooleanValue(m_isIdealRrc));
106 lteHelper->SetAttribute("NumberOfComponentCarriers",
108
109 auto epcHelper = CreateObject<PointToPointEpcHelper>();
110 lteHelper->SetEpcHelper(epcHelper);
111
112 // Create nodes.
113 auto enbNode = CreateObject<Node>();
114 NodeContainer ueNodes;
116
118 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
119 mobility.Install(enbNode);
120 mobility.Install(ueNodes);
121
122 // Physical layer.
123 auto enbDev = DynamicCast<LteEnbNetDevice>(lteHelper->InstallEnbDevice(enbNode).Get(0));
124 auto ueDevs = lteHelper->InstallUeDevice(ueNodes);
125
126 // Network layer.
127 InternetStackHelper internet;
128 internet.Install(ueNodes);
129 epcHelper->AssignUeIpv4Address(ueDevs);
130
131 auto ueDev = DynamicCast<LteUeNetDevice>(ueDevs.Get(0));
132 std::map<uint8_t, Ptr<ComponentCarrierUe>> ueCcMap = ueDev->GetCcMap();
133 for (auto it : ueCcMap)
134 {
135 NS_LOG_DEBUG("Assign DL EARFCN " << it.second->GetDlEarfcn() << " to UE "
136 << ueDevs.Get(it.first)->GetNode()->GetId());
137 DynamicCast<LteUeNetDevice>(ueDevs.Get(it.first))->SetDlEarfcn(it.second->GetDlEarfcn());
138 }
139
140 // Enable Idle mode cell selection.
141 lteHelper->Attach(ueDevs);
142
143 // Connect to trace sources in UEs
145 "/NodeList/*/DeviceList/*/LteUeRrc/StateTransition",
148 "/NodeList/*/DeviceList/*/LteUeRrc/ConnectionEstablished",
150
151 // Run simulation.
152 Simulator::Stop(Seconds(2.0));
153 Simulator::Run();
154
155 for (auto& it : enbDev->GetCcMap())
156 {
157 ueDev = DynamicCast<LteUeNetDevice>(ueDevs.Get(it.first));
158 uint16_t expectedCellId = it.second->GetCellId();
159 uint16_t actualCellId = ueDev->GetRrc()->GetCellId();
160 NS_LOG_DEBUG("RNTI " << ueDev->GetRrc()->GetRnti()
161 << " attached to cell ID: " << actualCellId);
162 NS_TEST_ASSERT_MSG_EQ(expectedCellId,
163 actualCellId,
164 "IMSI " << ueDev->GetImsi() << " has attached to an unexpected cell");
165
166 NS_TEST_ASSERT_MSG_EQ(m_lastState.at(ueDev->GetImsi()),
167 LteUeRrc::CONNECTED_NORMALLY,
168 "UE " << ueDev->GetImsi() << " is not at CONNECTED_NORMALLY state");
169 }
170
171 // Destroy simulator.
172 Simulator::Destroy();
173} // end of void LteSecondaryCellSelectionTestCase::DoRun ()
174
175void
177 uint64_t imsi,
178 uint16_t cellId,
179 uint16_t rnti,
180 LteUeRrc::State oldState,
181 LteUeRrc::State newState)
182{
183 NS_LOG_FUNCTION(this << imsi << cellId << rnti << LteUeRrc::ToString(oldState)
184 << LteUeRrc::ToString(newState));
185 m_lastState[imsi] = newState;
186}
187
188void
190 uint64_t imsi,
191 uint16_t cellId,
192 uint16_t rnti)
193{
194 NS_LOG_FUNCTION(this << imsi << cellId << rnti);
195}
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 ",...
#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 LteSecondaryCellSelectionTestSuite g_lteSecondaryCellSelectionTestSuite
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