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::PemEnabled", BooleanValue (false));
195  Config::SetDefault ("ns3::LteAmc::AmcModel", EnumValue (LteAmc::PiroEW2010));
196  Config::SetDefault ("ns3::LteAmc::Ber", DoubleValue (0.00005));
198 // LogComponentEnable ("LteEnbRrc", LOG_LEVEL_ALL);
199 // LogComponentEnable ("LteUeRrc", LOG_LEVEL_ALL);
200 // LogComponentEnable ("LteEnbMac", LOG_LEVEL_ALL);
201 // LogComponentEnable ("LteUeMac", LOG_LEVEL_ALL);
202 // LogComponentEnable ("LteRlc", LOG_LEVEL_ALL);
203 //
204 // LogComponentEnable ("LtePhy", LOG_LEVEL_ALL);
205 // LogComponentEnable ("LteEnbPhy", LOG_LEVEL_ALL);
206 // LogComponentEnable ("LteUePhy", LOG_LEVEL_ALL);
207 
208 // LogComponentEnable ("LteSpectrumPhy", LOG_LEVEL_ALL);
209 // LogComponentEnable ("LteInterference", LOG_LEVEL_ALL);
210 // LogComponentEnable ("LteSinrChunkProcessor", LOG_LEVEL_ALL);
211 //
212 // LogComponentEnable ("LtePropagationLossModel", LOG_LEVEL_ALL);
213 // LogComponentEnable ("LossModel", LOG_LEVEL_ALL);
214 // LogComponentEnable ("ShadowingLossModel", LOG_LEVEL_ALL);
215 // LogComponentEnable ("PenetrationLossModel", LOG_LEVEL_ALL);
216 // LogComponentEnable ("MultipathLossModel", LOG_LEVEL_ALL);
217 // LogComponentEnable ("PathLossModel", LOG_LEVEL_ALL);
218 //
219 // LogComponentEnable ("LteNetDevice", LOG_LEVEL_ALL);
220 // LogComponentEnable ("LteUeNetDevice", LOG_LEVEL_ALL);
221 // LogComponentEnable ("LteEnbNetDevice", LOG_LEVEL_ALL);
222 
223 // LogComponentEnable ("RrFfMacScheduler", LOG_LEVEL_ALL);
224  LogComponentEnable ("LenaTestRrFfMacCheduler", LOG_LEVEL_ALL);
225 // LogComponentEnable ("LteMiErrorModel", LOG_LEVEL_ALL);
226 // LogComponentEnable ("LenaHelper", LOG_LEVEL_ALL);
227 // LogComponentEnable ("LteSpectrumPhy", LOG_LEVEL_ALL);
228 
229 
235  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
236 
237  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::FriisSpectrumPropagationLossModel"));
238 
239  // Create Nodes: eNodeB and UE
240  NodeContainer enbNodes;
241  NodeContainer ueNodes;
242  enbNodes.Create (1);
243  ueNodes.Create (m_nUser);
244 
245  // Install Mobility Model
246  MobilityHelper mobility;
247  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
248  mobility.Install (enbNodes);
249  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
250  mobility.Install (ueNodes);
251 
252  // Create Devices and install them in the Nodes (eNB and UE)
253  NetDeviceContainer enbDevs;
254  NetDeviceContainer ueDevs;
255  lteHelper->SetSchedulerType ("ns3::RrFfMacScheduler");
256  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
257  ueDevs = lteHelper->InstallUeDevice (ueNodes);
258 
259  // Attach a UE to a eNB
260  lteHelper->Attach (ueDevs, enbDevs.Get (0));
261 
262  // Activate an EPS bearer
264  EpsBearer bearer (q);
265  lteHelper->ActivateEpsBearer (ueDevs, bearer, EpcTft::Default ());
266 
267 
268  Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ();
269  Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy ();
270  enbPhy->SetAttribute ("TxPower", DoubleValue (30.0));
271  enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0));
272 
273  // Set UEs' position and power
274  for (int i = 0; i < m_nUser; i++)
275  {
277  mm->SetPosition (Vector (m_dist, 0.0, 0.0));
278  Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (i)->GetObject<LteUeNetDevice> ();
279  Ptr<LteUePhy> uePhy = lteUeDev->GetPhy ();
280  uePhy->SetAttribute ("TxPower", DoubleValue (23.0));
281  uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0));
282  }
283 
284  lteHelper->EnableRlcTraces ();
285  double simulationTime = 0.4;
286  double tolerance = 0.1;
287  Simulator::Stop (Seconds (simulationTime));
288 
289  Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats ();
290  rlcStats->SetAttribute ("EpochDuration", TimeValue (Seconds (simulationTime)));
291 
292 
293  Simulator::Run ();
294 
298  NS_LOG_INFO ("DL - Test with " << m_nUser << " user(s) at distance " << m_dist);
299  std::vector <uint64_t> dlDataRxed;
300  for (int i = 0; i < m_nUser; i++)
301  {
302  // get the imsi
303  uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
304  // get the lcId
305  uint8_t lcId = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetRrc ()->GetLcIdVector ().at (0);
306  dlDataRxed.push_back (rlcStats->GetDlRxData (imsi, lcId));
307  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);
308  NS_TEST_ASSERT_MSG_EQ_TOL ((double)dlDataRxed.at (i) / simulationTime, m_thrRefDl, m_thrRefDl * tolerance, " Unfair Throughput!");
309  }
310 
311  NS_LOG_INFO ("UL - Test with " << m_nUser << " user(s) at distance " << m_dist);
312  std::vector <uint64_t> ulDataRxed;
313  for (int i = 0; i < m_nUser; i++)
314  {
315  // get the imsi
316  uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
317  // get the lcId
318  uint8_t lcId = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetRrc ()->GetLcIdVector ().at (0);
319  ulDataRxed.push_back (rlcStats->GetUlRxData (imsi, lcId));
320  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);
321  NS_TEST_ASSERT_MSG_EQ_TOL ((double)ulDataRxed.at (i) / simulationTime, m_thrRefUl, m_thrRefUl * tolerance, " Unfair Throughput!");
322  }
323 
325 }
326 
327 
328 } // namespace ns3
329