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
130
138 std::string name)
139 : TestCase("SINR calculation in uplink data frame: " + name),
140 m_sv1(sv1),
141 m_sv2(sv2),
142 m_sm(sv1->GetSpectrumModel()),
143 m_expectedSinr(sinr)
144{
145 NS_LOG_INFO("Creating LteUplinkDataSinrTestCase");
146}
147
149{
150}
151
152void
154{
158 Ptr<LteSpectrumPhy> dlPhy = CreateObject<LteSpectrumPhy>();
159 Ptr<LteSpectrumPhy> ulPhy = CreateObject<LteSpectrumPhy>();
160 Ptr<LteTestUePhy> uePhy = CreateObject<LteTestUePhy>(dlPhy, ulPhy);
161 uint16_t cellId = 100;
162 dlPhy->SetCellId(cellId);
163 ulPhy->SetCellId(cellId);
164
165 Ptr<LteChunkProcessor> chunkProcessor = Create<LteChunkProcessor>();
166 LteSpectrumValueCatcher actualSinrCatcher;
167 chunkProcessor->AddCallback(
168 MakeCallback(&LteSpectrumValueCatcher::ReportValue, &actualSinrCatcher));
169 ulPhy->AddDataSinrChunkProcessor(chunkProcessor);
170
179 // Number of packet bursts (2 data + 4 interferences)
180 const int numOfDataPbs = 2;
181 const int numOfIntfPbs = 4;
182 const int numOfPbs = numOfDataPbs + numOfIntfPbs;
183
184 // Number of packets in the packet bursts
185 const int numOfPkts = 10;
186
187 // Packet bursts
188 Ptr<PacketBurst> packetBursts[numOfPbs];
189
190 // Packets
191 Ptr<Packet> pkt[numOfPbs][numOfPkts];
192
193 // Bursts cellId
194 uint16_t pbCellId[numOfPbs];
195
199 int pb = 0;
200 for (int dataPb = 0; dataPb < numOfDataPbs; dataPb++, pb++)
201 {
202 // Create packet burst
203 packetBursts[pb] = CreateObject<PacketBurst>();
204 pbCellId[pb] = cellId;
205 // Create packets and add them to the burst
206 for (int i = 0; i < numOfPkts; i++)
207 {
208 pkt[pb][i] = Create<Packet>(1000);
209
210 packetBursts[pb]->AddPacket(pkt[pb][i]);
211 }
212 }
213 for (int intfPb = 0; intfPb < numOfIntfPbs; intfPb++, pb++)
214 {
215 // Create packet burst
216 packetBursts[pb] = CreateObject<PacketBurst>();
217 pbCellId[pb] = cellId * (pb + 1);
218
219 // Create packets and add them to the burst
220 for (int i = 0; i < numOfPkts; i++)
221 {
222 pkt[pb][i] = Create<Packet>(1000);
223
224 packetBursts[pb]->AddPacket(pkt[pb][i]);
225 }
226 }
227
228 Ptr<SpectrumValue> noisePsd = Create<SpectrumValue>(m_sm);
229 Ptr<SpectrumValue> i1 = Create<SpectrumValue>(m_sm);
230 Ptr<SpectrumValue> i2 = Create<SpectrumValue>(m_sm);
231 Ptr<SpectrumValue> i3 = Create<SpectrumValue>(m_sm);
232 Ptr<SpectrumValue> i4 = Create<SpectrumValue>(m_sm);
233
234 (*noisePsd)[0] = 5.000000000000e-19;
235 (*noisePsd)[1] = 4.545454545455e-19;
236
237 (*i1)[0] = 5.000000000000e-18;
238 (*i2)[0] = 5.000000000000e-16;
239 (*i3)[0] = 1.581138830084e-16;
240 (*i4)[0] = 7.924465962306e-17;
241 (*i1)[1] = 1.437398936440e-18;
242 (*i2)[1] = 5.722388235428e-16;
243 (*i3)[1] = 7.204059965732e-17;
244 (*i4)[1] = 5.722388235428e-17;
245
246 Time ts = Seconds(1);
247 Time ds = Seconds(1);
248 Time ti1 = Seconds(0);
249 Time di1 = Seconds(3);
250 Time ti2 = Seconds(0.7);
251 Time di2 = Seconds(1);
252 Time ti3 = Seconds(1.2);
253 Time di3 = Seconds(1);
254 Time ti4 = Seconds(1.5);
255 Time di4 = Seconds(0.1);
256
257 ulPhy->SetNoisePowerSpectralDensity(noisePsd);
258
263 // 2 UEs send data to the eNB through 2 subcarriers
264 Ptr<LteSpectrumSignalParametersDataFrame> sp1 = Create<LteSpectrumSignalParametersDataFrame>();
265 sp1->psd = m_sv1;
266 sp1->txPhy = nullptr;
267 sp1->duration = ds;
268 sp1->packetBurst = packetBursts[0];
269 sp1->cellId = pbCellId[0];
270 Simulator::Schedule(ts, &LteSpectrumPhy::StartRx, ulPhy, sp1);
271
272 Ptr<LteSpectrumSignalParametersDataFrame> sp2 = Create<LteSpectrumSignalParametersDataFrame>();
273 sp2->psd = m_sv2;
274 sp2->txPhy = nullptr;
275 sp2->duration = ds;
276 sp2->packetBurst = packetBursts[1];
277 sp2->cellId = pbCellId[1];
278 Simulator::Schedule(ts, &LteSpectrumPhy::StartRx, ulPhy, sp2);
279
280 Ptr<LteSpectrumSignalParametersDataFrame> ip1 = Create<LteSpectrumSignalParametersDataFrame>();
281 ip1->psd = i1;
282 ip1->txPhy = nullptr;
283 ip1->duration = di1;
284 ip1->packetBurst = packetBursts[2];
285 ip1->cellId = pbCellId[2];
286 Simulator::Schedule(ti1, &LteSpectrumPhy::StartRx, ulPhy, ip1);
287
288 Ptr<LteSpectrumSignalParametersDataFrame> ip2 = Create<LteSpectrumSignalParametersDataFrame>();
289 ip2->psd = i2;
290 ip2->txPhy = nullptr;
291 ip2->duration = di2;
292 ip2->packetBurst = packetBursts[3];
293 ip2->cellId = pbCellId[3];
294 Simulator::Schedule(ti2, &LteSpectrumPhy::StartRx, ulPhy, ip2);
295
296 Ptr<LteSpectrumSignalParametersDataFrame> ip3 = Create<LteSpectrumSignalParametersDataFrame>();
297 ip3->psd = i3;
298 ip3->txPhy = nullptr;
299 ip3->duration = di3;
300 ip3->packetBurst = packetBursts[4];
301 ip3->cellId = pbCellId[4];
302 Simulator::Schedule(ti3, &LteSpectrumPhy::StartRx, ulPhy, ip3);
303
304 Ptr<LteSpectrumSignalParametersDataFrame> ip4 = Create<LteSpectrumSignalParametersDataFrame>();
305 ip4->psd = i4;
306 ip4->txPhy = nullptr;
307 ip4->duration = di4;
308 ip4->packetBurst = packetBursts[5];
309 ip4->cellId = pbCellId[5];
310 Simulator::Schedule(ti4, &LteSpectrumPhy::StartRx, ulPhy, ip4);
311
312 Simulator::Stop(Seconds(5.0));
313 Simulator::Run();
314
315 NS_LOG_INFO("Data Frame - Theoretical SINR: " << *m_expectedSinr);
316 NS_LOG_INFO("Data Frame - Calculated SINR: " << *(actualSinrCatcher.GetValue()));
317
318 NS_TEST_EXPECT_MSG_NE(actualSinrCatcher.GetValue(), nullptr, "no actual SINR reported");
319
322 0.0000001,
323 "Data Frame - Wrong SINR !");
324 ulPhy->Dispose();
325 Simulator::Destroy();
326}
327
335 std::string name)
336 : TestCase("SINR calculation in uplink srs frame: " + name),
337 m_sv1(sv1),
338 m_sv2(sv2),
339 m_sm(sv1->GetSpectrumModel()),
340 m_expectedSinr(sinr)
341{
342 NS_LOG_INFO("Creating LteUplinkSrsSinrTestCase");
343}
344
346{
347}
348
349void
351{
352 m_actualSinr = sinr.Copy();
353}
354
355void
357{
362 Ptr<LteHelper> lteHelper = CreateObject<LteHelper>();
363 // lteHelper->EnableLogComponents ();
364 Ptr<LteSpectrumPhy> dlPhy = CreateObject<LteSpectrumPhy>();
365 Ptr<LteSpectrumPhy> ulPhy = CreateObject<LteSpectrumPhy>();
366 Ptr<LteTestUePhy> uePhy = CreateObject<LteTestUePhy>(dlPhy, ulPhy);
367 uint16_t cellId = 100;
368 dlPhy->SetCellId(cellId);
369 ulPhy->SetCellId(cellId);
370
371 Ptr<LteChunkProcessor> chunkProcessor = Create<LteChunkProcessor>();
372 chunkProcessor->AddCallback(MakeCallback(&LteUplinkSrsSinrTestCase::ReportSinr, this));
373 ulPhy->AddCtrlSinrChunkProcessor(chunkProcessor);
374
384 // Number of packet bursts (2 data + 4 interferences)
385 int numOfDataSignals = 2;
386 int numOfIntfSignals = 4;
387 int numOfSignals = numOfDataSignals + numOfIntfSignals;
388
389 uint16_t pbCellId[numOfSignals];
390
394 int pb = 0;
395 for (int dataPb = 0; dataPb < numOfDataSignals; dataPb++, pb++)
396 {
397 pbCellId[pb] = cellId;
398 }
399 for (int intfPb = 0; intfPb < numOfIntfSignals; intfPb++, pb++)
400 {
401 pbCellId[pb] = cellId * (pb + 1);
402 }
403
404 Ptr<SpectrumValue> noisePsd = Create<SpectrumValue>(m_sm);
405 Ptr<SpectrumValue> i1 = Create<SpectrumValue>(m_sm);
406 Ptr<SpectrumValue> i2 = Create<SpectrumValue>(m_sm);
407 Ptr<SpectrumValue> i3 = Create<SpectrumValue>(m_sm);
408 Ptr<SpectrumValue> i4 = Create<SpectrumValue>(m_sm);
409
410 (*noisePsd)[0] = 5.000000000000e-19;
411 (*noisePsd)[1] = 4.545454545455e-19;
412
413 (*i1)[0] = 5.000000000000e-18;
414 (*i2)[0] = 5.000000000000e-16;
415 (*i3)[0] = 1.581138830084e-16;
416 (*i4)[0] = 7.924465962306e-17;
417 (*i1)[1] = 1.437398936440e-18;
418 (*i2)[1] = 5.722388235428e-16;
419 (*i3)[1] = 7.204059965732e-17;
420 (*i4)[1] = 5.722388235428e-17;
421
422 Time ts = Seconds(1);
423 Time ds = Seconds(1);
424 Time ti1 = Seconds(0);
425 Time di1 = Seconds(3);
426 Time ti2 = Seconds(0.7);
427 Time di2 = Seconds(1);
428 Time ti3 = Seconds(1.2);
429 Time di3 = Seconds(1);
430 Time ti4 = Seconds(1.5);
431 Time di4 = Seconds(0.1);
432
433 ulPhy->SetNoisePowerSpectralDensity(noisePsd);
434
439 // 2 UEs send data to the eNB through 2 subcarriers
441 Create<LteSpectrumSignalParametersUlSrsFrame>();
442 sp1->psd = m_sv1;
443 sp1->txPhy = nullptr;
444 sp1->duration = ds;
445 sp1->cellId = pbCellId[0];
446 Simulator::Schedule(ts, &LteSpectrumPhy::StartRx, ulPhy, sp1);
447
449 Create<LteSpectrumSignalParametersUlSrsFrame>();
450 sp2->psd = m_sv2;
451 sp2->txPhy = nullptr;
452 sp2->duration = ds;
453 sp2->cellId = pbCellId[1];
454 Simulator::Schedule(ts, &LteSpectrumPhy::StartRx, ulPhy, sp2);
455
457 Create<LteSpectrumSignalParametersUlSrsFrame>();
458 ip1->psd = i1;
459 ip1->txPhy = nullptr;
460 ip1->duration = di1;
461 ip1->cellId = pbCellId[2];
462 Simulator::Schedule(ti1, &LteSpectrumPhy::StartRx, ulPhy, ip1);
463
465 Create<LteSpectrumSignalParametersUlSrsFrame>();
466 ip2->psd = i2;
467 ip2->txPhy = nullptr;
468 ip2->duration = di2;
469 ip2->cellId = pbCellId[3];
470 Simulator::Schedule(ti2, &LteSpectrumPhy::StartRx, ulPhy, ip2);
471
473 Create<LteSpectrumSignalParametersUlSrsFrame>();
474 ip3->psd = i3;
475 ip3->txPhy = nullptr;
476 ip3->duration = di3;
477 ip3->cellId = pbCellId[4];
478 Simulator::Schedule(ti3, &LteSpectrumPhy::StartRx, ulPhy, ip3);
479
481 Create<LteSpectrumSignalParametersUlSrsFrame>();
482 ip4->psd = i4;
483 ip4->txPhy = nullptr;
484 ip4->duration = di4;
485 ip4->cellId = pbCellId[5];
486 Simulator::Schedule(ti4, &LteSpectrumPhy::StartRx, ulPhy, ip4);
487
488 Simulator::Stop(Seconds(5.0));
489 Simulator::Run();
490
491 NS_ASSERT_MSG(m_actualSinr, "no actual SINR reported");
492
493 NS_LOG_INFO("SRS Frame - Theoretical SINR: " << *m_expectedSinr);
494 NS_LOG_INFO("SRS Frame - Calculated SINR: " << *m_actualSinr);
495
498 0.0000001,
499 "Data Frame - Wrong SINR !");
500 ulPhy->Dispose();
501 Simulator::Destroy();
502}
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
static LteUplinkSinrTestSuite lteUplinkSinrTestSuite
Static variable for test initialization.
#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:1336
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