A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lte-test-cell-selection.cc
Go to the documentation of this file.
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 
23 
24 #include <ns3/simulator.h>
25 #include <ns3/log.h>
26 #include <ns3/boolean.h>
27 #include <ns3/double.h>
28 #include <ns3/integer.h>
29 
30 #include <ns3/mobility-helper.h>
31 #include <ns3/lte-helper.h>
32 #include <ns3/point-to-point-epc-helper.h>
33 #include <ns3/internet-stack-helper.h>
34 #include <ns3/point-to-point-helper.h>
35 #include <ns3/ipv4-address-helper.h>
36 #include <ns3/ipv4-static-routing-helper.h>
37 
38 #include <ns3/node-container.h>
39 #include <ns3/net-device-container.h>
40 #include <ns3/ipv4-interface-container.h>
41 
42 #include <ns3/lte-ue-net-device.h>
43 #include <ns3/lte-ue-rrc.h>
44 #include <ns3/lte-enb-net-device.h>
45 
46 NS_LOG_COMPONENT_DEFINE ("LteCellSelectionTest");
47 
48 namespace ns3 {
49 
50 
51 /*
52  * Test Suite
53  */
54 
55 
57  : TestSuite ("lte-cell-selection", SYSTEM)
58 {
59  std::vector<LteCellSelectionTestCase::UeSetup_t> w;
60 
61  // REAL RRC PROTOCOL
62 
63  w.clear ();
64  // x y csgMember
65  // checkPoint cell1, cell2
66  w.push_back (LteCellSelectionTestCase::UeSetup_t (0.0, 0.55, false,
67  MilliSeconds (283), 1, 0));
68  w.push_back (LteCellSelectionTestCase::UeSetup_t (0.0, 0.45, false,
69  MilliSeconds (283), 1, 0));
70  w.push_back (LteCellSelectionTestCase::UeSetup_t (0.5, 0.45, false,
71  MilliSeconds (363), 1, 3));
72  w.push_back (LteCellSelectionTestCase::UeSetup_t (0.5, 0.0, true,
73  MilliSeconds (283), 2, 4));
74  w.push_back (LteCellSelectionTestCase::UeSetup_t (1.0, 0.55, true,
75  MilliSeconds (283), 3, 0));
76  w.push_back (LteCellSelectionTestCase::UeSetup_t (1.0, 0.45, true,
77  MilliSeconds (283), 4, 0));
78 
79  AddTestCase (new LteCellSelectionTestCase ("EPC, real RRC, RngNum=1",
80  true, false, 60.0, w, 1),
81  // isd rngrun
83 
84  // IDEAL RRC PROTOCOL
85 
86  w.clear ();
87  // x y csgMember
88  // checkPoint cell1, cell2
89  w.push_back (LteCellSelectionTestCase::UeSetup_t (0.0, 0.55, false,
90  MilliSeconds (266), 1, 0));
91  w.push_back (LteCellSelectionTestCase::UeSetup_t (0.0, 0.45, false,
92  MilliSeconds (266), 1, 0));
93  w.push_back (LteCellSelectionTestCase::UeSetup_t (0.5, 0.45, false,
94  MilliSeconds (346), 1, 3));
95  w.push_back (LteCellSelectionTestCase::UeSetup_t (0.5, 0.0, true,
96  MilliSeconds (266), 2, 4));
97  w.push_back (LteCellSelectionTestCase::UeSetup_t (1.0, 0.55, true,
98  MilliSeconds (266), 3, 0));
99  w.push_back (LteCellSelectionTestCase::UeSetup_t (1.0, 0.45, true,
100  MilliSeconds (266), 4, 0));
101 
102  AddTestCase (new LteCellSelectionTestCase ("EPC, ideal RRC, RngNum=1",
103  true, true, 60.0, w, 1),
104  // isd rngrun
106 
107 } // end of LteCellSelectionTestSuite::LteCellSelectionTestSuite ()
108 
109 
111 
112 
113 
114 /*
115  * Test Case
116  */
117 
118 
120  double relPosX, double relPosY, bool isCsgMember, Time checkPoint,
121  uint16_t expectedCellId1, uint16_t expectedCellId2)
122  : position (Vector (relPosX, relPosY, 0.0)),
123  isCsgMember (isCsgMember),
124  checkPoint (checkPoint),
125  expectedCellId1 (expectedCellId1),
126  expectedCellId2 (expectedCellId2)
127 {
128 }
129 
130 
132  std::string name, bool isEpcMode, bool isIdealRrc,
133  double interSiteDistance,
134  std::vector<UeSetup_t> ueSetupList, int64_t rngRun)
135  : TestCase (name),
136  m_isEpcMode (isEpcMode),
137  m_isIdealRrc (isIdealRrc),
138  m_interSiteDistance (interSiteDistance),
139  m_ueSetupList (ueSetupList),
140  m_rngRun (rngRun)
141 {
142  NS_LOG_FUNCTION (this << GetName ());
144 }
145 
146 
148 {
149  NS_LOG_FUNCTION (this << GetName ());
150 }
151 
152 
153 void
155 {
156  NS_LOG_FUNCTION (this << GetName ());
157 
159 
160  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
161  lteHelper->SetAttribute ("PathlossModel",
162  StringValue ("ns3::FriisSpectrumPropagationLossModel"));
163  lteHelper->SetAttribute ("UseIdealRrc", BooleanValue (m_isIdealRrc));
164 
165  Ptr<PointToPointEpcHelper> epcHelper;
166 
167  if (m_isEpcMode)
168  {
169  epcHelper = CreateObject<PointToPointEpcHelper> ();
170  lteHelper->SetEpcHelper (epcHelper);
171  }
172 
173  /*
174  * The topology is the following (the number on the node indicate the cell ID)
175  *
176  * [1] [3]
177  * non-CSG -- non-CSG
178  * | |
179  * | | 60 m
180  * | |
181  * [2] [4]
182  * CSG ------ CSG
183  * 60 m
184  */
185 
186  // Create Nodes
187  NodeContainer enbNodes;
188  enbNodes.Create (4);
189  NodeContainer ueNodes;
190  uint16_t nUe = m_ueSetupList.size ();
191  ueNodes.Create (nUe);
192 
193  // Assign nodes to position
194  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
195  // eNodeB
196  positionAlloc->Add (Vector ( 0.0, m_interSiteDistance, 0.0));
197  positionAlloc->Add (Vector ( 0.0, 0.0, 0.0));
198  positionAlloc->Add (Vector (m_interSiteDistance, m_interSiteDistance, 0.0));
199  positionAlloc->Add (Vector (m_interSiteDistance, 0.0, 0.0));
200  // UE
201  std::vector<UeSetup_t>::const_iterator itSetup;
202  for (itSetup = m_ueSetupList.begin ();
203  itSetup != m_ueSetupList.end (); itSetup++)
204  {
205  Vector uePos (m_interSiteDistance * itSetup->position.x,
206  m_interSiteDistance * itSetup->position.y,
207  m_interSiteDistance * itSetup->position.z);
208  NS_LOG_INFO ("UE position " << uePos);
209  positionAlloc->Add (uePos);
210  }
211 
212  MobilityHelper mobility;
213  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
214  mobility.SetPositionAllocator (positionAlloc);
215  mobility.Install (enbNodes);
216  mobility.Install (ueNodes);
217 
218  // Create Devices and install them in the Nodes (eNB and UE)
219  int64_t stream = 1;
220  NetDeviceContainer enbDevs;
221 
222  // cell ID 1 is a non-CSG cell
223  lteHelper->SetEnbDeviceAttribute ("CsgId", UintegerValue (0));
224  lteHelper->SetEnbDeviceAttribute ("CsgIndication", BooleanValue (false));
225  enbDevs.Add (lteHelper->InstallEnbDevice (enbNodes.Get (0)));
226 
227  // cell ID 2 is a CSG cell
228  lteHelper->SetEnbDeviceAttribute ("CsgId", UintegerValue (1));
229  lteHelper->SetEnbDeviceAttribute ("CsgIndication", BooleanValue (true));
230  enbDevs.Add (lteHelper->InstallEnbDevice (enbNodes.Get (1)));
231 
232  // cell ID 3 is a non-CSG cell
233  lteHelper->SetEnbDeviceAttribute ("CsgId", UintegerValue (0));
234  lteHelper->SetEnbDeviceAttribute ("CsgIndication", BooleanValue (false));
235  enbDevs.Add (lteHelper->InstallEnbDevice (enbNodes.Get (2)));
236 
237  // cell ID 4 is a CSG cell
238  lteHelper->SetEnbDeviceAttribute ("CsgId", UintegerValue (1));
239  lteHelper->SetEnbDeviceAttribute ("CsgIndication", BooleanValue (true));
240  enbDevs.Add (lteHelper->InstallEnbDevice (enbNodes.Get (3)));
241 
242  NetDeviceContainer ueDevs;
243  Time lastCheckPoint = MilliSeconds (0);
244  NS_ASSERT (m_ueSetupList.size () == ueNodes.GetN ());
246  for (itSetup = m_ueSetupList.begin (), itNode = ueNodes.Begin ();
247  itSetup != m_ueSetupList.end () || itNode != ueNodes.End ();
248  itSetup++, itNode++)
249  {
250  if (itSetup->isCsgMember)
251  {
252  lteHelper->SetUeDeviceAttribute ("CsgId", UintegerValue (1));
253  }
254  else
255  {
256  lteHelper->SetUeDeviceAttribute ("CsgId", UintegerValue (0));
257  }
258 
259  NetDeviceContainer devs = lteHelper->InstallUeDevice (*itNode);
260  Ptr<LteUeNetDevice> ueDev = devs.Get (0)->GetObject<LteUeNetDevice> ();
261  NS_ASSERT (ueDev != 0);
262  ueDevs.Add (devs);
263  Simulator::Schedule (itSetup->checkPoint,
265  this, ueDev,
266  itSetup->expectedCellId1, itSetup->expectedCellId2);
267 
268  if (lastCheckPoint < itSetup->checkPoint)
269  {
270  lastCheckPoint = itSetup->checkPoint;
271  }
272  }
273 
274  stream += lteHelper->AssignStreams (enbDevs, stream);
275  stream += lteHelper->AssignStreams (ueDevs, stream);
276 
277  // Tests
278  NS_ASSERT (m_ueSetupList.size () == ueDevs.GetN ());
280  for (itSetup = m_ueSetupList.begin (), itDev = ueDevs.Begin ();
281  itSetup != m_ueSetupList.end () || itDev != ueDevs.End ();
282  itSetup++, itDev++)
283  {
284  Ptr<LteUeNetDevice> ueDev = (*itDev)->GetObject<LteUeNetDevice> ();
285  }
286 
287  if (m_isEpcMode)
288  {
289  // Create P-GW node
290  Ptr<Node> pgw = epcHelper->GetPgwNode ();
291 
292  // Create a single RemoteHost
293  NodeContainer remoteHostContainer;
294  remoteHostContainer.Create (1);
295  Ptr<Node> remoteHost = remoteHostContainer.Get (0);
296  InternetStackHelper internet;
297  internet.Install (remoteHostContainer);
298 
299  // Create the Internet
300  PointToPointHelper p2ph;
301  p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
302  p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500));
303  p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.010)));
304  NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
305  Ipv4AddressHelper ipv4h;
306  ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
307  Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices);
308 
309  // Routing of the Internet Host (towards the LTE network)
310  Ipv4StaticRoutingHelper ipv4RoutingHelper;
311  Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
312  remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1);
313 
314  // Install the IP stack on the UEs
315  internet.Install (ueNodes);
316  Ipv4InterfaceContainer ueIpIfaces;
317  ueIpIfaces = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueDevs));
318 
319  // Assign IP address to UEs
320  for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
321  {
322  Ptr<Node> ueNode = ueNodes.Get (u);
323  // Set the default gateway for the UE
324  Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv4> ());
325  ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1);
326  }
327 
328  } // end of if (m_isEpcMode)
329  else
330  {
331  NS_FATAL_ERROR ("No support yet for LTE-only simulations");
332  }
333 
334  // Connect to trace sources in UEs
335  Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/StateTransition",
337  this));
338  Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/InitialCellSelectionEndOk",
340  this));
341  Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/InitialCellSelectionEndError",
343  this));
344  Config::Connect ("/NodeList/*/DeviceList/*/LteUeRrc/ConnectionEstablished",
346  this));
347 
348  // Enable Idle mode cell selection
349  lteHelper->Attach (ueDevs);
350 
351  // Run simulation
352  Simulator::Stop (lastCheckPoint);
353  Simulator::Run ();
354 
355  NS_LOG_INFO ("Simulation ends");
357 
358 } // end of void LteCellSelectionTestCase::DoRun ()
359 
360 
361 void
363  uint16_t expectedCellId1,
364  uint16_t expectedCellId2)
365 {
366  uint16_t actualCellId = ueDev->GetRrc ()->GetCellId ();
367 
368  if (expectedCellId2 == 0)
369  {
370  NS_TEST_ASSERT_MSG_EQ (actualCellId, expectedCellId1,
371  "IMSI " << ueDev->GetImsi ()
372  << " has attached to an unexpected cell");
373  }
374  else
375  {
376  bool pass = (actualCellId == expectedCellId1) ||
377  (actualCellId == expectedCellId2);
378  NS_TEST_ASSERT_MSG_EQ (pass, true,
379  "IMSI " << ueDev->GetImsi ()
380  << " has attached to an unexpected cell"
381  << " (actual: " << actualCellId << ","
382  << " expected: " << expectedCellId1
383  << " or " << expectedCellId2 << ")");
384  }
385 
386  if (expectedCellId1 > 0)
387  {
388  NS_TEST_ASSERT_MSG_EQ (m_lastState.at (ueDev->GetImsi () - 1),
390  "UE " << ueDev->GetImsi ()
391  << " is not at CONNECTED_NORMALLY state");
392  }
393 }
394 
395 
396 void
398  std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti,
399  LteUeRrc::State oldState, LteUeRrc::State newState)
400 {
401  NS_LOG_FUNCTION (this << imsi << cellId << rnti << oldState << newState);
402  m_lastState.at (imsi - 1) = newState;
403 }
404 
405 
406 void
408  std::string context, uint64_t imsi, uint16_t cellId)
409 {
410  NS_LOG_FUNCTION (this << imsi << cellId);
411 }
412 
413 
414 void
416  std::string context, uint64_t imsi, uint16_t cellId)
417 {
418  NS_LOG_FUNCTION (this << imsi << cellId);
419 }
420 
421 
422 void
424  std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti)
425 {
426  NS_LOG_FUNCTION (this << imsi << cellId << rnti);
427 }
428 
429 
430 
431 } // end of namespace ns3
Iterator Begin(void) const
Get an iterator which refers to the first NetDevice in the container.
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
void StateTransitionCallback(std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti, LteUeRrc::State oldState, LteUeRrc::State newState)
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
NS_LOG_COMPONENT_DEFINE("LteCellSelectionTest")
Hold a bool native type.
Definition: boolean.h:38
holds a vector of std::pair of Ptr and interface index.
std::vector< Ptr< Node > >::const_iterator Iterator
hold variables of type string
Definition: string.h:19
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
NetDeviceContainer Install(NodeContainer c)
std::vector< LteUeRrc::State > m_lastState
The current UE RRC state.
a class to represent an Ipv4 address mask
Definition: ipv4-address.h:210
A suite of tests to run.
Definition: test.h:1025
#define NS_ASSERT(condition)
Definition: assert.h:64
static void Run(void)
Run the simulation until one of:
Definition: simulator.cc:157
Hold a signed integer type.
Definition: integer.h:45
aggregate IP/TCP/UDP functionality to existing Nodes.
UeSetup_t(double relPosX, double relPosY, bool isCsgMember, Time checkPoint, uint16_t expectedCellId1, uint16_t expectedCellId2)
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
#define NS_LOG_INFO(msg)
Definition: log.h:298
Build a set of PointToPointNetDevice objects.
encapsulates test code
Definition: test.h:849
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:824
Testing the initial cell selection procedure by UE at IDLE state in the beginning of simulation...
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:728
void SetDeviceAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each NetDevice created by the helper.
a 3d vector
Definition: vector.h:31
void ConnectionEstablishedCallback(std::string context, uint64_t imsi, uint16_t cellId, uint16_t rnti)
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
uint32_t GetN(void) const
Get the number of Ptr stored in this container.
uint32_t GetN(void) const
Get the number of Ptr stored in this container.
Class for representing data rates.
Definition: data-rate.h:71
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
LteCellSelectionTestCase(std::string name, bool isEpcMode, bool isIdealRrc, double interSiteDistance, std::vector< UeSetup_t > ueSetupList, int64_t rngRun)
Creates an instance of the initial cell selection test case.
hold objects of type ns3::Time
Definition: nstime.h:961
void Add(NetDeviceContainer other)
Append the contents of another NetDeviceContainer to the end of this container.
Hold an unsigned integer type.
Definition: uinteger.h:46
holds a vector of ns3::NetDevice pointers
void CheckPoint(Ptr< LteUeNetDevice > ueDev, uint16_t expectedCellId1, uint16_t expectedCellId2)
Verifies if the given UE is attached to either of the given two cells and in a CONNECTED_NORMALLY sta...
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1238
void InitialCellSelectionEndOkCallback(std::string context, uint64_t imsi, uint16_t cellId)
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
void InitialCellSelectionEndErrorCallback(std::string context, uint64_t imsi, uint16_t cellId)
Access to the Ipv4 forwarding table, interfaces, and configuration.
Definition: ipv4.h:75
keep track of a set of node pointers.
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
void SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
void Install(std::string nodeName) const
Aggregate implementations of the ns3::Ipv4, ns3::Ipv6, ns3::Udp, and ns3::Tcp classes onto the provid...
static LteCellSelectionTestSuite g_lteCellSelectionTestSuite
std::vector< UeSetup_t > m_ueSetupList
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition: test.cc:173
void SetChannelAttribute(std::string name, const AttributeValue &value)
Set an attribute value to be propagated to each Channel created by the helper.
Fast test.
Definition: test.h:857
State
The states of the UE RRC entity.
Definition: lte-ue-rrc.h:86
Helper class used to assign positions and mobility models to nodes.
Ipv4 addresses are stored in host order in this class.
Definition: ipv4-address.h:38
Ipv4InterfaceContainer Assign(const NetDeviceContainer &c)
Assign IP addresses to the net devices specified in the container based on the current network prefix...
Ptr< Ipv4StaticRouting > GetStaticRouting(Ptr< Ipv4 > ipv4) const
Try and find the static routing protocol as either the main routing protocol or in the list of routin...
Helper class that adds ns3::Ipv4StaticRouting objects.
hold objects of type ns3::DataRate
static void Stop(void)
If an event invokes this method, it will be the last event scheduled by the Simulator::run method bef...
Definition: simulator.cc:165
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
std::vector< Ptr< NetDevice > >::const_iterator Iterator
A set of input parameters for setting up a UE in the simulation.
Test suite for executing the cell selection test cases in without-EPC and with-EPC scenarios...
std::string GetName(void) const
Definition: test.cc:242
A helper class to make life easier while doing simple IPv4 address assignment in scripts.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
Iterator End(void) const
Get an iterator which indicates past-the-last NetDevice in the container.
Ptr< T > GetObject(void) const
Definition: object.h:361
void SetGlobal(std::string name, const AttributeValue &value)
Definition: config.cc:707
virtual void DoRun()
Setup the simulation according to the configuration set by the class constructor, run it...
void SetBase(Ipv4Address network, Ipv4Mask mask, Ipv4Address base="0.0.0.1")
Set the base network number, network mask and base address.
#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:137
The LteUeNetDevice class implements the UE net device.