A Discrete-Event Network Simulator
API
lte-test-secondary-cell-selection.cc
Go to the documentation of this file.
1/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2017 Alexander Krotov
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Alexander Krotov <krotov@iitp.ru>
19 *
20 */
21
23
24#include <ns3/boolean.h>
25#include <ns3/double.h>
26#include <ns3/integer.h>
27#include <ns3/log.h>
28#include <ns3/simulator.h>
29
30#include <ns3/internet-stack-helper.h>
31#include <ns3/ipv4-address-helper.h>
32#include <ns3/ipv4-interface-container.h>
33#include <ns3/friis-spectrum-propagation-loss.h>
34#include <ns3/ipv4-static-routing-helper.h>
35#include <ns3/lte-enb-net-device.h>
36#include <ns3/lte-helper.h>
37#include <ns3/lte-ue-net-device.h>
38#include <ns3/lte-ue-rrc.h>
39#include <ns3/mobility-helper.h>
40#include <ns3/net-device-container.h>
41#include <ns3/node-container.h>
42#include <ns3/point-to-point-epc-helper.h>
43#include <ns3/point-to-point-helper.h>
44
45using namespace ns3;
46
47NS_LOG_COMPONENT_DEFINE ("LteSecondaryCellSelectionTest");
48
49/*
50 * Test Suite
51 */
52
54 : TestSuite ("lte-secondary-cell-selection", SYSTEM)
55{
56 // REAL RRC PROTOCOL, either 2 or 4 UEs connecting to 2 or 4 component carriers
57
58 AddTestCase (new LteSecondaryCellSelectionTestCase ("EPC, real RRC, RngRun=1", false, 1U, 2), TestCase::QUICK);
59 AddTestCase (new LteSecondaryCellSelectionTestCase ("EPC, real RRC, RngRun=1", false, 1U, 4), 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), TestCase::QUICK);
64 AddTestCase (new LteSecondaryCellSelectionTestCase ("EPC, ideal RRC, RngRun=1", true, 1U, 4), TestCase::QUICK);
65
66} // end of LteSecondaryCellSelectionTestSuite::LteSecondaryCellSelectionTestSuite ()
67
69
70/*
71 * Test Case
72 */
73
75 std::string name, bool isIdealRrc, uint64_t rngRun, uint8_t numberOfComponentCarriers)
76 : TestCase (name),
77 m_isIdealRrc (isIdealRrc),
78 m_rngRun (rngRun),
79 m_numberOfComponentCarriers (numberOfComponentCarriers)
80{
81 NS_LOG_FUNCTION (this << GetName ());
82}
83
84
86{
87 NS_LOG_FUNCTION (this << GetName ());
88}
89
90void
92{
93 NS_LOG_FUNCTION (this << GetName ());
94
96
97 // Create helpers.
98 auto lteHelper = CreateObject<LteHelper> ();
99 lteHelper->SetAttribute ("PathlossModel", TypeIdValue (ns3::FriisSpectrumPropagationLossModel::GetTypeId ()));
100 lteHelper->SetAttribute ("UseIdealRrc", BooleanValue (m_isIdealRrc));
101 lteHelper->SetAttribute ("NumberOfComponentCarriers", UintegerValue (m_numberOfComponentCarriers));
102
103 auto epcHelper = CreateObject<PointToPointEpcHelper> ();
104 lteHelper->SetEpcHelper (epcHelper);
105
106 // Create nodes.
107 auto enbNode = CreateObject<Node> ();
108 NodeContainer ueNodes;
110
112 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
113 mobility.Install (enbNode);
114 mobility.Install (ueNodes);
115
116 // Physical layer.
117 auto enbDev = DynamicCast<LteEnbNetDevice> (lteHelper->InstallEnbDevice (enbNode).Get (0));
118 auto ueDevs = lteHelper->InstallUeDevice (ueNodes);
119
120 // Network layer.
121 InternetStackHelper internet;
122 internet.Install (ueNodes);
123 epcHelper->AssignUeIpv4Address (ueDevs);
124
125 auto ueDev = DynamicCast<LteUeNetDevice> (ueDevs.Get (0));
126 std::map< uint8_t, Ptr<ComponentCarrierUe> > ueCcMap = ueDev->GetCcMap ();
127 for (auto it: ueCcMap)
128 {
129 NS_LOG_DEBUG ("Assign DL EARFCN " << it.second->GetDlEarfcn() << " to UE " << 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
137 Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/StateTransition",
139 this));
140 Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/ConnectionEstablished",
142 this));
143
144 // Run simulation.
145 Simulator::Stop (Seconds (2.0));
146 Simulator::Run ();
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 () << " attached to cell ID: " << actualCellId);
154 NS_TEST_ASSERT_MSG_EQ (expectedCellId, actualCellId, "IMSI " << ueDev->GetImsi () << " has attached to an unexpected cell");
155
156 NS_TEST_ASSERT_MSG_EQ (m_lastState.at (ueDev->GetImsi ()),
157 LteUeRrc::CONNECTED_NORMALLY,
158 "UE " << ueDev->GetImsi ()
159 << " is not at CONNECTED_NORMALLY state");
160 }
161
162 // Destroy simulator.
163 Simulator::Destroy ();
164} // end of void LteSecondaryCellSelectionTestCase::DoRun ()
165
166
167void
169 std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti,
170 LteUeRrc::State oldState, LteUeRrc::State newState)
171{
172 NS_LOG_FUNCTION (this << imsi << cellId << rnti << LteUeRrc::ToString (oldState) << LteUeRrc::ToString (newState));
173 m_lastState[imsi] = newState;
174}
175
176
177void
179 std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti)
180{
181 NS_LOG_FUNCTION (this << imsi << cellId << rnti);
182}
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.
virtual void DoRun()
Setup the simulation according to the configuration set by the class constructor, run it,...
LteSecondaryCellSelectionTestCase(std::string name, bool isIdealRrc, uint64_t rngRun, uint8_t numberOfComponentCarriers)
Creates an instance of the initial cell selection test case.
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:106
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:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
std::string GetName(void) const
Definition: test.cc:370
A suite of tests to run.
Definition: test.h:1188
AttributeValue implementation for TypeId.
Definition: type-id.h:595
Hold an unsigned integer type.
Definition: uinteger.h:44
void SetGlobal(std::string name, const AttributeValue &value)
Definition: config.cc:891
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:920
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#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:141
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
static LteSecondaryCellSelectionTestSuite g_lteSecondaryCellSelectionTestSuite
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1648
mobility
Definition: third.py:107