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 * 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: Manuel Requena <manuel.requena@cttc.es>
18 */
19
21
22#include "ns3/boolean.h"
23#include "ns3/double.h"
24#include "ns3/log.h"
25#include "ns3/lte-helper.h"
26#include "ns3/lte-ue-net-device.h"
27#include "ns3/lte-ue-phy.h"
28#include "ns3/mobility-helper.h"
29#include "ns3/simulator.h"
30#include "ns3/string.h"
31#include <ns3/enum.h>
32#include <ns3/lte-chunk-processor.h>
33
34using namespace ns3;
35
36NS_LOG_COMPONENT_DEFINE("LteLinkAdaptationTest");
37
38/**
39 * Test 1.3 Link Adaptation
40 */
41
42void
44 std::string path,
46{
47 testcase->DlScheduling(dlInfo);
48}
49
50/**
51 * TestSuite
52 */
53
55 : TestSuite("lte-link-adaptation", Type::SYSTEM)
56{
57 NS_LOG_INFO("Creating LteLinkAdaptionTestSuite");
58
59 struct SnrEfficiencyMcs
60 {
61 double snrDb;
62 double efficiency;
63 int mcsIndex;
64 };
65
66 /**
67 * Test vectors: SNRDB, Spectral Efficiency, MCS index
68 * From XXX
69 */
70 SnrEfficiencyMcs snrEfficiencyMcs[] = {
71 {-5.00000, 0.08024, -1}, {-4.00000, 0.10030, -1}, {-3.00000, 0.12518, -1},
72 {-2.00000, 0.15589, 0}, {-1.00000, 0.19365, 0}, {0.00000, 0.23983, 2},
73 {1.00000, 0.29593, 2}, {2.00000, 0.36360, 2}, {3.00000, 0.44451, 4},
74 {4.00000, 0.54031, 4}, {5.00000, 0.65251, 6}, {6.00000, 0.78240, 6},
75 {7.00000, 0.93086, 8}, {8.00000, 1.09835, 8}, {9.00000, 1.28485, 10},
76 {10.00000, 1.48981, 12}, {11.00000, 1.71229, 12}, {12.00000, 1.95096, 14},
77 {13.00000, 2.20429, 14}, {14.00000, 2.47062, 16}, {15.00000, 2.74826, 18},
78 {16.00000, 3.03560, 18}, {17.00000, 3.33115, 20}, {18.00000, 3.63355, 20},
79 {19.00000, 3.94163, 22}, {20.00000, 4.25439, 22}, {21.00000, 4.57095, 24},
80 {22.00000, 4.89060, 24}, {23.00000, 5.21276, 26}, {24.00000, 5.53693, 26},
81 {25.00000, 5.86271, 28}, {26.00000, 6.18980, 28}, {27.00000, 6.51792, 28},
82 {28.00000, 6.84687, 28}, {29.00000, 7.17649, 28}, {30.00000, 7.50663, 28},
83 };
84 int numOfTests = sizeof(snrEfficiencyMcs) / sizeof(SnrEfficiencyMcs);
85
86 double txPowerDbm = 30; // default eNB TX power over whole bandwidth
87 double ktDbm = -174; // reference LTE noise PSD
88 double noisePowerDbm =
89 ktDbm + 10 * std::log10(25 * 180000); // corresponds to kT*bandwidth in linear units
90 double receiverNoiseFigureDb = 9.0; // default UE noise figure
91
92 for (int i = 0; i < numOfTests; i++)
93 {
94 double lossDb =
95 txPowerDbm - snrEfficiencyMcs[i].snrDb - noisePowerDbm - receiverNoiseFigureDb;
96
97 std::ostringstream name;
98 name << " snr= " << snrEfficiencyMcs[i].snrDb << " dB, "
99 << " mcs= " << snrEfficiencyMcs[i].mcsIndex;
101 snrEfficiencyMcs[i].snrDb,
102 lossDb,
103 snrEfficiencyMcs[i].mcsIndex),
104 TestCase::Duration::QUICK);
105 }
106}
107
108/**
109 * \ingroup lte-test
110 * Static variable for test initialization
111 */
113
114/**
115 * TestCase
116 */
117
119 double snrDb,
120 double loss,
121 uint16_t mcsIndex)
122 : TestCase(name),
123 m_snrDb(snrDb),
124 m_loss(loss),
125 m_mcsIndex(mcsIndex)
126{
127 std::ostringstream sstream1;
128 std::ostringstream sstream2;
129 sstream1 << " snr=" << snrDb << " mcs=" << mcsIndex;
130
131 NS_LOG_INFO("Creating LteLinkAdaptationTestCase: " + sstream1.str());
132}
133
135{
136}
137
138void
140{
142 Config::SetDefault("ns3::LteAmc::AmcModel", EnumValue(LteAmc::PiroEW2010));
143 Config::SetDefault("ns3::LteAmc::Ber", DoubleValue(0.00005));
144 Config::SetDefault("ns3::LteEnbRrc::SrsPeriodicity", UintegerValue(2));
145 Config::SetDefault("ns3::LteHelper::UseIdealRrc", BooleanValue(true));
146 Config::SetDefault("ns3::MacStatsCalculator::DlOutputFilename",
147 StringValue(CreateTempDirFilename("DlMacStats.txt")));
148 Config::SetDefault("ns3::MacStatsCalculator::UlOutputFilename",
149 StringValue(CreateTempDirFilename("UlMacStats.txt")));
150 Config::SetDefault("ns3::RadioBearerStatsCalculator::DlRlcOutputFilename",
151 StringValue(CreateTempDirFilename("DlRlcStats.txt")));
152 Config::SetDefault("ns3::RadioBearerStatsCalculator::UlRlcOutputFilename",
153 StringValue(CreateTempDirFilename("UlRlcStats.txt")));
154
155 // Disable Uplink Power Control
156 Config::SetDefault("ns3::LteUePhy::EnableUplinkPowerControl", BooleanValue(false));
157
158 /**
159 * Simulation Topology
160 */
161
162 Ptr<LteHelper> lteHelper = CreateObject<LteHelper>();
163 // lteHelper->EnableLogComponents ();
164 lteHelper->SetAttribute("PathlossModel",
165 StringValue("ns3::ConstantSpectrumPropagationLossModel"));
166 NS_LOG_INFO("SNR = " << m_snrDb << " LOSS = " << m_loss);
167 lteHelper->SetPathlossModelAttribute("Loss", DoubleValue(m_loss));
168
169 // Create Nodes: eNodeB and UE
170 NodeContainer enbNodes;
171 NodeContainer ueNodes;
172 enbNodes.Create(1);
173 ueNodes.Create(1);
174 NodeContainer allNodes = NodeContainer(enbNodes, ueNodes);
175
176 // Install Mobility Model
177 MobilityHelper mobility;
178 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
179 mobility.Install(allNodes);
180
181 // Create Devices and install them in the Nodes (eNB and UE)
182 NetDeviceContainer enbDevs;
183 NetDeviceContainer ueDevs;
184 lteHelper->SetSchedulerType("ns3::RrFfMacScheduler");
185 enbDevs = lteHelper->InstallEnbDevice(enbNodes);
186 ueDevs = lteHelper->InstallUeDevice(ueNodes);
187
188 // Attach a UE to a eNB
189 lteHelper->Attach(ueDevs, enbDevs.Get(0));
190
191 // Activate the default EPS bearer
193 EpsBearer bearer(q);
194 lteHelper->ActivateDataRadioBearer(ueDevs, bearer);
195
196 // Use testing chunk processor in the PHY layer
197 // It will be used to test that the SNR is as intended
198 Ptr<LtePhy> uePhy = ueDevs.Get(0)->GetObject<LteUeNetDevice>()->GetPhy()->GetObject<LtePhy>();
199 Ptr<LteChunkProcessor> testSinr = Create<LteChunkProcessor>();
200 LteSpectrumValueCatcher sinrCatcher;
201 testSinr->AddCallback(MakeCallback(&LteSpectrumValueCatcher::ReportValue, &sinrCatcher));
202 uePhy->GetDownlinkSpectrumPhy()->AddCtrlSinrChunkProcessor(testSinr);
203
204 Config::Connect("/NodeList/0/DeviceList/0/ComponentCarrierMap/*/LteEnbMac/DlScheduling",
206
207 lteHelper->EnableMacTraces();
208 lteHelper->EnableRlcTraces();
209
210 Simulator::Stop(Seconds(0.040));
212
213 double calculatedSinrDb = 10.0 * std::log10(sinrCatcher.GetValue()->operator[](0));
214 NS_TEST_ASSERT_MSG_EQ_TOL(calculatedSinrDb, m_snrDb, 0.0000001, "Wrong SINR !");
216}
217
218void
220{
221 static bool firstTime = true;
222
223 if (firstTime)
224 {
225 firstTime = false;
226 NS_LOG_INFO("SNR\tRef_MCS\tCalc_MCS");
227 }
228
229 /**
230 * Note:
231 * the MCS can only be properly evaluated after:
232 * RRC connection has been completed and
233 * CQI feedback is available at the eNB.
234 */
235 if (Simulator::Now().GetSeconds() > 0.030)
236 {
237 NS_LOG_INFO(m_snrDb << "\t" << m_mcsIndex << "\t" << (uint16_t)dlInfo.mcsTb1);
238
239 NS_TEST_ASSERT_MSG_EQ((uint16_t)dlInfo.mcsTb1, m_mcsIndex, "Wrong MCS index");
240 }
241}
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
Hold variables of type enum.
Definition: enum.h:62
This class contains the specification of EPS Bearers.
Definition: eps-bearer.h:91
Qci
QoS Class Indicator.
Definition: eps-bearer.h:106
@ NGBR_VIDEO_TCP_DEFAULT
Non-GBR TCP-based Video (Buffered Streaming, e.g., www, e-mail...)
Definition: eps-bearer.h:126
@ PiroEW2010
Definition: lte-amc.h:63
The LtePhy models the physical layer of LTE.
Definition: lte-phy.h:51
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:522
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
static void Run()
Run the simulation.
Definition: simulator.cc:178
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:186
Hold variables of type string.
Definition: string.h:56
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
std::string CreateTempDirFilename(std::string filename)
Construct the full path to a file in a temporary directory.
Definition: test.cc:438
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
Hold an unsigned integer type.
Definition: uinteger.h:45
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:859
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:894
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:978
#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
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:765
#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:145
#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:338
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
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:704
DlSchedulingCallbackInfo structure.
Definition: lte-common.h:237