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, 1, 2), TestCase::QUICK);
59  AddTestCase (new LteSecondaryCellSelectionTestCase ("EPC, real RRC, RngRun=1", false, 1, 4), TestCase::QUICK);
60 
61  // IDEAL RRC PROTOCOL
62 
63  AddTestCase (new LteSecondaryCellSelectionTestCase ("EPC, ideal RRC, RngRun=1", true, 1, 2), TestCase::QUICK);
64  AddTestCase (new LteSecondaryCellSelectionTestCase ("EPC, ideal RRC, RngRun=1", true, 1, 4), TestCase::QUICK);
65 
66 } // end of LteSecondaryCellSelectionTestSuite::LteSecondaryCellSelectionTestSuite ()
67 
69 
70 /*
71  * Test Case
72  */
73 
75  std::string name, bool isIdealRrc, int64_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  auto cch = CreateObject<CcHelper> ();
107  cch->SetUlEarfcn (100 + 18000);
108  cch->SetDlEarfcn (100);
109  cch->SetUlBandwidth (25);
110  cch->SetDlBandwidth (25);
111  cch->SetNumberOfComponentCarriers (m_numberOfComponentCarriers);
112 
113  const auto ccm = cch->EquallySpacedCcs ();
114  lteHelper->SetCcPhyParams (ccm);
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  for (auto &it: ccm)
136  {
137  std::cerr << "Assign " << it.second.GetDlEarfcn () << std::endl;
138  DynamicCast<LteUeNetDevice> (ueDevs.Get (it.first))->SetDlEarfcn (it.second.GetDlEarfcn ());
139  }
140 
141  // Enable Idle mode cell selection.
142  lteHelper->Attach (ueDevs);
143 
144  // Connect to trace sources in UEs
145  Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/StateTransition",
147  this));
148  Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/InitialSecondaryCellSelectionEndOk",
150  this));
151  Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/ConnectionEstablished",
153  this));
154 
155  // Run simulation.
156  Simulator::Stop (Seconds (2.0));
157  Simulator::Run ();
158 
159  for (auto &it: enbDev->GetCcMap ())
160  {
161  auto ueDev = DynamicCast<LteUeNetDevice> (ueDevs.Get (it.first));
162  uint16_t expectedCellId = it.second->GetCellId ();
163  uint16_t actualCellId = ueDev->GetRrc ()->GetCellId ();
164  NS_TEST_ASSERT_MSG_EQ (expectedCellId, actualCellId, "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 ()
169  << " is not at CONNECTED_NORMALLY state");
170  }
171 
172  // Destroy simulator.
173  Simulator::Destroy ();
174 } // end of void LteSecondaryCellSelectionTestCase::DoRun ()
175 
176 
177 void
179  std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti,
180  LteUeRrc::State oldState, LteUeRrc::State newState)
181 {
182  NS_LOG_FUNCTION (this << imsi << cellId << rnti << oldState << newState);
183  m_lastState[imsi] = newState;
184 }
185 
186 
187 void
189  std::string context, uint64_t imsi, uint16_t cellId)
190 {
191  NS_LOG_FUNCTION (this << imsi << cellId);
192 }
193 
194 void
196  std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti)
197 {
198  NS_LOG_FUNCTION (this << imsi << cellId << rnti);
199 }
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
Hold a signed integer type.
Definition: integer.h:44
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
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.
Testing the initial cell selection procedure by UE at IDLE state in the beginning of simulation with ...
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
tuple mobility
Definition: third.py:101
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
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:843
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
void SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
LteSecondaryCellSelectionTestCase(std::string name, bool isIdealRrc, int64_t rngRun, uint8_t numberOfComponentCarriers)
Creates an instance of the initial cell selection test case.
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:103
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.
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:822
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:993
std::string GetName(void) const
Definition: test.cc:370
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.