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
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
36using namespace ns3;
37
38NS_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
107
114 std::string name)
115 : TestCase("SINR calculation in downlink Data frame: " + name),
116 m_sv(sv),
117 m_sm(sv->GetSpectrumModel()),
118 m_expectedSinr(sinr)
119{
120 NS_LOG_INFO("Creating LenaDownlinkSinrTestCase");
121}
122
124{
125}
126
127void
129{
130 Config::SetDefault("ns3::LteSpectrumPhy::CtrlErrorModelEnabled", BooleanValue(false));
134 Ptr<LteSpectrumPhy> dlPhy = CreateObject<LteSpectrumPhy>();
135 Ptr<LteSpectrumPhy> ulPhy = CreateObject<LteSpectrumPhy>();
136 Ptr<LteTestUePhy> uePhy = CreateObject<LteTestUePhy>(dlPhy, ulPhy);
137 uint16_t cellId = 100;
138 dlPhy->SetCellId(cellId);
139 ulPhy->SetCellId(cellId);
140
141 Ptr<LteChunkProcessor> chunkProcessor = Create<LteChunkProcessor>();
142 LteSpectrumValueCatcher actualSinrCatcher;
143 chunkProcessor->AddCallback(
144 MakeCallback(&LteSpectrumValueCatcher::ReportValue, &actualSinrCatcher));
145 dlPhy->AddDataSinrChunkProcessor(chunkProcessor);
146
155 // Number of packet bursts (1 data + 4 interferences)
156 const int numOfPbs = 5;
157
158 // Number of packets in the packet bursts
159 const int numOfPkts = 10;
160
161 // Packet bursts
162 Ptr<PacketBurst> packetBursts[numOfPbs];
163
164 // Packets
165 Ptr<Packet> pkt[numOfPbs][numOfPkts];
166
167 // Packet bursts cellId
168 uint16_t pbCellId[numOfPbs];
169
173 for (int pb = 0; pb < numOfPbs; pb++)
174 {
175 // Create packet burst
176 packetBursts[pb] = CreateObject<PacketBurst>();
177 pbCellId[pb] = cellId * (pb + 1);
178
179 // Create packets and add them to the burst
180 for (int i = 0; i < numOfPkts; i++)
181 {
182 pkt[pb][i] = Create<Packet>(1000);
183
184 packetBursts[pb]->AddPacket(pkt[pb][i]);
185 }
186 }
187
188 Ptr<SpectrumValue> noisePsd = Create<SpectrumValue>(m_sm);
189 Ptr<SpectrumValue> i1 = Create<SpectrumValue>(m_sm);
190 Ptr<SpectrumValue> i2 = Create<SpectrumValue>(m_sm);
191 Ptr<SpectrumValue> i3 = Create<SpectrumValue>(m_sm);
192 Ptr<SpectrumValue> i4 = Create<SpectrumValue>(m_sm);
193
194 (*noisePsd)[0] = 5.000000000000e-19;
195 (*noisePsd)[1] = 4.545454545455e-19;
196
197 (*i1)[0] = 5.000000000000e-18;
198 (*i2)[0] = 5.000000000000e-16;
199 (*i3)[0] = 1.581138830084e-16;
200 (*i4)[0] = 7.924465962306e-17;
201 (*i1)[1] = 1.437398936440e-18;
202 (*i2)[1] = 5.722388235428e-16;
203 (*i3)[1] = 7.204059965732e-17;
204 (*i4)[1] = 5.722388235428e-17;
205
206 Time ts = Seconds(1);
207 Time ds = Seconds(1);
208 Time ti1 = Seconds(0);
209 Time di1 = Seconds(3);
210 Time ti2 = Seconds(0.7);
211 Time di2 = Seconds(1);
212 Time ti3 = Seconds(1.2);
213 Time di3 = Seconds(1);
214 Time ti4 = Seconds(1.5);
215 Time di4 = Seconds(0.1);
216
217 dlPhy->SetNoisePowerSpectralDensity(noisePsd);
218
223 // eNB sends data to 2 UEs through 2 subcarriers
224 Ptr<LteSpectrumSignalParametersDataFrame> sp1 = Create<LteSpectrumSignalParametersDataFrame>();
225 sp1->psd = m_sv;
226 sp1->txPhy = nullptr;
227 sp1->duration = ds;
228 sp1->packetBurst = packetBursts[0];
229 sp1->cellId = pbCellId[0];
230 Simulator::Schedule(ts, &LteSpectrumPhy::StartRx, dlPhy, sp1);
231
232 Ptr<LteSpectrumSignalParametersDataFrame> ip1 = Create<LteSpectrumSignalParametersDataFrame>();
233 ip1->psd = i1;
234 ip1->txPhy = nullptr;
235 ip1->duration = di1;
236 ip1->packetBurst = packetBursts[1];
237 ip1->cellId = pbCellId[1];
238 Simulator::Schedule(ti1, &LteSpectrumPhy::StartRx, dlPhy, ip1);
239
240 Ptr<LteSpectrumSignalParametersDataFrame> ip2 = Create<LteSpectrumSignalParametersDataFrame>();
241 ip2->psd = i2;
242 ip2->txPhy = nullptr;
243 ip2->duration = di2;
244 ip2->packetBurst = packetBursts[2];
245 ip2->cellId = pbCellId[2];
246 Simulator::Schedule(ti2, &LteSpectrumPhy::StartRx, dlPhy, ip2);
247
248 Ptr<LteSpectrumSignalParametersDataFrame> ip3 = Create<LteSpectrumSignalParametersDataFrame>();
249 ip3->psd = i3;
250 ip3->txPhy = nullptr;
251 ip3->duration = di3;
252 ip3->packetBurst = packetBursts[3];
253 ip3->cellId = pbCellId[3];
254 Simulator::Schedule(ti3, &LteSpectrumPhy::StartRx, dlPhy, ip3);
255
256 Ptr<LteSpectrumSignalParametersDataFrame> ip4 = Create<LteSpectrumSignalParametersDataFrame>();
257 ip4->psd = i4;
258 ip4->txPhy = nullptr;
259 ip4->duration = di4;
260 ip4->packetBurst = packetBursts[4];
261 ip4->cellId = pbCellId[4];
262 Simulator::Schedule(ti4, &LteSpectrumPhy::StartRx, dlPhy, ip4);
263
264 Simulator::Stop(Seconds(5.0));
265 Simulator::Run();
266
267 NS_LOG_INFO("Data Frame - Theoretical SINR: " << *m_expectedSinr);
268 NS_LOG_INFO("Data Frame - Calculated SINR: " << *(actualSinrCatcher.GetValue()));
269
272 0.0000001,
273 "Data Frame - Wrong SINR !");
274 dlPhy->Dispose();
275 Simulator::Destroy();
276}
277
284 std::string name)
285 : TestCase("SINR calculation in downlink Ctrl Frame: " + name),
286 m_sv(sv),
287 m_sm(sv->GetSpectrumModel()),
288 m_expectedSinr(sinr)
289{
290 NS_LOG_INFO("Creating LenaDownlinkCtrlSinrTestCase");
291}
292
294{
295}
296
297void
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<LteChunkProcessor> chunkProcessor = Create<LteChunkProcessor>();
312 LteSpectrumValueCatcher actualSinrCatcher;
313 chunkProcessor->AddCallback(
314 MakeCallback(&LteSpectrumValueCatcher::ReportValue, &actualSinrCatcher));
315 dlPhy->AddCtrlSinrChunkProcessor(chunkProcessor);
316
324 // Number of ctrl bursts (1 data + 4 interferences)
325 const int numOfUes = 5;
326
327 // Number of control messages in the list
328 const int numOfCtrlMsgs = 10;
329
330 // control messages in the list
331 std::list<Ptr<LteControlMessage>> ctrlMsgList[numOfUes];
332
333 // signals cellId
334 uint16_t pbCellId[numOfUes];
335
339 for (int pb = 0; pb < numOfUes; pb++)
340 {
341 pbCellId[pb] = cellId * (pb + 1);
342
343 // Create ctrl msg and add them to the list
344 for (int i = 0; i < numOfCtrlMsgs; i++)
345 {
346 Ptr<DlDciLteControlMessage> msg = Create<DlDciLteControlMessage>();
348 msg->SetDci(dci);
349 ctrlMsgList[pb].emplace_back(msg);
350 }
351 }
352
353 Ptr<SpectrumValue> noisePsd = Create<SpectrumValue>(m_sm);
354 Ptr<SpectrumValue> i1 = Create<SpectrumValue>(m_sm);
355 Ptr<SpectrumValue> i2 = Create<SpectrumValue>(m_sm);
356 Ptr<SpectrumValue> i3 = Create<SpectrumValue>(m_sm);
357 Ptr<SpectrumValue> i4 = Create<SpectrumValue>(m_sm);
358
359 (*noisePsd)[0] = 5.000000000000e-19;
360 (*noisePsd)[1] = 4.545454545455e-19;
361
362 (*i1)[0] = 5.000000000000e-18;
363 (*i2)[0] = 5.000000000000e-16;
364 (*i3)[0] = 1.581138830084e-16;
365 (*i4)[0] = 7.924465962306e-17;
366 (*i1)[1] = 1.437398936440e-18;
367 (*i2)[1] = 5.722388235428e-16;
368 (*i3)[1] = 7.204059965732e-17;
369 (*i4)[1] = 5.722388235428e-17;
370
371 Time ts = Seconds(1);
372 Time ds = Seconds(1);
373 Time ti1 = Seconds(0);
374 Time di1 = Seconds(3);
375 Time ti2 = Seconds(0.7);
376 Time di2 = Seconds(1);
377 Time ti3 = Seconds(1.2);
378 Time di3 = Seconds(1);
379 Time ti4 = Seconds(1.5);
380 Time di4 = Seconds(0.1);
381
382 dlPhy->SetNoisePowerSpectralDensity(noisePsd);
383
388 // eNB sends data to 2 UEs through 2 subcarriers
390 Create<LteSpectrumSignalParametersDlCtrlFrame>();
391 sp1->psd = m_sv;
392 sp1->txPhy = nullptr;
393 sp1->duration = ds;
394 sp1->ctrlMsgList = ctrlMsgList[0];
395 sp1->cellId = pbCellId[0];
396 sp1->pss = false;
397 Simulator::Schedule(ts, &LteSpectrumPhy::StartRx, dlPhy, sp1);
398
400 Create<LteSpectrumSignalParametersDlCtrlFrame>();
401 ip1->psd = i1;
402 ip1->txPhy = nullptr;
403 ip1->duration = di1;
404 ip1->ctrlMsgList = ctrlMsgList[1];
405 ip1->cellId = pbCellId[1];
406 ip1->pss = false;
407 Simulator::Schedule(ti1, &LteSpectrumPhy::StartRx, dlPhy, ip1);
408
410 Create<LteSpectrumSignalParametersDlCtrlFrame>();
411 ip2->psd = i2;
412 ip2->txPhy = nullptr;
413 ip2->duration = di2;
414 ip2->ctrlMsgList = ctrlMsgList[2];
415 ip2->cellId = pbCellId[2];
416 ip2->pss = false;
417 Simulator::Schedule(ti2, &LteSpectrumPhy::StartRx, dlPhy, ip2);
418
420 Create<LteSpectrumSignalParametersDlCtrlFrame>();
421 ip3->psd = i3;
422 ip3->txPhy = nullptr;
423 ip3->duration = di3;
424 ip3->ctrlMsgList = ctrlMsgList[3];
425 ip3->cellId = pbCellId[3];
426 ip3->pss = false;
427 Simulator::Schedule(ti3, &LteSpectrumPhy::StartRx, dlPhy, ip3);
428
430 Create<LteSpectrumSignalParametersDlCtrlFrame>();
431 ip4->psd = i4;
432 ip4->txPhy = nullptr;
433 ip4->duration = di4;
434 ip4->ctrlMsgList = ctrlMsgList[4];
435 ip4->cellId = pbCellId[4];
436 ip4->pss = false;
437 Simulator::Schedule(ti4, &LteSpectrumPhy::StartRx, dlPhy, ip4);
438
439 Simulator::Stop(Seconds(5.0));
440 Simulator::Run();
441
442 NS_LOG_INFO("Ctrl Frame - Theoretical SINR: " << *m_expectedSinr);
443 NS_LOG_INFO("Ctrl Frame - Calculated SINR: " << *(actualSinrCatcher.GetValue()));
444
447 0.0000001,
448 "Data Frame - Wrong SINR !");
449 dlPhy->Dispose();
450 Simulator::Destroy();
451}
AttributeValue implementation for Boolean.
Definition: boolean.h:37
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:305
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:891
#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
#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:1338
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:691
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