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