A Discrete-Event Network Simulator
API
lte-test-secondary-cell-handover.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 
22 #include <ns3/friis-spectrum-propagation-loss.h>
23 #include <ns3/log.h>
24 #include <ns3/lte-enb-net-device.h>
25 #include <ns3/lte-helper.h>
26 #include <ns3/test.h>
27 #include <ns3/point-to-point-epc-helper.h>
28 #include <ns3/mobility-helper.h>
29 #include <ns3/boolean.h>
30 #include <ns3/double.h>
31 #include <ns3/integer.h>
32 #include <ns3/log.h>
33 #include <ns3/simulator.h>
34 #include <ns3/lte-ue-net-device.h>
35 #include <ns3/internet-stack-helper.h>
36 #include <ns3/lte-ue-rrc.h>
37 
38 using namespace ns3;
39 
40 NS_LOG_COMPONENT_DEFINE ("LteSecondaryCellHandoverTest");
41 
50 public:
58  LteSecondaryCellHandoverTestCase (std::string name, bool useIdealRrc);
59 
64  void ShutdownCell (uint32_t cellId);
65 
73  void UeHandoverStartCallback (uint64_t imsi,
74  uint16_t sourceCellId, uint16_t rnti,
75  uint16_t targetCellId);
76 
77 
78 
79 private:
83  virtual void DoRun ();
84 
88  virtual void DoTeardown ();
89 
92 
94 
96 };
97 
99  : TestCase {name},
100  m_useIdealRrc {useIdealRrc},
101  m_numberOfComponentCarriers {2},
102  m_hasUeHandoverStarted {false}
103 {
104 }
105 
106 void
108 {
109  Ptr<LteEnbPhy> phy = m_sourceEnbDev->GetPhy (cellId - 1);
110  phy->SetTxPower (1);
111 }
112 
113 void
115  uint16_t sourceCellId, uint16_t rnti,
116  uint16_t targetCellId)
117 {
118  NS_LOG_FUNCTION (this << imsi << sourceCellId << rnti << targetCellId);
119  m_hasUeHandoverStarted = true;
120 }
121 
122 void
124 {
125  NS_LOG_FUNCTION (this << GetName ());
126 
127  Config::SetDefault ("ns3::LteEnbNetDevice::DlEarfcn", UintegerValue (100));
128  Config::SetDefault ("ns3::LteEnbNetDevice::UlEarfcn", UintegerValue (100 + 18000));
129  Config::SetDefault ("ns3::LteEnbNetDevice::DlBandwidth", UintegerValue (25));
130  Config::SetDefault ("ns3::LteEnbNetDevice::UlBandwidth", UintegerValue (25));
131  Config::SetDefault ("ns3::LteUeNetDevice::DlEarfcn", UintegerValue (100));
132 
133  // Create helpers.
134  auto lteHelper = CreateObject<LteHelper> ();
135  lteHelper->SetAttribute ("PathlossModel", TypeIdValue (ns3::FriisSpectrumPropagationLossModel::GetTypeId ()));
136  lteHelper->SetAttribute ("UseIdealRrc", BooleanValue (m_useIdealRrc));
137  lteHelper->SetAttribute ("NumberOfComponentCarriers", UintegerValue (m_numberOfComponentCarriers));
138 
139  // Configure handover algorithm.
140  lteHelper->SetHandoverAlgorithmType ("ns3::A3RsrpHandoverAlgorithm");
141  lteHelper->SetHandoverAlgorithmAttribute ("Hysteresis", DoubleValue (1.5));
142  lteHelper->SetHandoverAlgorithmAttribute ("TimeToTrigger", TimeValue (MilliSeconds (128)));
143 
144  auto epcHelper = CreateObject<PointToPointEpcHelper> ();
145  lteHelper->SetEpcHelper (epcHelper);
146 
147  // Create nodes.
148  auto enbNode = CreateObject<Node> ();
149  auto ueNode = CreateObject<Node> ();
150 
151  // Setup node mobility.
153  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
154  mobility.Install (enbNode);
155  mobility.Install (ueNode);
156 
157  // Physical layer.
158  m_sourceEnbDev = DynamicCast<LteEnbNetDevice> (lteHelper->InstallEnbDevice (enbNode).Get (0));
159  auto ueDevs = lteHelper->InstallUeDevice (ueNode);
160  auto ueDev = DynamicCast<LteUeNetDevice> (ueDevs.Get (0));
161 
162  // Network layer.
163  InternetStackHelper internet;
164  internet.Install (ueNode);
165  epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueDev));
166 
167  uint16_t sourceCellId = m_sourceEnbDev->GetCellId ();
168  Simulator::Schedule (Seconds (0.5), &LteSecondaryCellHandoverTestCase::ShutdownCell, this, sourceCellId);
169 
170  // Setup traces.
171  ueDev->GetRrc ()->TraceConnectWithoutContext ("HandoverStart", MakeCallback (&LteSecondaryCellHandoverTestCase::UeHandoverStartCallback, this));
172 
173  std::map<uint8_t, Ptr<ComponentCarrierUe>> ueCcMap = ueDev->GetCcMap ();
174  ueDev->SetDlEarfcn (ueCcMap.at (0)->GetDlEarfcn ());
175  lteHelper->Attach (ueDev, m_sourceEnbDev, 0);
176 
177  // Run simulation.
178  Simulator::Stop (Seconds (1));
179  Simulator::Run ();
180  Simulator::Destroy ();
181 }
182 
183 void
185 {
186  NS_LOG_FUNCTION (this);
187  NS_TEST_ASSERT_MSG_EQ (m_hasUeHandoverStarted, true, "Handover did not occur");
188 }
189 
197 public:
199 };
200 
202  : TestSuite {"lte-secondary-cell-handover", SYSTEM}
203 {
204  AddTestCase (new LteSecondaryCellHandoverTestCase ("Ideal RRC", true), TestCase::QUICK);
205  AddTestCase (new LteSecondaryCellHandoverTestCase ("Real RRC", false), TestCase::QUICK);
206 }
207 
Test measurement-based handover to secondary cell.
void UeHandoverStartCallback(uint64_t imsi, uint16_t sourceCellId, uint16_t rnti, uint16_t targetCellId)
Callback method indicating start of UE handover.
bool m_useIdealRrc
whether LTE is configured to use ideal RRC
Ptr< LteEnbNetDevice > m_sourceEnbDev
Source eNB device.
void ShutdownCell(uint32_t cellId)
Shutdown cellId by reducing its power to 1 dBm.
LteSecondaryCellHandoverTestCase(std::string name, bool useIdealRrc)
Creates an instance of the measurement-based secondary cell handover test case.
virtual void DoTeardown()
Verify that handover has occurred during the simulation.
uint8_t m_numberOfComponentCarriers
Number of component carriers.
bool m_hasUeHandoverStarted
true if UE started handover
LTE measurement-based handover to secondary cell test suite.
AttributeValue implementation for Boolean.
Definition: boolean.h:37
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:41
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...
Ptr< LteEnbPhy > GetPhy(void) const
uint16_t GetCellId() const
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
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 Time.
Definition: nstime.h:1308
AttributeValue implementation for TypeId.
Definition: type-id.h:595
Hold an unsigned integer type.
Definition: uinteger.h:44
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:849
#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
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1252
static LteSecondaryCellHandoverTestSuite g_lteSecondaryCellHandoverTestSuiteInstance
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
phy
Definition: third.py:93