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 
45 using namespace ns3;
46 
47 NS_LOG_COMPONENT_DEFINE ("LteSecondaryCellSelectionTest");
48 
49 /*
50  * Test Suite
51  */
52 
54  : TestSuite ("lte-secondary-cell-selection", SYSTEM)
55 {
56  // REAL RRC PROTOCOL
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
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 
90 void
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  std::cerr << "Assign " << it.second->GetDlEarfcn() << std::endl;
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/InitialSecondaryCellSelectionEndOk",
142  this));
143  Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/ConnectionEstablished",
145  this));
146 
147  // Run simulation.
148  Simulator::Stop (Seconds (2.0));
149  Simulator::Run ();
150 
151  for (auto &it: enbDev->GetCcMap ())
152  {
153  ueDev = DynamicCast<LteUeNetDevice> (ueDevs.Get (it.first));
154  uint16_t expectedCellId = it.second->GetCellId ();
155  uint16_t actualCellId = ueDev->GetRrc ()->GetCellId ();
156  NS_TEST_ASSERT_MSG_EQ (expectedCellId, actualCellId, "IMSI " << ueDev->GetImsi () << " has attached to an unexpected cell");
157 
158  NS_TEST_ASSERT_MSG_EQ (m_lastState.at (ueDev->GetImsi ()),
159  LteUeRrc::CONNECTED_NORMALLY,
160  "UE " << ueDev->GetImsi ()
161  << " is not at CONNECTED_NORMALLY state");
162  }
163 
164  // Destroy simulator.
165  Simulator::Destroy ();
166 } // end of void LteSecondaryCellSelectionTestCase::DoRun ()
167 
168 
169 void
171  std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti,
172  LteUeRrc::State oldState, LteUeRrc::State newState)
173 {
174  NS_LOG_FUNCTION (this << imsi << cellId << rnti << oldState << newState);
175  m_lastState[imsi] = newState;
176 }
177 
178 
179 void
181  std::string context, uint64_t imsi, uint16_t cellId)
182 {
183  NS_LOG_FUNCTION (this << imsi << cellId);
184 }
185 
186 void
188  std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti)
189 {
190  NS_LOG_FUNCTION (this << imsi << cellId << rnti);
191 }
Test suite for executing the secondary cell selection test cases.
uint8_t m_numberOfComponentCarriers
number of component carriers
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
AttributeValue implementation for Boolean.
Definition: boolean.h:36
std::map< uint64_t, LteUeRrc::State > m_lastState
The current UE RRC state.
A suite of tests to run.
Definition: test.h:1342
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
aggregate IP/TCP/UDP functionality to existing Nodes.
encapsulates test code
Definition: test.h:1155
void StateTransitionCallback(std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti, LteUeRrc::State oldState, LteUeRrc::State newState)
State transition callback function.
mobility
Definition: third.py:101
Testing the initial cell selection procedure by UE at IDLE state in the beginning of simulation with ...
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
Hold an unsigned integer type.
Definition: uinteger.h:44
#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:168
LteSecondaryCellSelectionTestCase(std::string name, bool isIdealRrc, uint64_t rngRun, uint8_t numberOfComponentCarriers)
Creates an instance of the initial cell selection test case.
AttributeValue implementation for TypeId.
Definition: type-id.h:608
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
bool m_isIdealRrc
whether the LTE is configured to use ideal RRC
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:871
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
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:105
Helper class used to assign positions and mobility models to nodes.
void ConnectionEstablishedCallback(std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti)
Connection established callback function.
std::string GetName(void) const
Definition: test.cc:370
virtual void DoRun()
Setup the simulation according to the configuration set by the class constructor, run it...
void SetGlobal(std::string name, const AttributeValue &value)
Definition: config.cc:850
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1062
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
static LteSecondaryCellSelectionTestSuite g_lteSecondaryCellSelectionTestSuite
void InitialSecondaryCellSelectionEndOkCallback(std::string context, uint64_t imsi, uint16_t cellId)
Initial cell selection end ok callback function.