A Discrete-Event Network Simulator
API
lte-test-link-adaptation.cc
Go to the documentation of this file.
1/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Manuel Requena <manuel.requena@cttc.es>
19 */
20
21#include "ns3/simulator.h"
22#include "ns3/log.h"
23#include "ns3/string.h"
24#include "ns3/double.h"
25#include "ns3/boolean.h"
26#include <ns3/enum.h>
27
28#include "ns3/mobility-helper.h"
29#include "ns3/lte-helper.h"
30
31#include "ns3/lte-ue-phy.h"
32#include "ns3/lte-ue-net-device.h"
33
34#include <ns3/lte-chunk-processor.h>
35
37
38
39using namespace ns3;
40
41NS_LOG_COMPONENT_DEFINE ("LteLinkAdaptationTest");
42
47void
50{
51 testcase->DlScheduling (dlInfo);
52}
53
59 : TestSuite ("lte-link-adaptation", SYSTEM)
60{
61 NS_LOG_INFO ("Creating LteLinkAdaptionTestSuite");
62
63 struct SnrEfficiencyMcs
64 {
65 double snrDb;
66 double efficiency;
67 int mcsIndex;
68 };
69
74 SnrEfficiencyMcs snrEfficiencyMcs[] = {
75 { -5.00000, 0.08024, -1},
76 { -4.00000, 0.10030, -1},
77 { -3.00000, 0.12518, -1},
78 { -2.00000, 0.15589, 0},
79 { -1.00000, 0.19365, 0},
80 { 0.00000, 0.23983, 2},
81 { 1.00000, 0.29593, 2},
82 { 2.00000, 0.36360, 2},
83 { 3.00000, 0.44451, 4},
84 { 4.00000, 0.54031, 4},
85 { 5.00000, 0.65251, 6},
86 { 6.00000, 0.78240, 6},
87 { 7.00000, 0.93086, 8},
88 { 8.00000, 1.09835, 8},
89 { 9.00000, 1.28485, 10},
90 { 10.00000, 1.48981, 12},
91 { 11.00000, 1.71229, 12},
92 { 12.00000, 1.95096, 14},
93 { 13.00000, 2.20429, 14},
94 { 14.00000, 2.47062, 16},
95 { 15.00000, 2.74826, 18},
96 { 16.00000, 3.03560, 18},
97 { 17.00000, 3.33115, 20},
98 { 18.00000, 3.63355, 20},
99 { 19.00000, 3.94163, 22},
100 { 20.00000, 4.25439, 22},
101 { 21.00000, 4.57095, 24},
102 { 22.00000, 4.89060, 24},
103 { 23.00000, 5.21276, 26},
104 { 24.00000, 5.53693, 26},
105 { 25.00000, 5.86271, 28},
106 { 26.00000, 6.18980, 28},
107 { 27.00000, 6.51792, 28},
108 { 28.00000, 6.84687, 28},
109 { 29.00000, 7.17649, 28},
110 { 30.00000, 7.50663, 28},
111 };
112 int numOfTests = sizeof (snrEfficiencyMcs) / sizeof (SnrEfficiencyMcs);
113
114 double txPowerDbm = 30; // default eNB TX power over whole bandwidth
115 double ktDbm = -174; // reference LTE noise PSD
116 double noisePowerDbm = ktDbm + 10 * std::log10 (25 * 180000); // corresponds to kT*bandwidth in linear units
117 double receiverNoiseFigureDb = 9.0; // default UE noise figure
118
119 for ( int i = 0 ; i < numOfTests; i++ )
120 {
121 double lossDb = txPowerDbm - snrEfficiencyMcs[i].snrDb - noisePowerDbm - receiverNoiseFigureDb;
122
123 std::ostringstream name;
124 name << " snr= " << snrEfficiencyMcs[i].snrDb << " dB, "
125 << " mcs= " << snrEfficiencyMcs[i].mcsIndex;
126 AddTestCase (new LteLinkAdaptationTestCase (name.str (), snrEfficiencyMcs[i].snrDb, lossDb, snrEfficiencyMcs[i].mcsIndex), TestCase::QUICK);
127 }
128
129}
130
132
133
138LteLinkAdaptationTestCase::LteLinkAdaptationTestCase (std::string name, double snrDb, double loss, uint16_t mcsIndex)
139 : TestCase (name),
140 m_snrDb (snrDb),
141 m_loss (loss),
142 m_mcsIndex (mcsIndex)
143{
144 std::ostringstream sstream1, sstream2;
145 sstream1 << " snr=" << snrDb
146 << " mcs=" << mcsIndex;
147
148 NS_LOG_INFO ("Creating LteLinkAdaptationTestCase: " + sstream1.str ());
149}
150
152{
153}
154
155void
157{
158 Config::Reset ();
159 Config::SetDefault ("ns3::LteAmc::AmcModel", EnumValue (LteAmc::PiroEW2010));
160 Config::SetDefault ("ns3::LteAmc::Ber", DoubleValue (0.00005));
161 Config::SetDefault ("ns3::LteEnbRrc::SrsPeriodicity", UintegerValue (2));
162 Config::SetDefault ("ns3::LteHelper::UseIdealRrc", BooleanValue (true));
163 Config::SetDefault ("ns3::MacStatsCalculator::DlOutputFilename", StringValue (CreateTempDirFilename ("DlMacStats.txt")));
164 Config::SetDefault ("ns3::MacStatsCalculator::UlOutputFilename", StringValue (CreateTempDirFilename ("UlMacStats.txt")));
165 Config::SetDefault ("ns3::RadioBearerStatsCalculator::DlRlcOutputFilename", StringValue (CreateTempDirFilename ("DlRlcStats.txt")));
166 Config::SetDefault ("ns3::RadioBearerStatsCalculator::UlRlcOutputFilename", StringValue (CreateTempDirFilename ("UlRlcStats.txt")));
167
168 //Disable Uplink Power Control
169 Config::SetDefault ("ns3::LteUePhy::EnableUplinkPowerControl", BooleanValue (false));
170
175 Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
176// lteHelper->EnableLogComponents ();
177 lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::ConstantSpectrumPropagationLossModel"));
178 NS_LOG_INFO ("SNR = " << m_snrDb << " LOSS = " << m_loss);
179 lteHelper->SetPathlossModelAttribute ("Loss", DoubleValue (m_loss));
180
181 // Create Nodes: eNodeB and UE
182 NodeContainer enbNodes;
183 NodeContainer ueNodes;
184 enbNodes.Create (1);
185 ueNodes.Create (1);
186 NodeContainer allNodes = NodeContainer ( enbNodes, ueNodes );
187
188 // Install Mobility Model
190 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
191 mobility.Install (allNodes);
192
193 // Create Devices and install them in the Nodes (eNB and UE)
194 NetDeviceContainer enbDevs;
195 NetDeviceContainer ueDevs;
196 lteHelper->SetSchedulerType ("ns3::RrFfMacScheduler");
197 enbDevs = lteHelper->InstallEnbDevice (enbNodes);
198 ueDevs = lteHelper->InstallUeDevice (ueNodes);
199
200 // Attach a UE to a eNB
201 lteHelper->Attach (ueDevs, enbDevs.Get (0));
202
203 // Activate the default EPS bearer
204 enum EpsBearer::Qci q = EpsBearer::NGBR_VIDEO_TCP_DEFAULT;
205 EpsBearer bearer (q);
206 lteHelper->ActivateDataRadioBearer (ueDevs, bearer);
207
208 // Use testing chunk processor in the PHY layer
209 // It will be used to test that the SNR is as intended
210 Ptr<LtePhy> uePhy = ueDevs.Get (0)->GetObject<LteUeNetDevice> ()->GetPhy ()->GetObject<LtePhy> ();
211 Ptr<LteChunkProcessor> testSinr = Create<LteChunkProcessor> ();
212 LteSpectrumValueCatcher sinrCatcher;
213 testSinr->AddCallback (MakeCallback (&LteSpectrumValueCatcher::ReportValue, &sinrCatcher));
214 uePhy->GetDownlinkSpectrumPhy ()->AddCtrlSinrChunkProcessor (testSinr);
215
216 Config::Connect ("/NodeList/0/DeviceList/0/ComponentCarrierMap/*/LteEnbMac/DlScheduling",
218
219 lteHelper->EnableMacTraces ();
220 lteHelper->EnableRlcTraces ();
221
222 Simulator::Stop (Seconds (0.040));
223 Simulator::Run ();
224
225 double calculatedSinrDb = 10.0 * std::log10 (sinrCatcher.GetValue ()->operator[] (0));
226 NS_TEST_ASSERT_MSG_EQ_TOL (calculatedSinrDb, m_snrDb, 0.0000001, "Wrong SINR !");
227 Simulator::Destroy ();
228}
229
230
231void
233{
234 static bool firstTime = true;
235
236 if ( firstTime )
237 {
238 firstTime = false;
239 NS_LOG_INFO ("SNR\tRef_MCS\tCalc_MCS");
240 }
241
248 if (Simulator::Now ().GetSeconds () > 0.030)
249 {
250 NS_LOG_INFO (m_snrDb << "\t" << m_mcsIndex << "\t" << (uint16_t)dlInfo.mcsTb1);
251
252 NS_TEST_ASSERT_MSG_EQ ((uint16_t)dlInfo.mcsTb1, m_mcsIndex, "Wrong MCS index");
253 }
254}
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:41
Hold variables of type enum.
Definition: enum.h:55
This class contains the specification of EPS Bearers.
Definition: eps-bearer.h:92
Qci
QoS Class Indicator.
Definition: eps-bearer.h:107
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Create a set of eNodeB devices.
Definition: lte-helper.cc:474
void SetSchedulerType(std::string type)
Set the type of scheduler to be used by eNodeB devices.
Definition: lte-helper.cc:279
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:959
void SetPathlossModelAttribute(std::string n, const AttributeValue &v)
Set an attribute for the path loss models to be created.
Definition: lte-helper.cc:393
void EnableRlcTraces(void)
Enable trace sinks for RLC layer.
Definition: lte-helper.cc:1435
void ActivateDataRadioBearer(NetDeviceContainer ueDevices, EpsBearer bearer)
Activate a Data Radio Bearer on a given UE devices (for LTE-only simulation).
Definition: lte-helper.cc:1313
NetDeviceContainer InstallUeDevice(NodeContainer c)
Create a set of UE devices.
Definition: lte-helper.cc:489
void EnableMacTraces(void)
Enable trace sinks for MAC layer.
Definition: lte-helper.cc:1529
The LtePhy models the physical layer of LTE.
Definition: lte-phy.h:53
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.
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.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:256
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
Hold variables of type string.
Definition: string.h:41
encapsulates test code
Definition: test.h:994
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
std::string CreateTempDirFilename(std::string filename)
Construct the full path to a file in a temporary directory.
Definition: test.cc:430
A suite of tests to run.
Definition: test.h:1188
Hold an unsigned integer type.
Definition: uinteger.h:44
void Reset(void)
Reset the initial value of every attribute as well as the value of every global to what they were bef...
Definition: config.cc:820
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:849
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:920
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Make Callbacks with one bound argument.
Definition: callback.h:1709
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
#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:141
#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:323
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1244
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Ts... > MakeCallback(R(T::*memPtr)(Ts...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:1648
mobility
Definition: third.py:107
DlSchedulingCallbackInfo structure.
Definition: lte-common.h:240