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 #include <ns3/object.h>
27 #include <ns3/spectrum-interference.h>
28 #include <ns3/spectrum-error-model.h>
29 #include <ns3/log.h>
30 #include <ns3/test.h>
31 #include <ns3/simulator.h>
32 #include <ns3/packet.h>
33 #include <ns3/ptr.h>
34 #include "ns3/radio-bearer-stats-calculator.h"
35 #include <ns3/constant-position-mobility-model.h>
36 #include <ns3/ff-mac-scheduler.h>
37 #include "lte-test-fdmt-ff-mac-scheduler.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 using namespace ns3;
54
55 NS_LOG_COMPONENT_DEFINE ("LenaTestFdMtFfMacScheduler");
56
LenaTestFdMtFfMacSchedulerSuite()57 LenaTestFdMtFfMacSchedulerSuite::LenaTestFdMtFfMacSchedulerSuite ()
58 : TestSuite ("lte-fdmt-ff-mac-scheduler", SYSTEM)
59 {
60 NS_LOG_INFO ("creating LenaTestFdMtFfMacSchedulerSuite");
61
62 bool errorModel = false;
63
64 //Test Case : AMC works in FDMT
65
66 //Note: here the MCS is calculated by the narrowband CQI
67
68 // DOWNLINK - DISTANCE 0 -> MCS 28 -> Itbs 26 (from table 7.1.7.2.1-1 of 36.213)
69 // 1 user -> 24 PRB at Itbs 26 -> 2196 -> 2196000 bytes/sec for one UE; 0 bytes/sec for other UEs
70 // 3 users -> 2196000 among 3 users -> 2196000 bytes/sec for one UE; 0 bytes/sec for other UEs
71 // 6 users -> 2196000 among 6 users -> 2196000 bytes/sec for one UE; 0 bytes/sec for other UEs
72 // 12 users -> 2196000 among 12 users -> 2196000 bytes/sec for one UE; 0 bytes/sec for other UEs
73 // UPLINK- DISTANCE 0 -> MCS 28 -> Itbs 26 (from table 7.1.7.2.1-1 of 36.213)
74 // 1 user -> 25 PRB at Itbs 26 -> 2292 -> 2292000 bytes/sec
75 // 3 users -> 8 PRB at Itbs 26 -> 749 -> 749000 bytes/sec
76 // 6 users -> 4 PRB at Itbs 26 -> 373 -> 373000 bytes/sec
77 // after the patch enforcing min 3 PRBs per UE:
78 // 12 users -> 3 PRB at Itbs 26 -> 277 bytes * 8/12 UE/TTI -> 184670 bytes/sec
79 AddTestCase (new LenaFdMtFfMacSchedulerTestCase (1,0,2196000,2292000, errorModel), TestCase::EXTENSIVE);
80 AddTestCase (new LenaFdMtFfMacSchedulerTestCase (3,0,2196000,749000,errorModel), TestCase::QUICK);
81 AddTestCase (new LenaFdMtFfMacSchedulerTestCase (6,0,2196000,373000, errorModel), TestCase::EXTENSIVE);
82 AddTestCase (new LenaFdMtFfMacSchedulerTestCase (12,0,2196000,184670, errorModel), TestCase::EXTENSIVE);
83
84 // DOWNLINK - DISTANCE 4800 -> MCS 22 -> Itbs 20 (from table 7.1.7.2.1-1 of 36.213)
85 // 1 user -> 24 PRB at Itbs 20 -> 1383 -> 1383000 byte/secfor one UE; 0 bytes/sec for other UEs
86 // 3 users -> 1383000 among 3 users -> 1383000 bytes/sec for one UE; 0 bytes/sec for other UEs
87 // 6 users -> 1383000 among 6 users -> 1383000 bytes/sec for one UE; 0 bytes/sec for other UEs
88 // 12 users -> 1383000 among 12 users -> 1383000 bytes/sec for one UE; 0 bytes/sec for other UEs
89 // UPLINK - DISTANCE 4800 -> MCS 14 -> Itbs 13 (from table 7.1.7.2.1-1 of 36.213)
90 // 1 user -> 25 PRB at Itbs 13 -> 807 -> 807000 bytes/sec
91 // 3 users -> 8 PRB at Itbs 13 -> 253 -> 253000 bytes/sec
92 // 6 users -> 4 PRB at Itbs 13 -> 125 -> 125000 bytes/sec
93 // after the patch enforcing min 3 PRBs per UE:
94 // 12 users -> 3 PRB at Itbs 13 -> 93 bytes * 8/12 UE/TTI -> 62000 bytes/sec
95 AddTestCase (new LenaFdMtFfMacSchedulerTestCase (1,4800,1383000,807000,errorModel), TestCase::EXTENSIVE);
96 AddTestCase (new LenaFdMtFfMacSchedulerTestCase (3,4800,1383000,253000,errorModel), TestCase::EXTENSIVE);
97 AddTestCase (new LenaFdMtFfMacSchedulerTestCase (6,4800,1383000,125000,errorModel), TestCase::EXTENSIVE);
98 AddTestCase (new LenaFdMtFfMacSchedulerTestCase (12,4800,1383000,62000,errorModel), TestCase::EXTENSIVE);
99
100
101 // DOWNLINK - DISTANCE 6000 -> MCS 20 -> Itbs 18 (from table 7.1.7.2.1-1 of 36.213)
102 // 1 user -> 24 PRB at Itbs 18 -> 1191 -> 1191000 byte/sec for one UE; 0 bytes/sec for other UEs
103 // 3 users -> 1191000 among 3 users -> 1191000 bytes/sec for one UE; 0 bytes/sec for other UEs
104 // 6 users -> 1191000 among 6 users -> 1191000 bytes/sec for one UE; 0 bytes/sec for other UEs
105 // 12 users ->1191000 among 12 users -> 1191000 bytes/sec for one UE; 0 bytes/sec for other UEs
106 // UPLINK - DISTANCE 6000 -> MCS 12 -> Itbs 11 (from table 7.1.7.2.1-1 of 36.213)
107 // 1 user -> 25 PRB at Itbs 11 -> 621 -> 621000 bytes/sec
108 // 3 users -> 8 PRB at Itbs 11 -> 201 -> 201000 bytes/sec
109 // 6 users -> 4 PRB at Itbs 11 -> 97 -> 97000 bytes/sec
110 // after the patch enforcing min 3 PRBs per UE:
111 // 12 users -> 3 PRB at Itbs 11 -> 73 bytes * 8/12 UE/TTI -> 48667 bytes/sec
112 AddTestCase (new LenaFdMtFfMacSchedulerTestCase (1,6000,1191000,621000, errorModel), TestCase::EXTENSIVE);
113 AddTestCase (new LenaFdMtFfMacSchedulerTestCase (3,6000,1191000,201000, errorModel), TestCase::EXTENSIVE);
114 AddTestCase (new LenaFdMtFfMacSchedulerTestCase (6,6000,1191000,97000, errorModel), TestCase::EXTENSIVE);
115 AddTestCase (new LenaFdMtFfMacSchedulerTestCase (12,6000,1191000,48667, errorModel), TestCase::EXTENSIVE);
116
117 // DOWNLINK - DISTANCE 10000 -> MCS 14 -> Itbs 13 (from table 7.1.7.2.1-1 of 36.213)
118 // 1 user -> 24 PRB at Itbs 13 -> 775 -> 775000 byte/sec for one UE; 0 bytes/sec for other UEs
119 // 3 users -> 775000 among 3 users -> 775000 bytes/sec for one UE; 0 bytes/sec for other UEs
120 // 6 users -> 775000 among 6 users -> 775000 bytes/sec for one UE; 0 bytes/sec for other UEs
121 // 12 users -> 775000 among 12 users -> 775000 bytes/sec for one UE; 0 bytes/sec for other UEs
122 // UPLINK - DISTANCE 10000 -> MCS 8 -> Itbs 8 (from table 7.1.7.2.1-1 of 36.213)
123 // 1 user -> 24 PRB at Itbs 8 -> 437 -> 437000 bytes/sec
124 // 3 users -> 8 PRB at Itbs 8 -> 137 -> 137000 bytes/sec
125 // 6 users -> 4 PRB at Itbs 8 -> 67 -> 67000 bytes/sec
126 // after the patch enforcing min 3 PRBs per UE:
127 // 12 users -> 3 PRB at Itbs 8 -> 49 bytes * 8/12 UE/TTI -> 32667 bytes/sec
128 AddTestCase (new LenaFdMtFfMacSchedulerTestCase (1,10000,775000,437000,errorModel), TestCase::EXTENSIVE);
129 AddTestCase (new LenaFdMtFfMacSchedulerTestCase (3,10000,775000,137000,errorModel), TestCase::EXTENSIVE);
130 AddTestCase (new LenaFdMtFfMacSchedulerTestCase (6,10000,775000,67000,errorModel), TestCase::EXTENSIVE);
131 AddTestCase (new LenaFdMtFfMacSchedulerTestCase (12,10000,775000,32667,errorModel), TestCase::EXTENSIVE);
132
133 // DONWLINK - DISTANCE 20000 -> MCS 8 -> Itbs 8 (from table 7.1.7.2.1-1 of 36.213)
134 // 1 user -> 24 PRB at Itbs 8 -> 421 -> 421000 bytes/sec for one UE; 0 bytes/sec for other UEs
135 // 3 users -> 421000 among 3 users -> 421000 bytes/sec for one UE; 0 bytes/sec for other UEs
136 // 6 users -> 421000 among 6 users -> 421000 bytes/sec for one UE; 0 bytes/sec for other UEs
137 // 12 users -> 421000 among 12 users -> 421000 bytes/sec for one UE; 0 bytes/sec for other UEs
138 // UPLINK - DISTANCE 20000 -> MCS 2 -> Itbs 2 (from table 7.1.7.2.1-1 of 36.213)
139 // 1 user -> 25 PRB at Itbs 2 -> 233 -> 137000 bytes/sec
140 // 3 users -> 8 PRB at Itbs 2 -> 69 -> 41000 bytes/sec
141 // 6 users -> 4 PRB at Itbs 2 -> 32 -> 22000 bytes/sec
142 // after the patch enforcing min 3 PRBs per UE:
143 // 12 users -> 3 PRB at Itbs 2 -> 26 bytes * 8/12 UE/TTI -> 12000 bytes/sec
144 AddTestCase (new LenaFdMtFfMacSchedulerTestCase (1,20000,421000,137000,errorModel), TestCase::EXTENSIVE);
145 AddTestCase (new LenaFdMtFfMacSchedulerTestCase (3,20000,421000,41000,errorModel), TestCase::EXTENSIVE);
146 AddTestCase (new LenaFdMtFfMacSchedulerTestCase (6,20000,421000,22000,errorModel), TestCase::EXTENSIVE);
147 AddTestCase (new LenaFdMtFfMacSchedulerTestCase (12,20000,421000,12000,errorModel), TestCase::EXTENSIVE);
148
149 // DOWNLINK - DISTANCE 100000 -> CQI == 0 -> out of range -> 0 bytes/sec
150 // UPLINK - DISTANCE 100000 -> CQI == 0 -> out of range -> 0 bytes/sec
151 AddTestCase (new LenaFdMtFfMacSchedulerTestCase (1,100000,0,0,errorModel), TestCase::QUICK);
152 }
153
154 static LenaTestFdMtFfMacSchedulerSuite lenaTestFdMtFfMacSchedulerSuite;
155
156
157 // --------------- T E S T - C A S E ------------------------------
158
159 std::string
BuildNameString(uint16_t nUser,double dist)160 LenaFdMtFfMacSchedulerTestCase::BuildNameString (uint16_t nUser, double dist)
161 {
162 std::ostringstream oss;
163 oss << nUser << " UEs, distance " << dist << " m";
164 return oss.str ();
165 }
166
LenaFdMtFfMacSchedulerTestCase(uint16_t nUser,double dist,double thrRefDl,double thrRefUl,bool errorModelEnabled)167 LenaFdMtFfMacSchedulerTestCase::LenaFdMtFfMacSchedulerTestCase (uint16_t nUser, double dist, double thrRefDl, double thrRefUl, bool errorModelEnabled)
168 : TestCase (BuildNameString (nUser, dist)),
169 m_nUser (nUser),
170 m_dist (dist),
171 m_thrRefDl (thrRefDl),
172 m_thrRefUl (thrRefUl),
173 m_errorModelEnabled (errorModelEnabled)
174 {
175 }
176
~LenaFdMtFfMacSchedulerTestCase()177 LenaFdMtFfMacSchedulerTestCase::~LenaFdMtFfMacSchedulerTestCase ()
178 {
179 }
180
181
182 void
DoRun(void)183 LenaFdMtFfMacSchedulerTestCase::DoRun (void)
184 {
185
186 NS_LOG_FUNCTION (this << m_nUser << m_dist);
187
188 if (!m_errorModelEnabled)
189 {
190 Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (false));
191 Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (false));
192 }
193
194 Config::SetDefault ("ns3::LteHelper::UseIdealRrc", BooleanValue (true));
195 Config::SetDefault ("ns3::MacStatsCalculator::DlOutputFilename", StringValue (CreateTempDirFilename ("DlMacStats.txt")));
196 Config::SetDefault ("ns3::MacStatsCalculator::UlOutputFilename", StringValue (CreateTempDirFilename ("UlMacStats.txt")));
197 Config::SetDefault ("ns3::RadioBearerStatsCalculator::DlRlcOutputFilename", StringValue (CreateTempDirFilename ("DlRlcStats.txt")));
198 Config::SetDefault ("ns3::RadioBearerStatsCalculator::UlRlcOutputFilename", StringValue (CreateTempDirFilename ("UlRlcStats.txt")));
199
200 /**
201 * Initialize Simulation Scenario: 1 eNB and m_nUser UEs
202 */
203
204 Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
205 lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::FriisSpectrumPropagationLossModel"));
206
207 // Create Nodes: eNodeB and UE
208 NodeContainer enbNodes;
209 NodeContainer ueNodes;
210 enbNodes.Create (1);
211 ueNodes.Create (m_nUser);
212
213 // Install Mobility Model
214 MobilityHelper mobility;
215 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
216 mobility.Install (enbNodes);
217 mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
218 mobility.Install (ueNodes);
219
220 // Create Devices and install them in the Nodes (eNB and UE)
221 NetDeviceContainer enbDevs;
222 NetDeviceContainer ueDevs;
223 lteHelper->SetSchedulerType ("ns3::FdMtFfMacScheduler");
224 lteHelper->SetSchedulerAttribute ("UlCqiFilter", EnumValue (FfMacScheduler::SRS_UL_CQI));
225 enbDevs = lteHelper->InstallEnbDevice (enbNodes);
226 ueDevs = lteHelper->InstallUeDevice (ueNodes);
227
228 // Attach a UE to a eNB
229 lteHelper->Attach (ueDevs, enbDevs.Get (0));
230
231 // Activate an EPS bearer
232 enum EpsBearer::Qci q = EpsBearer::GBR_CONV_VOICE;
233 EpsBearer bearer (q);
234 lteHelper->ActivateDataRadioBearer (ueDevs, bearer);
235
236
237 Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ();
238 Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy ();
239 enbPhy->SetAttribute ("TxPower", DoubleValue (30.0));
240 enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0));
241
242 // Set UEs' position and power
243 for (int i = 0; i < m_nUser; i++)
244 {
245 Ptr<ConstantPositionMobilityModel> mm = ueNodes.Get (i)->GetObject<ConstantPositionMobilityModel> ();
246 mm->SetPosition (Vector (m_dist, 0.0, 0.0));
247 Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (i)->GetObject<LteUeNetDevice> ();
248 Ptr<LteUePhy> uePhy = lteUeDev->GetPhy ();
249 uePhy->SetAttribute ("TxPower", DoubleValue (23.0));
250 uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0));
251 }
252
253
254 double statsStartTime = 0.300; // need to allow for RRC connection establishment + SRS
255 double statsDuration = 0.6;
256 double tolerance = 0.1;
257 Simulator::Stop (Seconds (statsStartTime + statsDuration - 0.000001));
258
259 lteHelper->EnableMacTraces ();
260 lteHelper->EnableRlcTraces ();
261 Ptr<RadioBearerStatsCalculator> rlcStats = lteHelper->GetRlcStats ();
262 rlcStats->SetAttribute ("StartTime", TimeValue (Seconds (statsStartTime)));
263 rlcStats->SetAttribute ("EpochDuration", TimeValue (Seconds (statsDuration)));
264
265
266 Simulator::Run ();
267
268 /**
269 * Check that the downlink assignment is done in a "frequency domain maximum throughput" manner
270 */
271 NS_LOG_INFO ("DL - Test with " << m_nUser << " user(s) at distance " << m_dist);
272 std::vector <uint64_t> dlDataRxed;
273 for (int i = 0; i < m_nUser; i++)
274 {
275 // get the imsi
276 uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
277 uint8_t lcId = 3;
278 dlDataRxed.push_back (rlcStats->GetDlRxData (imsi, lcId));
279 NS_LOG_INFO ("\tUser " << i << " imsi " << imsi << " bytes rxed " << (double)dlDataRxed.at (i) << " thr " << (double)dlDataRxed.at (i) / statsDuration << " ref " << m_thrRefDl);
280 }
281
282 /**
283 * Check that the assignment is done in a "frequency domain maximum throughput" manner among users
284 * with maximum SINRs: without fading, current FD MT always assign all resources to one UE
285 */
286
287 uint8_t found = 0;
288 for (int i = 0; i < m_nUser; i++)
289 {
290 double throughput = (double)dlDataRxed.at (i) / statsDuration;
291 if (throughput != 0 && found == 0)
292 {
293 NS_TEST_ASSERT_MSG_EQ_TOL (throughput, m_thrRefDl, m_thrRefDl * tolerance, " Unfair Throughput!");
294 found = 1;
295 }
296 else if (throughput != 0 && found == 1)
297 {
298 NS_TEST_ASSERT_MSG_EQ_TOL (0, m_thrRefDl, m_thrRefDl * tolerance, " Unfair Throughput!");
299 }
300 else
301 NS_TEST_ASSERT_MSG_EQ_TOL (throughput, 0, 0, " Unfair Throughput!");
302 }
303
304 /**
305 * Check that the uplink assignment is done in a "proportional fair" manner
306 */
307 NS_LOG_INFO ("UL - Test with " << m_nUser << " user(s) at distance " << m_dist);
308 std::vector <uint64_t> ulDataRxed;
309 for (int i = 0; i < m_nUser; i++)
310 {
311 // get the imsi
312 uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
313 // get the lcId
314 uint8_t lcId = 3;
315 ulDataRxed.push_back (rlcStats->GetUlRxData (imsi, lcId));
316 NS_LOG_INFO ("\tUser " << i << " imsi " << imsi << " bytes rxed " << (double)ulDataRxed.at (i) << " thr " << (double)ulDataRxed.at (i) / statsDuration << " ref " << m_thrRefUl);
317 }
318 /**
319 * Check that the assignment is done in a "proportional fair" manner among users
320 * with equal SINRs: the bandwidth should be distributed according to the
321 * ratio of the estimated throughput per TTI of each user; therefore equally
322 * partitioning the whole bandwidth achievable from a single users in a TTI
323 */
324 for (int i = 0; i < m_nUser; i++)
325 {
326 NS_TEST_ASSERT_MSG_EQ_TOL ((double)ulDataRxed.at (i) / statsDuration, m_thrRefUl, m_thrRefUl * tolerance, " Unfair Throughput!");
327 }
328 Simulator::Destroy ();
329
330 }
331
332