A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lte-test-mimo.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
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: Marco Miozzo <marco.miozzo@cttc.es>
19  */
20 
21 #include <iostream>
22 #include <sstream>
23 #include <string>
24 
25 #include <ns3/object.h>
26 #include <ns3/spectrum-interference.h>
27 #include <ns3/spectrum-error-model.h>
28 #include <ns3/log.h>
29 #include <ns3/test.h>
30 #include <ns3/simulator.h>
31 #include <ns3/packet.h>
32 #include <ns3/ptr.h>
33 #include <iostream>
34 #include "ns3/radio-bearer-stats-calculator.h"
35 #include <ns3/mobility-building-info.h>
36 #include <ns3/buildings-propagation-loss-model.h>
37 #include <ns3/eps-bearer.h>
38 #include <ns3/node-container.h>
39 #include <ns3/mobility-helper.h>
40 #include <ns3/net-device-container.h>
41 #include <ns3/lte-ue-net-device.h>
42 #include <ns3/lte-enb-net-device.h>
43 #include <ns3/lte-ue-rrc.h>
44 #include <ns3/lte-helper.h>
45 #include "ns3/string.h"
46 #include "ns3/double.h"
47 #include <ns3/lte-enb-phy.h>
48 #include <ns3/lte-ue-phy.h>
49 #include <ns3/boolean.h>
50 #include <ns3/rr-ff-mac-scheduler.h>
51 #include <ns3/pf-ff-mac-scheduler.h>
52 #include <ns3/pointer.h>
53 #include <ns3/enum.h>
54 #include <ns3/buildings-helper.h>
55 
56 #include "lte-test-mimo.h"
57 
58 
59 NS_LOG_COMPONENT_DEFINE ("LteTestMimo");
60 
61 namespace ns3 {
62 
63 
65  : TestSuite ("lte-mimo", SYSTEM)
66 {
67  NS_LOG_INFO ("creating LenaMimoTestCase");
68 
69  // RR DOWNLINK- DISTANCE 300
70  // interval 1 : [0.1, 0.2) sec TxMode 0: MCS 20 -> TB size 1191 bytes
71  // interval 2 : [0.3, 0.4) sec TxMode 1: MCS 26 -> TB size 1836 bytes
72  // interval 3 : [0.5, 0.6) sec TxMode 2: MCS 18 -> TB size 967 bytes (x2 layers)
73  // -->
74  std::vector<uint32_t> estThrDl;
75  estThrDl.push_back (119100); // interval 1 : estimated throughput for TxMode 1
76  estThrDl.push_back (183600); // interval 2 : estimated throughput for TxMode 2
77  estThrDl.push_back (193400); // interval 3 : estimated throughput for TxMode 3
78  AddTestCase (new LenaMimoTestCase(300, estThrDl, "ns3::RrFfMacScheduler", true), TestCase::QUICK);
79  AddTestCase (new LenaMimoTestCase(300, estThrDl, "ns3::PfFfMacScheduler", true), TestCase::QUICK);
80  AddTestCase (new LenaMimoTestCase(300, estThrDl, "ns3::RrFfMacScheduler", false), TestCase::QUICK);
81  AddTestCase (new LenaMimoTestCase(300, estThrDl, "ns3::PfFfMacScheduler", false), TestCase::QUICK);
82 
83 }
84 
86 
87 std::string
88 LenaMimoTestCase::BuildNameString (uint16_t dist, std::string schedulerType, bool useIdealRrc)
89 {
90  std::ostringstream oss;
91  oss << " UE distance " << dist << " m" << " Scheduler " << schedulerType;
92  if (useIdealRrc)
93  {
94  oss << ", ideal RRC";
95  }
96  else
97  {
98  oss << ", real RRC";
99  }
100  return oss.str ();
101 }
102 
103 LenaMimoTestCase::LenaMimoTestCase (uint16_t dist, std::vector<uint32_t> estThrDl, std::string schedulerType, bool useIdealRrc)
104  : TestCase (BuildNameString (dist, schedulerType, useIdealRrc)),
105  m_dist (dist),
106  m_estThrDl (estThrDl),
107  m_schedulerType (schedulerType),
108  m_useIdealRrc (useIdealRrc)
109 {
110 }
111 
113 {
114 }
115 
116 void
118 {
119  NS_LOG_FUNCTION (this << GetName ());
120  Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (false));
121  Config::SetDefault ("ns3::LteAmc::AmcModel", EnumValue (LteAmc::PiroEW2010));
122  Config::SetDefault ("ns3::LteHelper::UseIdealRrc", BooleanValue (m_useIdealRrc));
123 
129  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
130  Config::SetDefault ("ns3::RrFfMacScheduler::HarqEnabled", BooleanValue (false));
131  Config::SetDefault ("ns3::PfFfMacScheduler::HarqEnabled", BooleanValue (false));
132 
133 // lteHelper->SetSchedulerAttribute ("HarqEnabled", BooleanValue (false));
134 
135 
136  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::HybridBuildingsPropagationLossModel"));
137  lteHelper->SetPathlossModelAttribute ("ShadowSigmaOutdoor", DoubleValue (0.0));
138  lteHelper->SetPathlossModelAttribute ("ShadowSigmaIndoor", DoubleValue (0.0));
139  lteHelper->SetPathlossModelAttribute ("ShadowSigmaExtWalls", DoubleValue (0.0));
140 
141 // lteHelper->EnableLogComponents ();
142 
143  // Create Nodes: eNodeB and UE
144  NodeContainer enbNodes;
145  NodeContainer ueNodes;
146  enbNodes.Create (1);
147  ueNodes.Create (1);
148 
149  // Install Mobility Model
150  MobilityHelper mobility;
151  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
152  mobility.Install (enbNodes);
153  BuildingsHelper::Install (enbNodes);
154  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
155  mobility.Install (ueNodes);
156  BuildingsHelper::Install (ueNodes);
157 
158  // Create Devices and install them in the Nodes (eNB and UE)
159  NetDeviceContainer enbDevs;
160  NetDeviceContainer ueDevs;
161  lteHelper->SetSchedulerType (m_schedulerType);
162  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
163  ueDevs = lteHelper->InstallUeDevice (ueNodes);
164 
165  // Attach a UE to a eNB
166  lteHelper->Attach (ueDevs, enbDevs.Get (0));
167 
168  // Activate an EPS bearer
170  EpsBearer bearer (q);
171  lteHelper->ActivateDataRadioBearer (ueDevs, bearer);
172 
173 
174  Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ();
175  Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy ();
176  enbPhy->SetAttribute ("TxPower", DoubleValue (46.0));
177  enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0));
178  Ptr<MobilityModel> mmenb = enbNodes.Get (0)->GetObject<MobilityModel> ();
179  mmenb->SetPosition (Vector (0.0, 0.0, 30.0));
180 
181  // Set UE's position and power
182  Ptr<MobilityModel> mmue = ueNodes.Get (0)->GetObject<MobilityModel> ();
183  mmue->SetPosition (Vector (m_dist, 0.0, 1.0));
184  Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (0)->GetObject<LteUeNetDevice> ();
185  Ptr<LteUePhy> uePhy = lteUeDev->GetPhy ();
186  uePhy->SetAttribute ("TxPower", DoubleValue (23.0));
187  uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0));
188 
189  // need to allow for RRC connection establishment + SRS before enabling traces
190  lteHelper->EnableRlcTraces ();
191  lteHelper->EnableMacTraces ();
192  double simulationTime = 0.6;
193  double tolerance = 0.1;
194 
195  uint8_t rnti = 1;
196  Ptr<LteEnbNetDevice> enbNetDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ();
197 
198  PointerValue ptrval;
199  enbNetDev->GetAttribute ("FfMacScheduler", ptrval);
200  Ptr<PfFfMacScheduler> pfsched;
201  Ptr<RrFfMacScheduler> rrsched;
202  if (m_schedulerType.compare ("ns3::RrFfMacScheduler") == 0)
203  {
204  rrsched = ptrval.Get<RrFfMacScheduler> ();
205  if (rrsched == 0)
206  {
207  NS_FATAL_ERROR ("No RR Scheduler available");
208  }
211  }
212  else if (m_schedulerType.compare ("ns3::PfFfMacScheduler") == 0)
213  {
214  pfsched = ptrval.Get<PfFfMacScheduler> ();
215  if (pfsched == 0)
216  {
217  NS_FATAL_ERROR ("No Pf Scheduler available");
218  }
219 
222  }
223  else
224  {
225  NS_FATAL_ERROR ("Scheduler not supported by this test");
226  }
227 
228 
229  Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats ();
230  rlcStats->SetAttribute ("EpochDuration", TimeValue (Seconds (0.1)));
231 
232  NS_LOG_INFO (m_schedulerType << " MIMO test:");
233  double sampleTime = 0.199999; // at 0.2 RlcStats are reset
234  for (uint8_t j = 0; j < m_estThrDl.size (); j ++)
235  {
236  NS_LOG_INFO ("\t test with user at distance " << m_dist << " time " << sampleTime);
237  // get the imsi
238  uint64_t imsi = ueDevs.Get (0)->GetObject<LteUeNetDevice> ()->GetImsi ();
239  uint8_t lcId = 3;
240  Time t = Seconds (sampleTime);
241  Simulator::Schedule(t, &LenaMimoTestCase::GetRlcBufferSample, this, rlcStats, imsi, lcId);
242  sampleTime += 0.2;
243  }
244  Simulator::Stop (Seconds (simulationTime));
245  Simulator::Run ();
247 
248  NS_LOG_INFO ("Check consistency");
249  for (uint8_t i = 0; i < m_estThrDl.size (); i++)
250  {
251  NS_LOG_INFO ("interval " << i + 1 << ": bytes rxed " << (double)m_dlDataRxed.at (i) << " ref " << m_estThrDl.at (i));
252  NS_TEST_ASSERT_MSG_EQ_TOL ((double)m_dlDataRxed.at (i) , m_estThrDl.at (i), m_estThrDl.at (i) * tolerance, " Unfair Throughput!");
253  }
254 
255 }
256 
257 
258 void
260 {
261  m_dlDataRxed.push_back (rlcStats->GetDlRxData (imsi, lcId));
262  NS_LOG_INFO (Simulator::Now () << "\t get bytes " << m_dlDataRxed.at (m_dlDataRxed.size () - 1));
263 }
264 
265 
266 
267 } // namespace ns3
268 
std::vector< uint64_t > m_dlDataRxed
Definition: lte-test-mimo.h:51
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
LenaMimoTestCase(uint16_t dist, std::vector< uint32_t > estThrDl, std::string schedulerType, bool useIdealRrc)
Hold a bool native type.
Definition: boolean.h:38
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.
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
Definition: test.h:326
A suite of tests to run.
Definition: test.h:1025
Implements the SCHED SAP and CSCHED SAP for a Proportional Fair scheduler.
static void Run(void)
Run the simulation until one of:
Definition: simulator.cc:157
#define NS_LOG_INFO(msg)
Definition: log.h:298
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
std::string m_schedulerType
Definition: lte-test-mimo.h:48
a 3d vector
Definition: vector.h:31
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
void TransmissionModeConfigurationUpdate(uint16_t rnti, uint8_t txMode)
NS_LOG_COMPONENT_DEFINE("LteTestMimo")
Keep track of the current position and velocity of an object.
This class contains the specification of EPS Bearers.
Definition: eps-bearer.h:71
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
hold variables of type 'enum'
Definition: enum.h:37
hold objects of type ns3::Time
Definition: nstime.h:961
holds a vector of ns3::NetDevice pointers
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
std::vector< uint32_t > m_estThrDl
Definition: lte-test-mimo.h:47
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:667
keep track of a set of node pointers.
hold objects of type Ptr
Definition: pointer.h:33
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())
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition: test.cc:173
static LenaTestMimoSuite lenaTestMimoSuite
void SetPosition(const Vector &position)
void GetRlcBufferSample(Ptr< RadioBearerStatsCalculator > rlcStats, uint64_t imsi, uint8_t rnti)
Fast test.
Definition: test.h:857
Helper class used to assign positions and mobility models to nodes.
This system test program creates different test cases with a single eNB...
Definition: lte-test-mimo.h:34
Implements the SCHED SAP and CSCHED SAP for a Round Robin scheduler.
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.
virtual void DoRun(void)
Implementation to actually run this TestCase.
static std::string BuildNameString(uint16_t dist, std::string schedulerType, bool useIdealRrc)
std::string GetName(void) const
Definition: test.cc:242
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void TransmissionModeConfigurationUpdate(uint16_t rnti, uint8_t txMode)
Hold a floating point type.
Definition: double.h:41
The eNodeB device implementation.
Ptr< T > GetObject(void) const
Definition: object.h:361
Qci
QoS Class Indicator.
Definition: eps-bearer.h:77
static void Install(Ptr< Node > node)
Install the MobilityBuildingInfo to a node.
The LteUeNetDevice class implements the UE net device.