A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
lte-test-uplink-sinr.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: Manuel Requena <manuel.requena@cttc.es>
19  * Modified by Marco Miozzo <mmiozzo@ctt.es>
20  * Extend to Data and SRS frames
21  */
22 
23 #include "ns3/simulator.h"
24 
25 #include "ns3/log.h"
26 
27 #include "ns3/spectrum-test.h"
28 
29 #include "ns3/lte-phy-tag.h"
30 #include "lte-test-ue-phy.h"
32 #include "ns3/lte-spectrum-signal-parameters.h"
33 
34 #include "lte-test-uplink-sinr.h"
35 
36 #include <ns3/lte-helper.h>
37 
38 NS_LOG_COMPONENT_DEFINE ("LteUplinkSinrTest");
39 
40 namespace ns3 {
41 
42 
51  : TestSuite ("lte-uplink-sinr", SYSTEM)
52 {
57 
58  Bands bands;
59  BandInfo bi;
60 
61  bi.fl = 2.400e9;
62  bi.fc = 2.410e9;
63  bi.fh = 2.420e9;
64  bands.push_back (bi);
65 
66  bi.fl = 2.420e9;
67  bi.fc = 2.431e9;
68  bi.fh = 2.442e9;
69  bands.push_back (bi);
70 
71  sm = Create<SpectrumModel> (bands);
72 
76  Ptr<SpectrumValue> rxPsd1 = Create<SpectrumValue> (sm);
77  (*rxPsd1)[0] = 1.255943215755e-15;
78  (*rxPsd1)[1] = 0.0;
79 
80  Ptr<SpectrumValue> rxPsd2 = Create<SpectrumValue> (sm);
81  (*rxPsd2)[0] = 0.0;
82  (*rxPsd2)[1] = 7.204059965732e-16;
83 
84  Ptr<SpectrumValue> theoreticalSinr1 = Create<SpectrumValue> (sm);
85  (*theoreticalSinr1)[0] = 3.72589167251055;
86  (*theoreticalSinr1)[1] = 3.72255684126076;
87 
88  AddTestCase (new LteUplinkDataSinrTestCase (rxPsd1, rxPsd2, theoreticalSinr1, "sdBm = [-46 -inf] and [-inf -48]"), TestCase::QUICK);
89 
90  AddTestCase (new LteUplinkSrsSinrTestCase (rxPsd1, rxPsd2, theoreticalSinr1, "sdBm = [-46 -inf] and [-inf -48]"), TestCase::QUICK);
91 
95  Ptr<SpectrumValue> rxPsd3 = Create<SpectrumValue> (sm);
96  (*rxPsd3)[0] = 2.505936168136e-17;
97  (*rxPsd3)[1] = 0.0;
98 
99  Ptr<SpectrumValue> rxPsd4 = Create<SpectrumValue> (sm);
100  (*rxPsd4)[0] = 0.0;
101  (*rxPsd4)[1] = 3.610582885110e-17;
102 
103  Ptr<SpectrumValue> theoreticalSinr2 = Create<SpectrumValue> (sm);
104  (*theoreticalSinr2)[0] = 0.0743413124381667;
105  (*theoreticalSinr2)[1] = 0.1865697965291756;
106 
107  AddTestCase (new LteUplinkDataSinrTestCase (rxPsd3, rxPsd4, theoreticalSinr2, "sdBm = [-63 -inf] and [-inf -61]"), TestCase::QUICK);
108 
109  AddTestCase (new LteUplinkSrsSinrTestCase (rxPsd3, rxPsd4, theoreticalSinr2, "sdBm = [-63 -inf] and [-inf -61]"), TestCase::QUICK);
110 
111 }
112 
114 
115 
121  : TestCase ("SINR calculation in uplink data frame: " + name),
122  m_sv1 (sv1),
123  m_sv2 (sv2),
124  m_sm (sv1->GetSpectrumModel ()),
125  m_sinr (sinr)
126 {
127  NS_LOG_INFO ("Creating LteUplinkDataSinrTestCase");
128 }
129 
131 {
132 }
133 
134 void
136 {
140  Ptr<LteSpectrumPhy> dlPhy = CreateObject<LteSpectrumPhy> ();
141  Ptr<LteSpectrumPhy> ulPhy = CreateObject<LteSpectrumPhy> ();
142  Ptr<LteTestUePhy> uePhy = CreateObject<LteTestUePhy> (dlPhy, ulPhy);
143  uint16_t cellId = 100;
144  dlPhy->SetCellId (cellId);
145  ulPhy->SetCellId (cellId);
146 
147  Ptr<LteTestSinrChunkProcessor> chunkProcessor = Create<LteTestSinrChunkProcessor> (uePhy->GetObject<LtePhy> ());
148  ulPhy->AddDataSinrChunkProcessor (chunkProcessor);
149 
158  // Number of packet bursts (2 data + 4 interferences)
159  const int numOfDataPbs = 2;
160  const int numOfIntfPbs = 4;
161  const int numOfPbs = numOfDataPbs + numOfIntfPbs;
162 
163  // Number of packets in the packet bursts
164  const int numOfPkts = 10;
165 
166  // Packet bursts
167  Ptr<PacketBurst> packetBursts[numOfPbs];
168 
169  // Packets
170  Ptr<Packet> pkt[numOfPbs][numOfPkts];
171 
172  // Bursts cellId
173  uint16_t pbCellId[numOfPbs];
174 
175 
176 
180  int pb = 0;
181  for ( int dataPb = 0 ; dataPb < numOfDataPbs ; dataPb++, pb++ )
182  {
183  // Create packet burst
184  packetBursts[pb] = CreateObject<PacketBurst> ();
185  pbCellId[pb] = cellId;
186  // Create packets and add them to the burst
187  for ( int i = 0 ; i < numOfPkts ; i++ )
188  {
189  pkt[pb][i] = Create<Packet> (1000);
190 
191  packetBursts[pb]->AddPacket ( pkt[pb][i] );
192  }
193  }
194  for ( int intfPb = 0 ; intfPb < numOfIntfPbs ; intfPb++, pb++ )
195  {
196  // Create packet burst
197  packetBursts[pb] = CreateObject<PacketBurst> ();
198  pbCellId[pb] = cellId * (pb + 1);
199 
200  // Create packets and add them to the burst
201  for ( int i = 0 ; i < numOfPkts ; i++ )
202  {
203  pkt[pb][i] = Create<Packet> (1000);
204 
205  packetBursts[pb]->AddPacket ( pkt[pb][i] );
206  }
207  }
208 
209 
210  Ptr<SpectrumValue> noisePsd = Create<SpectrumValue> (m_sm);
211  Ptr<SpectrumValue> i1 = Create<SpectrumValue> (m_sm);
212  Ptr<SpectrumValue> i2 = Create<SpectrumValue> (m_sm);
213  Ptr<SpectrumValue> i3 = Create<SpectrumValue> (m_sm);
214  Ptr<SpectrumValue> i4 = Create<SpectrumValue> (m_sm);
215 
216  (*noisePsd)[0] = 5.000000000000e-19;
217  (*noisePsd)[1] = 4.545454545455e-19;
218 
219  (*i1)[0] = 5.000000000000e-18;
220  (*i2)[0] = 5.000000000000e-16;
221  (*i3)[0] = 1.581138830084e-16;
222  (*i4)[0] = 7.924465962306e-17;
223  (*i1)[1] = 1.437398936440e-18;
224  (*i2)[1] = 5.722388235428e-16;
225  (*i3)[1] = 7.204059965732e-17;
226  (*i4)[1] = 5.722388235428e-17;
227 
228  Time ts = Seconds (1);
229  Time ds = Seconds (1);
230  Time ti1 = Seconds (0);
231  Time di1 = Seconds (3);
232  Time ti2 = Seconds (0.7);
233  Time di2 = Seconds (1);
234  Time ti3 = Seconds (1.2);
235  Time di3 = Seconds (1);
236  Time ti4 = Seconds (1.5);
237  Time di4 = Seconds (0.1);
238 
239  ulPhy->SetNoisePowerSpectralDensity (noisePsd);
240 
245  // 2 UEs send data to the eNB through 2 subcarriers
246  Ptr<LteSpectrumSignalParametersDataFrame> sp1 = Create<LteSpectrumSignalParametersDataFrame> ();
247  sp1->psd = m_sv1;
248  sp1->txPhy = 0;
249  sp1->duration = ds;
250  sp1->packetBurst = packetBursts[0];
251  sp1->cellId = pbCellId[0];
252  Simulator::Schedule (ts, &LteSpectrumPhy::StartRx, ulPhy, sp1);
253 
254  Ptr<LteSpectrumSignalParametersDataFrame> sp2 = Create<LteSpectrumSignalParametersDataFrame> ();
255  sp2->psd = m_sv2;
256  sp2->txPhy = 0;
257  sp2->duration = ds;
258  sp2->packetBurst = packetBursts[1];
259  sp2->cellId = pbCellId[1];
260  Simulator::Schedule (ts, &LteSpectrumPhy::StartRx, ulPhy, sp2);
261 
262 
263  Ptr<LteSpectrumSignalParametersDataFrame> ip1 = Create<LteSpectrumSignalParametersDataFrame> ();
264  ip1->psd = i1;
265  ip1->txPhy = 0;
266  ip1->duration = di1;
267  ip1->packetBurst = packetBursts[2];
268  ip1->cellId = pbCellId[2];
269  Simulator::Schedule (ti1, &LteSpectrumPhy::StartRx, ulPhy, ip1);
270 
271  Ptr<LteSpectrumSignalParametersDataFrame> ip2 = Create<LteSpectrumSignalParametersDataFrame> ();
272  ip2->psd = i2;
273  ip2->txPhy = 0;
274  ip2->duration = di2;
275  ip2->packetBurst = packetBursts[3];
276  ip2->cellId = pbCellId[3];
277  Simulator::Schedule (ti2, &LteSpectrumPhy::StartRx, ulPhy, ip2);
278 
279  Ptr<LteSpectrumSignalParametersDataFrame> ip3 = Create<LteSpectrumSignalParametersDataFrame> ();
280  ip3->psd = i3;
281  ip3->txPhy = 0;
282  ip3->duration = di3;
283  ip3->packetBurst = packetBursts[4];
284  ip3->cellId = pbCellId[4];
285  Simulator::Schedule (ti3, &LteSpectrumPhy::StartRx, ulPhy, ip3);
286 
287  Ptr<LteSpectrumSignalParametersDataFrame> ip4 = Create<LteSpectrumSignalParametersDataFrame> ();
288  ip4->psd = i4;
289  ip4->txPhy = 0;
290  ip4->duration = di4;
291  ip4->packetBurst = packetBursts[5];
292  ip4->cellId = pbCellId[5];
293  Simulator::Schedule (ti4, &LteSpectrumPhy::StartRx, ulPhy, ip4);
294 
295  Simulator::Stop (Seconds (5.0));
296  Simulator::Run ();
297 
302  Ptr<SpectrumValue> calculatedSinr = chunkProcessor->GetSinr ();
303 
304  NS_LOG_INFO ("Data Frame - Theoretical SINR: " << *m_sinr);
305  NS_LOG_INFO ("Data Frame - Calculated SINR: " << *calculatedSinr);
306 
307  NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL (*calculatedSinr, *m_sinr, 0.0000001, "Data Frame - Wrong SINR !");
308  ulPhy->Dispose ();
310 
311 }
312 
313 
319 : TestCase ("SINR calculation in uplink srs frame: " + name),
320 m_sv1 (sv1),
321 m_sv2 (sv2),
322 m_sm (sv1->GetSpectrumModel ()),
323 m_sinr (sinr)
324 {
325  NS_LOG_INFO ("Creating LteUplinkSrsSinrTestCase");
326 }
327 
329 {
330 }
331 
332 void
334 {
339  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
340  // lteHelper->EnableLogComponents ();
341  Ptr<LteSpectrumPhy> dlPhy = CreateObject<LteSpectrumPhy> ();
342  Ptr<LteSpectrumPhy> ulPhy = CreateObject<LteSpectrumPhy> ();
343  Ptr<LteTestUePhy> uePhy = CreateObject<LteTestUePhy> (dlPhy, ulPhy);
344  uint16_t cellId = 100;
345  dlPhy->SetCellId (cellId);
346  ulPhy->SetCellId (cellId);
347 
348  Ptr<LteTestSinrChunkProcessor> chunkProcessor = Create<LteTestSinrChunkProcessor> (uePhy->GetObject<LtePhy> ());
349  ulPhy->AddCtrlSinrChunkProcessor (chunkProcessor);
350 
360  // Number of packet bursts (2 data + 4 interferences)
361  int numOfDataSignals = 2;
362  int numOfIntfSignals = 4;
363  int numOfSignals = numOfDataSignals + numOfIntfSignals;
364 
365  uint16_t pbCellId[numOfSignals];
366 
367 
368 
372  int pb = 0;
373  for ( int dataPb = 0 ; dataPb < numOfDataSignals ; dataPb++, pb++ )
374  {
375  pbCellId[pb] = cellId;
376 
377  }
378  for ( int intfPb = 0 ; intfPb < numOfIntfSignals ; intfPb++, pb++ )
379  {
380 
381  pbCellId[pb] = cellId * (pb + 1);
382 
383  }
384 
385 
386  Ptr<SpectrumValue> noisePsd = Create<SpectrumValue> (m_sm);
387  Ptr<SpectrumValue> i1 = Create<SpectrumValue> (m_sm);
388  Ptr<SpectrumValue> i2 = Create<SpectrumValue> (m_sm);
389  Ptr<SpectrumValue> i3 = Create<SpectrumValue> (m_sm);
390  Ptr<SpectrumValue> i4 = Create<SpectrumValue> (m_sm);
391 
392  (*noisePsd)[0] = 5.000000000000e-19;
393  (*noisePsd)[1] = 4.545454545455e-19;
394 
395  (*i1)[0] = 5.000000000000e-18;
396  (*i2)[0] = 5.000000000000e-16;
397  (*i3)[0] = 1.581138830084e-16;
398  (*i4)[0] = 7.924465962306e-17;
399  (*i1)[1] = 1.437398936440e-18;
400  (*i2)[1] = 5.722388235428e-16;
401  (*i3)[1] = 7.204059965732e-17;
402  (*i4)[1] = 5.722388235428e-17;
403 
404  Time ts = Seconds (1);
405  Time ds = Seconds (1);
406  Time ti1 = Seconds (0);
407  Time di1 = Seconds (3);
408  Time ti2 = Seconds (0.7);
409  Time di2 = Seconds (1);
410  Time ti3 = Seconds (1.2);
411  Time di3 = Seconds (1);
412  Time ti4 = Seconds (1.5);
413  Time di4 = Seconds (0.1);
414 
415  ulPhy->SetNoisePowerSpectralDensity (noisePsd);
416 
421  // 2 UEs send data to the eNB through 2 subcarriers
422  Ptr<LteSpectrumSignalParametersUlSrsFrame> sp1 = Create<LteSpectrumSignalParametersUlSrsFrame> ();
423  sp1->psd = m_sv1;
424  sp1->txPhy = 0;
425  sp1->duration = ds;
426  sp1->cellId = pbCellId[0];
427  Simulator::Schedule (ts, &LteSpectrumPhy::StartRx, ulPhy, sp1);
428 
429  Ptr<LteSpectrumSignalParametersUlSrsFrame> sp2 = Create<LteSpectrumSignalParametersUlSrsFrame> ();
430  sp2->psd = m_sv2;
431  sp2->txPhy = 0;
432  sp2->duration = ds;
433  sp2->cellId = pbCellId[1];
434  Simulator::Schedule (ts, &LteSpectrumPhy::StartRx, ulPhy, sp2);
435 
436 
437  Ptr<LteSpectrumSignalParametersUlSrsFrame> ip1 = Create<LteSpectrumSignalParametersUlSrsFrame> ();
438  ip1->psd = i1;
439  ip1->txPhy = 0;
440  ip1->duration = di1;
441  ip1->cellId = pbCellId[2];
442  Simulator::Schedule (ti1, &LteSpectrumPhy::StartRx, ulPhy, ip1);
443 
444  Ptr<LteSpectrumSignalParametersUlSrsFrame> ip2 = Create<LteSpectrumSignalParametersUlSrsFrame> ();
445  ip2->psd = i2;
446  ip2->txPhy = 0;
447  ip2->duration = di2;
448  ip2->cellId = pbCellId[3];
449  Simulator::Schedule (ti2, &LteSpectrumPhy::StartRx, ulPhy, ip2);
450 
451  Ptr<LteSpectrumSignalParametersUlSrsFrame> ip3 = Create<LteSpectrumSignalParametersUlSrsFrame> ();
452  ip3->psd = i3;
453  ip3->txPhy = 0;
454  ip3->duration = di3;
455  ip3->cellId = pbCellId[4];
456  Simulator::Schedule (ti3, &LteSpectrumPhy::StartRx, ulPhy, ip3);
457 
458  Ptr<LteSpectrumSignalParametersUlSrsFrame> ip4 = Create<LteSpectrumSignalParametersUlSrsFrame> ();
459  ip4->psd = i4;
460  ip4->txPhy = 0;
461  ip4->duration = di4;
462  ip4->cellId = pbCellId[5];
463  Simulator::Schedule (ti4, &LteSpectrumPhy::StartRx, ulPhy, ip4);
464 
465  Simulator::Stop (Seconds (5.0));
466  Simulator::Run ();
467 
472  Ptr<SpectrumValue> calculatedSinr = chunkProcessor->GetSinr ();
473 
474  NS_LOG_INFO ("SRS Frame - Theoretical SINR: " << *m_sinr);
475  NS_LOG_INFO ("SRS Frame - Calculated SINR: " << *calculatedSinr);
476 
477  NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL (*calculatedSinr, *m_sinr, 0.0000001, "Data Frame - Wrong SINR !");
478  ulPhy->Dispose ();
480 
481 }
482 
483 } //namespace
keep track of time values and allow control of global simulation resolution
Definition: nstime.h:81
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:59
static LteUplinkSinrTestSuite lteUplinkSinrTestSuite
A suite of tests to run.
Definition: test.h:1025
static void Run(void)
Run the simulation until one of:
Definition: simulator.cc:157
#define NS_LOG_INFO(msg)
Definition: log.h:298
encapsulates test code
Definition: test.h:849
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:824
std::vector< BandInfo > Bands
double fc
center frequency
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
double fl
lower limit of subband
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition: test.cc:173
Fast test.
Definition: test.h:857
#define NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL(actual, expected, tol, msg)
Test if two SpectrumValue instances are equal within a given tolerance.
static void Stop(void)
If an event invokes this method, it will be the last event scheduled by the Simulator::run method bef...
Definition: simulator.cc:165
double fh
upper limit of subband
void StartRx(Ptr< SpectrumSignalParameters > params)
Notify the SpectrumPhy instance of an incoming signal.
The building block of a SpectrumModel.
The LtePhy models the physical layer of LTE.
Definition: lte-phy.h:52