A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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"
32 #include "ns3/lte-spectrum-signal-parameters.h"
33 
34 #include "lte-test-downlink-sinr.h"
35 #include <ns3/lte-control-messages.h>
36 #include "ns3/lte-helper.h"
37 
38 NS_LOG_COMPONENT_DEFINE ("LteDownlinkSinrTest");
39 
40 namespace ns3 {
41 
42 
52  : TestSuite ("lte-downlink-sinr", SYSTEM)
53 {
58 
59  Bands bands;
60  BandInfo bi;
61 
62  bi.fl = 2.400e9;
63  bi.fc = 2.410e9;
64  bi.fh = 2.420e9;
65  bands.push_back (bi);
66 
67  bi.fl = 2.420e9;
68  bi.fc = 2.431e9;
69  bi.fh = 2.442e9;
70  bands.push_back (bi);
71 
72  sm = Create<SpectrumModel> (bands);
73 
77  Ptr<SpectrumValue> rxPsd1 = Create<SpectrumValue> (sm);
78  (*rxPsd1)[0] = 1.255943215755e-15;
79  (*rxPsd1)[1] = 7.204059965732e-16;
80 
81  Ptr<SpectrumValue> theoreticalSinr1 = Create<SpectrumValue> (sm);
82  (*theoreticalSinr1)[0] = 3.72589167251055;
83  (*theoreticalSinr1)[1] = 3.72255684126076;
84 
85  AddTestCase (new LteDownlinkDataSinrTestCase (rxPsd1, theoreticalSinr1, "sdBm = [-46 -48]"), TestCase::QUICK);
86  AddTestCase (new LteDownlinkCtrlSinrTestCase (rxPsd1, theoreticalSinr1, "sdBm = [-46 -48]"), TestCase::QUICK);
87 
91  Ptr<SpectrumValue> rxPsd2 = Create<SpectrumValue> (sm);
92  (*rxPsd2)[0] = 2.505936168136e-17;
93  (*rxPsd2)[1] = 3.610582885110e-17;
94 
95  Ptr<SpectrumValue> theoreticalSinr2 = Create<SpectrumValue> (sm);
96  (*theoreticalSinr2)[0] = 0.0743413124381667;
97  (*theoreticalSinr2)[1] = 0.1865697965291756;
98 
99  AddTestCase (new LteDownlinkDataSinrTestCase (rxPsd2, theoreticalSinr2, "sdBm = [-63 -61]"), TestCase::QUICK);
100  AddTestCase (new LteDownlinkCtrlSinrTestCase (rxPsd2, theoreticalSinr2, "sdBm = [-63 -61]"), TestCase::QUICK);
101 
102 
103 }
104 
106 
107 
113  : TestCase ("SINR calculation in downlink Data frame: " + name),
114  m_sv (sv),
115  m_sm (sv->GetSpectrumModel ()),
116  m_sinr (sinr)
117 {
118  NS_LOG_INFO ("Creating LenaDownlinkSinrTestCase");
119 }
120 
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<LteTestSinrChunkProcessor> chunkProcessor = Create<LteTestSinrChunkProcessor> (uePhy->GetObject<LtePhy> ());
140  dlPhy->AddDataSinrChunkProcessor (chunkProcessor);
141 
150  // Number of packet bursts (1 data + 4 interferences)
151  const int numOfPbs = 5;
152 
153  // Number of packets in the packet bursts
154  const int numOfPkts = 10;
155 
156  // Packet bursts
157  Ptr<PacketBurst> packetBursts[numOfPbs];
158 
159  // Packets
160  Ptr<Packet> pkt[numOfPbs][numOfPkts];
161 
162  // Packet bursts cellId
163  uint16_t pbCellId[numOfPbs];
164 
168  for ( int pb = 0 ; pb < numOfPbs ; pb++ )
169  {
170  // Create packet burst
171  packetBursts[pb] = CreateObject<PacketBurst> ();
172  pbCellId[pb] = cellId * (pb + 1);
173 
174  // Create packets and add them to the burst
175  for ( int i = 0 ; i < numOfPkts ; i++ )
176  {
177  pkt[pb][i] = Create<Packet> (1000);
178 
179  packetBursts[pb]->AddPacket ( pkt[pb][i] );
180  }
181  }
182 
183 
184  Ptr<SpectrumValue> noisePsd = Create<SpectrumValue> (m_sm);
185  Ptr<SpectrumValue> i1 = Create<SpectrumValue> (m_sm);
186  Ptr<SpectrumValue> i2 = Create<SpectrumValue> (m_sm);
187  Ptr<SpectrumValue> i3 = Create<SpectrumValue> (m_sm);
188  Ptr<SpectrumValue> i4 = Create<SpectrumValue> (m_sm);
189 
190  (*noisePsd)[0] = 5.000000000000e-19;
191  (*noisePsd)[1] = 4.545454545455e-19;
192 
193  (*i1)[0] = 5.000000000000e-18;
194  (*i2)[0] = 5.000000000000e-16;
195  (*i3)[0] = 1.581138830084e-16;
196  (*i4)[0] = 7.924465962306e-17;
197  (*i1)[1] = 1.437398936440e-18;
198  (*i2)[1] = 5.722388235428e-16;
199  (*i3)[1] = 7.204059965732e-17;
200  (*i4)[1] = 5.722388235428e-17;
201 
202  Time ts = Seconds (1);
203  Time ds = Seconds (1);
204  Time ti1 = Seconds (0);
205  Time di1 = Seconds (3);
206  Time ti2 = Seconds (0.7);
207  Time di2 = Seconds (1);
208  Time ti3 = Seconds (1.2);
209  Time di3 = Seconds (1);
210  Time ti4 = Seconds (1.5);
211  Time di4 = Seconds (0.1);
212 
213  dlPhy->SetNoisePowerSpectralDensity (noisePsd);
214 
219  // eNB sends data to 2 UEs through 2 subcarriers
220  Ptr<LteSpectrumSignalParametersDataFrame> sp1 = Create<LteSpectrumSignalParametersDataFrame> ();
221  sp1->psd = m_sv;
222  sp1->txPhy = 0;
223  sp1->duration = ds;
224  sp1->packetBurst = packetBursts[0];
225  sp1->cellId = pbCellId[0];
226  Simulator::Schedule (ts, &LteSpectrumPhy::StartRx, dlPhy, sp1);
227 
228 
229  Ptr<LteSpectrumSignalParametersDataFrame> ip1 = Create<LteSpectrumSignalParametersDataFrame> ();
230  ip1->psd = i1;
231  ip1->txPhy = 0;
232  ip1->duration = di1;
233  ip1->packetBurst = packetBursts[1];
234  ip1->cellId = pbCellId[1];
235  Simulator::Schedule (ti1, &LteSpectrumPhy::StartRx, dlPhy, ip1);
236 
237  Ptr<LteSpectrumSignalParametersDataFrame> ip2 = Create<LteSpectrumSignalParametersDataFrame> ();
238  ip2->psd = i2;
239  ip2->txPhy = 0;
240  ip2->duration = di2;
241  ip2->packetBurst = packetBursts[2];
242  ip2->cellId = pbCellId[2];
243  Simulator::Schedule (ti2, &LteSpectrumPhy::StartRx, dlPhy, ip2);
244 
245  Ptr<LteSpectrumSignalParametersDataFrame> ip3 = Create<LteSpectrumSignalParametersDataFrame> ();
246  ip3->psd = i3;
247  ip3->txPhy = 0;
248  ip3->duration = di3;
249  ip3->packetBurst = packetBursts[3];
250  ip3->cellId = pbCellId[3];
251  Simulator::Schedule (ti3, &LteSpectrumPhy::StartRx, dlPhy, ip3);
252 
253  Ptr<LteSpectrumSignalParametersDataFrame> ip4 = Create<LteSpectrumSignalParametersDataFrame> ();
254  ip4->psd = i4;
255  ip4->txPhy = 0;
256  ip4->duration = di4;
257  ip4->packetBurst = packetBursts[4];
258  ip4->cellId = pbCellId[4];
259  Simulator::Schedule (ti4, &LteSpectrumPhy::StartRx, dlPhy, ip4);
260 
261  Simulator::Stop (Seconds (5.0));
262  Simulator::Run ();
263 
268  Ptr<SpectrumValue> calculatedSinr = chunkProcessor->GetSinr ();
269 
270  NS_LOG_INFO ("Data Frame - Theoretical SINR: " << *m_sinr);
271  NS_LOG_INFO ("Data Frame - Calculated SINR: " << *calculatedSinr);
272 
273  NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL(*calculatedSinr, *m_sinr, 0.0000001, "Data Frame - Wrong SINR !");
274  dlPhy->Dispose ();
276 }
277 
278 
279 
285 : TestCase ("SINR calculation in downlink Ctrl Frame: " + name),
286 m_sv (sv),
287 m_sm (sv->GetSpectrumModel ()),
288 m_sinr (sinr)
289 {
290  NS_LOG_INFO ("Creating LenaDownlinkCtrlSinrTestCase");
291 }
292 
294 {
295 }
296 
297 void
299 {
303  Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (false));
304  Ptr<LteSpectrumPhy> dlPhy = CreateObject<LteSpectrumPhy> ();
305  Ptr<LteSpectrumPhy> ulPhy = CreateObject<LteSpectrumPhy> ();
306  Ptr<LteTestUePhy> uePhy = CreateObject<LteTestUePhy> (dlPhy, ulPhy);
307  uint16_t cellId = 100;
308  dlPhy->SetCellId (cellId);
309  ulPhy->SetCellId (cellId);
310 
311  Ptr<LteTestSinrChunkProcessor> chunkProcessor = Create<LteTestSinrChunkProcessor> (uePhy->GetObject<LtePhy> ());
312  dlPhy->AddCtrlSinrChunkProcessor (chunkProcessor);
313 
321  // Number of ctrl bursts (1 data + 4 interferences)
322  const int numOfUes = 5;
323 
324  // Number of control messages in the list
325  const int numOfCtrlMsgs = 10;
326 
327  // control messages in the list
328  std::list<Ptr<LteControlMessage> > ctrlMsgList[numOfUes];
329 
330  // signals cellId
331  uint16_t pbCellId[numOfUes];
332 
336  for ( int pb = 0 ; pb < numOfUes ; pb++ )
337  {
338  pbCellId[pb] = cellId * (pb + 1);
339 
340  // Create ctrl msg and add them to the list
341  for ( int i = 0 ; i < numOfCtrlMsgs ; i++ )
342  {
343  Ptr<DlDciLteControlMessage> msg = Create<DlDciLteControlMessage> ();
344  DlDciListElement_s dci;
345  msg->SetDci (dci);
346  ctrlMsgList[pb].push_back (msg);
347  }
348  }
349 
350 
351  Ptr<SpectrumValue> noisePsd = Create<SpectrumValue> (m_sm);
352  Ptr<SpectrumValue> i1 = Create<SpectrumValue> (m_sm);
353  Ptr<SpectrumValue> i2 = Create<SpectrumValue> (m_sm);
354  Ptr<SpectrumValue> i3 = Create<SpectrumValue> (m_sm);
355  Ptr<SpectrumValue> i4 = Create<SpectrumValue> (m_sm);
356 
357  (*noisePsd)[0] = 5.000000000000e-19;
358  (*noisePsd)[1] = 4.545454545455e-19;
359 
360  (*i1)[0] = 5.000000000000e-18;
361  (*i2)[0] = 5.000000000000e-16;
362  (*i3)[0] = 1.581138830084e-16;
363  (*i4)[0] = 7.924465962306e-17;
364  (*i1)[1] = 1.437398936440e-18;
365  (*i2)[1] = 5.722388235428e-16;
366  (*i3)[1] = 7.204059965732e-17;
367  (*i4)[1] = 5.722388235428e-17;
368 
369  Time ts = Seconds (1);
370  Time ds = Seconds (1);
371  Time ti1 = Seconds (0);
372  Time di1 = Seconds (3);
373  Time ti2 = Seconds (0.7);
374  Time di2 = Seconds (1);
375  Time ti3 = Seconds (1.2);
376  Time di3 = Seconds (1);
377  Time ti4 = Seconds (1.5);
378  Time di4 = Seconds (0.1);
379 
380  dlPhy->SetNoisePowerSpectralDensity (noisePsd);
381 
386  // eNB sends data to 2 UEs through 2 subcarriers
387  Ptr<LteSpectrumSignalParametersDlCtrlFrame> sp1 = Create<LteSpectrumSignalParametersDlCtrlFrame> ();
388  sp1->psd = m_sv;
389  sp1->txPhy = 0;
390  sp1->duration = ds;
391  sp1->ctrlMsgList = ctrlMsgList[0];
392  sp1->cellId = pbCellId[0];
393  sp1->pss = false;
394  Simulator::Schedule (ts, &LteSpectrumPhy::StartRx, dlPhy, sp1);
395 
396 
397  Ptr<LteSpectrumSignalParametersDlCtrlFrame> ip1 = Create<LteSpectrumSignalParametersDlCtrlFrame> ();
398  ip1->psd = i1;
399  ip1->txPhy = 0;
400  ip1->duration = di1;
401  ip1->ctrlMsgList = ctrlMsgList[1];
402  ip1->cellId = pbCellId[1];
403  ip1->pss = false;
404  Simulator::Schedule (ti1, &LteSpectrumPhy::StartRx, dlPhy, ip1);
405 
406  Ptr<LteSpectrumSignalParametersDlCtrlFrame> ip2 = Create<LteSpectrumSignalParametersDlCtrlFrame> ();
407  ip2->psd = i2;
408  ip2->txPhy = 0;
409  ip2->duration = di2;
410  ip2->ctrlMsgList = ctrlMsgList[2];
411  ip2->cellId = pbCellId[2];
412  ip2->pss = false;
413  Simulator::Schedule (ti2, &LteSpectrumPhy::StartRx, dlPhy, ip2);
414 
415  Ptr<LteSpectrumSignalParametersDlCtrlFrame> ip3 = Create<LteSpectrumSignalParametersDlCtrlFrame> ();
416  ip3->psd = i3;
417  ip3->txPhy = 0;
418  ip3->duration = di3;
419  ip3->ctrlMsgList = ctrlMsgList[3];
420  ip3->cellId = pbCellId[3];
421  ip3->pss = false;
422  Simulator::Schedule (ti3, &LteSpectrumPhy::StartRx, dlPhy, ip3);
423 
424  Ptr<LteSpectrumSignalParametersDlCtrlFrame> ip4 = Create<LteSpectrumSignalParametersDlCtrlFrame> ();
425  ip4->psd = i4;
426  ip4->txPhy = 0;
427  ip4->duration = di4;
428  ip4->ctrlMsgList = ctrlMsgList[4];
429  ip4->cellId = pbCellId[4];
430  ip4->pss = false;
431  Simulator::Schedule (ti4, &LteSpectrumPhy::StartRx, dlPhy, ip4);
432 
433  Simulator::Stop (Seconds (5.0));
434  Simulator::Run ();
435 
440  Ptr<SpectrumValue> calculatedSinr = chunkProcessor->GetSinr ();
441 
442  NS_LOG_INFO ("Ctrl Frame - Theoretical SINR: " << *m_sinr);
443  NS_LOG_INFO ("Ctrl Frame - Calculated SINR: " << *calculatedSinr);
444 
445  NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL(*calculatedSinr, *m_sinr, 0.0000001, "Data Frame - Wrong SINR !");
446  dlPhy->Dispose ();
448 }
449 
450 
451 } // namespace
See section 4.3.1 dlDciListElement.
Definition: ff-mac-common.h:88
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
Hold a bool native type.
Definition: boolean.h:38
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 LteDownlinkSinrTestSuite lteDownlinkSinrTestSuite
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:667
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