5G-LENA nr-v3.0-32-g83aee33
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-test-harq.cc
Go to the documentation of this file.
1/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
3// Copyright (c) 2021 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4//
5// SPDX-License-Identifier: GPL-2.0-only
6
7#include <ns3/nr-eesm-cc-t1.h>
8#include <ns3/nr-eesm-error-model.h>
9#include <ns3/nr-eesm-ir-t1.h>
10#include <ns3/nr-spectrum-value-helper.h>
11#include <ns3/ptr.h>
12#include <ns3/spectrum-value.h>
13#include <ns3/test.h>
14
15#include <cmath>
16#include <iostream>
17
30namespace ns3
31{
32
33class TestHarqTestCase : public TestCase
34{
35 public:
36 TestHarqTestCase(std::vector<std::vector<double>> rxSinrDb,
37 std::vector<double> refEffSinrPerRx,
38 uint16_t mcs,
39 uint16_t tbSize,
40 const std::string& name)
41 : TestCase(name),
42 m_rxSinrDb(rxSinrDb),
43 m_refEffSinrPerRx(refEffSinrPerRx),
44 m_mcs(mcs),
45 m_tbSize(tbSize)
46 {
47 }
48
49 private:
50 void DoRun() override;
51 void ValidateHarqForTwoRx();
52 NrErrorModel::NrErrorModelHistory GetTbDecodStats(std::vector<double> sinrRx,
54 std::string harqType) const;
55 std::vector<std::vector<double>> m_rxSinrDb;
57 std::vector<double> m_refEffSinrPerRx;
59 uint16_t m_mcs{0};
60 uint16_t m_tbSize{0};
61};
62
64TestHarqTestCase::GetTbDecodStats(std::vector<double> sinrRx,
66 std::string harqType) const
67{
68 uint8_t nRbsRx = sinrRx.size();
69
70 Ptr<const SpectrumModel> spectModelRx =
72 SpectrumValue sinrRxSpecVal(spectModelRx);
73
74 for (size_t i = 0; i < sinrRx.size(); i++)
75 {
76 sinrRxSpecVal[i] = pow(10.0, sinrRx.at(i) / 10.0);
77 }
78
79 std::vector<int> rbMap;
80 int rbIndex = 0;
81 for (uint8_t i = 0; i < sinrRx.size(); i++, rbIndex++)
82 {
83 rbMap.push_back(rbIndex);
84 }
85
86 Ptr<NrErrorModelOutput> output;
87 if (harqType == "IR")
88 {
89 Ptr<NrEesmIrT1> errorModelIr = CreateObject<NrEesmIrT1>();
90 output = errorModelIr->GetTbDecodificationStats(sinrRxSpecVal,
91 rbMap,
92 m_tbSize,
93 m_mcs,
94 harqHistory);
95 }
96 else if (harqType == "CC")
97 {
98 Ptr<NrEesmCcT1> errorModelCc = CreateObject<NrEesmCcT1>();
99 output = errorModelCc->GetTbDecodificationStats(sinrRxSpecVal,
100 rbMap,
101 m_tbSize,
102 m_mcs,
103 harqHistory);
104 }
105 else
106 {
107 NS_FATAL_ERROR("Unknown HARQ type. Use IR or CC");
108 }
109
111 history.push_back(output);
112 return history;
113}
114
115void
116TestHarqTestCase::ValidateHarqForTwoRx()
117{
118 std::vector<double> sinrRx1 = m_rxSinrDb.at(0);
119 std::vector<double> sinrRx2 = m_rxSinrDb.at(1);
121
122 // Incremental Redundancy
123 history = GetTbDecodStats(sinrRx1, history, "IR");
124 auto outputIr = history.at(0);
125 auto eesmOutputIr = DynamicCast<NrEesmErrorModelOutput>(outputIr);
126 double sinrEffIr = eesmOutputIr->m_sinrEff;
127
128 // std::cout << "sinrEff IR Rx1 = " << sinrEffIr << std::endl;
129 NS_TEST_ASSERT_MSG_EQ_TOL(sinrEffIr,
130 m_refEffSinrPerRx.at(0),
131 0.0001,
132 "Resulted effective SINR of IR for RX 1 should be equal to the test "
133 "value with tol +-0.0001");
134
135 history = GetTbDecodStats(sinrRx2, history, "IR");
136 outputIr = history.at(0);
137 eesmOutputIr = DynamicCast<NrEesmErrorModelOutput>(outputIr);
138 sinrEffIr = eesmOutputIr->m_sinrEff;
139
140 // std::cout << "sinrEff IR Rx2 = " << sinrEffIr << std::endl;
141 NS_TEST_ASSERT_MSG_EQ_TOL(sinrEffIr,
142 m_refEffSinrPerRx.at(1),
143 0.0001,
144 "Resulted effective SINR of IR for RX 2 should be equal to the test "
145 "value with tol +-0.0001");
146
147 history.clear();
148 // Chase Combining
149 history = GetTbDecodStats(sinrRx1, history, "CC");
150 auto outputCc = history.at(0);
151 auto eesmOutputCc = DynamicCast<NrEesmErrorModelOutput>(outputCc);
152 double sinrEffCc = eesmOutputCc->m_sinrEff;
153
154 // std::cout << "sinrEff CC Rx1 = " << sinrEffCc << std::endl;
155 NS_TEST_ASSERT_MSG_EQ_TOL(sinrEffCc,
156 m_refEffSinrPerRx.at(2),
157 0.0001,
158 "Resulted effective SINR of CC for RX 1 should be equal to the test "
159 "value with tol +-0.0001");
160
161 history = GetTbDecodStats(sinrRx2, history, "CC");
162 outputCc = history.at(0);
163 eesmOutputCc = DynamicCast<NrEesmErrorModelOutput>(outputCc);
164 sinrEffCc = eesmOutputCc->m_sinrEff;
165
166 // std::cout << "sinrEff CC Rx2 = " << sinrEffCc << std::endl;
167 NS_TEST_ASSERT_MSG_EQ_TOL(sinrEffCc,
168 m_refEffSinrPerRx.at(3),
169 0.0001,
170 "Resulted effective SINR of CC for RX 2 should be equal to the test "
171 "value with tol +-0.0001");
172}
173
174void
175TestHarqTestCase::DoRun()
176{
177 switch (m_rxSinrDb.size())
178 {
179 case 2:
180 ValidateHarqForTwoRx();
181 break;
182 default:
183 NS_FATAL_ERROR("Unsupported number of RX given to test HARQ");
184 }
185}
186
187class TestHarq : public TestSuite
188{
189 public:
190 TestHarq()
191 : TestSuite("nr-test-harq", Type::SYSTEM)
192 {
193 // test-1: 2 receptions
194 std::vector<std::vector<double>> rxSinrDb;
195 std::vector<double> sinrDbRx1 = {1.0, 3.5};
196 rxSinrDb.push_back(sinrDbRx1);
197 std::vector<double> sinrDbRx2 = {1.0, 1.5, 2.0, 2.5, 3.0, 3.5};
198 rxSinrDb.push_back(sinrDbRx2);
199 std::vector<double> refEffSinrPerRx;
200 // first the effective SINRs of the two receptions with IR
201 refEffSinrPerRx.push_back(1.67919); // After 1st RX
202 refEffSinrPerRx.push_back(1.67907); // After 2nd RX
203 // the last two are the effective SINRs of the two receptions with CC
204 refEffSinrPerRx.push_back(1.67919); // After 1st RX
205 refEffSinrPerRx.push_back(3.3318); // After 2nd RX
206 uint16_t mcs = 5;
207 uint16_t tbSize = 256;
208 AddTestCase(new TestHarqTestCase(rxSinrDb,
209 refEffSinrPerRx,
210 mcs,
211 tbSize,
212 "HARQ test with 2 receptions"),
213 Duration::QUICK);
214 }
215};
216
217static TestHarq testHarq;
218
219} // namespace ns3
std::vector< Ptr< NrErrorModelOutput > > NrErrorModelHistory
Vector of previous output.
static Ptr< const SpectrumModel > GetSpectrumModel(uint32_t numRbs, double centerFrequency, double subcarrierSpacing)
Creates or obtains from a global map a spectrum model with a given number of RBs, center frequency an...
static TestHarq testHarq
HARQ test.