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/log.h"
14#include "ns3/lte-helper.h"
15#include "ns3/lte-ue-net-device.h"
16#include "ns3/lte-ue-phy.h"
17#include "ns3/mobility-helper.h"
18#include "ns3/simulator.h"
19#include "ns3/string.h"
20#include <ns3/enum.h>
21#include <ns3/lte-chunk-processor.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{
131 Config::SetDefault("ns3::LteAmc::AmcModel", EnumValue(LteAmc::PiroEW2010));
132 Config::SetDefault("ns3::LteAmc::Ber", DoubleValue(0.00005));
133 Config::SetDefault("ns3::LteEnbRrc::SrsPeriodicity", UintegerValue(2));
134 Config::SetDefault("ns3::LteHelper::UseIdealRrc", BooleanValue(true));
135 Config::SetDefault("ns3::MacStatsCalculator::DlOutputFilename",
136 StringValue(CreateTempDirFilename("DlMacStats.txt")));
137 Config::SetDefault("ns3::MacStatsCalculator::UlOutputFilename",
138 StringValue(CreateTempDirFilename("UlMacStats.txt")));
139 Config::SetDefault("ns3::RadioBearerStatsCalculator::DlRlcOutputFilename",
140 StringValue(CreateTempDirFilename("DlRlcStats.txt")));
141 Config::SetDefault("ns3::RadioBearerStatsCalculator::UlRlcOutputFilename",
142 StringValue(CreateTempDirFilename("UlRlcStats.txt")));
143
144 // Disable Uplink Power Control
145 Config::SetDefault("ns3::LteUePhy::EnableUplinkPowerControl", BooleanValue(false));
146
147 /**
148 * Simulation Topology
149 */
150
152 // lteHelper->EnableLogComponents ();
153 lteHelper->SetAttribute("PathlossModel",
154 StringValue("ns3::ConstantSpectrumPropagationLossModel"));
155 NS_LOG_INFO("SNR = " << m_snrDb << " LOSS = " << m_loss);
156 lteHelper->SetPathlossModelAttribute("Loss", DoubleValue(m_loss));
157
158 // Create Nodes: eNodeB and UE
159 NodeContainer enbNodes;
160 NodeContainer ueNodes;
161 enbNodes.Create(1);
162 ueNodes.Create(1);
163 NodeContainer allNodes = NodeContainer(enbNodes, ueNodes);
164
165 // Install Mobility Model
166 MobilityHelper mobility;
167 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
168 mobility.Install(allNodes);
169
170 // Create Devices and install them in the Nodes (eNB and UE)
171 NetDeviceContainer enbDevs;
172 NetDeviceContainer ueDevs;
173 lteHelper->SetSchedulerType("ns3::RrFfMacScheduler");
174 enbDevs = lteHelper->InstallEnbDevice(enbNodes);
175 ueDevs = lteHelper->InstallUeDevice(ueNodes);
176
177 // Attach a UE to a eNB
178 lteHelper->Attach(ueDevs, enbDevs.Get(0));
179
180 // Activate the default EPS bearer
182 EpsBearer bearer(q);
183 lteHelper->ActivateDataRadioBearer(ueDevs, bearer);
184
185 // Use testing chunk processor in the PHY layer
186 // It will be used to test that the SNR is as intended
187 Ptr<LtePhy> uePhy = ueDevs.Get(0)->GetObject<LteUeNetDevice>()->GetPhy()->GetObject<LtePhy>();
189 LteSpectrumValueCatcher sinrCatcher;
190 testSinr->AddCallback(MakeCallback(&LteSpectrumValueCatcher::ReportValue, &sinrCatcher));
191 uePhy->GetDownlinkSpectrumPhy()->AddCtrlSinrChunkProcessor(testSinr);
192
193 Config::Connect("/NodeList/0/DeviceList/0/ComponentCarrierMap/*/LteEnbMac/DlScheduling",
195
196 lteHelper->EnableMacTraces();
197 lteHelper->EnableRlcTraces();
198
199 Simulator::Stop(Seconds(0.040));
201
202 double calculatedSinrDb = 10.0 * std::log10(sinrCatcher.GetValue()->operator[](0));
203 NS_TEST_ASSERT_MSG_EQ_TOL(calculatedSinrDb, m_snrDb, 0.0000001, "Wrong SINR !");
205}
206
207void
209{
210 static bool firstTime = true;
211
212 if (firstTime)
213 {
214 firstTime = false;
215 NS_LOG_INFO("SNR\tRef_MCS\tCalc_MCS");
216 }
217
218 /**
219 * Note:
220 * the MCS can only be properly evaluated after:
221 * RRC connection has been completed and
222 * CQI feedback is available at the eNB.
223 */
224 if (Simulator::Now().GetSeconds() > 0.030)
225 {
226 NS_LOG_INFO(m_snrDb << "\t" << m_mcsIndex << "\t" << (uint16_t)dlInfo.mcsTb1);
227
228 NS_TEST_ASSERT_MSG_EQ((uint16_t)dlInfo.mcsTb1, m_mcsIndex, "Wrong MCS index");
229 }
230}
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
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:848
void SetDefault(std::string name, const AttributeValue &value)
Definition config.cc:883
void Connect(std::string path, const CallbackBase &cb)
Definition config.cc:967
#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:436
#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:1308
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