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/buildings-helper.h>
35 #include <ns3/lte-helper.h>
36 #include <ns3/single-model-spectrum-channel.h>
37 #include "ns3/string.h"
38 #include "ns3/double.h"
39 #include <ns3/building.h>
40 #include <ns3/enum.h>
41 #include <ns3/net-device-container.h>
42 #include <ns3/lte-ue-net-device.h>
43 #include <ns3/lte-enb-net-device.h>
44 #include <ns3/lte-ue-rrc.h>
45 #include <ns3/lte-helper.h>
46 #include <ns3/lte-enb-phy.h>
47 #include <ns3/lte-ue-phy.h>
48 
50 #include "lte-test-ue-phy.h"
52 
53 NS_LOG_COMPONENT_DEFINE ("LtePathlossModelTest");
54 
55 namespace ns3 {
56 
57 
68 void
70  uint32_t frameNo, uint32_t subframeNo, uint16_t rnti,
71  uint8_t mcsTb1, uint16_t sizeTb1, uint8_t mcsTb2, uint16_t sizeTb2)
72 {
73  testcase->DlScheduling (frameNo, subframeNo, rnti, mcsTb1, sizeTb1, mcsTb2, sizeTb2);
74 }
75 
76 
77 
79  : TestSuite ("lte-pathloss-model", SYSTEM)
80 {
81 
82 
83  // LogLevel logLevel = (LogLevel)(LOG_PREFIX_FUNC | LOG_PREFIX_TIME | LOG_LEVEL_ALL);
84  // LogComponentEnable ("LteHelper", logLevel);
85  // LogComponentEnable ("LtePathlossModelTest", logLevel);
86  // LogComponentEnable ("BuildingsPropagationLossModel", logLevel);
87  // LogComponentEnable ("LteInterference", logLevel);
88  // LogComponentEnable ("LteSpectrumValueHelper", logLevel);
89  // LogComponentEnable ("LteEnbNetDevice", logLevel);
90 
91  struct SnrEfficiencyMcs
92  {
93  double snrDb;
94  double efficiency;
95  int mcsIndex;
96  };
97 
102  SnrEfficiencyMcs snrEfficiencyMcs[] = {
103  { -5.00000, 0.08024, -1},
104  { -4.00000, 0.10030, -1},
105  { -3.00000, 0.12518, -1},
106  { -2.00000, 0.15589, 0},
107  { -1.00000, 0.19365, 0},
108  { 0.00000, 0.23983, 2},
109  { 1.00000, 0.29593, 2},
110  { 2.00000, 0.36360, 2},
111  { 3.00000, 0.44451, 4},
112  { 4.00000, 0.54031, 4},
113  { 5.00000, 0.65251, 6},
114  { 6.00000, 0.78240, 6},
115  { 7.00000, 0.93086, 8},
116  { 8.00000, 1.09835, 8},
117  { 9.00000, 1.28485, 10},
118  { 10.00000, 1.48981, 12},
119  { 11.00000, 1.71229, 12},
120  { 12.00000, 1.95096, 14},
121  { 13.00000, 2.20429, 14},
122  { 14.00000, 2.47062, 16},
123  { 15.00000, 2.74826, 18},
124  { 16.00000, 3.03560, 18},
125  { 17.00000, 3.33115, 20},
126  { 18.00000, 3.63355, 20},
127  { 19.00000, 3.94163, 22},
128  { 20.00000, 4.25439, 22},
129  { 21.00000, 4.57095, 24},
130  { 22.00000, 4.89060, 24},
131  { 23.00000, 5.21276, 26},
132  { 24.00000, 5.53693, 26},
133  { 25.00000, 5.86271, 28},
134  { 26.00000, 6.18980, 28},
135  { 27.00000, 6.51792, 28},
136  { 28.00000, 6.84687, 28},
137  { 29.00000, 7.17649, 28},
138  { 30.00000, 7.50663, 28},
139  };
140 
141 
142  double txPowerDbm = 30; // default eNB TX power over whole bandwidth
143  double txPowerLin = std::pow (10, (txPowerDbm - 30)/10);
144  double ktDbm = -174; // reference LTE noise PSD
145  double noisePowerDbm = ktDbm + 10 * std::log10 (25 * 180000); // corresponds to kT*bandwidth in linear units
146  double receiverNoiseFigureDb = 9.0; // default UE noise figure
147  double noiseLin = std::pow (10, (noisePowerDbm-30+receiverNoiseFigureDb)/10);
148 
149  // reference values obtained with the octave script src/lte/test/reference/lte_pathloss.m
150 
151  double loss[] = {81.062444, 134.078605, 144.259958};
152  double dist[] = {100.0, 500.0, 1500};
153 
154  int numOfTests = sizeof (loss) / sizeof (double);
155  for ( int i = 0 ; i < numOfTests; i++ )
156  {
157  // double lossDb = txPowerDbm - snrEfficiencyMcs[i].snrDb - noisePowerDbm - receiverNoiseFigureDb;
158  double sinrLin = (txPowerLin/(pow(10, loss[i]/10))) / noiseLin;
159  // double sinrDb = txPowerDbm- noisePowerDbm - receiverNoiseFigureDb - loss[i];
160  double sinrDb = 10 * std::log10 (sinrLin);
161  NS_LOG_INFO (" Ptx " << txPowerDbm << " Pn " << noisePowerDbm << " Fn " << receiverNoiseFigureDb << " Pl " << loss[i] << " dist " << dist[i]);
162 
163  int mcs = -1;
164  int numSnrEfficiencyMcsEntries = sizeof (snrEfficiencyMcs) / sizeof (SnrEfficiencyMcs);
165  for (int j = 0; j < numSnrEfficiencyMcsEntries && snrEfficiencyMcs[j].snrDb < sinrDb; ++j)
166  {
167  mcs = snrEfficiencyMcs[j].mcsIndex;
168  }
169 
170  std::ostringstream name;
171  name << " snr= " << sinrDb << " dB, "
172  << " mcs= " << snrEfficiencyMcs[i].mcsIndex;
173  AddTestCase (new LtePathlossModelSystemTestCase (name.str (), sinrDb, dist[i], mcs), TestCase::QUICK);
174  }
175 
176 
177 
178 
179 
180 }
181 
183 
184 
185 
186 
187 LtePathlossModelSystemTestCase::LtePathlossModelSystemTestCase (std::string name, double snrDb, double dist, uint16_t mcsIndex)
188 : TestCase (name),
189 m_snrDb (snrDb),
190 m_distance (dist),
191 m_mcsIndex (mcsIndex)
192 {
193  std::ostringstream sstream1, sstream2;
194  sstream1 << " snr=" << snrDb
195  << " mcs=" << mcsIndex << " distance=" << dist;
196 
197  NS_LOG_INFO ("Creating LtePathlossModelSystemTestCase: " + sstream1.str ());
198 }
199 
201 {
202 }
203 
204 void
206 {
211  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
212  // lteHelper->EnableLogComponents ();
213  lteHelper->EnableMacTraces ();
214  lteHelper->EnableRlcTraces ();
215  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::HybridBuildingsPropagationLossModel"));
216 
217  // set frequency. This is important because it changes the behavior of the pathloss model
218  lteHelper->SetEnbDeviceAttribute ("DlEarfcn", UintegerValue (200));
219 
220 
221  // remove shadowing component
222  lteHelper->SetPathlossModelAttribute ("ShadowSigmaOutdoor", DoubleValue (0.0));
223  lteHelper->SetPathlossModelAttribute ("ShadowSigmaIndoor", DoubleValue (0.0));
224  lteHelper->SetPathlossModelAttribute ("ShadowSigmaExtWalls", DoubleValue (0.0));
225 
226  // Create Nodes: eNodeB and UE
227  NodeContainer enbNodes;
228  NodeContainer ueNodes;
229  enbNodes.Create (1);
230  ueNodes.Create (1);
231  NodeContainer allNodes = NodeContainer ( enbNodes, ueNodes );
232 
233  // Install Mobility Model
234  MobilityHelper mobility;
235  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
236  mobility.Install (allNodes);
237  BuildingsHelper::Install (allNodes);
238 
239 
240  // Create Devices and install them in the Nodes (eNB and UE)
241  NetDeviceContainer enbDevs;
242  NetDeviceContainer ueDevs;
243  lteHelper->SetSchedulerType ("ns3::RrFfMacScheduler");
244  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
245  ueDevs = lteHelper->InstallUeDevice (ueNodes);
246 
247  Ptr<MobilityModel> mm_enb = enbNodes.Get (0)->GetObject<MobilityModel> ();
248  mm_enb->SetPosition (Vector (0.0, 0.0, 30.0));
249  Ptr<MobilityModel> mm_ue = ueNodes.Get (0)->GetObject<MobilityModel> ();
250  mm_ue->SetPosition (Vector (m_distance, 0.0, 1.0));
251 
252  Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ();
253  Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy ();
254  enbPhy->SetAttribute ("TxPower", DoubleValue (30.0));
255  enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0));
256 
257  Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (0)->GetObject<LteUeNetDevice> ();
258  Ptr<LteUePhy> uePhy = lteUeDev->GetPhy ();
259  uePhy->SetAttribute ("TxPower", DoubleValue (23.0));
260  uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0));
261 
262 
263  // Attach a UE to a eNB
264  lteHelper->Attach (ueDevs, enbDevs.Get (0));
265 
266 
267  // Activate an EPS bearer
269  EpsBearer bearer (q);
270  lteHelper->ActivateDataRadioBearer (ueDevs, bearer);
271 
272  // Use testing chunk processor in the PHY layer
273  // It will be used to test that the SNR is as intended
274  //Ptr<LtePhy> uePhy = ueDevs.Get (0)->GetObject<LteUeNetDevice> ()->GetPhy ()->GetObject<LtePhy> ();
275  Ptr<LteTestSinrChunkProcessor> testSinr = Create<LteTestSinrChunkProcessor> (uePhy);
276  uePhy->GetDownlinkSpectrumPhy ()->AddCtrlSinrChunkProcessor (testSinr);
277 
278 // Config::Connect ("/NodeList/0/DeviceList/0/LteEnbMac/DlScheduling",
279 // MakeBoundCallback (&LteTestPathlossDlSchedCallback, this));
280 
281  Simulator::Stop (Seconds (0.035));
282  Simulator::Run ();
283 
284  double calculatedSinrDb = 10.0 * std::log10 (testSinr->GetSinr ()->operator[] (0));
285  NS_LOG_INFO ("Distance " << m_distance << " Calculated SINR " << calculatedSinrDb << " ref " << m_snrDb);
287  NS_TEST_ASSERT_MSG_EQ_TOL (calculatedSinrDb, m_snrDb, 0.001, "Wrong SINR !");
288 }
289 
290 
291 void
292 LtePathlossModelSystemTestCase::DlScheduling (uint32_t frameNo, uint32_t subframeNo, uint16_t rnti,
293  uint8_t mcsTb1, uint16_t sizeTb1, uint8_t mcsTb2, uint16_t sizeTb2)
294 {
295  static bool firstTime = true;
296 
297  if ( firstTime )
298  {
299  firstTime = false;
300  NS_LOG_INFO ("SNR\tRef_MCS\tCalc_MCS");
301  }
302 
303 
304  // need to allow for RRC connection establishment + SRS transmission
305  if (Simulator::Now () > MilliSeconds (21))
306  {
307  NS_LOG_INFO (m_snrDb << "\t" << m_mcsIndex << "\t" << (uint16_t)mcsTb1);
308 
309  NS_TEST_ASSERT_MSG_EQ ((uint16_t)mcsTb1, m_mcsIndex, "Wrong MCS index");
310  }
311 }
312 
313 
314 } // namespace ns3
315 
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
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
static void Run(void)
Definition: simulator.cc:157
#define NS_LOG_INFO(msg)
Definition: log.h:264
encapsulates test code
Definition: test.h:849
a 3d vector
Definition: vector.h:31
Keep track of the current position and velocity of an object.
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
Hold an unsigned integer type.
Definition: uinteger.h:46
holds a vector of ns3::NetDevice pointers
static void Destroy(void)
Definition: simulator.cc:121
void DlScheduling(uint32_t frameNo, uint32_t subframeNo, uint16_t rnti, uint8_t mcsTb1, uint16_t sizeTb1, uint8_t mcsTb2, uint16_t sizeTb2)
keep track of a set of node pointers.
void LteTestPathlossDlSchedCallback(LtePathlossModelSystemTestCase *testcase, std::string path, uint32_t frameNo, uint32_t subframeNo, uint16_t rnti, uint8_t mcsTb1, uint16_t sizeTb1, uint8_t mcsTb2, uint16_t sizeTb2)
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())
NS_LOG_COMPONENT_DEFINE("LtePathlossModelTest")
static Time Now(void)
Definition: simulator.cc:180
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition: test.cc:172
void SetPosition(const Vector &position)
virtual void DoRun(void)
Implementation to actually run this TestCase.
Fast test.
Definition: test.h:857
static LtePathlossModelTestSuite ltePathlossModelTestSuite
Helper class used to assign positions and mobility models to nodes.
static void Stop(void)
Definition: simulator.cc:165
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Hold an floating point type.
Definition: double.h:41
Ptr< T > GetObject(void) const
Definition: object.h:360
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
Definition: test.h:137
static void Install(Ptr< Node > node)