24 #include "ns3/simulator.h"
29 #include "ns3/uinteger.h"
76 .SetGroupName(
"Wimax")
82 std::list<OfdmUlMapIe>
95 uint32_t randNr = rand ();
96 if (randNr % 5 == 0 ||
GetBs ()->GetNrDcdSent () == 0)
102 if (randNr % 5 == 0 ||
GetBs ()->GetNrUcdSent () == 0)
131 if (timeSinceLastDcd >
GetBs ()->GetDcdInterval ())
137 if (timeSinceLastUcd >
GetBs ()->GetUcdInterval ())
147 return GetBs ()->GetNrDlSymbols () *
GetBs ()->GetPhy ()->GetPsPerSymbol () +
GetBs ()->GetTtg ();
152 const uint32_t &allocationSize,
153 uint32_t &symbolsToAllocation,
154 uint32_t &availableSymbols)
159 symbolsToAllocation += allocationSize;
160 availableSymbols -= allocationSize;
169 bool allocationForDsa =
false;
171 uint32_t symbolsToAllocation = 0;
172 uint32_t allocationSize = 0;
173 uint32_t availableSymbols =
GetBs ()->GetNrUlSymbols ();
180 std::vector<SSRecord*> *ssRecords =
GetBs ()->GetSSManager ()->GetSSRecords ();
181 NS_LOG_INFO (
"UL Scheduler start, availableSymbols = " << availableSymbols);
183 for (std::vector<SSRecord*>::iterator iter = ssRecords->begin (); iter != ssRecords->end (); ++iter)
199 allocationSize =
GetBs ()->GetRangReqOppSize ();
202 if (availableSymbols >= allocationSize)
216 ulMapIe.
SetUiuc (
GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
225 if (!allocationForDsa)
227 allocationSize =
GetBs ()->GetPhy ()->GetNrSymbols (
sizeof(
DsaReq), modulationType);
228 if (availableSymbols >= allocationSize)
231 allocationForDsa =
true;
253 if (availableSymbols)
263 if (availableSymbols)
273 if (availableSymbols)
289 if (availableSymbols)
295 if (availableSymbols)
297 for (std::vector<SSRecord*>::iterator iter = ssRecords->begin (); iter != ssRecords->end (); ++iter)
311 ulMapIe.
SetUiuc (
GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
315 if (availableSymbols)
325 if (availableSymbols)
346 GetBs ()->GetBandwidthManager ()->SetSubframeRatio ();
354 uint32_t &symbolsToAllocation,
355 uint32_t &availableSymbols)
357 uint32_t allocationSize = 0;
358 uint8_t uiuc = ulMapIe.
GetUiuc ();
359 std::vector<ServiceFlow*> serviceFlows = ssRecord->
GetServiceFlows (schedulingType);
361 for (std::vector<ServiceFlow*>::iterator iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
369 allocationSize =
GetBs ()->GetBandwidthManager ()->CalculateAllocationSize (ssRecord, serviceFlow);
379 if (bps < serviceFlow->GetMinReservedTrafficRate ())
393 if (availableSymbols < allocationSize)
398 if (allocationSize > 0)
414 NS_LOG_DEBUG (
"BS uplink scheduler, UGS allocation, size: " << allocationSize <<
" symbols");
419 << allocationSize <<
" symbols" <<
", modulation: BPSK 1/2");
434 uint32_t &symbolsToAllocation,
435 uint32_t &availableSymbols)
437 std::vector<ServiceFlow*> serviceFlows = ssRecord->
GetServiceFlows (schedulingType);
439 for (std::vector<ServiceFlow*>::iterator iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
458 uint32_t &symbolsToAllocation,
459 uint32_t &availableSymbols)
461 uint32_t allocSizeBytes = 0;
462 uint32_t allocSizeSymbols = 0;
463 uint16_t sduSize = 0;
469 if (requiredBandwidth > 0)
474 allocSizeBytes = sduSize;
475 allocSizeSymbols =
GetBs ()->GetPhy ()->GetNrSymbols (sduSize, modulationType);
479 allocSizeBytes = requiredBandwidth;
480 allocSizeSymbols =
GetBs ()->GetPhy ()->GetNrSymbols (requiredBandwidth, modulationType);
483 if (availableSymbols >= allocSizeSymbols)
487 << allocSizeSymbols <<
" symbols" <<
", CID: " << serviceFlow->
GetConnection ()->GetCid () <<
", SFID: "
512 NS_LOG_INFO (
"\t\tavailableSymbols = " << availableSymbols);
514 uint32_t allocSizeSymbols_[100];
519 int nbAllocation = 0;
520 uint32_t allocSizeBytes;
521 uint32_t totAllocSizeSymbols = 0;
524 std::vector<SSRecord*> *ssRecords =
GetBs ()->GetSSManager ()->GetSSRecords ();
526 for (std::vector<SSRecord*>::iterator iter = ssRecords->begin (); iter != ssRecords->end (); ++iter)
539 ulMapIe.
SetUiuc (
GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
543 for (std::vector<ServiceFlow*>::iterator iter2 = serviceFlows.begin (); iter2 != serviceFlows.end (); ++iter2)
545 record_[nbAllocation] = (*iter2)->GetRecord ();
549 if (requiredBandwidth > 0)
551 modulationType_[nbAllocation] = modulationType;
552 ulMapIe_[nbAllocation] = ulMapIe;
553 allocSizeBytes = requiredBandwidth;
554 allocSizeSymbols_[nbAllocation] =
GetBs ()->GetPhy ()->GetNrSymbols (allocSizeBytes,
555 modulationType_[nbAllocation]);
556 totAllocSizeSymbols += allocSizeSymbols_[nbAllocation];
558 NS_LOG_INFO (
"\t\tUL Scheduler for CID = " << (*iter2)->GetConnection ()->GetCid ());
559 NS_LOG_INFO (
"\t\t\trequiredBandwidth = " << record_[nbAllocation]->GetRequestedBandwidth ()
560 <<
", allocSizeSymbols = " << allocSizeSymbols_[nbAllocation] <<
", modulationType = "
561 << modulationType_[nbAllocation]);
569 NS_LOG_INFO (
"\t\ttotAllocSizeSymbols = " << totAllocSizeSymbols);
572 while (totAllocSizeSymbols > availableSymbols)
574 NS_LOG_INFO (
"\tUL Channel Saturation: totAllocSizeSymbols > availableSymbols");
575 double delta = double(availableSymbols) / double(totAllocSizeSymbols);
577 totAllocSizeSymbols = 0;
578 for (
int i = 0; i < nbAllocation; i++)
580 NS_LOG_INFO (
"\t\tprevious allocSizeSymbols_[" << i <<
"] = " << allocSizeSymbols_[i]);
581 allocSizeSymbols_[i] = (uint32_t) std::floor (allocSizeSymbols_[i] * delta);
582 totAllocSizeSymbols += allocSizeSymbols_[i];
583 NS_LOG_INFO (
"\t\tnew allocSizeSymbols_[" << i <<
"] = " << allocSizeSymbols_[i]);
585 NS_LOG_INFO (
"\t\ttotAllocSizeSymbols = " << totAllocSizeSymbols);
589 for (
int i = 0; i < nbAllocation; i++)
591 AddUplinkAllocation (ulMapIe_[i], allocSizeSymbols_[i], symbolsToAllocation, availableSymbols);
592 allocSizeBytes =
GetBs ()->GetPhy ()->GetNrBytes (allocSizeSymbols_[i], modulationType_[i]);
593 NS_LOG_INFO (
"\t\tUpdateGrantedBandwidth for " << i <<
" = " << allocSizeBytes);
594 if (record_[i]->GetRequestedBandwidth () < allocSizeBytes)
616 if (timeSinceLastIrInterval +
GetBs ()->GetPhy ()->GetFrameDuration () >
GetBs ()->GetInitialRangingInterval ()
617 && availableSymbols >= allocationSize)
621 ulMapIeIr.
SetCid (
GetBs ()->GetBroadcastConnection ()->GetCid ());
625 NS_LOG_DEBUG (
"BS uplink scheduler, initial ranging allocation, size: " << allocationSize <<
" symbols"
626 <<
", modulation: BPSK 1/2");
631 GetBs ()->MarkRangingOppStart (ssUlStartTime +
Seconds (symbolsToAllocation
632 *
GetBs ()->GetSymbolDuration ().GetSeconds ()) +
Seconds (i *
GetBs ()->GetRangReqOppSize ()
633 *
GetBs ()->GetSymbolDuration ().GetSeconds ()));
644 uint8_t delayNrFrames = 1;
647 uint32_t bytesPerFrame =
648 (uint32_t ((
double)(bitsPerSecond) *
GetBs ()->GetPhy ()->GetFrameDuration ().GetSeconds ())) / 8;
649 uint32_t frameDurationMSec =
GetBs ()->GetPhy ()->GetFrameDuration ().GetMilliSeconds ();
663 uint32_t grantSize =
GetBs ()->GetPhy ()->GetNrSymbols (bytesPerFrame, modulation);
668 if (toleratedJitter > frameDurationMSec)
670 delayNrFrames = (uint8_t)(toleratedJitter / frameDurationMSec);
673 uint16_t interval = delayNrFrames * frameDurationMSec;
679 if (serviceFlow->
GetSduSize () > bytesPerFrame)
681 delayNrFrames = (uint8_t)(serviceFlow->
GetSduSize () / bytesPerFrame);
684 uint16_t interval = delayNrFrames * frameDurationMSec;
717 uint32_t grantedBandwidth = 0;