A Discrete-Event Network Simulator
API
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 
38 #include "ns3/lte-global-pathloss-database.h"
39 
41 
42 using namespace ns3;
43 
44 NS_LOG_COMPONENT_DEFINE ("LteAntennaTest");
45 
46 
48 {
49 public:
50  static std::string BuildNameString (double orientationDegrees, double beamwidthDegrees, double x, double y);
51  LteEnbAntennaTestCase (double orientationDegrees, double beamwidthDegrees, double x, double y, double antennaGainDb);
53  virtual ~LteEnbAntennaTestCase ();
54 
55 private:
56  virtual void DoRun (void);
57 
60  double m_x;
61  double m_y;
63 };
64 
65 
66 
67 
68 std::string LteEnbAntennaTestCase::BuildNameString (double orientationDegrees, double beamwidthDegrees, double x, double y)
69 {
70  std::ostringstream oss;
71  oss << "o=" << orientationDegrees
72  << ", bw=" << beamwidthDegrees
73  << ", x=" << x
74  << ", y=" << y;
75  return oss.str ();
76 }
77 
78 
79 LteEnbAntennaTestCase::LteEnbAntennaTestCase (double orientationDegrees, double beamwidthDegrees, double x, double y, double antennaGainDb)
80  : TestCase (BuildNameString (orientationDegrees, beamwidthDegrees, x, y)),
81  m_orientationDegrees (orientationDegrees),
82  m_beamwidthDegrees (beamwidthDegrees),
83  m_x (x),
84  m_y (y),
85  m_antennaGainDb (antennaGainDb)
86 {
87  NS_LOG_FUNCTION (this);
88 }
89 
91 {
92 }
93 
94 void
96 {
97  Config::Reset ();
98  Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (false));
99  Config::SetDefault ("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue (false));
100  Config::SetDefault ("ns3::LteHelper::UseIdealRrc", BooleanValue (true));
101 
102  //Disable Uplink Power Control
103  Config::SetDefault ("ns3::LteUePhy::EnableUplinkPowerControl", BooleanValue (false));
104 
105  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
106 
107  // use 0dB Pathloss, since we are testing only the antenna gain
108  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::ConstantSpectrumPropagationLossModel"));
109  lteHelper->SetPathlossModelAttribute ("Loss", DoubleValue (0.0));
110 
111  // Create Nodes: eNodeB and UE
112  NodeContainer enbNodes;
113  NodeContainer ueNodes;
114  enbNodes.Create (1);
115  ueNodes.Create (1);
116  NodeContainer allNodes = NodeContainer ( enbNodes, ueNodes );
117 
118  // Install Mobility Model
119  Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> ();
120  positionAlloc->Add (Vector (0.0, 0.0, 0.0)); // eNB
121  positionAlloc->Add (Vector (m_x, m_y, 0.0)); // UE
122  MobilityHelper mobility;
123  mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel");
124  mobility.SetPositionAllocator (positionAlloc);
125  mobility.Install (allNodes);
126 
127  // Create Devices and install them in the Nodes (eNB and UE)
128  NetDeviceContainer enbDevs;
129  NetDeviceContainer ueDevs;
130  lteHelper->SetSchedulerType ("ns3::RrFfMacScheduler");
131  lteHelper->SetSchedulerAttribute ("UlCqiFilter", EnumValue (FfMacScheduler::PUSCH_UL_CQI));
132  lteHelper->SetEnbAntennaModelType ("ns3::CosineAntennaModel");
133  lteHelper->SetEnbAntennaModelAttribute ("Orientation", DoubleValue (m_orientationDegrees));
134  lteHelper->SetEnbAntennaModelAttribute ("Beamwidth", DoubleValue (m_beamwidthDegrees));
135  lteHelper->SetEnbAntennaModelAttribute ("MaxGain", DoubleValue (0.0));
136 
137  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
138  ueDevs = lteHelper->InstallUeDevice (ueNodes);
139 
140  // Attach a UE to a eNB
141  lteHelper->Attach (ueDevs, enbDevs.Get (0));
142 
143  // Activate the default EPS bearer
144  enum EpsBearer::Qci q = EpsBearer::NGBR_VIDEO_TCP_DEFAULT;
145  EpsBearer bearer (q);
146  lteHelper->ActivateDataRadioBearer (ueDevs, bearer);
147 
148  // Use testing chunk processor in the PHY layer
149  // It will be used to test that the SNR is as intended
150  Ptr<LtePhy> uePhy = ueDevs.Get (0)->GetObject<LteUeNetDevice> ()->GetPhy ()->GetObject<LtePhy> ();
151  Ptr<LteTestSinrChunkProcessor> testDlSinr = Create<LteTestSinrChunkProcessor> ();
152  uePhy->GetDownlinkSpectrumPhy ()->AddDataSinrChunkProcessor (testDlSinr);
153 
154  Ptr<LtePhy> enbphy = enbDevs.Get (0)->GetObject<LteEnbNetDevice> ()->GetPhy ()->GetObject<LtePhy> ();
155  Ptr<LteTestSinrChunkProcessor> testUlSinr = Create<LteTestSinrChunkProcessor> ();
156  enbphy->GetUplinkSpectrumPhy ()->AddDataSinrChunkProcessor (testUlSinr);
157 
158 
159  // keep track of all path loss values in two centralized objects
161  UplinkLteGlobalPathlossDatabase ulPathlossDb;
162  // we rely on the fact that LteHelper creates the DL channel object first, then the UL channel object,
163  // hence the former will have index 0 and the latter 1
164  Config::Connect ("/ChannelList/0/PathLoss",
165  MakeCallback (&DownlinkLteGlobalPathlossDatabase::UpdatePathloss, &dlPathlossDb));
166  Config::Connect ("/ChannelList/1/PathLoss",
167  MakeCallback (&UplinkLteGlobalPathlossDatabase::UpdatePathloss, &ulPathlossDb));
168 
169  Simulator::Stop (Seconds (0.035));
170  Simulator::Run ();
171 
172  const double enbTxPowerDbm = 30; // default eNB TX power over whole bandwidth
173  const double ueTxPowerDbm = 10; // default UE TX power over whole bandwidth
174  const double ktDbm = -174; // reference LTE noise PSD
175  const double noisePowerDbm = ktDbm + 10 * std::log10 (25 * 180000); // corresponds to kT*bandwidth in linear units
176  const double ueNoiseFigureDb = 9.0; // default UE noise figure
177  const double enbNoiseFigureDb = 5.0; // default eNB noise figure
178  double tolerance = (m_antennaGainDb != 0) ? std::abs (m_antennaGainDb) * 0.001 : 0.001;
179 
180  // first test with SINR from LteTestSinrChunkProcessor
181  // this can only be done for not-too-bad SINR otherwise the measurement won't be available
182  double expectedSinrDl = enbTxPowerDbm + m_antennaGainDb - noisePowerDbm + ueNoiseFigureDb;
183  if (expectedSinrDl > 0)
184  {
185  double calculatedSinrDbDl = -INFINITY;
186  if (testDlSinr->GetSinr () != 0)
187  {
188  calculatedSinrDbDl = 10.0 * std::log10 (testDlSinr->GetSinr ()->operator[] (0));
189  }
190  // remember that propagation loss is 0dB
191  double calculatedAntennaGainDbDl = - (enbTxPowerDbm - calculatedSinrDbDl - noisePowerDbm - ueNoiseFigureDb);
192  NS_TEST_ASSERT_MSG_EQ_TOL (calculatedAntennaGainDbDl, m_antennaGainDb, tolerance, "Wrong DL antenna gain!");
193  }
194  double expectedSinrUl = ueTxPowerDbm + m_antennaGainDb - noisePowerDbm + enbNoiseFigureDb;
195  if (expectedSinrUl > 0)
196  {
197  double calculatedSinrDbUl = -INFINITY;
198  if (testUlSinr->GetSinr () != 0)
199  {
200  calculatedSinrDbUl = 10.0 * std::log10 (testUlSinr->GetSinr ()->operator[] (0));
201  }
202  double calculatedAntennaGainDbUl = - (ueTxPowerDbm - calculatedSinrDbUl - noisePowerDbm - enbNoiseFigureDb);
203  NS_TEST_ASSERT_MSG_EQ_TOL (calculatedAntennaGainDbUl, m_antennaGainDb, tolerance, "Wrong UL antenna gain!");
204  }
205 
206 
207  // repeat the same tests with the LteGlobalPathlossDatabases
208  double measuredLossDl = dlPathlossDb.GetPathloss (1, 1);
209  NS_TEST_ASSERT_MSG_EQ_TOL (measuredLossDl, -m_antennaGainDb, tolerance, "Wrong DL loss!");
210  double measuredLossUl = ulPathlossDb.GetPathloss (1, 1);
211  NS_TEST_ASSERT_MSG_EQ_TOL (measuredLossUl, -m_antennaGainDb, tolerance, "Wrong UL loss!");
212 
213 
214  Simulator::Destroy ();
215 }
216 
217 
219 {
220 public:
222 };
223 
224 
226  : TestSuite ("lte-antenna", SYSTEM)
227 {
228  NS_LOG_FUNCTION (this);
229 
230  // orientation beamwidth x y gain
231  AddTestCase (new LteEnbAntennaTestCase ( 0.0, 90.0, 1.0, 0.0, 0.0), TestCase::QUICK);
232  AddTestCase (new LteEnbAntennaTestCase ( 0.0, 90.0, 1.0, 1.0, -3.0), TestCase::QUICK);
233  AddTestCase (new LteEnbAntennaTestCase ( 0.0, 90.0, 1.0, -1.0, -3.0), TestCase::QUICK);
234  AddTestCase (new LteEnbAntennaTestCase ( 0.0, 90.0, -1.0, -1.0, -36.396), TestCase::QUICK);
235  AddTestCase (new LteEnbAntennaTestCase ( 0.0, 90.0, -1.0, -0.0, -1414.6), TestCase::QUICK);
236  AddTestCase (new LteEnbAntennaTestCase ( 0.0, 90.0, -1.0, 1.0, -36.396), TestCase::QUICK);
237  AddTestCase (new LteEnbAntennaTestCase ( 45.0, 90.0, 1.0, 1.0, 0.0), TestCase::QUICK);
238  AddTestCase (new LteEnbAntennaTestCase ( -45.0, 90.0, 1.0, -1.0, 0.0), TestCase::QUICK);
239  AddTestCase (new LteEnbAntennaTestCase ( 90.0, 90.0, 1.0, 1.0, -3.0), TestCase::QUICK);
240  AddTestCase (new LteEnbAntennaTestCase ( -90.0, 90.0, 1.0, -1.0, -3.0), TestCase::QUICK);
241 
242  AddTestCase (new LteEnbAntennaTestCase ( 0.0, 120.0, 1.0, 0.0, 0.0), TestCase::QUICK);
243  AddTestCase (new LteEnbAntennaTestCase ( 0.0, 120.0, 0.5, sin(M_PI/3), -3.0), TestCase::QUICK);
244  AddTestCase (new LteEnbAntennaTestCase ( 0.0, 120.0, 0.5, -sin(M_PI/3), -3.0), TestCase::QUICK);
245  AddTestCase (new LteEnbAntennaTestCase ( 0.0, 120.0, -1.0, -2.0, -13.410), TestCase::QUICK);
246  AddTestCase (new LteEnbAntennaTestCase ( 0.0, 120.0, -1.0, 1.0, -20.034), TestCase::QUICK);
247  AddTestCase (new LteEnbAntennaTestCase ( 60.0, 120.0, 0.5, sin(M_PI/3), 0.0), TestCase::QUICK);
248  AddTestCase (new LteEnbAntennaTestCase ( -60.0, 120.0, 0.5, -sin(M_PI/3), 0.0), TestCase::QUICK);
249  AddTestCase (new LteEnbAntennaTestCase ( -60.0, 120.0, 0.5, -sin(M_PI/3), 0.0), TestCase::QUICK);
250  AddTestCase (new LteEnbAntennaTestCase ( -120.0, 120.0, -0.5, -sin(M_PI/3), 0.0), TestCase::QUICK);
251  AddTestCase (new LteEnbAntennaTestCase ( -120.0, 120.0, 0.5, -sin(M_PI/3), -3.0), TestCase::QUICK);
252  AddTestCase (new LteEnbAntennaTestCase ( -120.0, 120.0, -1, 0, -3.0), TestCase::QUICK);
253  AddTestCase (new LteEnbAntennaTestCase ( -120.0, 120.0, -1, 2, -15.578), TestCase::QUICK);
254  AddTestCase (new LteEnbAntennaTestCase ( -120.0, 120.0, 1, 0, -14.457), TestCase::QUICK);
255  AddTestCase (new LteEnbAntennaTestCase ( -120.0, 120.0, 1, 2, -73.154), TestCase::QUICK);
256  AddTestCase (new LteEnbAntennaTestCase ( -120.0, 120.0, 1, -0.1, -12.754), TestCase::QUICK);
257 
258 
259 }
260 
void SetPathlossModelAttribute(std::string n, const AttributeValue &v)
Set an attribute for the path loss models to be created.
Definition: lte-helper.cc:299
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
AttributeValue implementation for Boolean.
Definition: boolean.h:34
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Create a set of eNodeB devices.
Definition: lte-helper.cc:382
void Reset(void)
Reset the initial value of every attribute as well as the value of every global to what they were bef...
Definition: config.cc:652
Hold variables of type string.
Definition: string.h:41
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr stored in this container at a given index.
A suite of tests to run.
Definition: test.h:1270
void Attach(NetDeviceContainer ueDevices)
Enables automatic attachment of a set of UE devices to a suitable cell using Idle mode initial cell s...
Definition: lte-helper.cc:716
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
Ptr< LteSpectrumPhy > GetUplinkSpectrumPhy()
Definition: lte-phy.cc:109
encapsulates test code
Definition: test.h:1102
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:738
void ActivateDataRadioBearer(NetDeviceContainer ueDevices, EpsBearer bearer)
Activate a Data Radio Bearer on a given UE devices (for LTE-only simulation).
Definition: lte-helper.cc:1046
void SetSchedulerType(std::string type)
Set the type of scheduler to be used by eNodeB devices.
Definition: lte-helper.cc:225
This class contains the specification of EPS Bearers.
Definition: eps-bearer.h:71
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:54
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:184
void SetSchedulerAttribute(std::string n, const AttributeValue &v)
Set an attribute for the scheduler to be created.
Definition: lte-helper.cc:239
holds a vector of ns3::NetDevice pointers
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1290
Ptr< LteSpectrumPhy > GetDownlinkSpectrumPhy()
Definition: lte-phy.cc:103
#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:356
void SetEnbAntennaModelType(std::string type)
Set the type of antenna model to be used by eNodeB devices.
Definition: lte-helper.cc:315
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:677
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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())
static std::string BuildNameString(double orientationDegrees, double beamwidthDegrees, double x, double y)
double GetPathloss(uint16_t cellId, uint64_t imsi)
NetDeviceContainer InstallUeDevice(NodeContainer c)
Create a set of UE devices.
Definition: lte-helper.cc:397
Helper class used to assign positions and mobility models to nodes.
static LteAntennaTestSuite lteAntennaTestSuite
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:859
void Add(Vector v)
Add a position to the list of positions.
void SetEnbAntennaModelAttribute(std::string n, const AttributeValue &v)
Set an attribute for the eNodeB antenna model to be created.
Definition: lte-helper.cc:322
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
virtual void DoRun(void)
Implementation to actually run this TestCase.
void SetPositionAllocator(Ptr< PositionAllocator > allocator)
Set the position allocator which will be used to allocate the initial position of every node initiali...
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:190
The eNodeB device implementation.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:455
Qci
QoS Class Indicator.
Definition: eps-bearer.h:77
The LtePhy models the physical layer of LTE.
Definition: lte-phy.h:52
The LteUeNetDevice class implements the UE net device.