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);