A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
test-lte-antenna.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011, 2012 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: Manuel Requena <manuel.requena@cttc.es>
19  * Nicola Baldo <nbaldo@cttc.es>
20  */
21 
22 #include "ns3/simulator.h"
23 #include "ns3/log.h"
24 #include "ns3/string.h"
25 #include "ns3/double.h"
26 #include "ns3/test.h"
27 #include "ns3/mobility-helper.h"
28 #include "ns3/lte-helper.h"
29 
30 #include "ns3/lte-ue-phy.h"
31 #include "ns3/lte-ue-net-device.h"
32 #include "ns3/lte-enb-phy.h"
33 #include "ns3/lte-enb-net-device.h"
34 
36 
37 NS_LOG_COMPONENT_DEFINE ("LteAntennaTest");
38 
39 namespace ns3 {
40 
41 
42 
44 {
45 public:
46  static std::string BuildNameString (double orientationDegrees, double beamwidthDegrees, double x, double y);
47  LteEnbAntennaTestCase (double orientationDegrees, double beamwidthDegrees, double x, double y, double antennaGainDb);
49  virtual ~LteEnbAntennaTestCase ();
50 
51 private:
52  virtual void DoRun (void);
53 
56  double m_x;
57  double m_y;
59 };
60 
61 
62 
63 
64 std::string LteEnbAntennaTestCase::BuildNameString (double orientationDegrees, double beamwidthDegrees, double x, double y)
65 {
66  std::ostringstream oss;
67  oss << "o=" << orientationDegrees
68  << ", bw=" << beamwidthDegrees
69  << ", x=" << x
70  << ", y=" << y;
71  return oss.str ();
72 }
73 
74 
75 LteEnbAntennaTestCase::LteEnbAntennaTestCase (double orientationDegrees, double beamwidthDegrees, double x, double y, double antennaGainDb)
76  : TestCase (BuildNameString (orientationDegrees, beamwidthDegrees, x, y)),
77  m_orientationDegrees (orientationDegrees),
78  m_beamwidthDegrees (beamwidthDegrees),
79  m_x (x),
80  m_y (y),
81  m_antennaGainDb (antennaGainDb)
82 {
83  NS_LOG_FUNCTION (this);
84 }
85 
87 {
88 }
89 
90 void
92 {
93 
94  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
95 
96  // use 0dB Pathloss, since we are testing only the antenna gain
97  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::ConstantSpectrumPropagationLossModel"));
98  lteHelper->SetPathlossModelAttribute ("Loss", DoubleValue (0.0));
99 
100  // Create Nodes: eNodeB and UE
101  NodeContainer enbNodes;
102  NodeContainer ueNodes;
103  enbNodes.Create (1);
104  ueNodes.Create (1);
105  NodeContainer allNodes = NodeContainer ( enbNodes, ueNodes );
106 
107  // Install Mobility Model
108  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
109  positionAlloc->Add (Vector (0.0, 0.0, 0.0)); // eNB
110  positionAlloc->Add (Vector (m_x, m_y, 0.0)); // UE
111  MobilityHelper mobility;
112  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
113  mobility.SetPositionAllocator (positionAlloc);
114  mobility.Install (allNodes);
115 
116  // Create Devices and install them in the Nodes (eNB and UE)
117  NetDeviceContainer enbDevs;
118  NetDeviceContainer ueDevs;
119  lteHelper->SetSchedulerType ("ns3::RrFfMacScheduler");
120  lteHelper->SetEnbAntennaModelType ("ns3::CosineAntennaModel");
121  lteHelper->SetEnbAntennaModelAttribute ("Orientation", DoubleValue (m_orientationDegrees));
122  lteHelper->SetEnbAntennaModelAttribute ("Beamwidth", DoubleValue (m_beamwidthDegrees));
123  lteHelper->SetEnbAntennaModelAttribute ("MaxGain", DoubleValue (0.0));
124 
125  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
126  ueDevs = lteHelper->InstallUeDevice (ueNodes);
127 
128  // Attach a UE to a eNB
129  lteHelper->Attach (ueDevs, enbDevs.Get (0));
130 
131  // Activate the default EPS bearer
133  EpsBearer bearer (q);
134  lteHelper->ActivateEpsBearer (ueDevs, bearer, EpcTft::Default ());
135 
136  // Use testing chunk processor in the PHY layer
137  // It will be used to test that the SNR is as intended
138  Ptr<LtePhy> uePhy = ueDevs.Get (0)->GetObject<LteUeNetDevice> ()->GetPhy ()->GetObject<LtePhy> ();
139  Ptr<LteTestSinrChunkProcessor> testDlSinr = Create<LteTestSinrChunkProcessor> (uePhy);
140  uePhy->GetDownlinkSpectrumPhy ()->AddSinrChunkProcessor (testDlSinr);
141 
142  Ptr<LtePhy> enbphy = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ()->GetPhy ()->GetObject<LtePhy> ();
143  Ptr<LteTestSinrChunkProcessor> testUlSinr = Create<LteTestSinrChunkProcessor> (enbphy);
144  enbphy->GetUplinkSpectrumPhy ()->AddSinrChunkProcessor (testUlSinr);
145 
146 
147  Simulator::Stop (Seconds (0.020));
148  Simulator::Run ();
149 
150 
151  const double enbTxPowerDbm = 30; // default eNB TX power over whole bandwdith
152  const double ueTxPowerDbm = 10; // default UE TX power over whole bandwdith
153  const double ktDbm = -174; // reference LTE noise PSD
154  const double noisePowerDbm = ktDbm + 10 * log10 (25 * 180000); // corresponds to kT*bandwidth in linear units
155  const double ueNoiseFigureDb = 9.0; // default UE noise figure
156  const double enbNoiseFigureDb = 5.0; // default eNB noise figure
157 
158  double calculatedSinrDbDl = -INFINITY;
159  if (testDlSinr->GetSinr () != 0)
160  {
161  calculatedSinrDbDl = 10.0 * log10 (testDlSinr->GetSinr ()->operator[] (0));
162  }
163  double calculatedSinrDbUl = -INFINITY;
164  if (testUlSinr->GetSinr () != 0)
165  {
166  calculatedSinrDbUl = 10.0 * log10 (testUlSinr->GetSinr ()->operator[] (0));
167  }
168 
169  // remember that propagation loss is 0dB
170  double calculatedAntennaGainDbDl = - (enbTxPowerDbm - calculatedSinrDbDl - noisePowerDbm - ueNoiseFigureDb);
171  double calculatedAntennaGainDbUl = - (ueTxPowerDbm - calculatedSinrDbUl - noisePowerDbm - enbNoiseFigureDb);
172  double tolerance = (m_antennaGainDb != 0) ? abs (m_antennaGainDb)*0.001 : 0.001;
173  NS_TEST_ASSERT_MSG_EQ_TOL (calculatedAntennaGainDbDl, m_antennaGainDb, tolerance, "Wrong DL antenna gain!");
174  NS_TEST_ASSERT_MSG_EQ_TOL (calculatedAntennaGainDbUl, m_antennaGainDb, tolerance, "Wrong UL antenna gain!");
175 
177 }
178 
179 
181 {
182 public:
184 };
185 
186 
188  : TestSuite ("lte-antenna", SYSTEM)
189 {
190  NS_LOG_FUNCTION (this);
191 
192  // orientation beamwidth x y gain
193  AddTestCase (new LteEnbAntennaTestCase ( 0.0, 90.0, 1.0, 0.0, 0.0));
194  AddTestCase (new LteEnbAntennaTestCase ( 0.0, 90.0, 1.0, 1.0, -3.0));
195  AddTestCase (new LteEnbAntennaTestCase ( 0.0, 90.0, 1.0, -1.0, -3.0));
196  AddTestCase (new LteEnbAntennaTestCase ( 0.0, 90.0, -1.0, -1.0, -36.396));
197  AddTestCase (new LteEnbAntennaTestCase ( 0.0, 90.0, -1.0, -0.0, -1414.6));
198  AddTestCase (new LteEnbAntennaTestCase ( 0.0, 90.0, -1.0, 1.0, -36.396));
199  AddTestCase (new LteEnbAntennaTestCase ( 45.0, 90.0, 1.0, 1.0, 0.0));
200  AddTestCase (new LteEnbAntennaTestCase ( -45.0, 90.0, 1.0, -1.0, 0.0));
201  AddTestCase (new LteEnbAntennaTestCase ( 90.0, 90.0, 1.0, 1.0, -3.0));
202  AddTestCase (new LteEnbAntennaTestCase ( -90.0, 90.0, 1.0, -1.0, -3.0));
203 
204  AddTestCase (new LteEnbAntennaTestCase ( 0.0, 120.0, 1.0, 0.0, 0.0));
205  AddTestCase (new LteEnbAntennaTestCase ( 0.0, 120.0, 0.5, sin(M_PI/3), -3.0));
206  AddTestCase (new LteEnbAntennaTestCase ( 0.0, 120.0, 0.5, -sin(M_PI/3), -3.0));
207  AddTestCase (new LteEnbAntennaTestCase ( 0.0, 120.0, -1.0, -2.0, -13.410));
208  AddTestCase (new LteEnbAntennaTestCase ( 0.0, 120.0, -1.0, 1.0, -20.034));
209  AddTestCase (new LteEnbAntennaTestCase ( 60.0, 120.0, 0.5, sin(M_PI/3), 0.0));
210  AddTestCase (new LteEnbAntennaTestCase ( -60.0, 120.0, 0.5, -sin(M_PI/3), 0.0));
211  AddTestCase (new LteEnbAntennaTestCase ( -60.0, 120.0, 0.5, -sin(M_PI/3), 0.0));
212  AddTestCase (new LteEnbAntennaTestCase ( -120.0, 120.0, -0.5, -sin(M_PI/3), 0.0));
213  AddTestCase (new LteEnbAntennaTestCase ( -120.0, 120.0, 0.5, -sin(M_PI/3), -3.0));
214  AddTestCase (new LteEnbAntennaTestCase ( -120.0, 120.0, -1, 0, -3.0));
215  AddTestCase (new LteEnbAntennaTestCase ( -120.0, 120.0, -1, 2, -15.578));
216  AddTestCase (new LteEnbAntennaTestCase ( -120.0, 120.0, 1, 0, -14.457));
217  AddTestCase (new LteEnbAntennaTestCase ( -120.0, 120.0, 1, 2, -73.154));
218  AddTestCase (new LteEnbAntennaTestCase ( -120.0, 120.0, 1, -0.1, -12.754));
219 
220 
221 }
222 
224 
225 
226 } // namespace ns3
227