|
|
| 1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 |
/* |
| 3 |
* Copyright (c) 2013 Magister Solutions |
| 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: Budiarto Herman <budiarto.herman@magister.fi> |
| 19 |
*/ |
| 20 |
|
| 21 |
#include <ns3/test.h> |
| 22 |
|
| 23 |
#include <ns3/log.h> |
| 24 |
#include <ns3/nstime.h> |
| 25 |
#include <ns3/callback.h> |
| 26 |
#include <ns3/config.h> |
| 27 |
#include <ns3/boolean.h> |
| 28 |
#include <ns3/simulator.h> |
| 29 |
|
| 30 |
#include <ns3/node-container.h> |
| 31 |
#include <ns3/net-device-container.h> |
| 32 |
#include <ns3/ipv4-interface-container.h> |
| 33 |
|
| 34 |
#include <ns3/lte-helper.h> |
| 35 |
#include <ns3/epc-helper.h> |
| 36 |
#include <ns3/internet-stack-helper.h> |
| 37 |
#include <ns3/point-to-point-helper.h> |
| 38 |
#include <ns3/ipv4-address-helper.h> |
| 39 |
#include <ns3/ipv4-static-routing-helper.h> |
| 40 |
#include <ns3/mobility-helper.h> |
| 41 |
|
| 42 |
#include <ns3/data-rate.h> |
| 43 |
#include <ns3/ipv4-static-routing.h> |
| 44 |
#include <ns3/position-allocator.h> |
| 45 |
|
| 46 |
|
| 47 |
NS_LOG_COMPONENT_DEFINE("LteHandoverDelayTest"); |
| 48 |
|
| 49 |
namespace ns3 { |
| 50 |
|
| 51 |
|
| 52 |
/* |
| 53 |
* HANDOVER DELAY TEST CASE |
| 54 |
*/ |
| 55 |
|
| 56 |
class LteHandoverDelayTestCase : public TestCase |
| 57 |
{ |
| 58 |
public: |
| 59 |
LteHandoverDelayTestCase (bool useIdealRrc, Time handoverTime, |
| 60 |
Time delayThreshold, Time simulationDuration) |
| 61 |
: TestCase ("Verifying that the time needed for handover is under a specified threshold"), |
| 62 |
m_useIdealRrc (useIdealRrc), |
| 63 |
m_handoverTime (handoverTime), |
| 64 |
m_delayThreshold (delayThreshold), |
| 65 |
m_simulationDuration (simulationDuration), |
| 66 |
m_ueHandoverStart (Seconds (0)), |
| 67 |
m_enbHandoverStart (Seconds (0)) |
| 68 |
{ |
| 69 |
} |
| 70 |
private: |
| 71 |
virtual void DoRun (void); |
| 72 |
|
| 73 |
void UeHandoverStartCallback (std::string context, uint64_t imsi, |
| 74 |
uint16_t cellid, uint16_t rnti, uint16_t targetCellId); |
| 75 |
void UeHandoverEndOkCallback (std::string context, uint64_t imsi, |
| 76 |
uint16_t cellid, uint16_t rnti); |
| 77 |
void EnbHandoverStartCallback (std::string context, uint64_t imsi, |
| 78 |
uint16_t cellid, uint16_t rnti, uint16_t targetCellId); |
| 79 |
void EnbHandoverEndOkCallback (std::string context, uint64_t imsi, |
| 80 |
uint16_t cellid, uint16_t rnti); |
| 81 |
|
| 82 |
bool m_useIdealRrc; |
| 83 |
Time m_handoverTime; |
| 84 |
Time m_delayThreshold; |
| 85 |
Time m_simulationDuration; |
| 86 |
|
| 87 |
Time m_ueHandoverStart; |
| 88 |
Time m_enbHandoverStart; |
| 89 |
}; |
| 90 |
|
| 91 |
|
| 92 |
void |
| 93 |
LteHandoverDelayTestCase::DoRun () |
| 94 |
{ |
| 95 |
NS_LOG_INFO ("-----test case: ideal RRC = " << m_useIdealRrc |
| 96 |
<< " handover time = " << m_handoverTime.GetSeconds () << "-----"); |
| 97 |
|
| 98 |
Ptr<LteHelper> lteHelper = CreateObject<LteHelper> (); |
| 99 |
Ptr<EpcHelper> epcHelper = CreateObject<EpcHelper> (); |
| 100 |
lteHelper->SetEpcHelper (epcHelper); |
| 101 |
lteHelper->SetAttribute ("UseIdealRrc", BooleanValue(m_useIdealRrc)); |
| 102 |
|
| 103 |
// SETUP A REMOTE HOST |
| 104 |
|
| 105 |
NodeContainer remoteHosts; |
| 106 |
remoteHosts.Create (1); |
| 107 |
InternetStackHelper inetStackHelper; |
| 108 |
inetStackHelper.Install (remoteHosts); |
| 109 |
|
| 110 |
// SETUP POINT-TO-POINT CONNECTION BETWEEN REMOTE HOST AND EPC |
| 111 |
|
| 112 |
PointToPointHelper p2pHelper; |
| 113 |
p2pHelper.SetDeviceAttribute ("DataRate", |
| 114 |
DataRateValue (DataRate ("100Gb/s"))); |
| 115 |
p2pHelper.SetDeviceAttribute ("Mtu", UintegerValue (1500)); |
| 116 |
p2pHelper.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010))); |
| 117 |
|
| 118 |
NetDeviceContainer inetDevs = p2pHelper.Install (epcHelper->GetPgwNode (), |
| 119 |
remoteHosts.Get (0)); |
| 120 |
|
| 121 |
Ipv4AddressHelper addrHelper; |
| 122 |
addrHelper.SetBase ("10.1.1.0", "255.255.255.0"); |
| 123 |
Ipv4InterfaceContainer inetIfs; |
| 124 |
inetIfs = addrHelper.Assign (inetDevs); |
| 125 |
|
| 126 |
// SETUP ROUTING |
| 127 |
|
| 128 |
Ipv4StaticRoutingHelper ipRoutingHelper; |
| 129 |
Ptr<Ipv4StaticRouting> remoteHostRouting = |
| 130 |
ipRoutingHelper.GetStaticRouting (remoteHosts.Get (0)->GetObject<Ipv4> ()); |
| 131 |
remoteHostRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), |
| 132 |
Ipv4Mask ("255.0.0.0"), 1); |
| 133 |
|
| 134 |
// CREATE NODES |
| 135 |
|
| 136 |
NodeContainer enbNodes; |
| 137 |
NodeContainer ueNodes; |
| 138 |
enbNodes.Create (2); |
| 139 |
ueNodes.Create (1); |
| 140 |
|
| 141 |
/** |
| 142 |
* eNodeB 0 UE eNodeB 1 |
| 143 |
* |
| 144 |
* x ----------------------- x ----------------------- x |
| 145 |
* 500 m 500 m |
| 146 |
*/ |
| 147 |
|
| 148 |
// SETUP MOBILITY |
| 149 |
|
| 150 |
Ptr<ListPositionAllocator> posAlloc = CreateObject<ListPositionAllocator> (); |
| 151 |
posAlloc->Add (Vector (0, 0, 0)); |
| 152 |
posAlloc->Add (Vector (1000, 0, 0)); |
| 153 |
posAlloc->Add (Vector (500, 0, 0)); |
| 154 |
|
| 155 |
MobilityHelper mobilityHelper; |
| 156 |
mobilityHelper.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); |
| 157 |
mobilityHelper.SetPositionAllocator (posAlloc); |
| 158 |
mobilityHelper.Install (enbNodes); |
| 159 |
mobilityHelper.Install (ueNodes); |
| 160 |
|
| 161 |
// SETUP LTE DEVICES |
| 162 |
|
| 163 |
NetDeviceContainer enbDevs; |
| 164 |
NetDeviceContainer ueDevs; |
| 165 |
enbDevs = lteHelper->InstallEnbDevice (enbNodes); |
| 166 |
ueDevs = lteHelper->InstallUeDevice (ueNodes); |
| 167 |
|
| 168 |
// SETUP INTERNET IN UE |
| 169 |
|
| 170 |
inetStackHelper.Install(ueNodes); |
| 171 |
Ipv4InterfaceContainer ueIfs; |
| 172 |
ueIfs = epcHelper->AssignUeIpv4Address (ueDevs); |
| 173 |
|
| 174 |
// SETUP DEFAULT GATEWAY FOR UE |
| 175 |
|
| 176 |
Ptr<Ipv4StaticRouting> ueStaticRouting = |
| 177 |
ipRoutingHelper.GetStaticRouting (ueNodes.Get (0)->GetObject<Ipv4> ()); |
| 178 |
ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), |
| 179 |
1); |
| 180 |
|
| 181 |
// INSTALLING TRACES |
| 182 |
|
| 183 |
Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/HandoverStart", |
| 184 |
MakeCallback (&LteHandoverDelayTestCase::UeHandoverStartCallback, this)); |
| 185 |
Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/HandoverEndOk", |
| 186 |
MakeCallback (&LteHandoverDelayTestCase::UeHandoverEndOkCallback, this)); |
| 187 |
|
| 188 |
Config::Connect ("/NodeList/*/DeviceList/*/LteEnbRrc/HandoverStart", |
| 189 |
MakeCallback (&LteHandoverDelayTestCase::EnbHandoverStartCallback, this)); |
| 190 |
Config::Connect ("/NodeList/*/DeviceList/*/LteEnbRrc/HandoverEndOk", |
| 191 |
MakeCallback (&LteHandoverDelayTestCase::EnbHandoverEndOkCallback, this)); |
| 192 |
|
| 193 |
// SIMULATION |
| 194 |
|
| 195 |
lteHelper->AddX2Interface (enbNodes); |
| 196 |
lteHelper->Attach (ueDevs.Get(0), enbDevs.Get(0)); |
| 197 |
lteHelper->HandoverRequest (m_handoverTime, ueDevs.Get (0), enbDevs.Get (0), |
| 198 |
enbDevs.Get (1)); |
| 199 |
// disable error model in dl ctrl channel |
| 200 |
//Config::Set ("/NodeList/*/DeviceList/*/LteUePhy/DlSpectrumPhy/CtrlErrorModelEnabled", |
| 201 |
// BooleanValue (false)); |
| 202 |
Simulator::Stop (m_simulationDuration); |
| 203 |
Simulator::Run (); |
| 204 |
Simulator::Destroy (); |
| 205 |
|
| 206 |
} // end of void LteHandoverDelayTestCase::DoRun () |
| 207 |
|
| 208 |
|
| 209 |
void |
| 210 |
LteHandoverDelayTestCase::UeHandoverStartCallback (std::string context, |
| 211 |
uint64_t imsi, uint16_t cellid, uint16_t rnti, uint16_t targetCellId) |
| 212 |
{ |
| 213 |
NS_LOG_FUNCTION (this << context); |
| 214 |
m_ueHandoverStart = Simulator::Now (); |
| 215 |
} |
| 216 |
|
| 217 |
void |
| 218 |
LteHandoverDelayTestCase::UeHandoverEndOkCallback (std::string context, |
| 219 |
uint64_t imsi, uint16_t cellid, uint16_t rnti) |
| 220 |
{ |
| 221 |
NS_LOG_FUNCTION (this << context); |
| 222 |
NS_ASSERT (m_ueHandoverStart > Seconds (0)); |
| 223 |
Time delay = Simulator::Now () - m_ueHandoverStart; |
| 224 |
NS_LOG_DEBUG (this << " UE delay = " << delay.GetSeconds ()); |
| 225 |
NS_TEST_ASSERT_MSG_LT (delay.GetSeconds (), m_delayThreshold.GetSeconds (), |
| 226 |
"UE handover delay is higher than the allowed threshold " |
| 227 |
<< "(ideal RRC = " << m_useIdealRrc |
| 228 |
<< " handover time = " << m_handoverTime.GetSeconds () << ")"); |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
void |
| 233 |
LteHandoverDelayTestCase::EnbHandoverStartCallback (std::string context, |
| 234 |
uint64_t imsi, uint16_t cellid, uint16_t rnti, uint16_t targetCellId) |
| 235 |
{ |
| 236 |
NS_LOG_FUNCTION (this << context); |
| 237 |
m_enbHandoverStart = Simulator::Now (); |
| 238 |
} |
| 239 |
|
| 240 |
void |
| 241 |
LteHandoverDelayTestCase::EnbHandoverEndOkCallback (std::string context, |
| 242 |
uint64_t imsi, uint16_t cellid, uint16_t rnti) |
| 243 |
{ |
| 244 |
NS_LOG_FUNCTION (this << context); |
| 245 |
NS_ASSERT (m_enbHandoverStart > Seconds (0)); |
| 246 |
Time delay = Simulator::Now () - m_enbHandoverStart; |
| 247 |
NS_LOG_DEBUG (this << " eNodeB delay = " << delay.GetSeconds ()); |
| 248 |
NS_TEST_ASSERT_MSG_LT (delay.GetSeconds (), m_delayThreshold.GetSeconds (), |
| 249 |
"eNodeB handover delay is higher than the allowed threshold " |
| 250 |
<< "(ideal RRC = " << m_useIdealRrc |
| 251 |
<< " handover time = " << m_handoverTime.GetSeconds () << ")"); |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
/* |
| 257 |
* TEST SUITE |
| 258 |
*/ |
| 259 |
|
| 260 |
static class LteHandoverDelayTestSuite : public TestSuite |
| 261 |
{ |
| 262 |
public: |
| 263 |
LteHandoverDelayTestSuite () |
| 264 |
: TestSuite ("lte-handover-delay", TestSuite::SYSTEM) |
| 265 |
{ |
| 266 |
//LogComponentEnable ("LteHandoverDelayTest", LOG_PREFIX_TIME); |
| 267 |
//LogComponentEnable ("LteHandoverDelayTest", LOG_DEBUG); |
| 268 |
//LogComponentEnable ("LteHandoverDelayTest", LOG_INFO); |
| 269 |
|
| 270 |
// HANDOVER DELAY TEST CASES WITH IDEAL RRC (THRESHOLD = 0.005 sec) |
| 271 |
|
| 272 |
for (Time handoverTime = Seconds (0.100); handoverTime < Seconds (0.110); |
| 273 |
handoverTime += Seconds (0.001)) |
| 274 |
{ |
| 275 |
// arguments: useIdealRrc, handoverTime, delayThreshold, simulationDuration |
| 276 |
AddTestCase ( |
| 277 |
new LteHandoverDelayTestCase (true, handoverTime, Seconds (0.005), |
| 278 |
Seconds (0.200)), TestCase::QUICK); |
| 279 |
} |
| 280 |
|
| 281 |
// HANDOVER DELAY TEST CASES WITH REAL RRC (THRESHOLD = 0.020 sec) |
| 282 |
|
| 283 |
for (Time handoverTime = Seconds (0.100); handoverTime < Seconds (0.110); |
| 284 |
handoverTime += Seconds (0.001)) |
| 285 |
{ |
| 286 |
// arguments: useIdealRrc, handoverTime, delayThreshold, simulationDuration |
| 287 |
AddTestCase ( |
| 288 |
new LteHandoverDelayTestCase (false, handoverTime, Seconds (0.020), |
| 289 |
Seconds (0.200)), TestCase::QUICK); |
| 290 |
} |
| 291 |
} |
| 292 |
} g_lteHandoverDelayTestSuite; |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
} // end of namespace ns3 |