A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lte-test-pss-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>
37 #include <ns3/eps-bearer.h>
38 #include <ns3/node-container.h>
39 #include <ns3/mobility-helper.h>
40 #include <ns3/net-device-container.h>
41 #include <ns3/lte-ue-net-device.h>
42 #include <ns3/lte-enb-net-device.h>
43 #include <ns3/lte-ue-rrc.h>
44 #include <ns3/lte-helper.h>
45 #include "ns3/string.h"
46 #include "ns3/double.h"
47 #include <ns3/lte-enb-phy.h>
48 #include <ns3/lte-ue-phy.h>
49 #include <ns3/boolean.h>
50 #include <ns3/enum.h>
51 
52 #include "ns3/epc-helper.h"
53 #include "ns3/network-module.h"
54 #include "ns3/ipv4-global-routing-helper.h"
55 #include "ns3/internet-module.h"
56 #include "ns3/applications-module.h"
57 #include "ns3/point-to-point-helper.h"
58 
60 
61 NS_LOG_COMPONENT_DEFINE ("LenaTestPssFfMacScheduler");
62 
63 namespace ns3 {
64 
66  : TestSuite ("lte-pss-ff-mac-scheduler", SYSTEM)
67 {
68  NS_LOG_INFO ("creating LenaTestPssFfMacSchedulerSuite");
69 
70  bool errorModel = false;
71 
72  // General config
73  // Traffic: UDP traffic with fixed rate
74  // Token generation rate = traffic rate
75  // RLC header length = 2 bytes, PDCP header = 2 bytes
76  // Simulation time = 1.0 sec
77  // Throughput in this file is calculated in RLC layer
78 
79  //Test Case 1: homogeneous flow test in PSS (same distance)
80  // DOWNLINK -> DISTANCE 0 -> MCS 28 -> Itbs 26 (from table 7.1.7.2.1-1 of 36.2 13)
81  // Traffic info
82  // UDP traffic: payload size = 200 bytes, interval = 1 ms
83  // UDP rate in scheduler: (payload + RLC header + PDCP header + IP header + UDP header) * 1000 byte/sec -> 232000 byte/rate
84  // Totol bandwidth: 24 PRB at Itbs 26 -> 2196 -> 2196000 byte/sec
85  // 1 user -> 232000 * 1 = 232000 < 2196000 -> throughput = 232000 byte/sec
86  // 3 user -> 232000 * 3 = 696000 < 2196000 -> througphut = 232000 byte/sec
87  // 6 user -> 232000 * 6 = 139200 < 2196000 -> throughput = 232000 byte/sec
88  // 12 user -> 232000 * 12 = 2784000 > 2196000 -> throughput = 2196000 / 12 = 183000 byte/sec
89  // UPLINK -> DISTANCE 0 -> MCS 28 -> Itbs 26 (from table 7.1.7.2.1-1 of 36.2 13)
90  // 1 user -> 25 PRB at Itbs 26 -> 2292 -> 2292000 > 232000 -> throughput = 232000 bytes/sec
91  // 3 users -> 8 PRB at Itbs 26 -> 749 -> 749000 > 232000 -> throughput = 232000 bytes/sec
92  // 6 users -> 4 PRB at Itbs 26 -> 373 -> 373000 > 232000 -> throughput = 232000 bytes/sec
93  // 12 users -> 2 PRB at Itbs 26 -> 185 -> 185000 < 232000 -> throughput = 185000 bytes/sec
94  AddTestCase (new LenaPssFfMacSchedulerTestCase1 (1,0,0,232000,232000,200,1,errorModel), TestCase::EXTENSIVE);
95  AddTestCase (new LenaPssFfMacSchedulerTestCase1 (3,0,0,232000,232000,200,1,errorModel), TestCase::EXTENSIVE);
96  AddTestCase (new LenaPssFfMacSchedulerTestCase1 (6,0,0,232000,232000,200,1,errorModel), TestCase::EXTENSIVE);
97 
98  //AddTestCase (new LenaPssFfMacSchedulerTestCase1 (12,0,0,183000,185000,200,1,errorModel));// simulation time = 1.5, otherwise, ul test will fail
99 
100  // DOWNLINK - DISTANCE 4800 -> MCS 22 -> Itbs 20 (from table 7.1.7.2.1-1 of 36.213)
101  // Traffic info
102  // UDP traffic: payload size = 200 bytes, interval = 1 ms
103  // UDP rate in scheduler: (payload + RLC header + PDCP header + IP header + UDP header) * 1000 byte/sec -> 232000 byte/rate
104  // Totol bandwidth: 24 PRB at Itbs 20 -> 1383 -> 1383000 byte/sec
105  // 1 user -> 903000 * 1 = 232000 < 1383000 -> throughput = 232000 byte/sec
106  // 3 user -> 232000 * 3 = 696000 < 1383000 -> througphut = 232000 byte/sec
107  // 6 user -> 232000 * 6 = 139200 > 1383000 -> throughput = 1383000 / 6 = 230500 byte/sec
108  // 12 user -> 232000 * 12 = 2784000 > 1383000 -> throughput = 1383000 / 12 = 115250 byte/sec
109  // UPLINK - DISTANCE 4800 -> MCS 14 -> Itbs 13 (from table 7.1.7.2.1-1 of 36.213)
110  // 1 user -> 25 PRB at Itbs 13 -> 807 -> 807000 > 232000 -> throughput = 232000 bytes/sec
111  // 3 users -> 8 PRB at Itbs 13 -> 253 -> 253000 > 232000 -> throughput = 232000 bytes/sec
112  // 6 users -> 4 PRB at Itbs 13 -> 125 -> 125000 < 232000 -> throughput = 125000 bytes/sec
113  // after the patch enforcing min 3 PRBs per UE:
114  // 12 users -> 3 PRB at Itbs 13 -> 93 bytes * 8/12 UE/TTI -> 62000 < 232000 -> throughput = 62000 bytes/sec
115  AddTestCase (new LenaPssFfMacSchedulerTestCase1 (1,0,4800,232000,232000,200,1,errorModel), TestCase::EXTENSIVE);
116  AddTestCase (new LenaPssFfMacSchedulerTestCase1 (3,0,4800,232000,232000,200,1,errorModel), TestCase::EXTENSIVE);
117  AddTestCase (new LenaPssFfMacSchedulerTestCase1 (6,0,4800,230500,125000,200,1,errorModel), TestCase::EXTENSIVE);
118  //AddTestCase (new LenaPssFfMacSchedulerTestCase1 (12,0,4800,115250,62000,200,1,errorModel)); // simulation time = 1.5, otherwise, ul test will fail
119 
120  // DOWNLINK - DISTANCE 6000 -> MCS 20 -> Itbs 18 (from table 7.1.7.2.1-1 of 36.213)
121  // Traffic info
122  // UDP traffic: payload size = 200 bytes, interval = 1 ms
123  // UDP rate in scheduler: (payload + RLC header + PDCP header + IP header + UDP header) * 1000 byte/sec -> 232000 byte/rate
124  // Totol bandwidth: 24 PRB at Itbs 18 -> 1191 -> 1191000 byte/sec
125  // 1 user -> 903000 * 1 = 232000 < 1191000 -> throughput = 232000 byte/sec
126  // 3 user -> 232000 * 3 = 696000 < 1191000 -> througphut = 232000 byte/sec
127  // 6 user -> 232000 * 6 = 1392000 > 1191000 -> throughput = 1191000 / 6 = 198500 byte/sec
128  // 12 user -> 232000 * 12 = 2784000 > 1191000 -> throughput = 1191000 / 12 = 99250 byte/sec
129 
130  // UPLINK - DISTANCE 6000 -> MCS 12 -> Itbs 11 (from table 7.1.7.2.1-1 of 36.213)
131  // 1 user -> 25 PRB at Itbs 11 -> 621 -> 621000 > 232000 -> throughput = 232000 bytes/sec
132  // 3 users -> 8 PRB at Itbs 11 -> 201 -> 201000 < 232000 -> throughput = 201000 bytes/sec
133  // 6 users -> 4 PRB at Itbs 11 -> 97 -> 97000 < 232000 -> throughput = 97000 bytes/sec
134  // after the patch enforcing min 3 PRBs per UE:
135  // 12 users -> 3 PRB at Itbs 11 -> 73 bytes * 8/12 UE/TTI -> 48667 < 232000 -> throughput = 48667 bytes/sec
136  AddTestCase (new LenaPssFfMacSchedulerTestCase1 (1,0,6000,232000,232000,200,1,errorModel), TestCase::EXTENSIVE);
137  AddTestCase (new LenaPssFfMacSchedulerTestCase1 (3,0,6000,232000,201000,200,1,errorModel), TestCase::EXTENSIVE);
138  AddTestCase (new LenaPssFfMacSchedulerTestCase1 (6,0,6000,198500,97000,200,1,errorModel), TestCase::EXTENSIVE);
139  //AddTestCase (new LenaPssFfMacSchedulerTestCase1 (12,0,6000,99250,48667,200,1, errorModel)); // simulation time = 1.5, otherwise, ul test will fail
140 
141  // DOWNLINK - DISTANCE 10000 -> MCS 14 -> Itbs 13 (from table 7.1.7.2.1-1 of 36.213)
142  // Traffic info
143  // UDP traffic: payload size = 200 bytes, interval = 1 ms
144  // UDP rate in scheduler: (payload + RLC header + PDCP header + IP header + UDP header) * 1000 byte/sec -> 232000 byte/rate
145  // Totol bandwidth: 24 PRB at Itbs 13 -> 775 -> 775000 byte/sec
146  // 1 user -> 903000 * 1 = 232000 < 775000 -> throughput = 232000 byte/sec
147  // 3 user -> 232000 * 3 = 696000 > 775000 -> througphut = 232000 byte/sec
148  // 6 user -> 232000 * 6 = 139200 > 775000 -> throughput = 775000 / 6 = 129166 byte/sec
149  // 12 user -> 232000 * 12 = 2784000 > 775000 -> throughput = 775000 / 12 = 64583 byte/sec
150  // UPLINK - DISTANCE 10000 -> MCS 8 -> Itbs 8 (from table 7.1.7.2.1-1 of 36.213)
151  // 1 user -> 24 PRB at Itbs 8 -> 437 -> 437000 > 232000 -> throughput = 232000 bytes/sec
152  // 3 users -> 8 PRB at Itbs 8 -> 137 -> 137000 < 232000 -> throughput = 137000 bytes/sec
153  // 6 users -> 4 PRB at Itbs 8 -> 67 -> 67000 < 232000 -> throughput = 67000 bytes/sec
154  // after the patch enforcing min 3 PRBs per UE:
155  // 12 users -> 3 PRB at Itbs 8 -> 49 bytes * 8/12 UE/TTI -> 32667 < 232000 -> throughput = 32667 bytes/sec
156  AddTestCase (new LenaPssFfMacSchedulerTestCase1 (1,0,10000,232000,232000,200,1,errorModel), TestCase::EXTENSIVE);
157  AddTestCase (new LenaPssFfMacSchedulerTestCase1 (3,0,10000,232000,137000,200,1,errorModel), TestCase::EXTENSIVE);
158  AddTestCase (new LenaPssFfMacSchedulerTestCase1 (6,0,10000,129166,67000,200,1,errorModel), TestCase::EXTENSIVE);
159  //AddTestCase (new LenaPssFfMacSchedulerTestCase1 (12,0,10000,64583,32667,200,1,errorModel));// simulation time = 1.5, otherwise, ul test will fail
160 
161  // Test Case 2: homogeneous flow test in PSS (different distance)
162  // Traffic1 info
163  // UDP traffic: payload size = 100 bytes, interval = 1 ms
164  // UDP rate in scheduler: (payload + RLC header + PDCP header + IP header + UDP header) * 1000 byte/sec -> 132000 byte/rate
165  // Maximum throughput = 4 / ( 1/2196000 + 1/1191000 + 1/1383000 + 1/775000 ) = 1209046 byte/s
166  // 132000 * 4 = 528000 < 1209046 -> estimated throughput in downlink = 132000 byte/sec
167  std::vector<uint16_t> dist1;
168  dist1.push_back (0); // User 0 distance --> MCS 28
169  dist1.push_back (4800); // User 1 distance --> MCS 22
170  dist1.push_back (6000); // User 2 distance --> MCS 20
171  dist1.push_back (10000); // User 3 distance --> MCS 14
172  std::vector<uint16_t> packetSize1;
173  packetSize1.push_back (100);
174  packetSize1.push_back (100);
175  packetSize1.push_back (100);
176  packetSize1.push_back (100);
177  std::vector<uint32_t> estThrPssDl1;
178  estThrPssDl1.push_back (132000); // User 0 estimated TTI throughput from PSS
179  estThrPssDl1.push_back (132000); // User 1 estimated TTI throughput from PSS
180  estThrPssDl1.push_back (132000); // User 2 estimated TTI throughput from PSS
181  estThrPssDl1.push_back (132000); // User 3 estimated TTI throughput from PSS
182  AddTestCase (new LenaPssFfMacSchedulerTestCase2 (dist1,estThrPssDl1,packetSize1,1,errorModel), TestCase::QUICK);
183 
184  // Traffic2 info
185  // UDP traffic: payload size = 200 bytes, interval = 1 ms
186  // UDP rate in scheduler: (payload + RLC header + PDCP header + IP header + UDP header) * 1000 byte/sec -> 232000 byte/rate
187  // Maximum throughput = 4 / ( 1/2196000 + 1/1191000 + 1/1383000 + 1/775000 ) = 1209046 byte/s
188  // 232000 * 4 = 928000 < 1209046 -> estimated throughput in downlink = 928000 / 4 = 230000 byte/sec
189  std::vector<uint16_t> dist2;
190  dist2.push_back (0); // User 0 distance --> MCS 28
191  dist2.push_back (4800); // User 1 distance --> MCS 22
192  dist2.push_back (6000); // User 2 distance --> MCS 20
193  dist2.push_back (10000); // User 3 distance --> MCS 14
194  std::vector<uint16_t> packetSize2;
195  packetSize2.push_back (200);
196  packetSize2.push_back (200);
197  packetSize2.push_back (200);
198  packetSize2.push_back (200);
199  std::vector<uint32_t> estThrPssDl2;
200  estThrPssDl2.push_back (230000); // User 0 estimated TTI throughput from PSS
201  estThrPssDl2.push_back (230000); // User 1 estimated TTI throughput from PSS
202  estThrPssDl2.push_back (230000); // User 2 estimated TTI throughput from PSS
203  estThrPssDl2.push_back (230000); // User 3 estimated TTI throughput from PSS
204  AddTestCase (new LenaPssFfMacSchedulerTestCase2 (dist2,estThrPssDl2,packetSize2,1,errorModel), TestCase::QUICK);
205 
206  // Test Case 3: heterogeneous flow test in PSS
207  // UDP traffic: payload size = [100,200,300] bytes, interval = 1 ms
208  // UDP rate in scheduler: (payload + RLC header + PDCP header + IP header + UDP header) * 1000 byte/sec -> [132000, 232000, 332000] byte/rate
209  // Maximum throughput = 3 / ( 1/2196000 + 1/1191000 + 1/1383000) = 1486569 byte/s
210  // 132000 + 232000 + 332000 = 696000 < 1486569 -> estimated throughput in downlink = [132000, 232000, 332000] byte/sec
211  std::vector<uint16_t> dist3;
212  dist3.push_back (0); // User 0 distance --> MCS 28
213  dist3.push_back (4800); // User 1 distance --> MCS 22
214  dist3.push_back (6000); // User 2 distance --> MCS 20
215  std::vector<uint16_t> packetSize3;
216  packetSize3.push_back (100);
217  packetSize3.push_back (200);
218  packetSize3.push_back (300);
219  std::vector<uint32_t> estThrPssDl3;
220  estThrPssDl3.push_back (132000); // User 0 estimated TTI throughput from PSS
221  estThrPssDl3.push_back (232000); // User 1 estimated TTI throughput from PSS
222  estThrPssDl3.push_back (332000); // User 2 estimated TTI throughput from PSS
223  AddTestCase (new LenaPssFfMacSchedulerTestCase2 (dist3,estThrPssDl3,packetSize3,1,errorModel), TestCase::QUICK);
224 
225 }
226 
228 
229 // --------------- T E S T - C A S E # 1 ------------------------------
230 
231 
232 std::string
233 LenaPssFfMacSchedulerTestCase1::BuildNameString (uint16_t nUser, uint16_t dist)
234 {
235  std::ostringstream oss;
236  oss << nUser << " UEs, distance " << dist << " m";
237  return oss.str ();
238 }
239 
240 
241 LenaPssFfMacSchedulerTestCase1::LenaPssFfMacSchedulerTestCase1 (uint16_t nUser, uint16_t nLc, uint16_t dist, double thrRefDl, double thrRefUl, uint16_t packetSize, uint16_t interval,bool errorModelEnabled)
242  : TestCase (BuildNameString (nUser, dist)),
243  m_nUser (nUser),
244  m_nLc (nLc),
245  m_dist (dist),
246  m_packetSize (packetSize),
247  m_interval (interval),
248  m_thrRefDl (thrRefDl),
249  m_thrRefUl (thrRefUl),
250  m_errorModelEnabled (errorModelEnabled)
251 {
252 }
253 
255 {
256 }
257 
258 void
260 {
261  NS_LOG_FUNCTION (this << GetName ());
262 
263  if (!m_errorModelEnabled)
264  {
265  Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (false));
266  Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (false));
267  }
268 
269  Config::SetDefault ("ns3::LteHelper::UseIdealRrc", BooleanValue (true));
270 
271  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
272  Ptr<EpcHelper> epcHelper = CreateObject<EpcHelper> ();
273  lteHelper->SetEpcHelper (epcHelper);
274 
275  //LogComponentEnable ("PssFfMacScheduler", LOG_DEBUG);
276 
277  Ptr<Node> pgw = epcHelper->GetPgwNode ();
278 
279  // Create a single RemoteHost
280  NodeContainer remoteHostContainer;
281  remoteHostContainer.Create (1);
282  Ptr<Node> remoteHost = remoteHostContainer.Get (0);
283  InternetStackHelper internet;
284  internet.Install (remoteHostContainer);
285 
286  // Create the Internet
287  PointToPointHelper p2ph;
288  p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
289  p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500));
290  p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.001)));
291  NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
292  Ipv4AddressHelper ipv4h;
293  ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
294  Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices);
295  // interface 0 is localhost, 1 is the p2p device
296  Ipv4Address remoteHostAddr = internetIpIfaces.GetAddress (1);
297 
298  Ipv4StaticRoutingHelper ipv4RoutingHelper;
299  Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
300  remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1);
301 
302  //Config::SetDefault ("ns3::LteAmc::AmcModel", EnumValue (LteAmc::PiroEW2010));
303  //Config::SetDefault ("ns3::LteAmc::Ber", DoubleValue (0.00005));
304  //Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (false));
305  //Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (false));
306 
307  //Config::SetDefault ("ns3::LteEnbRrc::EpsBearerToRlcMapping", EnumValue (LteHelper::RLC_UM_ALWAYS));
308 
309 // LogComponentDisableAll (LOG_LEVEL_ALL);
310  //LogComponentEnable ("LenaTestPssFfMacCheduler", LOG_LEVEL_ALL);
311 
312  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::FriisSpectrumPropagationLossModel"));
313 
314  // Create Nodes: eNodeB and UE
315  NodeContainer enbNodes;
316  NodeContainer ueNodes;
317  enbNodes.Create (1);
318  ueNodes.Create (m_nUser);
319 
320  // Install Mobility Model
321  MobilityHelper mobility;
322  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
323  mobility.Install (enbNodes);
324  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
325  mobility.Install (ueNodes);
326 
327  // Create Devices and install them in the Nodes (eNB and UE)
328  NetDeviceContainer enbDevs;
329  NetDeviceContainer ueDevs;
330  lteHelper->SetSchedulerType ("ns3::PssFfMacScheduler");
331  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
332  ueDevs = lteHelper->InstallUeDevice (ueNodes);
333 
334 
335  Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ();
336  Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy ();
337  enbPhy->SetAttribute ("TxPower", DoubleValue (30.0));
338  enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0));
339 
340  // Set UEs' position and power
341  for (int i = 0; i < m_nUser; i++)
342  {
344  mm->SetPosition (Vector (m_dist, 0.0, 0.0));
345  Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (i)->GetObject<LteUeNetDevice> ();
346  Ptr<LteUePhy> uePhy = lteUeDev->GetPhy ();
347  uePhy->SetAttribute ("TxPower", DoubleValue (23.0));
348  uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0));
349  }
350 
351  // Install the IP stack on the UEs
352  internet.Install (ueNodes);
353  Ipv4InterfaceContainer ueIpIface;
354  ueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueDevs));
355 
356  // Assign IP address to UEs
357  for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
358  {
359  Ptr<Node> ueNode = ueNodes.Get (u);
360  // Set the default gateway for the UE
361  Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv4> ());
362  ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1);
363  }
364 
365  // Attach a UE to a eNB
366  lteHelper->Attach (ueDevs, enbDevs.Get (0));
367 
368  // Activate an EPS bearer on all UEs
369  for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
370  {
371  Ptr<NetDevice> ueDevice = ueDevs.Get (u);
372  GbrQosInformation qos;
373  qos.gbrDl = (m_packetSize + 32) * (1000 / m_interval) * 8; // bit/s, considering IP, UDP, RLC, PDCP header size
374  qos.gbrUl = (m_packetSize + 32) * (1000 / m_interval) * 8;
375  qos.mbrDl = 0;
376  qos.mbrUl = 0;
377 
379  EpsBearer bearer (q, qos);
380  lteHelper->ActivateDedicatedEpsBearer (ueDevice, bearer, EpcTft::Default ());
381  }
382 
383  // Install downlind and uplink applications
384  uint16_t dlPort = 1234;
385  uint16_t ulPort = 2000;
386  PacketSinkHelper dlPacketSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), dlPort));
387  PacketSinkHelper ulPacketSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), ulPort));
390  for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
391  {
392  ++ulPort;
393  serverApps.Add (dlPacketSinkHelper.Install (ueNodes.Get (u))); // receive packets from remotehost
394  serverApps.Add (ulPacketSinkHelper.Install (remoteHost)); // receive packets from UEs
395 
396  UdpClientHelper dlClient (ueIpIface.GetAddress (u), dlPort); // uplink packets generator
397  dlClient.SetAttribute ("Interval", TimeValue (MilliSeconds (m_interval)));
398  dlClient.SetAttribute ("MaxPackets", UintegerValue (1000000));
399  dlClient.SetAttribute ("PacketSize", UintegerValue (m_packetSize));
400 
401  UdpClientHelper ulClient (remoteHostAddr, ulPort); // downlink packets generator
402  ulClient.SetAttribute ("Interval", TimeValue (MilliSeconds (m_interval)));
403  ulClient.SetAttribute ("MaxPackets", UintegerValue (1000000));
404  ulClient.SetAttribute ("PacketSize", UintegerValue (m_packetSize));
405 
406  clientApps.Add (dlClient.Install (remoteHost));
407  clientApps.Add (ulClient.Install (ueNodes.Get (u)));
408  }
409 
410  serverApps.Start (Seconds (0.030));
411  clientApps.Start (Seconds (0.030));
412 
413  double statsStartTime = 0.04; // need to allow for RRC connection establishment + SRS
414  double statsDuration = 0.5;
415  double tolerance = 0.1;
416  Simulator::Stop (Seconds (statsStartTime + statsDuration - 0.0001));
417 
418  lteHelper->EnableRlcTraces ();
419  lteHelper->EnableMacTraces ();
420  Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats ();
421  rlcStats->SetAttribute ("StartTime", TimeValue (Seconds (statsStartTime)));
422  rlcStats->SetAttribute ("EpochDuration", TimeValue (Seconds (statsDuration)));
423 
424  Simulator::Run ();
425 
430  NS_LOG_INFO ("DL - Test with " << m_nUser << " user(s) at distance " << m_dist);
431  std::vector <uint64_t> dlDataRxed;
432  for (int i = 0; i < m_nUser; i++)
433  {
434  // get the imsi
435  uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
436  // get the lcId
437  uint8_t lcId = 4;
438  uint64_t data = rlcStats->GetDlRxData (imsi, lcId);
439  dlDataRxed.push_back (data);
440  NS_LOG_INFO ("\tUser " << i << " imsi " << imsi << " bytes rxed " << (double)dlDataRxed.at (i) << " thr " << (double)dlDataRxed.at (i) / statsDuration << " ref " << m_thrRefDl);
441  }
442 
443  for (int i = 0; i < m_nUser; i++)
444  {
445  NS_TEST_ASSERT_MSG_EQ_TOL ((double)dlDataRxed.at (i) / statsDuration, m_thrRefDl, m_thrRefDl * tolerance, " Unfair Throughput!");
446  }
447 
452  NS_LOG_INFO ("UL - Test with " << m_nUser << " user(s) at distance " << m_dist);
453  std::vector <uint64_t> ulDataRxed;
454  for (int i = 0; i < m_nUser; i++)
455  {
456  // get the imsi
457  uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
458  // get the lcId
459  uint8_t lcId = 4;
460  ulDataRxed.push_back (rlcStats->GetUlRxData (imsi, lcId));
461  NS_LOG_INFO ("\tUser " << i << " imsi " << imsi << " bytes rxed " << (double)ulDataRxed.at (i) << " thr " << (double)ulDataRxed.at (i) / statsDuration << " ref " << m_thrRefUl);
462  }
463 
464  for (int i = 0; i < m_nUser; i++)
465  {
466  NS_TEST_ASSERT_MSG_EQ_TOL ((double)ulDataRxed.at (i) / statsDuration, m_thrRefUl, m_thrRefUl * tolerance, " Unfair Throughput!");
467  }
469 
470 }
471 
472 
473 
474 // --------------- T E S T - C A S E # 2 ------------------------------
475 
476 
477 std::string
478 LenaPssFfMacSchedulerTestCase2::BuildNameString (uint16_t nUser, std::vector<uint16_t> dist)
479 {
480  std::ostringstream oss;
481  oss << "distances (m) = [ " ;
482  for (std::vector<uint16_t>::iterator it = dist.begin (); it != dist.end (); ++it)
483  {
484  oss << *it << " ";
485  }
486  oss << "]";
487  return oss.str ();
488 }
489 
490 
491 LenaPssFfMacSchedulerTestCase2::LenaPssFfMacSchedulerTestCase2 (std::vector<uint16_t> dist, std::vector<uint32_t> estThrPssDl, std::vector<uint16_t> packetSize, uint16_t interval,bool errorModelEnabled)
492  : TestCase (BuildNameString (dist.size (), dist)),
493  m_nUser (dist.size ()),
494  m_dist (dist),
495  m_packetSize (packetSize),
496  m_interval (interval),
497  m_estThrPssDl (estThrPssDl),
498  m_errorModelEnabled (errorModelEnabled)
499 {
500 }
501 
503 {
504 }
505 
506 void
508 {
509 
510  if (!m_errorModelEnabled)
511  {
512  Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (false));
513  Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (false));
514  }
515 
516  Config::SetDefault ("ns3::LteHelper::UseIdealRrc", BooleanValue (true));
517 
518 
519  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
520  Ptr<EpcHelper> epcHelper = CreateObject<EpcHelper> ();
521  lteHelper->SetEpcHelper (epcHelper);
522 
523  Ptr<Node> pgw = epcHelper->GetPgwNode ();
524 
525  // Create a single RemoteHost
526  NodeContainer remoteHostContainer;
527  remoteHostContainer.Create (1);
528  Ptr<Node> remoteHost = remoteHostContainer.Get (0);
529  InternetStackHelper internet;
530  internet.Install (remoteHostContainer);
531 
532  // Create the Internet
533  PointToPointHelper p2ph;
534  p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s")));
535  p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500));
536  p2ph.SetChannelAttribute ("Delay", TimeValue (Seconds (0.001)));
537  NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost);
538  Ipv4AddressHelper ipv4h;
539  ipv4h.SetBase ("1.0.0.0", "255.0.0.0");
540  Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices);
541  // interface 0 is localhost, 1 is the p2p device
542  Ipv4Address remoteHostAddr = internetIpIfaces.GetAddress (1);
543 
544  Ipv4StaticRoutingHelper ipv4RoutingHelper;
545  Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ());
546  remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1);
547 
548 
549 // LogComponentDisableAll (LOG_LEVEL_ALL);
550  //LogComponentEnable ("LenaTestPssFfMacCheduler", LOG_LEVEL_ALL);
551 
552  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::FriisSpectrumPropagationLossModel"));
553 
554  // Create Nodes: eNodeB and UE
555  NodeContainer enbNodes;
556  NodeContainer ueNodes;
557  enbNodes.Create (1);
558  ueNodes.Create (m_nUser);
559 
560  // Install Mobility Model
561  MobilityHelper mobility;
562  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
563  mobility.Install (enbNodes);
564  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
565  mobility.Install (ueNodes);
566 
567  // Create Devices and install them in the Nodes (eNB and UE)
568  NetDeviceContainer enbDevs;
569  NetDeviceContainer ueDevs;
570  lteHelper->SetSchedulerType ("ns3::PssFfMacScheduler");
571  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
572  ueDevs = lteHelper->InstallUeDevice (ueNodes);
573 
574  Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ();
575  Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy ();
576  enbPhy->SetAttribute ("TxPower", DoubleValue (30.0));
577  enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0));
578 
579  // Set UEs' position and power
580  for (int i = 0; i < m_nUser; i++)
581  {
583  mm->SetPosition (Vector (m_dist.at (i), 0.0, 0.0));
584  Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (i)->GetObject<LteUeNetDevice> ();
585  Ptr<LteUePhy> uePhy = lteUeDev->GetPhy ();
586  uePhy->SetAttribute ("TxPower", DoubleValue (23.0));
587  uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0));
588  }
589 
590  // Install the IP stack on the UEs
591  internet.Install (ueNodes);
592  Ipv4InterfaceContainer ueIpIface;
593  ueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueDevs));
594 
595  // Assign IP address to UEs
596  for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
597  {
598  Ptr<Node> ueNode = ueNodes.Get (u);
599  // Set the default gateway for the UE
600  Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv4> ());
601  ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1);
602  }
603 
604  // Attach a UE to a eNB
605  lteHelper->Attach (ueDevs, enbDevs.Get (0));
606 
607  // Activate an EPS bearer on all UEs
608 
609  for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
610  {
611  Ptr<NetDevice> ueDevice = ueDevs.Get (u);
612  GbrQosInformation qos;
613  qos.gbrDl = (m_packetSize.at (u) + 32) * (1000 / m_interval) * 8; // bit/s, considering IP, UDP, RLC, PDCP header size
614  qos.gbrUl = (m_packetSize.at (u) + 32) * (1000 / m_interval) * 8;
615  qos.mbrDl = qos.gbrDl;
616  qos.mbrUl = qos.gbrUl;
617 
619  EpsBearer bearer (q, qos);
620  lteHelper->ActivateDedicatedEpsBearer (ueDevice, bearer, EpcTft::Default ());
621  }
622 
623 
624  // Install downlind and uplink applications
625  uint16_t dlPort = 1234;
626  uint16_t ulPort = 2000;
627  PacketSinkHelper dlPacketSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), dlPort));
628  PacketSinkHelper ulPacketSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), ulPort));
631  for (uint32_t u = 0; u < ueNodes.GetN (); ++u)
632  {
633  ++ulPort;
634  serverApps.Add (dlPacketSinkHelper.Install (ueNodes.Get (u))); // receive packets from remotehost
635  serverApps.Add (ulPacketSinkHelper.Install (remoteHost)); // receive packets from UEs
636 
637  UdpClientHelper dlClient (ueIpIface.GetAddress (u), dlPort); // uplink packets generator
638  dlClient.SetAttribute ("Interval", TimeValue (MilliSeconds (m_interval)));
639  dlClient.SetAttribute ("MaxPackets", UintegerValue (1000000));
640  dlClient.SetAttribute ("PacketSize", UintegerValue (m_packetSize.at (u)));
641 
642  UdpClientHelper ulClient (remoteHostAddr, ulPort); // downlink packets generator
643  ulClient.SetAttribute ("Interval", TimeValue (MilliSeconds (m_interval)));
644  ulClient.SetAttribute ("MaxPackets", UintegerValue (1000000));
645  ulClient.SetAttribute ("PacketSize", UintegerValue (m_packetSize.at (u)));
646 
647  clientApps.Add (dlClient.Install (remoteHost));
648  clientApps.Add (ulClient.Install (ueNodes.Get (u)));
649  }
650 
651  serverApps.Start (Seconds (0.030));
652  clientApps.Start (Seconds (0.030));
653 
654  double statsStartTime = 0.04; // need to allow for RRC connection establishment + SRS
655  double statsDuration = 0.5;
656  double tolerance = 0.1;
657  Simulator::Stop (Seconds (statsStartTime + statsDuration - 0.0001));
658 
659  lteHelper->EnableRlcTraces ();
660  Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats ();
661  rlcStats->SetAttribute ("StartTime", TimeValue (Seconds (statsStartTime)));
662  rlcStats->SetAttribute ("EpochDuration", TimeValue (Seconds (statsDuration)));
663 
664 
665  Simulator::Run ();
666 
671  NS_LOG_INFO ("DL - Test with " << m_nUser << " user(s)");
672  std::vector <uint64_t> dlDataRxed;
673  for (int i = 0; i < m_nUser; i++)
674  {
675  // get the imsi
676  uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
677  // get the lcId
678  uint8_t lcId = 4;
679  dlDataRxed.push_back (rlcStats->GetDlRxData (imsi, lcId));
680  NS_LOG_INFO ("\tUser " << i << " dist " << m_dist.at (i) << " imsi " << imsi << " bytes rxed " << (double)dlDataRxed.at (i) << " thr " << (double)dlDataRxed.at (i) / statsDuration << " ref " << m_estThrPssDl.at (i));
681  }
682 
683  for (int i = 0; i < m_nUser; i++)
684  {
685  NS_TEST_ASSERT_MSG_EQ_TOL ((double)dlDataRxed.at (i) / statsDuration, m_estThrPssDl.at (i), m_estThrPssDl.at (i) * tolerance, " Unfair Throughput!");
686  }
687 
689 
690 }
691 
692 
693 } // namespace ns3
694 
695 
696 
697