A Discrete-Event Network Simulator
API
lte-test-primary-cell-change.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 ("LtePrimaryCellChangeTest");
48 
49 /*
50  * Test Suite
51  */
52 
54  : TestSuite ("lte-primary-cell-change", SYSTEM)
55 {
56  // Test that handover from eNB to eNB with one carrier works within this framework.
57  AddTestCase (new LtePrimaryCellChangeTestCase ("ideal RRC, RngRun=1", true, 1, 1, 0, 1), TestCase::QUICK);
58  AddTestCase (new LtePrimaryCellChangeTestCase ("real RRC, RngRun=1", false, 1, 1, 0, 1), TestCase::QUICK);
59 
60  // Test that handover between first carriers of eNBs works.
61  AddTestCase (new LtePrimaryCellChangeTestCase ("ideal RRC, RngRun=1", true, 1, 2, 0, 2), TestCase::QUICK);
62  AddTestCase (new LtePrimaryCellChangeTestCase ("real RRC, RngRun=1", false, 1, 2, 0, 2), TestCase::QUICK);
63 
64  // Test that handover from second carrier of first eNB to first carrier of second eNB works.
65  AddTestCase (new LtePrimaryCellChangeTestCase ("ideal RRC, RngRun=1", true, 1, 2, 1, 2), TestCase::QUICK);
66  AddTestCase (new LtePrimaryCellChangeTestCase ("real RRC, RngRun=1", false, 1, 2, 1, 2), TestCase::QUICK);
67 
68  // Test that handover from first carrier of first eNB to first carrier of second eNB works.
69  AddTestCase (new LtePrimaryCellChangeTestCase ("ideal RRC, RngRun=1", true, 1, 2, 0, 3), TestCase::QUICK);
70  AddTestCase (new LtePrimaryCellChangeTestCase ("real RRC, RngRun=1", false, 1, 2, 0, 3), TestCase::QUICK);
71 
72  // Test that handover from second carrier of first eNB to second carrier of second eNB works.
73  AddTestCase (new LtePrimaryCellChangeTestCase ("ideal RRC, RngRun=1", true, 1, 2, 1, 3), TestCase::QUICK);
74  AddTestCase (new LtePrimaryCellChangeTestCase ("real RRC, RngRun=1", false, 1, 2, 1, 3), TestCase::QUICK);
75 
76  // Test intra-eNB inter-frequency handover.
77  AddTestCase (new LtePrimaryCellChangeTestCase ("ideal RRC, RngRun=1", true, 1, 2, 0, 1), TestCase::QUICK);
78  AddTestCase (new LtePrimaryCellChangeTestCase ("real RRC, RngRun=1", false, 1, 2, 0, 1), TestCase::QUICK);
79  AddTestCase (new LtePrimaryCellChangeTestCase ("ideal RRC, RngRun=1", true, 1, 2, 1, 0), TestCase::QUICK);
80  AddTestCase (new LtePrimaryCellChangeTestCase ("real RRC, RngRun=1", false, 1, 2, 1, 0), TestCase::QUICK);
81  AddTestCase (new LtePrimaryCellChangeTestCase ("ideal RRC, RngRun=1", true, 1, 4, 3, 1), TestCase::QUICK);
82  AddTestCase (new LtePrimaryCellChangeTestCase ("real RRC, RngRun=1", false, 1, 4, 3, 1), TestCase::QUICK);
83 } // end of LtePrimaryCellChangeTestSuite::LtePrimaryCellChangeTestSuite ()
84 
86 
87 /*
88  * Test Case
89  */
90 
92  std::string name, bool isIdealRrc, int64_t rngRun,
93  uint8_t numberOfComponentCarriers, uint8_t sourceComponentCarrier, uint8_t targetComponentCarrier)
94  : TestCase (name),
95  m_isIdealRrc {isIdealRrc},
96  m_rngRun {rngRun},
97  m_numberOfComponentCarriers {numberOfComponentCarriers},
98  m_sourceComponentCarrier {sourceComponentCarrier},
99  m_targetComponentCarrier {targetComponentCarrier}
100 {
101  NS_LOG_FUNCTION (this << GetName ());
102 }
103 
104 
106 {
107  NS_LOG_FUNCTION (this << GetName ());
108 }
109 
110 void
112 {
113  NS_LOG_FUNCTION (this << GetName ());
114 
116 
117  Config::SetDefault ("ns3::LteEnbNetDevice::DlEarfcn", UintegerValue (100));
118  Config::SetDefault ("ns3::LteEnbNetDevice::UlEarfcn", UintegerValue (100 + 18000));
119  Config::SetDefault ("ns3::LteEnbNetDevice::DlBandwidth", UintegerValue (25));
120  Config::SetDefault ("ns3::LteEnbNetDevice::UlBandwidth", UintegerValue (25));
121  Config::SetDefault ("ns3::LteUeNetDevice::DlEarfcn", UintegerValue (100));
122 
123  // Create helpers.
124  auto lteHelper = CreateObject<LteHelper> ();
125  lteHelper->SetAttribute ("PathlossModel", TypeIdValue (ns3::FriisSpectrumPropagationLossModel::GetTypeId ()));
126  lteHelper->SetAttribute ("UseIdealRrc", BooleanValue (m_isIdealRrc));
127  lteHelper->SetAttribute ("NumberOfComponentCarriers", UintegerValue (m_numberOfComponentCarriers));
128 
129  auto epcHelper = CreateObject<PointToPointEpcHelper> ();
130  lteHelper->SetEpcHelper (epcHelper);
131 
132  // Create nodes.
133  NodeContainer enbNodes;
134  enbNodes.Create (2);
135  auto ueNode = CreateObject<Node> ();
136 
138  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
139  mobility.Install (enbNodes);
140  mobility.Install (ueNode);
141 
142  // Physical layer.
143  auto enbDevs = lteHelper->InstallEnbDevice (enbNodes);
144  auto ueDev = DynamicCast<LteUeNetDevice> (lteHelper->InstallUeDevice (ueNode).Get (0));
145 
146  auto sourceEnbDev = DynamicCast<LteEnbNetDevice> (enbDevs.Get (m_sourceComponentCarrier / m_numberOfComponentCarriers));
147  auto targetEnbDev = DynamicCast<LteEnbNetDevice> (enbDevs.Get (m_targetComponentCarrier / m_numberOfComponentCarriers));
148 
149  // Network layer.
150  InternetStackHelper internet;
151  internet.Install (ueNode);
152  epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueDev));
153 
154  std::map<uint8_t, Ptr<ComponentCarrierUe>> ueCcMap = ueDev->GetCcMap ();
155  ueDev->SetDlEarfcn (ueCcMap.at (m_sourceComponentCarrier)->GetDlEarfcn ());
156 
157  // Attach UE to specified component carrier
158  lteHelper->Attach (ueDev, sourceEnbDev, m_sourceComponentCarrier % m_numberOfComponentCarriers);
159 
160  // Connect to trace sources in UEs
161  Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/StateTransition",
163  this));
164  Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/ConnectionEstablished",
166  this));
167 
168  uint16_t targetCellId = targetEnbDev->GetCcMap ().at (m_targetComponentCarrier % m_numberOfComponentCarriers)->GetCellId ();
169 
170  lteHelper->AddX2Interface (enbNodes);
171  lteHelper->HandoverRequest (Seconds (1.0), ueDev, sourceEnbDev, targetCellId);
172 
173  // Run simulation.
174  Simulator::Stop (Seconds (2.0));
175  Simulator::Run ();
176 
177  uint16_t expectedCellId = targetCellId;
178  uint16_t actualCellId = ueDev->GetRrc ()->GetCellId ();
179  NS_TEST_ASSERT_MSG_EQ (expectedCellId, actualCellId, "IMSI " << ueDev->GetImsi () << " has attached to an unexpected cell");
180 
181  NS_TEST_ASSERT_MSG_EQ (m_lastState.at (ueDev->GetImsi ()),
182  LteUeRrc::CONNECTED_NORMALLY,
183  "UE " << ueDev->GetImsi ()
184  << " is not at CONNECTED_NORMALLY state");
185 
186  // Destroy simulator.
187  Simulator::Destroy ();
188 } // end of void LtePrimaryCellChangeTestCase::DoRun ()
189 
190 
191 void
193  std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti,
194  LteUeRrc::State oldState, LteUeRrc::State newState)
195 {
196  NS_LOG_FUNCTION (this << imsi << cellId << rnti << oldState << newState);
197  m_lastState[imsi] = newState;
198 }
199 
200 void
202  std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti)
203 {
204  NS_LOG_FUNCTION (this << imsi << cellId << rnti);
205 }
Testing the handover procedure with multiple component carriers.
virtual void DoRun()
Setup the simulation according to the configuration set by the class constructor, run it,...
LtePrimaryCellChangeTestCase(std::string name, bool isIdealRrc, int64_t rngRun, uint8_t numberOfComponentCarriers, uint8_t sourceComponentCarrier, uint8_t targetComponentCarrier)
Creates an instance of the initial cell selection test case.
void StateTransitionCallback(std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti, LteUeRrc::State oldState, LteUeRrc::State newState)
State transition callback function.
uint8_t m_sourceComponentCarrier
source primary component carrier
void ConnectionEstablishedCallback(std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti)
Connection established callback function.
std::map< uint64_t, LteUeRrc::State > m_lastState
The current UE RRC state.
uint8_t m_targetComponentCarrier
target primary component carrier
bool m_isIdealRrc
whether the LTE is configured to use ideal RRC
uint8_t m_numberOfComponentCarriers
number of component carriers
Test suite for executing the primary cell change 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.
holds a vector of ns3::NetDevice pointers
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 SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:849
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_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 LtePrimaryCellChangeTestSuite g_ltePrimaryCellChangeTestSuite
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:108