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 #include <ns3/object.h>
25 #include <ns3/spectrum-interference.h>
26 #include <ns3/spectrum-error-model.h>
27 #include <ns3/log.h>
28 #include <ns3/test.h>
29 #include <ns3/simulator.h>
30 #include <ns3/packet.h>
31 #include <ns3/ptr.h>
32 #include "ns3/radio-bearer-stats-calculator.h"
33 #include <ns3/mobility-building-info.h>
34 #include <ns3/buildings-propagation-loss-model.h>
35 #include <ns3/eps-bearer.h>
36 #include <ns3/node-container.h>
37 #include <ns3/mobility-helper.h>
38 #include <ns3/net-device-container.h>
39 #include <ns3/lte-ue-net-device.h>
40 #include <ns3/lte-enb-net-device.h>
41 #include <ns3/lte-ue-rrc.h>
42 #include <ns3/lte-helper.h>
43 #include "ns3/string.h"
44 #include "ns3/double.h"
45 #include <ns3/lte-enb-phy.h>
46 #include <ns3/lte-ue-phy.h>
47 #include <ns3/boolean.h>
48 #include <ns3/rr-ff-mac-scheduler.h>
49 #include <ns3/pf-ff-mac-scheduler.h>
50 #include <ns3/pointer.h>
51 #include <ns3/enum.h>
52 #include <ns3/buildings-helper.h>
53 #include "lte-test-mimo.h"
54 
55 
56 using namespace ns3;
57 
58 NS_LOG_COMPONENT_DEFINE ("LteTestMimo");
59 
61  : TestSuite ("lte-mimo", SYSTEM)
62 {
63  NS_LOG_INFO ("creating LenaMimoTestCase");
64 
65  // RR DOWNLINK- DISTANCE 300
66  // interval 1 : [0.1, 0.2) sec TxMode 0: MCS 20 -> TB size 1191 bytes
67  // interval 2 : [0.3, 0.4) sec TxMode 1: MCS 26 -> TB size 1836 bytes
68  // interval 3 : [0.5, 0.6) sec TxMode 2: MCS 18 -> TB size 967 bytes (x2 layers)
69  // -->
70  std::vector<uint32_t> estThrDl;
71  estThrDl.push_back (119100); // interval 1 : estimated throughput for TxMode 1
72  estThrDl.push_back (183600); // interval 2 : estimated throughput for TxMode 2
73  estThrDl.push_back (193400); // interval 3 : estimated throughput for TxMode 3
74  AddTestCase (new LenaMimoTestCase(300, estThrDl, "ns3::RrFfMacScheduler", true), TestCase::QUICK);
75  AddTestCase (new LenaMimoTestCase(300, estThrDl, "ns3::PfFfMacScheduler", true), TestCase::QUICK);
76  AddTestCase (new LenaMimoTestCase(300, estThrDl, "ns3::RrFfMacScheduler", false), TestCase::QUICK);
77  AddTestCase (new LenaMimoTestCase(300, estThrDl, "ns3::PfFfMacScheduler", false), TestCase::QUICK);
78 
79 }
80 
82 
83 std::string
84 LenaMimoTestCase::BuildNameString (uint16_t dist, std::string schedulerType, bool useIdealRrc)
85 {
86  std::ostringstream oss;
87  oss << " UE distance " << dist << " m" << " Scheduler " << schedulerType;
88  if (useIdealRrc)
89  {
90  oss << ", ideal RRC";
91  }
92  else
93  {
94  oss << ", real RRC";
95  }
96  return oss.str ();
97 }
98 
99 LenaMimoTestCase::LenaMimoTestCase (uint16_t dist, std::vector<uint32_t> estThrDl, std::string schedulerType, bool useIdealRrc)
100  : TestCase (BuildNameString (dist, schedulerType, useIdealRrc)),
101  m_dist (dist),
102  m_estThrDl (estThrDl),
103  m_schedulerType (schedulerType),
104  m_useIdealRrc (useIdealRrc)
105 {
106 }
107 
109 {
110 }
111 
112 void
114 {
115  NS_LOG_FUNCTION (this << GetName ());
116  Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (false));
117  Config::SetDefault ("ns3::LteAmc::AmcModel", EnumValue (LteAmc::PiroEW2010));
118  Config::SetDefault ("ns3::LteHelper::UseIdealRrc", BooleanValue (m_useIdealRrc));
119 
120  //Disable Uplink Power Control
121  Config::SetDefault ("ns3::LteUePhy::EnableUplinkPowerControl", BooleanValue (false));
122 
128  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
129  Config::SetDefault ("ns3::RrFfMacScheduler::HarqEnabled", BooleanValue (false));
130  Config::SetDefault ("ns3::PfFfMacScheduler::HarqEnabled", BooleanValue (false));
131 
132 // lteHelper->SetSchedulerAttribute ("HarqEnabled", BooleanValue (false));
133 
134 
135  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::HybridBuildingsPropagationLossModel"));
136  lteHelper->SetPathlossModelAttribute ("ShadowSigmaOutdoor", DoubleValue (0.0));
137  lteHelper->SetPathlossModelAttribute ("ShadowSigmaIndoor", DoubleValue (0.0));
138  lteHelper->SetPathlossModelAttribute ("ShadowSigmaExtWalls", DoubleValue (0.0));
139 
140 // lteHelper->EnableLogComponents ();
141 
142  // Create Nodes: eNodeB and UE
143  NodeContainer enbNodes;
144  NodeContainer ueNodes;
145  enbNodes.Create (1);
146  ueNodes.Create (1);
147 
148  // Install Mobility Model
150  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
151  mobility.Install (enbNodes);
152  BuildingsHelper::Install (enbNodes);
153  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
154  mobility.Install (ueNodes);
155  BuildingsHelper::Install (ueNodes);
156 
157  // Create Devices and install them in the Nodes (eNB and UE)
158  NetDeviceContainer enbDevs;
159  NetDeviceContainer ueDevs;
160  lteHelper->SetSchedulerType (m_schedulerType);
161  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
162  ueDevs = lteHelper->InstallUeDevice (ueNodes);
163 
164  // Attach a UE to a eNB
165  lteHelper->Attach (ueDevs, enbDevs.Get (0));
166 
167  // Activate an EPS bearer
168  enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE;
169  EpsBearer bearer (q);
170  lteHelper->ActivateDataRadioBearer (ueDevs, bearer);
171 
172 
173  Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ();
174  Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy ();
175  enbPhy->SetAttribute ("TxPower", DoubleValue (46.0));
176  enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0));
177  Ptr<MobilityModel> mmenb = enbNodes.Get (0)->GetObject<MobilityModel> ();
178  mmenb->SetPosition (Vector (0.0, 0.0, 30.0));
179 
180  // Set UE's position and power
181  Ptr<MobilityModel> mmue = ueNodes.Get (0)->GetObject<MobilityModel> ();
182  mmue->SetPosition (Vector (m_dist, 0.0, 1.0));
183  Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (0)->GetObject<LteUeNetDevice> ();
184  Ptr<LteUePhy> uePhy = lteUeDev->GetPhy ();
185  uePhy->SetAttribute ("TxPower", DoubleValue (23.0));
186  uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0));
187 
188  // need to allow for RRC connection establishment + SRS before enabling traces
189  lteHelper->EnableRlcTraces ();
190  lteHelper->EnableMacTraces ();
191  double simulationTime = 0.6;
192  double tolerance = 0.1;
193 
194  uint8_t rnti = 1;
195  Ptr<LteEnbNetDevice> enbNetDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ();
196 
197  PointerValue ptrval;
198  enbNetDev->GetCcMap()[0]->GetAttribute ("FfMacScheduler", ptrval);
199  Ptr<PfFfMacScheduler> pfsched;
200  Ptr<RrFfMacScheduler> rrsched;
201  if (m_schedulerType.compare ("ns3::RrFfMacScheduler") == 0)
202  {
203  rrsched = ptrval.Get<RrFfMacScheduler> ();
204  if (rrsched == 0)
205  {
206  NS_FATAL_ERROR ("No RR Scheduler available");
207  }
208  Simulator::Schedule (Seconds (0.2), &RrFfMacScheduler::TransmissionModeConfigurationUpdate, rrsched, rnti, 1);
209  Simulator::Schedule (Seconds (0.4), &RrFfMacScheduler::TransmissionModeConfigurationUpdate, rrsched, rnti, 2);
210  }
211  else if (m_schedulerType.compare ("ns3::PfFfMacScheduler") == 0)
212  {
213  pfsched = ptrval.Get<PfFfMacScheduler> ();
214  if (pfsched == 0)
215  {
216  NS_FATAL_ERROR ("No Pf Scheduler available");
217  }
218 
219  Simulator::Schedule (Seconds (0.2), &PfFfMacScheduler::TransmissionModeConfigurationUpdate, pfsched, rnti, 1);
220  Simulator::Schedule (Seconds (0.4), &PfFfMacScheduler::TransmissionModeConfigurationUpdate, pfsched, rnti, 2);
221  }
222  else
223  {
224  NS_FATAL_ERROR ("Scheduler not supported by this test");
225  }
226 
227 
228  Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats ();
229  rlcStats->SetAttribute ("EpochDuration", TimeValue (Seconds (0.1)));
230 
231  NS_LOG_INFO (m_schedulerType << " MIMO test:");
232  double sampleTime = 0.199999; // at 0.2 RlcStats are reset
233  for (uint8_t j = 0; j < m_estThrDl.size (); j ++)
234  {
235  NS_LOG_INFO ("\t test with user at distance " << m_dist << " time " << sampleTime);
236  // get the imsi
237  uint64_t imsi = ueDevs.Get (0)->GetObject<LteUeNetDevice> ()->GetImsi ();
238  uint8_t lcId = 3;
239  Time t = Seconds (sampleTime);
240  Simulator::Schedule(t, &LenaMimoTestCase::GetRlcBufferSample, this, rlcStats, imsi, lcId);
241  sampleTime += 0.2;
242  }
243  Simulator::Stop (Seconds (simulationTime));
244  Simulator::Run ();
245  Simulator::Destroy ();
246 
247  NS_LOG_INFO ("Check consistency");
248  for (uint8_t i = 0; i < m_estThrDl.size (); i++)
249  {
250  NS_LOG_INFO ("interval " << i + 1 << ": bytes rxed " << (double)m_dlDataRxed.at (i) << " ref " << m_estThrDl.at (i));
251  NS_TEST_ASSERT_MSG_EQ_TOL ((double)m_dlDataRxed.at (i) , m_estThrDl.at (i), m_estThrDl.at (i) * tolerance, " Unfair Throughput!");
252  }
253 
254 }
255 
256 
257 void
259 {
260  m_dlDataRxed.push_back (rlcStats->GetDlRxData (imsi, lcId));
261  NS_LOG_INFO (Simulator::Now () << "\t get bytes " << m_dlDataRxed.at (m_dlDataRxed.size () - 1));
262 }
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
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:393
#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
the scheduler type
Definition: lte-test-mimo.h:75
AttributeValue implementation for Boolean.
Definition: boolean.h:36
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Create a set of eNodeB devices.
Definition: lte-helper.cc:474
Hold variables of type string.
Definition: string.h:41
A suite of tests to run.
Definition: test.h:1342
LenaMimoTestCase(uint16_t dist, std::vector< uint32_t > estThrDl, std::string schedulerType, bool useIdealRrc)
Constructor.
Implements the SCHED SAP and CSCHED SAP for a Proportional Fair scheduler.
virtual ~LenaMimoTestCase()
std::vector< uint32_t > m_estThrDl
estimated throughput DL
Definition: lte-test-mimo.h:74
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:961
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:204
void EnableRlcTraces(void)
Enable trace sinks for RLC layer.
Definition: lte-helper.cc:1435
This system test program creates different test cases with a single eNB and single UE...
Definition: lte-test-mimo.h:40
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:280
#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:1155
void ActivateDataRadioBearer(NetDeviceContainer ueDevices, EpsBearer bearer)
Activate a Data Radio Bearer on a given UE devices (for LTE-only simulation).
Definition: lte-helper.cc:1314
void SetSchedulerType(std::string type)
Set the type of scheduler to be used by eNodeB devices.
Definition: lte-helper.cc:279
mobility
Definition: third.py:101
virtual void DoRun(void)
Implementation to actually run this TestCase.
Keep track of the current position and velocity of an object.
static LenaTestMimoSuite lenaTestMimoSuite
Hold variables of type enum.
Definition: enum.h:54
AttributeValue implementation for Time.
Definition: nstime.h:1124
Lena Test Mimo Suite.
Definition: lte-test-mimo.h:90
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
uint64_t GetDlRxData(uint64_t imsi, uint8_t lcid)
Gets the number of received downlink data bytes.
holds a vector of ns3::NetDevice pointers
Ptr< LteEnbPhy > GetPhy(void) const
#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:380
bool m_useIdealRrc
whether to use the ideal RRC
Definition: lte-test-mimo.h:76
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
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<T>.
Definition: pointer.h:36
Ptr< LteUePhy > GetPhy(void) const
Get the Phy.
void GetRlcBufferSample(Ptr< RadioBearerStatsCalculator > rlcStats, uint64_t imsi, uint8_t rnti)
Get RLC buffer sample.
This class contains the specification of EPS Bearers.
Definition: eps-bearer.h:91
void SetPosition(const Vector &position)
Ptr< RadioBearerStatsCalculator > GetRlcStats(void)
Definition: lte-helper.cc:1572
NetDeviceContainer InstallUeDevice(NodeContainer c)
Create a set of UE devices.
Definition: lte-helper.cc:489
Helper class used to assign positions and mobility models to nodes.
std::string GetName(void) const
Definition: test.cc:370
std::vector< uint64_t > m_dlDataRxed
DL data received.
Definition: lte-test-mimo.h:78
Implements the SCHED SAP and CSCHED SAP for a Round Robin scheduler.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1062
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:810
uint16_t m_dist
the distance
Definition: lte-test-mimo.h:73
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Qci
QoS Class Indicator.
Definition: eps-bearer.h:106
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:309
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:1529
std::map< uint8_t, Ptr< ComponentCarrierBaseStation > > GetCcMap(void) const
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
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:185
The eNodeB device implementation.
static std::string BuildNameString(uint16_t dist, std::string schedulerType, bool useIdealRrc)
Builds the test name string based on provided parameter values.
The LteUeNetDevice class implements the UE net device.