A Discrete-Event Network Simulator
API
lte-test-tdmt-ff-mac-scheduler.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  * Nicola Baldo <nbaldo@cttc.es>
20  * Dizhi Zhou <dizhi.zhou@gmail.com>
21  */
22 
23 #include <iostream>
24 #include <sstream>
25 #include <string>
26 #include <ns3/object.h>
27 #include <ns3/spectrum-interference.h>
28 #include <ns3/spectrum-error-model.h>
29 #include <ns3/log.h>
30 #include <ns3/test.h>
31 #include <ns3/simulator.h>
32 #include <ns3/packet.h>
33 #include <ns3/ptr.h>
34 #include "ns3/radio-bearer-stats-calculator.h"
35 #include <ns3/constant-position-mobility-model.h>
37 #include <ns3/eps-bearer.h>
38 #include <ns3/node-container.h>
39 #include <ns3/mobility-helper.h>
40 #include <ns3/net-device-container.h>
41 #include <ns3/lte-ue-net-device.h>
42 #include <ns3/lte-enb-net-device.h>
43 #include <ns3/lte-ue-rrc.h>
44 #include <ns3/lte-helper.h>
45 #include "ns3/string.h"
46 #include "ns3/double.h"
47 #include <ns3/lte-enb-phy.h>
48 #include <ns3/lte-ue-phy.h>
49 #include <ns3/boolean.h>
50 #include <ns3/enum.h>
51 
52 using namespace ns3;
53 
54 NS_LOG_COMPONENT_DEFINE ("LenaTestTdMtFfMacScheduler");
55 
57  : TestSuite ("lte-tdmt-ff-mac-scheduler", SYSTEM)
58 {
59  NS_LOG_INFO ("creating LenaTestTdMtFfMacSchedulerSuite");
60 
61  bool errorModel = false;
62 
63  //Test Case : AMC works in TDMT
64 
65  //Note: here the MCS is calculated by the wideband CQI
66 
67  // DOWNLINK - DISTANCE 0 -> MCS 28 -> Itbs 26 (from table 7.1.7.2.1-1 of 36.213)
68  // 1 user -> 24 PRB at Itbs 26 -> 2196 -> 2196000 bytes/sec for one UE; 0 bytes/sec for other UEs
69  // 3 users -> 2196000 among 3 users -> 2196000 bytes/sec for one UE; 0 bytes/sec for other UEs
70  // 6 users -> 2196000 among 6 users -> 2196000 bytes/sec for one UE; 0 bytes/sec for other UEs
71  // 12 users -> 2196000 among 12 users -> 2196000 bytes/sec for one UE; 0 bytes/sec for other UEs
72  // UPLINK- DISTANCE 0 -> MCS 28 -> Itbs 26 (from table 7.1.7.2.1-1 of 36.213)
73  // 1 user -> 25 PRB at Itbs 26 -> 2292 -> 2292000 bytes/sec
74  // 3 users -> 8 PRB at Itbs 26 -> 749 -> 749000 bytes/sec
75  // 6 users -> 4 PRB at Itbs 26 -> 373 -> 373000 bytes/sec
76  // after the patch enforcing min 3 PRBs per UE:
77  // 12 users -> 3 PRB at Itbs 26 -> 277 bytes * 8/12 UE/TTI -> 184670 bytes/sec
78  AddTestCase (new LenaTdMtFfMacSchedulerTestCase (1,0,2196000,2292000, errorModel), TestCase::EXTENSIVE);
79  AddTestCase (new LenaTdMtFfMacSchedulerTestCase (3,0,2196000,749000,errorModel), TestCase::QUICK);
80  AddTestCase (new LenaTdMtFfMacSchedulerTestCase (6,0,2196000,373000, errorModel), TestCase::EXTENSIVE);
81  AddTestCase (new LenaTdMtFfMacSchedulerTestCase (12,0,2196000,184670, errorModel), TestCase::EXTENSIVE);
82 
83  // DOWNLINK - DISTANCE 4800 -> MCS 22 -> Itbs 20 (from table 7.1.7.2.1-1 of 36.213)
84  // 1 user -> 24 PRB at Itbs 20 -> 1383 -> 1383000 bytes/sec for one UE; 0 bytes/sec for other UEs
85  // 3 users -> 1383000 among 3 users -> 1383000 bytes/sec for one UE; 0 bytes/sec for other UEs
86  // 6 users -> 1383000 among 6 users -> 1383000 bytes/sec for one UE; 0 bytes/sec for other UEs
87  // 12 users -> 1383000 among 12 users -> 1383000 bytes/sec for one UE; 0 bytes/sec for other UEs
88  // UPLINK - DISTANCE 4800 -> MCS 14 -> Itbs 13 (from table 7.1.7.2.1-1 of 36.213)
89  // 1 user -> 25 PRB at Itbs 13 -> 807 -> 807000 bytes/sec
90  // 3 users -> 8 PRB at Itbs 13 -> 253 -> 253000 bytes/sec
91  // 6 users -> 4 PRB at Itbs 13 -> 125 -> 125000 bytes/sec
92  // after the patch enforcing min 3 PRBs per UE:
93  // 12 users -> 3 PRB at Itbs 13 -> 93 bytes * 8/12 UE/TTI -> 62000 bytes/sec
94  AddTestCase (new LenaTdMtFfMacSchedulerTestCase (1,4800,1383000,807000,errorModel), TestCase::EXTENSIVE);
95  AddTestCase (new LenaTdMtFfMacSchedulerTestCase (3,4800,1383000,253000,errorModel), TestCase::EXTENSIVE);
96  AddTestCase (new LenaTdMtFfMacSchedulerTestCase (6,4800,1383000,125000,errorModel), TestCase::EXTENSIVE);
97  AddTestCase (new LenaTdMtFfMacSchedulerTestCase (12,4800,1383000,62000,errorModel), TestCase::EXTENSIVE);
98 
99  // DOWNLINK - DISTANCE 6000 -> MCS 20 -> Itbs 18 (from table 7.1.7.2.1-1 of 36.213)
100  // 1 user -> 24 PRB at Itbs 18 -> 1191 -> 1191000 byte/sec for one UE; 0 bytes/sec for other UEs
101  // 3 users -> 1191000 among 3 users -> 1191000 bytes/sec for one UE; 0 bytes/sec for other UEs
102  // 6 users -> 1191000 among 6 users -> 1191000 bytes/sec for one UE; 0 bytes/sec for other UEs
103  // 12 users ->1191000 among 12 users -> 1191000 bytes/sec for one UE; 0 bytes/sec for other UEs
104  // UPLINK - DISTANCE 6000 -> MCS 12 -> Itbs 11 (from table 7.1.7.2.1-1 of 36.213)
105  // 1 user -> 25 PRB at Itbs 11 -> 621 -> 621000 bytes/sec
106  // 3 users -> 8 PRB at Itbs 11 -> 201 -> 201000 bytes/sec
107  // 6 users -> 4 PRB at Itbs 11 -> 97 -> 97000 bytes/sec
108  // after the patch enforcing min 3 PRBs per UE:
109  // 12 users -> 3 PRB at Itbs 11 -> 73 bytes * 8/12 UE/TTI -> 48667 bytes/sec
110  AddTestCase (new LenaTdMtFfMacSchedulerTestCase (1,6000,1191000,621000, errorModel), TestCase::EXTENSIVE);
111  AddTestCase (new LenaTdMtFfMacSchedulerTestCase (3,6000,1191000,201000, errorModel), TestCase::EXTENSIVE);
112  AddTestCase (new LenaTdMtFfMacSchedulerTestCase (6,6000,1191000,97000, errorModel), TestCase::EXTENSIVE);
113  AddTestCase (new LenaTdMtFfMacSchedulerTestCase (12,6000,1191000,48667, errorModel), TestCase::EXTENSIVE);
114 
115  // DOWNLINK - DISTANCE 10000 -> MCS 14 -> Itbs 13 (from table 7.1.7.2.1-1 of 36.213)
116  // 1 user -> 24 PRB at Itbs 13 -> 775 -> 775000 byte/sec for one UE; 0 bytes/sec for other UEs
117  // 3 users -> 775000 among 3 users -> 775000 bytes/sec for one UE; 0 bytes/sec for other UEs
118  // 6 users -> 775000 among 6 users -> 775000 bytes/sec for one UE; 0 bytes/sec for other UEs
119  // 12 users -> 775000 among 12 users -> 775000 bytes/sec for one UE; 0 bytes/sec for other UEs
120  // UPLINK - DISTANCE 10000 -> MCS 8 -> Itbs 8 (from table 7.1.7.2.1-1 of 36.213)
121  // 1 user -> 24 PRB at Itbs 8 -> 437 -> 437000 bytes/sec
122  // 3 users -> 8 PRB at Itbs 8 -> 137 -> 137000 bytes/sec
123  // 6 users -> 4 PRB at Itbs 8 -> 67 -> 67000 bytes/sec
124  // after the patch enforcing min 3 PRBs per UE:
125  // 12 users -> 3 PRB at Itbs 8 -> 49 bytes * 8/12 UE/TTI -> 32667 bytes/sec
126  AddTestCase (new LenaTdMtFfMacSchedulerTestCase (1,10000,775000,437000,errorModel), TestCase::EXTENSIVE);
127  AddTestCase (new LenaTdMtFfMacSchedulerTestCase (3,10000,775000,137000,errorModel), TestCase::EXTENSIVE);
128  AddTestCase (new LenaTdMtFfMacSchedulerTestCase (6,10000,775000,67000,errorModel), TestCase::EXTENSIVE);
129  AddTestCase (new LenaTdMtFfMacSchedulerTestCase (12,10000,775000,32667,errorModel), TestCase::EXTENSIVE);
130 
131  // DONWLINK - DISTANCE 20000 -> MCS 8 -> Itbs 8 (from table 7.1.7.2.1-1 of 36.213)
132  // 1 user -> 24 PRB at Itbs 8 -> 421 -> 421000 bytes/sec for one UE; 0 bytes/sec for other UEs
133  // 3 users -> 421000 among 3 users -> 421000 bytes/sec for one UE; 0 bytes/sec for other UEs
134  // 6 users -> 421000 among 6 users -> 421000 bytes/sec for one UE; 0 bytes/sec for other UEs
135  // 12 users -> 421000 among 12 users -> 421000 bytes/sec for one UE; 0 bytes/sec for other UEs
136  // UPLINK - DISTANCE 20000 -> MCS 2 -> Itbs 2 (from table 7.1.7.2.1-1 of 36.213)
137  // 1 user -> 25 PRB at Itbs 2 -> 233 -> 137000 bytes/sec
138  // 3 users -> 8 PRB at Itbs 2 -> 69 -> 41000 bytes/sec
139  // 6 users -> 4 PRB at Itbs 2 -> 32 -> 22000 bytes/sec
140  // after the patch enforcing min 3 PRBs per UE:
141  // 12 users -> 3 PRB at Itbs 2 -> 26 bytes * 8/12 UE/TTI -> 12000 bytes/sec
142  AddTestCase (new LenaTdMtFfMacSchedulerTestCase (1,20000,421000,137000,errorModel), TestCase::EXTENSIVE);
143  AddTestCase (new LenaTdMtFfMacSchedulerTestCase (3,20000,421000,41000,errorModel), TestCase::EXTENSIVE);
144  AddTestCase (new LenaTdMtFfMacSchedulerTestCase (6,20000,421000,22000,errorModel), TestCase::EXTENSIVE);
145  AddTestCase (new LenaTdMtFfMacSchedulerTestCase (12,20000,421000,12000,errorModel), TestCase::EXTENSIVE);
146 
147  // DOWNLINK - DISTANCE 100000 -> CQI == 0 -> out of range -> 0 bytes/sec
148  // UPLINK - DISTANCE 100000 -> CQI == 0 -> out of range -> 0 bytes/sec
149  AddTestCase (new LenaTdMtFfMacSchedulerTestCase (1,100000,0,0,errorModel), TestCase::QUICK);
150 }
151 
153 
154 
155 // --------------- T E S T - C A S E ------------------------------
156 
157 std::string
159 {
160  std::ostringstream oss;
161  oss << nUser << " UEs, distance " << dist << " m";
162  return oss.str ();
163 }
164 
165 LenaTdMtFfMacSchedulerTestCase::LenaTdMtFfMacSchedulerTestCase (uint16_t nUser, double dist, double thrRefDl, double thrRefUl, bool errorModelEnabled)
166  : TestCase (BuildNameString (nUser, dist)),
167  m_nUser (nUser),
168  m_dist (dist),
169  m_thrRefDl (thrRefDl),
170  m_thrRefUl (thrRefUl),
171  m_errorModelEnabled (errorModelEnabled)
172 {
173 }
174 
176 {
177 }
178 
179 
180 void
182 {
183 
184  NS_LOG_FUNCTION (this << m_nUser << m_dist);
185 
186  if (!m_errorModelEnabled)
187  {
188  Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (false));
189  Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (false));
190  }
191 
192  Config::SetDefault ("ns3::LteHelper::UseIdealRrc", BooleanValue (true));
193 
194  //Disable Uplink Power Control
195  Config::SetDefault ("ns3::LteUePhy::EnableUplinkPowerControl", BooleanValue (false));
196 
201  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
202  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::FriisSpectrumPropagationLossModel"));
203 
204  // Create Nodes: eNodeB and UE
205  NodeContainer enbNodes;
206  NodeContainer ueNodes;
207  enbNodes.Create (1);
208  ueNodes.Create (m_nUser);
209 
210  // Install Mobility Model
212  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
213  mobility.Install (enbNodes);
214  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
215  mobility.Install (ueNodes);
216 
217  // Create Devices and install them in the Nodes (eNB and UE)
218  NetDeviceContainer enbDevs;
219  NetDeviceContainer ueDevs;
220  lteHelper->SetSchedulerType ("ns3::TdMtFfMacScheduler");
221  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
222  ueDevs = lteHelper->InstallUeDevice (ueNodes);
223 
224  // Attach a UE to a eNB
225  lteHelper->Attach (ueDevs, enbDevs.Get (0));
226 
227  // Activate an EPS bearer
228  enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE;
229  EpsBearer bearer (q);
230  lteHelper->ActivateDataRadioBearer (ueDevs, bearer);
231 
232 
233  Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ();
234  Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy ();
235  enbPhy->SetAttribute ("TxPower", DoubleValue (30.0));
236  enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0));
237 
238  // Set UEs' position and power
239  for (int i = 0; i < m_nUser; i++)
240  {
242  mm->SetPosition (Vector (m_dist, 0.0, 0.0));
243  Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (i)->GetObject<LteUeNetDevice> ();
244  Ptr<LteUePhy> uePhy = lteUeDev->GetPhy ();
245  uePhy->SetAttribute ("TxPower", DoubleValue (23.0));
246  uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0));
247  }
248 
249 
250  double statsStartTime = 0.300; // need to allow for RRC connection establishment + SRS
251  double statsDuration = 0.6;
252  double tolerance = 0.1;
253  Simulator::Stop (Seconds (statsStartTime + statsDuration - 0.000001));
254 
255  lteHelper->EnableMacTraces ();
256  lteHelper->EnableRlcTraces ();
257  Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats ();
258  rlcStats->SetAttribute ("StartTime", TimeValue (Seconds (statsStartTime)));
259  rlcStats->SetAttribute ("EpochDuration", TimeValue (Seconds (statsDuration)));
260 
261 
262  Simulator::Run ();
263 
267  NS_LOG_INFO ("DL - Test with " << m_nUser << " user(s) at distance " << m_dist);
268  std::vector <uint64_t> dlDataRxed;
269  for (int i = 0; i < m_nUser; i++)
270  {
271  // get the imsi
272  uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
273  uint8_t lcId = 3;
274  dlDataRxed.push_back (rlcStats->GetDlRxData (imsi, lcId));
275  NS_LOG_INFO ("\tUser " << i << " imsi " << imsi << " bytes rxed " << (double)dlDataRxed.at (i) << " thr " << (double)dlDataRxed.at (i) / statsDuration << " ref " << m_thrRefDl);
276  }
277 
283  uint8_t found = 0;
284  for (int i = 0; i < m_nUser; i++)
285  {
286  double throughput = (double)dlDataRxed.at (i) / statsDuration;
287  if (throughput != 0 && found == 0)
288  {
289  NS_TEST_ASSERT_MSG_EQ_TOL (throughput, m_thrRefDl, m_thrRefDl * tolerance, " Unfair Throughput!");
290  found = 1;
291  }
292  else if (throughput != 0 && found == 1)
293  {
294  NS_TEST_ASSERT_MSG_EQ_TOL (0, m_thrRefDl, m_thrRefDl * tolerance, " Unfair Throughput!");
295  }
296  else
297  NS_TEST_ASSERT_MSG_EQ_TOL (throughput, 0, 0, " Unfair Throughput!");
298  }
299 
303  NS_LOG_INFO ("UL - Test with " << m_nUser << " user(s) at distance " << m_dist);
304  std::vector <uint64_t> ulDataRxed;
305  for (int i = 0; i < m_nUser; i++)
306  {
307  // get the imsi
308  uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
309  // get the lcId
310  uint8_t lcId = 3;
311  ulDataRxed.push_back (rlcStats->GetUlRxData (imsi, lcId));
312  NS_LOG_INFO ("\tUser " << i << " imsi " << imsi << " bytes rxed " << (double)ulDataRxed.at (i) << " thr " << (double)ulDataRxed.at (i) / statsDuration << " ref " << m_thrRefUl);
313  }
320  for (int i = 0; i < m_nUser; i++)
321  {
322  NS_TEST_ASSERT_MSG_EQ_TOL ((double)ulDataRxed.at (i) / statsDuration, m_thrRefUl, m_thrRefUl * tolerance, " Unfair Throughput!");
323  }
324  Simulator::Destroy ();
325 
326 }
327 
bool m_errorModelEnabled
whether the error model is enabled
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
static std::string BuildNameString(uint16_t nUser, double dist)
Builds the test name string based on provided parameter values.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
AttributeValue implementation for Boolean.
Definition: boolean.h:36
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Create a set of eNodeB devices.
Definition: lte-helper.cc:474
Hold variables of type string.
Definition: string.h:41
A suite of tests to run.
Definition: test.h:1342
Mobility model for which the current position does not change once it has been set and until it is se...
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:957
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
void EnableRlcTraces(void)
Enable trace sinks for RLC layer.
Definition: lte-helper.cc:1431
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:278
encapsulates test code
Definition: test.h:1155
void ActivateDataRadioBearer(NetDeviceContainer ueDevices, EpsBearer bearer)
Activate a Data Radio Bearer on a given UE devices (for LTE-only simulation).
Definition: lte-helper.cc:1310
void SetSchedulerType(std::string type)
Set the type of scheduler to be used by eNodeB devices.
Definition: lte-helper.cc:279
mobility
Definition: third.py:101
This class contains the specification of EPS Bearers.
Definition: eps-bearer.h:71
double m_dist
the distance between nodes
AttributeValue implementation for Time.
Definition: nstime.h:1076
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
uint64_t GetDlRxData(uint64_t imsi, uint8_t lcid)
Gets the number of received downlink data bytes.
holds a vector of ns3::NetDevice pointers
Ptr< LteEnbPhy > GetPhy(void) const
#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:380
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
double m_thrRefUl
the UL throughput reference
Ptr< LteUePhy > GetPhy(void) const
Get the Phy.
void SetPosition(const Vector &position)
static LenaTestTdMtFfMacSchedulerSuite lenaTestTdMtFfMacSchedulerSuite
Ptr< RadioBearerStatsCalculator > GetRlcStats(void)
Definition: lte-helper.cc:1568
NetDeviceContainer InstallUeDevice(NodeContainer c)
Create a set of UE devices.
Definition: lte-helper.cc:489
Helper class used to assign positions and mobility models to nodes.
uint64_t GetUlRxData(uint64_t imsi, uint8_t lcid)
Gets the number of received uplink data bytes.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:782
This system test program creates different test cases with a single eNB and several UEs...
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
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:1525
virtual void DoRun(void)
Implementation to actually run this TestCase.
LenaTdMtFfMacSchedulerTestCase(uint16_t nUser, double dist, double thrRefDl, double thrRefUl, bool errorModelEnabled)
Constructor.
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
Test suite for TdMtFfMacScheduler tests.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:185
The eNodeB device implementation.
Qci
QoS Class Indicator.
Definition: eps-bearer.h:77
double m_thrRefDl
the DL throughput reference
The LteUeNetDevice class implements the UE net device.