A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
35 
37 
38 NS_LOG_COMPONENT_DEFINE ("LteLinkAdaptationTest");
39 
40 using namespace ns3;
41 
42 
47 void
49  uint32_t frameNo, uint32_t subframeNo, uint16_t rnti,
50  uint8_t mcsTb1, uint16_t sizeTb1, uint8_t mcsTb2, uint16_t sizeTb2)
51 {
52  testcase->DlScheduling (frameNo, subframeNo, rnti, mcsTb1, sizeTb1, mcsTb2, sizeTb2);
53 }
54 
60  : TestSuite ("lte-link-adaptation", SYSTEM)
61 {
62  NS_LOG_INFO ("Creating LteLinkAdaptionTestSuite");
63 
64  struct SnrEfficiencyMcs
65  {
66  double snrDb;
67  double efficiency;
68  int mcsIndex;
69  };
70 
75  SnrEfficiencyMcs snrEfficiencyMcs[] = {
76  { -5.00000, 0.08024, -1},
77  { -4.00000, 0.10030, -1},
78  { -3.00000, 0.12518, -1},
79  { -2.00000, 0.15589, 0},
80  { -1.00000, 0.19365, 0},
81  { 0.00000, 0.23983, 2},
82  { 1.00000, 0.29593, 2},
83  { 2.00000, 0.36360, 2},
84  { 3.00000, 0.44451, 4},
85  { 4.00000, 0.54031, 4},
86  { 5.00000, 0.65251, 6},
87  { 6.00000, 0.78240, 6},
88  { 7.00000, 0.93086, 8},
89  { 8.00000, 1.09835, 8},
90  { 9.00000, 1.28485, 10},
91  { 10.00000, 1.48981, 12},
92  { 11.00000, 1.71229, 12},
93  { 12.00000, 1.95096, 14},
94  { 13.00000, 2.20429, 14},
95  { 14.00000, 2.47062, 16},
96  { 15.00000, 2.74826, 18},
97  { 16.00000, 3.03560, 18},
98  { 17.00000, 3.33115, 20},
99  { 18.00000, 3.63355, 20},
100  { 19.00000, 3.94163, 22},
101  { 20.00000, 4.25439, 22},
102  { 21.00000, 4.57095, 24},
103  { 22.00000, 4.89060, 24},
104  { 23.00000, 5.21276, 26},
105  { 24.00000, 5.53693, 26},
106  { 25.00000, 5.86271, 28},
107  { 26.00000, 6.18980, 28},
108  { 27.00000, 6.51792, 28},
109  { 28.00000, 6.84687, 28},
110  { 29.00000, 7.17649, 28},
111  { 30.00000, 7.50663, 28},
112  };
113  int numOfTests = sizeof (snrEfficiencyMcs) / sizeof (SnrEfficiencyMcs);
114 
115  double txPowerDbm = 30; // default eNB TX power over whole bandwidth
116  double ktDbm = -174; // reference LTE noise PSD
117  double noisePowerDbm = ktDbm + 10 * std::log10 (25 * 180000); // corresponds to kT*bandwidth in linear units
118  double receiverNoiseFigureDb = 9.0; // default UE noise figure
119 
120  for ( int i = 0 ; i < numOfTests; i++ )
121  {
122  double lossDb = txPowerDbm - snrEfficiencyMcs[i].snrDb - noisePowerDbm - receiverNoiseFigureDb;
123 
124  std::ostringstream name;
125  name << " snr= " << snrEfficiencyMcs[i].snrDb << " dB, "
126  << " mcs= " << snrEfficiencyMcs[i].mcsIndex;
127  AddTestCase (new LteLinkAdaptationTestCase (name.str (), snrEfficiencyMcs[i].snrDb, lossDb, snrEfficiencyMcs[i].mcsIndex), TestCase::QUICK);
128  }
129 
130 }
131 
133 
134 
139 LteLinkAdaptationTestCase::LteLinkAdaptationTestCase (std::string name, double snrDb, double loss, uint16_t mcsIndex)
140  : TestCase (name),
141  m_snrDb (snrDb),
142  m_loss (loss),
143  m_mcsIndex (mcsIndex)
144 {
145  std::ostringstream sstream1, sstream2;
146  sstream1 << " snr=" << snrDb
147  << " mcs=" << mcsIndex;
148 
149  NS_LOG_INFO ("Creating LteLinkAdaptationTestCase: " + sstream1.str ());
150 }
151 
153 {
154 }
155 
156 void
158 {
159  Config::Reset ();
160  Config::SetDefault ("ns3::LteAmc::AmcModel", EnumValue (LteAmc::PiroEW2010));
161  Config::SetDefault ("ns3::LteAmc::Ber", DoubleValue (0.00005));
162  Config::SetDefault ("ns3::LteEnbRrc::SrsPeriodicity", UintegerValue (2));
163  Config::SetDefault ("ns3::LteHelper::UseIdealRrc", BooleanValue (true));
164 
169  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
170 // lteHelper->EnableLogComponents ();
171  lteHelper->EnableMacTraces ();
172  lteHelper->EnableRlcTraces ();
173  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::ConstantSpectrumPropagationLossModel"));
174  NS_LOG_INFO ("SNR = " << m_snrDb << " LOSS = " << m_loss);
175  lteHelper->SetPathlossModelAttribute ("Loss", DoubleValue (m_loss));
176 
177  // Create Nodes: eNodeB and UE
178  NodeContainer enbNodes;
179  NodeContainer ueNodes;
180  enbNodes.Create (1);
181  ueNodes.Create (1);
182  NodeContainer allNodes = NodeContainer ( enbNodes, ueNodes );
183 
184  // Install Mobility Model
185  MobilityHelper mobility;
186  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
187  mobility.Install (allNodes);
188 
189  // Create Devices and install them in the Nodes (eNB and UE)
190  NetDeviceContainer enbDevs;
191  NetDeviceContainer ueDevs;
192  lteHelper->SetSchedulerType ("ns3::RrFfMacScheduler");
193  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
194  ueDevs = lteHelper->InstallUeDevice (ueNodes);
195 
196  // Attach a UE to a eNB
197  lteHelper->Attach (ueDevs, enbDevs.Get (0));
198 
199  // Activate the default EPS bearer
200  enum EpsBearer::Qci q = EpsBearer::NGBR_VIDEO_TCP_DEFAULT;
201  EpsBearer bearer (q);
202  lteHelper->ActivateDataRadioBearer (ueDevs, bearer);
203 
204  // Use testing chunk processor in the PHY layer
205  // It will be used to test that the SNR is as intended
206  Ptr<LtePhy> uePhy = ueDevs.Get (0)->GetObject<LteUeNetDevice> ()->GetPhy ()->GetObject<LtePhy> ();
207  Ptr<LteTestSinrChunkProcessor> testSinr = Create<LteTestSinrChunkProcessor> (uePhy);
208  uePhy->GetDownlinkSpectrumPhy ()->AddCtrlSinrChunkProcessor (testSinr);
209 
210  Config::Connect ("/NodeList/0/DeviceList/0/LteEnbMac/DlScheduling",
212 
213  Simulator::Stop (Seconds (0.040));
214  Simulator::Run ();
215 
216  double calculatedSinrDb = 10.0 * std::log10 (testSinr->GetSinr ()->operator[] (0));
217  NS_TEST_ASSERT_MSG_EQ_TOL (calculatedSinrDb, m_snrDb, 0.0000001, "Wrong SINR !");
218  Simulator::Destroy ();
219 }
220 
221 
222 void
223 LteLinkAdaptationTestCase::DlScheduling (uint32_t frameNo, uint32_t subframeNo, uint16_t rnti,
224  uint8_t mcsTb1, uint16_t sizeTb1, uint8_t mcsTb2, uint16_t sizeTb2)
225 {
226  static bool firstTime = true;
227 
228  if ( firstTime )
229  {
230  firstTime = false;
231  NS_LOG_INFO ("SNR\tRef_MCS\tCalc_MCS");
232  }
233 
240  if (Simulator::Now ().GetSeconds () > 0.030)
241  {
242  NS_LOG_INFO (m_snrDb << "\t" << m_mcsIndex << "\t" << (uint16_t)mcsTb1);
243 
244  NS_TEST_ASSERT_MSG_EQ ((uint16_t)mcsTb1, m_mcsIndex, "Wrong MCS index");
245  }
246 }
void SetPathlossModelAttribute(std::string n, const AttributeValue &v)
set an attribute for the pathloss model to be created
Definition: lte-helper.cc:263
Hold a bool native type.
Definition: boolean.h:38
NetDeviceContainer InstallEnbDevice(NodeContainer c)
create a set of eNB devices
Definition: lte-helper.cc:346
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:642
hold variables of type string
Definition: string.h:18
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
A suite of tests to run.
Definition: test.h:1105
Callback< R > MakeBoundCallback(R(*fnPtr)(TX), ARG a1)
Build bound Callbacks which take varying numbers of arguments, and potentially returning a value...
Definition: callback.h:1467
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:646
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
void EnableRlcTraces(void)
Enable trace sinks for RLC layer.
Definition: lte-helper.cc:956
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:223
encapsulates test code
Definition: test.h:929
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:728
void ActivateDataRadioBearer(NetDeviceContainer ueDevices, EpsBearer bearer)
Call ActivateDataRadioBearer (ueDevice, bearer) for each UE device in a given set.
Definition: lte-helper.cc:900
void SetSchedulerType(std::string type)
Definition: lte-helper.cc:210
This class contains the specification of EPS Bearers.
Definition: eps-bearer.h:71
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
hold variables of type 'enum'
Definition: enum.h:37
Hold an unsigned integer type.
Definition: uinteger.h:46
#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:148
holds a vector of ns3::NetDevice pointers
Ptr< LteSpectrumPhy > GetDownlinkSpectrumPhy()
Definition: lte-phy.cc:104
#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:355
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:667
keep track of a set of node pointers.
void SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition: test.cc:184
NetDeviceContainer InstallUeDevice(NodeContainer c)
create a set of UE devices
Definition: lte-helper.cc:361
Helper class used to assign positions and mobility models to nodes.
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void EnableMacTraces(void)
Enable trace sinks for MAC layer.
Definition: lte-helper.cc:1044
Hold a floating point type.
Definition: double.h:41
void SetAttribute(std::string name, const AttributeValue &value)
Definition: object-base.cc:176
Ptr< T > GetObject(void) const
Definition: object.h:362
Qci
QoS Class Indicator.
Definition: eps-bearer.h:77
The LtePhy models the physical layer of LTE.
Definition: lte-phy.h:52
The LteUeNetDevice class implements the UE net device.