A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lte-test-rr-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  */
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 "ns3/radio-bearer-stats-calculator.h"
31 #include <ns3/constant-position-mobility-model.h>
32 #include <ns3/eps-bearer.h>
33 #include <ns3/node-container.h>
34 #include <ns3/mobility-helper.h>
35 #include <ns3/net-device-container.h>
36 #include <ns3/lte-ue-net-device.h>
37 #include <ns3/lte-enb-net-device.h>
38 #include <ns3/lte-ue-rrc.h>
39 #include <ns3/lte-helper.h>
40 #include "ns3/string.h"
41 #include "ns3/double.h"
42 #include <ns3/lte-enb-phy.h>
43 #include <ns3/lte-ue-phy.h>
44 #include <ns3/boolean.h>
45 #include <ns3/enum.h>
46 
48 
49 NS_LOG_COMPONENT_DEFINE ("LenaTestRrFfMacCheduler");
50 
51 namespace ns3 {
52 
53 
55  : TestSuite ("lte-rr-ff-mac-scheduler", SYSTEM)
56 {
57  NS_LOG_INFO ("creating LenaRrFfMacSchedulerTestCase");
58 
59 
60  // DOWNLINK- DISTANCE 0 -> MCS 28 -> Itbs 26 (from table 7.1.7.2.1-1 of 36.213)
61  // 1 user -> 24 PRB at Itbs 26 -> 2196 -> 2196000 bytes/sec
62  // 3 users -> 8 PRB at Itbs 26 -> 749 -> 749000 bytes/sec
63  // 6 users -> 4 PRB at Itbs 26 -> 373 -> 373000 bytes/sec
64  // 9 user -> 2 PRB at Itbs 26 -> 185 -> 185000 bytes/sec
65  // 12 users -> 2 PRB at Itbs 26 -> 185 -> 185000 bytes/sec
66  // 15 users -> 2 PRB at Itbs 26 * 0.8 -> 148 -> 148000 bytes/sec
67  // UPLINK- DISTANCE 0 -> MCS 28 -> Itbs 26 (from table 7.1.7.2.1-1 of 36.213)
68  // 1 user -> 25 PRB at Itbs 26 -> 2292 -> 2292000 bytes/sec
69  // 3 users -> 8 PRB at Itbs 26 -> 749 -> 749000 bytes/sec
70  // 6 users -> 4 PRB at Itbs 26 -> 373 -> 373000 bytes/sec
71  // 9 user -> 2 PRB at Itbs 26 -> 185 -> 185000 bytes/sec
72  // 12 users -> 2 PRB at Itbs 26 -> 185 -> 185000 bytes/sec
73  // 15 users -> 1 PRB at Itbs 26 -> 89 -> 89000 bytes/sec
74  AddTestCase (new LenaRrFfMacSchedulerTestCase (1,0,0,2196000,2292000));
75  AddTestCase (new LenaRrFfMacSchedulerTestCase (3,0,0,749000,749000));
76  AddTestCase (new LenaRrFfMacSchedulerTestCase (6,0,0,373000,373000));
77  AddTestCase (new LenaRrFfMacSchedulerTestCase (9,0,0,185000,185000));
78  AddTestCase (new LenaRrFfMacSchedulerTestCase (12,0,0,185000,185000));
79  AddTestCase (new LenaRrFfMacSchedulerTestCase (15,0,0,148000,89000));
80 
81  // DOWNLINK - DISTANCE 3000 -> MCS 22 -> Itbs 20 (from table 7.1.7.2.1-1 of 36.213)
82  // 1 user -> 24 PRB at Itbs 20 -> 1383 -> 1383000 bytes/sec
83  // 3 users -> 8 PRB at Itbs 20 -> 469 -> 469000 bytes/sec
84  // 6 users -> 4 PRB at Itbs 20 -> 233 -> 233000 bytes/sec
85  // 9 user -> 2 PRB at Itbs 20 -> 113 -> 113000 bytes/sec
86  // 12 users -> 2 PRB at Itbs 20 -> 113 -> 113000 bytes/sec
87  // 15 users -> 2 PRB at Itbs 20 * 0.8 -> 90.4 -> 90400 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  // 9 user -> 2 PRB at Itbs 18 -> 97 -> 97000 bytes/sec
93  // 12 users -> 2 PRB at Itbs 18 -> 97 -> 97000 bytes/sec
94  // 15 users -> 1 PRB at Itbs 18 -> 47 -> 47000 bytes/sec
95  AddTestCase (new LenaRrFfMacSchedulerTestCase (1,0,3000,1383000,1239000));
96  AddTestCase (new LenaRrFfMacSchedulerTestCase (3,0,3000,469000,389000));
97  AddTestCase (new LenaRrFfMacSchedulerTestCase (6,0,3000,233000,193000));
98  AddTestCase (new LenaRrFfMacSchedulerTestCase (9,0,3000,113000,97000));
99  AddTestCase (new LenaRrFfMacSchedulerTestCase (12,0,3000,113000,97000));
100  AddTestCase (new LenaRrFfMacSchedulerTestCase (15,0,3000,90400,47000));
101 
102  // DOWNLINK - DISTANCE 6000 -> MCS 16 -> Itbs 15 (from table 7.1.7.2.1-1 of 36.213)
103  // 1 user -> 24 PRB at Itbs 15 -> 903 -> 903000 bytes/sec
104  // 3 users -> 8 PRB at Itbs 15 -> 309 -> 309000 bytes/sec
105  // 6 users -> 4 PRB at Itbs 15 -> 153 -> 153000 bytes/sec
106  // 9 user -> 2 PRB at Itbs 15 -> 75 -> 75000 bytes/sec
107  // 12 users -> 2 PRB at Itbs 15 -> 75 -> 75000 bytes/sec
108  // 15 users -> 2 PRB at Itbs 15 * 0.8 -> 60 -> 60000 bytes/sec
109  // UPLINK - DISTANCE 6000 -> MCS 12 -> Itbs 11 (from table 7.1.7.2.1-1 of 36.213)
110  // 1 user -> 25 PRB at Itbs 11 -> 621 -> 621000 bytes/sec
111  // 3 users -> 8 PRB at Itbs 11 -> 201 -> 201000 bytes/sec
112  // 6 users -> 4 PRB at Itbs 11 -> 97 -> 97000 bytes/sec
113  // 9 user -> 2 PRB at Itbs 11 -> 47 -> 47000 bytes/sec
114  // 12 users -> 2 PRB at Itbs 11 -> 47 -> 47000 bytes/sec
115  // 15 users -> 1 PRB at Itbs 11 -> 22 -> 22000 bytes/sec
116  AddTestCase (new LenaRrFfMacSchedulerTestCase (1,0,6000,903000,621000));
117  AddTestCase (new LenaRrFfMacSchedulerTestCase (3,0,6000,309000,201000));
118  AddTestCase (new LenaRrFfMacSchedulerTestCase (6,0,6000,153000,97000));
119  AddTestCase (new LenaRrFfMacSchedulerTestCase (9,0,6000,75000,47000));
120  AddTestCase (new LenaRrFfMacSchedulerTestCase (12,0,6000,75000,47000));
121  AddTestCase (new LenaRrFfMacSchedulerTestCase (15,0,6000,60000,22000));
122 
123  // DOWNLINK - DISTANCE 9000 -> MCS 12 -> Itbs 11 (from table 7.1.7.2.1-1 of 36.213)
124  // 1 user -> 24 PRB at Itbs 11 -> 597 -> 597000 bytes/sec
125  // 3 users -> 8 PRB at Itbs 11 -> 201 -> 201000 bytes/sec
126  // 6 users -> 4 PRB at Itbs 11 -> 97 -> 97000 bytes/sec
127  // 9 user -> 2 PRB at Itbs 11 -> 47 -> 47000 bytes/sec
128  // 12 users -> 2 PRB at Itbs 11 -> 47 -> 47000 bytes/sec
129  // 15 users -> 2 PRB at Itbs 11 * 0.8 -> 37.6 -> 37600 bytes/sec
130  // UPLINK - DISTANCE 9000 -> MCS 8 -> Itbs 8 (from table 7.1.7.2.1-1 of 36.213)
131  // 1 user -> 24 PRB at Itbs 8 -> 437 -> 437000 bytes/sec
132  // 3 users -> 8 PRB at Itbs 8 -> 137 -> 137000 bytes/sec
133  // 6 users -> 4 PRB at Itbs 8 -> 67 -> 67000 bytes/sec
134  // 9 user -> 2 PRB at Itbs 8 -> 32 -> 32000 bytes/sec
135  // 12 users -> 2 PRB at Itbs 8 -> 32 -> 32000 bytes/sec
136  // 15 users -> 1 PRB at Itbs 8 -> 15 -> 15000 bytes/sec
137  AddTestCase (new LenaRrFfMacSchedulerTestCase (1,0,9000,597000,437000));
138  AddTestCase (new LenaRrFfMacSchedulerTestCase (3,0,9000,201000,137000));
139  AddTestCase (new LenaRrFfMacSchedulerTestCase (6,0,9000,97000,67000));
140  AddTestCase (new LenaRrFfMacSchedulerTestCase (9,0,9000,47000,32000));
141  AddTestCase (new LenaRrFfMacSchedulerTestCase (12,0,9000,47000,32000));
142  AddTestCase (new LenaRrFfMacSchedulerTestCase (15,0,9000,37600,15000));
143 
144  // DOWNLINK - DISTANCE 15000 -> MCS 6 -> Itbs 6 (from table 7.1.7.2.1-1 of 36.213)
145  // 1 user -> 24 PRB at Itbs 6 -> 309 -> 309000 bytes/sec
146  // 3 users -> 8 PRB at Itbs 6 -> 101 -> 101000 bytes/sec
147  // 6 users -> 4 PRB at Itbs 6 -> 49 -> 49000 bytes/sec
148  // 9 user -> 2 PRB at Itbs 6 -> 22 -> 22000 bytes/sec
149  // 12 users -> 2 PRB at Itbs 6 -> 22 -> 22000 bytes/sec
150  // 15 users -> 2 PRB at Itbs 6 * 0.8 -> 17.6 -> 17600 bytes/sec
151  // UPLINK - DISTANCE 15000 -> MCS 6 -> Itbs 6 (from table 7.1.7.2.1-1 of 36.213)
152  // 1 user -> 25 PRB at Itbs 6 -> 233 -> 233000 bytes/sec
153  // 3 users -> 8 PRB at Itbs 6 -> 69 -> 69000 bytes/sec
154  // 6 users -> 4 PRB at Itbs 6 -> 32 -> 32000 bytes/sec
155  // 9 user -> 2 PRB at Itbs 6 -> 15 -> 15000 bytes/sec
156  // 12 users -> 2 PRB at Itbs 6 -> 15 -> 15000 bytes/sec
157  // 15 users -> 1 PRB at Itbs 6 -> 7 -> 7000 bytes/sec
158  AddTestCase (new LenaRrFfMacSchedulerTestCase (1,0,15000,309000,233000));
159  AddTestCase (new LenaRrFfMacSchedulerTestCase (3,0,15000,101000,69000));
160  AddTestCase (new LenaRrFfMacSchedulerTestCase (6,0,15000,49000,32000));
161  AddTestCase (new LenaRrFfMacSchedulerTestCase (9,0,15000,22000,15000));
162  AddTestCase (new LenaRrFfMacSchedulerTestCase (12,0,15000,22000,15000));
163  AddTestCase (new LenaRrFfMacSchedulerTestCase (15,0,15000,17600,7000));
164 
165 }
166 
168 
169 std::string
170 LenaRrFfMacSchedulerTestCase::BuildNameString (uint16_t nUser, uint16_t dist)
171 {
172  std::ostringstream oss;
173  oss << nUser << " UEs, distance " << dist << " m";
174  return oss.str ();
175 }
176 
177 LenaRrFfMacSchedulerTestCase::LenaRrFfMacSchedulerTestCase (uint16_t nUser, uint16_t nLc, uint16_t dist, double thrRefDl, double thrRefUl)
178  : TestCase (BuildNameString (nUser, dist)),
179  m_nUser (nUser),
180  m_nLc (nLc),
181  m_dist (dist),
182  m_thrRefDl (thrRefDl),
183  m_thrRefUl (thrRefUl)
184 {
185 }
186 
188 {
189 }
190 
191 void
193 {
194  Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (false));
195  Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (false)); Config::SetDefault ("ns3::LteAmc::AmcModel", EnumValue (LteAmc::PiroEW2010));
196  Config::SetDefault ("ns3::LteAmc::Ber", DoubleValue (0.00005));
197 
199  //LogComponentEnable ("LenaTestRrFfMacCheduler", LOG_LEVEL_ALL);
200 
206  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
207 
208  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::FriisSpectrumPropagationLossModel"));
209 
210  // Create Nodes: eNodeB and UE
211  NodeContainer enbNodes;
212  NodeContainer ueNodes;
213  enbNodes.Create (1);
214  ueNodes.Create (m_nUser);
215 
216  // Install Mobility Model
217  MobilityHelper mobility;
218  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
219  mobility.Install (enbNodes);
220  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
221  mobility.Install (ueNodes);
222 
223  // Create Devices and install them in the Nodes (eNB and UE)
224  NetDeviceContainer enbDevs;
225  NetDeviceContainer ueDevs;
226  lteHelper->SetSchedulerType ("ns3::RrFfMacScheduler");
227  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
228  ueDevs = lteHelper->InstallUeDevice (ueNodes);
229 
230  // Attach a UE to a eNB
231  lteHelper->Attach (ueDevs, enbDevs.Get (0));
232 
233  // Activate an EPS bearer
235  EpsBearer bearer (q);
236  lteHelper->ActivateEpsBearer (ueDevs, bearer, EpcTft::Default ());
237 
238 
239  Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ();
240  Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy ();
241  enbPhy->SetAttribute ("TxPower", DoubleValue (30.0));
242  enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0));
243 
244  // Set UEs' position and power
245  for (int i = 0; i < m_nUser; i++)
246  {
248  mm->SetPosition (Vector (m_dist, 0.0, 0.0));
249  Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (i)->GetObject<LteUeNetDevice> ();
250  Ptr<LteUePhy> uePhy = lteUeDev->GetPhy ();
251  uePhy->SetAttribute ("TxPower", DoubleValue (23.0));
252  uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0));
253  }
254 
255  lteHelper->EnableRlcTraces ();
256  double simulationTime = 0.4;
257  double tolerance = 0.1;
258  Simulator::Stop (Seconds (simulationTime));
259 
260  Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats ();
261  rlcStats->SetAttribute ("EpochDuration", TimeValue (Seconds (simulationTime)));
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  // get the lcId
276  uint8_t lcId = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetRrc ()->GetLcIdVector ().at (0);
277  dlDataRxed.push_back (rlcStats->GetDlRxData (imsi, lcId));
278  NS_LOG_INFO ("\tUser " << i << " imsi " << imsi << " lcid " << (uint16_t) lcId << " bytes rxed " << (double)dlDataRxed.at (i) << " thr " << (double)dlDataRxed.at (i) / simulationTime << " ref " << m_thrRefDl);
279  NS_TEST_ASSERT_MSG_EQ_TOL ((double)dlDataRxed.at (i) / simulationTime, m_thrRefDl, m_thrRefDl * tolerance, " Unfair Throughput!");
280  }
281 
282  NS_LOG_INFO ("UL - Test with " << m_nUser << " user(s) at distance " << m_dist);
283  std::vector <uint64_t> ulDataRxed;
284  for (int i = 0; i < m_nUser; i++)
285  {
286  // get the imsi
287  uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
288  // get the lcId
289  uint8_t lcId = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetRrc ()->GetLcIdVector ().at (0);
290  ulDataRxed.push_back (rlcStats->GetUlRxData (imsi, lcId));
291  NS_LOG_INFO ("\tUser " << i << " imsi " << imsi << " bytes txed " << (double)ulDataRxed.at (i) << " thr " << (double)ulDataRxed.at (i) / simulationTime << " ref " << m_thrRefUl << " txed " << rlcStats->GetUlTxData (imsi, lcId) / simulationTime);
292  NS_TEST_ASSERT_MSG_EQ_TOL ((double)ulDataRxed.at (i) / simulationTime, m_thrRefUl, m_thrRefUl * tolerance, " Unfair Throughput!");
293  }
294 
296 }
297 
298 
299 } // namespace ns3
300