A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lte-test-pathloss-model.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 "ns3/simulator.h"
22 
23 #include "ns3/log.h"
24 
25 #include "ns3/spectrum-test.h"
26 
27 #include "ns3/lte-phy-tag.h"
28 #include "ns3/lte-sinr-chunk-processor.h"
29 
30 
31 #include <ns3/hybrid-buildings-propagation-loss-model.h>
32 #include <ns3/node-container.h>
33 #include <ns3/mobility-helper.h>
34 #include <ns3/lte-helper.h>
35 #include <ns3/single-model-spectrum-channel.h>
36 #include "ns3/string.h"
37 #include "ns3/double.h"
38 #include <ns3/building.h>
39 #include <ns3/enum.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/lte-enb-phy.h>
46 #include <ns3/lte-ue-phy.h>
47 
49 #include "lte-test-ue-phy.h"
51 
52 NS_LOG_COMPONENT_DEFINE ("LtePathlossModelTest");
53 
54 namespace ns3 {
55 
56 
67 void
69  uint32_t frameNo, uint32_t subframeNo, uint16_t rnti,
70  uint8_t mcsTb1, uint16_t sizeTb1, uint8_t mcsTb2, uint16_t sizeTb2)
71 {
72  testcase->DlScheduling (frameNo, subframeNo, rnti, mcsTb1, sizeTb1, mcsTb2, sizeTb2);
73 }
74 
75 
76 
78  : TestSuite ("lte-pathloss-model", SYSTEM)
79 {
80 
81 
82  // LogLevel logLevel = (LogLevel)(LOG_PREFIX_FUNC | LOG_PREFIX_TIME | LOG_LEVEL_ALL);
83  // LogComponentEnable ("LteHelper", logLevel);
84  // LogComponentEnable ("LtePathlossModelTest", logLevel);
85  // LogComponentEnable ("BuildingsPropagationLossModel", logLevel);
86  // LogComponentEnable ("LteInterference", logLevel);
87  // LogComponentEnable ("LteSpectrumValueHelper", logLevel);
88  // LogComponentEnable ("LteEnbNetDevice", logLevel);
89 
90  struct SnrEfficiencyMcs
91  {
92  double snrDb;
93  double efficiency;
94  int mcsIndex;
95  };
96 
101  SnrEfficiencyMcs snrEfficiencyMcs[] = {
102  { -5.00000, 0.08024, -1},
103  { -4.00000, 0.10030, -1},
104  { -3.00000, 0.12518, -1},
105  { -2.00000, 0.15589, 0},
106  { -1.00000, 0.19365, 0},
107  { 0.00000, 0.23983, 2},
108  { 1.00000, 0.29593, 2},
109  { 2.00000, 0.36360, 2},
110  { 3.00000, 0.44451, 4},
111  { 4.00000, 0.54031, 4},
112  { 5.00000, 0.65251, 6},
113  { 6.00000, 0.78240, 6},
114  { 7.00000, 0.93086, 8},
115  { 8.00000, 1.09835, 8},
116  { 9.00000, 1.28485, 10},
117  { 10.00000, 1.48981, 12},
118  { 11.00000, 1.71229, 12},
119  { 12.00000, 1.95096, 14},
120  { 13.00000, 2.20429, 14},
121  { 14.00000, 2.47062, 16},
122  { 15.00000, 2.74826, 18},
123  { 16.00000, 3.03560, 18},
124  { 17.00000, 3.33115, 20},
125  { 18.00000, 3.63355, 20},
126  { 19.00000, 3.94163, 22},
127  { 20.00000, 4.25439, 22},
128  { 21.00000, 4.57095, 24},
129  { 22.00000, 4.89060, 24},
130  { 23.00000, 5.21276, 26},
131  { 24.00000, 5.53693, 26},
132  { 25.00000, 5.86271, 28},
133  { 26.00000, 6.18980, 28},
134  { 27.00000, 6.51792, 28},
135  { 28.00000, 6.84687, 28},
136  { 29.00000, 7.17649, 28},
137  { 30.00000, 7.50663, 28},
138  };
139 
140 
141  double txPowerDbm = 30; // default eNB TX power over whole bandwdith
142  double txPowerLin = pow (10, (txPowerDbm - 30)/10);
143  double ktDbm = -174; // reference LTE noise PSD
144  double noisePowerDbm = ktDbm + 10 * log10 (25 * 180000); // corresponds to kT*bandwidth in linear units
145  double receiverNoiseFigureDb = 9.0; // default UE noise figure
146  double noiseLin = pow (10, (noisePowerDbm-30+receiverNoiseFigureDb)/10);
147 
148  // reference values obtained with the octave script src/lte/test/reference/lte_pathloss.m
149 
150  double loss[] = {81.062444, 134.078605, 144.259958};
151  double dist[] = {100.0, 500.0, 1500};
152 
153  int numOfTests = sizeof (loss) / sizeof (double);
154  for ( int i = 0 ; i < numOfTests; i++ )
155  {
156  // double lossDb = txPowerDbm - snrEfficiencyMcs[i].snrDb - noisePowerDbm - receiverNoiseFigureDb;
157  double sinrLin = (txPowerLin/(pow(10, loss[i]/10))) / noiseLin;
158  // double sinrDb = txPowerDbm- noisePowerDbm - receiverNoiseFigureDb - loss[i];
159  double sinrDb = 10*log10(sinrLin);
160  NS_LOG_INFO (" Ptx " << txPowerDbm << " Pn " << noisePowerDbm << " Fn " << receiverNoiseFigureDb << " Pl " << loss[i] << " dist " << dist[i]);
161  std::ostringstream name;
162  name << " snr= " << sinrDb << " dB, "
163  << " mcs= " << snrEfficiencyMcs[i].mcsIndex;
164  AddTestCase (new LtePathlossModelSystemTestCase (name.str (), sinrDb, dist[i], snrEfficiencyMcs[i].mcsIndex));
165  }
166 
167 
168 
169 
170 
171 }
172 
174 
175 
176 
177 
178 LtePathlossModelSystemTestCase::LtePathlossModelSystemTestCase (std::string name, double snrDb, double dist, uint16_t mcsIndex)
179 : TestCase (name),
180 m_snrDb (snrDb),
181 m_distance (dist),
182 m_mcsIndex (mcsIndex)
183 {
184  std::ostringstream sstream1, sstream2;
185  sstream1 << " snr=" << snrDb
186  << " mcs=" << mcsIndex << " distance=" << dist;
187 
188  NS_LOG_INFO ("Creating LtePathlossModelSystemTestCase: " + sstream1.str ());
189 }
190 
192 {
193 }
194 
195 void
197 {
201 // LogLevel logLevel = (LogLevel)(LOG_PREFIX_FUNC | LOG_PREFIX_TIME | LOG_LEVEL_ALL);
202 // LogComponentEnable ("LteAmc", LOG_LEVEL_ALL);
203 // LogComponentEnable ("LtePhy", LOG_LEVEL_ALL);
204 // LogComponentEnable ("LteEnbPhy", LOG_LEVEL_ALL);
205 // LogComponentEnable ("LteUePhy", LOG_LEVEL_ALL);
206 // LogComponentEnable ("SingleModelSpectrumChannel", LOG_LEVEL_ALL);
207  LogComponentEnable ("BuildingsPropagationLossModel", LOG_LEVEL_ALL);
208  LogComponentEnable ("HybridBuildingsPropagationLossModel", LOG_LEVEL_ALL);
209 // LogComponentEnable ("LteHelper", LOG_LEVEL_ALL);
210 
211 //
212  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
213  // lteHelper->EnableLogComponents ();
214  lteHelper->EnableMacTraces ();
215  lteHelper->EnableRlcTraces ();
216  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::HybridBuildingsPropagationLossModel"));
217 
218  // set frequency. This is important because it changes the behavior of the pathloss model
219  lteHelper->SetEnbDeviceAttribute ("DlEarfcn", UintegerValue (200));
220 
221 
222  // remove shadowing component
223  lteHelper->SetPathlossModelAttribute ("ShadowSigmaOutdoor", DoubleValue (0.0));
224  lteHelper->SetPathlossModelAttribute ("ShadowSigmaIndoor", DoubleValue (0.0));
225  lteHelper->SetPathlossModelAttribute ("ShadowSigmaExtWalls", DoubleValue (0.0));
226 
227  // Create Nodes: eNodeB and UE
228  NodeContainer enbNodes;
229  NodeContainer ueNodes;
230  enbNodes.Create (1);
231  ueNodes.Create (1);
232  NodeContainer allNodes = NodeContainer ( enbNodes, ueNodes );
233 
234  // Install Mobility Model
235  MobilityHelper mobility;
236  mobility.SetMobilityModel ("ns3::BuildingsMobilityModel");
237  mobility.Install (allNodes);
238 
239  // Create Devices and install them in the Nodes (eNB and UE)
240  NetDeviceContainer enbDevs;
241  NetDeviceContainer ueDevs;
242  lteHelper->SetSchedulerType ("ns3::RrFfMacScheduler");
243  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
244  ueDevs = lteHelper->InstallUeDevice (ueNodes);
245 
247  mm_enb->SetPosition (Vector (0.0, 0.0, 30.0));
249  mm_ue->SetPosition (Vector (m_distance, 0.0, 1.0));
250 
251  Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ();
252  Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy ();
253  enbPhy->SetAttribute ("TxPower", DoubleValue (30.0));
254  enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0));
255 
256  Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (0)->GetObject<LteUeNetDevice> ();
257  Ptr<LteUePhy> uePhy = lteUeDev->GetPhy ();
258  uePhy->SetAttribute ("TxPower", DoubleValue (23.0));
259  uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0));
260 
261 
262  // Attach a UE to a eNB
263  lteHelper->Attach (ueDevs, enbDevs.Get (0));
264 
265 
266  // Activate an EPS bearer
268  EpsBearer bearer (q);
269  lteHelper->ActivateEpsBearer (ueDevs, bearer, EpcTft::Default ());
270 
271  // Use testing chunk processor in the PHY layer
272  // It will be used to test that the SNR is as intended
273  //Ptr<LtePhy> uePhy = ueDevs.Get (0)->GetObject<LteUeNetDevice> ()->GetPhy ()->GetObject<LtePhy> ();
274  Ptr<LteTestSinrChunkProcessor> testSinr = Create<LteTestSinrChunkProcessor> (uePhy);
275  uePhy->GetDownlinkSpectrumPhy ()->AddSinrChunkProcessor (testSinr);
276 
277 // Config::Connect ("/NodeList/0/DeviceList/0/LteEnbMac/DlScheduling",
278 // MakeBoundCallback (&LteTestPathlossDlSchedCallback, this));
279 
280  Simulator::Stop (Seconds (0.005));
281  Simulator::Run ();
282 
283  double calculatedSinrDb = 10.0 * log10 (testSinr->GetSinr ()->operator[] (0));
284  NS_LOG_INFO ("Distance " << m_distance << " Calculated SINR " << calculatedSinrDb << " ref " << m_snrDb);
286  NS_TEST_ASSERT_MSG_EQ_TOL (calculatedSinrDb, m_snrDb, 0.001, "Wrong SINR !");
287 }
288 
289 
290 void
291 LtePathlossModelSystemTestCase::DlScheduling (uint32_t frameNo, uint32_t subframeNo, uint16_t rnti,
292  uint8_t mcsTb1, uint16_t sizeTb1, uint8_t mcsTb2, uint16_t sizeTb2)
293 {
294  static bool firstTime = true;
295 
296  if ( firstTime )
297  {
298  firstTime = false;
299  NS_LOG_INFO ("SNR\tRef_MCS\tCalc_MCS");
300  }
301 
307  if ( (frameNo > 1) || (subframeNo > 4) )
308  {
309  NS_LOG_INFO (m_snrDb << "\t" << m_mcsIndex << "\t" << (uint16_t)mcsTb1);
310 
311  NS_TEST_ASSERT_MSG_EQ ((uint16_t)mcsTb1, m_mcsIndex, "Wrong MCS index");
312  }
313 }
314 
315 
316 } // namespace ns3
317