A Discrete-Event Network Simulator
API
lte-test-fading.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2 /*
3 * Copyright (c) 2011 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 */
20 
21 #include "ns3/simulator.h"
22 #include "ns3/log.h"
23 #include "ns3/spectrum-test.h"
24 #include "ns3/lte-phy-tag.h"
25 #include "ns3/lte-test-ue-phy.h"
26 #include "ns3/lte-chunk-processor.h"
27 #include "ns3/lte-test-fading.h"
28 #include <ns3/buildings-propagation-loss-model.h>
29 #include <ns3/node-container.h>
30 #include <ns3/mobility-helper.h>
31 #include <ns3/lte-helper.h>
32 #include <ns3/single-model-spectrum-channel.h>
33 #include "ns3/string.h"
34 #include "ns3/double.h"
35 #include <ns3/building.h>
36 #include <ns3/enum.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-enb-phy.h>
42 #include <ns3/lte-ue-phy.h>
43 #include "lte-test-sinr-chunk-processor.h"
44 
45 using namespace ns3;
46 
47 NS_LOG_COMPONENT_DEFINE ("LteFadingTest");
48 
60 : TestSuite ("lte-fading-model", SYSTEM)
61 {
62 
63 
64  // -------------- COMPOUND TESTS ----------------------------------
65 
66  LogComponentEnable ("LteFadingTest", LOG_LEVEL_ALL);
67 
68  // NS_LOG_INFO ("Creating LteDownlinkSinrTestSuite");
69 
70  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
71 
72  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::BuildingsPropagationLossModel"));
73 
74  // Create Nodes: eNodeB, home eNB, UE and home UE (UE attached to HeNB)
75  NodeContainer enbNodes;
76  NodeContainer henbNodes;
77  NodeContainer ueNodes;
78  NodeContainer hueNodes;
79  enbNodes.Create (1);
80  henbNodes.Create (2);
81  ueNodes.Create (5);
82  hueNodes.Create (3);
83 
84  // Install Mobility Model
86  mobility.SetMobilityModel ("ns3::BuildingsMobilityModel");
87  mobility.Install (enbNodes);
88  mobility.Install (henbNodes);
89  mobility.Install (ueNodes);
90  mobility.Install (hueNodes);
91 
92  NetDeviceContainer enbDevs;
93  NetDeviceContainer henbDevs;
94  NetDeviceContainer ueDevs;
95  NetDeviceContainer hueDevs;
96  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
97  ueDevs = lteHelper->InstallUeDevice (ueNodes);
98  henbDevs = lteHelper->InstallEnbDevice (henbNodes);
99  hueDevs = lteHelper->InstallUeDevice (hueNodes);
100 
101 
102 
103  lteHelper->Attach (ueDevs, enbDevs.Get (0));
104  lteHelper->Attach (hueDevs, henbDevs.Get (0));
105 
106  // Test #1 Okumura Hata Model (150 < freq < 1500 MHz) (Macro<->UE)
107 
108  double distance = 2000;
109  double hm = 1;
110  double hb = 30;
111 // double freq = 869e6; // E_UTRA BAND #5 see table 5.5-1 of 36.101
112  Ptr<BuildingsMobilityModel> mm1 = enbNodes.Get (0)->GetObject<BuildingsMobilityModel> ();
113  mm1->SetPosition (Vector (0.0, 0.0, hb));
114 
115  Ptr<BuildingsMobilityModel> mm2 = ueNodes.Get (0)->GetObject<BuildingsMobilityModel> ();
116  mm2->SetPosition (Vector (distance, 0.0, hm));
117 
118  AddTestCase (new LteFadingTestCase (mm1, mm2, 137.93, "OH Urban Large city"), TestCase::QUICK);
119 
120 
121 }
122 
124 
125 
131 : TestCase ("FADING calculation: " + name),
132 m_node1 (m1),
133 m_node2 (m2),
134 m_lossRef (refValue)
135 {
136 }
137 
139 {
140 }
141 
142 void
144 {
145  // LogLevel logLevel = (LogLevel)(LOG_PREFIX_FUNC | LOG_PREFIX_TIME | LOG_LEVEL_ALL);
146 
147  // LogComponentEnable ("LteEnbRrc", logLevel);
148  // LogComponentEnable ("LteUeRrc", logLevel);
149  // LogComponentEnable ("LteEnbMac", logLevel);
150  // LogComponentEnable ("LteUeMac", logLevel);
151  // LogComponentEnable ("LteRlc", logLevel);
152  // LogComponentEnable ("RrPacketScheduler", logLevel);
153  //
154  // LogComponentEnable ("LtePhy", logLevel);
155  // LogComponentEnable ("LteEnbPhy", logLevel);
156  // LogComponentEnable ("LteUePhy", logLevel);
157  //
158  // LogComponentEnable ("LteSpectrumPhy", logLevel);
159  // LogComponentEnable ("LteInterference", logLevel);
160  // LogComponentEnable ("LteChunkProcessor", logLevel);
161  //
162  // LogComponentEnable ("LtePropagationLossModel", logLevel);
163  // LogComponentEnable ("LossModel", logLevel);
164  // LogComponentEnable ("ShadowingLossModel", logLevel);
165  // LogComponentEnable ("PenetrationLossModel", logLevel);
166  // LogComponentEnable ("MultipathLossModel", logLevel);
167  // LogComponentEnable ("PathLossModel", logLevel);
168  //
169  // LogComponentEnable ("LteNetDevice", logLevel);
170  // LogComponentEnable ("LteUeNetDevice", logLevel);
171  // LogComponentEnable ("LteEnbNetDevice", logLevel);
172 
173  LogComponentEnable ("TraceFadingLossModel", LOG_LEVEL_ALL);
174 // LogComponentEnable ("TraceFadingLossModel", LOG_LEVEL_ALL);
175 // LogComponentEnable ("BuildingsPropagationLossModel", LOG_LEVEL_ALL);
176  NS_LOG_INFO ("Testing " << GetName());
177 
178 
179  m_fadingModule = CreateObject<TraceFadingLossModel> ();
180 
181  m_fadingModule->SetAttribute("TraceFilename", StringValue("../../../src/lte/model/fading-traces/fading_trace_EPA_3kmph.fad"));
182  //m_fadingModule->SetAttribute("WindowSize", TimeValue(Seconds (0.003)));
183 
184  m_fadingModule->CreateFadingChannelRealization (m_node1, m_node2);
185 
186 // Ptr<SpectrumModel> sm;
187 //
188 // Bands bands;
189 // BandInfo bi;
190 //
191 // bi.fl = 2.400e9;
192 // bi.fc = 2.410e9;
193 // bi.fh = 2.420e9;
194 // bands.push_back (bi);
195 //
196 // bi.fl = 2.420e9;
197 // bi.fc = 2.431e9;
198 // bi.fh = 2.442e9;
199 // bands.push_back (bi);
200 //
201 // sm = Create<SpectrumModel> (bands);
202 //
203 // /**
204 // * TX signal #1: Power Spectral Density (W/Hz) of the signal = [0 0] dBm and BW = [20 22] MHz
205 // */
206 // Ptr<SpectrumValue> inPsd1 = Create<SpectrumValue> (sm);
207 // (*inPsd1)[0] = 1.;
208 // (*inPsd1)[1] = 1.;
209 // Ptr<SpectrumValue> outPsd1 = Create<SpectrumValue> (sm);
210 // outPsd1 = m_fadingModule->CalcRxPowerSpectralDensity (inPsd1, m_node1, m_node2);
211 //
212 // NS_LOG_INFO ("A ver " << (*outPsd1)[0] << " " << (*outPsd1)[1]);
213  double samplingInterval = 0.001;
214  double time = 0.0;
215  while (time<0.010)
216  {
217  Time t = Seconds (time);
218  Simulator::Schedule(t, &LteFadingTestCase::GetFadingSample, this);
219  time += samplingInterval;
220  }
221  Simulator::Stop (Seconds (10.1));
222  Simulator::Run ();
223  Simulator::Destroy ();
224 // double loss = m_downlinkPropagationLossModel->GetLoss (m_node1, m_node2);
225  time = 0.0;
226  int rbNum = 2;
227  std::vector<double> sum (rbNum);
228  std::vector<double> sumSquared (rbNum);
229  for (int i = 0; i < rbNum; i++)
230  {
231  sum.at (i) = 0.;
232  sumSquared.at (i) = 0.;
233  }
234  for (std::vector<SpectrumValue>::size_type i = 0; i != m_fadingSamples.size (); i++)
235  {
236  NS_LOG_INFO ("Sample time " << time << " : " << m_fadingSamples.at(i)[0] << " " << m_fadingSamples.at(i)[1]);
237  time += samplingInterval;
238  for (int j = 0; j < rbNum; j++)
239  {
240  sum.at (j) += m_fadingSamples.at(i)[j];
241  sumSquared.at (j) += (m_fadingSamples.at(i)[j]*m_fadingSamples.at(i)[j]);
242  }
243  }
244 // NS_LOG_INFO ("Calculated loss: " << loss);
245  NS_LOG_INFO ("Theoretical loss: " << m_lossRef);
246  for (int i = 0; i < rbNum; i++)
247  {
248  double mean = sum.at (i)/m_fadingSamples.size ();
249  double sigma = sqrt(sumSquared.at (i)/m_fadingSamples.size () - (mean*mean));
250  NS_LOG_INFO (" Mean " << mean << " sigma " << sigma);
251  }
252 
253  // NS_TEST_ASSERT_MSG_EQ_TOL(loss, m_lossRef, 0.1, "Wrong loss !");
254 }
255 
256 
257 void
259 {
261 
262  Bands bands;
263  BandInfo bi;
264 
265  bi.fl = 2.400e9;
266  bi.fc = 2.410e9;
267  bi.fh = 2.420e9;
268  bands.push_back (bi);
269 
270  bi.fl = 2.420e9;
271  bi.fc = 2.431e9;
272  bi.fh = 2.442e9;
273  bands.push_back (bi);
274 
275  sm = Create<SpectrumModel> (bands);
276 
280  Ptr<SpectrumValue> inPsd1 = Create<SpectrumValue> (sm);
281  (*inPsd1)[0] = 1.;
282  (*inPsd1)[1] = 1.;
283  Ptr<SpectrumValue> outPsd1 = Create<SpectrumValue> (sm);
285  (*outPsd1)[0] = (10 * std::log10 (180000*(*outPsd1)[0])) - (10 * std::log10 (180000*(*inPsd1)[0]));
286  (*outPsd1)[1] = (10 * std::log10 (180000*(*outPsd1)[1])) - (10 * std::log10 (180000*(*inPsd1)[1]));
287  m_fadingSamples.push_back ((*outPsd1));
288 }
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Ptr< BuildingsMobilityModel > m_node2
building mobility model #2
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Create a set of eNodeB devices.
Definition: lte-helper.cc:474
Hold variables of type string.
Definition: string.h:41
std::vector< SpectrumValue > m_fadingSamples
fading samples
A suite of tests to run.
Definition: test.h:1342
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:957
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:278
const double m1
First component modulus, 232 - 209.
Definition: rng-stream.cc:57
encapsulates test code
Definition: test.h:1155
std::vector< BandInfo > Bands
Container of BandInfo.
Ptr< TraceFadingLossModel > m_fadingModule
fading loss model
mobility
Definition: third.py:101
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:369
static LteFadingTestSuite lteFadingTestSuite
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
virtual void DoRun(void)
Implementation to actually run this TestCase.
double fc
center frequency
LteFadingTestSuite()
Test 1.1 Fading compound test.
holds a vector of ns3::NetDevice pointers
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:459
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double fl
lower limit of subband
keep track of a set of node pointers.
Ptr< BuildingsMobilityModel > m_node1
building mobility model #1
Fading test case is checking if the pathloss between macro and UE is equal to the theoretical value w...
virtual ~LteFadingTestCase()
Test 1.1 fading model.
NetDeviceContainer InstallUeDevice(NodeContainer c)
Create a set of UE devices.
Definition: lte-helper.cc:489
Helper class used to assign positions and mobility models to nodes.
std::string GetName(void) const
Definition: test.cc:370
Ptr< SpectrumValue > CalcRxPowerSpectralDensity(Ptr< const SpectrumValue > txPsd, Ptr< const MobilityModel > a, Ptr< const MobilityModel > b) const
This method is to be called to calculate.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
LteFadingTestCase(Ptr< BuildingsMobilityModel > m1, Ptr< BuildingsMobilityModel > m2, double refValue, std::string name)
Lte Fading Test Case function.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Print everything.
Definition: log.h:113
const double m2
Second component modulus, 232 - 22853.
Definition: rng-stream.cc:60
void Create(uint32_t n)
Create n nodes and append pointers to them to the end of this NodeContainer.
double fh
upper limit of subband
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:185
The building block of a SpectrumModel.
double m_lossRef
loss reference