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 (std::vector<SSRecord*>::iterator iter = ssRecords->begin(); iter != ssRecords->end();
182 std::vector<ServiceFlow*> serviceFlows =
186 for (std::vector<ServiceFlow*>::iterator iter2 = serviceFlows.begin();
187 iter2 != serviceFlows.end();
229 bool allocationForDsa =
false;
237 std::vector<SSRecord*>* ssRecords =
GetBs()->GetSSManager()->GetSSRecords();
238 for (std::vector<SSRecord*>::iterator iter = ssRecords->begin(); iter != ssRecords->end();
257 allocationSize =
GetBs()->GetRangReqOppSize();
260 if (availableSymbols >= allocationSize)
274 ulMapIe.
SetUiuc(
GetBs()->GetBurstProfileManager()->GetBurstProfile(
284 if (!allocationForDsa)
287 GetBs()->GetPhy()->GetNrSymbols(
sizeof(
DsaReq), modulationType);
289 if (availableSymbols >= allocationSize)
295 allocationForDsa =
true;
314 if (availableSymbols)
322 <<
" offering be unicast polling");
324 Time frame_duration =
GetBs()->GetPhy()->GetFrameDuration();
328 ->GetLastGrantTime() +
331 ->GetUnsolicitedGrantInterval());
333 int64_t frame = ((timestamp -
Simulator::Now()) / frame_duration).GetHigh();
353 <<
" offering rtps unicast polling");
362 <<
" offering nrtps unicast polling");
372 <<
" offering be unicast polling");
385 uint32_t availableSymbolsAux = availableSymbols;
389 availableSymbolsAux -= symbolsUsed;
404 SSRecord* ssRecord = job->GetSsRecord();
412 GetBs()->GetBurstProfileManager()->GetBurstProfile(modulationType,
415 ReqType reqType = job->GetType();
426 else if (reqType ==
DATA)
429 uint32_t allocSizeBytes = job->GetSize();
449 SSRecord* ssRecord = job->GetSsRecord();
457 GetBs()->GetBurstProfileManager()->GetBurstProfile(modulationType,
460 ReqType reqType = job->GetType();
473 NS_FATAL_ERROR(
"Intermediate priority queue only should enqueue data packets.");
483 SSRecord* ssRecord = job->GetSsRecord();
491 GetBs()->GetBurstProfileManager()->GetBurstProfile(modulationType,
494 ReqType reqType = job->GetType();
507 NS_FATAL_ERROR(
"Low priority queue only should enqueue data packets.");
520 GetBs()->GetBandwidthManager()->SetSubframeRatio();
532 uint32_t allocSizeBytes = allocationSizeBytes;
539 if (requiredBandwidth > 0)
541 allocSizeSymbols =
GetBs()->GetPhy()->GetNrSymbols(allocSizeBytes, modulationType);
543 if (availableSymbols < allocSizeSymbols)
545 allocSizeSymbols = availableSymbols;
548 if (availableSymbols >= allocSizeSymbols)
552 <<
" allocation, size: " << allocSizeSymbols <<
" symbols"
554 <<
", SFID: " << serviceFlow->
GetSfid()
556 <<
", bw granted: " << allocSizeBytes << std::endl);
578 for (std::list<
Ptr<UlJob>>::iterator iter = jobs.begin(); iter != jobs.end(); ++iter)
594 job->SetSsRecord(ssRecord);
595 job->SetSchedulingType(schedType);
597 job->SetType(reqType);
604 SSRecord* ssRecord = job->GetSsRecord();
616 allocationSize =
GetBs()->GetBwReqOppSize();
626 if (requiredBandwidth > 0)
632 allocationSize =
GetBs()->GetPhy()->GetNrSymbols(sduSize, modulationType);
636 allocationSize =
GetBs()->GetPhy()->GetNrSymbols(requiredBandwidth, modulationType);
640 return allocationSize;
695 Time deadline = job->GetDeadline();
696 Time frame_duration =
GetBs()->GetPhy()->GetFrameDuration();
698 int64_t frame = ((deadline -
Simulator::Now()) / frame_duration).GetHigh();
701 << job->GetServiceFlow()->GetMinReservedTrafficRate()
702 <<
" deadline: " << job->GetDeadline().As(
Time::S)
703 <<
" frame start: " <<
GetBs()->m_frameStartTime.As(
Time::S)
704 <<
" frame duration: " << frame_duration);
709 if (availableSymbols)
712 GetBs()->GetPhy()->GetNrBytes(availableSymbols,
713 job->GetSsRecord()->GetModulationType());
714 uint32_t allocationSize = job->GetSize();
715 if (allocationSize > availableBytes)
717 allocationSize = availableBytes;
720 if (allocationSize == 0)
725 uint32_t symbolsToAllocate =
GetBs()->GetPhy()->GetNrSymbols(
727 job->GetSsRecord()->GetModulationType());
728 if (symbolsToAllocate > availableSymbols)
730 symbolsToAllocate = availableSymbols;
731 allocationSize =
GetBs()->GetPhy()->GetNrBytes(
733 job->GetSsRecord()->GetModulationType());
736 job->SetSize(job->GetSize() - allocationSize);
740 newJob->SetSsRecord(job->GetSsRecord());
741 newJob->SetServiceFlow(job->GetServiceFlow());
742 newJob->SetSize(allocationSize);
743 newJob->SetDeadline(job->GetDeadline());
744 newJob->SetReleaseTime(job->GetReleaseTime());
745 newJob->SetSchedulingType(job->GetSchedulingType());
746 newJob->SetPeriod(job->GetPeriod());
747 newJob->SetType(job->GetType());
753 if ((job->GetSize() - allocationSize) == 0)
775 std::list<Ptr<PriorityUlJob>> priorityUlJobs;
778 std::vector<SSRecord*>* ssRecords =
GetBs()->GetSSManager()->GetSSRecords();
779 for (std::vector<SSRecord*>::iterator iter = ssRecords->begin(); iter != ssRecords->end();
783 std::vector<ServiceFlow*> serviceFlows =
785 for (std::vector<ServiceFlow*>::iterator iter2 = serviceFlows.begin();
786 iter2 != serviceFlows.end();
817 priorityUlJob->SetUlJob(job);
819 if (minReservedTrafficRate <= grantedBandwidth)
821 priorityUlJob->SetPriority(-10000);
829 if (allocationSize > 0)
834 allocationSize = sduSize;
840 priorityUlJob->SetPriority(priority);
847 priorityUlJobs.push_back(priorityUlJob);
854 iter != priorityUlJobs.end();
858 Ptr<UlJob> job_priority = priorityUlJob->GetUlJob();
860 if (availableSymbols)
879 uint8_t uiuc = ulMapIe.
GetUiuc();
880 std::vector<ServiceFlow*> serviceFlows = ssRecord->
GetServiceFlows(schedulingType);
882 for (std::vector<ServiceFlow*>::iterator iter = serviceFlows.begin();
883 iter != serviceFlows.end();
894 GetBs()->GetBandwidthManager()->CalculateAllocationSize(ssRecord, serviceFlow);
896 if (availableSymbols < allocationSize)
901 if (allocationSize > 0)
918 NS_LOG_DEBUG(
"BS uplink scheduler, UGS allocation, size: " << allocationSize
924 <<
" unicast poll, size: " << allocationSize
926 <<
", modulation: BPSK 1/2");
930 <<
", SFID: " << serviceFlow->
GetSfid());
946 std::vector<ServiceFlow*> serviceFlows = ssRecord->
GetServiceFlows(schedulingType);
948 for (std::vector<ServiceFlow*>::iterator iter = serviceFlows.begin();
949 iter != serviceFlows.end();
974 uint16_t sduSize = 0;
980 if (requiredBandwidth > 0)
985 allocSizeBytes = sduSize;
986 allocSizeSymbols =
GetBs()->GetPhy()->GetNrSymbols(sduSize, modulationType);
990 allocSizeBytes = requiredBandwidth;
991 allocSizeSymbols =
GetBs()->GetPhy()->GetNrSymbols(requiredBandwidth, modulationType);
994 if (availableSymbols >= allocSizeSymbols)
998 <<
" allocation, size: " << allocSizeSymbols <<
" symbols"
1000 <<
", SFID: " << serviceFlow->
GetSfid()
1032 Time ssUlStartTime =
1040 if (timeSinceLastIrInterval +
GetBs()->GetPhy()->GetFrameDuration() >
1041 GetBs()->GetInitialRangingInterval() &&
1042 availableSymbols >= allocationSize)
1046 ulMapIeIr.
SetCid((
GetBs()->GetBroadcastConnection())->GetCid());
1050 NS_LOG_DEBUG(
"BS uplink scheduler, initial ranging allocation, size: "
1051 << allocationSize <<
" symbols"
1052 <<
", modulation: BPSK 1/2");
1057 GetBs()->MarkRangingOppStart(
1059 Seconds(symbolsToAllocation *
GetBs()->GetSymbolDuration().GetSeconds()) +
1061 GetBs()->GetSymbolDuration().GetSeconds()));
1072 uint8_t delayNrFrames = 1;
1076 (
uint32_t((
double)(bitsPerSecond)*
GetBs()->GetPhy()->GetFrameDuration().GetSeconds())) / 8;
1077 uint32_t frameDurationMSec =
GetBs()->GetPhy()->GetFrameDuration().GetMilliSeconds();
1090 uint32_t grantSize =
GetBs()->GetPhy()->GetNrSymbols(bytesPerFrame, modulation);
1095 if (toleratedJitter > frameDurationMSec)
1097 delayNrFrames = (uint8_t)(toleratedJitter / frameDurationMSec);
1100 uint16_t interval = delayNrFrames * frameDurationMSec;
1110 uint16_t interval = 1000;
1127 std::list<Ptr<PriorityUlJob>> priorityUlJobs;
1136 ServiceFlow* serviceFlowJob = job->GetServiceFlow();
1138 if (serviceFlowJob == serviceFlow)
1140 size += job->GetSize();
1152 GetBs()->GetConnectionManager()->GetConnection(bwRequestHdr.
GetCid());
1153 SSRecord* ssRecord =
GetBs()->GetSSManager()->GetSSRecord(connection->GetCid());
1154 ServiceFlow* serviceFlow = connection->GetServiceFlow();
1159 if (size > pendingSize)
1161 size -= pendingSize;
1175 const Time& period = deadline;
1178 <<
" at BS uplink scheduler, processing bandwidth request from."
1181 << deadline.
As(
Time::S) <<
" and size " << size <<
" aggreg size "
1182 << bwRequestHdr.
GetBr());
1185 job->SetSsRecord(ssRecord);
1186 job->SetServiceFlow(serviceFlow);
1188 job->SetDeadline(deadline);
1189 job->SetReleaseTime(currentTime);
1191 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.
AttributeValue implementation for Time.
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.
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
#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.
ReqType
Request type enumeration.
@ LOG_DEBUG
Full voluminous logging to support debugging.
SortProcessPtr structure.