A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lte-test-tta-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 
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>
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 NS_LOG_COMPONENT_DEFINE ("LenaTestTtaFfMacCheduler");
55 
56 using namespace ns3;
57 
59  : TestSuite ("lte-tta-ff-mac-scheduler", SYSTEM)
60 {
61  NS_LOG_INFO ("creating LenaTestTtaFfMacSchedulerSuite");
62 
63  //Test Case : AMC works in TTA
64 
65  // DOWNLINK - DISTANCE 0 -> MCS 28 -> Itbs 26 (from table 7.1.7.2.1-1 of 36.213)
66  // 1 user -> 24 PRB at Itbs 26 -> 2196 -> 2196000 bytes/sec for first UE; 0 bytes/sec for other UEs
67  // 3 users -> 2196000 among 3 users -> 2196000 bytes/sec for first UE; 0 bytes/sec for other UEs
68  // 6 users -> 2196000 among 6 users -> 2196000 bytes/sec for first UE; 0 bytes/sec for other UEs
69  // 12 users -> 2196000 among 12 users -> 2196000 bytes/sec for first UE; 0 bytes/sec for other UEs
70  // 15 users -> 2196000 among 15 users -> 2196000 bytes/sec for first UE; 0 bytes/sec for other UEs
71  // UPLINK- DISTANCE 0 -> MCS 28 -> Itbs 26 (from table 7.1.7.2.1-1 of 36.213)
72  // 1 user -> 25 PRB at Itbs 26 -> 2292 -> 2292000 bytes/sec
73  // 3 users -> 8 PRB at Itbs 26 -> 749 -> 749000 bytes/sec
74  // 6 users -> 4 PRB at Itbs 26 -> 373 -> 373000 bytes/sec
75  // 12 users -> 2 PRB at Itbs 26 -> 185 -> 185000 bytes/sec
76  // 15 users -> 1 PRB at Itbs 26 -> 89 -> 89000 bytes/sec
77  AddTestCase (new LenaTtaFfMacSchedulerTestCase (1,0,0,2196000,2292000));
78  AddTestCase (new LenaTtaFfMacSchedulerTestCase (3,0,0,2196000,749000));
79  AddTestCase (new LenaTtaFfMacSchedulerTestCase (6,0,0,2196000,373000));
80  AddTestCase (new LenaTtaFfMacSchedulerTestCase (12,0,0,2196000,185000));
81  AddTestCase (new LenaTtaFfMacSchedulerTestCase (15,0,0,2196000,89000));
82 
83  // DOWNLINK - DISTANCE 3000 -> MCS 24 -> Itbs 30 (from table 7.1.7.2.1-1 of 36.213)
84  // 1 user -> 24 PRB at Itbs 20 -> 1383 -> 1383000 bytes/sec for first UE; 0 bytes/sec for other UEs
85  // 3 users -> 1383000 among 3 users -> 1383000 bytes/sec for first UE; 0 bytes/sec for other UEs
86  // 6 users -> 1383000 among 6 users -> 1383000 bytes/sec for first UE; 0 bytes/sec for other UEs
87  // 12 users -> 1383000 among 12 users -> 1383000 bytes/sec for first UE; 0 bytes/sec for other UEs
88  // 15 users -> 1383000 among 15 users -> 1383000 bytes/sec for first UE; 0 bytes/sec for other UEs
89  // UPLINK - DISTANCE 3000 -> MCS 20 -> Itbs 18 (from table 7.1.7.2.1-1 of 36.213)
90  // 1 user -> 25 PRB at Itbs 18 -> 1239 -> 1239000 bytes/sec
91  // 3 users -> 8 PRB at Itbs 18 -> 389 -> 389000 bytes/sec
92  // 6 users -> 4 PRB at Itbs 18 -> 193 -> 193000 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 LenaTtaFfMacSchedulerTestCase (1,0,3000,1383000,1239000));
96  AddTestCase (new LenaTtaFfMacSchedulerTestCase (3,0,3000,1383000,389000));
97  AddTestCase (new LenaTtaFfMacSchedulerTestCase (6,0,3000,1383000,193000));
98  AddTestCase (new LenaTtaFfMacSchedulerTestCase (12,0,3000,1383000,97000));
99  AddTestCase (new LenaTtaFfMacSchedulerTestCase (15,0,3000,1383000,47000));
100 
101  // DOWNLINK - DISTANCE 6000 -> MCS 16 -> Itbs 15 (from table 7.1.7.2.1-1 of 36.213)
102  // 1 user -> 24 PRB at Itbs 15 -> 903 -> 903000 bytes/sec for first UE; 0 bytes/sec for other UEs
103  // 3 users -> 903000 among 3 users -> 903000 bytes/sec for first UE; 0 bytes/sec for other UEs
104  // 6 users -> 903000 among 6 users -> 903000 bytes/sec for first UE; 0 bytes/sec for other UEs
105  // 12 users -> 903000 among 12 users -> 903000 bytes/sec for first UE; 0 bytes/sec for other UEs
106  // 15 users -> 903000 among 15 users -> 903000 bytes/sec for first UE; 0 bytes/sec for other UEs
107  // UPLINK - DISTANCE 6000 -> MCS 12 -> Itbs 11 (from table 7.1.7.2.1-1 of 36.213)
108  // 1 user -> 25 PRB at Itbs 11 -> 621 -> 621000 bytes/sec
109  // 3 users -> 8 PRB at Itbs 11 -> 201 -> 201000 bytes/sec
110  // 6 users -> 4 PRB at Itbs 11 -> 97 -> 97000 bytes/sec
111  // 12 users -> 2 PRB at Itbs 11 -> 47 -> 47000 bytes/sec
112  // 15 users -> 1 PRB at Itbs 11 -> 22 -> 22000 bytes/sec
113  AddTestCase (new LenaTtaFfMacSchedulerTestCase (1,0,6000,903000,621000));
114  AddTestCase (new LenaTtaFfMacSchedulerTestCase (3,0,6000,903000,201000));
115  AddTestCase (new LenaTtaFfMacSchedulerTestCase (6,0,6000,903000,97000));
116  AddTestCase (new LenaTtaFfMacSchedulerTestCase (12,0,6000,903000,47000));
117  AddTestCase (new LenaTtaFfMacSchedulerTestCase (15,0,6000,903000,22000));
118 
119  // DOWNLINK - DISTANCE 9000 -> MCS 12 -> Itbs 11 (from table 7.1.7.2.1-1 of 36.213)
120  // 1 user -> 24 PRB at Itbs 11 -> 597 -> 597000 bytes/sec
121  // 3 users -> 597000 among 3 users -> 199000 bytes/sec
122  // 6 users -> 597000 among 6 users -> 99500 bytes/sec
123  // 12 users -> 597000 among 12 users -> 49750 bytes/sec
124  // 15 users -> 597000 among 15 users -> 39800 bytes/sec
125  // UPLINK - DISTANCE 9000 -> MCS 8 -> Itbs 8 (from table 7.1.7.2.1-1 of 36.213)
126  // 1 user -> 24 PRB at Itbs 8 -> 437 -> 437000 bytes/sec
127  // 3 users -> 8 PRB at Itbs 8 -> 137 -> 137000 bytes/sec
128  // 6 users -> 4 PRB at Itbs 8 -> 67 -> 67000 bytes/sec
129  // 12 users -> 2 PRB at Itbs 8 -> 32 -> 32000 bytes/sec
130  // 15 users -> 1 PRB at Itbs 8 -> 15 -> 15000 bytes/sec
131  AddTestCase (new LenaTtaFfMacSchedulerTestCase (1,0,9000,597000,437000));
132  AddTestCase (new LenaTtaFfMacSchedulerTestCase (3,0,9000,597000,137000));
133  AddTestCase (new LenaTtaFfMacSchedulerTestCase (6,0,9000,597000,67000));
134  AddTestCase (new LenaTtaFfMacSchedulerTestCase (12,0,9000,597000,32000));
135  AddTestCase (new LenaTtaFfMacSchedulerTestCase (15,0,9000,597000,15000));
136 
137  // DONWLINK - DISTANCE 15000 -> MCS 6 -> Itbs 6 (from table 7.1.7.2.1-1 of 36.213)
138  // 1 user -> 24 PRB at Itbs 6 -> 309 -> 309000 bytes/sec
139  // 3 users -> 309000 among 3 users -> 103000 bytes/sec
140  // 6 users -> 309000 among 6 users -> 51500 bytes/sec
141  // 12 users -> 309000 among 12 users -> 25750 bytes/sec
142  // 15 users -> 309000 among 15 users -> 20600 bytes/sec
143  // UPLINK - DISTANCE 15000 -> MCS 6 -> Itbs 6 (from table 7.1.7.2.1-1 of 36.213)
144  // 1 user -> 25 PRB at Itbs 6 -> 233 -> 233000 bytes/sec
145  // 3 users -> 8 PRB at Itbs 6 -> 69 -> 69000 bytes/sec
146  // 6 users -> 4 PRB at Itbs 6 -> 32 -> 32000 bytes/sec
147  // 12 users -> 2 PRB at Itbs 6 -> 15 -> 15000 bytes/sec
148  // 15 users -> 1 PRB at Itbs 6 -> 7 -> 7000 bytes/sec
149  AddTestCase (new LenaTtaFfMacSchedulerTestCase (1,0,15000,309000,233000));
150  AddTestCase (new LenaTtaFfMacSchedulerTestCase (3,0,15000,309000,69000));
151  AddTestCase (new LenaTtaFfMacSchedulerTestCase (6,0,15000,309000,32000));
152  AddTestCase (new LenaTtaFfMacSchedulerTestCase (12,0,15000,309000,15000));
153  AddTestCase (new LenaTtaFfMacSchedulerTestCase (15,0,15000,309000,7000));
154 
155 
156 }
157 
159 
160 
161 // --------------- T E S T - C A S E ------------------------------
162 
163 
164 std::string
165 LenaTtaFfMacSchedulerTestCase::BuildNameString (uint16_t nUser, uint16_t dist)
166 {
167  std::ostringstream oss;
168  oss << nUser << " UEs, distance " << dist << " m";
169  return oss.str ();
170 }
171 
172 LenaTtaFfMacSchedulerTestCase::LenaTtaFfMacSchedulerTestCase (uint16_t nUser, uint16_t nLc, uint16_t dist, double thrRefDl, double thrRefUl)
173  : TestCase (BuildNameString (nUser, dist)),
174  m_nUser (nUser),
175  m_nLc (nLc),
176  m_dist (dist),
177  m_thrRefDl (thrRefDl),
178  m_thrRefUl (thrRefUl)
179 {
180 }
181 
183 {
184 }
185 
186 void
188 {
189  Config::SetDefault ("ns3::LteAmc::AmcModel", EnumValue (LteAmc::PiroEW2010));
190  Config::SetDefault ("ns3::LteAmc::Ber", DoubleValue (0.00005));
191  Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (false));
192  Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (false));
193 
195  //LogComponentEnable ("LenaTestTtaFfMacCheduler", LOG_LEVEL_ALL);
196 
201  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
202 
203  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::FriisSpectrumPropagationLossModel"));
204 
205  // Create Nodes: eNodeB and UE
206  NodeContainer enbNodes;
207  NodeContainer ueNodes;
208  enbNodes.Create (1);
209  ueNodes.Create (m_nUser);
210 
211  // Install Mobility Model
212  MobilityHelper mobility;
213  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
214  mobility.Install (enbNodes);
215  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
216  mobility.Install (ueNodes);
217 
218  // Create Devices and install them in the Nodes (eNB and UE)
219  NetDeviceContainer enbDevs;
220  NetDeviceContainer ueDevs;
221  lteHelper->SetSchedulerType ("ns3::TtaFfMacScheduler");
222  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
223  ueDevs = lteHelper->InstallUeDevice (ueNodes);
224 
225  // Attach a UE to a eNB
226  lteHelper->Attach (ueDevs, enbDevs.Get (0));
227 
228  // Activate an EPS bearer
229  enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE;
230  EpsBearer bearer (q);
231  lteHelper->ActivateEpsBearer (ueDevs, bearer, EpcTft::Default ());
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  lteHelper->EnableRlcTraces ();
250 
251  double simulationTime = 1.0;
252  double tolerance = 0.1;
253  Simulator::Stop (Seconds (simulationTime));
254 
255  Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats ();
256  rlcStats->SetAttribute ("EpochDuration", TimeValue (Seconds (simulationTime)));
257 
258  Simulator::Run ();
259 
263  NS_LOG_INFO ("DL - Test with " << m_nUser << " user(s) at distance " << m_dist);
264  std::vector <uint64_t> dlDataRxed;
265  for (int i = 0; i < m_nUser; i++)
266  {
267  // get the imsi
268  uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
269  // get the lcId
270  uint8_t lcId = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetRrc ()->GetLcIdVector ().at (0);
271  dlDataRxed.push_back (rlcStats->GetDlRxData (imsi, lcId));
272  NS_LOG_INFO ("\tUser " << i << " imsi " << imsi << " bytes rxed " << (double)dlDataRxed.at (i) << " thr " << (double)dlDataRxed.at (i) / simulationTime << " ref " << m_thrRefDl);
273  }
278  for (int i = 0; i < 1; i++)
279  {
280  if (i == 0)
281  {
282  NS_TEST_ASSERT_MSG_EQ_TOL ((double)dlDataRxed.at (i) / simulationTime, m_thrRefDl, m_thrRefDl * tolerance, " Invalid Throughput!");
283  }
284  else
285  {
286  NS_TEST_ASSERT_MSG_EQ_TOL ((double)dlDataRxed.at (i) / simulationTime, 0, tolerance, " Invalid Throughput!");
287  }
288  }
289 
293  NS_LOG_INFO ("UL - Test with " << m_nUser << " user(s) at distance " << m_dist);
294  std::vector <uint64_t> ulDataRxed;
295  for (int i = 0; i < m_nUser; i++)
296  {
297  // get the imsi
298  uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
299  // get the lcId
300  uint8_t lcId = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetRrc ()->GetLcIdVector ().at (0);
301  ulDataRxed.push_back (rlcStats->GetUlRxData (imsi, lcId));
302  NS_LOG_INFO ("\tUser " << i << " imsi " << imsi << " bytes rxed " << (double)ulDataRxed.at (i) << " thr " << (double)ulDataRxed.at (i) / simulationTime << " ref " << m_thrRefUl);
303  }
311  for (int i = 0; i < 1; i++)
312  {
313  NS_TEST_ASSERT_MSG_EQ_TOL ((double)ulDataRxed.at (i) / simulationTime, m_thrRefUl, m_thrRefUl * tolerance, " Unfair Throughput!");
314  }
315  Simulator::Destroy ();
316 
317 }
318