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