A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
lte-test-fading.cc
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-sinr-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 NS_LOG_COMPONENT_DEFINE ("LteFadingTest");
54 
55 namespace ns3 {
56 
57 
69 : TestSuite ("lte-fading-model", SYSTEM)
70 {
71 
72 
73  // -------------- COMPOUND TESTS ----------------------------------
74 
75  LogComponentEnable ("LteFadingTest", LOG_LEVEL_ALL);
76 
77  // NS_LOG_INFO ("Creating LteDownlinkSinrTestSuite");
78 
79  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
80 
81  lteHelper->SetAttribute ("PathlossModel", StringValue ("ns3::BuildingsPropagationLossModel"));
82 
83  // Create Nodes: eNodeB, home eNB, UE and home UE (UE attached to HeNB)
84  NodeContainer enbNodes;
85  NodeContainer henbNodes;
86  NodeContainer ueNodes;
87  NodeContainer hueNodes;
88  enbNodes.Create (1);
89  henbNodes.Create (2);
90  ueNodes.Create (5);
91  hueNodes.Create (3);
92 
93  // Install Mobility Model
94  MobilityHelper mobility;
95  mobility.SetMobilityModel ("ns3::BuildingsMobilityModel");
96  mobility.Install (enbNodes);
97  mobility.Install (henbNodes);
98  mobility.Install (ueNodes);
99  mobility.Install (hueNodes);
100 
101  NetDeviceContainer enbDevs;
102  NetDeviceContainer henbDevs;
103  NetDeviceContainer ueDevs;
104  NetDeviceContainer hueDevs;
105  enbDevs = lteHelper->InstallEnbDevice (enbNodes);
106  ueDevs = lteHelper->InstallUeDevice (ueNodes);
107  henbDevs = lteHelper->InstallEnbDevice (henbNodes);
108  hueDevs = lteHelper->InstallUeDevice (hueNodes);
109 
110 
111 
112  lteHelper->Attach (ueDevs, enbDevs.Get (0));
113  lteHelper->Attach (hueDevs, henbDevs.Get (0));
114 
115  // Test #1 Okumura Hata Model (150 < freq < 1500 MHz) (Macro<->UE)
116 
117  double distance = 2000;
118  double hm = 1;
119  double hb = 30;
120 // double freq = 869e6; // E_UTRA BAND #5 see table 5.5-1 of 36.101
122  mm1->SetPosition (Vector (0.0, 0.0, hb));
123 
125  mm2->SetPosition (Vector (distance, 0.0, hm));
126 
127  AddTestCase (new LteFadingTestCase (mm1, mm2, 137.93, "OH Urban Large city"), TestCase::QUICK);
128 
129 
130 }
131 
132 static LteFadingTestSuite lteFadingTestSuite;
133 
134 
140 : TestCase ("FADING calculation: " + name),
141 m_node1 (m1),
142 m_node2 (m2),
143 m_lossRef (refValue)
144 {
145 }
146 
147 LteFadingTestCase::~LteFadingTestCase ()
148 {
149 }
150 
151 void
153 {
154  // LogLevel logLevel = (LogLevel)(LOG_PREFIX_FUNC | LOG_PREFIX_TIME | LOG_LEVEL_ALL);
155 
156  // LogComponentEnable ("LteEnbRrc", logLevel);
157  // LogComponentEnable ("LteUeRrc", logLevel);
158  // LogComponentEnable ("LteEnbMac", logLevel);
159  // LogComponentEnable ("LteUeMac", logLevel);
160  // LogComponentEnable ("LteRlc", logLevel);
161  // LogComponentEnable ("RrPacketScheduler", logLevel);
162  //
163  // LogComponentEnable ("LtePhy", logLevel);
164  // LogComponentEnable ("LteEnbPhy", logLevel);
165  // LogComponentEnable ("LteUePhy", logLevel);
166  //
167  // LogComponentEnable ("LteSpectrumPhy", logLevel);
168  // LogComponentEnable ("LteInterference", logLevel);
169  // LogComponentEnable ("LteSinrChunkProcessor", logLevel);
170  //
171  // LogComponentEnable ("LtePropagationLossModel", logLevel);
172  // LogComponentEnable ("LossModel", logLevel);
173  // LogComponentEnable ("ShadowingLossModel", logLevel);
174  // LogComponentEnable ("PenetrationLossModel", logLevel);
175  // LogComponentEnable ("MultipathLossModel", logLevel);
176  // LogComponentEnable ("PathLossModel", logLevel);
177  //
178  // LogComponentEnable ("LteNetDevice", logLevel);
179  // LogComponentEnable ("LteUeNetDevice", logLevel);
180  // LogComponentEnable ("LteEnbNetDevice", logLevel);
181 
182  LogComponentEnable ("TraceFadingLossModel", LOG_LEVEL_ALL);
183 // LogComponentEnable ("TraceFadingLossModel", LOG_LEVEL_ALL);
184 // LogComponentEnable ("BuildingsPropagationLossModel", LOG_LEVEL_ALL);
185  NS_LOG_INFO ("Testing " << GetName());
186 
187 
188  m_fadingModule = CreateObject<TraceFadingLossModel> ();
189 
190  m_fadingModule->SetAttribute("TraceFilename", StringValue("../../../src/lte/model/fading-traces/fading_trace_EPA_3kmph.fad"));
191  //m_fadingModule->SetAttribute("WindowSize", TimeValue(Seconds (0.003)));
192 
193  m_fadingModule->CreateFadingChannelRealization (m_node1, m_node2);
194 
195 // Ptr<SpectrumModel> sm;
196 //
197 // Bands bands;
198 // BandInfo bi;
199 //
200 // bi.fl = 2.400e9;
201 // bi.fc = 2.410e9;
202 // bi.fh = 2.420e9;
203 // bands.push_back (bi);
204 //
205 // bi.fl = 2.420e9;
206 // bi.fc = 2.431e9;
207 // bi.fh = 2.442e9;
208 // bands.push_back (bi);
209 //
210 // sm = Create<SpectrumModel> (bands);
211 //
212 // /**
213 // * TX signal #1: Power Spectral Density (W/Hz) of the signal = [0 0] dBm and BW = [20 22] MHz
214 // */
215 // Ptr<SpectrumValue> inPsd1 = Create<SpectrumValue> (sm);
216 // (*inPsd1)[0] = 1.;
217 // (*inPsd1)[1] = 1.;
218 // Ptr<SpectrumValue> outPsd1 = Create<SpectrumValue> (sm);
219 // outPsd1 = m_fadingModule->CalcRxPowerSpectralDensity (inPsd1, m_node1, m_node2);
220 //
221 // NS_LOG_INFO ("A ver " << (*outPsd1)[0] << " " << (*outPsd1)[1]);
222  double samplingInterval = 0.001;
223  double time = 0.0;
224  while (time<0.010)
225  {
226  Time t = Seconds (time);
228  time += samplingInterval;
229  }
230  Simulator::Stop (Seconds (10.1));
231  Simulator::Run ();
233 // double loss = m_downlinkPropagationLossModel->GetLoss (m_node1, m_node2);
234  time = 0.0;
235  int rbNum = 2;
236  std::vector<double> sum (rbNum);
237  std::vector<double> sumSquared (rbNum);
238  for (int i = 0; i < rbNum; i++)
239  {
240  sum.at (i) = 0.;
241  sumSquared.at (i) = 0.;
242  }
243  for (uint i = 0; i < m_fadingSamples.size (); i++)
244  {
245  NS_LOG_INFO ("Sample time " << time << " : " << m_fadingSamples.at(i)[0] << " " << m_fadingSamples.at(i)[1]);
246  time += samplingInterval;
247  for (int j = 0; j < rbNum; j++)
248  {
249  sum.at (j) += m_fadingSamples.at(i)[j];
250  sumSquared.at (j) += (m_fadingSamples.at(i)[j]*m_fadingSamples.at(i)[j]);
251  }
252  }
253 // NS_LOG_INFO ("Calculated loss: " << loss);
254  NS_LOG_INFO ("Theoretical loss: " << m_lossRef);
255  for (int i = 0; i < rbNum; i++)
256  {
257  double mean = sum.at (i)/m_fadingSamples.size ();
258  double sigma = sqrt(sumSquared.at (i)/m_fadingSamples.size () - (mean*mean));
259  NS_LOG_INFO (" Mean " << mean << " sigma " << sigma);
260  }
261 
262  // NS_TEST_ASSERT_MSG_EQ_TOL(loss, m_lossRef, 0.1, "Wrong loss !");
263 }
264 
265 
266 void
268 {
270 
271  Bands bands;
272  BandInfo bi;
273 
274  bi.fl = 2.400e9;
275  bi.fc = 2.410e9;
276  bi.fh = 2.420e9;
277  bands.push_back (bi);
278 
279  bi.fl = 2.420e9;
280  bi.fc = 2.431e9;
281  bi.fh = 2.442e9;
282  bands.push_back (bi);
283 
284  sm = Create<SpectrumModel> (bands);
285 
289  Ptr<SpectrumValue> inPsd1 = Create<SpectrumValue> (sm);
290  (*inPsd1)[0] = 1.;
291  (*inPsd1)[1] = 1.;
292  Ptr<SpectrumValue> outPsd1 = Create<SpectrumValue> (sm);
293  outPsd1 = m_fadingModule->CalcRxPowerSpectralDensity (inPsd1, m_node1, m_node2);
294  (*outPsd1)[0] = (10 * std::log10 (180000*(*outPsd1)[0])) - (10 * std::log10 (180000*(*inPsd1)[0]));
295  (*outPsd1)[1] = (10 * std::log10 (180000*(*outPsd1)[1])) - (10 * std::log10 (180000*(*inPsd1)[1]));
296  m_fadingSamples.push_back ((*outPsd1));
297 }
298 
299 } // namespace ns3
300 
keep track of time unit.
Definition: nstime.h:149
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
hold variables of type string
Definition: string.h:19
Ptr< NetDevice > Get(uint32_t i) const
Get the Ptr<NetDevice> stored in this container at a given index.
A suite of tests to run.
Definition: test.h:962
LteFadingTestCase(Ptr< BuildingsMobilityModel > m1, Ptr< BuildingsMobilityModel > m2, double refValue, std::string name)
static void Run(void)
Definition: simulator.cc:157
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
#define NS_LOG_INFO(msg)
Definition: log.h:264
encapsulates test code
Definition: test.h:834
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Definition: simulator.h:820
a 3d vector
Definition: vector.h:31
void Install(Ptr< Node > node) const
"Layout" a single node according to the current position allocator type.
double fc
center frequency
Buildings mobility model.
holds a vector of ns3::NetDevice pointers
virtual void DoRun(void)
Implementation to actually run this test case.
static void Destroy(void)
Definition: simulator.cc:121
double fl
lower limit of subband
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())
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual test case to this test suite.
Definition: test.cc:172
Helper class used to assign positions and mobility models to nodes.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
Definition: nstime.h:586
static void Stop(void)
Definition: simulator.cc:164
Ptr< Node > Get(uint32_t i) const
Get the Ptr<Node> stored in this container at a given index.
std::string GetName(void) const
Definition: test.cc:241
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
Ptr< T > GetObject(void) const
Definition: object.h:332
void LogComponentEnable(char const *name, enum LogLevel level)
Definition: log.cc:311