A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Manuel Requena <manuel.requena@cttc.es>
7 * Modified by Marco Miozzo <mmiozzo@ctt.es>
8 * Extend to Data and SRS frames
9 */
10
12
13#include "lte-test-ue-phy.h"
14
15#include "ns3/log.h"
16#include "ns3/lte-phy-tag.h"
17#include "ns3/lte-spectrum-signal-parameters.h"
18#include "ns3/simulator.h"
19#include "ns3/spectrum-test.h"
20#include <ns3/lte-chunk-processor.h>
21#include <ns3/lte-helper.h>
22
23using namespace ns3;
24
25NS_LOG_COMPONENT_DEFINE("LteUplinkSinrTest");
26
27/**
28 * Test 1.2 SINR calculation in uplink
29 */
30
31/**
32 * TestSuite
33 */
35 : TestSuite("lte-uplink-sinr", Type::SYSTEM)
36{
37 /**
38 * Build Spectrum Model values for the TX signal
39 */
41
42 Bands bands;
43 BandInfo bi;
44
45 bi.fl = 2.400e9;
46 bi.fc = 2.410e9;
47 bi.fh = 2.420e9;
48 bands.push_back(bi);
49
50 bi.fl = 2.420e9;
51 bi.fc = 2.431e9;
52 bi.fh = 2.442e9;
53 bands.push_back(bi);
54
55 sm = Create<SpectrumModel>(bands);
56
57 /**
58 * TX signals #1: Power Spectral Density (W/Hz) of the signals of interest = [-46 -inf] and
59 * [-inf -48] dBm and BW = [20 22] MHz
60 */
62 (*rxPsd1)[0] = 1.255943215755e-15;
63 (*rxPsd1)[1] = 0.0;
64
66 (*rxPsd2)[0] = 0.0;
67 (*rxPsd2)[1] = 7.204059965732e-16;
68
69 Ptr<SpectrumValue> theoreticalSinr1 = Create<SpectrumValue>(sm);
70 (*theoreticalSinr1)[0] = 3.72589167251055;
71 (*theoreticalSinr1)[1] = 3.72255684126076;
72
74 rxPsd2,
75 theoreticalSinr1,
76 "sdBm = [-46 -inf] and [-inf -48]"),
77 TestCase::Duration::QUICK);
78
80 rxPsd2,
81 theoreticalSinr1,
82 "sdBm = [-46 -inf] and [-inf -48]"),
83 TestCase::Duration::QUICK);
84
85 /**
86 * TX signals #2: Power Spectral Density of the signals of interest = [-63 -inf] and [-inf -61]
87 * dBm and BW = [20 22] MHz
88 */
90 (*rxPsd3)[0] = 2.505936168136e-17;
91 (*rxPsd3)[1] = 0.0;
92
94 (*rxPsd4)[0] = 0.0;
95 (*rxPsd4)[1] = 3.610582885110e-17;
96
97 Ptr<SpectrumValue> theoreticalSinr2 = Create<SpectrumValue>(sm);
98 (*theoreticalSinr2)[0] = 0.0743413124381667;
99 (*theoreticalSinr2)[1] = 0.1865697965291756;
100
102 rxPsd4,
103 theoreticalSinr2,
104 "sdBm = [-63 -inf] and [-inf -61]"),
105 TestCase::Duration::QUICK);
106
108 rxPsd4,
109 theoreticalSinr2,
110 "sdBm = [-63 -inf] and [-inf -61]"),
111 TestCase::Duration::QUICK);
112}
113
114/**
115 * @ingroup lte-test
116 * Static variable for test initialization
117 */
119
120/**
121 * TestCase Data
122 */
123
127 std::string name)
128 : TestCase("SINR calculation in uplink data frame: " + name),
129 m_sv1(sv1),
130 m_sv2(sv2),
131 m_sm(sv1->GetSpectrumModel()),
132 m_expectedSinr(sinr)
133{
134 NS_LOG_INFO("Creating LteUplinkDataSinrTestCase");
135}
136
140
141void
143{
144 /**
145 * Instantiate a single receiving LteSpectrumPhy
146 */
149 Ptr<LteTestUePhy> uePhy = CreateObject<LteTestUePhy>(dlPhy, ulPhy);
150 uint16_t cellId = 100;
151 dlPhy->SetCellId(cellId);
152 ulPhy->SetCellId(cellId);
153
155 LteSpectrumValueCatcher actualSinrCatcher;
156 chunkProcessor->AddCallback(
158 ulPhy->AddDataSinrChunkProcessor(chunkProcessor);
159
160 /**
161 * Generate several calls to LteSpectrumPhy::StartRx corresponding to
162 * several signals. One will be the signal of interest, i.e., the
163 * LteSpectrumSignalParametersDataFrame of the Packet burst
164 * will have the same CellId of the receiving PHY; the others will have
165 * a different CellId and hence will be the interfering signals
166 */
167
168 // Number of packet bursts (2 data + 4 interferences)
169 constexpr int numOfDataPbs = 2;
170 constexpr int numOfIntfPbs = 4;
171 constexpr int numOfPbs = numOfDataPbs + numOfIntfPbs;
172
173 // Number of packets in the packet bursts
174 constexpr int numOfPkts = 10;
175
176 // Packet bursts
177 Ptr<PacketBurst> packetBursts[numOfPbs];
178
179 // Packets
180 Ptr<Packet> pkt[numOfPbs][numOfPkts];
181
182 // Bursts cellId
183 uint16_t pbCellId[numOfPbs];
184
185 /**
186 * Build packet burst (Data and interference)
187 */
188 int pb = 0;
189 for (int dataPb = 0; dataPb < numOfDataPbs; dataPb++, pb++)
190 {
191 // Create packet burst
192 packetBursts[pb] = CreateObject<PacketBurst>();
193 pbCellId[pb] = cellId;
194 // Create packets and add them to the burst
195 for (int i = 0; i < numOfPkts; i++)
196 {
197 pkt[pb][i] = Create<Packet>(1000);
198
199 packetBursts[pb]->AddPacket(pkt[pb][i]);
200 }
201 }
202 for (int intfPb = 0; intfPb < numOfIntfPbs; intfPb++, pb++)
203 {
204 // Create packet burst
205 packetBursts[pb] = CreateObject<PacketBurst>();
206 pbCellId[pb] = cellId * (pb + 1);
207
208 // Create packets and add them to the burst
209 for (int i = 0; i < numOfPkts; i++)
210 {
211 pkt[pb][i] = Create<Packet>(1000);
212
213 packetBursts[pb]->AddPacket(pkt[pb][i]);
214 }
215 }
216
222
223 (*noisePsd)[0] = 5.000000000000e-19;
224 (*noisePsd)[1] = 4.545454545455e-19;
225
226 (*i1)[0] = 5.000000000000e-18;
227 (*i2)[0] = 5.000000000000e-16;
228 (*i3)[0] = 1.581138830084e-16;
229 (*i4)[0] = 7.924465962306e-17;
230 (*i1)[1] = 1.437398936440e-18;
231 (*i2)[1] = 5.722388235428e-16;
232 (*i3)[1] = 7.204059965732e-17;
233 (*i4)[1] = 5.722388235428e-17;
234
235 Time ts = Seconds(1);
236 Time ds = Seconds(1);
237 Time ti1 = Seconds(0);
238 Time di1 = Seconds(3);
239 Time ti2 = Seconds(0.7);
240 Time di2 = Seconds(1);
241 Time ti3 = Seconds(1.2);
242 Time di3 = Seconds(1);
243 Time ti4 = Seconds(1.5);
244 Time di4 = Seconds(0.1);
245
246 ulPhy->SetNoisePowerSpectralDensity(noisePsd);
247
248 /**
249 * Schedule the reception of the data signals plus the interference signals
250 */
251
252 // 2 UEs send data to the eNB through 2 subcarriers
254 sp1->psd = m_sv1;
255 sp1->txPhy = nullptr;
256 sp1->duration = ds;
257 sp1->packetBurst = packetBursts[0];
258 sp1->cellId = pbCellId[0];
260
262 sp2->psd = m_sv2;
263 sp2->txPhy = nullptr;
264 sp2->duration = ds;
265 sp2->packetBurst = packetBursts[1];
266 sp2->cellId = pbCellId[1];
268
270 ip1->psd = i1;
271 ip1->txPhy = nullptr;
272 ip1->duration = di1;
273 ip1->packetBurst = packetBursts[2];
274 ip1->cellId = pbCellId[2];
276
278 ip2->psd = i2;
279 ip2->txPhy = nullptr;
280 ip2->duration = di2;
281 ip2->packetBurst = packetBursts[3];
282 ip2->cellId = pbCellId[3];
284
286 ip3->psd = i3;
287 ip3->txPhy = nullptr;
288 ip3->duration = di3;
289 ip3->packetBurst = packetBursts[4];
290 ip3->cellId = pbCellId[4];
292
294 ip4->psd = i4;
295 ip4->txPhy = nullptr;
296 ip4->duration = di4;
297 ip4->packetBurst = packetBursts[5];
298 ip4->cellId = pbCellId[5];
300
303
304 NS_LOG_INFO("Data Frame - Theoretical SINR: " << *m_expectedSinr);
305 NS_LOG_INFO("Data Frame - Calculated SINR: " << *(actualSinrCatcher.GetValue()));
306
307 NS_TEST_EXPECT_MSG_NE(actualSinrCatcher.GetValue(), nullptr, "no actual SINR reported");
308
311 0.0000001,
312 "Data Frame - Wrong SINR !");
313 ulPhy->Dispose();
315}
316
317/**
318 * TestCase Srs
319 */
320
324 std::string name)
325 : TestCase("SINR calculation in uplink srs frame: " + name),
326 m_sv1(sv1),
327 m_sv2(sv2),
328 m_sm(sv1->GetSpectrumModel()),
329 m_expectedSinr(sinr)
330{
331 NS_LOG_INFO("Creating LteUplinkSrsSinrTestCase");
332}
333
337
338void
343
344void
346{
347 /**
348 * Instantiate a single receiving LteSpectrumPhy
349 */
350
352 // lteHelper->EnableLogComponents ();
355 Ptr<LteTestUePhy> uePhy = CreateObject<LteTestUePhy>(dlPhy, ulPhy);
356 uint16_t cellId = 100;
357 dlPhy->SetCellId(cellId);
358 ulPhy->SetCellId(cellId);
359
361 chunkProcessor->AddCallback(MakeCallback(&LteUplinkSrsSinrTestCase::ReportSinr, this));
362 ulPhy->AddCtrlSinrChunkProcessor(chunkProcessor);
363
364 /**
365 * Generate several calls to LteSpectrumPhy::StartRx corresponding to
366 * several signals.
367 * One will be the signal of interest, i.e., the
368 * LteSpectrumSignalParametersUlSrsFrame of the first signal will have the
369 * same CellId of the receiving PHY; the others will have a different
370 * CellId and hence will be the interfering signals
371 */
372
373 // Number of packet bursts (2 data + 4 interferences)
374 constexpr int numOfDataSignals = 2;
375 constexpr int numOfIntfSignals = 4;
376 constexpr int numOfSignals = numOfDataSignals + numOfIntfSignals;
377
378 uint16_t pbCellId[numOfSignals];
379
380 /**
381 * Build packet burst (Data and interference)
382 */
383 int pb = 0;
384 for (int dataPb = 0; dataPb < numOfDataSignals; dataPb++, pb++)
385 {
386 pbCellId[pb] = cellId;
387 }
388 for (int intfPb = 0; intfPb < numOfIntfSignals; intfPb++, pb++)
389 {
390 pbCellId[pb] = cellId * (pb + 1);
391 }
392
398
399 (*noisePsd)[0] = 5.000000000000e-19;
400 (*noisePsd)[1] = 4.545454545455e-19;
401
402 (*i1)[0] = 5.000000000000e-18;
403 (*i2)[0] = 5.000000000000e-16;
404 (*i3)[0] = 1.581138830084e-16;
405 (*i4)[0] = 7.924465962306e-17;
406 (*i1)[1] = 1.437398936440e-18;
407 (*i2)[1] = 5.722388235428e-16;
408 (*i3)[1] = 7.204059965732e-17;
409 (*i4)[1] = 5.722388235428e-17;
410
411 Time ts = Seconds(1);
412 Time ds = Seconds(1);
413 Time ti1 = Seconds(0);
414 Time di1 = Seconds(3);
415 Time ti2 = Seconds(0.7);
416 Time di2 = Seconds(1);
417 Time ti3 = Seconds(1.2);
418 Time di3 = Seconds(1);
419 Time ti4 = Seconds(1.5);
420 Time di4 = Seconds(0.1);
421
422 ulPhy->SetNoisePowerSpectralDensity(noisePsd);
423
424 /**
425 * Schedule the reception of the data signals plus the interference signals
426 */
427
428 // 2 UEs send data to the eNB through 2 subcarriers
431 sp1->psd = m_sv1;
432 sp1->txPhy = nullptr;
433 sp1->duration = ds;
434 sp1->cellId = pbCellId[0];
436
439 sp2->psd = m_sv2;
440 sp2->txPhy = nullptr;
441 sp2->duration = ds;
442 sp2->cellId = pbCellId[1];
444
447 ip1->psd = i1;
448 ip1->txPhy = nullptr;
449 ip1->duration = di1;
450 ip1->cellId = pbCellId[2];
452
455 ip2->psd = i2;
456 ip2->txPhy = nullptr;
457 ip2->duration = di2;
458 ip2->cellId = pbCellId[3];
460
463 ip3->psd = i3;
464 ip3->txPhy = nullptr;
465 ip3->duration = di3;
466 ip3->cellId = pbCellId[4];
468
471 ip4->psd = i4;
472 ip4->txPhy = nullptr;
473 ip4->duration = di4;
474 ip4->cellId = pbCellId[5];
476
479
480 NS_ASSERT_MSG(m_actualSinr, "no actual SINR reported");
481
482 NS_LOG_INFO("SRS Frame - Theoretical SINR: " << *m_expectedSinr);
483 NS_LOG_INFO("SRS Frame - Calculated SINR: " << *m_actualSinr);
484
487 0.0000001,
488 "Data Frame - Wrong SINR !");
489 ulPhy->Dispose();
491}
void StartRx(Ptr< SpectrumSignalParameters > params) override
Notify the SpectrumPhy instance of an incoming signal.
A sink to be plugged to the callback of LteChunkProcessor allowing to save and later retrieve the lat...
Ptr< SpectrumValue > GetValue()
void ReportValue(const SpectrumValue &value)
function to be plugged to LteChunkProcessor::AddCallback ()
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
Set of values corresponding to a given SpectrumModel.
Ptr< SpectrumValue > Copy() const
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
#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:75
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition log.h:264
static LteUplinkSinrTestSuite lteUplinkSinrTestSuite
Static variable for test initialization.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
#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:656
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
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:684
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