A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
lte-test-tta-ff-mac-scheduler.cc
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 
27 #include <ns3/object.h>
28 #include <ns3/spectrum-interference.h>
29 #include <ns3/spectrum-error-model.h>
30 #include <ns3/log.h>
31 #include <ns3/test.h>
32 #include <ns3/simulator.h>
33 #include <ns3/packet.h>
34 #include <ns3/ptr.h>
35 #include "ns3/radio-bearer-stats-calculator.h"
36 #include <ns3/constant-position-mobility-model.h>
37 #include "lte-test-tta-ff-mac-scheduler.h"
38 #include <ns3/eps-bearer.h>
39 #include <ns3/node-container.h>
40 #include <ns3/mobility-helper.h>
41 #include <ns3/net-device-container.h>
42 #include <ns3/lte-ue-net-device.h>
43 #include <ns3/lte-enb-net-device.h>
44 #include <ns3/lte-ue-rrc.h>
45 #include <ns3/lte-helper.h>
46 #include "ns3/string.h"
47 #include "ns3/double.h"
48 #include <ns3/lte-enb-phy.h>
49 #include <ns3/lte-ue-phy.h>
50 #include <ns3/boolean.h>
51 #include <ns3/enum.h>
52 
53 
54 #include "lte-test-tta-ff-mac-scheduler.h"
55 
56 NS_LOG_COMPONENT_DEFINE ("LenaTestTtaFfMacScheduler");
57 
58 using namespace ns3;
59 
60 LenaTestTtaFfMacSchedulerSuite::LenaTestTtaFfMacSchedulerSuite ()
61  : TestSuite ("lte-tta-ff-mac-scheduler", SYSTEM)
62 {
63  NS_LOG_INFO ("creating LenaTestTtaFfMacSchedulerSuite");
64 
65  bool errorModel = false;
66 
67  //Test Case : AMC works in TTA
68 
69 
70  //Note: here the MCS is calculated by the narrowband CQI
71 
72  // DOWNLINK - DISTANCE 0 -> MCS 28 -> Itbs 26 (from table 7.1.7.2.1-1 of 36.213)
73  // 1 user -> 24 PRB at Itbs 26 -> 2196 -> 2196000 bytes/sec for one UE; 0 bytes/sec for other UEs
74  // 3 users -> 2196000 among 3 users -> 2196000 bytes/sec for one UE; 0 bytes/sec for other UEs
75  // 6 users -> 2196000 among 6 users -> 2196000 bytes/sec for one UE; 0 bytes/sec for other UEs
76  // 12 users -> 2196000 among 12 users -> 2196000 bytes/sec for one UE; 0 bytes/sec for other UEs
77  // UPLINK- DISTANCE 0 -> MCS 28 -> Itbs 26 (from table 7.1.7.2.1-1 of 36.213)
78  // 1 user -> 25 PRB at Itbs 26 -> 2292 -> 2292000 bytes/sec
79  // 3 users -> 8 PRB at Itbs 26 -> 749 -> 749000 bytes/sec
80  // 6 users -> 4 PRB at Itbs 26 -> 373 -> 373000 bytes/sec
81  // after the patch enforcing min 3 PRBs per UE:
82  // 12 users -> 3 PRB at Itbs 26 -> 277 bytes * 8/12 UE/TTI -> 184670 bytes/sec
83  AddTestCase (new LenaTtaFfMacSchedulerTestCase (1,0,0,2196000,2292000, errorModel), TestCase::EXTENSIVE);
84  AddTestCase (new LenaTtaFfMacSchedulerTestCase (3,0,0,2196000,749000,errorModel), TestCase::QUICK);
85  AddTestCase (new LenaTtaFfMacSchedulerTestCase (6,0,0,2196000,373000, errorModel), TestCase::EXTENSIVE);
86  AddTestCase (new LenaTtaFfMacSchedulerTestCase (12,0,0,2196000,184670, errorModel), TestCase::EXTENSIVE);
87  AddTestCase (new LenaTtaFfMacSchedulerTestCase (15,0,0,2196000,147730, errorModel), TestCase::EXTENSIVE);
88 
89  // DOWNLINK - DISTANCE 4800 -> MCS 16 -> Itbs 15 (from table 7.1.7.2.1-1 of 36.213)
90  // 1 user -> 24 PRB at Itbs 15 -> 903 -> 903000 bytes/sec for one UE; 0 bytes/sec for other UEs
91  // 3 users -> 903000 among 3 users -> 903000 bytes/sec for one UE; 0 bytes/sec for other UEs
92  // 6 users -> 903000 among 6 users -> 903000 bytes/sec for one UE; 0 bytes/sec for other UEs
93  // 12 users -> 903000 among 12 users -> 903000 bytes/sec for one UE; 0 bytes/sec for other UEs
94  // UPLINK - DISTANCE 4800 -> MCS 14 -> Itbs 13 (from table 7.1.7.2.1-1 of 36.213)
95  // 1 user -> 25 PRB at Itbs 13 -> 807 -> 807000 bytes/sec
96  // 3 users -> 8 PRB at Itbs 13 -> 253 -> 253000 bytes/sec
97  // 6 users -> 4 PRB at Itbs 13 -> 125 -> 125000 bytes/sec
98  // after the patch enforcing min 3 PRBs per UE:
99  // 12 users -> 3 PRB at Itbs 13 -> 93 bytes * 8/12 UE/TTI -> 62000 bytes/sec
100  AddTestCase (new LenaTtaFfMacSchedulerTestCase (1,0,4800,903000,807000,errorModel), TestCase::EXTENSIVE);
101  AddTestCase (new LenaTtaFfMacSchedulerTestCase (3,0,4800,903000,253000,errorModel), TestCase::EXTENSIVE);
102  AddTestCase (new LenaTtaFfMacSchedulerTestCase (6,0,4800,903000,125000,errorModel), TestCase::EXTENSIVE);
103  AddTestCase (new LenaTtaFfMacSchedulerTestCase (12,0,4800,903000,62000,errorModel), TestCase::EXTENSIVE);
104 
105 
106  // DOWNLINK - DISTANCE 6000 -> MCS 16 -> Itbs 15 (from table 7.1.7.2.1-1 of 36.213)
107  // 1 user -> 24 PRB at Itbs 15 -> 775 -> 775000 bytes/sec for one UE; 0 bytes/sec for other UEs
108  // 3 users -> 775000 among 3 users -> 775000 bytes/sec for one UE; 0 bytes/sec for other UEs
109  // 6 users -> 775000 among 6 users -> 775000 bytes/sec for one UE; 0 bytes/sec for other UEs
110  // 12 users ->7753000 among 12 users -> 775000 bytes/sec for one UE; 0 bytes/sec for other UEs
111  // UPLINK - DISTANCE 6000 -> MCS 12 -> Itbs 11 (from table 7.1.7.2.1-1 of 36.213)
112  // 1 user -> 25 PRB at Itbs 11 -> 621 -> 621000 bytes/sec
113  // 3 users -> 8 PRB at Itbs 11 -> 201 -> 201000 bytes/sec
114  // 6 users -> 4 PRB at Itbs 11 -> 97 -> 97000 bytes/sec
115  // after the patch enforcing min 3 PRBs per UE:
116  // 12 users -> 3 PRB at Itbs 11 -> 73 bytes * 8/12 UE/TTI -> 48667 bytes/sec
117  AddTestCase (new LenaTtaFfMacSchedulerTestCase (1,0,6000,775000,621000, errorModel), TestCase::EXTENSIVE);
118  AddTestCase (new LenaTtaFfMacSchedulerTestCase (3,0,6000,775000,201000, errorModel), TestCase::EXTENSIVE);
119  AddTestCase (new LenaTtaFfMacSchedulerTestCase (6,0,6000,775000,97000, errorModel), TestCase::EXTENSIVE);
120  AddTestCase (new LenaTtaFfMacSchedulerTestCase (12,0,6000,775000,48667, errorModel), TestCase::EXTENSIVE);
121 
122  // DOWNLINK - DISTANCE 10000 -> MCS 8 -> Itbs 8 (from table 7.1.7.2.1-1 of 36.213)
123  // 1 user -> 24 PRB at Itbs 8 -> 421 -> 421000 bytes/sec for one UE; 0 bytes/sec for other UEs
124  // 3 users -> 421000 among 3 users -> 421000 bytes/sec for one UE; 0 bytes/sec for other UEs
125  // 6 users -> 421000 among 6 users -> 421000 bytes/sec for one UE; 0 bytes/sec for other UEs
126  // 12 users -> 421000 among 12 users -> 421000 bytes/sec for one UE; 0 bytes/sec for other UEs
127  // UPLINK - DISTANCE 10000 -> MCS 8 -> Itbs 8 (from table 7.1.7.2.1-1 of 36.213)
128  // 1 user -> 24 PRB at Itbs 8 -> 437 -> 437000 bytes/sec
129  // 3 users -> 8 PRB at Itbs 8 -> 137 -> 137000 bytes/sec
130  // 6 users -> 4 PRB at Itbs 8 -> 67 -> 67000 bytes/sec
131  // after the patch enforcing min 3 PRBs per UE:
132  // 12 users -> 3 PRB at Itbs 8 -> 49 bytes * 8/12 UE/TTI -> 32667 bytes/sec
133  AddTestCase (new LenaTtaFfMacSchedulerTestCase (1,0,10000,421000,437000,errorModel), TestCase::EXTENSIVE);
134  AddTestCase (new LenaTtaFfMacSchedulerTestCase (3,0,10000,421000,137000,errorModel), TestCase::EXTENSIVE);
135  AddTestCase (new LenaTtaFfMacSchedulerTestCase (6,0,10000,421000,67000,errorModel), TestCase::EXTENSIVE);
136  AddTestCase (new LenaTtaFfMacSchedulerTestCase (12,0,10000,421000,32667,errorModel), TestCase::EXTENSIVE);
137 
138  // DONWLINK - DISTANCE 20000 -> MCS 8 -> Itbs 8 (from table 7.1.7.2.1-1 of 36.213)
139  // 1 user -> 24 PRB at Itbs 8 -> 421 -> 421000 bytes/sec for one UE; 0 bytes/sec for other UEs
140  // 3 users -> 421000 among 3 users -> 421000 bytes/sec for one UE; 0 bytes/sec for other UEs
141  // 6 users -> 421000 among 6 users -> 421000 bytes/sec for one UE; 0 bytes/sec for other UEs
142  // 12 users -> 421000 among 12 users -> 421000 bytes/sec for one UE; 0 bytes/sec for other UEs
143  // UPLINK - DISTANCE 20000 -> MCS 2 -> Itbs 2 (from table 7.1.7.2.1-1 of 36.213)
144  // 1 user -> 25 PRB at Itbs 2 -> 233 -> 137000 bytes/sec
145  // 3 users -> 8 PRB at Itbs 2 -> 69 -> 41000 bytes/sec
146  // 6 users -> 4 PRB at Itbs 2 -> 32 -> 22000 bytes/sec
147  // after the patch enforcing min 3 PRBs per UE:
148  // 12 users -> 3 PRB at Itbs 2 -> 26 bytes * 8/12 UE/TTI -> 12000 bytes/sec
149  AddTestCase (new LenaTtaFfMacSchedulerTestCase (1,0,20000,421000,137000,errorModel), TestCase::EXTENSIVE);
150  AddTestCase (new LenaTtaFfMacSchedulerTestCase (3,0,20000,421000,41000,errorModel), TestCase::EXTENSIVE);
151  AddTestCase (new LenaTtaFfMacSchedulerTestCase (6,0,20000,421000,22000,errorModel), TestCase::EXTENSIVE);
152  AddTestCase (new LenaTtaFfMacSchedulerTestCase (12,0,20000,421000,12000,errorModel), TestCase::EXTENSIVE);
153 
154 }
155 
156 static LenaTestTtaFfMacSchedulerSuite lenaTestTtaFfMacSchedulerSuite;
157 
158 
159 // --------------- T E S T - C A S E ------------------------------
160 
161 std::string
162 LenaTtaFfMacSchedulerTestCase::BuildNameString (uint16_t nUser, uint16_t dist)
163 {
164  std::ostringstream oss;
165  oss << nUser << " UEs, distance " << dist << " m";
166  return oss.str ();
167 }
168 
169 LenaTtaFfMacSchedulerTestCase::LenaTtaFfMacSchedulerTestCase (uint16_t nUser, uint16_t nLc, uint16_t dist, double thrRefDl, double thrRefUl, bool errorModelEnabled)
170  : TestCase (BuildNameString (nUser, dist)),
171  m_nUser (nUser),
172  m_nLc (nLc),
173  m_dist (dist),
174  m_thrRefDl (thrRefDl),
175  m_thrRefUl (thrRefUl),
176  m_errorModelEnabled (errorModelEnabled)
177 {
178 }
179 
180 LenaTtaFfMacSchedulerTestCase::~LenaTtaFfMacSchedulerTestCase ()
181 {
182 }
183 
184 
185 void
187 {
188 
189  NS_LOG_FUNCTION (this << m_nUser << m_nLc << m_dist);
190 
191  if (!m_errorModelEnabled)
192  {
193  Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (false));
194  Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (false));
195  }
196 
197  Config::SetDefault ("ns3::LteHelper::UseIdealRrc", BooleanValue (true));
198 
203  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
204  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::FriisSpectrumPropagationLossModel"));
205 
206  // Create Nodes: eNodeB and UE
207  NodeContainer enbNodes;
208  NodeContainer ueNodes;
209  enbNodes.Create (1);
210  ueNodes.Create (m_nUser);
211 
212  // Install Mobility Model
213  MobilityHelper mobility;
214  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
215  mobility.Install (enbNodes);
216  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
217  mobility.Install (ueNodes);
218 
219  // Create Devices and install them in the Nodes (eNB and UE)
220  NetDeviceContainer enbDevs;
221  NetDeviceContainer ueDevs;
222  lteHelper->SetSchedulerType ("ns3::TtaFfMacScheduler");
223  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
224  ueDevs = lteHelper->InstallUeDevice (ueNodes);
225 
226  // Attach a UE to a eNB
227  lteHelper->Attach (ueDevs, enbDevs.Get (0));
228 
229  // Activate an EPS bearer
230  enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE;
231  EpsBearer bearer (q);
232  lteHelper->ActivateDataRadioBearer (ueDevs, bearer);
233 
234 
235  Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ();
236  Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy ();
237  enbPhy->SetAttribute ("TxPower", DoubleValue (30.0));
238  enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0));
239 
240  // Set UEs' position and power
241  for (int i = 0; i < m_nUser; i++)
242  {
244  mm->SetPosition (Vector (m_dist, 0.0, 0.0));
245  Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (i)->GetObject<LteUeNetDevice> ();
246  Ptr<LteUePhy> uePhy = lteUeDev->GetPhy ();
247  uePhy->SetAttribute ("TxPower", DoubleValue (23.0));
248  uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0));
249  }
250 
251 
252  double statsStartTime = 0.300; // need to allow for RRC connection establishment + SRS
253  double statsDuration = 0.6;
254  double tolerance = 0.1;
255  Simulator::Stop (Seconds (statsStartTime + statsDuration - 0.000001));
256 
257  lteHelper->EnableMacTraces ();
258  lteHelper->EnableRlcTraces ();
259  Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats ();
260  rlcStats->SetAttribute ("StartTime", TimeValue (Seconds (statsStartTime)));
261  rlcStats->SetAttribute ("EpochDuration", TimeValue (Seconds (statsDuration)));
262 
263 
264  Simulator::Run ();
265 
269  NS_LOG_INFO ("DL - Test with " << m_nUser << " user(s) at distance " << m_dist);
270  std::vector <uint64_t> dlDataRxed;
271  for (int i = 0; i < m_nUser; i++)
272  {
273  // get the imsi
274  uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
275  uint8_t lcId = 3;
276  dlDataRxed.push_back (rlcStats->GetDlRxData (imsi, lcId));
277  NS_LOG_INFO ("\tUser " << i << " imsi " << imsi << " bytes rxed " << (double)dlDataRxed.at (i) << " thr " << (double)dlDataRxed.at (i) / statsDuration << " ref " << m_thrRefDl);
278  }
279 
285  uint8_t found = 0;
286  for (int i = 0; i < m_nUser; i++)
287  {
288  double throughput = (double)dlDataRxed.at (i) / statsDuration;
289  if (throughput != 0 && found == 0)
290  {
291  NS_TEST_ASSERT_MSG_EQ_TOL (throughput, m_thrRefDl, m_thrRefDl * tolerance, " Unfair Throughput!");
292  found = 1;
293  }
294  else if (throughput != 0 && found == 1)
295  {
296  NS_TEST_ASSERT_MSG_EQ_TOL (0, m_thrRefDl, m_thrRefDl * tolerance, " Unfair Throughput!");
297  }
298  else
299  NS_TEST_ASSERT_MSG_EQ_TOL (throughput, 0, 0, " Unfair Throughput!");
300  }
301 
305  NS_LOG_INFO ("UL - Test with " << m_nUser << " user(s) at distance " << m_dist);
306  std::vector <uint64_t> ulDataRxed;
307  for (int i = 0; i < m_nUser; i++)
308  {
309  // get the imsi
310  uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
311  // get the lcId
312  uint8_t lcId = 3;
313  ulDataRxed.push_back (rlcStats->GetUlRxData (imsi, lcId));
314  NS_LOG_INFO ("\tUser " << i << " imsi " << imsi << " bytes rxed " << (double)ulDataRxed.at (i) << " thr " << (double)ulDataRxed.at (i) / statsDuration << " ref " << m_thrRefUl);
315  }
322  for (int i = 0; i < m_nUser; i++)
323  {
324  NS_TEST_ASSERT_MSG_EQ_TOL ((double)ulDataRxed.at (i) / statsDuration, m_thrRefUl, m_thrRefUl * tolerance, " Unfair Throughput!");
325  }
327 
328 }
329 
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
Hold a bool native type.
Definition: boolean.h:38
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Definition: lte-helper.cc:285
hold variables of type string
Definition: string.h:19
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
A suite of tests to run.
Definition: test.h:962
Ptr< LteEnbPhy > GetPhy(void) const
Mobility model for which the current position does not change once it has been set and until it is se...
static void Run(void)
Definition: simulator.cc:157
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
void EnableRlcTraces(void)
Definition: lte-helper.cc:829
virtual void DoRun(void)
Implementation to actually run this test case.
#define NS_LOG_INFO(msg)
Definition: log.h:264
encapsulates test code
Definition: test.h:834
void ActivateDataRadioBearer(NetDeviceContainer ueDevices, EpsBearer bearer)
Definition: lte-helper.cc:773
a 3d vector
Definition: vector.h:31
void SetSchedulerType(std::string type)
Definition: lte-helper.cc:183
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
hold objects of type ns3::Time
Definition: nstime.h:700
uint64_t GetDlRxData(uint64_t imsi, uint8_t lcid)
void Attach(NetDeviceContainer ueDevices, Ptr< NetDevice > enbDevice)
Definition: lte-helper.cc:562
Fast test.
Definition: test.h:843
holds a vector of ns3::NetDevice pointers
static void Destroy(void)
Definition: simulator.cc:121
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 test case to this test suite.
Definition: test.cc:172
void SetPosition(const Vector &position)
Ptr< RadioBearerStatsCalculator > GetRlcStats(void)
Definition: lte-helper.cc:1333
NetDeviceContainer InstallUeDevice(NodeContainer c)
Definition: lte-helper.cc:300
Helper class used to assign positions and mobility models to nodes.
uint64_t GetUlRxData(uint64_t imsi, uint8_t lcid)
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Definition: nstime.h:586
static void Stop(void)
Definition: simulator.cc:164
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)
Definition: lte-helper.cc:1204
Hold an floating point type.
Definition: double.h:41
void SetAttribute(std::string name, const AttributeValue &value)
Definition: object-base.cc:160
Ptr< T > GetObject(void) const
Definition: object.h:332