20 #include "ns3/simulator.h"
25 #include "ns3/uinteger.h"
43 : m_windowInterval (time)
61 .SetGroupName(
"Wimax")
63 .AddAttribute (
"WindowInterval",
64 "The time to wait to reset window",
77 std::list<OfdmUlMapIe>
93 uint32_t randNr = rand ();
94 if (randNr % 5 == 0 ||
GetBs ()->GetNrDcdSent () == 0)
100 if (randNr % 5 == 0 ||
GetBs ()->GetNrUcdSent () == 0)
129 if (timeSinceLastDcd >
GetBs ()->GetDcdInterval ())
135 if (timeSinceLastUcd >
GetBs ()->GetUcdInterval ())
145 return GetBs ()->GetNrDlSymbols () *
GetBs ()->GetPhy ()->GetPsPerSymbol () +
GetBs ()->GetTtg ();
150 const uint32_t &allocationSize,
151 uint32_t &symbolsToAllocation,
152 uint32_t &availableSymbols)
157 symbolsToAllocation += allocationSize;
158 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 (); ++iter)
184 for (std::vector<ServiceFlow*>::iterator iter2 = serviceFlows.begin (); iter2 != serviceFlows.end (); ++iter2)
223 bool allocationForDsa =
false;
225 uint32_t symbolsToAllocation = 0;
226 uint32_t allocationSize = 0;
227 uint32_t availableSymbols =
GetBs ()->GetNrUlSymbols ();
231 std::vector<SSRecord*> *ssRecords =
GetBs ()->GetSSManager ()->GetSSRecords ();
232 for (std::vector<SSRecord*>::iterator iter = ssRecords->begin (); iter != ssRecords->end (); ++iter)
249 allocationSize =
GetBs ()->GetRangReqOppSize ();
252 if (availableSymbols >= allocationSize)
266 ulMapIe.
SetUiuc (
GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
276 if (!allocationForDsa)
278 allocationSize =
GetBs ()->GetPhy ()->GetNrSymbols (
sizeof(
DsaReq), modulationType);
280 if (availableSymbols >= allocationSize)
283 allocationForDsa =
true;
301 if (availableSymbols)
309 Time frame_duration =
GetBs ()->GetPhy ()->GetFrameDuration ();
315 int64_t frame = ((timestamp -
Simulator::Now ()) / frame_duration).GetHigh ();
359 uint32_t availableSymbolsAux = availableSymbols;
360 uint32_t symbolsUsed = 0;
363 availableSymbolsAux -= symbolsUsed;
378 SSRecord * ssRecord = job->GetSsRecord ();
385 ulMapIe.
SetUiuc (
GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
388 ReqType reqType = job->GetType ();
399 else if (reqType ==
DATA)
402 uint32_t allocSizeBytes = job->GetSize ();
421 SSRecord * ssRecord = job->GetSsRecord ();
428 ulMapIe.
SetUiuc (
GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
431 ReqType reqType = job->GetType ();
444 NS_FATAL_ERROR (
"Intermediate priority queue only should enqueue data packets.");
455 SSRecord * ssRecord = job->GetSsRecord ();
462 ulMapIe.
SetUiuc (
GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
465 ReqType reqType = job->GetType ();
478 NS_FATAL_ERROR (
"Low priority queue only should enqueue data packets.");
491 GetBs ()->GetBandwidthManager ()->SetSubframeRatio ();
497 uint32_t &symbolsToAllocation, uint32_t &availableSymbols, uint32_t allocationSizeBytes)
499 uint32_t allocSizeBytes = allocationSizeBytes;
500 uint32_t allocSizeSymbols = 0;
506 if (requiredBandwidth > 0)
508 allocSizeSymbols =
GetBs ()->GetPhy ()->GetNrSymbols (allocSizeBytes, modulationType);
510 if (availableSymbols < allocSizeSymbols)
512 allocSizeSymbols = availableSymbols;
515 if (availableSymbols >= allocSizeSymbols)
520 <<
" allocation, size: " << allocSizeSymbols <<
" symbols"
523 <<
", SFID: " << serviceFlow->
GetSfid ()
525 <<
", bw granted: " << allocSizeBytes
548 uint32_t symbols = 0;
563 job->SetSsRecord (ssRecord);
564 job->SetSchedulingType (schedType);
565 job->SetServiceFlow (*(ssRecord->
GetServiceFlows (schedType).begin ()));
566 job->SetType (reqType);
573 SSRecord *ssRecord = job->GetSsRecord ();
575 uint32_t allocationSize = 0;
585 allocationSize =
GetBs ()->GetBwReqOppSize ();
591 uint16_t sduSize = serviceFlow->
GetSduSize ();
594 if (requiredBandwidth > 0)
600 allocationSize =
GetBs ()->GetPhy ()->GetNrSymbols (sduSize, modulationType);
604 allocationSize =
GetBs ()->GetPhy ()->GetNrSymbols (requiredBandwidth, modulationType);
608 return allocationSize;
663 Time deadline = job->GetDeadline ();
664 Time frame_duration =
GetBs ()->GetPhy ()->GetFrameDuration ();
666 int64_t frame = ((deadline -
Simulator::Now ()) / frame_duration).GetHigh ();
669 << job->GetServiceFlow ()->GetMinReservedTrafficRate ()
670 <<
" deadline: "<<job->GetDeadline ().As (
Time::S) <<
" frame start: "<<
GetBs ()->m_frameStartTime.As (
Time::S)
671 <<
" frame duration: "<< frame_duration );
677 if (availableSymbols)
679 uint32_t availableBytes =
GetBs ()->GetPhy ()->GetNrBytes (availableSymbols,job->GetSsRecord ()->GetModulationType ());
680 uint32_t allocationSize = job->GetSize ();
681 if (allocationSize > availableBytes)
683 allocationSize = availableBytes;
687 if (allocationSize == 0)
692 uint32_t symbolsToAllocate =
GetBs ()->GetPhy ()->GetNrSymbols (allocationSize, job->GetSsRecord ()->GetModulationType ());
693 if (symbolsToAllocate > availableSymbols)
695 symbolsToAllocate = availableSymbols;
696 allocationSize =
GetBs ()->GetPhy ()->GetNrBytes (symbolsToAllocate,job->GetSsRecord ()->GetModulationType ());
699 job->SetSize (job->GetSize () - allocationSize);
703 newJob->SetSsRecord (job->GetSsRecord ());
704 newJob->SetServiceFlow (job->GetServiceFlow ());
705 newJob->SetSize (allocationSize);
706 newJob->SetDeadline (job->GetDeadline ());
707 newJob->SetReleaseTime (job->GetReleaseTime ());
708 newJob->SetSchedulingType (job->GetSchedulingType ());
709 newJob->SetPeriod (job->GetPeriod ());
710 newJob->SetType (job->GetType ());
716 if ((job->GetSize () - allocationSize) == 0)
739 std::list<Ptr<PriorityUlJob> > priorityUlJobs;
742 std::vector<SSRecord*> *ssRecords =
GetBs ()->GetSSManager ()->GetSSRecords ();
743 for (std::vector<SSRecord*>::iterator iter = ssRecords->begin (); iter != ssRecords->end (); ++iter)
747 for (std::vector<ServiceFlow*>::iterator iter2 = serviceFlows.begin (); iter2 != serviceFlows.end (); ++iter2)
772 priorityUlJob->SetUlJob (job);
774 if (minReservedTrafficRate <= grantedBandwidth)
776 priorityUlJob->SetPriority (-10000);
782 uint32_t sduSize = serviceFlow->
GetSduSize ();
784 if (allocationSize > 0)
789 allocationSize = sduSize;
794 priorityUlJob->SetPriority (priority);
801 priorityUlJobs.push_back (priorityUlJob);
810 Ptr<UlJob> job_priority = priorityUlJob->GetUlJob ();
812 if (availableSymbols)
827 uint32_t &symbolsToAllocation,
828 uint32_t &availableSymbols)
830 uint32_t allocationSize = 0;
831 uint8_t uiuc = ulMapIe.
GetUiuc ();
832 std::vector<ServiceFlow*> serviceFlows = ssRecord->
GetServiceFlows (schedulingType);
834 for (std::vector<ServiceFlow*>::iterator iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
842 allocationSize =
GetBs ()->GetBandwidthManager ()->CalculateAllocationSize (ssRecord, serviceFlow);
844 if (availableSymbols < allocationSize)
849 if (allocationSize > 0)
865 NS_LOG_DEBUG (
"BS uplink scheduler, UGS allocation, size: " << allocationSize <<
" symbols");
870 << allocationSize <<
" symbols" <<
", modulation: BPSK 1/2");
886 uint32_t &symbolsToAllocation,
887 uint32_t &availableSymbols)
889 std::vector<ServiceFlow*> serviceFlows = ssRecord->
GetServiceFlows (schedulingType);
891 for (std::vector<ServiceFlow*>::iterator iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
910 uint32_t &symbolsToAllocation,
911 uint32_t &availableSymbols)
913 uint32_t allocSizeBytes = 0;
914 uint32_t allocSizeSymbols = 0;
915 uint16_t sduSize = 0;
921 if (requiredBandwidth > 0)
926 allocSizeBytes = sduSize;
927 allocSizeSymbols =
GetBs ()->GetPhy ()->GetNrSymbols (sduSize, modulationType);
932 allocSizeBytes = requiredBandwidth;
933 allocSizeSymbols =
GetBs ()->GetPhy ()->GetNrSymbols (requiredBandwidth, modulationType);
936 if (availableSymbols >= allocSizeSymbols)
939 << allocSizeSymbols <<
" symbols" <<
", CID: " << serviceFlow->
GetConnection ()->GetCid () <<
", SFID: "
976 if (timeSinceLastIrInterval +
GetBs ()->GetPhy ()->GetFrameDuration () >
GetBs ()->GetInitialRangingInterval ()
977 && availableSymbols >= allocationSize)
981 ulMapIeIr.
SetCid ((
GetBs ()->GetBroadcastConnection ())->GetCid ());
985 NS_LOG_DEBUG (
"BS uplink scheduler, initial ranging allocation, size: " << allocationSize <<
" symbols"
986 <<
", modulation: BPSK 1/2" );
991 GetBs ()->MarkRangingOppStart (ssUlStartTime +
Seconds (symbolsToAllocation
992 *
GetBs ()->GetSymbolDuration ().GetSeconds ()) +
Seconds (i *
GetBs ()->GetRangReqOppSize ()
993 *
GetBs ()->GetSymbolDuration ().GetSeconds ()));
1004 uint8_t delayNrFrames = 1;
1007 uint32_t bytesPerFrame =
1008 (uint32_t ((
double)(bitsPerSecond) *
GetBs ()->GetPhy ()->GetFrameDuration ().GetSeconds ())) / 8;
1009 uint32_t frameDurationMSec =
GetBs ()->GetPhy ()->GetFrameDuration ().GetMilliSeconds ();
1023 uint32_t grantSize =
GetBs ()->GetPhy ()->GetNrSymbols (bytesPerFrame, modulation);
1028 if (toleratedJitter > frameDurationMSec)
1030 delayNrFrames = (uint8_t)(toleratedJitter / frameDurationMSec);
1033 uint16_t interval = delayNrFrames * frameDurationMSec;
1045 uint16_t interval = 1000;
1062 std::list<Ptr <PriorityUlJob> > priorityUlJobs;
1070 ServiceFlow *serviceFlowJob = job->GetServiceFlow ();
1072 if (serviceFlowJob == serviceFlow)
1074 size += job->GetSize ();
1086 SSRecord *ssRecord =
GetBs ()->GetSSManager ()->GetSSRecord (connection->GetCid ());
1087 ServiceFlow *serviceFlow = connection->GetServiceFlow ();
1089 uint32_t size = bwRequestHdr.
GetBr ();
1092 if (size > pendingSize)
1094 size -= pendingSize;
1109 Time period = deadline;
1115 job->SetSsRecord (ssRecord);
1116 job->SetServiceFlow (serviceFlow);
1117 job->SetSize (size);
1118 job->SetDeadline (deadline);
1119 job->SetReleaseTime (currentTime);
1121 job->SetPeriod (period);
1122 job->SetType (
DATA);
This class implements the bandwidth-request mac Header as described by IEEE Standard for Local and me...
Cid GetCid(void) const
Get CID field.
uint32_t GetBr(void) const
Get BR 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...
uint8_t GetUiuc(void) const
Get UIUC.
void SetStartTime(uint16_t startTime)
Set start time.
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 GetHasServiceFlowBe(void) const
Check if at least one flow has scheduling type SF_TYPE_BE.
bool GetHasServiceFlowNrtps(void) const
Check if at least one flow has scheduling type SF_TYPE_NRTPS.
bool GetPollForRanging(void) const
Get poll for ranging.
WimaxNetDevice::RangingStatus GetRangingStatus(void) const
Get ranging status.
WimaxPhy::ModulationType GetModulationType(void) const
Get modulation type.
std::vector< ServiceFlow * > GetServiceFlows(enum ServiceFlow::SchedulingType schedulingType) const
Get service flows.
bool GetHasServiceFlowRtps(void) const
Check if at least one flow has scheduling type SF_TYPE_RTPS.
Mac48Address GetMacAddress(void) const
Get MAC address.
bool GetAreServiceFlowsAllocated(void) const
Check if service flows are allocated.
bool GetHasServiceFlowUgs(void) const
Check if at least one flow has scheduling type SF_TYPE_UGS.
bool GetIsBroadcastSS(void)
Get is broadcast SS.
Cid GetBasicCid(void) const
Get basic CID.
This class implements service flows as described by the IEEE-802.16 standard.
enum WimaxPhy::ModulationType GetModulation(void) const
Get modulation.
uint32_t GetMinReservedTrafficRate(void) const
Get minimum reserved traffic rate.
uint8_t GetSduSize(void) const
Get SDU size.
uint16_t GetUnsolicitedPollingInterval(void) const
Get unsolicited polling interval.
enum ServiceFlow::SchedulingType GetSchedulingType(void) const
Get scheduling type.
SchedulingType
section 11.13.11 Service flow scheduling type, page 701
char * GetSchedulingTypeStr(void) const
Get scheduling type string.
ServiceFlowRecord * GetRecord(void) const
Get service flow record.
Ptr< WimaxConnection > GetConnection(void) const
Can return a null connection is this service flow has not been associated yet to a connection.
uint32_t GetMaximumLatency(void) const
Get maximum latency.
void SetUnsolicitedGrantInterval(uint16_t unsolicitedGrantInterval)
Set unsolicied grant interval.
bool GetIsMulticast(void) const
Get is multicast.
void SetUnsolicitedPollingInterval(uint16_t unsolicitedPollingInterval)
Set unsolicited polling interval.
uint32_t GetToleratedJitter(void) const
Get tolerated jitter.
uint32_t GetSfid(void) const
Get SFID.
this class implements a structure to manage some parameters and statistics related to a service flow
Time GetGrantTimeStamp(void) const
void UpdateRequestedBandwidth(uint32_t requestedBandwidth)
update the requested bandwidth
uint32_t GetGrantedBandwidthTemp(void)
void UpdateGrantedBandwidthTemp(uint32_t grantedBandwidthTemp)
update the temporary granted bandwidth
uint32_t GetRequestedBandwidth(void)
void IncreaseBacklogged(uint32_t backlogged)
increase backlogged
uint32_t GetBacklogged(void) const
void SetBackloggedTemp(uint32_t backloggedTemp)
set temporary back logged
uint32_t GetBwSinceLastExpiry(void)
void SetGrantSize(uint32_t grantSize)
Set the grant size (only for UGS service flows)
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
uint32_t GetGrantedBandwidth(void)
void UpdateBwSinceLastExpiry(uint32_t bwSinceLastExpiry)
update BW since last expiry
void SetBacklogged(uint32_t backlogged)
set backlogged
void SetLastGrantTime(Time grantTime)
set last grant time
uint32_t GetBackloggedTemp(void) const
Time GetLastGrantTime(void) const
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now(void)
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
TimeWithUnit As(const enum 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 Time GetDcdTimeStamp(void) const
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(void) const
virtual void SetIsInvIrIntrvlAllocated(bool isInvIrIntrvlAllocated)
Set if the Inv IR interval is allocated.
virtual Time GetTimeStampIrInterval(void)
virtual Time GetUcdTimeStamp(void) const
virtual void SetTimeStampIrInterval(Time timeStampIrInterval)
Set timestamp IR interval.
virtual Ptr< BaseStationNetDevice > GetBs(void)
Ptr< UlJob > CreateUlJob(SSRecord *ssRecord, enum ServiceFlow::SchedulingType schedType, ReqType reqType)
void AddUplinkAllocation(OfdmUlMapIe &ulMapIe, const uint32_t &allocationSize, uint32_t &symbolsToAllocation, uint32_t &availableSymbols)
Add uplink allocation.
void ServiceBandwidthRequests(const SSRecord *ssRecord, enum ServiceFlow::SchedulingType schedulingType, OfdmUlMapIe &ulMapIe, const WimaxPhy::ModulationType modulationType, uint32_t &symbolsToAllocation, uint32_t &availableSymbols)
Service bandwidth requests.
uint32_t CountSymbolsQueue(std::list< Ptr< UlJob > > jobs)
void ServiceUnsolicitedGrants(const SSRecord *ssRecord, enum ServiceFlow::SchedulingType schedulingType, OfdmUlMapIe &ulMapIe, const WimaxPhy::ModulationType modulationType, uint32_t &symbolsToAllocation, uint32_t &availableSymbols)
Service unsolicited grants.
uint32_t CalculateAllocationStartTime(void)
Calculate allocation start time.
void CheckDeadline(uint32_t &availableSymbols)
Check deadline from jobs. Migrate requests if necessary.
void ProcessBandwidthRequest(const BandwidthRequestHeader &bwRequestHdr)
Process bandwidth request function.
static TypeId GetTypeId(void)
Get the type ID.
void GetChannelDescriptorsToUpdate(bool &updateDcd, bool &updateUcd, bool &sendDcd, bool &sendUcd)
Determines if channel descriptors sent in the current frame are required to be updated.
void AllocateInitialRangingInterval(uint32_t &symbolsToAllocation, uint32_t &availableSymbols)
Allocate initial ranging interval.
std::list< Ptr< UlJob > > m_uplinkJobs_inter
uplink jobs intermedite priority
std::list< Ptr< UlJob > > m_uplinkJobs_low
uplink jobs low priority
void UplinkSchedWindowTimer(void)
Reset the current window.
~UplinkSchedulerMBQoS(void)
uint32_t CountSymbolsJobs(Ptr< UlJob > job)
bool ServiceBandwidthRequestsBytes(ServiceFlow *serviceFlow, enum ServiceFlow::SchedulingType schedulingType, OfdmUlMapIe &ulMapIe, const WimaxPhy::ModulationType modulationType, uint32_t &symbolsToAllocation, uint32_t &availableSymbols, uint32_t allocationSizeBytes)
Service bandwidth requests bytes.
void InitOnce(void)
This method is called once to initialize window.
Time m_windowInterval
windows interval
Ptr< UlJob > DequeueJob(UlJob::JobPriority priority)
Dequeue a job from a priority queue.
void Schedule(void)
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.
std::list< OfdmUlMapIe > GetUplinkAllocations(void) const
Get uplink allocations.
Time DetermineDeadline(ServiceFlow *serviceFlow)
Calculates deadline of a request.
void CheckMinimumBandwidth(uint32_t &availableSymbols)
Check if Minimum bandwidth is guarantee. Migrate requests if necessary.
void OnSetRequestedBandwidth(ServiceFlowRecord *sfr)
Set requested bandwidth.
void SetupServiceFlow(SSRecord *ssRecord, ServiceFlow *serviceFlow)
Setup service flow.
std::list< OfdmUlMapIe > m_uplinkAllocations
uplink allocations
@ RANGING_STATUS_CONTINUE
ModulationType
ModulationType enumeration.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#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.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
@ LOG_DEBUG
Rare ad-hoc debug messages.
SortProcessPtr structure.