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_blerRef (blerRef),
117  m_toleranceRxPackets (toleranceRxPackets)
118 {
119 }
120 
122 {
123 }
124 
125 void
127 {
128 
129  double ber = 0.03;
130  Config::SetDefault ("ns3::LteAmc::Ber", DoubleValue (ber));
131  Config::SetDefault ("ns3::LteAmc::AmcModel", EnumValue (LteAmc::PiroEW2010));
132  Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (false));
133  Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (true));
134  Config::SetDefault ("ns3::RrFfMacScheduler::HarqEnabled", BooleanValue (false));
135 
136 
141  Ptr<LteHelper> lena = CreateObject<LteHelper> ();
142 
143  // Create Nodes: eNodeB and UE
144  NodeContainer enbNodes;
145  NodeContainer ueNodes;
146  enbNodes.Create (1);
147  ueNodes.Create (m_nUser);
148 
149  // Install Mobility Model
150  MobilityHelper mobility;
151  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
152  mobility.Install (enbNodes);
153  BuildingsHelper::Install (enbNodes);
154  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
155  mobility.Install (ueNodes);
156  BuildingsHelper::Install (ueNodes);
157 
158  // remove random shadowing component
159  lena->SetAttribute ("PathlossModel", StringValue ("ns3::HybridBuildingsPropagationLossModel"));
160  lena->SetPathlossModelAttribute ("ShadowSigmaOutdoor", DoubleValue (0.0));
161  lena->SetPathlossModelAttribute ("ShadowSigmaIndoor", DoubleValue (0.0));
162  lena->SetPathlossModelAttribute ("ShadowSigmaExtWalls", DoubleValue (0.0));
163 
164  // Create Devices and install them in the Nodes (eNB and UE)
165  NetDeviceContainer enbDevs;
166  NetDeviceContainer ueDevs;
167  lena->SetSchedulerType ("ns3::RrFfMacScheduler");
168  lena->SetSchedulerAttribute ("UlCqiFilter", EnumValue (FfMacScheduler::PUSCH_UL_CQI));
169 
170  enbDevs = lena->InstallEnbDevice (enbNodes);
171  ueDevs = lena->InstallUeDevice (ueNodes);
172 
173  // Attach a UE to a eNB
174  lena->Attach (ueDevs, enbDevs.Get (0));
175 
176  // Activate an EPS bearer
178  EpsBearer bearer (q);
179  lena->ActivateDataRadioBearer (ueDevs, bearer);
180 
181 
182  Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ();
183  Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy ();
184  enbPhy->SetAttribute ("TxPower", DoubleValue (43.0));
185  enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0));
186  // place the HeNB over the default rooftop level (20 mt.)
187  Ptr<MobilityModel> mm = enbNodes.Get (0)->GetObject<MobilityModel> ();
188  mm->SetPosition (Vector (0.0, 0.0, 30.0));
189 
190  // Set UEs' position and power
191  for (int i = 0; i < m_nUser; i++)
192  {
193  Ptr<MobilityModel> mm = ueNodes.Get (i)->GetObject<MobilityModel> ();
194  mm->SetPosition (Vector (m_dist, 0.0, 1.0));
195  Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (i)->GetObject<LteUeNetDevice> ();
196  Ptr<LteUePhy> uePhy = lteUeDev->GetPhy ();
197  uePhy->SetAttribute ("TxPower", DoubleValue (23.0));
198  uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0));
199  }
200 
201  lena->EnableRlcTraces ();
202  Time simulationTime = Seconds (1.000);
203 
204  Simulator::Stop (simulationTime);
205 
206  Ptr<RadioBearerStatsCalculator> rlcStats = lena->GetRlcStats ();
207  rlcStats->SetAttribute ("EpochDuration", TimeValue (simulationTime));
208 
209 
210  Simulator::Run ();
211 
212  NS_LOG_INFO ("\tTest downlink data shared channels (PDSCH)");
213  NS_LOG_INFO ("Test with " << m_nUser << " user(s) at distance " << m_dist << " expected BLER " << m_blerRef);
214  for (int i = 0; i < m_nUser; i++)
215  {
216  // get the imsi
217  uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
218  uint8_t lcId = 3;
219 
220  double dlRxPackets = rlcStats->GetDlRxPackets (imsi, lcId);
221  double dlTxPackets = rlcStats->GetDlTxPackets (imsi, lcId);
222  double dlBler = 1.0 - (dlRxPackets/dlTxPackets);
223  double expectedDlRxPackets = dlTxPackets -dlTxPackets*m_blerRef;
224  NS_LOG_INFO ("\tUser " << i << " imsi " << imsi << " DOWNLINK"
225  << " pkts rx " << dlRxPackets << " tx " << dlTxPackets
226  << " BLER " << dlBler << " Err " << std::fabs (m_blerRef - dlBler)
227  << " expected rx " << expectedDlRxPackets
228  << " difference " << std::abs (expectedDlRxPackets - dlRxPackets)
229  << " tolerance " << m_toleranceRxPackets);
230  NS_UNUSED (dlBler);
231 
232  // sanity check for whether the tx packets reported by the stats are correct
233  // we expect one packet per TTI, excluding the initial RRC connection establishment period
234  double expectedDlMinTxPackets = simulationTime.GetMilliSeconds () - 50;
235  NS_TEST_ASSERT_MSG_GT (dlTxPackets, expectedDlMinTxPackets, " too few DL TX packets reported");
236 
237  // the quantiles are evaluated offline according to a Bernoulli
238  // ditribution with n equal to the number of packet sent and p equal
239  // to the BLER (see /reference/bernuolliDistribution.m for details)
240  NS_TEST_ASSERT_MSG_EQ_TOL (dlRxPackets, expectedDlRxPackets, m_toleranceRxPackets, " Unexpected DL BLER distribution!");
241 
242 
243  }
244 
245 
247 }
248 
249 
250 
251 
252 std::string
254 {
255  std::ostringstream oss;
256  oss << nEnb << " eNBs, distance " << dist << " m";
257  return oss.str ();
258 }
259 
260 
261 LenaDlCtrlPhyErrorModelTestCase::LenaDlCtrlPhyErrorModelTestCase (uint16_t nEnb, uint16_t dist, uint16_t tbSize, double blerRef)
262 : TestCase (BuildNameString (nEnb, dist)),
263 m_nEnb (nEnb),
264 m_dist (dist),
265 m_blerRef (blerRef)
266 {
267 }
268 
270 {
271 }
272 
273 void
275 {
276 
277  double ber = 0.03;
278  Config::SetDefault ("ns3::LteAmc::Ber", DoubleValue (ber));
279  Config::SetDefault ("ns3::LteAmc::AmcModel", EnumValue (LteAmc::PiroEW2010));
280  Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (true));
281  Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (false));
282  Config::SetDefault ("ns3::RrFfMacScheduler::HarqEnabled", BooleanValue (false));
283 
288  Ptr<LteHelper> lena = CreateObject<LteHelper> ();
289 
290  // Create Nodes: eNodeB and UE
291  NodeContainer enbNodes;
292  NodeContainer ueNodes;
293  enbNodes.Create (m_nEnb);
294  ueNodes.Create (1);
295 
296  // Install Mobility Model
297  MobilityHelper mobility;
298  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
299  mobility.Install (enbNodes);
300  BuildingsHelper::Install (enbNodes);
301  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
302  mobility.Install (ueNodes);
303  BuildingsHelper::Install (ueNodes);
304 
305  // remove random shadowing component
306  lena->SetAttribute ("PathlossModel", StringValue ("ns3::HybridBuildingsPropagationLossModel"));
307  lena->SetPathlossModelAttribute ("ShadowSigmaOutdoor", DoubleValue (0.0));
308  lena->SetPathlossModelAttribute ("ShadowSigmaIndoor", DoubleValue (0.0));
309  lena->SetPathlossModelAttribute ("ShadowSigmaExtWalls", DoubleValue (0.0));
310 
311  // Create Devices and install them in the Nodes (eNB and UE)
312  NetDeviceContainer enbDevs;
313  NetDeviceContainer ueDevs;
314  lena->SetSchedulerType ("ns3::RrFfMacScheduler");
315  lena->SetSchedulerAttribute ("UlCqiFilter", EnumValue (FfMacScheduler::PUSCH_UL_CQI));
316 
317  enbDevs = lena->InstallEnbDevice (enbNodes);
318  ueDevs = lena->InstallUeDevice (ueNodes);
319 
320  // Attach a UE to one eNB (the others are interfering ones)
321  lena->Attach (ueDevs, enbDevs.Get (0));
322 
323  // Activate an EPS bearer
325  EpsBearer bearer (q);
326  lena->ActivateDataRadioBearer (ueDevs, bearer);
327 
328  // Set UEs' position and power
329  for (int i = 0; i < m_nEnb; i++)
330  {
331  // place the HeNB over the default rooftop level (20 mt.)
332  Ptr<MobilityModel> mm = enbNodes.Get (i)->GetObject<MobilityModel> ();
333  mm->SetPosition (Vector (0.0, 0.0, 30.0));
334  Ptr<LteEnbNetDevice> lteEnbDev = enbDevs.Get (i)->GetObject<LteEnbNetDevice> ();
335  Ptr<LteEnbPhy> enbPhy = lteEnbDev->GetPhy ();
336  enbPhy->SetAttribute ("TxPower", DoubleValue (43.0));
337  enbPhy->SetAttribute ("NoiseFigure", DoubleValue (5.0));
338  }
339 
340  // Set UEs' position and power
341  Ptr<MobilityModel> mm = ueNodes.Get (0)->GetObject<MobilityModel> ();
342  mm->SetPosition (Vector (m_dist, 0.0, 1.0));
343  Ptr<LteUeNetDevice> lteUeDev = ueDevs.Get (0)->GetObject<LteUeNetDevice> ();
344  Ptr<LteUePhy> uePhy = lteUeDev->GetPhy ();
345  uePhy->SetAttribute ("TxPower", DoubleValue (23.0));
346  uePhy->SetAttribute ("NoiseFigure", DoubleValue (9.0));
347 
348 
349  lena->EnableRlcTraces ();
350  Time simulationTime = Seconds (1.000);
351 
352  Simulator::Stop (simulationTime);
353 
354  Ptr<RadioBearerStatsCalculator> rlcStats = lena->GetRlcStats ();
355  rlcStats->SetAttribute ("EpochDuration", TimeValue (simulationTime));
356 
357 
358  Simulator::Run ();
359 
360  NS_LOG_INFO ("\tTest downlink control channels (PCFICH+PDCCH)");
361  NS_LOG_INFO ("Test with " << m_nEnb << " eNB(s) at distance " << m_dist << " expected BLER " << m_blerRef);
362  int nUser = 1;
363  for (int i = 0; i < nUser; i++)
364  {
365  // get the imsi
366  uint64_t imsi = ueDevs.Get (i)->GetObject<LteUeNetDevice> ()->GetImsi ();
367  uint8_t lcId = 3;
368  double dlRxPackets = rlcStats->GetDlRxPackets (imsi, lcId);
369  double dlTxPackets = rlcStats->GetDlTxPackets (imsi, lcId);
370  double bler = 1.0 - (dlRxPackets/dlTxPackets);
371  NS_LOG_INFO ("\tUser " << i << " imsi " << imsi
372  << " pkts rx " << dlRxPackets << " tx " << dlTxPackets
373  << " BLER " << bler << " Err " << fabs (m_blerRef - bler));
374  NS_UNUSED (bler);
375 
376  // sanity check for whether the tx packets reported by the stats are correct
377  // we expect one packet per TTI, excluding the initial RRC connection establishment period
378  double expectedMinDlTxPackets = simulationTime.GetMilliSeconds () - 50;
379  NS_TEST_ASSERT_MSG_GT (dlTxPackets, expectedMinDlTxPackets, " too few TX packets reported");
380 
381  NS_TEST_ASSERT_MSG_EQ_TOL (bler, m_blerRef, 0.1, " Unexpected BLER distribution!");
382  }
383 
385 }
386 
387 
388 } // namespace
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
Hold a bool native type.
Definition: boolean.h:38
virtual void DoRun(void)
Implementation to actually run this TestCase.
static std::string BuildNameString(uint16_t nUser, uint16_t dist)
NS_LOG_COMPONENT_DEFINE("LenaTestPhyErrorModel")
hold variables of type string
Definition: string.h:19
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
LenaDataPhyErrorModelTestCase(uint16_t nUser, uint16_t dist, uint16_t tbSize, double refBler, uint16_t toleranceRxPackets)
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
Definition: test.h:326
A suite of tests to run.
Definition: test.h:1025
static void Run(void)
Definition: simulator.cc:157
#define NS_LOG_INFO(msg)
Definition: log.h:264
encapsulates test code
Definition: test.h:849
a 3d vector
Definition: vector.h:31
static std::string BuildNameString(uint16_t nUser, uint16_t dist)
Keep track of the current position and velocity of an object.
#define NS_TEST_ASSERT_MSG_GT(actual, limit, msg)
Test that an actual value is greater than a limit and report and abort if not.
Definition: test.h:773
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
hold variables of type 'enum'
Definition: enum.h:37
hold objects of type ns3::Time
Definition: nstime.h:828
virtual void DoRun(void)
Implementation to actually run this TestCase.
Medium length test.
Definition: test.h:858
holds a vector of ns3::NetDevice pointers
static void Destroy(void)
Definition: simulator.cc:121
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:667
keep track of a set of node pointers.
void SetMobilityModel(std::string type, std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition: test.cc:172
void SetPosition(const Vector &position)
Fast test.
Definition: test.h:857
Helper class used to assign positions and mobility models to nodes.
static void Stop(void)
Definition: simulator.cc:165
Ptr< Node > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
static LenaTestPhyErrorModelrSuite lenaTestPhyErrorModelrSuite
#define NS_UNUSED(x)
Definition: unused.h:5
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
LenaDlCtrlPhyErrorModelTestCase(uint16_t nEnbr, uint16_t dist, uint16_t tbSize, double refBler)
Hold an floating point type.
Definition: double.h:41
Ptr< T > GetObject(void) const
Definition: object.h:360
int64_t GetMilliSeconds(void) const
Definition: nstime.h:275
static void Install(Ptr< Node > node)