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/buildings-mobility-model.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 
55 #include "lte-test-mimo.h"
56 
57 
58 NS_LOG_COMPONENT_DEFINE ("LenaTestMimo");
59 
60 namespace ns3 {
61 
62 
64  : TestSuite ("lte-mimo", SYSTEM)
65 {
66  NS_LOG_INFO ("creating LenaMimoTestCase");
67 
68  // RR DOWNLINK- DISTANCE 300
69  // [0, 0.2] sec TxMode 0: MCS 20 -> TB size 1191
70  // [0.2, 0.3] sec TxMode 1: MCS 26 -> TB size 1836
71  // [0.3, 0.4] sec TxMode 2: MCS 18 -> TB size 967 (x2 layers)
72  // -->
73  std::vector<uint32_t> estThrDl;
74  estThrDl.push_back (119100); // TTI 1 estimated throughput for TxMode 1
75  estThrDl.push_back (183600); // TTI 2 estimated throughput for TxMode 2
76  estThrDl.push_back (193400); // TTI 3 estimated throughput for TxMode 3
77  AddTestCase (new LenaMimoTestCase(300, estThrDl, "ns3::RrFfMacScheduler"));
78  AddTestCase (new LenaMimoTestCase(300, estThrDl, "ns3::PfFfMacScheduler"));
79 
80 
81 }
82 
84 
85 std::string
87 {
88  std::ostringstream oss;
89  oss << " UE distance " << dist << " m";
90  return oss.str ();
91 }
92 
93 LenaMimoTestCase::LenaMimoTestCase (uint16_t dist, std::vector<uint32_t> estThrDl, std::string schedulerType)
94  : TestCase (BuildNameString (dist)),
95  m_dist (dist),
96  m_estThrDl (estThrDl),
97  m_schedulerType (schedulerType)
98 {
99 }
100 
102 {
103 }
104 
105 void
107 {
108 // Config::SetDefault ("ns3::LteSpectrumPhy::PemEnabled", BooleanValue (false));
109  Config::SetDefault ("ns3::LteAmc::AmcModel", EnumValue (LteAmc::PiroEW2010));
111 // LogComponentEnable ("LteEnbRrc", LOG_LEVEL_ALL);
112 // LogComponentEnable ("LteUeRrc", LOG_LEVEL_ALL);
113 // LogComponentEnable ("LteEnbMac", LOG_LEVEL_ALL);
114 // LogComponentEnable ("LteUeMac", LOG_LEVEL_ALL);
115 // LogComponentEnable ("LteRlc", LOG_LEVEL_ALL);
116 //
117 // LogComponentEnable ("LtePhy", LOG_LEVEL_ALL);
118 // LogComponentEnable ("LteEnbPhy", LOG_LEVEL_ALL);
119 // LogComponentEnable ("LteUePhy", LOG_LEVEL_ALL);
120 
121 // LogComponentEnable ("LteSpectrumPhy", LOG_LEVEL_ALL);
122 // LogComponentEnable ("LteInterference", LOG_LEVEL_ALL);
123 // LogComponentEnable ("LteSinrChunkProcessor", LOG_LEVEL_ALL);
124 //
125 // LogComponentEnable ("LtePropagationLossModel", LOG_LEVEL_ALL);
126 // LogComponentEnable ("LossModel", LOG_LEVEL_ALL);
127 // LogComponentEnable ("ShadowingLossModel", LOG_LEVEL_ALL);
128 // LogComponentEnable ("PenetrationLossModel", LOG_LEVEL_ALL);
129 // LogComponentEnable ("MultipathLossModel", LOG_LEVEL_ALL);
130 // LogComponentEnable ("PathLossModel", LOG_LEVEL_ALL);
131 //
132 // LogComponentEnable ("LteNetDevice", LOG_LEVEL_ALL);
133 // LogComponentEnable ("LteUeNetDevice", LOG_LEVEL_ALL);
134 // LogComponentEnable ("LteEnbNetDevice", LOG_LEVEL_ALL);
135 
136 // LogComponentEnable ("LteMiErrorModel", LOG_LEVEL_ALL);
137 // LogComponentEnable ("LteAmc", LOG_LEVEL_ALL);
138 // LogComponentEnable ("LteSpectrumPhy", LOG_LEVEL_ALL);
139 
140  LogComponentEnable ("LenaTestMimo", LOG_LEVEL_ALL);
141 // LogComponentEnable ("BuildingsPropagationLossModel", LOG_LEVEL_ALL);
142 // LogComponentEnable ("RrFfMacScheduler", LOG_LEVEL_ALL);
143 // LogComponentEnable ("PfFfMacScheduler", LOG_LEVEL_ALL);
144 
145 
151  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
152 
153 
154  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::HybridBuildingsPropagationLossModel"));
155  lteHelper->SetPathlossModelAttribute ("ShadowSigmaOutdoor", DoubleValue (0.0));
156  lteHelper->SetPathlossModelAttribute ("ShadowSigmaIndoor", DoubleValue (0.0));
157  lteHelper->SetPathlossModelAttribute ("ShadowSigmaExtWalls", DoubleValue (0.0));
158 
159 // lteHelper->EnableLogComponents ();
160 
161  // Create Nodes: eNodeB and UE
162  NodeContainer enbNodes;
163  NodeContainer ueNodes;
164  enbNodes.Create (1);
165  ueNodes.Create (1);
166 
167  // Install Mobility Model
168  MobilityHelper mobility;
169  mobility.SetMobilityModel ("ns3::BuildingsMobilityModel");
170  mobility.Install (enbNodes);
171  mobility.SetMobilityModel ("ns3::BuildingsMobilityModel");
172  mobility.Install (ueNodes);
173 
174  // Create Devices and install them in the Nodes (eNB and UE)
175  NetDeviceContainer enbDevs;
176  NetDeviceContainer ueDevs;
177  lteHelper->SetSchedulerType (m_schedulerType);
178  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
179  ueDevs = lteHelper->InstallUeDevice (ueNodes);
180 
181  // Attach a UE to a eNB
182  lteHelper->Attach (ueDevs, enbDevs.Get (0));
183 
184  // Activate an EPS bearer
186  EpsBearer bearer (q);
187  lteHelper->ActivateEpsBearer (ueDevs, bearer, EpcTft::Default ());
188 
189 
190  Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ();
191  Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy ();
192  enbPhy->SetAttribute ("TxPower", DoubleValue (46.0));
193  enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0));
195  mmenb->SetPosition (Vector (0.0, 0.0, 30.0));
196 
197  // Set UE's position and power
199  mmue->SetPosition (Vector (m_dist, 0.0, 1.0));
200  Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (0)->GetObject<LteUeNetDevice> ();
201  Ptr<LteUePhy> uePhy = lteUeDev->GetPhy ();
202  uePhy->SetAttribute ("TxPower", DoubleValue (23.0));
203  uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0));
204 
205 
206  lteHelper->EnableRlcTraces ();
207  lteHelper->EnableMacTraces ();
208  double simulationTime = 0.401;
209  double tolerance = 0.1;
210 
211  uint8_t rnti = ueDevs.Get (0)->GetObject<LteUeNetDevice> ()->GetRrc ()->GetRnti ();
212  Ptr<LteEnbNetDevice> enbNetDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ();
213 
214  PointerValue ptrval;
215  enbNetDev->GetAttribute ("FfMacScheduler", ptrval);
216  Ptr<PfFfMacScheduler> pfsched;
217  Ptr<RrFfMacScheduler> rrsched;
218  if (m_schedulerType.compare ("ns3::RrFfMacScheduler") == 0)
219  {
220  rrsched = ptrval.Get<RrFfMacScheduler> ();
221  if (rrsched == 0)
222  {
223  NS_FATAL_ERROR ("No RR Scheduler available");
224  }
225 
228  }
229  else if (m_schedulerType.compare ("ns3::PfFfMacScheduler") == 0)
230  {
231  pfsched = ptrval.Get<PfFfMacScheduler> ();
232  if (pfsched == 0)
233  {
234  NS_FATAL_ERROR ("No Pf Scheduler available");
235  }
236 
239  }
240  else
241  {
242  NS_FATAL_ERROR ("Scheduler not supported by this test");
243  }
244 
245 
246  Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats ();
247  rlcStats->SetAttribute ("EpochDuration", TimeValue (Seconds (0.1)));
248 
249 
253  NS_LOG_INFO (m_schedulerType << " MIMO test:");
254  double sampleTime = 0.2;
255  for (uint8_t j = 0; j < m_estThrDl.size (); j ++)
256  {
257  NS_LOG_INFO ("\t test with user at distance " << m_dist << " time " << sampleTime);
258  // get the imsi
259  uint64_t imsi = ueDevs.Get (0)->GetObject<LteUeNetDevice> ()->GetImsi ();
260  // get the lcId
261  uint8_t lcId = ueDevs.Get (0)->GetObject<LteUeNetDevice> ()->GetRrc ()->GetLcIdVector ().at (0);
262  Time t = Seconds (sampleTime);
263  Simulator::Schedule(t, &LenaMimoTestCase::GetRlcBufferSample, this, rlcStats, imsi, lcId);
264  sampleTime += 0.1;
265  }
266  Simulator::Stop (Seconds (simulationTime));
267  Simulator::Run ();
269 
270  NS_LOG_INFO ("Check consistency");
271  for (uint8_t i = 0; i < m_estThrDl.size (); i++)
272  {
273  NS_LOG_INFO ("\tTTI " << i + 1 << " bytes rxed " << (double)m_dlDataRxed.at (i) << " ref " << m_estThrDl.at (i));
274  NS_TEST_ASSERT_MSG_EQ_TOL ((double)m_dlDataRxed.at (i) , m_estThrDl.at (i), m_estThrDl.at (i) * tolerance, " Unfair Throughput!");
275  }
276 
277 }
278 
279 
280 void
282 {
283  m_dlDataRxed.push_back (rlcStats->GetDlRxData (imsi, lcId));
284 // NS_LOG_INFO ("\t get bytes " << m_dlDataRxed.at (m_dlDataRxed.size () - 1));
285 }
286 
287 
288 
289 } // namespace ns3
290