OLD | NEW |
(Empty) | |
| 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 "lte-test-primary-cell-change.h" |
| 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 |
| 53 LtePrimaryCellChangeTestSuite::LtePrimaryCellChangeTestSuite () |
| 54 : TestSuite ("lte-primary-cell-change", SYSTEM) |
| 55 { |
| 56 // Test that handover from eNB to eNB with one carrier works within this frame
work. |
| 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 sec
ond 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 seco
nd 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 se
cond 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 |
| 85 static LtePrimaryCellChangeTestSuite g_ltePrimaryCellChangeTestSuite; |
| 86 |
| 87 /* |
| 88 * Test Case |
| 89 */ |
| 90 |
| 91 LtePrimaryCellChangeTestCase::LtePrimaryCellChangeTestCase ( |
| 92 std::string name, bool isIdealRrc, int64_t rngRun, |
| 93 uint8_t numberOfComponentCarriers, uint8_t sourceComponentCarrier, uint8_t tar
getComponentCarrier) |
| 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 |
| 105 LtePrimaryCellChangeTestCase::~LtePrimaryCellChangeTestCase () |
| 106 { |
| 107 NS_LOG_FUNCTION (this << GetName ()); |
| 108 } |
| 109 |
| 110 void |
| 111 LtePrimaryCellChangeTestCase::DoRun () |
| 112 { |
| 113 NS_LOG_FUNCTION (this << GetName ()); |
| 114 |
| 115 Config::SetGlobal ("RngRun", IntegerValue (m_rngRun)); |
| 116 |
| 117 // Create helpers. |
| 118 auto lteHelper = CreateObject<LteHelper> (); |
| 119 lteHelper->SetAttribute ("PathlossModel", TypeIdValue (ns3::FriisSpectrumPropa
gationLossModel::GetTypeId ())); |
| 120 lteHelper->SetAttribute ("UseIdealRrc", BooleanValue (m_isIdealRrc)); |
| 121 lteHelper->SetAttribute ("NumberOfComponentCarriers", UintegerValue (m_numberO
fComponentCarriers)); |
| 122 |
| 123 auto epcHelper = CreateObject<PointToPointEpcHelper> (); |
| 124 lteHelper->SetEpcHelper (epcHelper); |
| 125 |
| 126 auto cch = CreateObject<CcHelper> (); |
| 127 cch->SetUlEarfcn (100 + 18000); |
| 128 cch->SetDlEarfcn (100); |
| 129 cch->SetUlBandwidth (25); |
| 130 cch->SetDlBandwidth (25); |
| 131 cch->SetNumberOfComponentCarriers (m_numberOfComponentCarriers); |
| 132 |
| 133 const auto ccm = cch->EquallySpacedCcs (); |
| 134 lteHelper->SetCcPhyParams (ccm); |
| 135 |
| 136 // Create nodes. |
| 137 NodeContainer enbNodes; |
| 138 enbNodes.Create (2); |
| 139 auto ueNode = CreateObject<Node> (); |
| 140 |
| 141 MobilityHelper mobility; |
| 142 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); |
| 143 mobility.Install (enbNodes); |
| 144 mobility.Install (ueNode); |
| 145 |
| 146 // Physical layer. |
| 147 auto enbDevs = lteHelper->InstallEnbDevice (enbNodes); |
| 148 auto ueDev = DynamicCast<LteUeNetDevice> (lteHelper->InstallUeDevice (ueNode).
Get (0)); |
| 149 |
| 150 auto sourceEnbDev = DynamicCast<LteEnbNetDevice> (enbDevs.Get (m_sourceCompone
ntCarrier / m_numberOfComponentCarriers)); |
| 151 auto targetEnbDev = DynamicCast<LteEnbNetDevice> (enbDevs.Get (m_targetCompone
ntCarrier / m_numberOfComponentCarriers)); |
| 152 |
| 153 // Network layer. |
| 154 InternetStackHelper internet; |
| 155 internet.Install (ueNode); |
| 156 epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueDev)); |
| 157 |
| 158 ueDev->SetDlEarfcn (ccm.at (m_sourceComponentCarrier).GetDlEarfcn ()); |
| 159 |
| 160 // Attach UE to specified component carrier |
| 161 lteHelper->Attach (ueDev, sourceEnbDev, m_sourceComponentCarrier % m_numberOfC
omponentCarriers); |
| 162 |
| 163 // Connect to trace sources in UEs |
| 164 Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/StateTransition", |
| 165 MakeCallback (&LtePrimaryCellChangeTestCase::StateTransitionC
allback, |
| 166 this)); |
| 167 Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/InitialPrimaryCellChangeEn
dOk", |
| 168 MakeCallback (&LtePrimaryCellChangeTestCase::InitialPrimaryCe
llChangeEndOkCallback, |
| 169 this)); |
| 170 Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/ConnectionEstablished", |
| 171 MakeCallback (&LtePrimaryCellChangeTestCase::ConnectionEstabl
ishedCallback, |
| 172 this)); |
| 173 |
| 174 uint16_t targetCellId = targetEnbDev->GetCcMap ().at (m_targetComponentCarrier
% m_numberOfComponentCarriers)->GetCellId (); |
| 175 |
| 176 lteHelper->AddX2Interface (enbNodes); |
| 177 lteHelper->HandoverRequest (Seconds (1.0), ueDev, sourceEnbDev, targetCellId); |
| 178 |
| 179 // Run simulation. |
| 180 Simulator::Stop (Seconds (2.0)); |
| 181 Simulator::Run (); |
| 182 |
| 183 uint16_t expectedCellId = targetCellId; |
| 184 uint16_t actualCellId = ueDev->GetRrc ()->GetCellId (); |
| 185 NS_TEST_ASSERT_MSG_EQ (expectedCellId, actualCellId, "IMSI " << ueDev->GetImsi
() << " has attached to an unexpected cell"); |
| 186 |
| 187 NS_TEST_ASSERT_MSG_EQ (m_lastState.at (ueDev->GetImsi ()), |
| 188 LteUeRrc::CONNECTED_NORMALLY, |
| 189 "UE " << ueDev->GetImsi () |
| 190 << " is not at CONNECTED_NORMALLY state"); |
| 191 |
| 192 // Destroy simulator. |
| 193 Simulator::Destroy (); |
| 194 } // end of void LtePrimaryCellChangeTestCase::DoRun () |
| 195 |
| 196 |
| 197 void |
| 198 LtePrimaryCellChangeTestCase::StateTransitionCallback ( |
| 199 std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti, |
| 200 LteUeRrc::State oldState, LteUeRrc::State newState) |
| 201 { |
| 202 NS_LOG_FUNCTION (this << imsi << cellId << rnti << oldState << newState); |
| 203 m_lastState[imsi] = newState; |
| 204 } |
| 205 |
| 206 |
| 207 void |
| 208 LtePrimaryCellChangeTestCase::InitialPrimaryCellChangeEndOkCallback ( |
| 209 std::string context, uint64_t imsi, uint16_t cellId) |
| 210 { |
| 211 NS_LOG_FUNCTION (this << imsi << cellId); |
| 212 } |
| 213 |
| 214 void |
| 215 LtePrimaryCellChangeTestCase::ConnectionEstablishedCallback ( |
| 216 std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti) |
| 217 { |
| 218 NS_LOG_FUNCTION (this << imsi << cellId << rnti); |
| 219 } |
OLD | NEW |