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 * 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
38/**
39 * Test 1.2 SINR calculation in uplink
40 */
41
42/**
43 * TestSuite
44 */
46 : TestSuite("lte-uplink-sinr", Type::SYSTEM)
47{
48 /**
49 * Build Spectrum Model values for the TX signal
50 */
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
68 /**
69 * TX signals #1: Power Spectral Density (W/Hz) of the signals of interest = [-46 -inf] and
70 * [-inf -48] dBm and BW = [20 22] MHz
71 */
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::Duration::QUICK);
89
91 rxPsd2,
92 theoreticalSinr1,
93 "sdBm = [-46 -inf] and [-inf -48]"),
94 TestCase::Duration::QUICK);
95
96 /**
97 * TX signals #2: Power Spectral Density of the signals of interest = [-63 -inf] and [-inf -61]
98 * dBm and BW = [20 22] MHz
99 */
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::Duration::QUICK);
117
119 rxPsd4,
120 theoreticalSinr2,
121 "sdBm = [-63 -inf] and [-inf -61]"),
122 TestCase::Duration::QUICK);
123}
124
125/**
126 * \ingroup lte-test
127 * Static variable for test initialization
128 */
130
131/**
132 * TestCase Data
133 */
134
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{
155 /**
156 * Instantiate a single receiving LteSpectrumPhy
157 */
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(
169 ulPhy->AddDataSinrChunkProcessor(chunkProcessor);
170
171 /**
172 * Generate several calls to LteSpectrumPhy::StartRx corresponding to
173 * several signals. One will be the signal of interest, i.e., the
174 * LteSpectrumSignalParametersDataFrame of the Packet burst
175 * will have the same CellId of the receiving PHY; the others will have
176 * a different CellId and hence will be the interfering signals
177 */
178
179 // Number of packet bursts (2 data + 4 interferences)
180 constexpr int numOfDataPbs = 2;
181 constexpr int numOfIntfPbs = 4;
182 constexpr int numOfPbs = numOfDataPbs + numOfIntfPbs;
183
184 // Number of packets in the packet bursts
185 constexpr 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
196 /**
197 * Build packet burst (Data and interference)
198 */
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
259 /**
260 * Schedule the reception of the data signals plus the interference signals
261 */
262
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];
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];
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];
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];
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];
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];
311
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();
326}
327
328/**
329 * TestCase Srs
330 */
331
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{
358 /**
359 * Instantiate a single receiving LteSpectrumPhy
360 */
361
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
375 /**
376 * Generate several calls to LteSpectrumPhy::StartRx corresponding to
377 * several signals.
378 * One will be the signal of interest, i.e., the
379 * LteSpectrumSignalParametersUlSrsFrame of the first signal will have the
380 * same CellId of the receiving PHY; the others will have a different
381 * CellId and hence will be the interfering signals
382 */
383
384 // Number of packet bursts (2 data + 4 interferences)
385 constexpr int numOfDataSignals = 2;
386 constexpr int numOfIntfSignals = 4;
387 constexpr int numOfSignals = numOfDataSignals + numOfIntfSignals;
388
389 uint16_t pbCellId[numOfSignals];
390
391 /**
392 * Build packet burst (Data and interference)
393 */
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
435 /**
436 * Schedule the reception of the data signals plus the interference signals
437 */
438
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];
447
449 Create<LteSpectrumSignalParametersUlSrsFrame>();
450 sp2->psd = m_sv2;
451 sp2->txPhy = nullptr;
452 sp2->duration = ds;
453 sp2->cellId = pbCellId[1];
455
457 Create<LteSpectrumSignalParametersUlSrsFrame>();
458 ip1->psd = i1;
459 ip1->txPhy = nullptr;
460 ip1->duration = di1;
461 ip1->cellId = pbCellId[2];
463
465 Create<LteSpectrumSignalParametersUlSrsFrame>();
466 ip2->psd = i2;
467 ip2->txPhy = nullptr;
468 ip2->duration = di2;
469 ip2->cellId = pbCellId[3];
471
473 Create<LteSpectrumSignalParametersUlSrsFrame>();
474 ip3->psd = i3;
475 ip3->txPhy = nullptr;
476 ip3->duration = di3;
477 ip3->cellId = pbCellId[4];
479
481 Create<LteSpectrumSignalParametersUlSrsFrame>();
482 ip4->psd = i4;
483 ip4->txPhy = nullptr;
484 ip4->duration = di4;
485 ip4->cellId = pbCellId[5];
487
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();
502}
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.
Definition: ptr.h:77
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:142
static void Run()
Run the simulation.
Definition: simulator.cc:178
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:186
Set of values corresponding to a given SpectrumModel.
Ptr< SpectrumValue > Copy() const
encapsulates test code
Definition: test.h:1061
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition: test.cc:301
A suite of tests to run.
Definition: test.h:1268
Type
Type of test.
Definition: test.h:1275
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:667
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1319
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:706
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