A Discrete-Event Network Simulator
API
lte-test-downlink-sinr.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Manuel Requena <manuel.requena@cttc.es>
18  * Modified by Marco Miozzo <mmiozzo@ctt.es>
19  * Extend to Data and Ctrl frames
20  */
21 
22 #include "lte-test-downlink-sinr.h"
23 
24 #include "lte-test-ue-phy.h"
25 
26 #include "ns3/boolean.h"
27 #include "ns3/log.h"
28 #include "ns3/lte-helper.h"
29 #include "ns3/lte-phy-tag.h"
30 #include "ns3/lte-spectrum-signal-parameters.h"
31 #include "ns3/simulator.h"
32 #include "ns3/spectrum-test.h"
33 #include <ns3/lte-chunk-processor.h>
34 #include <ns3/lte-control-messages.h>
35 
36 using namespace ns3;
37 
38 NS_LOG_COMPONENT_DEFINE("LteDownlinkSinrTest");
39 
49  : TestSuite("lte-downlink-sinr", SYSTEM)
50 {
55 
56  Bands bands;
57  BandInfo bi;
58 
59  bi.fl = 2.400e9;
60  bi.fc = 2.410e9;
61  bi.fh = 2.420e9;
62  bands.push_back(bi);
63 
64  bi.fl = 2.420e9;
65  bi.fc = 2.431e9;
66  bi.fh = 2.442e9;
67  bands.push_back(bi);
68 
69  sm = Create<SpectrumModel>(bands);
70 
75  Ptr<SpectrumValue> rxPsd1 = Create<SpectrumValue>(sm);
76  (*rxPsd1)[0] = 1.255943215755e-15;
77  (*rxPsd1)[1] = 7.204059965732e-16;
78 
79  Ptr<SpectrumValue> theoreticalSinr1 = Create<SpectrumValue>(sm);
80  (*theoreticalSinr1)[0] = 3.72589167251055;
81  (*theoreticalSinr1)[1] = 3.72255684126076;
82 
83  AddTestCase(new LteDownlinkDataSinrTestCase(rxPsd1, theoreticalSinr1, "sdBm = [-46 -48]"),
84  TestCase::QUICK);
85  AddTestCase(new LteDownlinkCtrlSinrTestCase(rxPsd1, theoreticalSinr1, "sdBm = [-46 -48]"),
86  TestCase::QUICK);
87 
92  Ptr<SpectrumValue> rxPsd2 = Create<SpectrumValue>(sm);
93  (*rxPsd2)[0] = 2.505936168136e-17;
94  (*rxPsd2)[1] = 3.610582885110e-17;
95 
96  Ptr<SpectrumValue> theoreticalSinr2 = Create<SpectrumValue>(sm);
97  (*theoreticalSinr2)[0] = 0.0743413124381667;
98  (*theoreticalSinr2)[1] = 0.1865697965291756;
99 
100  AddTestCase(new LteDownlinkDataSinrTestCase(rxPsd2, theoreticalSinr2, "sdBm = [-63 -61]"),
101  TestCase::QUICK);
102  AddTestCase(new LteDownlinkCtrlSinrTestCase(rxPsd2, theoreticalSinr2, "sdBm = [-63 -61]"),
103  TestCase::QUICK);
104 }
105 
111 
117  Ptr<SpectrumValue> sinr,
118  std::string name)
119  : TestCase("SINR calculation in downlink Data frame: " + name),
120  m_sv(sv),
121  m_sm(sv->GetSpectrumModel()),
122  m_expectedSinr(sinr)
123 {
124  NS_LOG_INFO("Creating LenaDownlinkSinrTestCase");
125 }
126 
128 {
129 }
130 
131 void
133 {
134  Config::SetDefault("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue(false));
138  Ptr<LteSpectrumPhy> dlPhy = CreateObject<LteSpectrumPhy>();
139  Ptr<LteSpectrumPhy> ulPhy = CreateObject<LteSpectrumPhy>();
140  Ptr<LteTestUePhy> uePhy = CreateObject<LteTestUePhy>(dlPhy, ulPhy);
141  uint16_t cellId = 100;
142  dlPhy->SetCellId(cellId);
143  ulPhy->SetCellId(cellId);
144 
145  Ptr<LteChunkProcessor> chunkProcessor = Create<LteChunkProcessor>();
146  LteSpectrumValueCatcher actualSinrCatcher;
147  chunkProcessor->AddCallback(
148  MakeCallback(&LteSpectrumValueCatcher::ReportValue, &actualSinrCatcher));
149  dlPhy->AddDataSinrChunkProcessor(chunkProcessor);
150 
159  // Number of packet bursts (1 data + 4 interferences)
160  const int numOfPbs = 5;
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  // Packet bursts cellId
172  uint16_t pbCellId[numOfPbs];
173 
177  for (int pb = 0; pb < numOfPbs; pb++)
178  {
179  // Create packet burst
180  packetBursts[pb] = CreateObject<PacketBurst>();
181  pbCellId[pb] = cellId * (pb + 1);
182 
183  // Create packets and add them to the burst
184  for (int i = 0; i < numOfPkts; i++)
185  {
186  pkt[pb][i] = Create<Packet>(1000);
187 
188  packetBursts[pb]->AddPacket(pkt[pb][i]);
189  }
190  }
191 
192  Ptr<SpectrumValue> noisePsd = Create<SpectrumValue>(m_sm);
193  Ptr<SpectrumValue> i1 = Create<SpectrumValue>(m_sm);
194  Ptr<SpectrumValue> i2 = Create<SpectrumValue>(m_sm);
195  Ptr<SpectrumValue> i3 = Create<SpectrumValue>(m_sm);
196  Ptr<SpectrumValue> i4 = Create<SpectrumValue>(m_sm);
197 
198  (*noisePsd)[0] = 5.000000000000e-19;
199  (*noisePsd)[1] = 4.545454545455e-19;
200 
201  (*i1)[0] = 5.000000000000e-18;
202  (*i2)[0] = 5.000000000000e-16;
203  (*i3)[0] = 1.581138830084e-16;
204  (*i4)[0] = 7.924465962306e-17;
205  (*i1)[1] = 1.437398936440e-18;
206  (*i2)[1] = 5.722388235428e-16;
207  (*i3)[1] = 7.204059965732e-17;
208  (*i4)[1] = 5.722388235428e-17;
209 
210  Time ts = Seconds(1);
211  Time ds = Seconds(1);
212  Time ti1 = Seconds(0);
213  Time di1 = Seconds(3);
214  Time ti2 = Seconds(0.7);
215  Time di2 = Seconds(1);
216  Time ti3 = Seconds(1.2);
217  Time di3 = Seconds(1);
218  Time ti4 = Seconds(1.5);
219  Time di4 = Seconds(0.1);
220 
221  dlPhy->SetNoisePowerSpectralDensity(noisePsd);
222 
227  // eNB sends data to 2 UEs through 2 subcarriers
228  Ptr<LteSpectrumSignalParametersDataFrame> sp1 = Create<LteSpectrumSignalParametersDataFrame>();
229  sp1->psd = m_sv;
230  sp1->txPhy = nullptr;
231  sp1->duration = ds;
232  sp1->packetBurst = packetBursts[0];
233  sp1->cellId = pbCellId[0];
234  Simulator::Schedule(ts, &LteSpectrumPhy::StartRx, dlPhy, sp1);
235 
236  Ptr<LteSpectrumSignalParametersDataFrame> ip1 = Create<LteSpectrumSignalParametersDataFrame>();
237  ip1->psd = i1;
238  ip1->txPhy = nullptr;
239  ip1->duration = di1;
240  ip1->packetBurst = packetBursts[1];
241  ip1->cellId = pbCellId[1];
242  Simulator::Schedule(ti1, &LteSpectrumPhy::StartRx, dlPhy, ip1);
243 
244  Ptr<LteSpectrumSignalParametersDataFrame> ip2 = Create<LteSpectrumSignalParametersDataFrame>();
245  ip2->psd = i2;
246  ip2->txPhy = nullptr;
247  ip2->duration = di2;
248  ip2->packetBurst = packetBursts[2];
249  ip2->cellId = pbCellId[2];
250  Simulator::Schedule(ti2, &LteSpectrumPhy::StartRx, dlPhy, ip2);
251 
252  Ptr<LteSpectrumSignalParametersDataFrame> ip3 = Create<LteSpectrumSignalParametersDataFrame>();
253  ip3->psd = i3;
254  ip3->txPhy = nullptr;
255  ip3->duration = di3;
256  ip3->packetBurst = packetBursts[3];
257  ip3->cellId = pbCellId[3];
258  Simulator::Schedule(ti3, &LteSpectrumPhy::StartRx, dlPhy, ip3);
259 
260  Ptr<LteSpectrumSignalParametersDataFrame> ip4 = Create<LteSpectrumSignalParametersDataFrame>();
261  ip4->psd = i4;
262  ip4->txPhy = nullptr;
263  ip4->duration = di4;
264  ip4->packetBurst = packetBursts[4];
265  ip4->cellId = pbCellId[4];
266  Simulator::Schedule(ti4, &LteSpectrumPhy::StartRx, dlPhy, ip4);
267 
268  Simulator::Stop(Seconds(5.0));
269  Simulator::Run();
270 
271  NS_LOG_INFO("Data Frame - Theoretical SINR: " << *m_expectedSinr);
272  NS_LOG_INFO("Data Frame - Calculated SINR: " << *(actualSinrCatcher.GetValue()));
273 
274  NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL(*(actualSinrCatcher.GetValue()),
276  0.0000001,
277  "Data Frame - Wrong SINR !");
278  dlPhy->Dispose();
279  Simulator::Destroy();
280 }
281 
287  Ptr<SpectrumValue> sinr,
288  std::string name)
289  : TestCase("SINR calculation in downlink Ctrl Frame: " + name),
290  m_sv(sv),
291  m_sm(sv->GetSpectrumModel()),
292  m_expectedSinr(sinr)
293 {
294  NS_LOG_INFO("Creating LenaDownlinkCtrlSinrTestCase");
295 }
296 
298 {
299 }
300 
301 void
303 {
307  Config::SetDefault("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue(false));
308  Ptr<LteSpectrumPhy> dlPhy = CreateObject<LteSpectrumPhy>();
309  Ptr<LteSpectrumPhy> ulPhy = CreateObject<LteSpectrumPhy>();
310  Ptr<LteTestUePhy> uePhy = CreateObject<LteTestUePhy>(dlPhy, ulPhy);
311  uint16_t cellId = 100;
312  dlPhy->SetCellId(cellId);
313  ulPhy->SetCellId(cellId);
314 
315  Ptr<LteChunkProcessor> chunkProcessor = Create<LteChunkProcessor>();
316  LteSpectrumValueCatcher actualSinrCatcher;
317  chunkProcessor->AddCallback(
318  MakeCallback(&LteSpectrumValueCatcher::ReportValue, &actualSinrCatcher));
319  dlPhy->AddCtrlSinrChunkProcessor(chunkProcessor);
320 
328  // Number of ctrl bursts (1 data + 4 interferences)
329  const int numOfUes = 5;
330 
331  // Number of control messages in the list
332  const int numOfCtrlMsgs = 10;
333 
334  // control messages in the list
335  std::list<Ptr<LteControlMessage>> ctrlMsgList[numOfUes];
336 
337  // signals cellId
338  uint16_t pbCellId[numOfUes];
339 
343  for (int pb = 0; pb < numOfUes; pb++)
344  {
345  pbCellId[pb] = cellId * (pb + 1);
346 
347  // Create ctrl msg and add them to the list
348  for (int i = 0; i < numOfCtrlMsgs; i++)
349  {
350  Ptr<DlDciLteControlMessage> msg = Create<DlDciLteControlMessage>();
351  DlDciListElement_s dci;
352  msg->SetDci(dci);
353  ctrlMsgList[pb].emplace_back(msg);
354  }
355  }
356 
357  Ptr<SpectrumValue> noisePsd = Create<SpectrumValue>(m_sm);
358  Ptr<SpectrumValue> i1 = Create<SpectrumValue>(m_sm);
359  Ptr<SpectrumValue> i2 = Create<SpectrumValue>(m_sm);
360  Ptr<SpectrumValue> i3 = Create<SpectrumValue>(m_sm);
361  Ptr<SpectrumValue> i4 = Create<SpectrumValue>(m_sm);
362 
363  (*noisePsd)[0] = 5.000000000000e-19;
364  (*noisePsd)[1] = 4.545454545455e-19;
365 
366  (*i1)[0] = 5.000000000000e-18;
367  (*i2)[0] = 5.000000000000e-16;
368  (*i3)[0] = 1.581138830084e-16;
369  (*i4)[0] = 7.924465962306e-17;
370  (*i1)[1] = 1.437398936440e-18;
371  (*i2)[1] = 5.722388235428e-16;
372  (*i3)[1] = 7.204059965732e-17;
373  (*i4)[1] = 5.722388235428e-17;
374 
375  Time ts = Seconds(1);
376  Time ds = Seconds(1);
377  Time ti1 = Seconds(0);
378  Time di1 = Seconds(3);
379  Time ti2 = Seconds(0.7);
380  Time di2 = Seconds(1);
381  Time ti3 = Seconds(1.2);
382  Time di3 = Seconds(1);
383  Time ti4 = Seconds(1.5);
384  Time di4 = Seconds(0.1);
385 
386  dlPhy->SetNoisePowerSpectralDensity(noisePsd);
387 
392  // eNB sends data to 2 UEs through 2 subcarriers
394  Create<LteSpectrumSignalParametersDlCtrlFrame>();
395  sp1->psd = m_sv;
396  sp1->txPhy = nullptr;
397  sp1->duration = ds;
398  sp1->ctrlMsgList = ctrlMsgList[0];
399  sp1->cellId = pbCellId[0];
400  sp1->pss = false;
401  Simulator::Schedule(ts, &LteSpectrumPhy::StartRx, dlPhy, sp1);
402 
404  Create<LteSpectrumSignalParametersDlCtrlFrame>();
405  ip1->psd = i1;
406  ip1->txPhy = nullptr;
407  ip1->duration = di1;
408  ip1->ctrlMsgList = ctrlMsgList[1];
409  ip1->cellId = pbCellId[1];
410  ip1->pss = false;
411  Simulator::Schedule(ti1, &LteSpectrumPhy::StartRx, dlPhy, ip1);
412 
414  Create<LteSpectrumSignalParametersDlCtrlFrame>();
415  ip2->psd = i2;
416  ip2->txPhy = nullptr;
417  ip2->duration = di2;
418  ip2->ctrlMsgList = ctrlMsgList[2];
419  ip2->cellId = pbCellId[2];
420  ip2->pss = false;
421  Simulator::Schedule(ti2, &LteSpectrumPhy::StartRx, dlPhy, ip2);
422 
424  Create<LteSpectrumSignalParametersDlCtrlFrame>();
425  ip3->psd = i3;
426  ip3->txPhy = nullptr;
427  ip3->duration = di3;
428  ip3->ctrlMsgList = ctrlMsgList[3];
429  ip3->cellId = pbCellId[3];
430  ip3->pss = false;
431  Simulator::Schedule(ti3, &LteSpectrumPhy::StartRx, dlPhy, ip3);
432 
434  Create<LteSpectrumSignalParametersDlCtrlFrame>();
435  ip4->psd = i4;
436  ip4->txPhy = nullptr;
437  ip4->duration = di4;
438  ip4->ctrlMsgList = ctrlMsgList[4];
439  ip4->cellId = pbCellId[4];
440  ip4->pss = false;
441  Simulator::Schedule(ti4, &LteSpectrumPhy::StartRx, dlPhy, ip4);
442 
443  Simulator::Stop(Seconds(5.0));
444  Simulator::Run();
445 
446  NS_LOG_INFO("Ctrl Frame - Theoretical SINR: " << *m_expectedSinr);
447  NS_LOG_INFO("Ctrl Frame - Calculated SINR: " << *(actualSinrCatcher.GetValue()));
448 
449  NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL(*(actualSinrCatcher.GetValue()),
451  0.0000001,
452  "Data Frame - Wrong SINR !");
453  dlPhy->Dispose();
454  Simulator::Destroy();
455 }
A sink to be plugged to the callback of LteChunkProcessor allowing to save and later retrieve the lat...
Ptr< SpectrumValue > GetValue()
encapsulates test code
Definition: test.h:1060
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1256
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:890
#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:275
static LteDownlinkSinrTestSuite lteDownlinkSinrTestSuite
Static variable for test initialization.
#define NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL(actual, expected, tol, msg)
Test if two SpectrumValue instances are equal within a given tolerance.
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1326
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
Definition: callback.h:704
std::vector< BandInfo > Bands
Container of BandInfo.
The building block of a SpectrumModel.
double fc
center frequency
double fl
lower limit of subband
double fh
upper limit of subband
See section 4.3.1 dlDciListElement.
Definition: ff-mac-common.h:93