5G-LENA nr-v3.3-18-g7e4df5bb
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-test-sched.cc
Go to the documentation of this file.
1// Copyright (c) 2019 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
2//
3// SPDX-License-Identifier: GPL-2.0-only
4
5#include <ns3/nr-mac-sched-sap.h>
6#include <ns3/nr-mac-scheduler-ns3.h>
7#include <ns3/object-factory.h>
8#include <ns3/test.h>
9
21namespace ns3
22{
23
30class TestCschedSapUser : public NrMacCschedSapUser
31{
32 public:
33 TestCschedSapUser()
34 : NrMacCschedSapUser()
35 {
36 }
37
38 void CschedCellConfigCnf(
39 [[maybe_unused]] const struct CschedCellConfigCnfParameters& params) override
40 {
41 }
42
43 void CschedUeConfigCnf(
44 [[maybe_unused]] const struct CschedUeConfigCnfParameters& params) override
45 {
46 }
47
48 void CschedLcConfigCnf(
49 [[maybe_unused]] const struct CschedLcConfigCnfParameters& params) override
50 {
51 }
52
53 void CschedLcReleaseCnf(
54 [[maybe_unused]] const struct CschedLcReleaseCnfParameters& params) override
55 {
56 }
57
58 void CschedUeReleaseCnf(
59 [[maybe_unused]] const struct CschedUeReleaseCnfParameters& params) override
60 {
61 }
62
63 void CschedUeConfigUpdateInd(
64 [[maybe_unused]] const struct CschedUeConfigUpdateIndParameters& params) override
65 {
66 }
67
68 void CschedCellConfigUpdateInd(
69 [[maybe_unused]] const struct CschedCellConfigUpdateIndParameters& params) override
70 {
71 }
72};
73
74class TestSchedSapUser;
75
79class NrSchedGeneralTestCase : public TestCase
80{
81 public:
87 NrSchedGeneralTestCase(const std::string& scheduler, const std::string& name)
88 : TestCase(name),
89 m_scheduler(scheduler)
90 {
91 }
92
96 ~NrSchedGeneralTestCase() override
97 {
98 }
99
100 void SchedConfigInd(const struct NrMacSchedSapUser::SchedConfigIndParameters& params);
101
102 protected:
103 void TestSAPInterface(const Ptr<NrMacScheduler>& sched);
104 void TestAddingRemovingUsersNoData(const Ptr<NrMacSchedulerNs3>& sched);
105 void TestSchedNewData(const Ptr<NrMacSchedulerNs3>& sched);
106 void TestSchedNewDlData(const Ptr<NrMacSchedulerNs3>& sched);
107 void TestSchedNewUlData(const Ptr<NrMacSchedulerNs3>& sched);
108 void TestSchedNewDlUlData(const Ptr<NrMacSchedulerNs3>& sched);
109
110 protected:
111 void AddOneUser(uint16_t rnti, const Ptr<NrMacSchedulerNs3>& sched);
112 void TestingRemovingUsers(const Ptr<NrMacSchedulerNs3>& sched);
113 void TestingAddingUsers(const Ptr<NrMacSchedulerNs3>& sched);
114 void LcConfigFor(uint16_t rnti, uint32_t bytes, const Ptr<NrMacSchedulerNs3>& sched);
115
116 private:
117 void DoRun() override;
118
119 std::string m_scheduler{};
120 TestCschedSapUser* m_cSchedSapUser{nullptr};
121 TestSchedSapUser* m_schedSapUser{nullptr};
122};
123
124class TestSchedSapUser : public NrMacSchedSapUser
125{
126 public:
127 TestSchedSapUser(NrSchedGeneralTestCase* testCase)
128 : NrMacSchedSapUser(),
129 m_testCase(testCase)
130 {
131 }
132
133 void SchedConfigInd(const struct SchedConfigIndParameters& params) override
134 {
135 m_testCase->SchedConfigInd(params);
136 }
137
138 // For the rest, setup some hard-coded values; for the moment, there is
139 // no need to have real values here.
140 Ptr<const SpectrumModel> GetSpectrumModel() const override
141 {
142 return nullptr;
143 }
144
145 uint32_t GetNumRbPerRbg() const override
146 {
147 return 1;
148 }
149
150 uint8_t GetNumHarqProcess() const override
151 {
152 return 20;
153 }
154
155 uint16_t GetBwpId() const override
156 {
157 return 0;
158 }
159
160 uint16_t GetCellId() const override
161 {
162 return 0;
163 }
164
165 uint32_t GetSymbolsPerSlot() const override
166 {
167 return 14;
168 }
169
170 Time GetSlotPeriod() const override
171 {
172 return MilliSeconds(1);
173 }
174
175 void BuildRarList(SlotAllocInfo& allocInfo) override
176 {
177 }
178
179 private:
180 NrSchedGeneralTestCase* m_testCase;
181};
182
183void
184NrSchedGeneralTestCase::TestSAPInterface(const Ptr<NrMacScheduler>& sched)
185{
186 NS_ABORT_IF(sched->GetMacSchedSapProvider() == nullptr);
187 NS_ABORT_IF(sched->GetMacCschedSapProvider() == nullptr);
188 sched->SetMacCschedSapUser(m_cSchedSapUser);
189 sched->SetMacSchedSapUser(m_schedSapUser);
190}
191
192void
193NrSchedGeneralTestCase::SchedConfigInd(
194 [[maybe_unused]] const struct NrMacSchedSapUser::SchedConfigIndParameters& params)
195{
196}
197
198void
199NrSchedGeneralTestCase::AddOneUser(uint16_t rnti, const Ptr<NrMacSchedulerNs3>& sched)
200{
201 NrMacCschedSapProvider::CschedUeConfigReqParameters params;
202 params.m_rnti = rnti;
203 params.m_beamId = BeamId(8, 120.0);
204 sched->DoCschedUeConfigReq(params);
205}
206
207void
208NrSchedGeneralTestCase::TestingAddingUsers(const Ptr<NrMacSchedulerNs3>& sched)
209{
210 for (uint16_t i = 0; i < 80; ++i)
211 {
212 AddOneUser(i, sched);
213 NS_TEST_ASSERT_MSG_EQ(sched->m_ueMap.size(),
214 static_cast<uint32_t>(i + 1),
215 "UE not saved in the map");
216 }
217}
218
219void
220NrSchedGeneralTestCase::TestingRemovingUsers(const Ptr<NrMacSchedulerNs3>& sched)
221{
222 for (uint16_t i = 80; i > 0; --i)
223 {
224 NrMacCschedSapProvider::CschedUeReleaseReqParameters params;
225 params.m_rnti = i - 1;
226 sched->DoCschedUeReleaseReq(params);
227 NS_TEST_ASSERT_MSG_EQ(sched->m_ueMap.size(),
228 static_cast<uint32_t>(i - 1),
229 "UE released from the map. Map size " << sched->m_ueMap.size()
230 << " counter " << i);
231 }
232}
233
234void
235NrSchedGeneralTestCase::TestAddingRemovingUsersNoData(const Ptr<NrMacSchedulerNs3>& sched)
236{
237 NS_TEST_ASSERT_MSG_EQ(sched->m_ueMap.size(), 0, "some UE are in the map");
238 TestingAddingUsers(sched);
239 TestingRemovingUsers(sched);
240 NS_TEST_ASSERT_MSG_EQ(sched->m_ueMap.size(),
241 0,
242 sched->m_ueMap.size() << " UEs are still in the map");
243}
244
245void
246NrSchedGeneralTestCase::TestSchedNewData(const Ptr<NrMacSchedulerNs3>& sched)
247{
248 TestSchedNewDlData(sched);
249 TestSchedNewUlData(sched);
250 TestSchedNewDlUlData(sched);
251}
252
253void
254NrSchedGeneralTestCase::LcConfigFor(uint16_t rnti,
255 uint32_t bytes,
256 const Ptr<NrMacSchedulerNs3>& sched)
257{
258 NrMacCschedSapProvider::CschedLcConfigReqParameters params;
259 nr::LogicalChannelConfigListElement_s lc;
260 params.m_rnti = rnti;
261 params.m_reconfigureFlag = false;
262 params.m_logicalChannelConfigList.emplace_back(lc);
263
264 sched->DoCschedLcConfigReq(params);
265}
266
267void
268NrSchedGeneralTestCase::TestSchedNewDlData(const Ptr<NrMacSchedulerNs3>& sched)
269{
270 // Add 80 users
271 TestingAddingUsers(sched);
272}
273
274void
275NrSchedGeneralTestCase::TestSchedNewUlData(const Ptr<NrMacSchedulerNs3>& sched)
276{
277}
278
279void
280NrSchedGeneralTestCase::TestSchedNewDlUlData(const Ptr<NrMacSchedulerNs3>& sched)
281{
282}
283
284void
285NrSchedGeneralTestCase::DoRun()
286{
287 m_cSchedSapUser = new TestCschedSapUser();
288 m_schedSapUser = new TestSchedSapUser(this);
289
290 ObjectFactory factory;
291 factory.SetTypeId(m_scheduler);
292 Ptr<NrMacSchedulerNs3> sched = DynamicCast<NrMacSchedulerNs3>(factory.Create());
293 NS_ABORT_MSG_IF(sched == nullptr, "Can't create a NrMacSchedulerNs3 from type " + m_scheduler);
294
295 TestSAPInterface(sched);
296 TestAddingRemovingUsersNoData(sched);
297 TestSchedNewData(sched);
298
299 delete m_cSchedSapUser;
300 delete m_schedSapUser;
301}
302
303class NrTestSchedSuite : public TestSuite
304{
305 public:
306 NrTestSchedSuite()
307 : TestSuite("nr-test-sched", Type::SYSTEM)
308 {
309 AddTestCase(new NrSchedGeneralTestCase("ns3::NrMacSchedulerTdmaRR", "TdmaRR test"),
310 Duration::QUICK);
311 AddTestCase(new NrSchedGeneralTestCase("ns3::NrMacSchedulerTdmaPF", "TdmaPF test"),
312 Duration::QUICK);
313 AddTestCase(new NrSchedGeneralTestCase("ns3::NrMacSchedulerOfdmaRR", "OfdmaRR test"),
314 Duration::QUICK);
315 AddTestCase(new NrSchedGeneralTestCase("ns3::NrMacSchedulerOfdmaPF", "OfdmaPF test"),
316 Duration::QUICK);
317 }
318};
319
320static NrTestSchedSuite nrSchedTestSuite;
321
322} // namespace ns3
static NrTestSchedSuite nrSchedTestSuite
Nr scheduler test suite.