A Discrete-Event Network Simulator
API
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"
31 #include "ns3/lte-spectrum-signal-parameters.h"
32 
33 #include "lte-test-uplink-sinr.h"
34 
35 #include <ns3/lte-helper.h>
36 #include <ns3/lte-chunk-processor.h>
37 
38 using namespace ns3;
39 
40 NS_LOG_COMPONENT_DEFINE ("LteUplinkSinrTest");
41 
50  : TestSuite ("lte-uplink-sinr", SYSTEM)
51 {
56 
57  Bands bands;
58  BandInfo bi;
59 
60  bi.fl = 2.400e9;
61  bi.fc = 2.410e9;
62  bi.fh = 2.420e9;
63  bands.push_back (bi);
64 
65  bi.fl = 2.420e9;
66  bi.fc = 2.431e9;
67  bi.fh = 2.442e9;
68  bands.push_back (bi);
69 
70  sm = Create<SpectrumModel> (bands);
71 
75  Ptr<SpectrumValue> rxPsd1 = Create<SpectrumValue> (sm);
76  (*rxPsd1)[0] = 1.255943215755e-15;
77  (*rxPsd1)[1] = 0.0;
78 
79  Ptr<SpectrumValue> rxPsd2 = Create<SpectrumValue> (sm);
80  (*rxPsd2)[0] = 0.0;
81  (*rxPsd2)[1] = 7.204059965732e-16;
82 
83  Ptr<SpectrumValue> theoreticalSinr1 = Create<SpectrumValue> (sm);
84  (*theoreticalSinr1)[0] = 3.72589167251055;
85  (*theoreticalSinr1)[1] = 3.72255684126076;
86 
87  AddTestCase (new LteUplinkDataSinrTestCase (rxPsd1, rxPsd2, theoreticalSinr1, "sdBm = [-46 -inf] and [-inf -48]"), TestCase::QUICK);
88 
89  AddTestCase (new LteUplinkSrsSinrTestCase (rxPsd1, rxPsd2, theoreticalSinr1, "sdBm = [-46 -inf] and [-inf -48]"), TestCase::QUICK);
90 
94  Ptr<SpectrumValue> rxPsd3 = Create<SpectrumValue> (sm);
95  (*rxPsd3)[0] = 2.505936168136e-17;
96  (*rxPsd3)[1] = 0.0;
97 
98  Ptr<SpectrumValue> rxPsd4 = Create<SpectrumValue> (sm);
99  (*rxPsd4)[0] = 0.0;
100  (*rxPsd4)[1] = 3.610582885110e-17;
101 
102  Ptr<SpectrumValue> theoreticalSinr2 = Create<SpectrumValue> (sm);
103  (*theoreticalSinr2)[0] = 0.0743413124381667;
104  (*theoreticalSinr2)[1] = 0.1865697965291756;
105 
106  AddTestCase (new LteUplinkDataSinrTestCase (rxPsd3, rxPsd4, theoreticalSinr2, "sdBm = [-63 -inf] and [-inf -61]"), TestCase::QUICK);
107 
108  AddTestCase (new LteUplinkSrsSinrTestCase (rxPsd3, rxPsd4, theoreticalSinr2, "sdBm = [-63 -inf] and [-inf -61]"), TestCase::QUICK);
109 
110 }
111 
113 
114 
120  : TestCase ("SINR calculation in uplink data frame: " + name),
121  m_sv1 (sv1),
122  m_sv2 (sv2),
123  m_sm (sv1->GetSpectrumModel ()),
124  m_expectedSinr (sinr)
125 {
126  NS_LOG_INFO ("Creating LteUplinkDataSinrTestCase");
127 }
128 
130 {
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<LteChunkProcessor> chunkProcessor = Create<LteChunkProcessor> ();
148  LteSpectrumValueCatcher actualSinrCatcher;
149  chunkProcessor->AddCallback (MakeCallback (&LteSpectrumValueCatcher::ReportValue, &actualSinrCatcher));
150  ulPhy->AddDataSinrChunkProcessor (chunkProcessor);
151 
160  // Number of packet bursts (2 data + 4 interferences)
161  const int numOfDataPbs = 2;
162  const int numOfIntfPbs = 4;
163  const int numOfPbs = numOfDataPbs + numOfIntfPbs;
164 
165  // Number of packets in the packet bursts
166  const int numOfPkts = 10;
167 
168  // Packet bursts
169  Ptr<PacketBurst> packetBursts[numOfPbs];
170 
171  // Packets
172  Ptr<Packet> pkt[numOfPbs][numOfPkts];
173 
174  // Bursts cellId
175  uint16_t pbCellId[numOfPbs];
176 
177 
178 
182  int pb = 0;
183  for ( int dataPb = 0 ; dataPb < numOfDataPbs ; dataPb++, pb++ )
184  {
185  // Create packet burst
186  packetBursts[pb] = CreateObject<PacketBurst> ();
187  pbCellId[pb] = cellId;
188  // Create packets and add them to the burst
189  for ( int i = 0 ; i < numOfPkts ; i++ )
190  {
191  pkt[pb][i] = Create<Packet> (1000);
192 
193  packetBursts[pb]->AddPacket ( pkt[pb][i] );
194  }
195  }
196  for ( int intfPb = 0 ; intfPb < numOfIntfPbs ; intfPb++, pb++ )
197  {
198  // Create packet burst
199  packetBursts[pb] = CreateObject<PacketBurst> ();
200  pbCellId[pb] = cellId * (pb + 1);
201 
202  // Create packets and add them to the burst
203  for ( int i = 0 ; i < numOfPkts ; i++ )
204  {
205  pkt[pb][i] = Create<Packet> (1000);
206 
207  packetBursts[pb]->AddPacket ( pkt[pb][i] );
208  }
209  }
210 
211 
212  Ptr<SpectrumValue> noisePsd = Create<SpectrumValue> (m_sm);
213  Ptr<SpectrumValue> i1 = Create<SpectrumValue> (m_sm);
214  Ptr<SpectrumValue> i2 = Create<SpectrumValue> (m_sm);
215  Ptr<SpectrumValue> i3 = Create<SpectrumValue> (m_sm);
216  Ptr<SpectrumValue> i4 = Create<SpectrumValue> (m_sm);
217 
218  (*noisePsd)[0] = 5.000000000000e-19;
219  (*noisePsd)[1] = 4.545454545455e-19;
220 
221  (*i1)[0] = 5.000000000000e-18;
222  (*i2)[0] = 5.000000000000e-16;
223  (*i3)[0] = 1.581138830084e-16;
224  (*i4)[0] = 7.924465962306e-17;
225  (*i1)[1] = 1.437398936440e-18;
226  (*i2)[1] = 5.722388235428e-16;
227  (*i3)[1] = 7.204059965732e-17;
228  (*i4)[1] = 5.722388235428e-17;
229 
230  Time ts = Seconds (1);
231  Time ds = Seconds (1);
232  Time ti1 = Seconds (0);
233  Time di1 = Seconds (3);
234  Time ti2 = Seconds (0.7);
235  Time di2 = Seconds (1);
236  Time ti3 = Seconds (1.2);
237  Time di3 = Seconds (1);
238  Time ti4 = Seconds (1.5);
239  Time di4 = Seconds (0.1);
240 
241  ulPhy->SetNoisePowerSpectralDensity (noisePsd);
242 
247  // 2 UEs send data to the eNB through 2 subcarriers
248  Ptr<LteSpectrumSignalParametersDataFrame> sp1 = Create<LteSpectrumSignalParametersDataFrame> ();
249  sp1->psd = m_sv1;
250  sp1->txPhy = 0;
251  sp1->duration = ds;
252  sp1->packetBurst = packetBursts[0];
253  sp1->cellId = pbCellId[0];
254  Simulator::Schedule (ts, &LteSpectrumPhy::StartRx, ulPhy, sp1);
255 
256  Ptr<LteSpectrumSignalParametersDataFrame> sp2 = Create<LteSpectrumSignalParametersDataFrame> ();
257  sp2->psd = m_sv2;
258  sp2->txPhy = 0;
259  sp2->duration = ds;
260  sp2->packetBurst = packetBursts[1];
261  sp2->cellId = pbCellId[1];
262  Simulator::Schedule (ts, &LteSpectrumPhy::StartRx, ulPhy, sp2);
263 
264 
265  Ptr<LteSpectrumSignalParametersDataFrame> ip1 = Create<LteSpectrumSignalParametersDataFrame> ();
266  ip1->psd = i1;
267  ip1->txPhy = 0;
268  ip1->duration = di1;
269  ip1->packetBurst = packetBursts[2];
270  ip1->cellId = pbCellId[2];
271  Simulator::Schedule (ti1, &LteSpectrumPhy::StartRx, ulPhy, ip1);
272 
273  Ptr<LteSpectrumSignalParametersDataFrame> ip2 = Create<LteSpectrumSignalParametersDataFrame> ();
274  ip2->psd = i2;
275  ip2->txPhy = 0;
276  ip2->duration = di2;
277  ip2->packetBurst = packetBursts[3];
278  ip2->cellId = pbCellId[3];
279  Simulator::Schedule (ti2, &LteSpectrumPhy::StartRx, ulPhy, ip2);
280 
281  Ptr<LteSpectrumSignalParametersDataFrame> ip3 = Create<LteSpectrumSignalParametersDataFrame> ();
282  ip3->psd = i3;
283  ip3->txPhy = 0;
284  ip3->duration = di3;
285  ip3->packetBurst = packetBursts[4];
286  ip3->cellId = pbCellId[4];
287  Simulator::Schedule (ti3, &LteSpectrumPhy::StartRx, ulPhy, ip3);
288 
289  Ptr<LteSpectrumSignalParametersDataFrame> ip4 = Create<LteSpectrumSignalParametersDataFrame> ();
290  ip4->psd = i4;
291  ip4->txPhy = 0;
292  ip4->duration = di4;
293  ip4->packetBurst = packetBursts[5];
294  ip4->cellId = pbCellId[5];
295  Simulator::Schedule (ti4, &LteSpectrumPhy::StartRx, ulPhy, ip4);
296 
297  Simulator::Stop (Seconds (5.0));
298  Simulator::Run ();
299 
300  NS_LOG_INFO ("Data Frame - Theoretical SINR: " << *m_expectedSinr);
301  NS_LOG_INFO ("Data Frame - Calculated SINR: " << *(actualSinrCatcher.GetValue ()));
302 
303  NS_TEST_EXPECT_MSG_NE (actualSinrCatcher.GetValue (), 0, "no actual SINR reported");
304 
305  NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL (*(actualSinrCatcher.GetValue ()), *m_expectedSinr, 0.0000001, "Data Frame - Wrong SINR !");
306  ulPhy->Dispose ();
307  Simulator::Destroy ();
308 
309 }
310 
311 
317  : TestCase ("SINR calculation in uplink srs frame: " + name),
318  m_sv1 (sv1),
319  m_sv2 (sv2),
320  m_sm (sv1->GetSpectrumModel ()),
321  m_expectedSinr (sinr)
322 {
323  NS_LOG_INFO ("Creating LteUplinkSrsSinrTestCase");
324 }
325 
327 {
328 }
329 
330 void
332 {
333  m_actualSinr = sinr.Copy ();
334 }
335 
336 void
338 {
343  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
344  // lteHelper->EnableLogComponents ();
345  Ptr<LteSpectrumPhy> dlPhy = CreateObject<LteSpectrumPhy> ();
346  Ptr<LteSpectrumPhy> ulPhy = CreateObject<LteSpectrumPhy> ();
347  Ptr<LteTestUePhy> uePhy = CreateObject<LteTestUePhy> (dlPhy, ulPhy);
348  uint16_t cellId = 100;
349  dlPhy->SetCellId (cellId);
350  ulPhy->SetCellId (cellId);
351 
352  Ptr<LteChunkProcessor> chunkProcessor = Create<LteChunkProcessor> ();
354  ulPhy->AddCtrlSinrChunkProcessor (chunkProcessor);
355 
365  // Number of packet bursts (2 data + 4 interferences)
366  int numOfDataSignals = 2;
367  int numOfIntfSignals = 4;
368  int numOfSignals = numOfDataSignals + numOfIntfSignals;
369 
370  uint16_t pbCellId[numOfSignals];
371 
372 
373 
377  int pb = 0;
378  for ( int dataPb = 0 ; dataPb < numOfDataSignals ; dataPb++, pb++ )
379  {
380  pbCellId[pb] = cellId;
381 
382  }
383  for ( int intfPb = 0 ; intfPb < numOfIntfSignals ; intfPb++, pb++ )
384  {
385 
386  pbCellId[pb] = cellId * (pb + 1);
387 
388  }
389 
390 
391  Ptr<SpectrumValue> noisePsd = Create<SpectrumValue> (m_sm);
392  Ptr<SpectrumValue> i1 = Create<SpectrumValue> (m_sm);
393  Ptr<SpectrumValue> i2 = Create<SpectrumValue> (m_sm);
394  Ptr<SpectrumValue> i3 = Create<SpectrumValue> (m_sm);
395  Ptr<SpectrumValue> i4 = Create<SpectrumValue> (m_sm);
396 
397  (*noisePsd)[0] = 5.000000000000e-19;
398  (*noisePsd)[1] = 4.545454545455e-19;
399 
400  (*i1)[0] = 5.000000000000e-18;
401  (*i2)[0] = 5.000000000000e-16;
402  (*i3)[0] = 1.581138830084e-16;
403  (*i4)[0] = 7.924465962306e-17;
404  (*i1)[1] = 1.437398936440e-18;
405  (*i2)[1] = 5.722388235428e-16;
406  (*i3)[1] = 7.204059965732e-17;
407  (*i4)[1] = 5.722388235428e-17;
408 
409  Time ts = Seconds (1);
410  Time ds = Seconds (1);
411  Time ti1 = Seconds (0);
412  Time di1 = Seconds (3);
413  Time ti2 = Seconds (0.7);
414  Time di2 = Seconds (1);
415  Time ti3 = Seconds (1.2);
416  Time di3 = Seconds (1);
417  Time ti4 = Seconds (1.5);
418  Time di4 = Seconds (0.1);
419 
420  ulPhy->SetNoisePowerSpectralDensity (noisePsd);
421 
426  // 2 UEs send data to the eNB through 2 subcarriers
427  Ptr<LteSpectrumSignalParametersUlSrsFrame> sp1 = Create<LteSpectrumSignalParametersUlSrsFrame> ();
428  sp1->psd = m_sv1;
429  sp1->txPhy = 0;
430  sp1->duration = ds;
431  sp1->cellId = pbCellId[0];
432  Simulator::Schedule (ts, &LteSpectrumPhy::StartRx, ulPhy, sp1);
433 
434  Ptr<LteSpectrumSignalParametersUlSrsFrame> sp2 = Create<LteSpectrumSignalParametersUlSrsFrame> ();
435  sp2->psd = m_sv2;
436  sp2->txPhy = 0;
437  sp2->duration = ds;
438  sp2->cellId = pbCellId[1];
439  Simulator::Schedule (ts, &LteSpectrumPhy::StartRx, ulPhy, sp2);
440 
441 
442  Ptr<LteSpectrumSignalParametersUlSrsFrame> ip1 = Create<LteSpectrumSignalParametersUlSrsFrame> ();
443  ip1->psd = i1;
444  ip1->txPhy = 0;
445  ip1->duration = di1;
446  ip1->cellId = pbCellId[2];
447  Simulator::Schedule (ti1, &LteSpectrumPhy::StartRx, ulPhy, ip1);
448 
449  Ptr<LteSpectrumSignalParametersUlSrsFrame> ip2 = Create<LteSpectrumSignalParametersUlSrsFrame> ();
450  ip2->psd = i2;
451  ip2->txPhy = 0;
452  ip2->duration = di2;
453  ip2->cellId = pbCellId[3];
454  Simulator::Schedule (ti2, &LteSpectrumPhy::StartRx, ulPhy, ip2);
455 
456  Ptr<LteSpectrumSignalParametersUlSrsFrame> ip3 = Create<LteSpectrumSignalParametersUlSrsFrame> ();
457  ip3->psd = i3;
458  ip3->txPhy = 0;
459  ip3->duration = di3;
460  ip3->cellId = pbCellId[4];
461  Simulator::Schedule (ti3, &LteSpectrumPhy::StartRx, ulPhy, ip3);
462 
463  Ptr<LteSpectrumSignalParametersUlSrsFrame> ip4 = Create<LteSpectrumSignalParametersUlSrsFrame> ();
464  ip4->psd = i4;
465  ip4->txPhy = 0;
466  ip4->duration = di4;
467  ip4->cellId = pbCellId[5];
468  Simulator::Schedule (ti4, &LteSpectrumPhy::StartRx, ulPhy, ip4);
469 
470  Simulator::Stop (Seconds (5.0));
471  Simulator::Run ();
472 
473  NS_ASSERT_MSG (m_actualSinr != 0, "no actual SINR reported");
474 
475  NS_LOG_INFO ("SRS Frame - Theoretical SINR: " << *m_expectedSinr);
476  NS_LOG_INFO ("SRS Frame - Calculated SINR: " << *m_actualSinr);
477 
478  NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL (*m_actualSinr, *m_expectedSinr, 0.0000001, "Data Frame - Wrong SINR !");
479  ulPhy->Dispose ();
480  Simulator::Destroy ();
481 
482 }
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
A suite of tests to run.
Definition: test.h:1342
#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
encapsulates test code
Definition: test.h:1155
std::vector< BandInfo > Bands
Container of BandInfo.
virtual void AddCallback(LteChunkProcessorCallback c)
Add callback to list.
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:299
double fc
center frequency
Ptr< SpectrumPhy > txPhy
The SpectrumPhy instance that is making the transmission.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Definition: callback.h:1489
A sink to be plugged to the callback of LteChunkProcessor allowing to save and later retrieve the lat...
Ptr< SpectrumValue > Copy() const
void AddPacket(Ptr< Packet > packet)
add a packet to the list of packet
Definition: packet-burst.cc:82
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double fl
lower limit of subband
Ptr< PacketBurst > packetBurst
The packet burst being transmitted with this signal.
#define NS_TEST_EXPECT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report if not.
Definition: test.h:739
#define NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL(actual, expected, tol, msg)
Test if two SpectrumValue instances are equal within a given tolerance.
Ptr< SpectrumValue > psd
The Power Spectral Density of the waveform, in linear units.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1014
Time duration
The duration of the packet transmission.
double fh
upper limit of subband
Set of values corresponding to a given SpectrumModel.
The building block of a SpectrumModel.