21 #include "bs-uplink-scheduler-simple.h"
22 #include "bs-net-device.h"
23 #include "ns3/simulator.h"
25 #include "burst-profile-manager.h"
26 #include "ss-manager.h"
28 #include "ns3/uinteger.h"
29 #include "ss-record.h"
30 #include "service-flow.h"
31 #include "service-flow-record.h"
32 #include "bs-link-manager.h"
33 #include "bandwidth-manager.h"
38 NS_OBJECT_ENSURE_REGISTERED (UplinkSchedulerSimple);
40 UplinkSchedulerSimple::UplinkSchedulerSimple (
void)
43 SetTimeStampIrInterval (
Seconds (0));
44 SetNrIrOppsAllocated (0);
45 SetIsIrIntrvlAllocated (
false);
46 SetIsInvIrIntrvlAllocated (
false);
51 UplinkSchedulerSimple::UplinkSchedulerSimple (Ptr<BaseStationNetDevice> bs)
54 SetTimeStampIrInterval (
Seconds (0));
55 SetNrIrOppsAllocated (0);
56 SetIsIrIntrvlAllocated (
false);
57 SetIsInvIrIntrvlAllocated (
false);
62 UplinkSchedulerSimple::~UplinkSchedulerSimple (
void)
65 m_uplinkAllocations.clear ();
69 UplinkSchedulerSimple::InitOnce ()
75 UplinkSchedulerSimple::GetTypeId (
void)
77 static TypeId tid = TypeId (
"ns3::UplinkSchedulerSimple").SetParent<Object> ();
81 std::list<OfdmUlMapIe>
82 UplinkSchedulerSimple::GetUplinkAllocations (
void)
const
84 return m_uplinkAllocations;
97 uint32_t randNr = rand ();
98 if (randNr % 5 == 0 || GetBs ()->GetNrDcdSent () == 0)
104 if (randNr % 5 == 0 || GetBs ()->GetNrUcdSent () == 0)
133 if (timeSinceLastDcd > GetBs ()->GetDcdInterval ())
139 if (timeSinceLastUcd > GetBs ()->GetUcdInterval ())
147 UplinkSchedulerSimple::CalculateAllocationStartTime (
void)
149 return GetBs ()->GetNrDlSymbols () * GetBs ()->GetPhy ()->GetPsPerSymbol () + GetBs ()->GetTtg ();
153 UplinkSchedulerSimple::AddUplinkAllocation (OfdmUlMapIe &ulMapIe,
154 const uint32_t &allocationSize,
155 uint32_t &symbolsToAllocation,
156 uint32_t &availableSymbols)
158 ulMapIe.SetDuration (allocationSize);
159 ulMapIe.SetStartTime (symbolsToAllocation);
160 m_uplinkAllocations.push_back (ulMapIe);
161 symbolsToAllocation += allocationSize;
162 availableSymbols -= allocationSize;
166 UplinkSchedulerSimple::Schedule (
void)
168 m_uplinkAllocations.clear ();
169 SetIsIrIntrvlAllocated (
false);
170 SetIsInvIrIntrvlAllocated (
false);
171 bool allocationForDsa =
false;
173 uint32_t symbolsToAllocation = 0;
174 uint32_t allocationSize = 0;
175 uint32_t availableSymbols = GetBs ()->GetNrUlSymbols ();
177 AllocateInitialRangingInterval (symbolsToAllocation, availableSymbols);
179 std::vector<SSRecord*> *ssRecords = GetBs ()->GetSSManager ()->GetSSRecords ();
180 for (std::vector<SSRecord*>::iterator iter = ssRecords->begin (); iter != ssRecords->end (); ++iter)
182 SSRecord *ssRecord = *iter;
184 if (ssRecord->GetIsBroadcastSS ())
188 Cid cid = ssRecord->GetBasicCid ();
190 ulMapIe.SetCid (cid);
192 if (ssRecord->GetPollForRanging () && ssRecord->GetRangingStatus () == WimaxNetDevice::RANGING_STATUS_CONTINUE)
197 ulMapIe.SetUiuc (OfdmUlBurstProfile::UIUC_INITIAL_RANGING);
198 allocationSize = GetBs ()->GetRangReqOppSize ();
199 SetIsInvIrIntrvlAllocated (
true);
201 if (availableSymbols >= allocationSize)
203 AddUplinkAllocation (ulMapIe, allocationSize, symbolsToAllocation, availableSymbols);
213 WimaxPhy::ModulationType modulationType = ssRecord->GetModulationType ();
216 ulMapIe.SetUiuc (GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
217 WimaxNetDevice::DIRECTION_UPLINK));
220 if (ssRecord->GetRangingStatus () == WimaxNetDevice::RANGING_STATUS_SUCCESS
221 && !ssRecord->GetAreServiceFlowsAllocated ())
226 if (!allocationForDsa)
228 allocationSize = GetBs ()->GetPhy ()->GetNrSymbols (
sizeof(DsaReq), modulationType);
230 if (availableSymbols >= allocationSize)
232 AddUplinkAllocation (ulMapIe, allocationSize, symbolsToAllocation, availableSymbols);
233 allocationForDsa =
true;
247 ServiceUnsolicitedGrants (ssRecord,
248 ServiceFlow::SF_TYPE_UGS,
255 if (availableSymbols)
257 ServiceUnsolicitedGrants (ssRecord,
258 ServiceFlow::SF_TYPE_RTPS,
265 if (availableSymbols)
267 ServiceUnsolicitedGrants (ssRecord,
268 ServiceFlow::SF_TYPE_NRTPS,
275 if (availableSymbols)
277 ServiceUnsolicitedGrants (ssRecord,
278 ServiceFlow::SF_TYPE_BE,
287 if (availableSymbols)
289 ServiceBandwidthRequests (ssRecord,
290 ServiceFlow::SF_TYPE_RTPS,
297 if (availableSymbols)
299 ServiceBandwidthRequests (ssRecord,
300 ServiceFlow::SF_TYPE_NRTPS,
307 if (availableSymbols)
309 ServiceBandwidthRequests (ssRecord,
310 ServiceFlow::SF_TYPE_BE,
319 OfdmUlMapIe ulMapIeEnd;
322 ulMapIeEnd.SetStartTime (symbolsToAllocation);
323 ulMapIeEnd.SetUiuc (OfdmUlBurstProfile::UIUC_END_OF_MAP);
324 ulMapIeEnd.SetDuration (0);
325 m_uplinkAllocations.push_back (ulMapIeEnd);
328 GetBs ()->GetBandwidthManager ()->SetSubframeRatio ();
332 UplinkSchedulerSimple::ServiceUnsolicitedGrants (
const SSRecord *ssRecord,
333 enum ServiceFlow::SchedulingType schedulingType,
334 OfdmUlMapIe &ulMapIe,
335 const WimaxPhy::ModulationType modulationType,
336 uint32_t &symbolsToAllocation,
337 uint32_t &availableSymbols)
339 uint32_t allocationSize = 0;
340 uint8_t uiuc = ulMapIe.GetUiuc ();
341 std::vector<ServiceFlow*> serviceFlows = ssRecord->GetServiceFlows (schedulingType);
343 for (std::vector<ServiceFlow*>::iterator iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
345 ServiceFlow *serviceFlow = *iter;
351 allocationSize = GetBs ()->GetBandwidthManager ()->CalculateAllocationSize (ssRecord, serviceFlow);
353 if (serviceFlow->GetSchedulingType () == ServiceFlow::SF_TYPE_NRTPS)
356 ServiceFlowRecord *record = serviceFlow->GetRecord ();
357 if (currentTime - record->GetGrantTimeStamp () >
Seconds (1))
359 uint32_t bps = (record->GetBwSinceLastExpiry () * 8);
360 if (bps < serviceFlow->GetMinReservedTrafficRate ())
362 ServiceBandwidthRequests (serviceFlow,
368 record->SetBwSinceLastExpiry (0);
369 record->SetGrantTimeStamp (currentTime);
374 if (availableSymbols < allocationSize)
379 if (allocationSize > 0)
381 ulMapIe.SetStartTime (symbolsToAllocation);
382 if (serviceFlow->GetSchedulingType () != ServiceFlow::SF_TYPE_UGS)
385 ulMapIe.SetUiuc (OfdmUlBurstProfile::UIUC_REQ_REGION_FULL);
393 NS_LOG_DEBUG (
", CID: " << serviceFlow->GetConnection ()->GetCid () <<
", SFID: " << serviceFlow->GetSfid ());
395 AddUplinkAllocation (ulMapIe, allocationSize, symbolsToAllocation, availableSymbols);
396 ulMapIe.SetUiuc (uiuc);
401 UplinkSchedulerSimple::ServiceBandwidthRequests (
const SSRecord *ssRecord,
402 enum ServiceFlow::SchedulingType schedulingType,
403 OfdmUlMapIe &ulMapIe,
404 const WimaxPhy::ModulationType modulationType,
405 uint32_t &symbolsToAllocation,
406 uint32_t &availableSymbols)
408 std::vector<ServiceFlow*> serviceFlows = ssRecord->GetServiceFlows (schedulingType);
410 for (std::vector<ServiceFlow*>::iterator iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
412 if (!ServiceBandwidthRequests (*iter,
425 UplinkSchedulerSimple::ServiceBandwidthRequests (ServiceFlow *serviceFlow,
426 enum ServiceFlow::SchedulingType schedulingType,
427 OfdmUlMapIe &ulMapIe,
428 const WimaxPhy::ModulationType modulationType,
429 uint32_t &symbolsToAllocation,
430 uint32_t &availableSymbols)
432 uint32_t allocSizeBytes = 0;
433 uint32_t allocSizeSymbols = 0;
434 uint16_t sduSize = 0;
436 ServiceFlowRecord *record = serviceFlow->GetRecord ();
437 sduSize = serviceFlow->GetSduSize ();
439 uint32_t requiredBandwidth = record->GetRequestedBandwidth () - record->GetGrantedBandwidth ();
440 if (requiredBandwidth > 0)
445 allocSizeBytes = sduSize;
446 allocSizeSymbols = GetBs ()->GetPhy ()->GetNrSymbols (sduSize, modulationType);
450 allocSizeBytes = requiredBandwidth;
451 allocSizeSymbols = GetBs ()->GetPhy ()->GetNrSymbols (requiredBandwidth, modulationType);
454 if (availableSymbols >= allocSizeSymbols)
456 record->UpdateGrantedBandwidth (allocSizeBytes);
458 if (schedulingType == ServiceFlow::SF_TYPE_NRTPS)
460 record->SetBwSinceLastExpiry (allocSizeBytes);
463 AddUplinkAllocation (ulMapIe, allocSizeSymbols, symbolsToAllocation, availableSymbols);
474 UplinkSchedulerSimple::AllocateInitialRangingInterval (uint32_t &symbolsToAllocation, uint32_t &availableSymbols)
476 Time ssUlStartTime =
Seconds (CalculateAllocationStartTime () * GetBs ()->GetPsDuration ().GetSeconds ());
477 SetNrIrOppsAllocated (GetBs ()->GetLinkManager ()->CalculateRangingOppsToAllocate ());
478 uint32_t allocationSize = GetNrIrOppsAllocated () * GetBs ()->GetRangReqOppSize ();
479 Time timeSinceLastIrInterval =
Simulator::Now () - GetTimeStampIrInterval ();
482 if (timeSinceLastIrInterval + GetBs ()->GetPhy ()->GetFrameDuration () > GetBs ()->GetInitialRangingInterval ()
483 && availableSymbols >= allocationSize)
485 SetIsIrIntrvlAllocated (
true);
486 OfdmUlMapIe ulMapIeIr;
487 ulMapIeIr.SetCid ((GetBs ()->GetBroadcastConnection ())->GetCid ());
488 ulMapIeIr.SetStartTime (symbolsToAllocation);
489 ulMapIeIr.SetUiuc (OfdmUlBurstProfile::UIUC_INITIAL_RANGING);
491 NS_LOG_DEBUG (
"BS uplink scheduler, initial ranging allocation, size: " << allocationSize <<
" symbols"
492 <<
", modulation: BPSK 1/2");
495 for (uint8_t i = 0; i < GetNrIrOppsAllocated (); i++)
497 GetBs ()->MarkRangingOppStart (ssUlStartTime +
Seconds (symbolsToAllocation
498 * GetBs ()->GetSymbolDuration ().GetSeconds ()) +
Seconds (i * GetBs ()->GetRangReqOppSize ()
499 * GetBs ()->GetSymbolDuration ().GetSeconds ()));
502 AddUplinkAllocation (ulMapIeIr, allocationSize, symbolsToAllocation, availableSymbols);
508 UplinkSchedulerSimple::SetupServiceFlow (SSRecord *ssRecord, ServiceFlow *serviceFlow)
510 uint8_t delayNrFrames = 1;
511 uint32_t bitsPerSecond = serviceFlow->GetMinReservedTrafficRate ();
512 WimaxPhy::ModulationType modulation;
513 uint32_t bytesPerFrame =
514 (uint32_t ((
double)(bitsPerSecond) * GetBs ()->GetPhy ()->GetFrameDuration ().GetSeconds ())) / 8;
515 uint32_t frameDurationMSec = GetBs ()->GetPhy ()->GetFrameDuration ().GetMilliSeconds ();
517 switch (serviceFlow->GetSchedulingType ())
519 case ServiceFlow::SF_TYPE_UGS:
521 if (serviceFlow->GetIsMulticast () ==
true)
523 modulation = serviceFlow->GetModulation ();
527 modulation = ssRecord->GetModulationType ();
529 uint32_t grantSize = GetBs ()->GetPhy ()->GetNrSymbols (bytesPerFrame, modulation);
530 serviceFlow->GetRecord ()->SetGrantSize (grantSize);
532 uint32_t toleratedJitter = serviceFlow->GetToleratedJitter ();
534 if (toleratedJitter > frameDurationMSec)
536 delayNrFrames = (uint8_t)(toleratedJitter / frameDurationMSec);
539 uint16_t interval = delayNrFrames * frameDurationMSec;
540 serviceFlow->SetUnsolicitedGrantInterval (interval);
543 case ServiceFlow::SF_TYPE_RTPS:
545 if (serviceFlow->GetSduSize () > bytesPerFrame)
547 delayNrFrames = (uint8_t)(serviceFlow->GetSduSize () / bytesPerFrame);
550 uint16_t interval = delayNrFrames * frameDurationMSec;
551 serviceFlow->SetUnsolicitedPollingInterval (interval);
554 case ServiceFlow::SF_TYPE_NRTPS:
559 case ServiceFlow::SF_TYPE_BE:
570 UplinkSchedulerSimple::ProcessBandwidthRequest (
const BandwidthRequestHeader &bwRequestHdr)
577 UplinkSchedulerSimple::OnSetRequestedBandwidth (ServiceFlowRecord *sfr)
580 uint32_t grantedBandwidth = 0;
581 sfr->SetGrantedBandwidth (grantedBandwidth);
#define NS_LOG_COMPONENT_DEFINE(name)
void GetChannelDescriptorsToUpdate(bool &, bool &, bool &, bool &)
Determines if channel descriptors sent in the current frame are required to be updated.
#define NS_FATAL_ERROR(msg)
fatal error handling
static Cid InitialRanging(void)
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
#define NS_LOG_DEBUG(msg)