A Discrete-Event Network Simulator
API
lte-test-harq.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: Marco Miozzo <marco.miozzo@cttc.es>
19  */
20 
21 #include <ns3/object.h>
22 #include <ns3/spectrum-interference.h>
23 #include <ns3/spectrum-error-model.h>
24 #include <ns3/log.h>
25 #include <ns3/test.h>
26 #include <ns3/simulator.h>
27 #include <ns3/packet.h>
28 #include <ns3/ptr.h>
29 #include <iostream>
30 #include <cmath>
31 #include <ns3/radio-bearer-stats-calculator.h>
32 #include <ns3/mobility-building-info.h>
33 #include <ns3/hybrid-buildings-propagation-loss-model.h>
34 #include <ns3/eps-bearer.h>
35 #include <ns3/node-container.h>
36 #include <ns3/mobility-helper.h>
37 #include <ns3/net-device-container.h>
38 #include <ns3/lte-ue-net-device.h>
39 #include <ns3/lte-enb-net-device.h>
40 #include <ns3/lte-ue-rrc.h>
41 #include <ns3/lte-helper.h>
42 #include <ns3/string.h>
43 #include <ns3/double.h>
44 #include <ns3/lte-enb-phy.h>
45 #include <ns3/lte-ue-phy.h>
46 #include <ns3/config.h>
47 #include <ns3/boolean.h>
48 #include <ns3/enum.h>
49 #include <ns3/unused.h>
50 #include <ns3/ff-mac-scheduler.h>
51 #include <ns3/buildings-helper.h>
52 
53 #include "lte-test-harq.h"
54 
55 using namespace ns3;
56 
57 NS_LOG_COMPONENT_DEFINE ("LenaTestHarq");
58 
60  : TestSuite ("lte-harq", SYSTEM)
61 {
62  NS_LOG_INFO ("creating LenaTestHarqTestCase");
63 
64 
65  // Tests on DL/UL Data channels (PDSCH, PUSCH)
66  // MCS 0 TB size of 66 bytes SINR -9.91 dB expected throughput 31822 bytes/s
67  // TBLER 1st tx 1.0
68  // TBLER 2nd tx 0.074
69  AddTestCase (new LenaHarqTestCase (2, 2400, 66, 0.12, 31822), TestCase::QUICK);
70 
71  // Tests on DL/UL Data channels (PDSCH, PUSCH)
72  // MCS 10 TB size of 472 bytes SINR 0.3 dB expected throughput 209964 bytes/s
73  // TBLER 1st tx 1.0
74  // TBLER 2nd tx 0.248
75  AddTestCase (new LenaHarqTestCase (1, 770, 472, 0.06, 209964), TestCase::QUICK);
76 
77 
78 
79 }
80 
82 
83 std::string
84 LenaHarqTestCase::BuildNameString (uint16_t nUser, uint16_t dist, uint16_t tbSize)
85 {
86  std::ostringstream oss;
87  oss << nUser << " UEs, distance " << dist << " m, TB size " << tbSize;
88  return oss.str ();
89 }
90 
91 LenaHarqTestCase::LenaHarqTestCase (uint16_t nUser, uint16_t dist, uint16_t tbSize, double amcBer, double thrRef)
92  : TestCase (BuildNameString (nUser, dist, tbSize)),
93  m_nUser (nUser),
94  m_dist (dist),
95  m_amcBer (amcBer),
96  m_throughputRef (thrRef)
97 {
98 }
99 
101 {
102 }
103 
104 void
106 {
107 
108  Config::SetDefault ("ns3::LteAmc::Ber", DoubleValue (m_amcBer));
109  Config::SetDefault ("ns3::LteAmc::AmcModel", EnumValue (LteAmc::PiroEW2010));
110  Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (false));
111  Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (true));
112  Config::SetDefault ("ns3::LteHelper::UseIdealRrc", BooleanValue (true));
113  Config::SetDefault ("ns3::MacStatsCalculator::DlOutputFilename", StringValue (CreateTempDirFilename ("DlMacStats.txt")));
114  Config::SetDefault ("ns3::MacStatsCalculator::UlOutputFilename", StringValue (CreateTempDirFilename ("UlMacStats.txt")));
115  Config::SetDefault ("ns3::RadioBearerStatsCalculator::DlRlcOutputFilename", StringValue (CreateTempDirFilename ("DlRlcStats.txt")));
116  Config::SetDefault ("ns3::RadioBearerStatsCalculator::UlRlcOutputFilename", StringValue (CreateTempDirFilename ("UlRlcStats.txt")));
117 
118 
119  //Disable Uplink Power Control
120  Config::SetDefault ("ns3::LteUePhy::EnableUplinkPowerControl", BooleanValue (false));
121 
122 // Config::SetDefault ("ns3::RrFfMacScheduler::HarqEnabled", BooleanValue (false));
123 // LogComponentEnable ("LteEnbRrc", LOG_LEVEL_ALL);
124 // LogComponentEnable ("LteUeRrc", LOG_LEVEL_ALL);
125 // LogComponentEnable ("LteEnbMac", LOG_LEVEL_ALL);
126 // LogComponentEnable ("LteUeMac", LOG_LEVEL_ALL);
127 // LogComponentEnable ("LteRlc", LOG_LEVEL_ALL);
128 //
129 // LogComponentEnable ("LtePhy", LOG_LEVEL_ALL);
130 // LogComponentEnable ("LteEnbPhy", LOG_LEVEL_ALL);
131 // LogComponentEnable ("LteUePhy", LOG_LEVEL_ALL);
132 
133 // LogComponentEnable ("LteSpectrumPhy", LOG_LEVEL_ALL);
134 // LogComponentEnable ("LteInterference", LOG_LEVEL_ALL);
135 // LogComponentEnable ("LteChunkProcessor", LOG_LEVEL_ALL);
136 //
137 // LogComponentEnable ("LtePropagationLossModel", LOG_LEVEL_ALL);
138 // LogComponentEnable ("LossModel", LOG_LEVEL_ALL);
139 // LogComponentEnable ("ShadowingLossModel", LOG_LEVEL_ALL);
140 // LogComponentEnable ("PenetrationLossModel", LOG_LEVEL_ALL);
141 // LogComponentEnable ("MultipathLossModel", LOG_LEVEL_ALL);
142 // LogComponentEnable ("PathLossModel", LOG_LEVEL_ALL);
143 //
144 // LogComponentEnable ("LteNetDevice", LOG_LEVEL_ALL);
145 // LogComponentEnable ("LteUeNetDevice", LOG_LEVEL_ALL);
146 // LogComponentEnable ("LteEnbNetDevice", LOG_LEVEL_ALL);
147 
148 // LogComponentEnable ("RrFfMacScheduler", LOG_LEVEL_ALL);
149 // LogComponentEnable ("LenaHelper", LOG_LEVEL_ALL);
150 // LogComponentEnable ("RlcStatsCalculator", LOG_LEVEL_ALL);
151 
152 
153 // LogComponentEnable ("LteSpectrumPhy", LOG_LEVEL_ALL);
154 // LogComponentEnable ("LteEnbMac", LOG_LEVEL_ALL);
155 // LogComponentEnable ("LteEnbPhy", LOG_LEVEL_ALL);
156 // LogComponentEnable ("LteUePhy", LOG_LEVEL_ALL);
157 // LogComponentEnable ("RrFfMacScheduler", LOG_LEVEL_ALL);
158 // LogComponentEnable ("LenaHelper", LOG_LEVEL_ALL);
159 // LogComponentEnable ("BuildingsPropagationLossModel", LOG_LEVEL_ALL);
160 // LogComponentEnable ("LteMiErrorModel", LOG_LEVEL_ALL);
161 // LogComponentEnable ("LteAmc", LOG_LEVEL_ALL);
162 //
163 // LogComponentDisableAll (LOG_LEVEL_ALL);
164 
165 // LogComponentEnable ("LenaTestHarq", LOG_LEVEL_ALL);
166 
167 
172  Ptr<LteHelper> lena = CreateObject<LteHelper> ();
173 
174  // Create Nodes: eNodeB and UE
175  NodeContainer enbNodes;
176  NodeContainer ueNodes;
177  enbNodes.Create (1);
178  ueNodes.Create (m_nUser);
179 
180  // Install Mobility Model
182  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
183  mobility.Install (enbNodes);
184  BuildingsHelper::Install (enbNodes);
185 
186  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
187  mobility.Install (ueNodes);
188  BuildingsHelper::Install (ueNodes);
189 
190  // remove random shadowing component
191  lena->SetAttribute ("PathlossModel", StringValue ("ns3::HybridBuildingsPropagationLossModel"));
192  lena->SetPathlossModelAttribute ("ShadowSigmaOutdoor", DoubleValue (0.0));
193  lena->SetPathlossModelAttribute ("ShadowSigmaIndoor", DoubleValue (0.0));
194  lena->SetPathlossModelAttribute ("ShadowSigmaExtWalls", DoubleValue (0.0));
195 
196  // Create Devices and install them in the Nodes (eNB and UE)
197  NetDeviceContainer enbDevs;
198  NetDeviceContainer ueDevs;
199  lena->SetSchedulerType ("ns3::RrFfMacScheduler");
200  lena->SetSchedulerAttribute ("UlCqiFilter", EnumValue (FfMacScheduler::PUSCH_UL_CQI));
201 
202  enbDevs = lena->InstallEnbDevice (enbNodes);
203  ueDevs = lena->InstallUeDevice (ueNodes);
204 
205  // Attach a UE to a eNB
206  lena->Attach (ueDevs, enbDevs.Get (0));
207 
208  // Activate an EPS bearer
209  enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE;
210  EpsBearer bearer (q);
211  lena->ActivateDataRadioBearer (ueDevs, bearer);
212 
213 
214  Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ();
215  Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy ();
216  enbPhy->SetAttribute ("TxPower", DoubleValue (43.0));
217  enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0));
218  // place the HeNB over the default rooftop level (20 mt.)
219  Ptr<MobilityModel> mm = enbNodes.Get (0)->GetObject<MobilityModel> ();
220  mm->SetPosition (Vector (0.0, 0.0, 30.0));
221 
222  // Set UEs' position and power
223  for (int i = 0; i < m_nUser; i++)
224  {
225  Ptr<MobilityModel> mm = ueNodes.Get (i)->GetObject<MobilityModel> ();
226  mm->SetPosition (Vector (m_dist, 0.0, 1.0));
227  Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (i)->GetObject<LteUeNetDevice> ();
228  Ptr<LteUePhy> uePhy = lteUeDev->GetPhy ();
229  uePhy->SetAttribute ("TxPower", DoubleValue (23.0));
230  uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0));
231  }
232 
233 
234  double statsStartTime = 0.050; // need to allow for RRC connection establishment + SRS
235  double statsDuration = 2.0;
236  Simulator::Stop (Seconds (statsStartTime + statsDuration - 0.0001));
237 
238  lena->EnableRlcTraces ();
239  Ptr<RadioBearerStatsCalculator> rlcStats = lena->GetRlcStats ();
240  rlcStats->SetAttribute ("StartTime", TimeValue (Seconds (statsStartTime)));
241  rlcStats->SetAttribute ("EpochDuration", TimeValue (Seconds (statsDuration)));
242 
243  // for debugging purposes
244  lena->EnableMacTraces ();
245 
246  Simulator::Run ();
247 
251  NS_LOG_INFO ("\tTest on downlink data shared channels (PDSCH)");
252  NS_LOG_INFO ("Test with " << m_nUser << " user(s) at distance " << m_dist << " expected Thr " << m_throughputRef);
253  for (int i = 0; i < m_nUser; i++)
254  {
255  // get the imsi
256  uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
257  uint8_t lcId = 3;
258  double txed = rlcStats->GetDlTxData (imsi, lcId);
259  double rxed = rlcStats->GetDlRxData (imsi, lcId);
260  double tolerance = 0.1;
261 
262  NS_LOG_INFO (" User " << i << " imsi " << imsi << " bytes rxed/t " << rxed/statsDuration << " txed/t " << txed/statsDuration << " thr Ref " << m_throughputRef << " Err " << (std::abs (txed/statsDuration - m_throughputRef)) / m_throughputRef);
263 
264  NS_TEST_ASSERT_MSG_EQ_TOL (txed/statsDuration, m_throughputRef, m_throughputRef * tolerance, " Unexpected Throughput!");
265  NS_TEST_ASSERT_MSG_EQ_TOL (rxed/statsDuration, m_throughputRef, m_throughputRef * tolerance, " Unexpected Throughput!");
266  }
267 
268 
269  Simulator::Destroy ();
270 }
This system test program creates different test cases with a single eNB and several UEs,...
Definition: lte-test-harq.h:42
double m_throughputRef
throughput reference
Definition: lte-test-harq.h:70
uint16_t m_dist
distance between nodes
Definition: lte-test-harq.h:68
uint16_t m_nUser
number of UE nodes
Definition: lte-test-harq.h:67
static std::string BuildNameString(uint16_t nUser, uint16_t dist, uint16_t tbSize)
Build name string function.
virtual void DoRun(void)
Implementation to actually run this TestCase.
LenaHarqTestCase(uint16_t nUser, uint16_t dist, uint16_t tbSize, double amcBer, double thrRef)
Constructor.
double m_amcBer
AMC bit error rate.
Definition: lte-test-harq.h:69
virtual ~LenaHarqTestCase()
Test suite for harq test.
Definition: lte-test-harq.h:85
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
The eNodeB device implementation.
Ptr< LteEnbPhy > GetPhy(void) const
void SetSchedulerAttribute(std::string n, const AttributeValue &v)
Set an attribute for the scheduler to be created.
Definition: lte-helper.cc:293
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Create a set of eNodeB devices.
Definition: lte-helper.cc:474
Ptr< RadioBearerStatsCalculator > GetRlcStats(void)
Definition: lte-helper.cc:1573
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:961
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:1436
void ActivateDataRadioBearer(NetDeviceContainer ueDevices, EpsBearer bearer)
Activate a Data Radio Bearer on a given UE devices (for LTE-only simulation).
Definition: lte-helper.cc:1314
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:1530
The LteUeNetDevice class implements the UE net device.
Helper class used to assign positions and mobility models to nodes.
Keep track of the current position and velocity of an object.
void SetPosition(const Vector &position)
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< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:185
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:1154
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:1344
AttributeValue implementation for Time.
Definition: nstime.h:1353
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:849
#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
#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:378
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
static LenaTestHarqSuite lenaTestHarqSuite
Every class exported by the ns3 library is enclosed in the ns3 namespace.
mobility
Definition: third.py:108