A Discrete-Event Network Simulator
API
test-lte-antenna.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011, 2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Manuel Requena <manuel.requena@cttc.es>
18 * Nicola Baldo <nbaldo@cttc.es>
19 */
20
21#include "ns3/boolean.h"
22#include "ns3/double.h"
23#include "ns3/enum.h"
24#include "ns3/ff-mac-scheduler.h"
25#include "ns3/log.h"
26#include "ns3/lte-enb-net-device.h"
27#include "ns3/lte-enb-phy.h"
28#include "ns3/lte-global-pathloss-database.h"
29#include "ns3/lte-helper.h"
30#include "ns3/lte-ue-net-device.h"
31#include "ns3/lte-ue-phy.h"
32#include "ns3/mobility-helper.h"
33#include "ns3/simulator.h"
34#include "ns3/string.h"
35#include "ns3/test.h"
36#include <ns3/lte-chunk-processor.h>
37
38using namespace ns3;
39
40NS_LOG_COMPONENT_DEFINE("LteAntennaTest");
41
52{
53 public:
62 static std::string BuildNameString(double orientationDegrees,
63 double beamwidthDegrees,
64 double x,
65 double y);
75 LteEnbAntennaTestCase(double orientationDegrees,
76 double beamwidthDegrees,
77 double x,
78 double y,
79 double antennaGainDb);
81 ~LteEnbAntennaTestCase() override;
82
83 private:
84 void DoRun() override;
85
88 double m_x;
89 double m_y;
91};
92
93std::string
95 double beamwidthDegrees,
96 double x,
97 double y)
98{
99 std::ostringstream oss;
100 oss << "o=" << orientationDegrees << ", bw=" << beamwidthDegrees << ", x=" << x << ", y=" << y;
101 return oss.str();
102}
103
105 double beamwidthDegrees,
106 double x,
107 double y,
108 double antennaGainDb)
109 : TestCase(BuildNameString(orientationDegrees, beamwidthDegrees, x, y)),
110 m_orientationDegrees(orientationDegrees),
111 m_beamwidthDegrees(beamwidthDegrees),
112 m_x(x),
113 m_y(y),
114 m_antennaGainDb(antennaGainDb)
115{
116 NS_LOG_FUNCTION(this);
117}
118
120{
121}
122
123void
125{
127 Config::SetDefault("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue(false));
128 Config::SetDefault("ns3::LteSpectrumPhy::DataErrorModelEnabled", BooleanValue(false));
129 Config::SetDefault("ns3::LteHelper::UseIdealRrc", BooleanValue(true));
130
131 // Disable Uplink Power Control
132 Config::SetDefault("ns3::LteUePhy::EnableUplinkPowerControl", BooleanValue(false));
133
134 Ptr<LteHelper> lteHelper = CreateObject<LteHelper>();
135
136 // use 0dB Pathloss, since we are testing only the antenna gain
137 lteHelper->SetAttribute("PathlossModel",
138 StringValue("ns3::ConstantSpectrumPropagationLossModel"));
139 lteHelper->SetPathlossModelAttribute("Loss", DoubleValue(0.0));
140
141 // Create Nodes: eNodeB and UE
142 NodeContainer enbNodes;
143 NodeContainer ueNodes;
144 enbNodes.Create(1);
145 ueNodes.Create(1);
146 NodeContainer allNodes = NodeContainer(enbNodes, ueNodes);
147
148 // Install Mobility Model
149 Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator>();
150 positionAlloc->Add(Vector(0.0, 0.0, 0.0)); // eNB
151 positionAlloc->Add(Vector(m_x, m_y, 0.0)); // UE
153 mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel");
154 mobility.SetPositionAllocator(positionAlloc);
155 mobility.Install(allNodes);
156
157 // Create Devices and install them in the Nodes (eNB and UE)
158 NetDeviceContainer enbDevs;
159 NetDeviceContainer ueDevs;
160 lteHelper->SetSchedulerType("ns3::RrFfMacScheduler");
161 lteHelper->SetSchedulerAttribute("UlCqiFilter", EnumValue(FfMacScheduler::PUSCH_UL_CQI));
162 lteHelper->SetEnbAntennaModelType("ns3::CosineAntennaModel");
164 lteHelper->SetEnbAntennaModelAttribute("HorizontalBeamwidth", DoubleValue(m_beamwidthDegrees));
165 lteHelper->SetEnbAntennaModelAttribute("MaxGain", DoubleValue(0.0));
166
167 // set DL and UL bandwidth.
168 lteHelper->SetEnbDeviceAttribute("DlBandwidth", UintegerValue(25));
169 lteHelper->SetEnbDeviceAttribute("UlBandwidth", UintegerValue(25));
170
171 enbDevs = lteHelper->InstallEnbDevice(enbNodes);
172 ueDevs = lteHelper->InstallUeDevice(ueNodes);
173
174 // Attach a UE to a eNB
175 lteHelper->Attach(ueDevs, enbDevs.Get(0));
176
177 // Activate the default EPS bearer
178 enum EpsBearer::Qci q = EpsBearer::NGBR_VIDEO_TCP_DEFAULT;
179 EpsBearer bearer(q);
180 lteHelper->ActivateDataRadioBearer(ueDevs, bearer);
181
182 // Use testing chunk processor in the PHY layer
183 // It will be used to test that the SNR is as intended
184 Ptr<LtePhy> uePhy = ueDevs.Get(0)->GetObject<LteUeNetDevice>()->GetPhy()->GetObject<LtePhy>();
185 Ptr<LteChunkProcessor> testDlSinr = Create<LteChunkProcessor>();
186 LteSpectrumValueCatcher dlSinrCatcher;
187 testDlSinr->AddCallback(MakeCallback(&LteSpectrumValueCatcher::ReportValue, &dlSinrCatcher));
188 uePhy->GetDownlinkSpectrumPhy()->AddDataSinrChunkProcessor(testDlSinr);
189
190 Ptr<LtePhy> enbphy =
191 enbDevs.Get(0)->GetObject<LteEnbNetDevice>()->GetPhy()->GetObject<LtePhy>();
192 Ptr<LteChunkProcessor> testUlSinr = Create<LteChunkProcessor>();
193 LteSpectrumValueCatcher ulSinrCatcher;
194 testUlSinr->AddCallback(MakeCallback(&LteSpectrumValueCatcher::ReportValue, &ulSinrCatcher));
195 enbphy->GetUplinkSpectrumPhy()->AddDataSinrChunkProcessor(testUlSinr);
196
197 // keep track of all path loss values in two centralized objects
200 // we rely on the fact that LteHelper creates the DL channel object first, then the UL channel
201 // object, hence the former will have index 0 and the latter 1
203 "/ChannelList/0/PathLoss",
204 MakeCallback(&DownlinkLteGlobalPathlossDatabase::UpdatePathloss, &dlPathlossDb));
205 Config::Connect("/ChannelList/1/PathLoss",
206 MakeCallback(&UplinkLteGlobalPathlossDatabase::UpdatePathloss, &ulPathlossDb));
207
208 Simulator::Stop(Seconds(0.035));
209 Simulator::Run();
210
211 const double enbTxPowerDbm = 30; // default eNB TX power over whole bandwidth
212 const double ueTxPowerDbm = 10; // default UE TX power over whole bandwidth
213 const double ktDbm = -174; // reference LTE noise PSD
214 const double noisePowerDbm =
215 ktDbm + 10 * std::log10(25 * 180000); // corresponds to kT*bandwidth in linear units
216 const double ueNoiseFigureDb = 9.0; // default UE noise figure
217 const double enbNoiseFigureDb = 5.0; // default eNB noise figure
218 double tolerance = (m_antennaGainDb != 0) ? std::abs(m_antennaGainDb) * 0.001 : 0.001;
219
220 // first test with SINR from LteChunkProcessor
221 // this can only be done for not-too-bad SINR otherwise the measurement won't be available
222 double expectedSinrDl = enbTxPowerDbm + m_antennaGainDb - noisePowerDbm + ueNoiseFigureDb;
223 if (expectedSinrDl > 0)
224 {
225 double calculatedSinrDbDl = -INFINITY;
226 if (dlSinrCatcher.GetValue())
227 {
228 calculatedSinrDbDl = 10.0 * std::log10(dlSinrCatcher.GetValue()->operator[](0));
229 }
230 // remember that propagation loss is 0dB
231 double calculatedAntennaGainDbDl =
232 -(enbTxPowerDbm - calculatedSinrDbDl - noisePowerDbm - ueNoiseFigureDb);
233 NS_LOG_INFO("expected " << m_antennaGainDb << " actual " << calculatedAntennaGainDbDl
234 << " tol " << tolerance);
235 NS_TEST_ASSERT_MSG_EQ_TOL(calculatedAntennaGainDbDl,
237 tolerance,
238 "Wrong DL antenna gain!");
239 }
240 double expectedSinrUl = ueTxPowerDbm + m_antennaGainDb - noisePowerDbm + enbNoiseFigureDb;
241 if (expectedSinrUl > 0)
242 {
243 double calculatedSinrDbUl = -INFINITY;
244 if (ulSinrCatcher.GetValue())
245 {
246 calculatedSinrDbUl = 10.0 * std::log10(ulSinrCatcher.GetValue()->operator[](0));
247 }
248 double calculatedAntennaGainDbUl =
249 -(ueTxPowerDbm - calculatedSinrDbUl - noisePowerDbm - enbNoiseFigureDb);
250 NS_TEST_ASSERT_MSG_EQ_TOL(calculatedAntennaGainDbUl,
252 tolerance,
253 "Wrong UL antenna gain!");
254 }
255
256 // repeat the same tests with the LteGlobalPathlossDatabases
257 double measuredLossDl = dlPathlossDb.GetPathloss(1, 1);
258 NS_TEST_ASSERT_MSG_EQ_TOL(measuredLossDl, -m_antennaGainDb, tolerance, "Wrong DL loss!");
259 double measuredLossUl = ulPathlossDb.GetPathloss(1, 1);
260 NS_TEST_ASSERT_MSG_EQ_TOL(measuredLossUl, -m_antennaGainDb, tolerance, "Wrong UL loss!");
261
262 Simulator::Destroy();
263}
264
272{
273 public:
275};
276
278 : TestSuite("lte-antenna", SYSTEM)
279{
280 NS_LOG_FUNCTION(this);
281
282 // orientation beamwidth x y gain
283 AddTestCase(new LteEnbAntennaTestCase(0.0, 90.0, 1.0, 0.0, 0.0), TestCase::QUICK);
284 AddTestCase(new LteEnbAntennaTestCase(0.0, 90.0, 1.0, 1.0, -3.0), TestCase::QUICK);
285 AddTestCase(new LteEnbAntennaTestCase(0.0, 90.0, 1.0, -1.0, -3.0), TestCase::QUICK);
286 AddTestCase(new LteEnbAntennaTestCase(0.0, 90.0, -1.0, -1.0, -36.396), TestCase::QUICK);
287 AddTestCase(new LteEnbAntennaTestCase(0.0, 90.0, -1.0, -0.0, -1414.6), TestCase::QUICK);
288 AddTestCase(new LteEnbAntennaTestCase(0.0, 90.0, -1.0, 1.0, -36.396), TestCase::QUICK);
289 AddTestCase(new LteEnbAntennaTestCase(45.0, 90.0, 1.0, 1.0, 0.0), TestCase::QUICK);
290 AddTestCase(new LteEnbAntennaTestCase(-45.0, 90.0, 1.0, -1.0, 0.0), TestCase::QUICK);
291 AddTestCase(new LteEnbAntennaTestCase(90.0, 90.0, 1.0, 1.0, -3.0), TestCase::QUICK);
292 AddTestCase(new LteEnbAntennaTestCase(-90.0, 90.0, 1.0, -1.0, -3.0), TestCase::QUICK);
293
294 AddTestCase(new LteEnbAntennaTestCase(0.0, 120.0, 1.0, 0.0, 0.0), TestCase::QUICK);
295 AddTestCase(new LteEnbAntennaTestCase(0.0, 120.0, 0.5, sin(M_PI / 3), -3.0), TestCase::QUICK);
296 AddTestCase(new LteEnbAntennaTestCase(0.0, 120.0, 0.5, -sin(M_PI / 3), -3.0), TestCase::QUICK);
297 AddTestCase(new LteEnbAntennaTestCase(0.0, 120.0, -1.0, -2.0, -13.410), TestCase::QUICK);
298 AddTestCase(new LteEnbAntennaTestCase(0.0, 120.0, -1.0, 1.0, -20.034), TestCase::QUICK);
299 AddTestCase(new LteEnbAntennaTestCase(60.0, 120.0, 0.5, sin(M_PI / 3), 0.0), TestCase::QUICK);
300 AddTestCase(new LteEnbAntennaTestCase(-60.0, 120.0, 0.5, -sin(M_PI / 3), 0.0), TestCase::QUICK);
301 AddTestCase(new LteEnbAntennaTestCase(-60.0, 120.0, 0.5, -sin(M_PI / 3), 0.0), TestCase::QUICK);
302 AddTestCase(new LteEnbAntennaTestCase(-120.0, 120.0, -0.5, -sin(M_PI / 3), 0.0),
303 TestCase::QUICK);
304 AddTestCase(new LteEnbAntennaTestCase(-120.0, 120.0, 0.5, -sin(M_PI / 3), -3.0),
305 TestCase::QUICK);
306 AddTestCase(new LteEnbAntennaTestCase(-120.0, 120.0, -1, 0, -3.0), TestCase::QUICK);
307 AddTestCase(new LteEnbAntennaTestCase(-120.0, 120.0, -1, 2, -15.578), TestCase::QUICK);
308 AddTestCase(new LteEnbAntennaTestCase(-120.0, 120.0, 1, 0, -14.457), TestCase::QUICK);
309 AddTestCase(new LteEnbAntennaTestCase(-120.0, 120.0, 1, 2, -73.154), TestCase::QUICK);
310 AddTestCase(new LteEnbAntennaTestCase(-120.0, 120.0, 1, -0.1, -12.754), TestCase::QUICK);
311}
312
Lte Enb Antenna Test Suite.
Tests that the propagation model and the antenna parameters are generate the correct values.
double m_orientationDegrees
antenna orientation in degrees
double m_antennaGainDb
antenna gain in dB
static std::string BuildNameString(double orientationDegrees, double beamwidthDegrees, double x, double y)
Build name string.
double m_x
x position of the UE
double m_beamwidthDegrees
antenna beamwidth in degrees
double m_y
y position of the UE
void DoRun() override
Implementation to actually run this TestCase.
AttributeValue implementation for Boolean.
Definition: boolean.h:37
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
Hold variables of type enum.
Definition: enum.h:56
This class contains the specification of EPS Bearers.
Definition: eps-bearer.h:91
Qci
QoS Class Indicator.
Definition: eps-bearer.h:106
The eNodeB device implementation.
double GetPathloss(uint16_t cellId, uint64_t imsi)
void SetSchedulerAttribute(std::string n, const AttributeValue &v)
Set an attribute for the scheduler to be created.
Definition: lte-helper.cc:303
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Create a set of eNodeB devices.
Definition: lte-helper.cc:482
void SetEnbAntennaModelType(std::string type)
Set the type of antenna model to be used by eNodeB devices.
Definition: lte-helper.cc:416
void SetSchedulerType(std::string type)
Set the type of scheduler to be used by eNodeB devices.
Definition: lte-helper.cc:289
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:1044
void SetPathlossModelAttribute(std::string n, const AttributeValue &v)
Set an attribute for the path loss models to be created.
Definition: lte-helper.cc:402
void SetEnbAntennaModelAttribute(std::string n, const AttributeValue &v)
Set an attribute for the eNodeB antenna model to be created.
Definition: lte-helper.cc:423
void SetEnbDeviceAttribute(std::string n, const AttributeValue &v)
Set an attribute for the eNodeB devices (LteEnbNetDevice) to be created.
Definition: lte-helper.cc:409
void ActivateDataRadioBearer(NetDeviceContainer ueDevices, EpsBearer bearer)
Activate a Data Radio Bearer on a given UE devices (for LTE-only simulation).
Definition: lte-helper.cc:1441
NetDeviceContainer InstallUeDevice(NodeContainer c)
Create a set of UE devices.
Definition: lte-helper.cc:497
The LtePhy models the physical layer of LTE.
Definition: lte-phy.h:50
A sink to be plugged to the callback of LteChunkProcessor allowing to save and later retrieve the lat...
Ptr< SpectrumValue > GetValue()
The LteUeNetDevice class implements the UE net device.
Helper class used to assign positions and mobility models to nodes.
holds a vector of ns3::NetDevice pointers
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
keep track of a set of node pointers.
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:258
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:471
Hold variables of type string.
Definition: string.h:42
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:305
A suite of tests to run.
Definition: test.h:1256
Hold an unsigned integer type.
Definition: uinteger.h:45
void Reset()
Reset the initial value of every attribute as well as the value of every global to what they were bef...
Definition: config.cc:856
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:891
void Connect(std::string path, const CallbackBase &cb)
Definition: config.cc:975
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
#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:337
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1338
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:691
mobility
Definition: third.py:96
static LteAntennaTestSuite lteAntennaTestSuite