30#include "ns3/simulator.h"
31#include "ns3/uinteger.h"
45 : m_windowInterval(time)
62 .SetGroupName(
"Wimax")
64 .AddAttribute(
"WindowInterval",
65 "The time to wait to reset window",
95 if (randNr % 5 == 0 ||
GetBs()->GetNrDcdSent() == 0)
101 if (randNr % 5 == 0 ||
GetBs()->GetNrUcdSent() == 0)
130 if (timeSinceLastDcd >
GetBs()->GetDcdInterval())
136 if (timeSinceLastUcd >
GetBs()->GetUcdInterval())
146 return GetBs()->GetNrDlSymbols() *
GetBs()->GetPhy()->GetPsPerSymbol() +
GetBs()->GetTtg();
158 symbolsToAllocation += allocationSize;
159 availableSymbols -= allocationSize;
169 if (!
GetBs()->GetSSManager())
175 std::vector<SSRecord*>* ssRecords =
GetBs()->GetSSManager()->GetSSRecords();
178 for (
auto iter = ssRecords->begin(); iter != ssRecords->end(); ++iter)
181 std::vector<ServiceFlow*> serviceFlows =
185 for (
auto iter2 = serviceFlows.begin(); iter2 != serviceFlows.end(); ++iter2)
226 bool allocationForDsa =
false;
234 std::vector<SSRecord*>* ssRecords =
GetBs()->GetSSManager()->GetSSRecords();
235 for (
auto iter = ssRecords->begin(); iter != ssRecords->end(); ++iter)
253 allocationSize =
GetBs()->GetRangReqOppSize();
256 if (availableSymbols >= allocationSize)
270 ulMapIe.
SetUiuc(
GetBs()->GetBurstProfileManager()->GetBurstProfile(
280 if (!allocationForDsa)
283 GetBs()->GetPhy()->GetNrSymbols(
sizeof(
DsaReq), modulationType);
285 if (availableSymbols >= allocationSize)
291 allocationForDsa =
true;
310 if (availableSymbols)
318 <<
" offering be unicast polling");
320 Time frame_duration =
GetBs()->GetPhy()->GetFrameDuration();
324 ->GetLastGrantTime() +
327 ->GetUnsolicitedGrantInterval());
329 int64_t frame = ((timestamp -
Simulator::Now()) / frame_duration).GetHigh();
349 <<
" offering rtps unicast polling");
358 <<
" offering nrtps unicast polling");
368 <<
" offering be unicast polling");
381 uint32_t availableSymbolsAux = availableSymbols;
385 availableSymbolsAux -= symbolsUsed;
400 SSRecord* ssRecord = job->GetSsRecord();
408 GetBs()->GetBurstProfileManager()->GetBurstProfile(modulationType,
411 ReqType reqType = job->GetType();
422 else if (reqType ==
DATA)
425 uint32_t allocSizeBytes = job->GetSize();
445 SSRecord* ssRecord = job->GetSsRecord();
453 GetBs()->GetBurstProfileManager()->GetBurstProfile(modulationType,
456 ReqType reqType = job->GetType();
469 NS_FATAL_ERROR(
"Intermediate priority queue only should enqueue data packets.");
479 SSRecord* ssRecord = job->GetSsRecord();
487 GetBs()->GetBurstProfileManager()->GetBurstProfile(modulationType,
490 ReqType reqType = job->GetType();
503 NS_FATAL_ERROR(
"Low priority queue only should enqueue data packets.");
516 GetBs()->GetBandwidthManager()->SetSubframeRatio();
528 uint32_t allocSizeBytes = allocationSizeBytes;
535 if (requiredBandwidth > 0)
537 allocSizeSymbols =
GetBs()->GetPhy()->GetNrSymbols(allocSizeBytes, modulationType);
539 if (availableSymbols < allocSizeSymbols)
541 allocSizeSymbols = availableSymbols;
544 if (availableSymbols >= allocSizeSymbols)
548 <<
" allocation, size: " << allocSizeSymbols <<
" symbols"
550 <<
", SFID: " << serviceFlow->
GetSfid()
552 <<
", bw granted: " << allocSizeBytes << std::endl);
574 for (
auto iter = jobs.begin(); iter != jobs.end(); ++iter)
590 job->SetSsRecord(ssRecord);
591 job->SetSchedulingType(schedType);
593 job->SetType(reqType);
600 SSRecord* ssRecord = job->GetSsRecord();
612 allocationSize =
GetBs()->GetBwReqOppSize();
622 if (requiredBandwidth > 0)
628 allocationSize =
GetBs()->GetPhy()->GetNrSymbols(sduSize, modulationType);
632 allocationSize =
GetBs()->GetPhy()->GetNrSymbols(requiredBandwidth, modulationType);
636 return allocationSize;
691 Time deadline = job->GetDeadline();
692 Time frame_duration =
GetBs()->GetPhy()->GetFrameDuration();
694 int64_t frame = ((deadline -
Simulator::Now()) / frame_duration).GetHigh();
697 << job->GetServiceFlow()->GetMinReservedTrafficRate()
698 <<
" deadline: " << job->GetDeadline().As(
Time::S)
699 <<
" frame start: " <<
GetBs()->m_frameStartTime.As(
Time::S)
700 <<
" frame duration: " << frame_duration);
705 if (availableSymbols)
708 GetBs()->GetPhy()->GetNrBytes(availableSymbols,
709 job->GetSsRecord()->GetModulationType());
710 uint32_t allocationSize = job->GetSize();
711 if (allocationSize > availableBytes)
713 allocationSize = availableBytes;
716 if (allocationSize == 0)
721 uint32_t symbolsToAllocate =
GetBs()->GetPhy()->GetNrSymbols(
723 job->GetSsRecord()->GetModulationType());
724 if (symbolsToAllocate > availableSymbols)
726 symbolsToAllocate = availableSymbols;
727 allocationSize =
GetBs()->GetPhy()->GetNrBytes(
729 job->GetSsRecord()->GetModulationType());
732 job->SetSize(job->GetSize() - allocationSize);
736 newJob->SetSsRecord(job->GetSsRecord());
737 newJob->SetServiceFlow(job->GetServiceFlow());
738 newJob->SetSize(allocationSize);
739 newJob->SetDeadline(job->GetDeadline());
740 newJob->SetReleaseTime(job->GetReleaseTime());
741 newJob->SetSchedulingType(job->GetSchedulingType());
742 newJob->SetPeriod(job->GetPeriod());
743 newJob->SetType(job->GetType());
749 if ((job->GetSize() - allocationSize) == 0)
771 std::list<Ptr<PriorityUlJob>> priorityUlJobs;
774 std::vector<SSRecord*>* ssRecords =
GetBs()->GetSSManager()->GetSSRecords();
775 for (
auto iter = ssRecords->begin(); iter != ssRecords->end(); ++iter)
778 std::vector<ServiceFlow*> serviceFlows =
780 for (
auto iter2 = serviceFlows.begin(); iter2 != serviceFlows.end(); ++iter2)
808 priorityUlJob->SetUlJob(job);
810 if (minReservedTrafficRate <= grantedBandwidth)
812 priorityUlJob->SetPriority(-10000);
820 if (allocationSize > 0)
825 allocationSize = sduSize;
831 priorityUlJob->SetPriority(priority);
838 priorityUlJobs.push_back(priorityUlJob);
844 for (
auto iter = priorityUlJobs.begin(); iter != priorityUlJobs.end(); ++iter)
847 Ptr<UlJob> job_priority = priorityUlJob->GetUlJob();
849 if (availableSymbols)
868 uint8_t uiuc = ulMapIe.
GetUiuc();
869 std::vector<ServiceFlow*> serviceFlows = ssRecord->
GetServiceFlows(schedulingType);
871 for (
auto iter = serviceFlows.begin(); iter != serviceFlows.end(); ++iter)
881 GetBs()->GetBandwidthManager()->CalculateAllocationSize(ssRecord, serviceFlow);
883 if (availableSymbols < allocationSize)
888 if (allocationSize > 0)
905 NS_LOG_DEBUG(
"BS uplink scheduler, UGS allocation, size: " << allocationSize
911 <<
" unicast poll, size: " << allocationSize
913 <<
", modulation: BPSK 1/2");
917 <<
", SFID: " << serviceFlow->
GetSfid());
933 std::vector<ServiceFlow*> serviceFlows = ssRecord->
GetServiceFlows(schedulingType);
935 for (
auto iter = serviceFlows.begin(); iter != serviceFlows.end(); ++iter)
959 uint16_t sduSize = 0;
965 if (requiredBandwidth > 0)
970 allocSizeBytes = sduSize;
971 allocSizeSymbols =
GetBs()->GetPhy()->GetNrSymbols(sduSize, modulationType);
975 allocSizeBytes = requiredBandwidth;
976 allocSizeSymbols =
GetBs()->GetPhy()->GetNrSymbols(requiredBandwidth, modulationType);
979 if (availableSymbols >= allocSizeSymbols)
983 <<
" allocation, size: " << allocSizeSymbols <<
" symbols"
985 <<
", SFID: " << serviceFlow->
GetSfid()
1017 Time ssUlStartTime =
1025 if (timeSinceLastIrInterval +
GetBs()->GetPhy()->GetFrameDuration() >
1026 GetBs()->GetInitialRangingInterval() &&
1027 availableSymbols >= allocationSize)
1031 ulMapIeIr.
SetCid((
GetBs()->GetBroadcastConnection())->GetCid());
1035 NS_LOG_DEBUG(
"BS uplink scheduler, initial ranging allocation, size: "
1036 << allocationSize <<
" symbols"
1037 <<
", modulation: BPSK 1/2");
1042 GetBs()->MarkRangingOppStart(
1044 Seconds(symbolsToAllocation *
GetBs()->GetSymbolDuration().GetSeconds()) +
1046 GetBs()->GetSymbolDuration().GetSeconds()));
1057 uint8_t delayNrFrames = 1;
1061 (
uint32_t((
double)(bitsPerSecond)*
GetBs()->GetPhy()->GetFrameDuration().GetSeconds())) / 8;
1062 uint32_t frameDurationMSec =
GetBs()->GetPhy()->GetFrameDuration().GetMilliSeconds();
1075 uint32_t grantSize =
GetBs()->GetPhy()->GetNrSymbols(bytesPerFrame, modulation);
1080 if (toleratedJitter > frameDurationMSec)
1082 delayNrFrames = (uint8_t)(toleratedJitter / frameDurationMSec);
1085 uint16_t interval = delayNrFrames * frameDurationMSec;
1095 uint16_t interval = 1000;
1112 std::list<Ptr<PriorityUlJob>> priorityUlJobs;
1119 ServiceFlow* serviceFlowJob = job->GetServiceFlow();
1121 if (serviceFlowJob == serviceFlow)
1123 size += job->GetSize();
1135 GetBs()->GetConnectionManager()->GetConnection(bwRequestHdr.
GetCid());
1136 SSRecord* ssRecord =
GetBs()->GetSSManager()->GetSSRecord(connection->GetCid());
1137 ServiceFlow* serviceFlow = connection->GetServiceFlow();
1142 if (size > pendingSize)
1144 size -= pendingSize;
1158 const Time& period = deadline;
1161 <<
" at BS uplink scheduler, processing bandwidth request from."
1164 << deadline.
As(
Time::S) <<
" and size " << size <<
" aggreg size "
1165 << bwRequestHdr.
GetBr());
1168 job->SetSsRecord(ssRecord);
1169 job->SetServiceFlow(serviceFlow);
1171 job->SetDeadline(deadline);
1172 job->SetReleaseTime(currentTime);
1174 job->SetPeriod(period);
This class implements the bandwidth-request mac Header as described by IEEE Standard for Local and me...
uint32_t GetBr() const
Get BR field.
Cid GetCid() const
Get CID field.
This class implements the DSA-REQ message described by "IEEE Standard for Local and metropolitan area...
This class implements the UL-MAP_IE message as described by "IEEE Standard for Local and metropolitan...
void SetStartTime(uint16_t startTime)
Set start time.
uint8_t GetUiuc() const
Get UIUC.
void SetDuration(uint16_t duration)
Set duration.
void SetCid(const Cid &cid)
Set CID.
void SetUiuc(uint8_t uiuc)
Set UIUC.
Smart pointer class similar to boost::intrusive_ptr.
This class is used by the base station to store some information related to subscriber station in the...
bool GetHasServiceFlowUgs() const
Check if at least one flow has scheduling type SF_TYPE_UGS.
Cid GetBasicCid() const
Get basic CID.
WimaxNetDevice::RangingStatus GetRangingStatus() const
Get ranging status.
bool GetPollForRanging() const
Get poll for ranging.
bool GetHasServiceFlowRtps() const
Check if at least one flow has scheduling type SF_TYPE_RTPS.
std::vector< ServiceFlow * > GetServiceFlows(ServiceFlow::SchedulingType schedulingType) const
Get service flows.
bool GetAreServiceFlowsAllocated() const
Check if service flows are allocated.
Mac48Address GetMacAddress() const
Get MAC address.
bool GetIsBroadcastSS() const
Get is broadcast SS.
WimaxPhy::ModulationType GetModulationType() const
Get modulation type.
bool GetHasServiceFlowNrtps() const
Check if at least one flow has scheduling type SF_TYPE_NRTPS.
bool GetHasServiceFlowBe() const
Check if at least one flow has scheduling type SF_TYPE_BE.
This class implements service flows as described by the IEEE-802.16 standard.
uint32_t GetSfid() const
Get SFID.
uint32_t GetMaximumLatency() const
Get maximum latency.
ServiceFlow::SchedulingType GetSchedulingType() const
Get scheduling type.
uint16_t GetUnsolicitedPollingInterval() const
Get unsolicited polling interval.
SchedulingType
section 11.13.11 Service flow scheduling type, page 701
char * GetSchedulingTypeStr() const
Get scheduling type string.
uint32_t GetMinReservedTrafficRate() const
Get minimum reserved traffic rate.
uint8_t GetSduSize() const
Get SDU size.
WimaxPhy::ModulationType GetModulation() const
Get modulation.
void SetUnsolicitedGrantInterval(uint16_t unsolicitedGrantInterval)
Set unsolicited grant interval.
ServiceFlowRecord * GetRecord() const
Get service flow record.
void SetUnsolicitedPollingInterval(uint16_t unsolicitedPollingInterval)
Set unsolicited polling interval.
bool GetIsMulticast() const
Get is multicast.
uint32_t GetToleratedJitter() const
Get tolerated jitter.
Ptr< WimaxConnection > GetConnection() const
Can return a null connection is this service flow has not been associated yet to a connection.
this class implements a structure to manage some parameters and statistics related to a service flow
Time GetGrantTimeStamp() const
uint32_t GetBacklogged() const
void UpdateRequestedBandwidth(uint32_t requestedBandwidth)
update the requested bandwidth
void UpdateGrantedBandwidthTemp(uint32_t grantedBandwidthTemp)
update the temporary granted bandwidth
uint32_t GetRequestedBandwidth() const
Time GetLastGrantTime() const
void IncreaseBacklogged(uint32_t backlogged)
increase backlogged
uint32_t GetBackloggedTemp() const
void SetBackloggedTemp(uint32_t backloggedTemp)
set temporary back logged
uint32_t GetGrantedBandwidthTemp() const
void SetGrantSize(uint32_t grantSize)
Set the grant size (only for UGS service flows)
uint32_t GetGrantedBandwidth() const
void SetGrantedBandwidthTemp(uint32_t grantedBandwidthTemp)
set the temporary granted bandwidth
void SetBwSinceLastExpiry(uint32_t bwSinceLastExpiry)
set BW since last expiry
void UpdateGrantedBandwidth(uint32_t grantedBandwidth)
update the granted bandwidth
void UpdateBwSinceLastExpiry(uint32_t bwSinceLastExpiry)
update BW since last expiry
void SetBacklogged(uint32_t backlogged)
set backlogged
uint32_t GetBwSinceLastExpiry() const
void SetLastGrantTime(Time grantTime)
set last grant time
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now()
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
JobPriority
Job priority enumeration.
Virtual class for uplink scheduler.
virtual void SetUcdTimeStamp(Time ucdTimeStamp)
Set UCD timestamp.
virtual void SetDcdTimeStamp(Time dcdTimeStamp)
Set DCD timestamp.
virtual void SetNrIrOppsAllocated(uint8_t nrIrOppsAllocated)
Set the number of IR opps allocated.
virtual void SetBs(Ptr< BaseStationNetDevice > bs)
Set base station device.
virtual void SetIsIrIntrvlAllocated(bool isIrIntrvlAllocated)
Set if the IR interval is allocated.
virtual uint8_t GetNrIrOppsAllocated() const
virtual void SetIsInvIrIntrvlAllocated(bool isInvIrIntrvlAllocated)
Set if the Inv IR interval is allocated.
virtual Time GetTimeStampIrInterval()
virtual Time GetDcdTimeStamp() const
virtual void SetTimeStampIrInterval(Time timeStampIrInterval)
Set timestamp IR interval.
virtual Ptr< BaseStationNetDevice > GetBs()
virtual Time GetUcdTimeStamp() const
void InitOnce() override
This method is called once to initialize window.
uint32_t CountSymbolsQueue(std::list< Ptr< UlJob > > jobs)
~UplinkSchedulerMBQoS() override
Ptr< UlJob > CreateUlJob(SSRecord *ssRecord, ServiceFlow::SchedulingType schedType, ReqType reqType)
void CheckDeadline(uint32_t &availableSymbols)
Check deadline from jobs. Migrate requests if necessary.
void OnSetRequestedBandwidth(ServiceFlowRecord *sfr) override
Set requested bandwidth.
std::list< Ptr< UlJob > > m_uplinkJobs_inter
uplink jobs intermedite priority
std::list< Ptr< UlJob > > m_uplinkJobs_low
uplink jobs low priority
bool ServiceBandwidthRequestsBytes(ServiceFlow *serviceFlow, ServiceFlow::SchedulingType schedulingType, OfdmUlMapIe &ulMapIe, const WimaxPhy::ModulationType modulationType, uint32_t &symbolsToAllocation, uint32_t &availableSymbols, uint32_t allocationSizeBytes)
Service bandwidth requests bytes.
std::list< OfdmUlMapIe > GetUplinkAllocations() const override
Get uplink allocations.
uint32_t CountSymbolsJobs(Ptr< UlJob > job)
void GetChannelDescriptorsToUpdate(bool &updateDcd, bool &updateUcd, bool &sendDcd, bool &sendUcd) override
Determines if channel descriptors sent in the current frame are required to be updated.
void ServiceUnsolicitedGrants(const SSRecord *ssRecord, ServiceFlow::SchedulingType schedulingType, OfdmUlMapIe &ulMapIe, const WimaxPhy::ModulationType modulationType, uint32_t &symbolsToAllocation, uint32_t &availableSymbols) override
Service unsolicited grants.
Time m_windowInterval
windows interval
void ProcessBandwidthRequest(const BandwidthRequestHeader &bwRequestHdr) override
Process bandwidth request function.
void AllocateInitialRangingInterval(uint32_t &symbolsToAllocation, uint32_t &availableSymbols) override
Allocate initial ranging interval.
void ServiceBandwidthRequests(const SSRecord *ssRecord, ServiceFlow::SchedulingType schedulingType, OfdmUlMapIe &ulMapIe, const WimaxPhy::ModulationType modulationType, uint32_t &symbolsToAllocation, uint32_t &availableSymbols) override
Service bandwidth requests.
Ptr< UlJob > DequeueJob(UlJob::JobPriority priority)
Dequeue a job from a priority queue.
uint32_t CalculateAllocationStartTime() override
Calculate allocation start time.
void Schedule() override
Schedule function.
std::list< Ptr< UlJob > > m_uplinkJobs_high
uplink jobs high priority
uint32_t GetPendingSize(ServiceFlow *serviceFlow)
void EnqueueJob(UlJob::JobPriority priority, Ptr< UlJob > job)
Enqueue a job in a priority queue.
Time DetermineDeadline(ServiceFlow *serviceFlow)
Calculates deadline of a request.
static TypeId GetTypeId()
Get the type ID.
void CheckMinimumBandwidth(uint32_t &availableSymbols)
Check if Minimum bandwidth is guarantee. Migrate requests if necessary.
void UplinkSchedWindowTimer()
Reset the current window.
void SetupServiceFlow(SSRecord *ssRecord, ServiceFlow *serviceFlow) override
Setup service flow.
void AddUplinkAllocation(OfdmUlMapIe &ulMapIe, const uint32_t &allocationSize, uint32_t &symbolsToAllocation, uint32_t &availableSymbols) override
Add uplink allocation.
std::list< OfdmUlMapIe > m_uplinkAllocations
uplink allocations
@ RANGING_STATUS_CONTINUE
ModulationType
ModulationType enumeration.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG(level, msg)
This macro allows you to log an arbitrary message at a specific log level.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time Seconds(double value)
Construct a Time in the indicated unit.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
ReqType
Request type enumeration.
@ LOG_DEBUG
Full voluminous logging to support debugging.
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
SortProcessPtr structure.