A Discrete-Event Network Simulator
API
lte-test-downlink-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 Ctrl frames
21  */
22 
23 #include "ns3/simulator.h"
24 
25 #include "ns3/log.h"
26 
27 #include "ns3/spectrum-test.h"
28 #include "ns3/boolean.h"
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-downlink-sinr.h"
34 #include <ns3/lte-control-messages.h>
35 #include "ns3/lte-helper.h"
36 #include <ns3/lte-chunk-processor.h>
37 
38 using namespace ns3;
39 
40 NS_LOG_COMPONENT_DEFINE ("LteDownlinkSinrTest");
41 
51  : TestSuite ("lte-downlink-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] = 7.204059965732e-16;
79 
80  Ptr<SpectrumValue> theoreticalSinr1 = Create<SpectrumValue> (sm);
81  (*theoreticalSinr1)[0] = 3.72589167251055;
82  (*theoreticalSinr1)[1] = 3.72255684126076;
83 
84  AddTestCase (new LteDownlinkDataSinrTestCase (rxPsd1, theoreticalSinr1, "sdBm = [-46 -48]"), TestCase::QUICK);
85  AddTestCase (new LteDownlinkCtrlSinrTestCase (rxPsd1, theoreticalSinr1, "sdBm = [-46 -48]"), TestCase::QUICK);
86 
90  Ptr<SpectrumValue> rxPsd2 = Create<SpectrumValue> (sm);
91  (*rxPsd2)[0] = 2.505936168136e-17;
92  (*rxPsd2)[1] = 3.610582885110e-17;
93 
94  Ptr<SpectrumValue> theoreticalSinr2 = Create<SpectrumValue> (sm);
95  (*theoreticalSinr2)[0] = 0.0743413124381667;
96  (*theoreticalSinr2)[1] = 0.1865697965291756;
97 
98  AddTestCase (new LteDownlinkDataSinrTestCase (rxPsd2, theoreticalSinr2, "sdBm = [-63 -61]"), TestCase::QUICK);
99  AddTestCase (new LteDownlinkCtrlSinrTestCase (rxPsd2, theoreticalSinr2, "sdBm = [-63 -61]"), TestCase::QUICK);
100 
101 
102 }
103 
105 
106 
112  : TestCase ("SINR calculation in downlink Data frame: " + name),
113  m_sv (sv),
114  m_sm (sv->GetSpectrumModel ()),
115  m_expectedSinr (sinr)
116 {
117  NS_LOG_INFO ("Creating LenaDownlinkSinrTestCase");
118 }
119 
121 {
122 }
123 
124 
125 void
127 {
128  Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (false));
132  Ptr<LteSpectrumPhy> dlPhy = CreateObject<LteSpectrumPhy> ();
133  Ptr<LteSpectrumPhy> ulPhy = CreateObject<LteSpectrumPhy> ();
134  Ptr<LteTestUePhy> uePhy = CreateObject<LteTestUePhy> (dlPhy, ulPhy);
135  uint16_t cellId = 100;
136  dlPhy->SetCellId (cellId);
137  ulPhy->SetCellId (cellId);
138 
139  Ptr<LteChunkProcessor> chunkProcessor = Create<LteChunkProcessor> ();
140  LteSpectrumValueCatcher actualSinrCatcher;
141  chunkProcessor->AddCallback (MakeCallback (&LteSpectrumValueCatcher::ReportValue, &actualSinrCatcher));
142  dlPhy->AddDataSinrChunkProcessor (chunkProcessor);
143 
152  // Number of packet bursts (1 data + 4 interferences)
153  const int numOfPbs = 5;
154 
155  // Number of packets in the packet bursts
156  const int numOfPkts = 10;
157 
158  // Packet bursts
159  Ptr<PacketBurst> packetBursts[numOfPbs];
160 
161  // Packets
162  Ptr<Packet> pkt[numOfPbs][numOfPkts];
163 
164  // Packet bursts cellId
165  uint16_t pbCellId[numOfPbs];
166 
170  for ( int pb = 0 ; pb < numOfPbs ; pb++ )
171  {
172  // Create packet burst
173  packetBursts[pb] = CreateObject<PacketBurst> ();
174  pbCellId[pb] = cellId * (pb + 1);
175 
176  // Create packets and add them to the burst
177  for ( int i = 0 ; i < numOfPkts ; i++ )
178  {
179  pkt[pb][i] = Create<Packet> (1000);
180 
181  packetBursts[pb]->AddPacket ( pkt[pb][i] );
182  }
183  }
184 
185 
186  Ptr<SpectrumValue> noisePsd = Create<SpectrumValue> (m_sm);
187  Ptr<SpectrumValue> i1 = Create<SpectrumValue> (m_sm);
188  Ptr<SpectrumValue> i2 = Create<SpectrumValue> (m_sm);
189  Ptr<SpectrumValue> i3 = Create<SpectrumValue> (m_sm);
190  Ptr<SpectrumValue> i4 = Create<SpectrumValue> (m_sm);
191 
192  (*noisePsd)[0] = 5.000000000000e-19;
193  (*noisePsd)[1] = 4.545454545455e-19;
194 
195  (*i1)[0] = 5.000000000000e-18;
196  (*i2)[0] = 5.000000000000e-16;
197  (*i3)[0] = 1.581138830084e-16;
198  (*i4)[0] = 7.924465962306e-17;
199  (*i1)[1] = 1.437398936440e-18;
200  (*i2)[1] = 5.722388235428e-16;
201  (*i3)[1] = 7.204059965732e-17;
202  (*i4)[1] = 5.722388235428e-17;
203 
204  Time ts = Seconds (1);
205  Time ds = Seconds (1);
206  Time ti1 = Seconds (0);
207  Time di1 = Seconds (3);
208  Time ti2 = Seconds (0.7);
209  Time di2 = Seconds (1);
210  Time ti3 = Seconds (1.2);
211  Time di3 = Seconds (1);
212  Time ti4 = Seconds (1.5);
213  Time di4 = Seconds (0.1);
214 
215  dlPhy->SetNoisePowerSpectralDensity (noisePsd);
216 
221  // eNB sends data to 2 UEs through 2 subcarriers
222  Ptr<LteSpectrumSignalParametersDataFrame> sp1 = Create<LteSpectrumSignalParametersDataFrame> ();
223  sp1->psd = m_sv;
224  sp1->txPhy = 0;
225  sp1->duration = ds;
226  sp1->packetBurst = packetBursts[0];
227  sp1->cellId = pbCellId[0];
228  Simulator::Schedule (ts, &LteSpectrumPhy::StartRx, dlPhy, sp1);
229 
230 
231  Ptr<LteSpectrumSignalParametersDataFrame> ip1 = Create<LteSpectrumSignalParametersDataFrame> ();
232  ip1->psd = i1;
233  ip1->txPhy = 0;
234  ip1->duration = di1;
235  ip1->packetBurst = packetBursts[1];
236  ip1->cellId = pbCellId[1];
237  Simulator::Schedule (ti1, &LteSpectrumPhy::StartRx, dlPhy, ip1);
238 
239  Ptr<LteSpectrumSignalParametersDataFrame> ip2 = Create<LteSpectrumSignalParametersDataFrame> ();
240  ip2->psd = i2;
241  ip2->txPhy = 0;
242  ip2->duration = di2;
243  ip2->packetBurst = packetBursts[2];
244  ip2->cellId = pbCellId[2];
245  Simulator::Schedule (ti2, &LteSpectrumPhy::StartRx, dlPhy, ip2);
246 
247  Ptr<LteSpectrumSignalParametersDataFrame> ip3 = Create<LteSpectrumSignalParametersDataFrame> ();
248  ip3->psd = i3;
249  ip3->txPhy = 0;
250  ip3->duration = di3;
251  ip3->packetBurst = packetBursts[3];
252  ip3->cellId = pbCellId[3];
253  Simulator::Schedule (ti3, &LteSpectrumPhy::StartRx, dlPhy, ip3);
254 
255  Ptr<LteSpectrumSignalParametersDataFrame> ip4 = Create<LteSpectrumSignalParametersDataFrame> ();
256  ip4->psd = i4;
257  ip4->txPhy = 0;
258  ip4->duration = di4;
259  ip4->packetBurst = packetBursts[4];
260  ip4->cellId = pbCellId[4];
261  Simulator::Schedule (ti4, &LteSpectrumPhy::StartRx, dlPhy, ip4);
262 
263  Simulator::Stop (Seconds (5.0));
264  Simulator::Run ();
265 
266  NS_LOG_INFO ("Data Frame - Theoretical SINR: " << *m_expectedSinr);
267  NS_LOG_INFO ("Data Frame - Calculated SINR: " << *(actualSinrCatcher.GetValue ()));
268 
269  NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL(*(actualSinrCatcher.GetValue ()), *m_expectedSinr, 0.0000001, "Data Frame - Wrong SINR !");
270  dlPhy->Dispose ();
271  Simulator::Destroy ();
272 }
273 
274 
275 
281 : TestCase ("SINR calculation in downlink Ctrl Frame: " + name),
282 m_sv (sv),
283 m_sm (sv->GetSpectrumModel ()),
284 m_expectedSinr (sinr)
285 {
286  NS_LOG_INFO ("Creating LenaDownlinkCtrlSinrTestCase");
287 }
288 
290 {
291 }
292 
293 void
295 {
299  Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (false));
300  Ptr<LteSpectrumPhy> dlPhy = CreateObject<LteSpectrumPhy> ();
301  Ptr<LteSpectrumPhy> ulPhy = CreateObject<LteSpectrumPhy> ();
302  Ptr<LteTestUePhy> uePhy = CreateObject<LteTestUePhy> (dlPhy, ulPhy);
303  uint16_t cellId = 100;
304  dlPhy->SetCellId (cellId);
305  ulPhy->SetCellId (cellId);
306 
307  Ptr<LteChunkProcessor> chunkProcessor = Create<LteChunkProcessor> ();
308  LteSpectrumValueCatcher actualSinrCatcher;
309  chunkProcessor->AddCallback (MakeCallback (&LteSpectrumValueCatcher::ReportValue, &actualSinrCatcher));
310  dlPhy->AddCtrlSinrChunkProcessor (chunkProcessor);
311 
319  // Number of ctrl bursts (1 data + 4 interferences)
320  const int numOfUes = 5;
321 
322  // Number of control messages in the list
323  const int numOfCtrlMsgs = 10;
324 
325  // control messages in the list
326  std::list<Ptr<LteControlMessage> > ctrlMsgList[numOfUes];
327 
328  // signals cellId
329  uint16_t pbCellId[numOfUes];
330 
334  for ( int pb = 0 ; pb < numOfUes ; pb++ )
335  {
336  pbCellId[pb] = cellId * (pb + 1);
337 
338  // Create ctrl msg and add them to the list
339  for ( int i = 0 ; i < numOfCtrlMsgs ; i++ )
340  {
341  Ptr<DlDciLteControlMessage> msg = Create<DlDciLteControlMessage> ();
342  DlDciListElement_s dci;
343  msg->SetDci (dci);
344  ctrlMsgList[pb].push_back (msg);
345  }
346  }
347 
348 
349  Ptr<SpectrumValue> noisePsd = Create<SpectrumValue> (m_sm);
350  Ptr<SpectrumValue> i1 = Create<SpectrumValue> (m_sm);
351  Ptr<SpectrumValue> i2 = Create<SpectrumValue> (m_sm);
352  Ptr<SpectrumValue> i3 = Create<SpectrumValue> (m_sm);
353  Ptr<SpectrumValue> i4 = Create<SpectrumValue> (m_sm);
354 
355  (*noisePsd)[0] = 5.000000000000e-19;
356  (*noisePsd)[1] = 4.545454545455e-19;
357 
358  (*i1)[0] = 5.000000000000e-18;
359  (*i2)[0] = 5.000000000000e-16;
360  (*i3)[0] = 1.581138830084e-16;
361  (*i4)[0] = 7.924465962306e-17;
362  (*i1)[1] = 1.437398936440e-18;
363  (*i2)[1] = 5.722388235428e-16;
364  (*i3)[1] = 7.204059965732e-17;
365  (*i4)[1] = 5.722388235428e-17;
366 
367  Time ts = Seconds (1);
368  Time ds = Seconds (1);
369  Time ti1 = Seconds (0);
370  Time di1 = Seconds (3);
371  Time ti2 = Seconds (0.7);
372  Time di2 = Seconds (1);
373  Time ti3 = Seconds (1.2);
374  Time di3 = Seconds (1);
375  Time ti4 = Seconds (1.5);
376  Time di4 = Seconds (0.1);
377 
378  dlPhy->SetNoisePowerSpectralDensity (noisePsd);
379 
384  // eNB sends data to 2 UEs through 2 subcarriers
385  Ptr<LteSpectrumSignalParametersDlCtrlFrame> sp1 = Create<LteSpectrumSignalParametersDlCtrlFrame> ();
386  sp1->psd = m_sv;
387  sp1->txPhy = 0;
388  sp1->duration = ds;
389  sp1->ctrlMsgList = ctrlMsgList[0];
390  sp1->cellId = pbCellId[0];
391  sp1->pss = false;
392  Simulator::Schedule (ts, &LteSpectrumPhy::StartRx, dlPhy, sp1);
393 
394 
395  Ptr<LteSpectrumSignalParametersDlCtrlFrame> ip1 = Create<LteSpectrumSignalParametersDlCtrlFrame> ();
396  ip1->psd = i1;
397  ip1->txPhy = 0;
398  ip1->duration = di1;
399  ip1->ctrlMsgList = ctrlMsgList[1];
400  ip1->cellId = pbCellId[1];
401  ip1->pss = false;
402  Simulator::Schedule (ti1, &LteSpectrumPhy::StartRx, dlPhy, ip1);
403 
404  Ptr<LteSpectrumSignalParametersDlCtrlFrame> ip2 = Create<LteSpectrumSignalParametersDlCtrlFrame> ();
405  ip2->psd = i2;
406  ip2->txPhy = 0;
407  ip2->duration = di2;
408  ip2->ctrlMsgList = ctrlMsgList[2];
409  ip2->cellId = pbCellId[2];
410  ip2->pss = false;
411  Simulator::Schedule (ti2, &LteSpectrumPhy::StartRx, dlPhy, ip2);
412 
413  Ptr<LteSpectrumSignalParametersDlCtrlFrame> ip3 = Create<LteSpectrumSignalParametersDlCtrlFrame> ();
414  ip3->psd = i3;
415  ip3->txPhy = 0;
416  ip3->duration = di3;
417  ip3->ctrlMsgList = ctrlMsgList[3];
418  ip3->cellId = pbCellId[3];
419  ip3->pss = false;
420  Simulator::Schedule (ti3, &LteSpectrumPhy::StartRx, dlPhy, ip3);
421 
422  Ptr<LteSpectrumSignalParametersDlCtrlFrame> ip4 = Create<LteSpectrumSignalParametersDlCtrlFrame> ();
423  ip4->psd = i4;
424  ip4->txPhy = 0;
425  ip4->duration = di4;
426  ip4->ctrlMsgList = ctrlMsgList[4];
427  ip4->cellId = pbCellId[4];
428  ip4->pss = false;
429  Simulator::Schedule (ti4, &LteSpectrumPhy::StartRx, dlPhy, ip4);
430 
431  Simulator::Stop (Seconds (5.0));
432  Simulator::Run ();
433 
434  NS_LOG_INFO ("Ctrl Frame - Theoretical SINR: " << *m_expectedSinr);
435  NS_LOG_INFO ("Ctrl Frame - Calculated SINR: " << *(actualSinrCatcher.GetValue ()));
436 
437  NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL(*(actualSinrCatcher.GetValue ()), *m_expectedSinr, 0.0000001, "Data Frame - Wrong SINR !");
438  dlPhy->Dispose ();
439  Simulator::Destroy ();
440 }
See section 4.3.1 dlDciListElement.
Definition: ff-mac-common.h:93
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
std::list< Ptr< LteControlMessage > > ctrlMsgList
control message list
AttributeValue implementation for Boolean.
Definition: boolean.h:36
A suite of tests to run.
Definition: test.h:1343
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
encapsulates test code
Definition: test.h:1153
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:1610
A sink to be plugged to the callback of LteChunkProcessor allowing to save and later retrieve the lat...
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.
void SetDci(DlDciListElement_s dci)
add a DCI into the message
#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:1070
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:812
Time duration
The duration of the packet transmission.
double fh
upper limit of subband
The building block of a SpectrumModel.