A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lte-test-pf-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  */
21 
22 #include <iostream>
23 #include <sstream>
24 #include <string>
25 
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>
36 #include <ns3/eps-bearer.h>
37 #include <ns3/node-container.h>
38 #include <ns3/mobility-helper.h>
39 #include <ns3/net-device-container.h>
40 #include <ns3/lte-ue-net-device.h>
41 #include <ns3/lte-enb-net-device.h>
42 #include <ns3/lte-ue-rrc.h>
43 #include <ns3/lte-helper.h>
44 #include "ns3/string.h"
45 #include "ns3/double.h"
46 #include <ns3/lte-enb-phy.h>
47 #include <ns3/lte-ue-phy.h>
48 #include <ns3/boolean.h>
49 #include <ns3/enum.h>
50 
52 
53 NS_LOG_COMPONENT_DEFINE ("LenaTestPfFfMacCheduler");
54 
55 namespace ns3 {
56 
58  : TestSuite ("lte-pf-ff-mac-scheduler", SYSTEM)
59 {
60  NS_LOG_INFO ("creating LenaTestPfFfMacSchedulerSuite");
61 
62  //Test Case 1: AMC works in PF
63 
64  // DOWNLINK - DISTANCE 0 -> MCS 28 -> Itbs 26 (from table 7.1.7.2.1-1 of 36.213)
65  // 1 user -> 24 PRB at Itbs 26 -> 2196 -> 2196000 bytes/sec
66  // 3 users -> 2196000 among 3 users -> 732000 bytes/sec
67  // 6 users -> 2196000 among 6 users -> 366000 bytes/sec
68  // 12 users -> 2196000 among 12 users -> 183000 bytes/sec
69  // 15 users -> 2196000 among 15 users -> 146400 bytes/sec
70  // UPLINK- DISTANCE 0 -> MCS 28 -> Itbs 26 (from table 7.1.7.2.1-1 of 36.213)
71  // 1 user -> 25 PRB at Itbs 26 -> 2292 -> 2292000 bytes/sec
72  // 3 users -> 8 PRB at Itbs 26 -> 749 -> 749000 bytes/sec
73  // 6 users -> 4 PRB at Itbs 26 -> 373 -> 373000 bytes/sec
74  // 12 users -> 2 PRB at Itbs 26 -> 185 -> 185000 bytes/sec
75  // 15 users -> 1 PRB at Itbs 26 -> 89 -> 89000 bytes/sec
76  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (1,0,0,2196000,2292000));
77  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (3,0,0,732000,749000));
78  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (6,0,0,366000,373000));
79  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (12,0,0,183000,185000));
80  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (15,0,0,146400,89000));
81 
82  // DOWNLINK - DISTANCE 3000 -> MCS 24 -> Itbs 30 (from table 7.1.7.2.1-1 of 36.213)
83  // 1 user -> 24 PRB at Itbs 20 -> 1383 -> 1383000 bytes/sec
84  // 3 users -> 1383000 among 3 users -> 461000 bytes/sec
85  // 6 users -> 1383000 among 6 users -> 230500 bytes/sec
86  // 12 users -> 1383000 among 12 users -> 115250 bytes/sec
87  // 15 users -> 1383000 among 15 users -> 92200 bytes/sec
88  // UPLINK - DISTANCE 3000 -> MCS 20 -> Itbs 18 (from table 7.1.7.2.1-1 of 36.213)
89  // 1 user -> 25 PRB at Itbs 18 -> 1239 -> 1239000 bytes/sec
90  // 3 users -> 8 PRB at Itbs 18 -> 389 -> 389000 bytes/sec
91  // 6 users -> 4 PRB at Itbs 18 -> 193 -> 193000 bytes/sec
92  // 12 users -> 2 PRB at Itbs 18 -> 97 -> 97000 bytes/sec
93  // 15 users -> 1 PRB at Itbs 18 -> 47 -> 47000 bytes/sec
94  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (1,0,3000,1383000,1239000));
95  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (3,0,3000,461000,389000));
96  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (6,0,3000,230500,193000));
97  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (12,0,3000,115250,97000));
98  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (15,0,3000,92200,47000));
99 
100  // DOWNLINK - DISTANCE 6000 -> MCS 16 -> Itbs 15 (from table 7.1.7.2.1-1 of 36.213)
101  // 1 user -> 24 PRB at Itbs 15 -> 903 -> 903000 bytes/sec
102  // 3 users -> 903000 among 3 users -> 301000 bytes/sec
103  // 6 users -> 903000 among 6 users -> 150500 bytes/sec
104  // 12 users -> 903000 among 12 users -> 75250 bytes/sec
105  // 15 users -> 903000 among 15 users -> 60200 bytes/sec
106  // UPLINK - DISTANCE 6000 -> MCS 12 -> Itbs 11 (from table 7.1.7.2.1-1 of 36.213)
107  // 1 user -> 25 PRB at Itbs 11 -> 621 -> 621000 bytes/sec
108  // 3 users -> 8 PRB at Itbs 11 -> 201 -> 201000 bytes/sec
109  // 6 users -> 4 PRB at Itbs 11 -> 97 -> 97000 bytes/sec
110  // 12 users -> 2 PRB at Itbs 11 -> 47 -> 47000 bytes/sec
111  // 15 users -> 1 PRB at Itbs 11 -> 22 -> 22000 bytes/sec
112  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (1,0,6000,903000,621000));
113  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (3,0,6000,301000,201000));
114  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (6,0,6000,150500,97000));
115  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (12,0,6000,75250,47000));
116  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (15,0,6000,60200,22000));
117 
118  // DOWNLINK - DISTANCE 9000 -> MCS 12 -> Itbs 11 (from table 7.1.7.2.1-1 of 36.213)
119  // 1 user -> 24 PRB at Itbs 11 -> 597 -> 597000 bytes/sec
120  // 3 users -> 597000 among 3 users -> 199000 bytes/sec
121  // 6 users -> 597000 among 6 users -> 99500 bytes/sec
122  // 12 users -> 597000 among 12 users -> 49750 bytes/sec
123  // 15 users -> 597000 among 15 users -> 39800 bytes/sec
124  // UPLINK - DISTANCE 9000 -> MCS 8 -> Itbs 8 (from table 7.1.7.2.1-1 of 36.213)
125  // 1 user -> 24 PRB at Itbs 8 -> 437 -> 437000 bytes/sec
126  // 3 users -> 8 PRB at Itbs 8 -> 137 -> 137000 bytes/sec
127  // 6 users -> 4 PRB at Itbs 8 -> 67 -> 67000 bytes/sec
128  // 12 users -> 2 PRB at Itbs 8 -> 32 -> 32000 bytes/sec
129  // 15 users -> 1 PRB at Itbs 8 -> 15 -> 15000 bytes/sec
130  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (1,0,9000,597000,437000));
131  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (3,0,9000,199000,137000));
132  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (6,0,9000,99500,67000));
133  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (12,0,9000,49750,32000));
134  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (15,0,9000,39800,15000));
135 
136  // DONWLINK - DISTANCE 15000 -> MCS 6 -> Itbs 6 (from table 7.1.7.2.1-1 of 36.213)
137  // 1 user -> 24 PRB at Itbs 6 -> 309 -> 309000 bytes/sec
138  // 3 users -> 309000 among 3 users -> 103000 bytes/sec
139  // 6 users -> 309000 among 6 users -> 51500 bytes/sec
140  // 12 users -> 309000 among 12 users -> 25750 bytes/sec
141  // 15 users -> 309000 among 15 users -> 20600 bytes/sec
142  // UPLINK - DISTANCE 15000 -> MCS 6 -> Itbs 6 (from table 7.1.7.2.1-1 of 36.213)
143  // 1 user -> 25 PRB at Itbs 6 -> 233 -> 233000 bytes/sec
144  // 3 users -> 8 PRB at Itbs 6 -> 69 -> 69000 bytes/sec
145  // 6 users -> 4 PRB at Itbs 6 -> 32 -> 32000 bytes/sec
146  // 12 users -> 2 PRB at Itbs 6 -> 15 -> 15000 bytes/sec
147  // 15 users -> 1 PRB at Itbs 6 -> 7 -> 7000 bytes/sec
148  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (1,0,15000,309000,233000));
149  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (3,0,15000,103000,69000));
150  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (6,0,15000,51500,32000));
151  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (12,0,15000,25750,15000));
152  AddTestCase (new LenaPfFfMacSchedulerTestCase1 (15,0,15000,20600,7000));
153 
154  // Test Case 2: fairness check
155 
156  std::vector<uint16_t> dist;
157  dist.push_back (0); // User 0 distance --> MCS 28
158  dist.push_back (3000); // User 1 distance --> MCS 24
159  dist.push_back (6000); // User 2 distance --> MCS 16
160  dist.push_back (9000); // User 3 distance --> MCS 12
161  dist.push_back (15000); // User 4 distance --> MCS 6
162  std::vector<uint32_t> estThrPfDl;
163  estThrPfDl.push_back (89000); // User 0 estimated TTI throughput from PF
164  estThrPfDl.push_back (55000); // User 1 estimated TTI throughput from PF
165  estThrPfDl.push_back (35000); // User 2 estimated TTI throughput from PF
166  estThrPfDl.push_back (22000); // User 3 estimated TTI throughput from PF
167  estThrPfDl.push_back (11000); // User 4 estimated TTI throughput from PF
168  std::vector<uint32_t> estThrPfUl;
169  estThrPfUl.push_back (469000); // User 0 estimated TTI throughput from PF
170  estThrPfUl.push_back (249000); // User 1 estimated TTI throughput from PF
171  estThrPfUl.push_back (125000); // User 2 estimated TTI throughput from PF
172  estThrPfUl.push_back (85000); // User 3 estimated TTI throughput from PF
173  estThrPfUl.push_back (41000); // User 4 estimated TTI throughput from PF
174  AddTestCase (new LenaPfFfMacSchedulerTestCase2 (dist, estThrPfDl, estThrPfUl));
175 
176 
177 }
178 
180 
181 
182 // --------------- T E S T - C A S E # 1 ------------------------------
183 
184 
185 std::string
186 LenaPfFfMacSchedulerTestCase1::BuildNameString (uint16_t nUser, uint16_t dist)
187 {
188  std::ostringstream oss;
189  oss << nUser << " UEs, distance " << dist << " m";
190  return oss.str ();
191 }
192 
193 LenaPfFfMacSchedulerTestCase1::LenaPfFfMacSchedulerTestCase1 (uint16_t nUser, uint16_t nLc, uint16_t dist, double thrRefDl, double thrRefUl)
194  : TestCase (BuildNameString (nUser, dist)),
195  m_nUser (nUser),
196  m_nLc (nLc),
197  m_dist (dist),
198  m_thrRefDl (thrRefDl),
199  m_thrRefUl (thrRefUl)
200 {
201 }
202 
204 {
205 }
206 
207 void
209 {
210  Config::SetDefault ("ns3::LteAmc::AmcModel", EnumValue (LteAmc::PiroEW2010));
211  Config::SetDefault ("ns3::LteAmc::Ber", DoubleValue (0.00005));
212  Config::SetDefault ("ns3::LteSpectrumPhy::PemEnabled", BooleanValue (false));
214  // LogComponentEnable ("LteEnbRrc", LOG_LEVEL_ALL);
215  // LogComponentEnable ("LteUeRrc", LOG_LEVEL_ALL);
216  // LogComponentEnable ("LteEnbMac", LOG_LEVEL_ALL);
217  // LogComponentEnable ("LteUeMac", LOG_LEVEL_ALL);
218 // LogComponentEnable ("LteRlc", LOG_LEVEL_ALL);
219 //
220 // LogComponentEnable ("LtePhy", LOG_LEVEL_ALL);
221 // LogComponentEnable ("LteEnbPhy", LOG_LEVEL_ALL);
222 // LogComponentEnable ("LteUePhy", LOG_LEVEL_ALL);
223 
224  // LogComponentEnable ("LteSpectrumPhy", LOG_LEVEL_ALL);
225  // LogComponentEnable ("LteInterference", LOG_LEVEL_ALL);
226  // LogComponentEnable ("LteSinrChunkProcessor", LOG_LEVEL_ALL);
227  //
228  // LogComponentEnable ("LtePropagationLossModel", LOG_LEVEL_ALL);
229  // LogComponentEnable ("LossModel", LOG_LEVEL_ALL);
230  // LogComponentEnable ("ShadowingLossModel", LOG_LEVEL_ALL);
231  // LogComponentEnable ("PenetrationLossModel", LOG_LEVEL_ALL);
232  // LogComponentEnable ("MultipathLossModel", LOG_LEVEL_ALL);
233  // LogComponentEnable ("PathLossModel", LOG_LEVEL_ALL);
234  //
235  // LogComponentEnable ("LteNetDevice", LOG_LEVEL_ALL);
236  // LogComponentEnable ("LteUeNetDevice", LOG_LEVEL_ALL);
237  // LogComponentEnable ("LteEnbNetDevice", LOG_LEVEL_ALL);
238 
239 // LogComponentEnable ("PfFfMacScheduler", LOG_LEVEL_ALL);
240  LogComponentEnable ("LenaTestPfFfMacCheduler", LOG_LEVEL_ALL);
241  // LogComponentEnable ("LteAmc", LOG_LEVEL_ALL);
242 // LogComponentEnable ("RadioBearerStatsCalculator", LOG_LEVEL_ALL);
243 
248  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
249 
250  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::FriisSpectrumPropagationLossModel"));
251 
252  // Create Nodes: eNodeB and UE
253  NodeContainer enbNodes;
254  NodeContainer ueNodes;
255  enbNodes.Create (1);
256  ueNodes.Create (m_nUser);
257 
258  // Install Mobility Model
259  MobilityHelper mobility;
260  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
261  mobility.Install (enbNodes);
262  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
263  mobility.Install (ueNodes);
264 
265  // Create Devices and install them in the Nodes (eNB and UE)
266  NetDeviceContainer enbDevs;
267  NetDeviceContainer ueDevs;
268  lteHelper->SetSchedulerType ("ns3::PfFfMacScheduler");
269  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
270  ueDevs = lteHelper->InstallUeDevice (ueNodes);
271 
272  // Attach a UE to a eNB
273  lteHelper->Attach (ueDevs, enbDevs.Get (0));
274 
275  // Activate an EPS bearer
277  EpsBearer bearer (q);
278  lteHelper->ActivateEpsBearer (ueDevs, bearer, EpcTft::Default ());
279 
280  Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ();
281  Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy ();
282  enbPhy->SetAttribute ("TxPower", DoubleValue (30.0));
283  enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0));
284 
285  // Set UEs' position and power
286  for (int i = 0; i < m_nUser; i++)
287  {
289  mm->SetPosition (Vector (m_dist, 0.0, 0.0));
290  Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (i)->GetObject<LteUeNetDevice> ();
291  Ptr<LteUePhy> uePhy = lteUeDev->GetPhy ();
292  uePhy->SetAttribute ("TxPower", DoubleValue (23.0));
293  uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0));
294  }
295 
296  lteHelper->EnableRlcTraces ();
297 
298  double simulationTime = 1.0;
299  double tolerance = 0.1;
300  Simulator::Stop (Seconds (simulationTime));
301 
302  Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats ();
303  rlcStats->SetAttribute ("EpochDuration", TimeValue (Seconds (simulationTime)));
304 
305  Simulator::Run ();
306 
310  NS_LOG_INFO ("DL - Test with " << m_nUser << " user(s) at distance " << m_dist);
311  std::vector <uint64_t> dlDataRxed;
312  for (int i = 0; i < m_nUser; i++)
313  {
314  // get the imsi
315  uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
316  // get the lcId
317  uint8_t lcId = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetRrc ()->GetLcIdVector ().at (0);
318  dlDataRxed.push_back (rlcStats->GetDlRxData (imsi, lcId));
319  NS_LOG_INFO ("\tUser " << i << " imsi " << imsi << " bytes rxed " << (double)dlDataRxed.at (i) << " thr " << (double)dlDataRxed.at (i) / simulationTime << " ref " << m_thrRefDl);
320  }
327  for (int i = 0; i < m_nUser; i++)
328  {
329  NS_TEST_ASSERT_MSG_EQ_TOL ((double)dlDataRxed.at (i) / simulationTime, m_thrRefDl, m_thrRefDl * tolerance, " Unfair Throughput!");
330  }
331 
335  NS_LOG_INFO ("UL - Test with " << m_nUser << " user(s) at distance " << m_dist);
336  std::vector <uint64_t> ulDataRxed;
337  for (int i = 0; i < m_nUser; i++)
338  {
339  // get the imsi
340  uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
341  // get the lcId
342  uint8_t lcId = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetRrc ()->GetLcIdVector ().at (0);
343  ulDataRxed.push_back (rlcStats->GetUlRxData (imsi, lcId));
344  NS_LOG_INFO ("\tUser " << i << " imsi " << imsi << " bytes rxed " << (double)ulDataRxed.at (i) << " thr " << (double)ulDataRxed.at (i) / simulationTime << " ref " << m_thrRefUl);
345  }
352  for (int i = 0; i < m_nUser; i++)
353  {
354  NS_TEST_ASSERT_MSG_EQ_TOL ((double)ulDataRxed.at (i) / simulationTime, m_thrRefUl, m_thrRefUl * tolerance, " Unfair Throughput!");
355  }
357 
358 }
359 
360 
361 
362 // --------------- T E S T - C A S E # 2 ------------------------------
363 
364 
365 std::string
366 LenaPfFfMacSchedulerTestCase2::BuildNameString (uint16_t nUser, std::vector<uint16_t> dist)
367 {
368  std::ostringstream oss;
369  oss << "distances (m) = [ " ;
370  for (std::vector<uint16_t>::iterator it = dist.begin (); it != dist.end (); ++it)
371  {
372  oss << *it << " ";
373  }
374  oss << "]";
375  return oss.str ();
376 }
377 
378 
379 LenaPfFfMacSchedulerTestCase2::LenaPfFfMacSchedulerTestCase2 (std::vector<uint16_t> dist, std::vector<uint32_t> estThrPfDl, std::vector<uint32_t> estThrPfUl)
380  : TestCase (BuildNameString (dist.size (), dist)),
381  m_nUser (dist.size ()),
382  m_dist (dist),
383  m_estThrPfDl (estThrPfDl),
384  m_estThrPfUl (estThrPfUl)
385 {
386 }
387 
389 {
390 }
391 
392 void
394 {
395  // LogComponentEnable ("LteEnbRrc", LOG_LEVEL_ALL);
396  // LogComponentEnable ("LteUeRrc", LOG_LEVEL_ALL);
397  // LogComponentEnable ("LteEnbMac", LOG_LEVEL_ALL);
398  // LogComponentEnable ("LteUeMac", LOG_LEVEL_ALL);
399  // LogComponentEnable ("LteRlc", LOG_LEVEL_ALL);
400  //
401  // LogComponentEnable ("LtePhy", LOG_LEVEL_ALL);
402  // LogComponentEnable ("LteEnbPhy", LOG_LEVEL_ALL);
403  // LogComponentEnable ("LteUePhy", LOG_LEVEL_ALL);
404 
405  // LogComponentEnable ("LteSpectrumPhy", LOG_LEVEL_ALL);
406  // LogComponentEnable ("LteInterference", LOG_LEVEL_ALL);
407  // LogComponentEnable ("LteSinrChunkProcessor", LOG_LEVEL_ALL);
408  //
409  // LogComponentEnable ("LtePropagationLossModel", LOG_LEVEL_ALL);
410  // LogComponentEnable ("LossModel", LOG_LEVEL_ALL);
411  // LogComponentEnable ("ShadowingLossModel", LOG_LEVEL_ALL);
412  // LogComponentEnable ("PenetrationLossModel", LOG_LEVEL_ALL);
413  // LogComponentEnable ("MultipathLossModel", LOG_LEVEL_ALL);
414  // LogComponentEnable ("PathLossModel", LOG_LEVEL_ALL);
415  //
416  // LogComponentEnable ("LteNetDevice", LOG_LEVEL_ALL);
417  // LogComponentEnable ("LteUeNetDevice", LOG_LEVEL_ALL);
418  // LogComponentEnable ("LteEnbNetDevice", LOG_LEVEL_ALL);
419 
420 // LogComponentEnable ("PfFfMacScheduler", LOG_LEVEL_ALL);
421  LogComponentEnable ("LenaTestPfFfMacCheduler", LOG_LEVEL_ALL);
422  // LogComponentEnable ("LteAmc", LOG_LEVEL_ALL);
423  // LogComponentEnable ("RadioBearerStatsCalculator", LOG_LEVEL_ALL);
424 
429  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
430 
431  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::FriisSpectrumPropagationLossModel"));
432 
433  // Create Nodes: eNodeB and UE
434  NodeContainer enbNodes;
435  NodeContainer ueNodes;
436  enbNodes.Create (1);
437  ueNodes.Create (m_nUser);
438 
439  // Install Mobility Model
440  MobilityHelper mobility;
441  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
442  mobility.Install (enbNodes);
443  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
444  mobility.Install (ueNodes);
445 
446  // Create Devices and install them in the Nodes (eNB and UE)
447  NetDeviceContainer enbDevs;
448  NetDeviceContainer ueDevs;
449  lteHelper->SetSchedulerType ("ns3::PfFfMacScheduler");
450  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
451  ueDevs = lteHelper->InstallUeDevice (ueNodes);
452 
453  // Attach a UE to a eNB
454  lteHelper->Attach (ueDevs, enbDevs.Get (0));
455 
456  // Activate an EPS bearer
458  EpsBearer bearer (q);
459  lteHelper->ActivateEpsBearer (ueDevs, bearer, EpcTft::Default ());
460 
461  Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ();
462  Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy ();
463  enbPhy->SetAttribute ("TxPower", DoubleValue (30.0));
464  enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0));
465 
466  // Set UEs' position and power
467  for (int i = 0; i < m_nUser; i++)
468  {
470  mm->SetPosition (Vector (m_dist.at (i), 0.0, 0.0));
471  Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (i)->GetObject<LteUeNetDevice> ();
472  Ptr<LteUePhy> uePhy = lteUeDev->GetPhy ();
473  uePhy->SetAttribute ("TxPower", DoubleValue (23.0));
474  uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0));
475  }
476 
477  lteHelper->EnableRlcTraces ();
478 
479  double simulationTime = 0.4;
480  double tolerance = 0.1;
481  Simulator::Stop (Seconds (simulationTime));
482 
483  Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats ();
484  rlcStats->SetAttribute ("EpochDuration", TimeValue (Seconds (simulationTime)));
485 
486  Simulator::Run ();
487 
488  NS_LOG_INFO ("DL - Test with " << m_nUser << " user(s)");
489  std::vector <uint64_t> dlDataRxed;
490  double totalData = 0;
491  double totalEstThrPf = 0;
492  for (int i = 0; i < m_nUser; i++)
493  {
494  // get the imsi
495  uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
496  // get the lcId
497  uint8_t lcId = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetRrc ()->GetLcIdVector ().at (0);
498  dlDataRxed.push_back (rlcStats->GetDlRxData (imsi, lcId));
499  totalData += (double)dlDataRxed.at (i);
500  NS_LOG_INFO ("\tUser " << i << " dist " << m_dist.at (i) << " imsi " << imsi << " bytes rxed " << (double)dlDataRxed.at (i) << " thr " << (double)dlDataRxed.at (i) / simulationTime << " ref " << m_nUser);
501  totalEstThrPf += m_estThrPfDl.at (i);
502  }
503 
509  for (int i = 0; i < m_nUser; i++)
510  {
511  double thrRatio = (double)dlDataRxed.at (i) / totalData;
512  double estThrRatio = (double)m_estThrPfDl.at (i) / totalEstThrPf;
513  NS_LOG_INFO ("\tUser " << i << " thrRatio " << thrRatio << " estThrRatio " << estThrRatio);
514  NS_TEST_ASSERT_MSG_EQ_TOL (estThrRatio, thrRatio, tolerance, " Unfair Throughput!");
515  }
516 
521  NS_LOG_INFO ("UL - Test with " << m_nUser);
522  std::vector <uint64_t> ulDataRxed;
523  for (int i = 0; i < m_nUser; i++)
524  {
525  // get the imsi
526  uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
527  // get the lcId
528  uint8_t lcId = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetRrc ()->GetLcIdVector ().at (0);
529  ulDataRxed.push_back (rlcStats->GetUlRxData (imsi, lcId));
530  NS_LOG_INFO ("\tUser " << i << " dist " << m_dist.at (i) << " bytes rxed " << (double)ulDataRxed.at (i) << " thr " << (double)ulDataRxed.at (i) / simulationTime << " ref " << (double)m_estThrPfUl.at (i));
531  NS_TEST_ASSERT_MSG_EQ_TOL ((double)ulDataRxed.at (i) / simulationTime, (double)m_estThrPfUl.at (i), (double)m_estThrPfUl.at (i) * tolerance, " Unfair Throughput!");
532  }
534 
535 }
536 
537 
538 } // namespace ns3
539 
540 
541 
542