A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
lte-test-link-adaptation.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: Manuel Requena <manuel.requena@cttc.es>
7 */
8
10
11#include "ns3/boolean.h"
12#include "ns3/double.h"
13#include "ns3/enum.h"
14#include "ns3/log.h"
15#include "ns3/lte-chunk-processor.h"
16#include "ns3/lte-helper.h"
17#include "ns3/lte-ue-net-device.h"
18#include "ns3/lte-ue-phy.h"
19#include "ns3/mobility-helper.h"
20#include "ns3/simulator.h"
21#include "ns3/string.h"
22
23using namespace ns3;
24
25NS_LOG_COMPONENT_DEFINE("LteLinkAdaptationTest");
26
27/**
28 * Test 1.3 Link Adaptation
29 */
30
31void
33 std::string path,
35{
36 testcase->DlScheduling(dlInfo);
37}
38
39/**
40 * TestSuite
41 */
42
44 : TestSuite("lte-link-adaptation", Type::SYSTEM)
45{
46 NS_LOG_INFO("Creating LteLinkAdaptionTestSuite");
47
48 struct SnrEfficiencyMcs
49 {
50 double snrDb;
51 double efficiency;
52 int mcsIndex;
53 };
54
55 /**
56 * Test vectors: SNRDB, Spectral Efficiency, MCS index
57 * From XXX
58 */
59 SnrEfficiencyMcs snrEfficiencyMcs[] = {
60 {-5.00000, 0.08024, -1}, {-4.00000, 0.10030, -1}, {-3.00000, 0.12518, -1},
61 {-2.00000, 0.15589, 0}, {-1.00000, 0.19365, 0}, {0.00000, 0.23983, 2},
62 {1.00000, 0.29593, 2}, {2.00000, 0.36360, 2}, {3.00000, 0.44451, 4},
63 {4.00000, 0.54031, 4}, {5.00000, 0.65251, 6}, {6.00000, 0.78240, 6},
64 {7.00000, 0.93086, 8}, {8.00000, 1.09835, 8}, {9.00000, 1.28485, 10},
65 {10.00000, 1.48981, 12}, {11.00000, 1.71229, 12}, {12.00000, 1.95096, 14},
66 {13.00000, 2.20429, 14}, {14.00000, 2.47062, 16}, {15.00000, 2.74826, 18},
67 {16.00000, 3.03560, 18}, {17.00000, 3.33115, 20}, {18.00000, 3.63355, 20},
68 {19.00000, 3.94163, 22}, {20.00000, 4.25439, 22}, {21.00000, 4.57095, 24},
69 {22.00000, 4.89060, 24}, {23.00000, 5.21276, 26}, {24.00000, 5.53693, 26},
70 {25.00000, 5.86271, 28}, {26.00000, 6.18980, 28}, {27.00000, 6.51792, 28},
71 {28.00000, 6.84687, 28}, {29.00000, 7.17649, 28}, {30.00000, 7.50663, 28},
72 };
73 int numOfTests = sizeof(snrEfficiencyMcs) / sizeof(SnrEfficiencyMcs);
74
75 double txPowerDbm = 30; // default eNB TX power over whole bandwidth
76 double ktDbm = -174; // reference LTE noise PSD
77 double noisePowerDbm =
78 ktDbm + 10 * std::log10(25 * 180000); // corresponds to kT*bandwidth in linear units
79 double receiverNoiseFigureDb = 9.0; // default UE noise figure
80
81 for (int i = 0; i < numOfTests; i++)
82 {
83 double lossDb =
84 txPowerDbm - snrEfficiencyMcs[i].snrDb - noisePowerDbm - receiverNoiseFigureDb;
85
86 std::ostringstream name;
87 name << " snr= " << snrEfficiencyMcs[i].snrDb << " dB, "
88 << " mcs= " << snrEfficiencyMcs[i].mcsIndex;
90 snrEfficiencyMcs[i].snrDb,
91 lossDb,
92 snrEfficiencyMcs[i].mcsIndex),
93 TestCase::Duration::QUICK);
94 }
95}
96
97/**
98 * @ingroup lte-test
99 * Static variable for test initialization
100 */
102
103/**
104 * TestCase
105 */
106
108 double snrDb,
109 double loss,
110 uint16_t mcsIndex)
111 : TestCase(name),
112 m_snrDb(snrDb),
113 m_loss(loss),
114 m_mcsIndex(mcsIndex)
115{
116 std::ostringstream sstream1;
117 std::ostringstream sstream2;
118 sstream1 << " snr=" << snrDb << " mcs=" << mcsIndex;
119
120 NS_LOG_INFO("Creating LteLinkAdaptationTestCase: " + sstream1.str());
121}
122
126
127void
129{
130 SetDataDir(NS_TEST_SOURCEDIR);
132 Config::SetDefault("ns3::LteAmc::AmcModel", EnumValue(LteAmc::PiroEW2010));
133 Config::SetDefault("ns3::LteAmc::Ber", DoubleValue(0.00005));
134 Config::SetDefault("ns3::LteEnbRrc::SrsPeriodicity", UintegerValue(2));
135 Config::SetDefault("ns3::LteHelper::UseIdealRrc", BooleanValue(true));
136 Config::SetDefault("ns3::MacStatsCalculator::DlOutputFilename",
137 StringValue(CreateTempDirFilename("DlMacStats.txt")));
138 Config::SetDefault("ns3::MacStatsCalculator::UlOutputFilename",
139 StringValue(CreateTempDirFilename("UlMacStats.txt")));
140 Config::SetDefault("ns3::RadioBearerStatsCalculator::DlRlcOutputFilename",
141 StringValue(CreateTempDirFilename("DlRlcStats.txt")));
142 Config::SetDefault("ns3::RadioBearerStatsCalculator::UlRlcOutputFilename",
143 StringValue(CreateTempDirFilename("UlRlcStats.txt")));
144
145 // Disable Uplink Power Control
146 Config::SetDefault("ns3::LteUePhy::EnableUplinkPowerControl", BooleanValue(false));
147
148 /**
149 * Simulation Topology
150 */
151
153 // lteHelper->EnableLogComponents ();
154 lteHelper->SetAttribute("PathlossModel",
155 StringValue("ns3::ConstantSpectrumPropagationLossModel"));
156 NS_LOG_INFO("SNR = " << m_snrDb << " LOSS = " << m_loss);
157 lteHelper->SetPathlossModelAttribute("Loss", DoubleValue(m_loss));
158
159 // Create Nodes: eNodeB and UE
160 NodeContainer enbNodes;
161 NodeContainer ueNodes;
162 enbNodes.Create(1);
163 ueNodes.Create(1);
164 NodeContainer allNodes = NodeContainer(enbNodes, ueNodes);
165
166 // Install Mobility Model
167 MobilityHelper mobility;
168 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
169 mobility.Install(allNodes);
170
171 // Create Devices and install them in the Nodes (eNB and UE)
172 NetDeviceContainer enbDevs;
173 NetDeviceContainer ueDevs;
174 lteHelper->SetSchedulerType("ns3::RrFfMacScheduler");
175 enbDevs = lteHelper->InstallEnbDevice(enbNodes);
176 ueDevs = lteHelper->InstallUeDevice(ueNodes);
177
178 // Attach a UE to a eNB
179 lteHelper->Attach(ueDevs, enbDevs.Get(0));
180
181 // Activate the default EPS bearer
183 EpsBearer bearer(q);
184 lteHelper->ActivateDataRadioBearer(ueDevs, bearer);
185
186 // Use testing chunk processor in the PHY layer
187 // It will be used to test that the SNR is as intended
188 Ptr<LtePhy> uePhy = ueDevs.Get(0)->GetObject<LteUeNetDevice>()->GetPhy()->GetObject<LtePhy>();
190 LteSpectrumValueCatcher sinrCatcher;
191 testSinr->AddCallback(MakeCallback(&LteSpectrumValueCatcher::ReportValue, &sinrCatcher));
192 uePhy->GetDownlinkSpectrumPhy()->AddCtrlSinrChunkProcessor(testSinr);
193
194 Config::Connect("/NodeList/0/DeviceList/0/ComponentCarrierMap/*/LteEnbMac/DlScheduling",
196
197 lteHelper->EnableMacTraces();
198 lteHelper->EnableRlcTraces();
199
200 Simulator::Stop(Seconds(0.040));
202
203 double calculatedSinrDb = 10.0 * std::log10(sinrCatcher.GetValue()->operator[](0));
204 NS_TEST_ASSERT_MSG_EQ_TOL(calculatedSinrDb, m_snrDb, 0.0000001, "Wrong SINR !");
206}
207
208void
210{
211 static bool firstTime = true;
212
213 if (firstTime)
214 {
215 firstTime = false;
216 NS_LOG_INFO("SNR\tRef_MCS\tCalc_MCS");
217 }
218
219 /**
220 * Note:
221 * the MCS can only be properly evaluated after:
222 * RRC connection has been completed and
223 * CQI feedback is available at the eNB.
224 */
225 if (Simulator::Now().GetSeconds() > 0.030)
226 {
227 NS_LOG_INFO(m_snrDb << "\t" << m_mcsIndex << "\t" << (uint16_t)dlInfo.mcsTb1);
228
229 NS_TEST_ASSERT_MSG_EQ((uint16_t)dlInfo.mcsTb1, m_mcsIndex, "Wrong MCS index");
230 }
231}
AttributeValue implementation for Boolean.
Definition boolean.h:26
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
Hold variables of type enum.
Definition enum.h:52
This class contains the specification of EPS Bearers.
Definition eps-bearer.h:80
Qci
QoS Class Indicator.
Definition eps-bearer.h:95
@ NGBR_VIDEO_TCP_DEFAULT
Non-GBR TCP-based Video (Buffered Streaming, e.g., www, e-mail...)
Definition eps-bearer.h:115
The LtePhy models the physical layer of LTE.
Definition lte-phy.h:40
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.
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< 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 Reset()
Reset the initial value of every attribute as well as the value of every global to what they were bef...
Definition config.cc:851
void SetDefault(std::string name, const AttributeValue &value)
Definition config.cc:886
void Connect(std::string path, const CallbackBase &cb)
Definition config.cc:970
#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 LteLinkAdaptationTestSuite lteLinkAdaptationTestSuite
Static variable for test initialization.
auto MakeBoundCallback(R(*fnPtr)(Args...), BArgs &&... bargs)
Make Callbacks with varying number of bound arguments.
Definition callback.h:745
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
void LteTestDlSchedulingCallback(CarrierAggregationTestCase *testcase, std::string path, DlSchedulingCallbackInfo dlInfo)
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