5#include <ns3/nr-mac-sched-sap.h>
6#include <ns3/nr-mac-scheduler-ns3.h>
7#include <ns3/object-factory.h>
30class TestCschedSapUser :
public NrMacCschedSapUser
34 : NrMacCschedSapUser()
38 void CschedCellConfigCnf(
39 [[maybe_unused]]
const struct CschedCellConfigCnfParameters& params)
override
43 void CschedUeConfigCnf(
44 [[maybe_unused]]
const struct CschedUeConfigCnfParameters& params)
override
48 void CschedLcConfigCnf(
49 [[maybe_unused]]
const struct CschedLcConfigCnfParameters& params)
override
53 void CschedLcReleaseCnf(
54 [[maybe_unused]]
const struct CschedLcReleaseCnfParameters& params)
override
58 void CschedUeReleaseCnf(
59 [[maybe_unused]]
const struct CschedUeReleaseCnfParameters& params)
override
63 void CschedUeConfigUpdateInd(
64 [[maybe_unused]]
const struct CschedUeConfigUpdateIndParameters& params)
override
68 void CschedCellConfigUpdateInd(
69 [[maybe_unused]]
const struct CschedCellConfigUpdateIndParameters& params)
override
74class TestSchedSapUser;
79class NrSchedGeneralTestCase :
public TestCase
87 NrSchedGeneralTestCase(
const std::string& scheduler,
const std::string& name)
89 m_scheduler(scheduler)
96 ~NrSchedGeneralTestCase()
override
100 void SchedConfigInd(
const struct NrMacSchedSapUser::SchedConfigIndParameters& params);
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);
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);
117 void DoRun()
override;
119 std::string m_scheduler{};
120 TestCschedSapUser* m_cSchedSapUser{
nullptr};
121 TestSchedSapUser* m_schedSapUser{
nullptr};
124class TestSchedSapUser :
public NrMacSchedSapUser
127 TestSchedSapUser(NrSchedGeneralTestCase* testCase)
128 : NrMacSchedSapUser(),
133 void SchedConfigInd(
const struct SchedConfigIndParameters& params)
override
135 m_testCase->SchedConfigInd(params);
140 Ptr<const SpectrumModel> GetSpectrumModel()
const override
145 uint32_t GetNumRbPerRbg()
const override
150 uint8_t GetNumHarqProcess()
const override
155 uint16_t GetBwpId()
const override
160 uint16_t GetCellId()
const override
165 uint32_t GetSymbolsPerSlot()
const override
170 Time GetSlotPeriod()
const override
172 return MilliSeconds(1);
175 void BuildRarList(SlotAllocInfo& allocInfo)
override
180 NrSchedGeneralTestCase* m_testCase;
184NrSchedGeneralTestCase::TestSAPInterface(
const Ptr<NrMacScheduler>& sched)
186 NS_ABORT_IF(sched->GetMacSchedSapProvider() ==
nullptr);
187 NS_ABORT_IF(sched->GetMacCschedSapProvider() ==
nullptr);
188 sched->SetMacCschedSapUser(m_cSchedSapUser);
189 sched->SetMacSchedSapUser(m_schedSapUser);
193NrSchedGeneralTestCase::SchedConfigInd(
194 [[maybe_unused]]
const struct NrMacSchedSapUser::SchedConfigIndParameters& params)
199NrSchedGeneralTestCase::AddOneUser(uint16_t rnti,
const Ptr<NrMacSchedulerNs3>& sched)
201 NrMacCschedSapProvider::CschedUeConfigReqParameters params;
202 params.m_rnti = rnti;
203 params.m_beamId = BeamId(8, 120.0);
204 sched->DoCschedUeConfigReq(params);
208NrSchedGeneralTestCase::TestingAddingUsers(
const Ptr<NrMacSchedulerNs3>& sched)
210 for (uint16_t i = 0; i < 80; ++i)
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");
220NrSchedGeneralTestCase::TestingRemovingUsers(
const Ptr<NrMacSchedulerNs3>& sched)
222 for (uint16_t i = 80; i > 0; --i)
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);
235NrSchedGeneralTestCase::TestAddingRemovingUsersNoData(
const Ptr<NrMacSchedulerNs3>& sched)
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(),
242 sched->m_ueMap.size() <<
" UEs are still in the map");
246NrSchedGeneralTestCase::TestSchedNewData(
const Ptr<NrMacSchedulerNs3>& sched)
248 TestSchedNewDlData(sched);
249 TestSchedNewUlData(sched);
250 TestSchedNewDlUlData(sched);
254NrSchedGeneralTestCase::LcConfigFor(uint16_t rnti,
256 const Ptr<NrMacSchedulerNs3>& sched)
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);
264 sched->DoCschedLcConfigReq(params);
268NrSchedGeneralTestCase::TestSchedNewDlData(
const Ptr<NrMacSchedulerNs3>& sched)
271 TestingAddingUsers(sched);
275NrSchedGeneralTestCase::TestSchedNewUlData(
const Ptr<NrMacSchedulerNs3>& sched)
280NrSchedGeneralTestCase::TestSchedNewDlUlData(
const Ptr<NrMacSchedulerNs3>& sched)
285NrSchedGeneralTestCase::DoRun()
287 m_cSchedSapUser =
new TestCschedSapUser();
288 m_schedSapUser =
new TestSchedSapUser(
this);
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);
295 TestSAPInterface(sched);
296 TestAddingRemovingUsersNoData(sched);
297 TestSchedNewData(sched);
299 delete m_cSchedSapUser;
300 delete m_schedSapUser;
303class NrTestSchedSuite :
public TestSuite
307 : TestSuite(
"nr-test-sched", Type::SYSTEM)
309 AddTestCase(
new NrSchedGeneralTestCase(
"ns3::NrMacSchedulerTdmaRR",
"TdmaRR test"),
311 AddTestCase(
new NrSchedGeneralTestCase(
"ns3::NrMacSchedulerTdmaPF",
"TdmaPF test"),
313 AddTestCase(
new NrSchedGeneralTestCase(
"ns3::NrMacSchedulerOfdmaRR",
"OfdmaRR test"),
315 AddTestCase(
new NrSchedGeneralTestCase(
"ns3::NrMacSchedulerOfdmaPF",
"OfdmaPF test"),
static NrTestSchedSuite nrSchedTestSuite
Nr scheduler test suite.