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