|
|
| 1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
| 2 |
/* |
| 3 |
* Copyright (c) 2013 Budiarto Herman |
| 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 |
|
| 22 |
#include <ns3/test.h> |
| 23 |
#include <ns3/lte-ue-rrc.h> |
| 24 |
#include <ns3/lte-ue-net-device.h> |
| 25 |
#include <ns3/lte-enb-rrc.h> |
| 26 |
#include <ns3/lte-enb-net-device.h> |
| 27 |
|
| 28 |
#include <ns3/simulator.h> |
| 29 |
#include <ns3/log.h> |
| 30 |
#include <ns3/boolean.h> |
| 31 |
#include <ns3/integer.h> |
| 32 |
#include <ns3/string.h> |
| 33 |
|
| 34 |
#include <ns3/mobility-helper.h> |
| 35 |
#include <ns3/lte-helper.h> |
| 36 |
#include <ns3/node-container.h> |
| 37 |
#include <ns3/net-device-container.h> |
| 38 |
|
| 39 |
NS_LOG_COMPONENT_DEFINE ("LteRrcConnEstablishmentTest"); |
| 40 |
|
| 41 |
namespace ns3 { |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
/** |
| 46 |
* \brief TODO |
| 47 |
*/ |
| 48 |
class LteRrcConnEstablishmentTestCase : public TestCase |
| 49 |
{ |
| 50 |
public: |
| 51 |
/** |
| 52 |
* \brief TODO |
| 53 |
*/ |
| 54 |
LteRrcConnEstablishmentTestCase (uint16_t nUe, double distance, |
| 55 |
int64_t rngRun); |
| 56 |
virtual ~LteRrcConnEstablishmentTestCase (); |
| 57 |
|
| 58 |
private: |
| 59 |
virtual void DoRun (); |
| 60 |
// void DlSchedulingCallback (std::string context, uint32_t frameNo, |
| 61 |
// uint32_t subframeNo, uint16_t rnti, |
| 62 |
// uint8_t mcs1, uint16_t tbSize1, |
| 63 |
// uint8_t mcs2, uint16_t tbSize2); |
| 64 |
// void UlSchedulingCallback (std::string context, uint32_t frameNo, |
| 65 |
// uint32_t subframeNo, uint16_t rnti, |
| 66 |
// uint8_t mcs, uint16_t tbSize); |
| 67 |
// void UeStateTransitionCallback (std::string context, uint64_t imsi, |
| 68 |
// uint16_t cellId, uint16_t rnti, |
| 69 |
// LteUeRrc::State oldState, LteUeRrc::State newState); |
| 70 |
// void EnbStateTransitionCallback (std::string context, uint64_t imsi, |
| 71 |
// uint16_t cellId, uint16_t rnti, |
| 72 |
// UeManager::State oldState, UeManager::State newState); |
| 73 |
void ConnectionEstablishedCallback (std::string context, uint64_t imsi, |
| 74 |
uint16_t cellId, uint16_t rnti); |
| 75 |
void ConnectionTimeoutCallback (std::string context, uint64_t imsi, |
| 76 |
uint16_t cellId, uint16_t rnti); |
| 77 |
uint16_t m_nUe; |
| 78 |
double m_distance; |
| 79 |
int64_t m_rngRun; |
| 80 |
bool m_isConnectionEstablished; |
| 81 |
bool m_isConnectionTimeout; |
| 82 |
}; |
| 83 |
|
| 84 |
|
| 85 |
LteRrcConnEstablishmentTestCase::LteRrcConnEstablishmentTestCase ( |
| 86 |
uint16_t nUe, double distance, int64_t rngRun) |
| 87 |
: TestCase (""), |
| 88 |
m_nUe (nUe), |
| 89 |
m_distance (distance), |
| 90 |
m_rngRun (rngRun), |
| 91 |
m_isConnectionEstablished (false), |
| 92 |
m_isConnectionTimeout (false) |
| 93 |
{ |
| 94 |
NS_LOG_FUNCTION (this << GetName ()); |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
LteRrcConnEstablishmentTestCase::~LteRrcConnEstablishmentTestCase () |
| 99 |
{ |
| 100 |
NS_LOG_FUNCTION (this << GetName ()); |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
void |
| 105 |
LteRrcConnEstablishmentTestCase::DoRun () |
| 106 |
{ |
| 107 |
NS_LOG_FUNCTION (this << GetName ()); |
| 108 |
|
| 109 |
Config::SetGlobal ("RngRun", IntegerValue (m_rngRun)); |
| 110 |
|
| 111 |
Ptr<LteHelper> lteHelper = CreateObject<LteHelper> (); |
| 112 |
lteHelper->SetAttribute ("PathlossModel", |
| 113 |
StringValue ("ns3::FriisSpectrumPropagationLossModel")); |
| 114 |
lteHelper->SetAttribute ("UseIdealRrc", BooleanValue (false)); |
| 115 |
|
| 116 |
// Create Nodes |
| 117 |
NodeContainer enbNodes; |
| 118 |
enbNodes.Create (4); |
| 119 |
NodeContainer ueNodes; |
| 120 |
ueNodes.Create (m_nUe); |
| 121 |
|
| 122 |
// Assign nodes to position |
| 123 |
Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> (); |
| 124 |
positionAlloc->Add (Vector (0, 0, 0)); |
| 125 |
positionAlloc->Add (Vector (m_distance, 0, 0)); |
| 126 |
positionAlloc->Add (Vector (0, m_distance, 0)); |
| 127 |
positionAlloc->Add (Vector (m_distance, m_distance, 0)); |
| 128 |
for (uint16_t i = 0; i < m_nUe; i++) |
| 129 |
{ |
| 130 |
positionAlloc->Add (Vector (0.55 * m_distance, 0.55 * m_distance, 0)); |
| 131 |
} |
| 132 |
|
| 133 |
MobilityHelper mobility; |
| 134 |
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); |
| 135 |
mobility.SetPositionAllocator (positionAlloc); |
| 136 |
mobility.Install (enbNodes); |
| 137 |
mobility.Install (ueNodes); |
| 138 |
|
| 139 |
// Create Devices and install them in the Nodes (eNB and UE) |
| 140 |
int64_t stream = 1; |
| 141 |
NetDeviceContainer enbDevs; |
| 142 |
enbDevs = lteHelper->InstallEnbDevice (enbNodes); |
| 143 |
stream += lteHelper->AssignStreams (enbDevs, stream); |
| 144 |
|
| 145 |
NetDeviceContainer ueDevs; |
| 146 |
ueDevs = lteHelper->InstallUeDevice (ueNodes); |
| 147 |
stream += lteHelper->AssignStreams (ueDevs, stream); |
| 148 |
|
| 149 |
// Connect to trace sources in UEs |
| 150 |
// Config::Connect ("/NodeList/*/DeviceList/*/LteEnbMac/DlScheduling", |
| 151 |
// MakeCallback (&LteRrcConnEstablishmentTestCase::DlSchedulingCallback, |
| 152 |
// this)); |
| 153 |
// Config::Connect ("/NodeList/*/DeviceList/*/LteEnbMac/UlScheduling", |
| 154 |
// MakeCallback (&LteRrcConnEstablishmentTestCase::UlSchedulingCallback, |
| 155 |
// this)); |
| 156 |
// Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/StateTransition", |
| 157 |
// MakeCallback (&LteRrcConnEstablishmentTestCase::UeStateTransitionCallback, |
| 158 |
// this)); |
| 159 |
Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/ConnectionEstablished", |
| 160 |
MakeCallback (&LteRrcConnEstablishmentTestCase::ConnectionEstablishedCallback, |
| 161 |
this)); |
| 162 |
Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/ConnectionTimeout", |
| 163 |
MakeCallback (&LteRrcConnEstablishmentTestCase::ConnectionTimeoutCallback, |
| 164 |
this)); |
| 165 |
|
| 166 |
// Connect to trace source in serving eNodeB |
| 167 |
// Config::Connect ("/NodeList/*/DeviceList/*/LteEnbRrc/UeMap/StateTransition", |
| 168 |
// MakeCallback (&LteRrcConnEstablishmentTestCase::EnbStateTransitionCallback, |
| 169 |
// this)); |
| 170 |
|
| 171 |
lteHelper->Attach (ueDevs, enbDevs.Get (0)); |
| 172 |
|
| 173 |
// Activate an EPS bearer |
| 174 |
enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE; |
| 175 |
EpsBearer bearer (q); |
| 176 |
lteHelper->ActivateDataRadioBearer (ueDevs, bearer); |
| 177 |
|
| 178 |
// Run simulation |
| 179 |
Simulator::Stop (MilliSeconds (150)); |
| 180 |
Simulator::Run (); |
| 181 |
|
| 182 |
NS_LOG_INFO ("Simulation ends"); |
| 183 |
|
| 184 |
// Verification |
| 185 |
|
| 186 |
Ptr<LteEnbNetDevice> servingEnb = enbDevs.Get (0)->GetObject<LteEnbNetDevice> (); |
| 187 |
Ptr<LteEnbRrc> enbRrc = servingEnb->GetRrc (); |
| 188 |
|
| 189 |
for (uint16_t i = 0; i < m_nUe; i++) |
| 190 |
{ |
| 191 |
// verify UE state in UE RRC |
| 192 |
Ptr<LteUeNetDevice> ueDev = ueDevs.Get (i)->GetObject<LteUeNetDevice> (); |
| 193 |
NS_ASSERT (ueDev != 0); |
| 194 |
if (m_isConnectionEstablished) |
| 195 |
{ |
| 196 |
// connection establishment was successful |
| 197 |
NS_TEST_ASSERT_MSG_EQ (ueDev->GetRrc ()->GetState (), LteUeRrc::CONNECTED_NORMALLY, |
| 198 |
"UE " << i << " is not at CONNECTED_NORMALLY state"); |
| 199 |
} |
| 200 |
else |
| 201 |
{ |
| 202 |
/* |
| 203 |
* T300 has expired, thus connection establishment was failed. The UE |
| 204 |
* should be back to Idle state. |
| 205 |
*/ |
| 206 |
NS_TEST_ASSERT_MSG_EQ (m_isConnectionTimeout, true, |
| 207 |
"Connection timeout should have occurred"); |
| 208 |
NS_TEST_ASSERT_MSG_EQ (ueDev->GetRrc ()->GetState (), LteUeRrc::IDLE_CAMPED_NORMALLY, |
| 209 |
"UE " << i << " but it is not at IDLE_CAMPED_NORMALLY state"); |
| 210 |
} |
| 211 |
|
| 212 |
// verify UE state in eNodeB RRC |
| 213 |
Ptr<UeManager> ueManager = enbRrc->GetUeManager (i + 1); |
| 214 |
NS_ASSERT (ueManager != 0); |
| 215 |
UeManager::State state = ueManager->GetState (); |
| 216 |
if (m_isConnectionEstablished) |
| 217 |
{ |
| 218 |
/* |
| 219 |
* At this point, UE side's of connection has been established. But |
| 220 |
* several "failures" may follow after this point: |
| 221 |
* (1) failure in the RRC Connection Reconfiguration procedure (which |
| 222 |
* immediately follows the RRC Connection Establishment procedure) |
| 223 |
* (2) eNodeB's failure in receiving RRC Connection Setup Complete |
| 224 |
* message from the UE. |
| 225 |
* Those failure cases are outside the scope of this test case, so we |
| 226 |
* simply include them as the accepted cases. |
| 227 |
*/ |
| 228 |
bool isValidState = |
| 229 |
(state == UeManager::CONNECTED_NORMALLY) // successful establishment |
| 230 |
|| (state == UeManager::CONNECTION_RECONFIGURATION) // failure (1) |
| 231 |
|| (state == UeManager::CONNECTION_SETUP); // failure (2) |
| 232 |
NS_TEST_ASSERT_MSG_EQ (isValidState, true, |
| 233 |
"The context of UE " << i << " is invalid on eNodeB side"); |
| 234 |
} |
| 235 |
else |
| 236 |
{ |
| 237 |
/* |
| 238 |
* When T300 expires on the UE side, the corresponding UE's context on |
| 239 |
* the eNodeB side would stay indefinitely in CONNECTION_SETUP state. |
| 240 |
*/ |
| 241 |
NS_TEST_ASSERT_MSG_EQ (state, UeManager::CONNECTION_SETUP, |
| 242 |
"The context of UE " << i << " is not at CONNECTION_SETUP state"); |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
Simulator::Destroy (); |
| 247 |
|
| 248 |
} // end of void LteRrcConnEstablishmentTestCase::DoRun () |
| 249 |
|
| 250 |
|
| 251 |
//void |
| 252 |
//LteRrcConnEstablishmentTestCase::DlSchedulingCallback ( |
| 253 |
// std::string context, uint32_t frameNo, uint32_t subframeNo, uint16_t rnti, |
| 254 |
// uint8_t mcs1, uint16_t tbSize1, uint8_t mcs2, uint16_t tbSize2) |
| 255 |
//{ |
| 256 |
// NS_LOG_FUNCTION (this << frameNo << subframeNo << rnti |
| 257 |
// << (uint16_t) mcs1 << tbSize1 |
| 258 |
// << (uint16_t) mcs2 << tbSize2); |
| 259 |
//} |
| 260 |
|
| 261 |
|
| 262 |
//void |
| 263 |
//LteRrcConnEstablishmentTestCase::UlSchedulingCallback ( |
| 264 |
// std::string context, uint32_t frameNo, uint32_t subframeNo, uint16_t rnti, |
| 265 |
// uint8_t mcs, uint16_t tbSize) |
| 266 |
//{ |
| 267 |
// NS_LOG_FUNCTION (this << frameNo << subframeNo << rnti |
| 268 |
// << (uint16_t) mcs << tbSize); |
| 269 |
//} |
| 270 |
|
| 271 |
|
| 272 |
//void |
| 273 |
//LteRrcConnEstablishmentTestCase::UeStateTransitionCallback ( |
| 274 |
// std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti, |
| 275 |
// LteUeRrc::State oldState, LteUeRrc::State newState) |
| 276 |
//{ |
| 277 |
// //NS_LOG_FUNCTION (this << imsi << cellId << rnti << oldState << newState); |
| 278 |
//} |
| 279 |
|
| 280 |
|
| 281 |
//void |
| 282 |
//LteRrcConnEstablishmentTestCase::EnbStateTransitionCallback ( |
| 283 |
// std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti, |
| 284 |
// UeManager::State oldState, UeManager::State newState) |
| 285 |
//{ |
| 286 |
// //NS_LOG_FUNCTION (this << imsi << cellId << rnti << oldState << newState); |
| 287 |
//} |
| 288 |
|
| 289 |
|
| 290 |
void |
| 291 |
LteRrcConnEstablishmentTestCase::ConnectionEstablishedCallback ( |
| 292 |
std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti) |
| 293 |
{ |
| 294 |
NS_LOG_FUNCTION (this << imsi << cellId); |
| 295 |
m_isConnectionEstablished = true; |
| 296 |
} |
| 297 |
|
| 298 |
|
| 299 |
void |
| 300 |
LteRrcConnEstablishmentTestCase::ConnectionTimeoutCallback ( |
| 301 |
std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti) |
| 302 |
{ |
| 303 |
NS_LOG_FUNCTION (this << imsi << cellId); |
| 304 |
m_isConnectionTimeout = true; |
| 305 |
} |
| 306 |
|
| 307 |
|
| 308 |
/** |
| 309 |
* \brief TODO |
| 310 |
* |
| 311 |
* \sa ns3::LteRrcConnEstablishmentTestCase |
| 312 |
*/ |
| 313 |
class LteRrcConnEstablishmentTestSuite : public TestSuite |
| 314 |
{ |
| 315 |
public: |
| 316 |
LteRrcConnEstablishmentTestSuite (); |
| 317 |
}; |
| 318 |
|
| 319 |
|
| 320 |
LteRrcConnEstablishmentTestSuite::LteRrcConnEstablishmentTestSuite () |
| 321 |
: TestSuite ("lte-rrc-conn-establishment", SYSTEM) |
| 322 |
{ |
| 323 |
// LogComponentEnable ("LteRrcConnEstablishmentTest", LOG_PREFIX_ALL); |
| 324 |
// LogComponentEnable ("LteRrcConnEstablishmentTest", LOG_FUNCTION); |
| 325 |
// LogComponentEnable ("LteRrcConnEstablishmentTest", LOG_INFO); |
| 326 |
//// LogComponentEnable ("LteSpectrumPhy", LOG_PREFIX_ALL); |
| 327 |
//// LogComponentEnable ("LteSpectrumPhy", LOG_DEBUG); |
| 328 |
// LogComponentEnable ("LteUeMac", LOG_PREFIX_ALL); |
| 329 |
// LogComponentEnable ("LteUeMac", LOG_INFO); |
| 330 |
//// LogComponentEnable ("LteUeMac", LOG_LOGIC); |
| 331 |
//// LogComponentEnable ("LteUeMac", LOG_DEBUG); |
| 332 |
//// LogComponentEnable ("LteUeMac", LOG_FUNCTION); |
| 333 |
//// LogComponentEnable ("LteRlcTm", LOG_PREFIX_ALL); |
| 334 |
//// LogComponentEnable ("LteRlcTm", LOG_FUNCTION); |
| 335 |
//// LogComponentEnable ("LteRlcTm", LOG_LOGIC); |
| 336 |
//// LogComponentEnable ("LteRlcTm", LOG_WARN); |
| 337 |
// LogComponentEnable ("LteEnbRrc", LOG_PREFIX_ALL); |
| 338 |
// LogComponentEnable ("LteEnbRrc", LOG_INFO); |
| 339 |
// LogComponentEnable ("LteUeRrc", LOG_PREFIX_ALL); |
| 340 |
// LogComponentEnable ("LteUeRrc", LOG_INFO); |
| 341 |
|
| 342 |
// assuming T300 is 100 ms |
| 343 |
|
| 344 |
// RngRun 1: transmission failure in RRC Connection Setup message |
| 345 |
// RngRun 2: successful establishment, followed by successful reconfiguration |
| 346 |
// RngRun 3: successful establishment, followed by failed reconfiguration |
| 347 |
// RngRun 4: successful establishment, followed by successful reconfiguration |
| 348 |
// RngRun 5: transmission failure in RRC Connection Setup message |
| 349 |
// RngRun 6: transmission failure in RRC Connection Setup Complete message |
| 350 |
for (int64_t i = 3; i <= 6; i++) |
| 351 |
{ |
| 352 |
AddTestCase (new LteRrcConnEstablishmentTestCase (1, 100, i), |
| 353 |
TestCase::QUICK); |
| 354 |
} |
| 355 |
} |
| 356 |
|
| 357 |
|
| 358 |
static LteRrcConnEstablishmentTestSuite g_lteRrcConnEstablishmentTestSuite; |
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
} // end of namespace ns3 |