A Discrete-Event Network Simulator
API
lte-test-uplink-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 SRS frames
20 */
21
23
24#include "lte-test-ue-phy.h"
25
26#include "ns3/log.h"
27#include "ns3/lte-phy-tag.h"
28#include "ns3/lte-spectrum-signal-parameters.h"
29#include "ns3/simulator.h"
30#include "ns3/spectrum-test.h"
31#include <ns3/lte-chunk-processor.h>
32#include <ns3/lte-helper.h>
33
34using namespace ns3;
35
36NS_LOG_COMPONENT_DEFINE("LteUplinkSinrTest");
37
46 : TestSuite("lte-uplink-sinr", SYSTEM)
47{
52
53 Bands bands;
54 BandInfo bi;
55
56 bi.fl = 2.400e9;
57 bi.fc = 2.410e9;
58 bi.fh = 2.420e9;
59 bands.push_back(bi);
60
61 bi.fl = 2.420e9;
62 bi.fc = 2.431e9;
63 bi.fh = 2.442e9;
64 bands.push_back(bi);
65
66 sm = Create<SpectrumModel>(bands);
67
72 Ptr<SpectrumValue> rxPsd1 = Create<SpectrumValue>(sm);
73 (*rxPsd1)[0] = 1.255943215755e-15;
74 (*rxPsd1)[1] = 0.0;
75
76 Ptr<SpectrumValue> rxPsd2 = Create<SpectrumValue>(sm);
77 (*rxPsd2)[0] = 0.0;
78 (*rxPsd2)[1] = 7.204059965732e-16;
79
80 Ptr<SpectrumValue> theoreticalSinr1 = Create<SpectrumValue>(sm);
81 (*theoreticalSinr1)[0] = 3.72589167251055;
82 (*theoreticalSinr1)[1] = 3.72255684126076;
83
85 rxPsd2,
86 theoreticalSinr1,
87 "sdBm = [-46 -inf] and [-inf -48]"),
88 TestCase::QUICK);
89
91 rxPsd2,
92 theoreticalSinr1,
93 "sdBm = [-46 -inf] and [-inf -48]"),
94 TestCase::QUICK);
95
100 Ptr<SpectrumValue> rxPsd3 = Create<SpectrumValue>(sm);
101 (*rxPsd3)[0] = 2.505936168136e-17;
102 (*rxPsd3)[1] = 0.0;
103
104 Ptr<SpectrumValue> rxPsd4 = Create<SpectrumValue>(sm);
105 (*rxPsd4)[0] = 0.0;
106 (*rxPsd4)[1] = 3.610582885110e-17;
107
108 Ptr<SpectrumValue> theoreticalSinr2 = Create<SpectrumValue>(sm);
109 (*theoreticalSinr2)[0] = 0.0743413124381667;
110 (*theoreticalSinr2)[1] = 0.1865697965291756;
111
113 rxPsd4,
114 theoreticalSinr2,
115 "sdBm = [-63 -inf] and [-inf -61]"),
116 TestCase::QUICK);
117
119 rxPsd4,
120 theoreticalSinr2,
121 "sdBm = [-63 -inf] and [-inf -61]"),
122 TestCase::QUICK);
123}
124
126
134 std::string name)
135 : TestCase("SINR calculation in uplink data frame: " + name),
136 m_sv1(sv1),
137 m_sv2(sv2),
138 m_sm(sv1->GetSpectrumModel()),
139 m_expectedSinr(sinr)
140{
141 NS_LOG_INFO("Creating LteUplinkDataSinrTestCase");
142}
143
145{
146}
147
148void
150{
154 Ptr<LteSpectrumPhy> dlPhy = CreateObject<LteSpectrumPhy>();
155 Ptr<LteSpectrumPhy> ulPhy = CreateObject<LteSpectrumPhy>();
156 Ptr<LteTestUePhy> uePhy = CreateObject<LteTestUePhy>(dlPhy, ulPhy);
157 uint16_t cellId = 100;
158 dlPhy->SetCellId(cellId);
159 ulPhy->SetCellId(cellId);
160
161 Ptr<LteChunkProcessor> chunkProcessor = Create<LteChunkProcessor>();
162 LteSpectrumValueCatcher actualSinrCatcher;
163 chunkProcessor->AddCallback(
164 MakeCallback(&LteSpectrumValueCatcher::ReportValue, &actualSinrCatcher));
165 ulPhy->AddDataSinrChunkProcessor(chunkProcessor);
166
175 // Number of packet bursts (2 data + 4 interferences)
176 const int numOfDataPbs = 2;
177 const int numOfIntfPbs = 4;
178 const int numOfPbs = numOfDataPbs + numOfIntfPbs;
179
180 // Number of packets in the packet bursts
181 const int numOfPkts = 10;
182
183 // Packet bursts
184 Ptr<PacketBurst> packetBursts[numOfPbs];
185
186 // Packets
187 Ptr<Packet> pkt[numOfPbs][numOfPkts];
188
189 // Bursts cellId
190 uint16_t pbCellId[numOfPbs];
191
195 int pb = 0;
196 for (int dataPb = 0; dataPb < numOfDataPbs; dataPb++, pb++)
197 {
198 // Create packet burst
199 packetBursts[pb] = CreateObject<PacketBurst>();
200 pbCellId[pb] = cellId;
201 // Create packets and add them to the burst
202 for (int i = 0; i < numOfPkts; i++)
203 {
204 pkt[pb][i] = Create<Packet>(1000);
205
206 packetBursts[pb]->AddPacket(pkt[pb][i]);
207 }
208 }
209 for (int intfPb = 0; intfPb < numOfIntfPbs; intfPb++, pb++)
210 {
211 // Create packet burst
212 packetBursts[pb] = CreateObject<PacketBurst>();
213 pbCellId[pb] = cellId * (pb + 1);
214
215 // Create packets and add them to the burst
216 for (int i = 0; i < numOfPkts; i++)
217 {
218 pkt[pb][i] = Create<Packet>(1000);
219
220 packetBursts[pb]->AddPacket(pkt[pb][i]);
221 }
222 }
223
224 Ptr<SpectrumValue> noisePsd = Create<SpectrumValue>(m_sm);
225 Ptr<SpectrumValue> i1 = Create<SpectrumValue>(m_sm);
226 Ptr<SpectrumValue> i2 = Create<SpectrumValue>(m_sm);
227 Ptr<SpectrumValue> i3 = Create<SpectrumValue>(m_sm);
228 Ptr<SpectrumValue> i4 = Create<SpectrumValue>(m_sm);
229
230 (*noisePsd)[0] = 5.000000000000e-19;
231 (*noisePsd)[1] = 4.545454545455e-19;
232
233 (*i1)[0] = 5.000000000000e-18;
234 (*i2)[0] = 5.000000000000e-16;
235 (*i3)[0] = 1.581138830084e-16;
236 (*i4)[0] = 7.924465962306e-17;
237 (*i1)[1] = 1.437398936440e-18;
238 (*i2)[1] = 5.722388235428e-16;
239 (*i3)[1] = 7.204059965732e-17;
240 (*i4)[1] = 5.722388235428e-17;
241
242 Time ts = Seconds(1);
243 Time ds = Seconds(1);
244 Time ti1 = Seconds(0);
245 Time di1 = Seconds(3);
246 Time ti2 = Seconds(0.7);
247 Time di2 = Seconds(1);
248 Time ti3 = Seconds(1.2);
249 Time di3 = Seconds(1);
250 Time ti4 = Seconds(1.5);
251 Time di4 = Seconds(0.1);
252
253 ulPhy->SetNoisePowerSpectralDensity(noisePsd);
254
259 // 2 UEs send data to the eNB through 2 subcarriers
260 Ptr<LteSpectrumSignalParametersDataFrame> sp1 = Create<LteSpectrumSignalParametersDataFrame>();
261 sp1->psd = m_sv1;
262 sp1->txPhy = nullptr;
263 sp1->duration = ds;
264 sp1->packetBurst = packetBursts[0];
265 sp1->cellId = pbCellId[0];
266 Simulator::Schedule(ts, &LteSpectrumPhy::StartRx, ulPhy, sp1);
267
268 Ptr<LteSpectrumSignalParametersDataFrame> sp2 = Create<LteSpectrumSignalParametersDataFrame>();
269 sp2->psd = m_sv2;
270 sp2->txPhy = nullptr;
271 sp2->duration = ds;
272 sp2->packetBurst = packetBursts[1];
273 sp2->cellId = pbCellId[1];
274 Simulator::Schedule(ts, &LteSpectrumPhy::StartRx, ulPhy, sp2);
275
276 Ptr<LteSpectrumSignalParametersDataFrame> ip1 = Create<LteSpectrumSignalParametersDataFrame>();
277 ip1->psd = i1;
278 ip1->txPhy = nullptr;
279 ip1->duration = di1;
280 ip1->packetBurst = packetBursts[2];
281 ip1->cellId = pbCellId[2];
282 Simulator::Schedule(ti1, &LteSpectrumPhy::StartRx, ulPhy, ip1);
283
284 Ptr<LteSpectrumSignalParametersDataFrame> ip2 = Create<LteSpectrumSignalParametersDataFrame>();
285 ip2->psd = i2;
286 ip2->txPhy = nullptr;
287 ip2->duration = di2;
288 ip2->packetBurst = packetBursts[3];
289 ip2->cellId = pbCellId[3];
290 Simulator::Schedule(ti2, &LteSpectrumPhy::StartRx, ulPhy, ip2);
291
292 Ptr<LteSpectrumSignalParametersDataFrame> ip3 = Create<LteSpectrumSignalParametersDataFrame>();
293 ip3->psd = i3;
294 ip3->txPhy = nullptr;
295 ip3->duration = di3;
296 ip3->packetBurst = packetBursts[4];
297 ip3->cellId = pbCellId[4];
298 Simulator::Schedule(ti3, &LteSpectrumPhy::StartRx, ulPhy, ip3);
299
300 Ptr<LteSpectrumSignalParametersDataFrame> ip4 = Create<LteSpectrumSignalParametersDataFrame>();
301 ip4->psd = i4;
302 ip4->txPhy = nullptr;
303 ip4->duration = di4;
304 ip4->packetBurst = packetBursts[5];
305 ip4->cellId = pbCellId[5];
306 Simulator::Schedule(ti4, &LteSpectrumPhy::StartRx, ulPhy, ip4);
307
308 Simulator::Stop(Seconds(5.0));
309 Simulator::Run();
310
311 NS_LOG_INFO("Data Frame - Theoretical SINR: " << *m_expectedSinr);
312 NS_LOG_INFO("Data Frame - Calculated SINR: " << *(actualSinrCatcher.GetValue()));
313
314 NS_TEST_EXPECT_MSG_NE(actualSinrCatcher.GetValue(), nullptr, "no actual SINR reported");
315
318 0.0000001,
319 "Data Frame - Wrong SINR !");
320 ulPhy->Dispose();
321 Simulator::Destroy();
322}
323
331 std::string name)
332 : TestCase("SINR calculation in uplink srs frame: " + name),
333 m_sv1(sv1),
334 m_sv2(sv2),
335 m_sm(sv1->GetSpectrumModel()),
336 m_expectedSinr(sinr)
337{
338 NS_LOG_INFO("Creating LteUplinkSrsSinrTestCase");
339}
340
342{
343}
344
345void
347{
348 m_actualSinr = sinr.Copy();
349}
350
351void
353{
358 Ptr<LteHelper> lteHelper = CreateObject<LteHelper>();
359 // lteHelper->EnableLogComponents ();
360 Ptr<LteSpectrumPhy> dlPhy = CreateObject<LteSpectrumPhy>();
361 Ptr<LteSpectrumPhy> ulPhy = CreateObject<LteSpectrumPhy>();
362 Ptr<LteTestUePhy> uePhy = CreateObject<LteTestUePhy>(dlPhy, ulPhy);
363 uint16_t cellId = 100;
364 dlPhy->SetCellId(cellId);
365 ulPhy->SetCellId(cellId);
366
367 Ptr<LteChunkProcessor> chunkProcessor = Create<LteChunkProcessor>();
368 chunkProcessor->AddCallback(MakeCallback(&LteUplinkSrsSinrTestCase::ReportSinr, this));
369 ulPhy->AddCtrlSinrChunkProcessor(chunkProcessor);
370
380 // Number of packet bursts (2 data + 4 interferences)
381 int numOfDataSignals = 2;
382 int numOfIntfSignals = 4;
383 int numOfSignals = numOfDataSignals + numOfIntfSignals;
384
385 uint16_t pbCellId[numOfSignals];
386
390 int pb = 0;
391 for (int dataPb = 0; dataPb < numOfDataSignals; dataPb++, pb++)
392 {
393 pbCellId[pb] = cellId;
394 }
395 for (int intfPb = 0; intfPb < numOfIntfSignals; intfPb++, pb++)
396 {
397 pbCellId[pb] = cellId * (pb + 1);
398 }
399
400 Ptr<SpectrumValue> noisePsd = Create<SpectrumValue>(m_sm);
401 Ptr<SpectrumValue> i1 = Create<SpectrumValue>(m_sm);
402 Ptr<SpectrumValue> i2 = Create<SpectrumValue>(m_sm);
403 Ptr<SpectrumValue> i3 = Create<SpectrumValue>(m_sm);
404 Ptr<SpectrumValue> i4 = Create<SpectrumValue>(m_sm);
405
406 (*noisePsd)[0] = 5.000000000000e-19;
407 (*noisePsd)[1] = 4.545454545455e-19;
408
409 (*i1)[0] = 5.000000000000e-18;
410 (*i2)[0] = 5.000000000000e-16;
411 (*i3)[0] = 1.581138830084e-16;
412 (*i4)[0] = 7.924465962306e-17;
413 (*i1)[1] = 1.437398936440e-18;
414 (*i2)[1] = 5.722388235428e-16;
415 (*i3)[1] = 7.204059965732e-17;
416 (*i4)[1] = 5.722388235428e-17;
417
418 Time ts = Seconds(1);
419 Time ds = Seconds(1);
420 Time ti1 = Seconds(0);
421 Time di1 = Seconds(3);
422 Time ti2 = Seconds(0.7);
423 Time di2 = Seconds(1);
424 Time ti3 = Seconds(1.2);
425 Time di3 = Seconds(1);
426 Time ti4 = Seconds(1.5);
427 Time di4 = Seconds(0.1);
428
429 ulPhy->SetNoisePowerSpectralDensity(noisePsd);
430
435 // 2 UEs send data to the eNB through 2 subcarriers
437 Create<LteSpectrumSignalParametersUlSrsFrame>();
438 sp1->psd = m_sv1;
439 sp1->txPhy = nullptr;
440 sp1->duration = ds;
441 sp1->cellId = pbCellId[0];
442 Simulator::Schedule(ts, &LteSpectrumPhy::StartRx, ulPhy, sp1);
443
445 Create<LteSpectrumSignalParametersUlSrsFrame>();
446 sp2->psd = m_sv2;
447 sp2->txPhy = nullptr;
448 sp2->duration = ds;
449 sp2->cellId = pbCellId[1];
450 Simulator::Schedule(ts, &LteSpectrumPhy::StartRx, ulPhy, sp2);
451
453 Create<LteSpectrumSignalParametersUlSrsFrame>();
454 ip1->psd = i1;
455 ip1->txPhy = nullptr;
456 ip1->duration = di1;
457 ip1->cellId = pbCellId[2];
458 Simulator::Schedule(ti1, &LteSpectrumPhy::StartRx, ulPhy, ip1);
459
461 Create<LteSpectrumSignalParametersUlSrsFrame>();
462 ip2->psd = i2;
463 ip2->txPhy = nullptr;
464 ip2->duration = di2;
465 ip2->cellId = pbCellId[3];
466 Simulator::Schedule(ti2, &LteSpectrumPhy::StartRx, ulPhy, ip2);
467
469 Create<LteSpectrumSignalParametersUlSrsFrame>();
470 ip3->psd = i3;
471 ip3->txPhy = nullptr;
472 ip3->duration = di3;
473 ip3->cellId = pbCellId[4];
474 Simulator::Schedule(ti3, &LteSpectrumPhy::StartRx, ulPhy, ip3);
475
477 Create<LteSpectrumSignalParametersUlSrsFrame>();
478 ip4->psd = i4;
479 ip4->txPhy = nullptr;
480 ip4->duration = di4;
481 ip4->cellId = pbCellId[5];
482 Simulator::Schedule(ti4, &LteSpectrumPhy::StartRx, ulPhy, ip4);
483
484 Simulator::Stop(Seconds(5.0));
485 Simulator::Run();
486
487 NS_ASSERT_MSG(m_actualSinr, "no actual SINR reported");
488
489 NS_LOG_INFO("SRS Frame - Theoretical SINR: " << *m_expectedSinr);
490 NS_LOG_INFO("SRS Frame - Calculated SINR: " << *m_actualSinr);
491
494 0.0000001,
495 "Data Frame - Wrong SINR !");
496 ulPhy->Dispose();
497 Simulator::Destroy();
498}
A sink to be plugged to the callback of LteChunkProcessor allowing to save and later retrieve the lat...
Ptr< SpectrumValue > GetValue()
Set of values corresponding to a given SpectrumModel.
Ptr< SpectrumValue > Copy() const
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
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
#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.
#define NS_TEST_EXPECT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report if not.
Definition: test.h:666
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