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"
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 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_sinr (sinr)
125 {
126  NS_LOG_INFO ("Creating LteUplinkDataSinrTestCase");
127 }
128 
130 {
131 }
132 
133 void
135 {
139  Ptr<LteSpectrumPhy> dlPhy = CreateObject<LteSpectrumPhy> ();
140  Ptr<LteSpectrumPhy> ulPhy = CreateObject<LteSpectrumPhy> ();
141  Ptr<LteTestUePhy> uePhy = CreateObject<LteTestUePhy> (dlPhy, ulPhy);
142  uint16_t cellId = 100;
143  dlPhy->SetCellId (cellId);
144  ulPhy->SetCellId (cellId);
145 
146  Ptr<LteTestSinrChunkProcessor> chunkProcessor = Create<LteTestSinrChunkProcessor> ();
147  ulPhy->AddDataSinrChunkProcessor (chunkProcessor);
148 
157  // Number of packet bursts (2 data + 4 interferences)
158  const int numOfDataPbs = 2;
159  const int numOfIntfPbs = 4;
160  const int numOfPbs = numOfDataPbs + numOfIntfPbs;
161 
162  // Number of packets in the packet bursts
163  const int numOfPkts = 10;
164 
165  // Packet bursts
166  Ptr<PacketBurst> packetBursts[numOfPbs];
167 
168  // Packets
169  Ptr<Packet> pkt[numOfPbs][numOfPkts];
170 
171  // Bursts cellId
172  uint16_t pbCellId[numOfPbs];
173 
174 
175 
179  int pb = 0;
180  for ( int dataPb = 0 ; dataPb < numOfDataPbs ; dataPb++, pb++ )
181  {
182  // Create packet burst
183  packetBursts[pb] = CreateObject<PacketBurst> ();
184  pbCellId[pb] = cellId;
185  // Create packets and add them to the burst
186  for ( int i = 0 ; i < numOfPkts ; i++ )
187  {
188  pkt[pb][i] = Create<Packet> (1000);
189 
190  packetBursts[pb]->AddPacket ( pkt[pb][i] );
191  }
192  }
193  for ( int intfPb = 0 ; intfPb < numOfIntfPbs ; intfPb++, pb++ )
194  {
195  // Create packet burst
196  packetBursts[pb] = CreateObject<PacketBurst> ();
197  pbCellId[pb] = cellId * (pb + 1);
198 
199  // Create packets and add them to the burst
200  for ( int i = 0 ; i < numOfPkts ; i++ )
201  {
202  pkt[pb][i] = Create<Packet> (1000);
203 
204  packetBursts[pb]->AddPacket ( pkt[pb][i] );
205  }
206  }
207 
208 
209  Ptr<SpectrumValue> noisePsd = Create<SpectrumValue> (m_sm);
210  Ptr<SpectrumValue> i1 = Create<SpectrumValue> (m_sm);
211  Ptr<SpectrumValue> i2 = Create<SpectrumValue> (m_sm);
212  Ptr<SpectrumValue> i3 = Create<SpectrumValue> (m_sm);
213  Ptr<SpectrumValue> i4 = Create<SpectrumValue> (m_sm);
214 
215  (*noisePsd)[0] = 5.000000000000e-19;
216  (*noisePsd)[1] = 4.545454545455e-19;
217 
218  (*i1)[0] = 5.000000000000e-18;
219  (*i2)[0] = 5.000000000000e-16;
220  (*i3)[0] = 1.581138830084e-16;
221  (*i4)[0] = 7.924465962306e-17;
222  (*i1)[1] = 1.437398936440e-18;
223  (*i2)[1] = 5.722388235428e-16;
224  (*i3)[1] = 7.204059965732e-17;
225  (*i4)[1] = 5.722388235428e-17;
226 
227  Time ts = Seconds (1);
228  Time ds = Seconds (1);
229  Time ti1 = Seconds (0);
230  Time di1 = Seconds (3);
231  Time ti2 = Seconds (0.7);
232  Time di2 = Seconds (1);
233  Time ti3 = Seconds (1.2);
234  Time di3 = Seconds (1);
235  Time ti4 = Seconds (1.5);
236  Time di4 = Seconds (0.1);
237 
238  ulPhy->SetNoisePowerSpectralDensity (noisePsd);
239 
244  // 2 UEs send data to the eNB through 2 subcarriers
245  Ptr<LteSpectrumSignalParametersDataFrame> sp1 = Create<LteSpectrumSignalParametersDataFrame> ();
246  sp1->psd = m_sv1;
247  sp1->txPhy = 0;
248  sp1->duration = ds;
249  sp1->packetBurst = packetBursts[0];
250  sp1->cellId = pbCellId[0];
251  Simulator::Schedule (ts, &LteSpectrumPhy::StartRx, ulPhy, sp1);
252 
253  Ptr<LteSpectrumSignalParametersDataFrame> sp2 = Create<LteSpectrumSignalParametersDataFrame> ();
254  sp2->psd = m_sv2;
255  sp2->txPhy = 0;
256  sp2->duration = ds;
257  sp2->packetBurst = packetBursts[1];
258  sp2->cellId = pbCellId[1];
259  Simulator::Schedule (ts, &LteSpectrumPhy::StartRx, ulPhy, sp2);
260 
261 
262  Ptr<LteSpectrumSignalParametersDataFrame> ip1 = Create<LteSpectrumSignalParametersDataFrame> ();
263  ip1->psd = i1;
264  ip1->txPhy = 0;
265  ip1->duration = di1;
266  ip1->packetBurst = packetBursts[2];
267  ip1->cellId = pbCellId[2];
268  Simulator::Schedule (ti1, &LteSpectrumPhy::StartRx, ulPhy, ip1);
269 
270  Ptr<LteSpectrumSignalParametersDataFrame> ip2 = Create<LteSpectrumSignalParametersDataFrame> ();
271  ip2->psd = i2;
272  ip2->txPhy = 0;
273  ip2->duration = di2;
274  ip2->packetBurst = packetBursts[3];
275  ip2->cellId = pbCellId[3];
276  Simulator::Schedule (ti2, &LteSpectrumPhy::StartRx, ulPhy, ip2);
277 
278  Ptr<LteSpectrumSignalParametersDataFrame> ip3 = Create<LteSpectrumSignalParametersDataFrame> ();
279  ip3->psd = i3;
280  ip3->txPhy = 0;
281  ip3->duration = di3;
282  ip3->packetBurst = packetBursts[4];
283  ip3->cellId = pbCellId[4];
284  Simulator::Schedule (ti3, &LteSpectrumPhy::StartRx, ulPhy, ip3);
285 
286  Ptr<LteSpectrumSignalParametersDataFrame> ip4 = Create<LteSpectrumSignalParametersDataFrame> ();
287  ip4->psd = i4;
288  ip4->txPhy = 0;
289  ip4->duration = di4;
290  ip4->packetBurst = packetBursts[5];
291  ip4->cellId = pbCellId[5];
292  Simulator::Schedule (ti4, &LteSpectrumPhy::StartRx, ulPhy, ip4);
293 
294  Simulator::Stop (Seconds (5.0));
295  Simulator::Run ();
296 
301  Ptr<SpectrumValue> calculatedSinr = chunkProcessor->GetSinr ();
302 
303  NS_LOG_INFO ("Data Frame - Theoretical SINR: " << *m_sinr);
304  NS_LOG_INFO ("Data Frame - Calculated SINR: " << *calculatedSinr);
305 
306  NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL (*calculatedSinr, *m_sinr, 0.0000001, "Data Frame - Wrong SINR !");
307  ulPhy->Dispose ();
308  Simulator::Destroy ();
309 
310 }
311 
312 
318 : TestCase ("SINR calculation in uplink srs frame: " + name),
319 m_sv1 (sv1),
320 m_sv2 (sv2),
321 m_sm (sv1->GetSpectrumModel ()),
322 m_sinr (sinr)
323 {
324  NS_LOG_INFO ("Creating LteUplinkSrsSinrTestCase");
325 }
326 
328 {
329 }
330 
331 void
333 {
338  Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();
339  // lteHelper->EnableLogComponents ();
340  Ptr<LteSpectrumPhy> dlPhy = CreateObject<LteSpectrumPhy> ();
341  Ptr<LteSpectrumPhy> ulPhy = CreateObject<LteSpectrumPhy> ();
342  Ptr<LteTestUePhy> uePhy = CreateObject<LteTestUePhy> (dlPhy, ulPhy);
343  uint16_t cellId = 100;
344  dlPhy->SetCellId (cellId);
345  ulPhy->SetCellId (cellId);
346 
347  Ptr<LteTestSinrChunkProcessor> chunkProcessor = Create<LteTestSinrChunkProcessor> ();
348  ulPhy->AddCtrlSinrChunkProcessor (chunkProcessor);
349 
359  // Number of packet bursts (2 data + 4 interferences)
360  int numOfDataSignals = 2;
361  int numOfIntfSignals = 4;
362  int numOfSignals = numOfDataSignals + numOfIntfSignals;
363 
364  uint16_t pbCellId[numOfSignals];
365 
366 
367 
371  int pb = 0;
372  for ( int dataPb = 0 ; dataPb < numOfDataSignals ; dataPb++, pb++ )
373  {
374  pbCellId[pb] = cellId;
375 
376  }
377  for ( int intfPb = 0 ; intfPb < numOfIntfSignals ; intfPb++, pb++ )
378  {
379 
380  pbCellId[pb] = cellId * (pb + 1);
381 
382  }
383 
384 
385  Ptr<SpectrumValue> noisePsd = Create<SpectrumValue> (m_sm);
386  Ptr<SpectrumValue> i1 = Create<SpectrumValue> (m_sm);
387  Ptr<SpectrumValue> i2 = Create<SpectrumValue> (m_sm);
388  Ptr<SpectrumValue> i3 = Create<SpectrumValue> (m_sm);
389  Ptr<SpectrumValue> i4 = Create<SpectrumValue> (m_sm);
390 
391  (*noisePsd)[0] = 5.000000000000e-19;
392  (*noisePsd)[1] = 4.545454545455e-19;
393 
394  (*i1)[0] = 5.000000000000e-18;
395  (*i2)[0] = 5.000000000000e-16;
396  (*i3)[0] = 1.581138830084e-16;
397  (*i4)[0] = 7.924465962306e-17;
398  (*i1)[1] = 1.437398936440e-18;
399  (*i2)[1] = 5.722388235428e-16;
400  (*i3)[1] = 7.204059965732e-17;
401  (*i4)[1] = 5.722388235428e-17;
402 
403  Time ts = Seconds (1);
404  Time ds = Seconds (1);
405  Time ti1 = Seconds (0);
406  Time di1 = Seconds (3);
407  Time ti2 = Seconds (0.7);
408  Time di2 = Seconds (1);
409  Time ti3 = Seconds (1.2);
410  Time di3 = Seconds (1);
411  Time ti4 = Seconds (1.5);
412  Time di4 = Seconds (0.1);
413 
414  ulPhy->SetNoisePowerSpectralDensity (noisePsd);
415 
420  // 2 UEs send data to the eNB through 2 subcarriers
421  Ptr<LteSpectrumSignalParametersUlSrsFrame> sp1 = Create<LteSpectrumSignalParametersUlSrsFrame> ();
422  sp1->psd = m_sv1;
423  sp1->txPhy = 0;
424  sp1->duration = ds;
425  sp1->cellId = pbCellId[0];
426  Simulator::Schedule (ts, &LteSpectrumPhy::StartRx, ulPhy, sp1);
427 
428  Ptr<LteSpectrumSignalParametersUlSrsFrame> sp2 = Create<LteSpectrumSignalParametersUlSrsFrame> ();
429  sp2->psd = m_sv2;
430  sp2->txPhy = 0;
431  sp2->duration = ds;
432  sp2->cellId = pbCellId[1];
433  Simulator::Schedule (ts, &LteSpectrumPhy::StartRx, ulPhy, sp2);
434 
435 
436  Ptr<LteSpectrumSignalParametersUlSrsFrame> ip1 = Create<LteSpectrumSignalParametersUlSrsFrame> ();
437  ip1->psd = i1;
438  ip1->txPhy = 0;
439  ip1->duration = di1;
440  ip1->cellId = pbCellId[2];
441  Simulator::Schedule (ti1, &LteSpectrumPhy::StartRx, ulPhy, ip1);
442 
443  Ptr<LteSpectrumSignalParametersUlSrsFrame> ip2 = Create<LteSpectrumSignalParametersUlSrsFrame> ();
444  ip2->psd = i2;
445  ip2->txPhy = 0;
446  ip2->duration = di2;
447  ip2->cellId = pbCellId[3];
448  Simulator::Schedule (ti2, &LteSpectrumPhy::StartRx, ulPhy, ip2);
449 
450  Ptr<LteSpectrumSignalParametersUlSrsFrame> ip3 = Create<LteSpectrumSignalParametersUlSrsFrame> ();
451  ip3->psd = i3;
452  ip3->txPhy = 0;
453  ip3->duration = di3;
454  ip3->cellId = pbCellId[4];
455  Simulator::Schedule (ti3, &LteSpectrumPhy::StartRx, ulPhy, ip3);
456 
457  Ptr<LteSpectrumSignalParametersUlSrsFrame> ip4 = Create<LteSpectrumSignalParametersUlSrsFrame> ();
458  ip4->psd = i4;
459  ip4->txPhy = 0;
460  ip4->duration = di4;
461  ip4->cellId = pbCellId[5];
462  Simulator::Schedule (ti4, &LteSpectrumPhy::StartRx, ulPhy, ip4);
463 
464  Simulator::Stop (Seconds (5.0));
465  Simulator::Run ();
466 
471  Ptr<SpectrumValue> calculatedSinr = chunkProcessor->GetSinr ();
472 
473  NS_LOG_INFO ("SRS Frame - Theoretical SINR: " << *m_sinr);
474  NS_LOG_INFO ("SRS Frame - Calculated SINR: " << *calculatedSinr);
475 
476  NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL (*calculatedSinr, *m_sinr, 0.0000001, "Data Frame - Wrong SINR !");
477  ulPhy->Dispose ();
478  Simulator::Destroy ();
479 
480 }
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:95
A suite of tests to run.
Definition: test.h:1270
#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:1102
std::vector< BandInfo > Bands
void AddTestCase(TestCase *testCase, enum TestDuration duration)
Add an individual child TestCase to this test suite.
Definition: test.cc:184
double fc
center frequency
Ptr< SpectrumPhy > txPhy
The SpectrumPhy instance that is making the transmission.
void AddPacket(Ptr< Packet > packet)
add a packet to the list of packet
Definition: packet-burst.cc:81
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_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:859
Time duration
The duration of the packet transmission.
double fh
upper limit of subband
The building block of a SpectrumModel.