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 using namespace ns3;
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_sinr (sinr)
116 {
117  NS_LOG_INFO ("Creating LenaDownlinkSinrTestCase");
118 }
119 
121 {
122 }
123 
124 void
126 {
127  Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (false));
131  Ptr<LteSpectrumPhy> dlPhy = CreateObject<LteSpectrumPhy> ();
132  Ptr<LteSpectrumPhy> ulPhy = CreateObject<LteSpectrumPhy> ();
133  Ptr<LteTestUePhy> uePhy = CreateObject<LteTestUePhy> (dlPhy, ulPhy);
134  uint16_t cellId = 100;
135  dlPhy->SetCellId (cellId);
136  ulPhy->SetCellId (cellId);
137 
138  Ptr<LteTestSinrChunkProcessor> chunkProcessor = Create<LteTestSinrChunkProcessor> (uePhy->GetObject<LtePhy> ());
139  dlPhy->AddDataSinrChunkProcessor (chunkProcessor);
140 
149  // Number of packet bursts (1 data + 4 interferences)
150  const int numOfPbs = 5;
151 
152  // Number of packets in the packet bursts
153  const int numOfPkts = 10;
154 
155  // Packet bursts
156  Ptr<PacketBurst> packetBursts[numOfPbs];
157 
158  // Packets
159  Ptr<Packet> pkt[numOfPbs][numOfPkts];
160 
161  // Packet bursts cellId
162  uint16_t pbCellId[numOfPbs];
163 
167  for ( int pb = 0 ; pb < numOfPbs ; pb++ )
168  {
169  // Create packet burst
170  packetBursts[pb] = CreateObject<PacketBurst> ();
171  pbCellId[pb] = cellId * (pb + 1);
172 
173  // Create packets and add them to the burst
174  for ( int i = 0 ; i < numOfPkts ; i++ )
175  {
176  pkt[pb][i] = Create<Packet> (1000);
177 
178  packetBursts[pb]->AddPacket ( pkt[pb][i] );
179  }
180  }
181 
182 
183  Ptr<SpectrumValue> noisePsd = Create<SpectrumValue> (m_sm);
184  Ptr<SpectrumValue> i1 = Create<SpectrumValue> (m_sm);
185  Ptr<SpectrumValue> i2 = Create<SpectrumValue> (m_sm);
186  Ptr<SpectrumValue> i3 = Create<SpectrumValue> (m_sm);
187  Ptr<SpectrumValue> i4 = Create<SpectrumValue> (m_sm);
188 
189  (*noisePsd)[0] = 5.000000000000e-19;
190  (*noisePsd)[1] = 4.545454545455e-19;
191 
192  (*i1)[0] = 5.000000000000e-18;
193  (*i2)[0] = 5.000000000000e-16;
194  (*i3)[0] = 1.581138830084e-16;
195  (*i4)[0] = 7.924465962306e-17;
196  (*i1)[1] = 1.437398936440e-18;
197  (*i2)[1] = 5.722388235428e-16;
198  (*i3)[1] = 7.204059965732e-17;
199  (*i4)[1] = 5.722388235428e-17;
200 
201  Time ts = Seconds (1);
202  Time ds = Seconds (1);
203  Time ti1 = Seconds (0);
204  Time di1 = Seconds (3);
205  Time ti2 = Seconds (0.7);
206  Time di2 = Seconds (1);
207  Time ti3 = Seconds (1.2);
208  Time di3 = Seconds (1);
209  Time ti4 = Seconds (1.5);
210  Time di4 = Seconds (0.1);
211 
212  dlPhy->SetNoisePowerSpectralDensity (noisePsd);
213 
218  // eNB sends data to 2 UEs through 2 subcarriers
219  Ptr<LteSpectrumSignalParametersDataFrame> sp1 = Create<LteSpectrumSignalParametersDataFrame> ();
220  sp1->psd = m_sv;
221  sp1->txPhy = 0;
222  sp1->duration = ds;
223  sp1->packetBurst = packetBursts[0];
224  sp1->cellId = pbCellId[0];
225  Simulator::Schedule (ts, &LteSpectrumPhy::StartRx, dlPhy, sp1);
226 
227 
228  Ptr<LteSpectrumSignalParametersDataFrame> ip1 = Create<LteSpectrumSignalParametersDataFrame> ();
229  ip1->psd = i1;
230  ip1->txPhy = 0;
231  ip1->duration = di1;
232  ip1->packetBurst = packetBursts[1];
233  ip1->cellId = pbCellId[1];
234  Simulator::Schedule (ti1, &LteSpectrumPhy::StartRx, dlPhy, ip1);
235 
236  Ptr<LteSpectrumSignalParametersDataFrame> ip2 = Create<LteSpectrumSignalParametersDataFrame> ();
237  ip2->psd = i2;
238  ip2->txPhy = 0;
239  ip2->duration = di2;
240  ip2->packetBurst = packetBursts[2];
241  ip2->cellId = pbCellId[2];
242  Simulator::Schedule (ti2, &LteSpectrumPhy::StartRx, dlPhy, ip2);
243 
244  Ptr<LteSpectrumSignalParametersDataFrame> ip3 = Create<LteSpectrumSignalParametersDataFrame> ();
245  ip3->psd = i3;
246  ip3->txPhy = 0;
247  ip3->duration = di3;
248  ip3->packetBurst = packetBursts[3];
249  ip3->cellId = pbCellId[3];
250  Simulator::Schedule (ti3, &LteSpectrumPhy::StartRx, dlPhy, ip3);
251 
252  Ptr<LteSpectrumSignalParametersDataFrame> ip4 = Create<LteSpectrumSignalParametersDataFrame> ();
253  ip4->psd = i4;
254  ip4->txPhy = 0;
255  ip4->duration = di4;
256  ip4->packetBurst = packetBursts[4];
257  ip4->cellId = pbCellId[4];
258  Simulator::Schedule (ti4, &LteSpectrumPhy::StartRx, dlPhy, ip4);
259 
260  Simulator::Stop (Seconds (5.0));
261  Simulator::Run ();
262 
267  Ptr<SpectrumValue> calculatedSinr = chunkProcessor->GetSinr ();
268 
269  NS_LOG_INFO ("Data Frame - Theoretical SINR: " << *m_sinr);
270  NS_LOG_INFO ("Data Frame - Calculated SINR: " << *calculatedSinr);
271 
272  NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL(*calculatedSinr, *m_sinr, 0.0000001, "Data Frame - Wrong SINR !");
273  dlPhy->Dispose ();
274  Simulator::Destroy ();
275 }
276 
277 
278 
284 : TestCase ("SINR calculation in downlink Ctrl Frame: " + name),
285 m_sv (sv),
286 m_sm (sv->GetSpectrumModel ()),
287 m_sinr (sinr)
288 {
289  NS_LOG_INFO ("Creating LenaDownlinkCtrlSinrTestCase");
290 }
291 
293 {
294 }
295 
296 void
298 {
302  Config::SetDefault ("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue (false));
303  Ptr<LteSpectrumPhy> dlPhy = CreateObject<LteSpectrumPhy> ();
304  Ptr<LteSpectrumPhy> ulPhy = CreateObject<LteSpectrumPhy> ();
305  Ptr<LteTestUePhy> uePhy = CreateObject<LteTestUePhy> (dlPhy, ulPhy);
306  uint16_t cellId = 100;
307  dlPhy->SetCellId (cellId);
308  ulPhy->SetCellId (cellId);
309 
310  Ptr<LteTestSinrChunkProcessor> chunkProcessor = Create<LteTestSinrChunkProcessor> (uePhy->GetObject<LtePhy> ());
311  dlPhy->AddCtrlSinrChunkProcessor (chunkProcessor);
312 
320  // Number of ctrl bursts (1 data + 4 interferences)
321  const int numOfUes = 5;
322 
323  // Number of control messages in the list
324  const int numOfCtrlMsgs = 10;
325 
326  // control messages in the list
327  std::list<Ptr<LteControlMessage> > ctrlMsgList[numOfUes];
328 
329  // signals cellId
330  uint16_t pbCellId[numOfUes];
331 
335  for ( int pb = 0 ; pb < numOfUes ; pb++ )
336  {
337  pbCellId[pb] = cellId * (pb + 1);
338 
339  // Create ctrl msg and add them to the list
340  for ( int i = 0 ; i < numOfCtrlMsgs ; i++ )
341  {
342  Ptr<DlDciLteControlMessage> msg = Create<DlDciLteControlMessage> ();
343  DlDciListElement_s dci;
344  msg->SetDci (dci);
345  ctrlMsgList[pb].push_back (msg);
346  }
347  }
348 
349 
350  Ptr<SpectrumValue> noisePsd = Create<SpectrumValue> (m_sm);
351  Ptr<SpectrumValue> i1 = Create<SpectrumValue> (m_sm);
352  Ptr<SpectrumValue> i2 = Create<SpectrumValue> (m_sm);
353  Ptr<SpectrumValue> i3 = Create<SpectrumValue> (m_sm);
354  Ptr<SpectrumValue> i4 = Create<SpectrumValue> (m_sm);
355 
356  (*noisePsd)[0] = 5.000000000000e-19;
357  (*noisePsd)[1] = 4.545454545455e-19;
358 
359  (*i1)[0] = 5.000000000000e-18;
360  (*i2)[0] = 5.000000000000e-16;
361  (*i3)[0] = 1.581138830084e-16;
362  (*i4)[0] = 7.924465962306e-17;
363  (*i1)[1] = 1.437398936440e-18;
364  (*i2)[1] = 5.722388235428e-16;
365  (*i3)[1] = 7.204059965732e-17;
366  (*i4)[1] = 5.722388235428e-17;
367 
368  Time ts = Seconds (1);
369  Time ds = Seconds (1);
370  Time ti1 = Seconds (0);
371  Time di1 = Seconds (3);
372  Time ti2 = Seconds (0.7);
373  Time di2 = Seconds (1);
374  Time ti3 = Seconds (1.2);
375  Time di3 = Seconds (1);
376  Time ti4 = Seconds (1.5);
377  Time di4 = Seconds (0.1);
378 
379  dlPhy->SetNoisePowerSpectralDensity (noisePsd);
380 
385  // eNB sends data to 2 UEs through 2 subcarriers
386  Ptr<LteSpectrumSignalParametersDlCtrlFrame> sp1 = Create<LteSpectrumSignalParametersDlCtrlFrame> ();
387  sp1->psd = m_sv;
388  sp1->txPhy = 0;
389  sp1->duration = ds;
390  sp1->ctrlMsgList = ctrlMsgList[0];
391  sp1->cellId = pbCellId[0];
392  sp1->pss = false;
393  Simulator::Schedule (ts, &LteSpectrumPhy::StartRx, dlPhy, sp1);
394 
395 
396  Ptr<LteSpectrumSignalParametersDlCtrlFrame> ip1 = Create<LteSpectrumSignalParametersDlCtrlFrame> ();
397  ip1->psd = i1;
398  ip1->txPhy = 0;
399  ip1->duration = di1;
400  ip1->ctrlMsgList = ctrlMsgList[1];
401  ip1->cellId = pbCellId[1];
402  ip1->pss = false;
403  Simulator::Schedule (ti1, &LteSpectrumPhy::StartRx, dlPhy, ip1);
404 
405  Ptr<LteSpectrumSignalParametersDlCtrlFrame> ip2 = Create<LteSpectrumSignalParametersDlCtrlFrame> ();
406  ip2->psd = i2;
407  ip2->txPhy = 0;
408  ip2->duration = di2;
409  ip2->ctrlMsgList = ctrlMsgList[2];
410  ip2->cellId = pbCellId[2];
411  ip2->pss = false;
412  Simulator::Schedule (ti2, &LteSpectrumPhy::StartRx, dlPhy, ip2);
413 
414  Ptr<LteSpectrumSignalParametersDlCtrlFrame> ip3 = Create<LteSpectrumSignalParametersDlCtrlFrame> ();
415  ip3->psd = i3;
416  ip3->txPhy = 0;
417  ip3->duration = di3;
418  ip3->ctrlMsgList = ctrlMsgList[3];
419  ip3->cellId = pbCellId[3];
420  ip3->pss = false;
421  Simulator::Schedule (ti3, &LteSpectrumPhy::StartRx, dlPhy, ip3);
422 
423  Ptr<LteSpectrumSignalParametersDlCtrlFrame> ip4 = Create<LteSpectrumSignalParametersDlCtrlFrame> ();
424  ip4->psd = i4;
425  ip4->txPhy = 0;
426  ip4->duration = di4;
427  ip4->ctrlMsgList = ctrlMsgList[4];
428  ip4->cellId = pbCellId[4];
429  ip4->pss = false;
430  Simulator::Schedule (ti4, &LteSpectrumPhy::StartRx, dlPhy, ip4);
431 
432  Simulator::Stop (Seconds (5.0));
433  Simulator::Run ();
434 
439  Ptr<SpectrumValue> calculatedSinr = chunkProcessor->GetSinr ();
440 
441  NS_LOG_INFO ("Ctrl Frame - Theoretical SINR: " << *m_sinr);
442  NS_LOG_INFO ("Ctrl Frame - Calculated SINR: " << *calculatedSinr);
443 
444  NS_TEST_ASSERT_MSG_SPECTRUM_VALUE_EQ_TOL(*calculatedSinr, *m_sinr, 0.0000001, "Data Frame - Wrong SINR !");
445  dlPhy->Dispose ();
446  Simulator::Destroy ();
447 }
See section 4.3.1 dlDciListElement.
Definition: ff-mac-common.h:88
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
Hold a bool native type.
Definition: boolean.h:38
A suite of tests to run.
Definition: test.h:1105
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:223
encapsulates test code
Definition: test.h:929
std::vector< BandInfo > Bands
double fc
center frequency
Ptr< SpectrumPhy > txPhy
The SpectrumPhy instance that is making the transmission.
void SetDefault(std::string name, const AttributeValue &value)
Definition: config.cc:667
void AddPacket(Ptr< Packet > packet)
add a packet to the list of packet
Definition: packet-burst.cc:81
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
void AddTestCase(TestCase *testCase) NS_DEPRECATED
Add an individual child TestCase case to this TestCase.
Definition: test.cc:184
#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 duration
The duration of the packet transmission.
double fh
upper limit of subband
The building block of a SpectrumModel.
The LtePhy models the physical layer of LTE.
Definition: lte-phy.h:52