A Discrete-Event Network Simulator
API
lte-test-pathloss-model.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Marco Miozzo <marco.miozzo@cttc.es>
18 */
19
21
22#include "lte-test-ue-phy.h"
23
24#include "ns3/double.h"
25#include "ns3/log.h"
26#include "ns3/lte-chunk-processor.h"
27#include "ns3/lte-phy-tag.h"
28#include "ns3/simulator.h"
29#include "ns3/spectrum-test.h"
30#include "ns3/string.h"
31#include <ns3/boolean.h>
32#include <ns3/building.h>
33#include <ns3/buildings-helper.h>
34#include <ns3/enum.h>
35#include <ns3/hybrid-buildings-propagation-loss-model.h>
36#include <ns3/lte-enb-net-device.h>
37#include <ns3/lte-enb-phy.h>
38#include <ns3/lte-helper.h>
39#include <ns3/lte-ue-net-device.h>
40#include <ns3/lte-ue-phy.h>
41#include <ns3/lte-ue-rrc.h>
42#include <ns3/mobility-helper.h>
43#include <ns3/net-device-container.h>
44#include <ns3/node-container.h>
45#include <ns3/single-model-spectrum-channel.h>
46
47using namespace ns3;
48
49NS_LOG_COMPONENT_DEFINE("LtePathlossModelTest");
50
60void
62 std::string path,
64{
65 testcase->DlScheduling(dlInfo);
66}
67
69 : TestSuite("lte-pathloss-model", SYSTEM)
70{
71 // LogLevel logLevel = (LogLevel)(LOG_PREFIX_FUNC | LOG_PREFIX_TIME | LOG_LEVEL_ALL);
72 // LogComponentEnable ("LteHelper", logLevel);
73 // LogComponentEnable ("LtePathlossModelTest", logLevel);
74 // LogComponentEnable ("BuildingsPropagationLossModel", logLevel);
75 // LogComponentEnable ("LteInterference", logLevel);
76 // LogComponentEnable ("LteSpectrumValueHelper", logLevel);
77 // LogComponentEnable ("LteEnbNetDevice", logLevel);
78
79 struct SnrEfficiencyMcs
80 {
81 double snrDb;
82 double efficiency;
83 int mcsIndex;
84 };
85
90 SnrEfficiencyMcs snrEfficiencyMcs[] = {
91 {-5.00000, 0.08024, -1}, {-4.00000, 0.10030, -1}, {-3.00000, 0.12518, -1},
92 {-2.00000, 0.15589, 0}, {-1.00000, 0.19365, 0}, {0.00000, 0.23983, 2},
93 {1.00000, 0.29593, 2}, {2.00000, 0.36360, 2}, {3.00000, 0.44451, 4},
94 {4.00000, 0.54031, 4}, {5.00000, 0.65251, 6}, {6.00000, 0.78240, 6},
95 {7.00000, 0.93086, 8}, {8.00000, 1.09835, 8}, {9.00000, 1.28485, 10},
96 {10.00000, 1.48981, 12}, {11.00000, 1.71229, 12}, {12.00000, 1.95096, 14},
97 {13.00000, 2.20429, 14}, {14.00000, 2.47062, 16}, {15.00000, 2.74826, 18},
98 {16.00000, 3.03560, 18}, {17.00000, 3.33115, 20}, {18.00000, 3.63355, 20},
99 {19.00000, 3.94163, 22}, {20.00000, 4.25439, 22}, {21.00000, 4.57095, 24},
100 {22.00000, 4.89060, 24}, {23.00000, 5.21276, 26}, {24.00000, 5.53693, 26},
101 {25.00000, 5.86271, 28}, {26.00000, 6.18980, 28}, {27.00000, 6.51792, 28},
102 {28.00000, 6.84687, 28}, {29.00000, 7.17649, 28}, {30.00000, 7.50663, 28},
103 };
104
105 double txPowerDbm = 30; // default eNB TX power over whole bandwidth
106 double txPowerLin = std::pow(10, (txPowerDbm - 30) / 10);
107 double ktDbm = -174; // reference LTE noise PSD
108 double noisePowerDbm =
109 ktDbm + 10 * std::log10(25 * 180000); // corresponds to kT*bandwidth in linear units
110 double receiverNoiseFigureDb = 9.0; // default UE noise figure
111 double noiseLin = std::pow(10, (noisePowerDbm - 30 + receiverNoiseFigureDb) / 10);
112
113 // reference values obtained with the octave script src/lte/test/reference/lte_pathloss.m
114
115 double loss[] = {81.062444, 134.078605, 144.259958};
116 double dist[] = {100.0, 500.0, 1500};
117
118 int numOfTests = sizeof(loss) / sizeof(double);
119 for (int i = 0; i < numOfTests; i++)
120 {
121 // double lossDb = txPowerDbm - snrEfficiencyMcs[i].snrDb - noisePowerDbm -
122 // receiverNoiseFigureDb;
123 double sinrLin = (txPowerLin / (pow(10, loss[i] / 10))) / noiseLin;
124 // double sinrDb = txPowerDbm- noisePowerDbm - receiverNoiseFigureDb - loss[i];
125 double sinrDb = 10 * std::log10(sinrLin);
126 NS_LOG_INFO(" Ptx " << txPowerDbm << " Pn " << noisePowerDbm << " Fn "
127 << receiverNoiseFigureDb << " Pl " << loss[i] << " dist " << dist[i]);
128
129 int mcs = -1;
130 int numSnrEfficiencyMcsEntries = sizeof(snrEfficiencyMcs) / sizeof(SnrEfficiencyMcs);
131 for (int j = 0; j < numSnrEfficiencyMcsEntries && snrEfficiencyMcs[j].snrDb < sinrDb; ++j)
132 {
133 mcs = snrEfficiencyMcs[j].mcsIndex;
134 }
135
136 std::ostringstream name;
137 name << " snr= " << sinrDb << " dB, "
138 << " mcs= " << snrEfficiencyMcs[i].mcsIndex;
139 AddTestCase(new LtePathlossModelSystemTestCase(name.str(), sinrDb, dist[i], mcs),
140 TestCase::QUICK);
141 }
142}
143
145
147 double snrDb,
148 double dist,
149 uint16_t mcsIndex)
150 : TestCase(name),
151 m_snrDb(snrDb),
152 m_distance(dist),
153 m_mcsIndex(mcsIndex)
154{
155 std::ostringstream sstream1;
156 std::ostringstream sstream2;
157 sstream1 << " snr=" << snrDb << " mcs=" << mcsIndex << " distance=" << dist;
158
159 NS_LOG_INFO("Creating LtePathlossModelSystemTestCase: " + sstream1.str());
160}
161
163{
164}
165
166void
168{
169 Config::SetDefault("ns3::MacStatsCalculator::DlOutputFilename",
170 StringValue(CreateTempDirFilename("DlMacStats.txt")));
171 Config::SetDefault("ns3::MacStatsCalculator::UlOutputFilename",
172 StringValue(CreateTempDirFilename("UlMacStats.txt")));
173 Config::SetDefault("ns3::RadioBearerStatsCalculator::DlRlcOutputFilename",
174 StringValue(CreateTempDirFilename("DlRlcStats.txt")));
175 Config::SetDefault("ns3::RadioBearerStatsCalculator::UlRlcOutputFilename",
176 StringValue(CreateTempDirFilename("UlRlcStats.txt")));
180 // Disable Uplink Power Control
181 Config::SetDefault("ns3::LteUePhy::EnableUplinkPowerControl", BooleanValue(false));
182
183 Ptr<LteHelper> lteHelper = CreateObject<LteHelper>();
184 // lteHelper->EnableLogComponents ();
185 lteHelper->SetAttribute("PathlossModel",
186 StringValue("ns3::HybridBuildingsPropagationLossModel"));
187
188 // set frequency. This is important because it changes the behavior of the path loss model
189 lteHelper->SetEnbDeviceAttribute("DlEarfcn", UintegerValue(200));
190 lteHelper->SetEnbDeviceAttribute("UlEarfcn", UintegerValue(18200));
191 lteHelper->SetUeDeviceAttribute("DlEarfcn", UintegerValue(200));
192
193 // remove shadowing component
194 lteHelper->SetPathlossModelAttribute("ShadowSigmaOutdoor", DoubleValue(0.0));
195 lteHelper->SetPathlossModelAttribute("ShadowSigmaIndoor", DoubleValue(0.0));
196 lteHelper->SetPathlossModelAttribute("ShadowSigmaExtWalls", DoubleValue(0.0));
197
198 // Create Nodes: eNodeB and UE
199 NodeContainer enbNodes;
200 NodeContainer ueNodes;
201 enbNodes.Create(1);
202 ueNodes.Create(1);
203 NodeContainer allNodes = NodeContainer(enbNodes, ueNodes);
204
205 // Install Mobility Model
207 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
208 mobility.Install(allNodes);
209 BuildingsHelper::Install(allNodes);
210
211 // Create Devices and install them in the Nodes (eNB and UE)
212 NetDeviceContainer enbDevs;
213 NetDeviceContainer ueDevs;
214 lteHelper->SetSchedulerType("ns3::RrFfMacScheduler");
215 enbDevs = lteHelper->InstallEnbDevice(enbNodes);
216 ueDevs = lteHelper->InstallUeDevice(ueNodes);
217
218 Ptr<MobilityModel> mm_enb = enbNodes.Get(0)->GetObject<MobilityModel>();
219 mm_enb->SetPosition(Vector(0.0, 0.0, 30.0));
220 Ptr<MobilityModel> mm_ue = ueNodes.Get(0)->GetObject<MobilityModel>();
221 mm_ue->SetPosition(Vector(m_distance, 0.0, 1.0));
222
223 Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get(0)->GetObject<LteEnbNetDevice>();
224 Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy();
225 enbPhy->SetAttribute("TxPower", DoubleValue(30.0));
226 enbPhy->SetAttribute("NoiseFigure", DoubleValue(5.0));
227
228 Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get(0)->GetObject<LteUeNetDevice>();
229 Ptr<LteUePhy> uePhy = lteUeDev->GetPhy();
230 uePhy->SetAttribute("TxPower", DoubleValue(23.0));
231 uePhy->SetAttribute("NoiseFigure", DoubleValue(9.0));
232
233 // Attach a UE to a eNB
234 lteHelper->Attach(ueDevs, enbDevs.Get(0));
235
236 // Activate an EPS bearer
237 enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE;
238 EpsBearer bearer(q);
239 lteHelper->ActivateDataRadioBearer(ueDevs, bearer);
240
241 // Use testing chunk processor in the PHY layer
242 // It will be used to test that the SNR is as intended
243 // Ptr<LtePhy> uePhy = ueDevs.Get (0)->GetObject<LteUeNetDevice> ()->GetPhy
244 // ()->GetObject<LtePhy> ();
245 Ptr<LteChunkProcessor> testSinr = Create<LteChunkProcessor>();
246 LteSpectrumValueCatcher sinrCatcher;
247 testSinr->AddCallback(MakeCallback(&LteSpectrumValueCatcher::ReportValue, &sinrCatcher));
248 uePhy->GetDownlinkSpectrumPhy()->AddCtrlSinrChunkProcessor(testSinr);
249
250 // Config::Connect ("/NodeList/0/DeviceList/0/LteEnbMac/DlScheduling",
251 // MakeBoundCallback (&LteTestPathlossDlSchedCallback, this));
252
253 lteHelper->EnableMacTraces();
254 lteHelper->EnableRlcTraces();
255
256 Simulator::Stop(Seconds(0.035));
257 Simulator::Run();
258
259 double calculatedSinrDb = 10.0 * std::log10(sinrCatcher.GetValue()->operator[](0));
260 NS_LOG_INFO("Distance " << m_distance << " Calculated SINR " << calculatedSinrDb << " ref "
261 << m_snrDb);
262 Simulator::Destroy();
263 NS_TEST_ASSERT_MSG_EQ_TOL(calculatedSinrDb, m_snrDb, 0.001, "Wrong SINR !");
264}
265
266void
268{
269 static bool firstTime = true;
270
271 if (firstTime)
272 {
273 firstTime = false;
274 NS_LOG_INFO("SNR\tRef_MCS\tCalc_MCS");
275 }
276
277 // need to allow for RRC connection establishment + SRS transmission
278 if (Simulator::Now() > MilliSeconds(21))
279 {
280 NS_LOG_INFO(m_snrDb << "\t" << m_mcsIndex << "\t" << (uint16_t)dlInfo.mcsTb1);
281
282 NS_TEST_ASSERT_MSG_EQ((uint16_t)dlInfo.mcsTb1, m_mcsIndex, "Wrong MCS index");
283 }
284}
Tests that the BuildingPathlossModel works according to the expected theoretical values.
void DlScheduling(DlSchedulingCallbackInfo dlInfo)
DL scheduling function.
void DoRun() override
Implementation to actually run this TestCase.
Test 1.1 pathloss calculation.
AttributeValue implementation for Boolean.
Definition: boolean.h:37
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
This class contains the specification of EPS Bearers.
Definition: eps-bearer.h:91
Qci
QoS Class Indicator.
Definition: eps-bearer.h:106
The eNodeB device implementation.
Ptr< LteEnbPhy > GetPhy() const
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Create a set of eNodeB devices.
Definition: lte-helper.cc:482
void SetSchedulerType(std::string type)
Set the type of scheduler to be used by eNodeB devices.
Definition: lte-helper.cc:289
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:1044
void SetPathlossModelAttribute(std::string n, const AttributeValue &v)
Set an attribute for the path loss models to be created.
Definition: lte-helper.cc:402
void EnableRlcTraces()
Enable trace sinks for RLC layer.
Definition: lte-helper.cc:1563
void SetEnbDeviceAttribute(std::string n, const AttributeValue &v)
Set an attribute for the eNodeB devices (LteEnbNetDevice) to be created.
Definition: lte-helper.cc:409
void ActivateDataRadioBearer(NetDeviceContainer ueDevices, EpsBearer bearer)
Activate a Data Radio Bearer on a given UE devices (for LTE-only simulation).
Definition: lte-helper.cc:1441
NetDeviceContainer InstallUeDevice(NodeContainer c)
Create a set of UE devices.
Definition: lte-helper.cc:497
void EnableMacTraces()
Enable trace sinks for MAC layer.
Definition: lte-helper.cc:1666
void SetUeDeviceAttribute(std::string n, const AttributeValue &v)
Set an attribute for the UE devices (LteUeNetDevice) to be created.
Definition: lte-helper.cc:430
A sink to be plugged to the callback of LteChunkProcessor allowing to save and later retrieve the lat...
Ptr< SpectrumValue > GetValue()
The LteUeNetDevice class implements the UE net device.
Helper class used to assign positions and mobility models to nodes.
Keep track of the current position and velocity of an object.
void SetPosition(const Vector &position)
holds a vector of ns3::NetDevice pointers
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:258
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
Hold variables of type string.
Definition: string.h:42
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
std::string CreateTempDirFilename(std::string filename)
Construct the full path to a file in a temporary directory.
Definition: test.cc:442
A suite of tests to run.
Definition: test.h:1256
Hold an unsigned integer type.
Definition: uinteger.h:45
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:891
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:296
#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:144
#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:337
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1350
void LteTestPathlossDlSchedCallback(LtePathlossModelSystemTestCase *testcase, std::string path, DlSchedulingCallbackInfo dlInfo)
Test 1.1 Pathloss compound test.
static LtePathlossModelTestSuite ltePathlossModelTestSuite
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:691
mobility
Definition: third.py:96
DlSchedulingCallbackInfo structure.
Definition: lte-common.h:231