A Discrete-Event Network Simulator
API
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-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/boolean.h>
40 #include <ns3/building.h>
41 #include <ns3/enum.h>
42 #include <ns3/net-device-container.h>
43 #include <ns3/lte-ue-net-device.h>
44 #include <ns3/lte-enb-net-device.h>
45 #include <ns3/lte-ue-rrc.h>
46 #include <ns3/lte-helper.h>
47 #include <ns3/lte-enb-phy.h>
48 #include <ns3/lte-ue-phy.h>
49 
50 #include "lte-test-ue-phy.h"
52 
53 using namespace ns3;
54 
55 NS_LOG_COMPONENT_DEFINE ("LtePathlossModelTest");
56 
67 void
70 {
71  testcase->DlScheduling (dlInfo);
72 }
73 
74 
75 
77  : TestSuite ("lte-pathloss-model", SYSTEM)
78 {
79  // LogLevel logLevel = (LogLevel)(LOG_PREFIX_FUNC | LOG_PREFIX_TIME | LOG_LEVEL_ALL);
80  // LogComponentEnable ("LteHelper", logLevel);
81  // LogComponentEnable ("LtePathlossModelTest", logLevel);
82  // LogComponentEnable ("BuildingsPropagationLossModel", logLevel);
83  // LogComponentEnable ("LteInterference", logLevel);
84  // LogComponentEnable ("LteSpectrumValueHelper", logLevel);
85  // LogComponentEnable ("LteEnbNetDevice", logLevel);
86 
87  struct SnrEfficiencyMcs
88  {
89  double snrDb;
90  double efficiency;
91  int mcsIndex;
92  };
93 
98  SnrEfficiencyMcs snrEfficiencyMcs[] = {
99  { -5.00000, 0.08024, -1},
100  { -4.00000, 0.10030, -1},
101  { -3.00000, 0.12518, -1},
102  { -2.00000, 0.15589, 0},
103  { -1.00000, 0.19365, 0},
104  { 0.00000, 0.23983, 2},
105  { 1.00000, 0.29593, 2},
106  { 2.00000, 0.36360, 2},
107  { 3.00000, 0.44451, 4},
108  { 4.00000, 0.54031, 4},
109  { 5.00000, 0.65251, 6},
110  { 6.00000, 0.78240, 6},
111  { 7.00000, 0.93086, 8},
112  { 8.00000, 1.09835, 8},
113  { 9.00000, 1.28485, 10},
114  { 10.00000, 1.48981, 12},
115  { 11.00000, 1.71229, 12},
116  { 12.00000, 1.95096, 14},
117  { 13.00000, 2.20429, 14},
118  { 14.00000, 2.47062, 16},
119  { 15.00000, 2.74826, 18},
120  { 16.00000, 3.03560, 18},
121  { 17.00000, 3.33115, 20},
122  { 18.00000, 3.63355, 20},
123  { 19.00000, 3.94163, 22},
124  { 20.00000, 4.25439, 22},
125  { 21.00000, 4.57095, 24},
126  { 22.00000, 4.89060, 24},
127  { 23.00000, 5.21276, 26},
128  { 24.00000, 5.53693, 26},
129  { 25.00000, 5.86271, 28},
130  { 26.00000, 6.18980, 28},
131  { 27.00000, 6.51792, 28},
132  { 28.00000, 6.84687, 28},
133  { 29.00000, 7.17649, 28},
134  { 30.00000, 7.50663, 28},
135  };
136 
137 
138  double txPowerDbm = 30; // default eNB TX power over whole bandwidth
139  double txPowerLin = std::pow (10, (txPowerDbm - 30)/10);
140  double ktDbm = -174; // reference LTE noise PSD
141  double noisePowerDbm = ktDbm + 10 * std::log10 (25 * 180000); // corresponds to kT*bandwidth in linear units
142  double receiverNoiseFigureDb = 9.0; // default UE noise figure
143  double noiseLin = std::pow (10, (noisePowerDbm-30+receiverNoiseFigureDb)/10);
144 
145  // reference values obtained with the octave script src/lte/test/reference/lte_pathloss.m
146 
147  double loss[] = {81.062444, 134.078605, 144.259958};
148  double dist[] = {100.0, 500.0, 1500};
149 
150  int numOfTests = sizeof (loss) / sizeof (double);
151  for ( int i = 0 ; i < numOfTests; i++ )
152  {
153  // double lossDb = txPowerDbm - snrEfficiencyMcs[i].snrDb - noisePowerDbm - receiverNoiseFigureDb;
154  double sinrLin = (txPowerLin/(pow(10, loss[i]/10))) / noiseLin;
155  // double sinrDb = txPowerDbm- noisePowerDbm - receiverNoiseFigureDb - loss[i];
156  double sinrDb = 10 * std::log10 (sinrLin);
157  NS_LOG_INFO (" Ptx " << txPowerDbm << " Pn " << noisePowerDbm << " Fn " << receiverNoiseFigureDb << " Pl " << loss[i] << " dist " << dist[i]);
158 
159  int mcs = -1;
160  int numSnrEfficiencyMcsEntries = sizeof (snrEfficiencyMcs) / sizeof (SnrEfficiencyMcs);
161  for (int j = 0; j < numSnrEfficiencyMcsEntries && snrEfficiencyMcs[j].snrDb < sinrDb; ++j)
162  {
163  mcs = snrEfficiencyMcs[j].mcsIndex;
164  }
165 
166  std::ostringstream name;
167  name << " snr= " << sinrDb << " dB, "
168  << " mcs= " << snrEfficiencyMcs[i].mcsIndex;
169  AddTestCase (new LtePathlossModelSystemTestCase (name.str (), sinrDb, dist[i], mcs), TestCase::QUICK);
170  }
171 
172 
173 
174 
175 
176 }
177 
179 
180 
181 
182 
183 LtePathlossModelSystemTestCase::LtePathlossModelSystemTestCase (std::string name, double snrDb, double dist, uint16_t mcsIndex)
184 : TestCase (name),
185 m_snrDb (snrDb),
186 m_distance (dist),
187 m_mcsIndex (mcsIndex)
188 {
189  std::ostringstream sstream1, sstream2;
190  sstream1 << " snr=" << snrDb
191  << " mcs=" << mcsIndex << " distance=" << dist;
192 
193  NS_LOG_INFO ("Creating LtePathlossModelSystemTestCase: " + sstream1.str ());
194 }
195 
197 {
198 }
199 
200 void
202 {
206  //Disable Uplink Power Control
207  Config::SetDefault ("ns3::LteUePhy::EnableUplinkPowerControl", BooleanValue (false));
208 
209  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
210  // lteHelper->EnableLogComponents ();
211  lteHelper->EnableMacTraces ();
212  lteHelper->EnableRlcTraces ();
213  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::HybridBuildingsPropagationLossModel"));
214 
215  // set frequency. This is important because it changes the behavior of the path loss model
216  lteHelper->SetEnbDeviceAttribute ("DlEarfcn", UintegerValue (200));
217  lteHelper->SetEnbDeviceAttribute ("UlEarfcn", UintegerValue (18200));
218  lteHelper->SetUeDeviceAttribute ("DlEarfcn", UintegerValue (200));
219 
220  // remove shadowing component
221  lteHelper->SetPathlossModelAttribute ("ShadowSigmaOutdoor", DoubleValue (0.0));
222  lteHelper->SetPathlossModelAttribute ("ShadowSigmaIndoor", DoubleValue (0.0));
223  lteHelper->SetPathlossModelAttribute ("ShadowSigmaExtWalls", DoubleValue (0.0));
224 
225  // Create Nodes: eNodeB and UE
226  NodeContainer enbNodes;
227  NodeContainer ueNodes;
228  enbNodes.Create (1);
229  ueNodes.Create (1);
230  NodeContainer allNodes = NodeContainer ( enbNodes, ueNodes );
231 
232  // Install Mobility Model
234  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
235  mobility.Install (allNodes);
236  BuildingsHelper::Install (allNodes);
237 
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 
246  Ptr<MobilityModel> mm_enb = enbNodes.Get (0)->GetObject<MobilityModel> ();
247  mm_enb->SetPosition (Vector (0.0, 0.0, 30.0));
248  Ptr<MobilityModel> mm_ue = ueNodes.Get (0)->GetObject<MobilityModel> ();
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  // Activate an EPS bearer
266  enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE;
267  EpsBearer bearer (q);
268  lteHelper->ActivateDataRadioBearer (ueDevs, bearer);
269 
270  // Use testing chunk processor in the PHY layer
271  // It will be used to test that the SNR is as intended
272  //Ptr<LtePhy> uePhy = ueDevs.Get (0)->GetObject<LteUeNetDevice> ()->GetPhy ()->GetObject<LtePhy> ();
273  Ptr<LteChunkProcessor> testSinr = Create<LteChunkProcessor> ();
274  LteSpectrumValueCatcher sinrCatcher;
275  testSinr->AddCallback (MakeCallback (&LteSpectrumValueCatcher::ReportValue, &sinrCatcher));
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 (sinrCatcher.GetValue ()->operator[] (0));
285  NS_LOG_INFO ("Distance " << m_distance << " Calculated SINR " << calculatedSinrDb << " ref " << m_snrDb);
286  Simulator::Destroy ();
287  NS_TEST_ASSERT_MSG_EQ_TOL (calculatedSinrDb, m_snrDb, 0.001, "Wrong SINR !");
288 }
289 
290 
291 void
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 
302 
303  // need to allow for RRC connection establishment + SRS transmission
304  if (Simulator::Now () > MilliSeconds (21))
305  {
306  NS_LOG_INFO (m_snrDb << "\t" << m_mcsIndex << "\t" << (uint16_t)dlInfo.mcsTb1);
307 
308  NS_TEST_ASSERT_MSG_EQ ((uint16_t)dlInfo.mcsTb1, m_mcsIndex, "Wrong MCS index");
309  }
310 }
void SetPathlossModelAttribute(std::string n, const AttributeValue &v)
Set an attribute for the path loss models to be created.
Definition: lte-helper.cc:396
AttributeValue implementation for Boolean.
Definition: boolean.h:36
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Create a set of eNodeB devices.
Definition: lte-helper.cc:484
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
Hold variables of type string.
Definition: string.h:41
void DlScheduling(DlSchedulingCallbackInfo dlInfo)
DL scheduling function.
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:1342
Ptr< LteEnbPhy > GetPhy(void) const
void LteTestPathlossDlSchedCallback(LtePathlossModelSystemTestCase *testcase, std::string path, DlSchedulingCallbackInfo dlInfo)
Test 1.1 Pathloss compound test.
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:943
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1001
void EnableRlcTraces(void)
Enable trace sinks for RLC layer.
Definition: lte-helper.cc:1350
void SetUeDeviceAttribute(std::string n, const AttributeValue &v)
Set an attribute for the UE devices (LteUeNetDevice) to be created.
Definition: lte-helper.cc:425
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:277
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:1294
static LtePathlossModelTestSuite ltePathlossModelTestSuite
void SetSchedulerType(std::string type)
Set the type of scheduler to be used by eNodeB devices.
Definition: lte-helper.cc:282
Keep track of the current position and velocity of an object.
Test 1.1 pathloss calculation.
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
virtual void AddCallback(LteChunkProcessorCallback c)
Add callback to list.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
Hold an unsigned integer type.
Definition: uinteger.h:44
#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:168
holds a vector of ns3::NetDevice pointers
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
A sink to be plugged to the callback of LteChunkProcessor allowing to save and later retrieve the lat...
#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
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
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 SetPosition(const Vector &position)
Tests that the BuildingPathlossModel works according to the expected theoretical values.
NetDeviceContainer InstallUeDevice(NodeContainer c)
Create a set of UE devices.
Definition: lte-helper.cc:499
Helper class used to assign positions and mobility models to nodes.
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:993
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:782
virtual void DoRun(void)
Implementation to actually run this TestCase.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:365
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:1444
DlSchedulingCallbackInfo structure.
Definition: lte-common.h:239
Ptr< LteUePhy > GetPhy(void) const
Get the Phy.
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:185
The eNodeB device implementation.
Qci
QoS Class Indicator.
Definition: eps-bearer.h:77
void SetEnbDeviceAttribute(std::string n, const AttributeValue &v)
Set an attribute for the eNodeB devices (LteEnbNetDevice) to be created.
Definition: lte-helper.cc:403
The LteUeNetDevice class implements the UE net device.