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-2013 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  */
21 
22 #include <ns3/object.h>
23 #include <ns3/spectrum-interference.h>
24 #include <ns3/spectrum-error-model.h>
25 #include <ns3/log.h>
26 #include <ns3/test.h>
27 #include <ns3/simulator.h>
28 #include <ns3/packet.h>
29 #include <ns3/ptr.h>
30 #include <iostream>
31 #include <ns3/radio-bearer-stats-calculator.h>
32 #include <ns3/mobility-building-info.h>
33 #include <ns3/hybrid-buildings-propagation-loss-model.h>
34 #include <ns3/eps-bearer.h>
35 #include <ns3/node-container.h>
36 #include <ns3/mobility-helper.h>
37 #include <ns3/net-device-container.h>
38 #include <ns3/lte-ue-net-device.h>
39 #include <ns3/lte-enb-net-device.h>
40 #include <ns3/lte-ue-rrc.h>
41 #include <ns3/lte-helper.h>
42 #include <ns3/string.h>
43 #include <ns3/double.h>
44 #include <ns3/lte-enb-phy.h>
45 #include <ns3/lte-ue-phy.h>
46 #include <ns3/config.h>
47 #include <ns3/boolean.h>
48 #include <ns3/enum.h>
49 #include <ns3/unused.h>
50 #include <ns3/ff-mac-scheduler.h>
51 #include <ns3/buildings-helper.h>
52 
54 
55 NS_LOG_COMPONENT_DEFINE ("LenaTestPhyErrorModel");
56 
57 namespace ns3 {
58 
59 
61  : TestSuite ("lte-phy-error-model", SYSTEM)
62 {
63  NS_LOG_INFO ("creating LenaTestPhyErrorModelTestCase");
64 
65 
66  // Tests on DL Control Channels (PCFICH+PDDCH)
67  // 1 interfering eNB SINR -2.0 BLER 0.007 TB size 217
68  AddTestCase (new LenaDlCtrlPhyErrorModelTestCase (2, 1078, 217, 0.007), TestCase::QUICK);
69  // 2 interfering eNBs SINR -4.0 BLER 0.037 TB size 217
71  // 3 interfering eNBs SINR -6.0 BLER 0.21 TB size 133
73  // 4 interfering eNBs SINR -7.0 BLER 0.34 TB size 133
75 
76  // Tests on DL Data channels (PDSCH)
77  // the tolerance is calculated with the following octave code:
78  //
79  // n = 1000;
80  // for p=1-[0.33 0.11 0.2 0.3 0.55 0.14]
81  // tol = n*p - binoinv(0.005, n, p)
82  // endfor
83 
84  // MCS 2 TB size of 256 bits BLER 0.33 SINR -5.51
85  AddTestCase (new LenaDataPhyErrorModelTestCase (4, 1800, 32, 0.33, 39), TestCase::QUICK);
86 // MCS 2 TB size of 528 bits BLER 0.11 SINR -5.51
87  AddTestCase (new LenaDataPhyErrorModelTestCase (2, 1800, 66, 0.11, 26), TestCase::EXTENSIVE);
88 // MCS 2 TB size of 1088 bits BLER 0.02 SINR -5.51
89  AddTestCase (new LenaDataPhyErrorModelTestCase (1, 1800, 136, 0.02, 33), TestCase::EXTENSIVE);
90  // MCS 12 TB size of 4800 bits BLER 0.3 SINR 4.43
92 // MCS 12 TB size of 1632 bits BLER 0.55 SINR 4.43
93  AddTestCase (new LenaDataPhyErrorModelTestCase (3, 600, 204, 0.55, 40), TestCase::EXTENSIVE);
94 // MCS 16 TB size of 7272 bits (3648 x 3584) BLER 0.14 SINR 8.48
95 // BLER 0.14 = 1 - ((1-0.075)*(1-0.075))
96  AddTestCase (new LenaDataPhyErrorModelTestCase (1, 470, 781, 0.14, 29), TestCase::EXTENSIVE);
97 
98 
99 
100 }
101 
103 
104 std::string
105 LenaDataPhyErrorModelTestCase::BuildNameString (uint16_t nUser, uint16_t dist)
106 {
107  std::ostringstream oss;
108  oss << nUser << " UEs, distance " << dist << " m";
109  return oss.str ();
110 }
111 
112 LenaDataPhyErrorModelTestCase::LenaDataPhyErrorModelTestCase (uint16_t nUser, uint16_t dist, uint16_t tbSize, double blerRef, uint16_t toleranceRxPackets)
113  : TestCase (BuildNameString (nUser, dist)),
114  m_nUser (nUser),
115  m_dist (dist),
116  m_tbSize (tbSize),
117  m_blerRef (blerRef),
118  m_toleranceRxPackets (toleranceRxPackets)
119 {
120 }
121 
123 {
124 }
125 
126 void
128 {
129 
130  double ber = 0.03;
131  Config::SetDefault ("ns3::LteAmc::Ber", DoubleValue (ber));
132  Config::SetDefault ("ns3::LteAmc::AmcModel", EnumValue (LteAmc::PiroEW2010));
133  Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (false));
134  Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (true));
135  Config::SetDefault ("ns3::RrFfMacScheduler::HarqEnabled", BooleanValue (false));
136 
137 
142  Ptr<LteHelper> lena = CreateObject<LteHelper> ();
143 
144  // Create Nodes: eNodeB and UE
145  NodeContainer enbNodes;
146  NodeContainer ueNodes;
147  enbNodes.Create (1);
148  ueNodes.Create (m_nUser);
149 
150  // Install Mobility Model
151  MobilityHelper mobility;
152  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
153  mobility.Install (enbNodes);
154  BuildingsHelper::Install (enbNodes);
155  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
156  mobility.Install (ueNodes);
157  BuildingsHelper::Install (ueNodes);
158 
159  // remove random shadowing component
160  lena->SetAttribute ("PathlossModel", StringValue ("ns3::HybridBuildingsPropagationLossModel"));
161  lena->SetPathlossModelAttribute ("ShadowSigmaOutdoor", DoubleValue (0.0));
162  lena->SetPathlossModelAttribute ("ShadowSigmaIndoor", DoubleValue (0.0));
163  lena->SetPathlossModelAttribute ("ShadowSigmaExtWalls", DoubleValue (0.0));
164 
165  // Create Devices and install them in the Nodes (eNB and UE)
166  NetDeviceContainer enbDevs;
167  NetDeviceContainer ueDevs;
168  lena->SetSchedulerType ("ns3::RrFfMacScheduler");
170 
171  enbDevs = lena->InstallEnbDevice (enbNodes);
172  ueDevs = lena->InstallUeDevice (ueNodes);
173 
174  // Attach a UE to a eNB
175  lena->Attach (ueDevs, enbDevs.Get (0));
176 
177  // Activate an EPS bearer
179  EpsBearer bearer (q);
180  lena->ActivateDataRadioBearer (ueDevs, bearer);
181 
182 
183  Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ();
184  Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy ();
185  enbPhy->SetAttribute ("TxPower", DoubleValue (43.0));
186  enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0));
187  // place the HeNB over the default rooftop level (20 mt.)
188  Ptr<MobilityModel> mm = enbNodes.Get (0)->GetObject<MobilityModel> ();
189  mm->SetPosition (Vector (0.0, 0.0, 30.0));
190 
191  // Set UEs' position and power
192  for (int i = 0; i < m_nUser; i++)
193  {
194  Ptr<MobilityModel> mm = ueNodes.Get (i)->GetObject<MobilityModel> ();
195  mm->SetPosition (Vector (m_dist, 0.0, 1.0));
196  Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (i)->GetObject<LteUeNetDevice> ();
197  Ptr<LteUePhy> uePhy = lteUeDev->GetPhy ();
198  uePhy->SetAttribute ("TxPower", DoubleValue (23.0));
199  uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0));
200  }
201 
202  lena->EnableRlcTraces ();
203  Time simulationTime = Seconds (1.000);
204 
205  Simulator::Stop (simulationTime);
206 
207  Ptr<RadioBearerStatsCalculator> rlcStats = lena->GetRlcStats ();
208  rlcStats->SetAttribute ("EpochDuration", TimeValue (simulationTime));
209 
210 
211  Simulator::Run ();
212 
213  NS_LOG_INFO ("\tTest downlink data shared channels (PDSCH)");
214  NS_LOG_INFO ("Test with " << m_nUser << " user(s) at distance " << m_dist << " expected BLER " << m_blerRef);
215  for (int i = 0; i < m_nUser; i++)
216  {
217  // get the imsi
218  uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
219  uint8_t lcId = 3;
220 
221  double dlRxPackets = rlcStats->GetDlRxPackets (imsi, lcId);
222  double dlTxPackets = rlcStats->GetDlTxPackets (imsi, lcId);
223  double dlBler = 1.0 - (dlRxPackets/dlTxPackets);
224  double expectedDlRxPackets = dlTxPackets -dlTxPackets*m_blerRef;
225  NS_LOG_INFO ("\tUser " << i << " imsi " << imsi << " DOWNLINK"
226  << " pkts rx " << dlRxPackets << " tx " << dlTxPackets
227  << " BLER " << dlBler << " Err " << std::fabs (m_blerRef - dlBler)
228  << " expected rx " << expectedDlRxPackets
229  << " difference " << std::abs (expectedDlRxPackets - dlRxPackets)
230  << " tolerance " << m_toleranceRxPackets);
231  NS_UNUSED (dlBler);
232 
233  // sanity check for whether the tx packets reported by the stats are correct
234  // we expect one packet per TTI, excluding the initial RRC connection establishment period
235  double expectedDlMinTxPackets = simulationTime.GetMilliSeconds () - 50;
236  NS_TEST_ASSERT_MSG_GT (dlTxPackets, expectedDlMinTxPackets, " too few DL TX packets reported");
237 
238  // the quantiles are evaluated offline according to a Bernoulli
239  // ditribution with n equal to the number of packet sent and p equal
240  // to the BLER (see /reference/bernuolliDistribution.m for details)
241  NS_TEST_ASSERT_MSG_EQ_TOL (dlRxPackets, expectedDlRxPackets, m_toleranceRxPackets, " Unexpected DL BLER distribution!");
242 
243 
244  }
245 
246 
248 }
249 
250 
251 
252 
253 std::string
255 {
256  std::ostringstream oss;
257  oss << nEnb << " eNBs, distance " << dist << " m";
258  return oss.str ();
259 }
260 
261 
262 LenaDlCtrlPhyErrorModelTestCase::LenaDlCtrlPhyErrorModelTestCase (uint16_t nEnb, uint16_t dist, uint16_t tbSize, double blerRef)
263 : TestCase (BuildNameString (nEnb, dist)),
264 m_nEnb (nEnb),
265 m_dist (dist),
266 m_tbSize (tbSize),
267 m_blerRef (blerRef)
268 {
269 }
270 
272 {
273 }
274 
275 void
277 {
278 
279  double ber = 0.03;
280  Config::SetDefault ("ns3::LteAmc::Ber", DoubleValue (ber));
281  Config::SetDefault ("ns3::LteAmc::AmcModel", EnumValue (LteAmc::PiroEW2010));
282  Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (true));
283  Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (false));
284  Config::SetDefault ("ns3::RrFfMacScheduler::HarqEnabled", BooleanValue (false));
285 
290  Ptr<LteHelper> lena = CreateObject<LteHelper> ();
291 
292  // Create Nodes: eNodeB and UE
293  NodeContainer enbNodes;
294  NodeContainer ueNodes;
295  enbNodes.Create (m_nEnb);
296  ueNodes.Create (1);
297 
298  // Install Mobility Model
299  MobilityHelper mobility;
300  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
301  mobility.Install (enbNodes);
302  BuildingsHelper::Install (enbNodes);
303  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
304  mobility.Install (ueNodes);
305  BuildingsHelper::Install (ueNodes);
306 
307  // remove random shadowing component
308  lena->SetAttribute ("PathlossModel", StringValue ("ns3::HybridBuildingsPropagationLossModel"));
309  lena->SetPathlossModelAttribute ("ShadowSigmaOutdoor", DoubleValue (0.0));
310  lena->SetPathlossModelAttribute ("ShadowSigmaIndoor", DoubleValue (0.0));
311  lena->SetPathlossModelAttribute ("ShadowSigmaExtWalls", DoubleValue (0.0));
312 
313  // Create Devices and install them in the Nodes (eNB and UE)
314  NetDeviceContainer enbDevs;
315  NetDeviceContainer ueDevs;
316  lena->SetSchedulerType ("ns3::RrFfMacScheduler");
318 
319  enbDevs = lena->InstallEnbDevice (enbNodes);
320  ueDevs = lena->InstallUeDevice (ueNodes);
321 
322  // Attach a UE to one eNB (the others are interfering ones)
323  lena->Attach (ueDevs, enbDevs.Get (0));
324 
325  // Activate an EPS bearer
327  EpsBearer bearer (q);
328  lena->ActivateDataRadioBearer (ueDevs, bearer);
329 
330  // Set UEs' position and power
331  for (int i = 0; i < m_nEnb; i++)
332  {
333  // place the HeNB over the default rooftop level (20 mt.)
334  Ptr<MobilityModel> mm = enbNodes.Get (i)->GetObject<MobilityModel> ();
335  mm->SetPosition (Vector (0.0, 0.0, 30.0));
336  Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (i)->GetObject<LteEnbNetDevice> ();
337  Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy ();
338  enbPhy->SetAttribute ("TxPower", DoubleValue (43.0));
339  enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0));
340  }
341 
342  // Set UEs' position and power
343  Ptr<MobilityModel> mm = ueNodes.Get (0)->GetObject<MobilityModel> ();
344  mm->SetPosition (Vector (m_dist, 0.0, 1.0));
345  Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (0)->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  lena->EnableRlcTraces ();
352  Time simulationTime = Seconds (1.000);
353 
354  Simulator::Stop (simulationTime);
355 
356  Ptr<RadioBearerStatsCalculator> rlcStats = lena->GetRlcStats ();
357  rlcStats->SetAttribute ("EpochDuration", TimeValue (simulationTime));
358 
359 
360  Simulator::Run ();
361 
362  NS_LOG_INFO ("\tTest downlink control channels (PCFICH+PDCCH)");
363  NS_LOG_INFO ("Test with " << m_nEnb << " eNB(s) at distance " << m_dist << " expected BLER " << m_blerRef);
364  int nUser = 1;
365  for (int i = 0; i < nUser; i++)
366  {
367  // get the imsi
368  uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
369  uint8_t lcId = 3;
370  double dlRxPackets = rlcStats->GetDlRxPackets (imsi, lcId);
371  double dlTxPackets = rlcStats->GetDlTxPackets (imsi, lcId);
372  double bler = 1.0 - (dlRxPackets/dlTxPackets);
373  NS_LOG_INFO ("\tUser " << i << " imsi " << imsi
374  << " pkts rx " << dlRxPackets << " tx " << dlTxPackets
375  << " BLER " << bler << " Err " << fabs (m_blerRef - bler));
376  NS_UNUSED (bler);
377 
378  // sanity check for whether the tx packets reported by the stats are correct
379  // we expect one packet per TTI, excluding the initial RRC connection establishment period
380  double expectedMinDlTxPackets = simulationTime.GetMilliSeconds () - 50;
381  NS_TEST_ASSERT_MSG_GT (dlTxPackets, expectedMinDlTxPackets, " too few TX packets reported");
382 
383  NS_TEST_ASSERT_MSG_EQ_TOL (bler, m_blerRef, 0.1, " Unexpected BLER distribution!");
384  }
385 
387 }
388 
389 
390 } // namespace