A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lte-test-phy-error-model.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Marco Miozzo <marco.miozzo@cttc.es>
19  */
20 
21 #include <ns3/object.h>
22 #include <ns3/spectrum-interference.h>
23 #include <ns3/spectrum-error-model.h>
24 #include <ns3/log.h>
25 #include <ns3/test.h>
26 #include <ns3/simulator.h>
27 #include <ns3/packet.h>
28 #include <ns3/ptr.h>
29 #include <iostream>
30 #include <ns3/radio-bearer-stats-calculator.h>
31 #include <ns3/buildings-mobility-model.h>
32 #include <ns3/hybrid-buildings-propagation-loss-model.h>
33 #include <ns3/eps-bearer.h>
34 #include <ns3/node-container.h>
35 #include <ns3/mobility-helper.h>
36 #include <ns3/net-device-container.h>
37 #include <ns3/lte-ue-net-device.h>
38 #include <ns3/lte-enb-net-device.h>
39 #include <ns3/lte-ue-rrc.h>
40 #include <ns3/lte-helper.h>
41 #include <ns3/string.h>
42 #include <ns3/double.h>
43 #include <ns3/lte-enb-phy.h>
44 #include <ns3/lte-ue-phy.h>
45 #include <ns3/config.h>
46 #include <ns3/boolean.h>
47 #include <ns3/enum.h>
48 #include <ns3/unused.h>
49 #include <ns3/ff-mac-scheduler.h>
50 
52 
53 NS_LOG_COMPONENT_DEFINE ("LenaTestPhyErrorModel");
54 
55 namespace ns3 {
56 
57 
59  : TestSuite ("lte-phy-error-model", SYSTEM)
60 {
61  NS_LOG_INFO ("creating LenaTestPhyErrorModelTestCase");
62 
63 
64  // Tests on DL Control Channels (PCFICH+PDDCH)
65  // 1 interfering eNB SINR -2.0 BER 0.007 TB size 217
66  AddTestCase (new LenaDlCtrlPhyErrorModelTestCase (2, 1078, 217, 0.007));
67  // 2 interfering eNBs SINR -4.0 BER 0.037 TB size 217
68  AddTestCase (new LenaDlCtrlPhyErrorModelTestCase (3, 1040, 217, 0.045));
69  // 3 interfering eNBs SINR -6.0 BER 0.21 TB size 133
70  AddTestCase (new LenaDlCtrlPhyErrorModelTestCase (4, 1250, 133, 0.206));
71  // 4 interfering eNBs SINR -7.0 BER 0.34 TB size 133
72  AddTestCase (new LenaDlCtrlPhyErrorModelTestCase (5, 1260, 81, 0.343));
73 
74  // Tests on DL/UL Data channels (PDSCH, PUSCH)
75  // MCS 2 TB size of 256 bits BER 0.33 SINR -5.51
76  AddTestCase (new LenaDataPhyErrorModelTestCase (4, 1800, 32, 0.35, 50));
77 // MCS 2 TB size of 528 bits BER 0.11 SINR -5.51
78  AddTestCase (new LenaDataPhyErrorModelTestCase (2, 1800, 66, 0.11, 34));
79 // MCS 2 TB size of 1088 bits BER 0.02 SINR -5.51
80  AddTestCase (new LenaDataPhyErrorModelTestCase (1, 1800, 136, 0.02, 16));
81  // MCS 12 TB size of 4800 bits BER 0.3 SINR 4.43
82  AddTestCase (new LenaDataPhyErrorModelTestCase (1, 600, 600, 0.3, 48));
83 // MCS 12 TB size of 1632 bits BER 0.55 SINR 4.43
84  AddTestCase (new LenaDataPhyErrorModelTestCase (3, 600, 204, 0.55, 52));
85 // MCS 16 TB size of 7272 bits (3648 x 3584) BER 0.14 SINR 8.48
86 // BER 0.14 = 1 - ((1-0.075)*(1-0.075))
87  AddTestCase (new LenaDataPhyErrorModelTestCase (1, 470, 781, 0.14, 29));
88 
89 
90 
91 }
92 
94 
95 std::string
96 LenaDataPhyErrorModelTestCase::BuildNameString (uint16_t nUser, uint16_t dist)
97 {
98  std::ostringstream oss;
99  oss << nUser << " UEs, distance " << dist << " m";
100  return oss.str ();
101 }
102 
103 LenaDataPhyErrorModelTestCase::LenaDataPhyErrorModelTestCase (uint16_t nUser, uint16_t dist, uint16_t tbSize, double berRef, uint16_t bernQuantile)
104  : TestCase (BuildNameString (nUser, dist)),
105  m_nUser (nUser),
106  m_dist (dist),
107  m_tbSize (tbSize),
108  m_berRef (berRef),
109  m_bernQuantile (bernQuantile)
110 {
111 }
112 
114 {
115 }
116 
117 void
119 {
120 
121  double ber = 0.03;
122  Config::SetDefault ("ns3::LteAmc::Ber", DoubleValue (ber));
123  Config::SetDefault ("ns3::LteAmc::AmcModel", EnumValue (LteAmc::PiroEW2010));
124  Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (false));
125  Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (true));
126 // LogComponentEnable ("LteEnbRrc", LOG_LEVEL_ALL);
127 // LogComponentEnable ("LteUeRrc", LOG_LEVEL_ALL);
128 // LogComponentEnable ("LteEnbMac", LOG_LEVEL_ALL);
129 // LogComponentEnable ("LteUeMac", LOG_LEVEL_ALL);
130 // LogComponentEnable ("LteRlc", LOG_LEVEL_ALL);
131 //
132 // LogComponentEnable ("LtePhy", LOG_LEVEL_ALL);
133 // LogComponentEnable ("LteEnbPhy", LOG_LEVEL_ALL);
134 // LogComponentEnable ("LteUePhy", LOG_LEVEL_ALL);
135 
136 // LogComponentEnable ("LteSpectrumPhy", LOG_LEVEL_ALL);
137 // LogComponentEnable ("LteInterference", LOG_LEVEL_ALL);
138 // LogComponentEnable ("LteSinrChunkProcessor", LOG_LEVEL_ALL);
139 //
140 // LogComponentEnable ("LtePropagationLossModel", LOG_LEVEL_ALL);
141 // LogComponentEnable ("LossModel", LOG_LEVEL_ALL);
142 // LogComponentEnable ("ShadowingLossModel", LOG_LEVEL_ALL);
143 // LogComponentEnable ("PenetrationLossModel", LOG_LEVEL_ALL);
144 // LogComponentEnable ("MultipathLossModel", LOG_LEVEL_ALL);
145 // LogComponentEnable ("PathLossModel", LOG_LEVEL_ALL);
146 //
147 // LogComponentEnable ("LteNetDevice", LOG_LEVEL_ALL);
148 // LogComponentEnable ("LteUeNetDevice", LOG_LEVEL_ALL);
149 // LogComponentEnable ("LteEnbNetDevice", LOG_LEVEL_ALL);
150 
151 // LogComponentEnable ("RrFfMacScheduler", LOG_LEVEL_ALL);
152 // LogComponentEnable ("LenaHelper", LOG_LEVEL_ALL);
153 // LogComponentEnable ("RlcStatsCalculator", LOG_LEVEL_ALL);
154 
155 
156 // LogComponentEnable ("LteSpectrumPhy", LOG_LEVEL_ALL);
157 // LogComponentEnable ("LteEnbMac", LOG_LEVEL_ALL);
158 // LogComponentEnable ("LteEnbPhy", LOG_LEVEL_ALL);
159 // LogComponentEnable ("LteUePhy", LOG_LEVEL_ALL);
160 // LogComponentEnable ("RrFfMacScheduler", LOG_LEVEL_ALL);
161 // LogComponentEnable ("LenaHelper", LOG_LEVEL_ALL);
162 // LogComponentEnable ("BuildingsPropagationLossModel", LOG_LEVEL_ALL);
163 // LogComponentEnable ("LteMiErrorModel", LOG_LEVEL_ALL);
164 // LogComponentEnable ("LteAmc", LOG_LEVEL_ALL);
165 //
167 
168  LogComponentEnable ("LenaTestPhyErrorModel", LOG_LEVEL_ALL);
169 
170 
175  Ptr<LteHelper> lena = CreateObject<LteHelper> ();
176 
177  // Create Nodes: eNodeB and UE
178  NodeContainer enbNodes;
179  NodeContainer ueNodes;
180  enbNodes.Create (1);
181  ueNodes.Create (m_nUser);
182 
183  // Install Mobility Model
184  MobilityHelper mobility;
185  mobility.SetMobilityModel ("ns3::BuildingsMobilityModel");
186  mobility.Install (enbNodes);
187  mobility.SetMobilityModel ("ns3::BuildingsMobilityModel");
188  mobility.Install (ueNodes);
189 
190  // remove random shadowing component
191  lena->SetAttribute ("PathlossModel", StringValue ("ns3::HybridBuildingsPropagationLossModel"));
192  lena->SetPathlossModelAttribute ("ShadowSigmaOutdoor", DoubleValue (0.0));
193  lena->SetPathlossModelAttribute ("ShadowSigmaIndoor", DoubleValue (0.0));
194  lena->SetPathlossModelAttribute ("ShadowSigmaExtWalls", DoubleValue (0.0));
195 
196  // Create Devices and install them in the Nodes (eNB and UE)
197  NetDeviceContainer enbDevs;
198  NetDeviceContainer ueDevs;
199  lena->SetSchedulerType ("ns3::RrFfMacScheduler");
201 
202  enbDevs = lena->InstallEnbDevice (enbNodes);
203  ueDevs = lena->InstallUeDevice (ueNodes);
204 
205  // Attach a UE to a eNB
206  lena->Attach (ueDevs, enbDevs.Get (0));
207 
208  // Activate an EPS bearer
210  EpsBearer bearer (q);
211  lena->ActivateEpsBearer (ueDevs, bearer, EpcTft::Default ());
212 
213 
214  Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ();
215  Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy ();
216  enbPhy->SetAttribute ("TxPower", DoubleValue (43.0));
217  enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0));
218  // place the HeNB over the default rooftop level (20 mt.)
220  mm->SetPosition (Vector (0.0, 0.0, 30.0));
221 
222  // Set UEs' position and power
223  for (int i = 0; i < m_nUser; i++)
224  {
226  mm->SetPosition (Vector (m_dist, 0.0, 1.0));
227  Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (i)->GetObject<LteUeNetDevice> ();
228  Ptr<LteUePhy> uePhy = lteUeDev->GetPhy ();
229  uePhy->SetAttribute ("TxPower", DoubleValue (23.0));
230  uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0));
231  }
232 
233  lena->EnableRlcTraces ();
234  double simulationTime = 1.000;
235 
236  Simulator::Stop (Seconds (simulationTime));
237 
238  Ptr<RadioBearerStatsCalculator> rlcStats = lena->GetRlcStats ();
239  rlcStats->SetAttribute ("EpochDuration", TimeValue (Seconds (simulationTime)));
240 
241 
242  Simulator::Run ();
243 
247  NS_LOG_INFO ("\tTest downlink/uplink data shared channels (PDSCH and PUSCH)");
248  NS_LOG_INFO ("Test with " << m_nUser << " user(s) at distance " << m_dist << " expected BER " << m_berRef);
249  std::vector <uint64_t> dlDataRxed;
250  for (int i = 0; i < m_nUser; i++)
251  {
252  // get the imsi
253  uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
254  // get the lcId
255  uint8_t lcId = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetRrc ()->GetLcIdVector ().at (0);
256  dlDataRxed.push_back (rlcStats->GetDlRxData (imsi, lcId));
257  double txed = rlcStats->GetDlTxData (imsi, lcId);
258  int n = txed / m_tbSize;
259  int lambda = (double)dlDataRxed.at (i) / m_tbSize;
260  double ber = 1.0 - ((double)dlDataRxed.at (i)/txed);
261  double np = n-n*m_berRef;
262  NS_LOG_INFO ("\tUser " << i << " imsi " << imsi << " bytes rxed " << (double)dlDataRxed.at (i) << " txed " << txed
263  << " BER " << ber << " Err " << std::fabs (m_berRef - ber) << " lambda " << lambda
264  << " np " << np << " difference " << std::abs (lambda - np) << " quantile " << m_bernQuantile);
265  NS_UNUSED (ber);
266  // the quantiles are evaluated offline according to a Bernoulli
267  // ditribution with n equal to the number of packet sent and p equal
268  // to the BER (see /reference/bernuolliDistribution.m for details)
269  NS_TEST_ASSERT_MSG_EQ_TOL (lambda, np, m_bernQuantile, " Unexpected BER distribution!");
270  }
271 
272 
274 }
275 
276 
277 
278 
279 std::string
281 {
282  std::ostringstream oss;
283  oss << nEnb << " eNBs, distance " << dist << " m";
284  return oss.str ();
285 }
286 
287 
288 LenaDlCtrlPhyErrorModelTestCase::LenaDlCtrlPhyErrorModelTestCase (uint16_t nEnb, uint16_t dist, uint16_t tbSize, double berRef)
289 : TestCase (BuildNameString (nEnb, dist)),
290 m_nEnb (nEnb),
291 m_dist (dist),
292 m_tbSize (tbSize),
293 m_berRef (berRef)
294 {
295 }
296 
298 {
299 }
300 
301 void
303 {
304 
305  double ber = 0.03;
306  Config::SetDefault ("ns3::LteAmc::Ber", DoubleValue (ber));
307  Config::SetDefault ("ns3::LteAmc::AmcModel", EnumValue (LteAmc::PiroEW2010));
308  Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (true));
309  Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (false));
310  // LogComponentEnable ("LteEnbRrc", LOG_LEVEL_ALL);
311  // LogComponentEnable ("LteUeRrc", LOG_LEVEL_ALL);
312  // LogComponentEnable ("LteEnbMac", LOG_LEVEL_ALL);
313  // LogComponentEnable ("LteUeMac", LOG_LEVEL_ALL);
314  // LogComponentEnable ("LteRlc", LOG_LEVEL_ALL);
315  //
316  // LogComponentEnable ("LtePhy", LOG_LEVEL_ALL);
317  // LogComponentEnable ("LteEnbPhy", LOG_LEVEL_ALL);
318  // LogComponentEnable ("LteUePhy", LOG_LEVEL_ALL);
319 
320  // LogComponentEnable ("LteSpectrumPhy", LOG_LEVEL_ALL);
321  // LogComponentEnable ("LteInterference", LOG_LEVEL_ALL);
322  // LogComponentEnable ("LteSinrChunkProcessor", LOG_LEVEL_ALL);
323  //
324  // LogComponentEnable ("LtePropagationLossModel", LOG_LEVEL_ALL);
325  // LogComponentEnable ("LossModel", LOG_LEVEL_ALL);
326  // LogComponentEnable ("ShadowingLossModel", LOG_LEVEL_ALL);
327  // LogComponentEnable ("PenetrationLossModel", LOG_LEVEL_ALL);
328  // LogComponentEnable ("MultipathLossModel", LOG_LEVEL_ALL);
329  // LogComponentEnable ("PathLossModel", LOG_LEVEL_ALL);
330  //
331  // LogComponentEnable ("LteNetDevice", LOG_LEVEL_ALL);
332  // LogComponentEnable ("LteUeNetDevice", LOG_LEVEL_ALL);
333  // LogComponentEnable ("LteEnbNetDevice", LOG_LEVEL_ALL);
334 
335 // LogComponentEnable ("RrFfMacScheduler", LOG_LEVEL_ALL);
336  // LogComponentEnable ("LenaHelper", LOG_LEVEL_ALL);
337  // LogComponentEnable ("RlcStatsCalculator", LOG_LEVEL_ALL);
338 
339 
340  // LogComponentEnable ("LteSpectrumPhy", LOG_LEVEL_ALL);
341  // LogComponentEnable ("LteEnbMac", LOG_LEVEL_ALL);
342  // LogComponentEnable ("LteEnbPhy", LOG_LEVEL_ALL);
343  // LogComponentEnable ("LteUePhy", LOG_LEVEL_ALL);
344  // LogComponentEnable ("RrFfMacScheduler", LOG_LEVEL_ALL);
345  // LogComponentEnable ("LenaHelper", LOG_LEVEL_ALL);
346  // LogComponentEnable ("BuildingsPropagationLossModel", LOG_LEVEL_ALL);
347 // LogComponentEnable ("LteMiErrorModel", LOG_LEVEL_ALL);
348  // LogComponentEnable ("LteAmc", LOG_LEVEL_ALL);
349  //
351 
352  LogComponentEnable ("LenaTestPhyErrorModel", LOG_LEVEL_ALL);
353 
354 
359  Ptr<LteHelper> lena = CreateObject<LteHelper> ();
360 
361  // Create Nodes: eNodeB and UE
362  NodeContainer enbNodes;
363  NodeContainer ueNodes;
364  enbNodes.Create (m_nEnb);
365  ueNodes.Create (1);
366 
367  // Install Mobility Model
368  MobilityHelper mobility;
369  mobility.SetMobilityModel ("ns3::BuildingsMobilityModel");
370  mobility.Install (enbNodes);
371  mobility.SetMobilityModel ("ns3::BuildingsMobilityModel");
372  mobility.Install (ueNodes);
373 
374  // remove random shadowing component
375  lena->SetAttribute ("PathlossModel", StringValue ("ns3::HybridBuildingsPropagationLossModel"));
376  lena->SetPathlossModelAttribute ("ShadowSigmaOutdoor", DoubleValue (0.0));
377  lena->SetPathlossModelAttribute ("ShadowSigmaIndoor", DoubleValue (0.0));
378  lena->SetPathlossModelAttribute ("ShadowSigmaExtWalls", DoubleValue (0.0));
379 
380  // Create Devices and install them in the Nodes (eNB and UE)
381  NetDeviceContainer enbDevs;
382  NetDeviceContainer ueDevs;
383  lena->SetSchedulerType ("ns3::RrFfMacScheduler");
385 
386  enbDevs = lena->InstallEnbDevice (enbNodes);
387  ueDevs = lena->InstallUeDevice (ueNodes);
388 
389  // Attach a UE to one eNB (the others are interfering ones)
390  lena->Attach (ueDevs, enbDevs.Get (0));
391 
392  // Activate an EPS bearer
394  EpsBearer bearer (q);
395  lena->ActivateEpsBearer (ueDevs, bearer, EpcTft::Default ());
396 
397  // Set UEs' position and power
398  for (int i = 0; i < m_nEnb; i++)
399  {
400  // place the HeNB over the default rooftop level (20 mt.)
402  mm->SetPosition (Vector (0.0, 0.0, 30.0));
403  Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (i)->GetObject<LteEnbNetDevice> ();
404  Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy ();
405  enbPhy->SetAttribute ("TxPower", DoubleValue (43.0));
406  enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0));
407  }
408 
409  // Set UEs' position and power
411  mm->SetPosition (Vector (m_dist, 0.0, 1.0));
412  Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (0)->GetObject<LteUeNetDevice> ();
413  Ptr<LteUePhy> uePhy = lteUeDev->GetPhy ();
414  uePhy->SetAttribute ("TxPower", DoubleValue (23.0));
415  uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0));
416 
417 
418  lena->EnableRlcTraces ();
419  double simulationTime = 1.000;
420 
421  Simulator::Stop (Seconds (simulationTime));
422 
423  Ptr<RadioBearerStatsCalculator> rlcStats = lena->GetRlcStats ();
424  rlcStats->SetAttribute ("EpochDuration", TimeValue (Seconds (simulationTime)));
425 
426 
427  Simulator::Run ();
428 
432  NS_LOG_INFO ("\tTest downlink control channels (PCFICH+PDCCH)");
433  NS_LOG_INFO ("Test with " << m_nEnb << " eNB(s) at distance " << m_dist << " expected BER " << m_berRef);
434  std::vector <uint64_t> dlDataRxed;
435  int nUser = 1;
436  for (int i = 0; i < nUser; i++)
437  {
438  // get the imsi
439  uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
440  // get the lcId
441  uint8_t lcId = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetRrc ()->GetLcIdVector ().at (0);
442  dlDataRxed.push_back (rlcStats->GetDlRxData (imsi, lcId));
443  double txed = rlcStats->GetDlTxData (imsi, lcId);
444  double ber = 1.0 - ((double)dlDataRxed.at (i)/txed);
445  NS_LOG_INFO ("\tUser " << i << " imsi " << imsi << " bytes rxed " << (double)dlDataRxed.at (i) << " txed " << txed
446  << " BER " << ber << " Err " << fabs (m_berRef - ber));
447  NS_UNUSED (ber);
448  NS_TEST_ASSERT_MSG_EQ_TOL (ber, m_berRef, 0.1, " Unexpected BER distribution!");
449  }
450 
451 
453 }
454 
455 
456 } // namespace