A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
23 #include "ns3/log.h"
24 
25 #include "ns3/spectrum-test.h"
26 
27 #include "ns3/lte-phy-tag.h"
28 #include "ns3/lte-test-ue-phy.h"
29 #include "ns3/lte-chunk-processor.h"
30 
31 #include "ns3/lte-test-fading.h"
32 #include <ns3/buildings-propagation-loss-model.h>
33 #include <ns3/node-container.h>
34 #include <ns3/mobility-helper.h>
35 #include <ns3/lte-helper.h>
36 #include <ns3/single-model-spectrum-channel.h>
37 #include "ns3/string.h"
38 #include "ns3/double.h"
39 #include <ns3/building.h>
40 #include <ns3/enum.h>
41 #include <ns3/net-device-container.h>
42 #include <ns3/lte-ue-net-device.h>
43 #include <ns3/lte-enb-net-device.h>
44 #include <ns3/lte-ue-rrc.h>
45 #include <ns3/lte-helper.h>
46 #include <ns3/lte-enb-phy.h>
47 #include <ns3/lte-ue-phy.h>
48 #include "lte-test-sinr-chunk-processor.h"
49 
50 // #include <ns3/trace-fading-loss-model.h>
51 // #include <ns3/spectrum-value.h>
52 
53 using namespace ns3;
54 
55 NS_LOG_COMPONENT_DEFINE ("LteFadingTest");
56 
68 : TestSuite ("lte-fading-model", SYSTEM)
69 {
70 
71 
72  // -------------- COMPOUND TESTS ----------------------------------
73 
74  LogComponentEnable ("LteFadingTest", LOG_LEVEL_ALL);
75 
76  // NS_LOG_INFO ("Creating LteDownlinkSinrTestSuite");
77 
78  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
79 
80  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::BuildingsPropagationLossModel"));
81 
82  // Create Nodes: eNodeB, home eNB, UE and home UE (UE attached to HeNB)
83  NodeContainer enbNodes;
84  NodeContainer henbNodes;
85  NodeContainer ueNodes;
86  NodeContainer hueNodes;
87  enbNodes.Create (1);
88  henbNodes.Create (2);
89  ueNodes.Create (5);
90  hueNodes.Create (3);
91 
92  // Install Mobility Model
94  mobility.SetMobilityModel ("ns3::BuildingsMobilityModel");
95  mobility.Install (enbNodes);
96  mobility.Install (henbNodes);
97  mobility.Install (ueNodes);
98  mobility.Install (hueNodes);
99 
100  NetDeviceContainer enbDevs;
101  NetDeviceContainer henbDevs;
102  NetDeviceContainer ueDevs;
103  NetDeviceContainer hueDevs;
104  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
105  ueDevs = lteHelper->InstallUeDevice (ueNodes);
106  henbDevs = lteHelper->InstallEnbDevice (henbNodes);
107  hueDevs = lteHelper->InstallUeDevice (hueNodes);
108 
109 
110 
111  lteHelper->Attach (ueDevs, enbDevs.Get (0));
112  lteHelper->Attach (hueDevs, henbDevs.Get (0));
113 
114  // Test #1 Okumura Hata Model (150 < freq < 1500 MHz) (Macro<->UE)
115 
116  double distance = 2000;
117  double hm = 1;
118  double hb = 30;
119 // double freq = 869e6; // E_UTRA BAND #5 see table 5.5-1 of 36.101
120  Ptr<BuildingsMobilityModel> mm1 = enbNodes.Get (0)->GetObject<BuildingsMobilityModel> ();
121  mm1->SetPosition (Vector (0.0, 0.0, hb));
122 
123  Ptr<BuildingsMobilityModel> mm2 = ueNodes.Get (0)->GetObject<BuildingsMobilityModel> ();
124  mm2->SetPosition (Vector (distance, 0.0, hm));
125 
126  AddTestCase (new LteFadingTestCase (mm1, mm2, 137.93, "OH Urban Large city"), TestCase::QUICK);
127 
128 
129 }
130 
132 
133 
139 : TestCase ("FADING calculation: " + name),
140 m_node1 (m1),
141 m_node2 (m2),
142 m_lossRef (refValue)
143 {
144 }
145 
147 {
148 }
149 
150 void
152 {
153  // LogLevel logLevel = (LogLevel)(LOG_PREFIX_FUNC | LOG_PREFIX_TIME | LOG_LEVEL_ALL);
154 
155  // LogComponentEnable ("LteEnbRrc", logLevel);
156  // LogComponentEnable ("LteUeRrc", logLevel);
157  // LogComponentEnable ("LteEnbMac", logLevel);
158  // LogComponentEnable ("LteUeMac", logLevel);
159  // LogComponentEnable ("LteRlc", logLevel);
160  // LogComponentEnable ("RrPacketScheduler", logLevel);
161  //
162  // LogComponentEnable ("LtePhy", logLevel);
163  // LogComponentEnable ("LteEnbPhy", logLevel);
164  // LogComponentEnable ("LteUePhy", logLevel);
165  //
166  // LogComponentEnable ("LteSpectrumPhy", logLevel);
167  // LogComponentEnable ("LteInterference", logLevel);
168  // LogComponentEnable ("LteChunkProcessor", logLevel);
169  //
170  // LogComponentEnable ("LtePropagationLossModel", logLevel);
171  // LogComponentEnable ("LossModel", logLevel);
172  // LogComponentEnable ("ShadowingLossModel", logLevel);
173  // LogComponentEnable ("PenetrationLossModel", logLevel);
174  // LogComponentEnable ("MultipathLossModel", logLevel);
175  // LogComponentEnable ("PathLossModel", logLevel);
176  //
177  // LogComponentEnable ("LteNetDevice", logLevel);
178  // LogComponentEnable ("LteUeNetDevice", logLevel);
179  // LogComponentEnable ("LteEnbNetDevice", logLevel);
180 
181  LogComponentEnable ("TraceFadingLossModel", LOG_LEVEL_ALL);
182 // LogComponentEnable ("TraceFadingLossModel", LOG_LEVEL_ALL);
183 // LogComponentEnable ("BuildingsPropagationLossModel", LOG_LEVEL_ALL);
184  NS_LOG_INFO ("Testing " << GetName());
185 
186 
187  m_fadingModule = CreateObject<TraceFadingLossModel> ();
188 
189  m_fadingModule->SetAttribute("TraceFilename", StringValue("../../../src/lte/model/fading-traces/fading_trace_EPA_3kmph.fad"));
190  //m_fadingModule->SetAttribute("WindowSize", TimeValue(Seconds (0.003)));
191 
192  m_fadingModule->CreateFadingChannelRealization (m_node1, m_node2);
193 
194 // Ptr<SpectrumModel> sm;
195 //
196 // Bands bands;
197 // BandInfo bi;
198 //
199 // bi.fl = 2.400e9;
200 // bi.fc = 2.410e9;
201 // bi.fh = 2.420e9;
202 // bands.push_back (bi);
203 //
204 // bi.fl = 2.420e9;
205 // bi.fc = 2.431e9;
206 // bi.fh = 2.442e9;
207 // bands.push_back (bi);
208 //
209 // sm = Create<SpectrumModel> (bands);
210 //
211 // /**
212 // * TX signal #1: Power Spectral Density (W/Hz) of the signal = [0 0] dBm and BW = [20 22] MHz
213 // */
214 // Ptr<SpectrumValue> inPsd1 = Create<SpectrumValue> (sm);
215 // (*inPsd1)[0] = 1.;
216 // (*inPsd1)[1] = 1.;
217 // Ptr<SpectrumValue> outPsd1 = Create<SpectrumValue> (sm);
218 // outPsd1 = m_fadingModule->CalcRxPowerSpectralDensity (inPsd1, m_node1, m_node2);
219 //
220 // NS_LOG_INFO ("A ver " << (*outPsd1)[0] << " " << (*outPsd1)[1]);
221  double samplingInterval = 0.001;
222  double time = 0.0;
223  while (time<0.010)
224  {
225  Time t = Seconds (time);
226  Simulator::Schedule(t, &LteFadingTestCase::GetFadingSample, this);
227  time += samplingInterval;
228  }
229  Simulator::Stop (Seconds (10.1));
230  Simulator::Run ();
231  Simulator::Destroy ();
232 // double loss = m_downlinkPropagationLossModel->GetLoss (m_node1, m_node2);
233  time = 0.0;
234  int rbNum = 2;
235  std::vector<double> sum (rbNum);
236  std::vector<double> sumSquared (rbNum);
237  for (int i = 0; i < rbNum; i++)
238  {
239  sum.at (i) = 0.;
240  sumSquared.at (i) = 0.;
241  }
242  for (std::vector<SpectrumValue>::size_type i = 0; i != m_fadingSamples.size (); i++)
243  {
244  NS_LOG_INFO ("Sample time " << time << " : " << m_fadingSamples.at(i)[0] << " " << m_fadingSamples.at(i)[1]);
245  time += samplingInterval;
246  for (int j = 0; j < rbNum; j++)
247  {
248  sum.at (j) += m_fadingSamples.at(i)[j];
249  sumSquared.at (j) += (m_fadingSamples.at(i)[j]*m_fadingSamples.at(i)[j]);
250  }
251  }
252 // NS_LOG_INFO ("Calculated loss: " << loss);
253  NS_LOG_INFO ("Theoretical loss: " << m_lossRef);
254  for (int i = 0; i < rbNum; i++)
255  {
256  double mean = sum.at (i)/m_fadingSamples.size ();
257  double sigma = sqrt(sumSquared.at (i)/m_fadingSamples.size () - (mean*mean));
258  NS_LOG_INFO (" Mean " << mean << " sigma " << sigma);
259  }
260 
261  // NS_TEST_ASSERT_MSG_EQ_TOL(loss, m_lossRef, 0.1, "Wrong loss !");
262 }
263 
264 
265 void
267 {
269 
270  Bands bands;
271  BandInfo bi;
272 
273  bi.fl = 2.400e9;
274  bi.fc = 2.410e9;
275  bi.fh = 2.420e9;
276  bands.push_back (bi);
277 
278  bi.fl = 2.420e9;
279  bi.fc = 2.431e9;
280  bi.fh = 2.442e9;
281  bands.push_back (bi);
282 
283  sm = Create<SpectrumModel> (bands);
284 
288  Ptr<SpectrumValue> inPsd1 = Create<SpectrumValue> (sm);
289  (*inPsd1)[0] = 1.;
290  (*inPsd1)[1] = 1.;
291  Ptr<SpectrumValue> outPsd1 = Create<SpectrumValue> (sm);
293  (*outPsd1)[0] = (10 * std::log10 (180000*(*outPsd1)[0])) - (10 * std::log10 (180000*(*inPsd1)[0]));
294  (*outPsd1)[1] = (10 * std::log10 (180000*(*outPsd1)[1])) - (10 * std::log10 (180000*(*inPsd1)[1]));
295  m_fadingSamples.push_back ((*outPsd1));
296 }
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Ptr< BuildingsMobilityModel > m_node2
NetDeviceContainer InstallEnbDevice(NodeContainer c)
Create a set of eNodeB devices.
Definition: lte-helper.cc:382
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:455
Hold variables of type string.
Definition: string.h:41
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
std::vector< SpectrumValue > m_fadingSamples
A suite of tests to run.
Definition: test.h:1333
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
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:244
encapsulates test code
Definition: test.h:1147
std::vector< BandInfo > Bands
Container of BandInfo.
Ptr< TraceFadingLossModel > m_fadingModule
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
void LogComponentEnable(char const *name, enum LogLevel level)
Enable the logging output associated with that log component.
Definition: log.cc:351
tuple mobility
Definition: third.py:101
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:297
static LteFadingTestSuite lteFadingTestSuite
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< SpectrumValue > CalcRxPowerSpectralDensity(Ptr< const SpectrumValue > txPsd, Ptr< const MobilityModel > a, Ptr< const MobilityModel > b) const
This method is to be called to calculate.
double fl
lower limit of subband
keep track of a set of node pointers.
Ptr< BuildingsMobilityModel > m_node1
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())
virtual ~LteFadingTestCase()
Test 1.1 fading model.
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.
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:895
const double m2
Second component modulus, 232 - 22853.
Definition: rng-stream.cc:58
LteFadingTestCase(Ptr< BuildingsMobilityModel > m1, Ptr< BuildingsMobilityModel > m2, double refValue, std::string name)
TestCase.
Print everything.
Definition: log.h:112
std::string GetName(void) const
Definition: test.cc:368
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
const double m1
First component modulus, 232 - 209.
Definition: rng-stream.cc:54
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:191
The building block of a SpectrumModel.