22 #include "bs-uplink-scheduler-rtps.h"
23 #include "bs-net-device.h"
24 #include "ns3/simulator.h"
26 #include "burst-profile-manager.h"
27 #include "ss-manager.h"
29 #include "ns3/uinteger.h"
30 #include "ss-record.h"
31 #include "service-flow.h"
32 #include "service-flow-record.h"
33 #include "bs-link-manager.h"
34 #include "bandwidth-manager.h"
39 NS_OBJECT_ENSURE_REGISTERED ( UplinkSchedulerRtps);
41 UplinkSchedulerRtps::UplinkSchedulerRtps ()
44 SetTimeStampIrInterval (
Seconds (0));
45 SetNrIrOppsAllocated (0);
46 SetIsIrIntrvlAllocated (
false);
47 SetIsInvIrIntrvlAllocated (
false);
52 UplinkSchedulerRtps::UplinkSchedulerRtps (Ptr<BaseStationNetDevice> bs)
55 SetTimeStampIrInterval (
Seconds (0));
56 SetNrIrOppsAllocated (0);
57 SetIsIrIntrvlAllocated (
false);
58 SetIsInvIrIntrvlAllocated (
false);
63 UplinkSchedulerRtps::~UplinkSchedulerRtps (
void)
66 m_uplinkAllocations.clear ();
70 UplinkSchedulerRtps::GetTypeId (
void)
72 static TypeId tid = TypeId (
"ns3::UplinkSchedulerRtps").SetParent<UplinkScheduler> ();
76 std::list<OfdmUlMapIe>
77 UplinkSchedulerRtps::GetUplinkAllocations (
void)
const
79 return m_uplinkAllocations;
89 uint32_t randNr = rand ();
90 if (randNr % 5 == 0 || GetBs ()->GetNrDcdSent () == 0)
96 if (randNr % 5 == 0 || GetBs ()->GetNrUcdSent () == 0)
125 if (timeSinceLastDcd > GetBs ()->GetDcdInterval ())
131 if (timeSinceLastUcd > GetBs ()->GetUcdInterval ())
139 UplinkSchedulerRtps::CalculateAllocationStartTime (
void)
141 return GetBs ()->GetNrDlSymbols () * GetBs ()->GetPhy ()->GetPsPerSymbol () + GetBs ()->GetTtg ();
145 UplinkSchedulerRtps::AddUplinkAllocation (OfdmUlMapIe &ulMapIe,
146 const uint32_t &allocationSize,
147 uint32_t &symbolsToAllocation,
148 uint32_t &availableSymbols)
150 ulMapIe.SetDuration (allocationSize);
151 ulMapIe.SetStartTime (symbolsToAllocation);
152 m_uplinkAllocations.push_back (ulMapIe);
153 symbolsToAllocation += allocationSize;
154 availableSymbols -= allocationSize;
160 m_uplinkAllocations.clear ();
161 SetIsIrIntrvlAllocated (
false);
162 SetIsInvIrIntrvlAllocated (
false);
163 bool allocationForDsa =
false;
165 uint32_t symbolsToAllocation = 0;
166 uint32_t allocationSize = 0;
167 uint32_t availableSymbols = GetBs ()->GetNrUlSymbols ();
169 WimaxPhy::ModulationType modulationType;
172 AllocateInitialRangingInterval (symbolsToAllocation, availableSymbols);
174 std::vector<SSRecord*> *ssRecords = GetBs ()->GetSSManager ()->GetSSRecords ();
175 NS_LOG_INFO (
"UL Scheduler start, availableSymbols = " << availableSymbols);
177 for (std::vector<SSRecord*>::iterator iter = ssRecords->begin (); iter != ssRecords->end (); ++iter)
180 if (ssRecord->GetIsBroadcastSS ())
184 cid = ssRecord->GetBasicCid ();
186 ulMapIe.SetCid (cid);
188 if (ssRecord->GetPollForRanging () && ssRecord->GetRangingStatus () == WimaxNetDevice::RANGING_STATUS_CONTINUE)
192 ulMapIe.SetUiuc (OfdmUlBurstProfile::UIUC_INITIAL_RANGING);
193 allocationSize = GetBs ()->GetRangReqOppSize ();
194 SetIsInvIrIntrvlAllocated (
true);
196 if (availableSymbols >= allocationSize)
198 AddUplinkAllocation (ulMapIe, allocationSize, symbolsToAllocation, availableSymbols);
207 modulationType = ssRecord->GetModulationType ();
210 ulMapIe.SetUiuc (GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
211 WimaxNetDevice::DIRECTION_UPLINK));
214 if (ssRecord->GetRangingStatus () == WimaxNetDevice::RANGING_STATUS_SUCCESS
215 && !ssRecord->GetAreServiceFlowsAllocated ())
219 if (!allocationForDsa)
221 allocationSize = GetBs ()->GetPhy ()->GetNrSymbols (
sizeof(
DsaReq), modulationType);
222 if (availableSymbols >= allocationSize)
224 AddUplinkAllocation (ulMapIe, allocationSize, symbolsToAllocation, availableSymbols);
225 allocationForDsa =
true;
239 ServiceUnsolicitedGrants (ssRecord,
240 ServiceFlow::SF_TYPE_UGS,
247 if (availableSymbols)
249 ServiceUnsolicitedGrants (ssRecord,
250 ServiceFlow::SF_TYPE_RTPS,
257 if (availableSymbols)
259 ServiceUnsolicitedGrants (ssRecord,
260 ServiceFlow::SF_TYPE_NRTPS,
267 if (availableSymbols)
269 ServiceUnsolicitedGrants (ssRecord,
270 ServiceFlow::SF_TYPE_BE,
283 if (availableSymbols)
289 if (availableSymbols)
291 for (std::vector<SSRecord*>::iterator iter = ssRecords->begin (); iter != ssRecords->end (); ++iter)
294 if (ssRecord->GetIsBroadcastSS ())
298 if (!ssRecord->GetPollForRanging () && ssRecord->GetRangingStatus ()
299 != WimaxNetDevice::RANGING_STATUS_CONTINUE && ssRecord->GetAreServiceFlowsAllocated ())
302 cid = ssRecord->GetBasicCid ();
303 ulMapIe.SetCid (cid);
304 modulationType = ssRecord->GetModulationType ();
305 ulMapIe.SetUiuc (GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
306 WimaxNetDevice::DIRECTION_UPLINK));
309 if (availableSymbols)
311 ServiceBandwidthRequests (ssRecord,
312 ServiceFlow::SF_TYPE_NRTPS,
319 if (availableSymbols)
321 ServiceBandwidthRequests (ssRecord,
322 ServiceFlow::SF_TYPE_BE,
334 ulMapIeEnd.SetStartTime (symbolsToAllocation);
335 ulMapIeEnd.SetUiuc (OfdmUlBurstProfile::UIUC_END_OF_MAP);
336 ulMapIeEnd.SetDuration (0);
337 m_uplinkAllocations.push_back (ulMapIeEnd);
340 GetBs ()->GetBandwidthManager ()->SetSubframeRatio ();
344 UplinkSchedulerRtps::ServiceUnsolicitedGrants (
const SSRecord *ssRecord,
345 enum ServiceFlow::SchedulingType schedulingType,
347 const WimaxPhy::ModulationType modulationType,
348 uint32_t &symbolsToAllocation,
349 uint32_t &availableSymbols)
351 uint32_t allocationSize = 0;
352 uint8_t uiuc = ulMapIe.GetUiuc ();
353 std::vector<ServiceFlow*> serviceFlows = ssRecord->GetServiceFlows (schedulingType);
355 for (std::vector<ServiceFlow*>::iterator iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
363 allocationSize = GetBs ()->GetBandwidthManager ()->CalculateAllocationSize (ssRecord, serviceFlow);
366 if (serviceFlow->GetSchedulingType () == ServiceFlow::SF_TYPE_NRTPS)
372 uint32_t bps = (record->GetBwSinceLastExpiry () * 8);
373 if (bps < serviceFlow->GetMinReservedTrafficRate ())
375 ServiceBandwidthRequests (serviceFlow,
381 record->SetBwSinceLastExpiry (0);
387 if (availableSymbols < allocationSize)
392 if (allocationSize > 0)
394 ulMapIe.SetStartTime (symbolsToAllocation);
395 if (serviceFlow->GetSchedulingType () != ServiceFlow::SF_TYPE_UGS)
398 ulMapIe.SetUiuc (OfdmUlBurstProfile::UIUC_REQ_REGION_FULL);
406 if (serviceFlow->GetSchedulingType () == ServiceFlow::SF_TYPE_UGS)
408 NS_LOG_DEBUG (
"BS uplink scheduler, UGS allocation, size: " << allocationSize <<
" symbols");
412 NS_LOG_DEBUG (
"BS uplink scheduler, " << serviceFlow->GetSchedulingTypeStr () <<
" unicast poll, size: "
413 << allocationSize <<
" symbols" <<
", modulation: BPSK 1/2");
416 NS_LOG_DEBUG (
", CID: " << serviceFlow->GetConnection ()->GetCid () <<
", SFID: " << serviceFlow->GetSfid ());
418 AddUplinkAllocation (ulMapIe, allocationSize, symbolsToAllocation, availableSymbols);
419 ulMapIe.SetUiuc (uiuc);
424 UplinkSchedulerRtps::ServiceBandwidthRequests (
const SSRecord *ssRecord,
425 enum ServiceFlow::SchedulingType schedulingType,
426 OfdmUlMapIe &ulMapIe,
427 const WimaxPhy::ModulationType modulationType,
428 uint32_t &symbolsToAllocation,
429 uint32_t &availableSymbols)
431 std::vector<ServiceFlow*> serviceFlows = ssRecord->GetServiceFlows (schedulingType);
433 for (std::vector<ServiceFlow*>::iterator iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
435 if (!ServiceBandwidthRequests (*iter,
448 UplinkSchedulerRtps::ServiceBandwidthRequests (ServiceFlow *serviceFlow,
449 enum ServiceFlow::SchedulingType schedulingType,
450 OfdmUlMapIe &ulMapIe,
451 const WimaxPhy::ModulationType modulationType,
452 uint32_t &symbolsToAllocation,
453 uint32_t &availableSymbols)
455 uint32_t allocSizeBytes = 0;
456 uint32_t allocSizeSymbols = 0;
457 uint16_t sduSize = 0;
459 ServiceFlowRecord *record = serviceFlow->GetRecord ();
460 sduSize = serviceFlow->GetSduSize ();
462 uint32_t requiredBandwidth = record->GetRequestedBandwidth () - record->GetGrantedBandwidth ();
463 if (requiredBandwidth > 0)
468 allocSizeBytes = sduSize;
469 allocSizeSymbols = GetBs ()->GetPhy ()->GetNrSymbols (sduSize, modulationType);
473 allocSizeBytes = requiredBandwidth;
474 allocSizeSymbols = GetBs ()->GetPhy ()->GetNrSymbols (requiredBandwidth, modulationType);
477 if (availableSymbols >= allocSizeSymbols)
480 NS_LOG_DEBUG (
"BS uplink scheduler, " << serviceFlow->GetSchedulingTypeStr () <<
" allocation, size: "
481 << allocSizeSymbols <<
" symbols" <<
", CID: " << serviceFlow->GetConnection ()->GetCid () <<
", SFID: "
482 << serviceFlow->GetSfid () <<
", bw requested: " << record->GetRequestedBandwidth () <<
", bw granted: "
483 << record->GetGrantedBandwidth ());
485 record->UpdateGrantedBandwidth (allocSizeBytes);
487 if (schedulingType == ServiceFlow::SF_TYPE_NRTPS)
489 record->SetBwSinceLastExpiry (allocSizeBytes);
492 AddUplinkAllocation (ulMapIe, allocSizeSymbols, symbolsToAllocation, availableSymbols);
506 NS_LOG_INFO (
"\t\tavailableSymbols = " << availableSymbols);
508 uint32_t allocSizeSymbols_[100];
511 WimaxPhy::ModulationType modulationType_[100];
512 WimaxPhy::ModulationType modulationType;
513 int nbAllocation = 0;
514 uint32_t allocSizeBytes;
515 uint32_t totAllocSizeSymbols = 0;
518 std::vector<SSRecord*> *ssRecords = GetBs ()->GetSSManager ()->GetSSRecords ();
520 for (std::vector<SSRecord*>::iterator iter = ssRecords->begin (); iter != ssRecords->end (); ++iter)
523 if (ssRecord->GetIsBroadcastSS ())
527 if (!ssRecord->GetPollForRanging () && ssRecord->GetRangingStatus () != WimaxNetDevice::RANGING_STATUS_CONTINUE
528 && ssRecord->GetAreServiceFlowsAllocated ())
530 cid = ssRecord->GetBasicCid ();
531 ulMapIe.SetCid (cid);
532 modulationType = ssRecord->GetModulationType ();
533 ulMapIe.SetUiuc (GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
534 WimaxNetDevice::DIRECTION_UPLINK));
536 std::vector<ServiceFlow*> serviceFlows = ssRecord->GetServiceFlows (ServiceFlow::SF_TYPE_RTPS);
537 for (std::vector<ServiceFlow*>::iterator iter2 = serviceFlows.begin (); iter2 != serviceFlows.end (); ++iter2)
539 record_[nbAllocation] = (*iter2)->GetRecord ();
540 uint32_t requiredBandwidth = record_[nbAllocation]->GetRequestedBandwidth ()
541 - record_[nbAllocation]->GetGrantedBandwidth ();
543 if (requiredBandwidth > 0)
545 modulationType_[nbAllocation] = modulationType;
546 ulMapIe_[nbAllocation] = ulMapIe;
547 allocSizeBytes = requiredBandwidth;
548 allocSizeSymbols_[nbAllocation] = GetBs ()->GetPhy ()->GetNrSymbols (allocSizeBytes,
549 modulationType_[nbAllocation]);
550 totAllocSizeSymbols += allocSizeSymbols_[nbAllocation];
552 NS_LOG_INFO (
"\t\tUL Scheduler for CID = " << (*iter2)->GetConnection ()->GetCid ());
553 NS_LOG_INFO (
"\t\t\trequiredBandwidth = " << record_[nbAllocation]->GetRequestedBandwidth ()
554 <<
", allocSizeSymbols = " << allocSizeSymbols_[nbAllocation] <<
", modulationType = "
555 << modulationType_[nbAllocation]);
563 NS_LOG_INFO (
"\t\ttotAllocSizeSymbols = " << totAllocSizeSymbols);
566 while (totAllocSizeSymbols > availableSymbols)
568 NS_LOG_INFO (
"\tUL Channel Saturation: totAllocSizeSymbols > availableSymbols");
569 double delta = double(availableSymbols) / double(totAllocSizeSymbols);
571 totAllocSizeSymbols = 0;
572 for (
int i = 0; i < nbAllocation; i++)
574 NS_LOG_INFO (
"\t\tprevious allocSizeSymbols_[" << i <<
"] = " << allocSizeSymbols_[i]);
575 allocSizeSymbols_[i] = (uint32_t) std::floor (allocSizeSymbols_[i] * delta);
576 totAllocSizeSymbols += allocSizeSymbols_[i];
577 NS_LOG_INFO (
"\t\tnew allocSizeSymbols_[" << i <<
"] = " << allocSizeSymbols_[i]);
579 NS_LOG_INFO (
"\t\ttotAllocSizeSymbols = " << totAllocSizeSymbols);
583 for (
int i = 0; i < nbAllocation; i++)
585 AddUplinkAllocation (ulMapIe_[i], allocSizeSymbols_[i], symbolsToAllocation, availableSymbols);
586 allocSizeBytes = GetBs ()->GetPhy ()->GetNrBytes (allocSizeSymbols_[i], modulationType_[i]);
587 NS_LOG_INFO (
"\t\tUpdateGrantedBandwidth for " << i <<
" = " << allocSizeBytes);
588 if (record_[i]->GetRequestedBandwidth () < allocSizeBytes)
591 record_[i]->SetGrantedBandwidth (0);
592 record_[i]->SetRequestedBandwidth (0);
596 record_[i]->UpdateGrantedBandwidth (allocSizeBytes);
602 UplinkSchedulerRtps::AllocateInitialRangingInterval (uint32_t &symbolsToAllocation, uint32_t &availableSymbols)
604 Time ssUlStartTime =
Seconds (CalculateAllocationStartTime () * GetBs ()->GetPsDuration ().GetSeconds ());
605 SetNrIrOppsAllocated (GetBs ()->GetLinkManager ()->CalculateRangingOppsToAllocate ());
606 uint32_t allocationSize = GetNrIrOppsAllocated () * GetBs ()->GetRangReqOppSize ();
610 if (timeSinceLastIrInterval + GetBs ()->GetPhy ()->GetFrameDuration () > GetBs ()->GetInitialRangingInterval ()
611 && availableSymbols >= allocationSize)
613 SetIsIrIntrvlAllocated (
true);
615 ulMapIeIr.SetCid (GetBs ()->GetBroadcastConnection ()->GetCid ());
616 ulMapIeIr.SetStartTime (symbolsToAllocation);
617 ulMapIeIr.SetUiuc (OfdmUlBurstProfile::UIUC_INITIAL_RANGING);
619 NS_LOG_DEBUG (
"BS uplink scheduler, initial ranging allocation, size: " << allocationSize <<
" symbols"
620 <<
", modulation: BPSK 1/2");
623 for (uint8_t i = 0; i < GetNrIrOppsAllocated (); i++)
625 GetBs ()->MarkRangingOppStart (ssUlStartTime +
Seconds (symbolsToAllocation
626 * GetBs ()->GetSymbolDuration ().GetSeconds ()) +
Seconds (i * GetBs ()->GetRangReqOppSize ()
627 * GetBs ()->GetSymbolDuration ().GetSeconds ()));
630 AddUplinkAllocation (ulMapIeIr, allocationSize, symbolsToAllocation, availableSymbols);
636 UplinkSchedulerRtps::SetupServiceFlow (SSRecord *ssRecord, ServiceFlow *serviceFlow)
638 uint8_t delayNrFrames = 1;
639 uint32_t bitsPerSecond = serviceFlow->GetMinReservedTrafficRate ();
640 WimaxPhy::ModulationType modulation;
641 uint32_t bytesPerFrame =
642 (uint32_t ((
double)(bitsPerSecond) * GetBs ()->GetPhy ()->GetFrameDuration ().GetSeconds ())) / 8;
643 uint32_t frameDurationMSec = GetBs ()->GetPhy ()->GetFrameDuration ().GetMilliSeconds ();
645 switch (serviceFlow->GetSchedulingType ())
647 case ServiceFlow::SF_TYPE_UGS:
649 if (serviceFlow->GetIsMulticast () ==
true)
651 modulation = serviceFlow->GetModulation ();
655 modulation = ssRecord->GetModulationType ();
657 uint32_t grantSize = GetBs ()->GetPhy ()->GetNrSymbols (bytesPerFrame, modulation);
658 serviceFlow->GetRecord ()->SetGrantSize (grantSize);
660 uint32_t toleratedJitter = serviceFlow->GetToleratedJitter ();
662 if (toleratedJitter > frameDurationMSec)
664 delayNrFrames = (uint8_t)(toleratedJitter / frameDurationMSec);
667 uint16_t interval = delayNrFrames * frameDurationMSec;
668 serviceFlow->SetUnsolicitedGrantInterval (interval);
671 case ServiceFlow::SF_TYPE_RTPS:
673 if (serviceFlow->GetSduSize () > bytesPerFrame)
675 delayNrFrames = (uint8_t)(serviceFlow->GetSduSize () / bytesPerFrame);
678 uint16_t interval = delayNrFrames * frameDurationMSec;
679 serviceFlow->SetUnsolicitedPollingInterval (interval);
682 case ServiceFlow::SF_TYPE_NRTPS:
687 case ServiceFlow::SF_TYPE_BE:
698 UplinkSchedulerRtps::InitOnce ()
703 UplinkSchedulerRtps::ProcessBandwidthRequest (
const BandwidthRequestHeader &bwRequestHdr)
708 UplinkSchedulerRtps::OnSetRequestedBandwidth (ServiceFlowRecord *sfr)
711 uint32_t grantedBandwidth = 0;
712 sfr->SetGrantedBandwidth (grantedBandwidth);
this class implements a structure to manage some parameters and statistics related to a service flow ...
#define NS_LOG_COMPONENT_DEFINE(name)
#define NS_FATAL_ERROR(msg)
fatal error handling
Time GetGrantTimeStamp(void) const
static Cid InitialRanging(void)
void SetGrantTimeStamp(Time grantTimeStamp)
Set the grant time stamp. Used for data alocation for ugs flows, and unicast poll (bw request) for no...
void ULSchedulerRTPSConnection(uint32_t &symbolsToAllocation, uint32_t &availableSymbols)
Uplink Scheduler for rtPS connections.
void Schedule(void)
Schedule function.
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
#define NS_LOG_DEBUG(msg)
This class is used by the base station to store some information related to subscriber station in the...
void GetChannelDescriptorsToUpdate(bool &, bool &, bool &, bool &)