5#include "nr-mac-scheduler-srs-default.h"
7#include "ns3/shuffle.h"
8#include "ns3/uinteger.h"
15NS_LOG_COMPONENT_DEFINE(
"NrMacSchedulerSrsDefault");
16NS_OBJECT_ENSURE_REGISTERED(NrMacSchedulerSrsDefault);
18std::vector<uint32_t> NrMacSchedulerSrsDefault::StandardPeriodicity =
19 {2, 4, 5, 8, 10, 16, 20, 32, 40, 64, 80, 160, 320, 640, 1280, 2560};
23 m_random = CreateObject<UniformRandomVariable>();
29 NS_LOG_FUNCTION(
this << stream);
30 m_random->SetStream(stream);
42 TypeId(
"ns3::NrMacSchedulerSrsDefault")
44 .AddConstructor<NrMacSchedulerSrsDefault>()
46 .AddAttribute(
"StartingPeriodicity",
47 "Starting value for the periodicity",
51 MakeUintegerChecker<uint32_t>());
58 NS_LOG_FUNCTION(
this);
61 if (m_availableOffsetValues.empty())
66 ret.
m_offset = m_availableOffsetValues.back();
70 m_availableOffsetValues.pop_back();
77 NS_LOG_FUNCTION(
this);
78 m_availableOffsetValues.push_back(offset);
83 std::unordered_map<uint16_t, std::shared_ptr<NrMacSchedulerUeInfo>>* ueMap)
85 NS_LOG_FUNCTION(
this);
87 m_availableOffsetValues.clear();
89 std::upper_bound(StandardPeriodicity.begin(), StandardPeriodicity.end(), m_periodicity);
90 if (it == StandardPeriodicity.end())
96 ReassignSrsValue(ueMap);
103 std::unordered_map<uint16_t, std::shared_ptr<NrMacSchedulerUeInfo>>* ueMap)
105 NS_LOG_FUNCTION(
this);
107 m_availableOffsetValues.clear();
109 std::lower_bound(StandardPeriodicity.begin(), StandardPeriodicity.end(), m_periodicity);
110 if (it == StandardPeriodicity.end())
116 ReassignSrsValue(ueMap);
123 NS_ABORT_MSG_IF(!m_availableOffsetValues.empty(),
124 "We already started giving offset to UEs, you cannot alter the periodicity");
126 if (std::find(StandardPeriodicity.begin(), StandardPeriodicity.end(), start) ==
127 StandardPeriodicity.end())
129 NS_FATAL_ERROR(
"You cannot use "
131 <<
" as periodicity; please use a standard value like "
132 "2, 4, 5, 8, 10, 16, 20, 32, 40, 64, 80, 160, 320, 640, 1280, 2560"
133 " (or write your own algorithm)");
136 m_periodicity = start;
137 m_availableOffsetValues.resize(m_periodicity);
140 for (uint32_t i = 0; i < m_periodicity; ++i)
142 m_availableOffsetValues[i] = i;
146 if (m_shuffleEventId.IsPending())
148 NS_LOG_DEBUG(
"Canceling previously scheduled shuffle");
149 m_shuffleEventId.Cancel();
151 m_shuffleEventId = Simulator::ScheduleNow(&NrMacSchedulerSrsDefault::ShuffleOffsets,
this);
157 return m_periodicity;
161NrMacSchedulerSrsDefault::ShuffleOffsets()
163 NS_LOG_FUNCTION(
this);
165 Shuffle(m_availableOffsetValues.begin(), m_availableOffsetValues.end(), m_random);
169NrMacSchedulerSrsDefault::ReassignSrsValue(
170 std::unordered_map<uint16_t, std::shared_ptr<NrMacSchedulerUeInfo>>* ueMap)
172 NS_LOG_FUNCTION(
this);
174 for (
auto& ue : *ueMap)
178 NS_ASSERT(srs.m_isValid);
180 ue.second->m_srsPeriodicity = srs.m_periodicity;
181 ue.second->m_srsOffset = srs.m_offset;
189 return m_periodicity == StandardPeriodicity.back() && m_availableOffsetValues.empty();
static TypeId GetTypeId()
GetTypeId.
bool IncreasePeriodicity(std::unordered_map< uint16_t, std::shared_ptr< NrMacSchedulerUeInfo > > *ueMap) override
Increase the periodicity and assign to all UEs a different offset.
bool DecreasePeriodicity(std::unordered_map< uint16_t, std::shared_ptr< NrMacSchedulerUeInfo > > *ueMap) override
Decrease the periodicity and assign to all UEs a different offset.
int64_t AssignStreams(int64_t stream)
bool IsMaxSrsReached() const override
Check if all SRS periodicity is at the maximum allowed and all offsets have been used.
uint32_t GetStartingPeriodicity() const
Get the periodicity.
SrsPeriodicityAndOffset AddUe() override
Function called when the scheduler needs to know what is the offset and periodicy of a newly added ue...
~NrMacSchedulerSrsDefault() override
~NrMacSchedulerSrsDefault
NrMacSchedulerSrsDefault()
NrMacSchedulerSrsDefault.
void SetStartingPeriodicity(uint32_t start)
Set the Periodicity for all the UEs.
void RemoveUe(uint32_t offset) override
Function called when the scheduler has to release a previously owned periodicity and offset.
Struct to indicate to the scheduler the periodicity and the offset, in slots.
uint32_t m_periodicity
The periodicity requested (in slot).
uint32_t m_offset
The offset requested (in slot).
bool m_isValid
Indicates if the values are valid.