A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lte-test-secondary-cell-selection.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("LteSecondaryCellSelectionTest");
35
36/*
37 * Test Suite
38 */
39
41 : TestSuite("lte-secondary-cell-selection", Type::SYSTEM)
42{
43 // REAL RRC PROTOCOL, either 2 or 4 UEs connecting to 2 or 4 component carriers
44
45 AddTestCase(new LteSecondaryCellSelectionTestCase("EPC, real RRC, RngRun=1", false, 1U, 2),
46 TestCase::Duration::QUICK);
47 AddTestCase(new LteSecondaryCellSelectionTestCase("EPC, real RRC, RngRun=1", false, 1U, 4),
48 TestCase::Duration::QUICK);
49
50 // IDEAL RRC PROTOCOL, either 2 or 4 UEs connecting to 2 or 4 component carriers
51
52 AddTestCase(new LteSecondaryCellSelectionTestCase("EPC, ideal RRC, RngRun=1", true, 1U, 2),
53 TestCase::Duration::QUICK);
54 AddTestCase(new LteSecondaryCellSelectionTestCase("EPC, ideal RRC, RngRun=1", true, 1U, 4),
55 TestCase::Duration::QUICK);
56
57} // end of LteSecondaryCellSelectionTestSuite::LteSecondaryCellSelectionTestSuite ()
58
59/**
60 * @ingroup lte-test
61 * Static variable for test initialization
62 */
64
65/*
66 * Test Case
67 */
68
70 std::string name,
71 bool isIdealRrc,
72 uint64_t rngRun,
73 uint8_t numberOfComponentCarriers)
74 : TestCase(name),
75 m_isIdealRrc(isIdealRrc),
76 m_rngRun(rngRun),
77 m_numberOfComponentCarriers(numberOfComponentCarriers)
78{
79 NS_LOG_FUNCTION(this << GetName());
80}
81
86
87void
89{
90 NS_LOG_FUNCTION(this << GetName());
91
93
94 // Create helpers.
95 auto lteHelper = CreateObject<LteHelper>();
96 lteHelper->SetAttribute("PathlossModel",
98 lteHelper->SetAttribute("UseIdealRrc", BooleanValue(m_isIdealRrc));
99 lteHelper->SetAttribute("NumberOfComponentCarriers",
101
102 auto epcHelper = CreateObject<PointToPointEpcHelper>();
103 lteHelper->SetEpcHelper(epcHelper);
104
105 // Create nodes.
106 auto enbNode = CreateObject<Node>();
107 NodeContainer ueNodes;
109
110 MobilityHelper mobility;
111 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
112 mobility.Install(enbNode);
113 mobility.Install(ueNodes);
114
115 // Physical layer.
116 auto enbDev = DynamicCast<LteEnbNetDevice>(lteHelper->InstallEnbDevice(enbNode).Get(0));
117 auto ueDevs = lteHelper->InstallUeDevice(ueNodes);
118
119 // Network layer.
120 InternetStackHelper internet;
121 internet.Install(ueNodes);
122 epcHelper->AssignUeIpv4Address(ueDevs);
123
124 auto ueDev = DynamicCast<LteUeNetDevice>(ueDevs.Get(0));
125 std::map<uint8_t, Ptr<ComponentCarrierUe>> ueCcMap = ueDev->GetCcMap();
126 for (auto it : ueCcMap)
127 {
128 NS_LOG_DEBUG("Assign DL EARFCN " << it.second->GetDlEarfcn() << " to UE "
129 << ueDevs.Get(it.first)->GetNode()->GetId());
130 DynamicCast<LteUeNetDevice>(ueDevs.Get(it.first))->SetDlEarfcn(it.second->GetDlEarfcn());
131 }
132
133 // Enable Idle mode cell selection.
134 lteHelper->Attach(ueDevs);
135
136 // Connect to trace sources in UEs
138 "/NodeList/*/DeviceList/*/LteUeRrc/StateTransition",
141 "/NodeList/*/DeviceList/*/LteUeRrc/ConnectionEstablished",
143
144 // Run simulation.
147
148 for (auto& it : enbDev->GetCcMap())
149 {
150 ueDev = DynamicCast<LteUeNetDevice>(ueDevs.Get(it.first));
151 uint16_t expectedCellId = it.second->GetCellId();
152 uint16_t actualCellId = ueDev->GetRrc()->GetCellId();
153 NS_LOG_DEBUG("RNTI " << ueDev->GetRrc()->GetRnti()
154 << " attached to cell ID: " << actualCellId);
155 NS_TEST_ASSERT_MSG_EQ(expectedCellId,
156 actualCellId,
157 "IMSI " << ueDev->GetImsi() << " has attached to an unexpected cell");
158
159 NS_TEST_ASSERT_MSG_EQ(m_lastState.at(ueDev->GetImsi()),
161 "UE " << ueDev->GetImsi() << " is not at CONNECTED_NORMALLY state");
162 }
163
164 // Destroy simulator.
166} // end of void LteSecondaryCellSelectionTestCase::DoRun ()
167
168void
170 uint64_t imsi,
171 uint16_t cellId,
172 uint16_t rnti,
173 LteUeRrc::State oldState,
174 LteUeRrc::State newState)
175{
176 NS_LOG_FUNCTION(this << imsi << cellId << rnti << oldState << newState);
177 m_lastState[imsi] = newState;
178}
179
180void
182 uint64_t imsi,
183 uint16_t cellId,
184 uint16_t rnti)
185{
186 NS_LOG_FUNCTION(this << imsi << cellId << rnti);
187}
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: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.
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 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_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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.
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