A Discrete-Event Network Simulator
API
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 using namespace ns3;
60 
61 NS_LOG_COMPONENT_DEFINE ("LteTestMimo");
62 
64  : TestSuite ("lte-mimo", SYSTEM)
65 {
66  NS_LOG_INFO ("creating LenaMimoTestCase");
67 
68  // RR DOWNLINK- DISTANCE 300
69  // interval 1 : [0.1, 0.2) sec TxMode 0: MCS 20 -> TB size 1191 bytes
70  // interval 2 : [0.3, 0.4) sec TxMode 1: MCS 26 -> TB size 1836 bytes
71  // interval 3 : [0.5, 0.6) sec TxMode 2: MCS 18 -> TB size 967 bytes (x2 layers)
72  // -->
73  std::vector<uint32_t> estThrDl;
74  estThrDl.push_back (119100); // interval 1 : estimated throughput for TxMode 1
75  estThrDl.push_back (183600); // interval 2 : estimated throughput for TxMode 2
76  estThrDl.push_back (193400); // interval 3 : estimated throughput for TxMode 3
77  AddTestCase (new LenaMimoTestCase(300, estThrDl, "ns3::RrFfMacScheduler", true), TestCase::QUICK);
78  AddTestCase (new LenaMimoTestCase(300, estThrDl, "ns3::PfFfMacScheduler", true), TestCase::QUICK);
79  AddTestCase (new LenaMimoTestCase(300, estThrDl, "ns3::RrFfMacScheduler", false), TestCase::QUICK);
80  AddTestCase (new LenaMimoTestCase(300, estThrDl, "ns3::PfFfMacScheduler", false), TestCase::QUICK);
81 
82 }
83 
85 
86 std::string
87 LenaMimoTestCase::BuildNameString (uint16_t dist, std::string schedulerType, bool useIdealRrc)
88 {
89  std::ostringstream oss;
90  oss << " UE distance " << dist << " m" << " Scheduler " << schedulerType;
91  if (useIdealRrc)
92  {
93  oss << ", ideal RRC";
94  }
95  else
96  {
97  oss << ", real RRC";
98  }
99  return oss.str ();
100 }
101 
102 LenaMimoTestCase::LenaMimoTestCase (uint16_t dist, std::vector<uint32_t> estThrDl, std::string schedulerType, bool useIdealRrc)
103  : TestCase (BuildNameString (dist, schedulerType, useIdealRrc)),
104  m_dist (dist),
105  m_estThrDl (estThrDl),
106  m_schedulerType (schedulerType),
107  m_useIdealRrc (useIdealRrc)
108 {
109 }
110 
112 {
113 }
114 
115 void
117 {
118  NS_LOG_FUNCTION (this << GetName ());
119  Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (false));
120  Config::SetDefault ("ns3::LteAmc::AmcModel", EnumValue (LteAmc::PiroEW2010));
121  Config::SetDefault ("ns3::LteHelper::UseIdealRrc", BooleanValue (m_useIdealRrc));
122 
123  //Disable Uplink Power Control
124  Config::SetDefault ("ns3::LteUePhy::EnableUplinkPowerControl", BooleanValue (false));
125 
131  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
132  Config::SetDefault ("ns3::RrFfMacScheduler::HarqEnabled", BooleanValue (false));
133  Config::SetDefault ("ns3::PfFfMacScheduler::HarqEnabled", BooleanValue (false));
134 
135 // lteHelper->SetSchedulerAttribute ("HarqEnabled", BooleanValue (false));
136 
137 
138  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::HybridBuildingsPropagationLossModel"));
139  lteHelper->SetPathlossModelAttribute ("ShadowSigmaOutdoor", DoubleValue (0.0));
140  lteHelper->SetPathlossModelAttribute ("ShadowSigmaIndoor", DoubleValue (0.0));
141  lteHelper->SetPathlossModelAttribute ("ShadowSigmaExtWalls", DoubleValue (0.0));
142 
143 // lteHelper->EnableLogComponents ();
144 
145  // Create Nodes: eNodeB and UE
146  NodeContainer enbNodes;
147  NodeContainer ueNodes;
148  enbNodes.Create (1);
149  ueNodes.Create (1);
150 
151  // Install Mobility Model
153  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
154  mobility.Install (enbNodes);
155  BuildingsHelper::Install (enbNodes);
156  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
157  mobility.Install (ueNodes);
158  BuildingsHelper::Install (ueNodes);
159 
160  // Create Devices and install them in the Nodes (eNB and UE)
161  NetDeviceContainer enbDevs;
162  NetDeviceContainer ueDevs;
163  lteHelper->SetSchedulerType (m_schedulerType);
164  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
165  ueDevs = lteHelper->InstallUeDevice (ueNodes);
166 
167  // Attach a UE to a eNB
168  lteHelper->Attach (ueDevs, enbDevs.Get (0));
169 
170  // Activate an EPS bearer
171  enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE;
172  EpsBearer bearer (q);
173  lteHelper->ActivateDataRadioBearer (ueDevs, bearer);
174 
175 
176  Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ();
177  Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy ();
178  enbPhy->SetAttribute ("TxPower", DoubleValue (46.0));
179  enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0));
180  Ptr<MobilityModel> mmenb = enbNodes.Get (0)->GetObject<MobilityModel> ();
181  mmenb->SetPosition (Vector (0.0, 0.0, 30.0));
182 
183  // Set UE's position and power
184  Ptr<MobilityModel> mmue = ueNodes.Get (0)->GetObject<MobilityModel> ();
185  mmue->SetPosition (Vector (m_dist, 0.0, 1.0));
186  Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (0)->GetObject<LteUeNetDevice> ();
187  Ptr<LteUePhy> uePhy = lteUeDev->GetPhy ();
188  uePhy->SetAttribute ("TxPower", DoubleValue (23.0));
189  uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0));
190 
191  // need to allow for RRC connection establishment + SRS before enabling traces
192  lteHelper->EnableRlcTraces ();
193  lteHelper->EnableMacTraces ();
194  double simulationTime = 0.6;
195  double tolerance = 0.1;
196 
197  uint8_t rnti = 1;
198  Ptr<LteEnbNetDevice> enbNetDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ();
199 
200  PointerValue ptrval;
201  enbNetDev->GetAttribute ("FfMacScheduler", ptrval);
202  Ptr<PfFfMacScheduler> pfsched;
203  Ptr<RrFfMacScheduler> rrsched;
204  if (m_schedulerType.compare ("ns3::RrFfMacScheduler") == 0)
205  {
206  rrsched = ptrval.Get<RrFfMacScheduler> ();
207  if (rrsched == 0)
208  {
209  NS_FATAL_ERROR ("No RR Scheduler available");
210  }
211  Simulator::Schedule (Seconds (0.2), &RrFfMacScheduler::TransmissionModeConfigurationUpdate, rrsched, rnti, 1);
212  Simulator::Schedule (Seconds (0.4), &RrFfMacScheduler::TransmissionModeConfigurationUpdate, rrsched, rnti, 2);
213  }
214  else if (m_schedulerType.compare ("ns3::PfFfMacScheduler") == 0)
215  {
216  pfsched = ptrval.Get<PfFfMacScheduler> ();
217  if (pfsched == 0)
218  {
219  NS_FATAL_ERROR ("No Pf Scheduler available");
220  }
221 
222  Simulator::Schedule (Seconds (0.2), &PfFfMacScheduler::TransmissionModeConfigurationUpdate, pfsched, rnti, 1);
223  Simulator::Schedule (Seconds (0.4), &PfFfMacScheduler::TransmissionModeConfigurationUpdate, pfsched, rnti, 2);
224  }
225  else
226  {
227  NS_FATAL_ERROR ("Scheduler not supported by this test");
228  }
229 
230 
231  Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats ();
232  rlcStats->SetAttribute ("EpochDuration", TimeValue (Seconds (0.1)));
233 
234  NS_LOG_INFO (m_schedulerType << " MIMO test:");
235  double sampleTime = 0.199999; // at 0.2 RlcStats are reset
236  for (uint8_t j = 0; j < m_estThrDl.size (); j ++)
237  {
238  NS_LOG_INFO ("\t test with user at distance " << m_dist << " time " << sampleTime);
239  // get the imsi
240  uint64_t imsi = ueDevs.Get (0)->GetObject<LteUeNetDevice> ()->GetImsi ();
241  uint8_t lcId = 3;
242  Time t = Seconds (sampleTime);
243  Simulator::Schedule(t, &LenaMimoTestCase::GetRlcBufferSample, this, rlcStats, imsi, lcId);
244  sampleTime += 0.2;
245  }
246  Simulator::Stop (Seconds (simulationTime));
247  Simulator::Run ();
248  Simulator::Destroy ();
249 
250  NS_LOG_INFO ("Check consistency");
251  for (uint8_t i = 0; i < m_estThrDl.size (); i++)
252  {
253  NS_LOG_INFO ("interval " << i + 1 << ": bytes rxed " << (double)m_dlDataRxed.at (i) << " ref " << m_estThrDl.at (i));
254  NS_TEST_ASSERT_MSG_EQ_TOL ((double)m_dlDataRxed.at (i) , m_estThrDl.at (i), m_estThrDl.at (i) * tolerance, " Unfair Throughput!");
255  }
256 
257 }
258 
259 
260 void
262 {
263  m_dlDataRxed.push_back (rlcStats->GetDlRxData (imsi, lcId));
264  NS_LOG_INFO (Simulator::Now () << "\t get bytes " << m_dlDataRxed.at (m_dlDataRxed.size () - 1));
265 }
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
void SetPathlossModelAttribute(std::string n, const AttributeValue &v)
Set an attribute for the path loss models to be created.
Definition: lte-helper.cc:299
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
std::string m_schedulerType
Definition: lte-test-mimo.h:48
AttributeValue implementation for Boolean.
Definition: boolean.h:34
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Create a set of eNodeB devices.
Definition: lte-helper.cc:382
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:462
Hold variables of type string.
Definition: string.h:41
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
A suite of tests to run.
Definition: test.h:1333
LenaMimoTestCase(uint16_t dist, std::vector< uint32_t > estThrDl, std::string schedulerType, bool useIdealRrc)
Implements the SCHED SAP and CSCHED SAP for a Proportional Fair scheduler.
Ptr< LteEnbPhy > GetPhy(void) const
virtual ~LenaMimoTestCase()
std::vector< uint32_t > m_estThrDl
Definition: lte-test-mimo.h:47
void Attach(NetDeviceContainer ueDevices)
Enables automatic attachment of a set of UE devices to a suitable cell using Idle mode initial cell s...
Definition: lte-helper.cc:716
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
void EnableRlcTraces(void)
Enable trace sinks for RLC layer.
Definition: lte-helper.cc:1102
This system test program creates different test cases with a single eNB...
Definition: lte-test-mimo.h:34
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
encapsulates test code
Definition: test.h:1147
void ActivateDataRadioBearer(NetDeviceContainer ueDevices, EpsBearer bearer)
Activate a Data Radio Bearer on a given UE devices (for LTE-only simulation).
Definition: lte-helper.cc:1046
void SetSchedulerType(std::string type)
Set the type of scheduler to be used by eNodeB devices.
Definition: lte-helper.cc:225
virtual void DoRun(void)
Implementation to actually run this TestCase.
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.
tuple mobility
Definition: third.py:101
static LenaTestMimoSuite lenaTestMimoSuite
Hold variables of type enum.
Definition: enum.h:54
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:298
AttributeValue implementation for Time.
Definition: nstime.h:957
uint64_t GetDlRxData(uint64_t imsi, uint8_t lcid)
Gets the number of received downlink data bytes.
holds a vector of ns3::NetDevice pointers
#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:373
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
Hold objects of type Ptr.
Definition: pointer.h:36
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 GetRlcBufferSample(Ptr< RadioBearerStatsCalculator > rlcStats, uint64_t imsi, uint8_t rnti)
void GetAttribute(std::string name, AttributeValue &value) const
Get the value of an attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:229
void SetPosition(const Vector &position)
Ptr< RadioBearerStatsCalculator > GetRlcStats(void)
Definition: lte-helper.cc:1233
NetDeviceContainer InstallUeDevice(NodeContainer c)
Create a set of UE devices.
Definition: lte-helper.cc:397
Helper class used to assign positions and mobility models to nodes.
std::vector< uint64_t > m_dlDataRxed
Definition: lte-test-mimo.h:51
Implements the SCHED SAP and CSCHED SAP for a Round Robin scheduler.
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:774
std::string GetName(void) const
Definition: test.cc:369
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:340
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void EnableMacTraces(void)
Enable trace sinks for MAC layer.
Definition: lte-helper.cc:1190
Ptr< LteUePhy > GetPhy(void) const
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:191
The eNodeB device implementation.
Qci
QoS Class Indicator.
Definition: eps-bearer.h:77
static std::string BuildNameString(uint16_t dist, std::string schedulerType, bool useIdealRrc)
The LteUeNetDevice class implements the UE net device.