A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Marco Miozzo <marco.miozzo@cttc.es>
7 */
8
10
11#include "lte-test-ue-phy.h"
12
13#include "ns3/boolean.h"
14#include "ns3/building.h"
15#include "ns3/buildings-helper.h"
16#include "ns3/double.h"
17#include "ns3/enum.h"
18#include "ns3/hybrid-buildings-propagation-loss-model.h"
19#include "ns3/log.h"
20#include "ns3/lte-chunk-processor.h"
21#include "ns3/lte-enb-net-device.h"
22#include "ns3/lte-enb-phy.h"
23#include "ns3/lte-helper.h"
24#include "ns3/lte-phy-tag.h"
25#include "ns3/lte-ue-net-device.h"
26#include "ns3/lte-ue-phy.h"
27#include "ns3/lte-ue-rrc.h"
28#include "ns3/mobility-helper.h"
29#include "ns3/net-device-container.h"
30#include "ns3/node-container.h"
31#include "ns3/simulator.h"
32#include "ns3/single-model-spectrum-channel.h"
33#include "ns3/spectrum-test.h"
34#include "ns3/string.h"
35
36using namespace ns3;
37
38NS_LOG_COMPONENT_DEFINE("LtePathlossModelTest");
39
40/**
41 * Test 1.1 Pathloss compound test
42 */
43
44/**
45 * This TestSuite tests the BuildingPathlossModel by reproducing
46 * several communication scenarios
47 */
48
49void
51 std::string path,
53{
54 testcase->DlScheduling(dlInfo);
55}
56
58 : TestSuite("lte-pathloss-model", Type::SYSTEM)
59{
60 // LogLevel logLevel = (LogLevel)(LOG_PREFIX_FUNC | LOG_PREFIX_TIME | LOG_LEVEL_ALL);
61 // LogComponentEnable ("LteHelper", logLevel);
62 // LogComponentEnable ("LtePathlossModelTest", logLevel);
63 // LogComponentEnable ("BuildingsPropagationLossModel", logLevel);
64 // LogComponentEnable ("LteInterference", logLevel);
65 // LogComponentEnable ("LteSpectrumValueHelper", logLevel);
66 // LogComponentEnable ("LteEnbNetDevice", logLevel);
67
68 struct SnrEfficiencyMcs
69 {
70 double snrDb;
71 double efficiency;
72 int mcsIndex;
73 };
74
75 /**
76 * Test vectors: SNRDB, Spectral Efficiency, MCS index
77 * From XXX
78 */
79 SnrEfficiencyMcs snrEfficiencyMcs[] = {
80 {-5.00000, 0.08024, -1}, {-4.00000, 0.10030, -1}, {-3.00000, 0.12518, -1},
81 {-2.00000, 0.15589, 0}, {-1.00000, 0.19365, 0}, {0.00000, 0.23983, 2},
82 {1.00000, 0.29593, 2}, {2.00000, 0.36360, 2}, {3.00000, 0.44451, 4},
83 {4.00000, 0.54031, 4}, {5.00000, 0.65251, 6}, {6.00000, 0.78240, 6},
84 {7.00000, 0.93086, 8}, {8.00000, 1.09835, 8}, {9.00000, 1.28485, 10},
85 {10.00000, 1.48981, 12}, {11.00000, 1.71229, 12}, {12.00000, 1.95096, 14},
86 {13.00000, 2.20429, 14}, {14.00000, 2.47062, 16}, {15.00000, 2.74826, 18},
87 {16.00000, 3.03560, 18}, {17.00000, 3.33115, 20}, {18.00000, 3.63355, 20},
88 {19.00000, 3.94163, 22}, {20.00000, 4.25439, 22}, {21.00000, 4.57095, 24},
89 {22.00000, 4.89060, 24}, {23.00000, 5.21276, 26}, {24.00000, 5.53693, 26},
90 {25.00000, 5.86271, 28}, {26.00000, 6.18980, 28}, {27.00000, 6.51792, 28},
91 {28.00000, 6.84687, 28}, {29.00000, 7.17649, 28}, {30.00000, 7.50663, 28},
92 };
93
94 double txPowerDbm = 30; // default eNB TX power over whole bandwidth
95 double txPowerLin = std::pow(10, (txPowerDbm - 30) / 10);
96 double ktDbm = -174; // reference LTE noise PSD
97 double noisePowerDbm =
98 ktDbm + 10 * std::log10(25 * 180000); // corresponds to kT*bandwidth in linear units
99 double receiverNoiseFigureDb = 9.0; // default UE noise figure
100 double noiseLin = std::pow(10, (noisePowerDbm - 30 + receiverNoiseFigureDb) / 10);
101
102 // reference values obtained with the octave script src/lte/test/reference/lte_pathloss.m
103
104 double loss[] = {81.062444, 134.078605, 144.259958};
105 double dist[] = {100.0, 500.0, 1500};
106
107 int numOfTests = sizeof(loss) / sizeof(double);
108 for (int i = 0; i < numOfTests; i++)
109 {
110 // double lossDb = txPowerDbm - snrEfficiencyMcs[i].snrDb - noisePowerDbm -
111 // receiverNoiseFigureDb;
112 double sinrLin = (txPowerLin / (pow(10, loss[i] / 10))) / noiseLin;
113 // double sinrDb = txPowerDbm- noisePowerDbm - receiverNoiseFigureDb - loss[i];
114 double sinrDb = 10 * std::log10(sinrLin);
115 NS_LOG_INFO(" Ptx " << txPowerDbm << " Pn " << noisePowerDbm << " Fn "
116 << receiverNoiseFigureDb << " Pl " << loss[i] << " dist " << dist[i]);
117
118 int mcs = -1;
119 int numSnrEfficiencyMcsEntries = sizeof(snrEfficiencyMcs) / sizeof(SnrEfficiencyMcs);
120 for (int j = 0; j < numSnrEfficiencyMcsEntries && snrEfficiencyMcs[j].snrDb < sinrDb; ++j)
121 {
122 mcs = snrEfficiencyMcs[j].mcsIndex;
123 }
124
125 std::ostringstream name;
126 name << " snr= " << sinrDb << " dB, "
127 << " mcs= " << snrEfficiencyMcs[i].mcsIndex;
128 AddTestCase(new LtePathlossModelSystemTestCase(name.str(), sinrDb, dist[i], mcs),
129 TestCase::Duration::QUICK);
130 }
131}
132
133/**
134 * @ingroup lte-test
135 * Static variable for test initialization
136 */
138
140 double snrDb,
141 double dist,
142 uint16_t mcsIndex)
143 : TestCase(name),
144 m_snrDb(snrDb),
145 m_distance(dist),
146 m_mcsIndex(mcsIndex)
147{
148 std::ostringstream sstream1;
149 std::ostringstream sstream2;
150 sstream1 << " snr=" << snrDb << " mcs=" << mcsIndex << " distance=" << dist;
151
152 NS_LOG_INFO("Creating LtePathlossModelSystemTestCase: " + sstream1.str());
153}
154
158
159void
161{
162 SetDataDir(NS_TEST_SOURCEDIR);
163 Config::SetDefault("ns3::MacStatsCalculator::DlOutputFilename",
164 StringValue(CreateTempDirFilename("DlMacStats.txt")));
165 Config::SetDefault("ns3::MacStatsCalculator::UlOutputFilename",
166 StringValue(CreateTempDirFilename("UlMacStats.txt")));
167 Config::SetDefault("ns3::RadioBearerStatsCalculator::DlRlcOutputFilename",
168 StringValue(CreateTempDirFilename("DlRlcStats.txt")));
169 Config::SetDefault("ns3::RadioBearerStatsCalculator::UlRlcOutputFilename",
170 StringValue(CreateTempDirFilename("UlRlcStats.txt")));
171 /**
172 * Simulation Topology
173 */
174 // Disable Uplink Power Control
175 Config::SetDefault("ns3::LteUePhy::EnableUplinkPowerControl", BooleanValue(false));
176
178 // lteHelper->EnableLogComponents ();
179 lteHelper->SetAttribute("PathlossModel",
180 StringValue("ns3::HybridBuildingsPropagationLossModel"));
181
182 // set frequency. This is important because it changes the behavior of the path loss model
183 lteHelper->SetEnbDeviceAttribute("DlEarfcn", UintegerValue(200));
184 lteHelper->SetEnbDeviceAttribute("UlEarfcn", UintegerValue(18200));
185 lteHelper->SetUeDeviceAttribute("DlEarfcn", UintegerValue(200));
186
187 // remove shadowing component
188 lteHelper->SetPathlossModelAttribute("ShadowSigmaOutdoor", DoubleValue(0.0));
189 lteHelper->SetPathlossModelAttribute("ShadowSigmaIndoor", DoubleValue(0.0));
190 lteHelper->SetPathlossModelAttribute("ShadowSigmaExtWalls", DoubleValue(0.0));
191
192 // Create Nodes: eNodeB and UE
193 NodeContainer enbNodes;
194 NodeContainer ueNodes;
195 enbNodes.Create(1);
196 ueNodes.Create(1);
197 NodeContainer allNodes = NodeContainer(enbNodes, ueNodes);
198
199 // Install Mobility Model
200 MobilityHelper mobility;
201 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
202 mobility.Install(allNodes);
203 BuildingsHelper::Install(allNodes);
204
205 // Create Devices and install them in the Nodes (eNB and UE)
206 NetDeviceContainer enbDevs;
207 NetDeviceContainer ueDevs;
208 lteHelper->SetSchedulerType("ns3::RrFfMacScheduler");
209 enbDevs = lteHelper->InstallEnbDevice(enbNodes);
210 ueDevs = lteHelper->InstallUeDevice(ueNodes);
211
212 Ptr<MobilityModel> mm_enb = enbNodes.Get(0)->GetObject<MobilityModel>();
213 mm_enb->SetPosition(Vector(0.0, 0.0, 30.0));
214 Ptr<MobilityModel> mm_ue = ueNodes.Get(0)->GetObject<MobilityModel>();
215 mm_ue->SetPosition(Vector(m_distance, 0.0, 1.0));
216
217 Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get(0)->GetObject<LteEnbNetDevice>();
218 Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy();
219 enbPhy->SetAttribute("TxPower", DoubleValue(30.0));
220 enbPhy->SetAttribute("NoiseFigure", DoubleValue(5.0));
221
222 Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get(0)->GetObject<LteUeNetDevice>();
223 Ptr<LteUePhy> uePhy = lteUeDev->GetPhy();
224 uePhy->SetAttribute("TxPower", DoubleValue(23.0));
225 uePhy->SetAttribute("NoiseFigure", DoubleValue(9.0));
226
227 // Attach a UE to a eNB
228 lteHelper->Attach(ueDevs, enbDevs.Get(0));
229
230 // Activate an EPS bearer
232 EpsBearer bearer(q);
233 lteHelper->ActivateDataRadioBearer(ueDevs, bearer);
234
235 // Use testing chunk processor in the PHY layer
236 // It will be used to test that the SNR is as intended
237 // Ptr<LtePhy> uePhy = ueDevs.Get (0)->GetObject<LteUeNetDevice> ()->GetPhy
238 // ()->GetObject<LtePhy> ();
240 LteSpectrumValueCatcher sinrCatcher;
241 testSinr->AddCallback(MakeCallback(&LteSpectrumValueCatcher::ReportValue, &sinrCatcher));
242 uePhy->GetDownlinkSpectrumPhy()->AddCtrlSinrChunkProcessor(testSinr);
243
244 // Config::Connect ("/NodeList/0/DeviceList/0/LteEnbMac/DlScheduling",
245 // MakeBoundCallback (&LteTestPathlossDlSchedCallback, this));
246
247 lteHelper->EnableMacTraces();
248 lteHelper->EnableRlcTraces();
249
250 Simulator::Stop(Seconds(0.035));
252
253 double calculatedSinrDb = 10.0 * std::log10(sinrCatcher.GetValue()->operator[](0));
254 NS_LOG_INFO("Distance " << m_distance << " Calculated SINR " << calculatedSinrDb << " ref "
255 << m_snrDb);
257 NS_TEST_ASSERT_MSG_EQ_TOL(calculatedSinrDb, m_snrDb, 0.001, "Wrong SINR !");
258}
259
260void
262{
263 static bool firstTime = true;
264
265 if (firstTime)
266 {
267 firstTime = false;
268 NS_LOG_INFO("SNR\tRef_MCS\tCalc_MCS");
269 }
270
271 // need to allow for RRC connection establishment + SRS transmission
272 if (Simulator::Now() > MilliSeconds(21))
273 {
274 NS_LOG_INFO(m_snrDb << "\t" << m_mcsIndex << "\t" << (uint16_t)dlInfo.mcsTb1);
275
276 NS_TEST_ASSERT_MSG_EQ((uint16_t)dlInfo.mcsTb1, m_mcsIndex, "Wrong MCS index");
277 }
278}
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:26
static void Install(Ptr< Node > node)
Install the MobilityBuildingInfo to a node.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
This class contains the specification of EPS Bearers.
Definition eps-bearer.h:80
Qci
QoS Class Indicator.
Definition eps-bearer.h:95
@ GBR_CONV_VOICE
GBR Conversational Voice.
Definition eps-bearer.h:96
The eNodeB device implementation.
A sink to be plugged to the callback of LteChunkProcessor allowing to save and later retrieve the lat...
Ptr< SpectrumValue > GetValue()
void ReportValue(const SpectrumValue &value)
function to be plugged to LteChunkProcessor::AddCallback ()
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.
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.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition object.h:511
Smart pointer class similar to boost::intrusive_ptr.
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
Hold variables of type string.
Definition string.h:45
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
std::string CreateTempDirFilename(std::string filename)
Construct the full path to a file in a temporary directory.
Definition test.cc:432
void SetDataDir(std::string directory)
Set the data directory where reference trace files can be found.
Definition test.cc:472
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
Hold an unsigned integer type.
Definition uinteger.h:34
void SetDefault(std::string name, const AttributeValue &value)
Definition config.cc:886
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
static LtePathlossModelTestSuite ltePathlossModelTestSuite
Static variable for test initialization.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:439
#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:134
#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:327
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1345
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1357
void LteTestPathlossDlSchedCallback(LtePathlossModelSystemTestCase *testcase, std::string path, DlSchedulingCallbackInfo dlInfo)
Test 1.1 Pathloss compound test.
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:684
DlSchedulingCallbackInfo structure.
Definition lte-common.h:226