23 #include "ns3/simulator.h"
25 #include "ns3/packet-burst.h"
70 std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst> > > *downlinkBursts =
m_downlinkBursts;
71 std::pair<OfdmDlMapIe*, Ptr<PacketBurst> > pair;
72 while (downlinkBursts->size ())
74 pair = downlinkBursts->front ();
84 std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst> > >*
97 dlMapIe->
SetCid (connection->GetCid ());
100 NS_LOG_INFO (
"BS scheduler, burst size: " << burst->GetSize () <<
" bytes" <<
", pkts: " << burst->GetNPackets ()
101 <<
", connection: " << connection->GetTypeStr () <<
", CID: "
102 << connection->GetCid ());
105 NS_LOG_INFO (
", SFID: " << connection->GetServiceFlow ()->GetSfid () <<
", service: "
106 << connection->GetServiceFlow ()->GetSchedulingTypeStr ());
108 NS_LOG_INFO (
", modulation: " << modulationType <<
", DIUC: " << (uint32_t) diuc);
131 uint32_t availableSymbols =
GetBs ()->GetNrDlSymbols ();
152 << availableSymbols << std::endl <<
"BS scheduler, queues:" <<
" IR "
153 <<
GetBs ()->GetInitialRangingConnection ()->GetQueue ()->GetSize ()
155 <<
GetBs ()->GetBroadcastConnection ()->GetQueue ()->GetSize ()
168 uint32_t availableSymbols)
174 uint32_t nrSymbolsRequired = 0;
181 nrSymbolsRequired =
GetBs ()->GetPhy ()->GetNrSymbols (FirstPacketSize,modulationType);
186 uint32_t availableByte =
GetBs ()->GetPhy ()->GetNrBytes (availableSymbols, modulationType);
188 availableSymbols = 0;
192 packet = connection->Dequeue ();
193 availableSymbols -= nrSymbolsRequired;
195 burst->AddPacket (packet);
196 if (availableSymbols <= 0)
217 uint32_t nrSymbolsRequired = 0;
222 while (
GetBs ()->GetBroadcastConnection ()->HasPackets () && availableSymbols > 0)
224 connection =
GetBs ()->GetBroadcastConnection ();
226 packet = connection->GetQueue ()->Peek (hdr);
227 nrSymbolsRequired =
GetBs ()->GetPhy ()->GetNrSymbols (packet->
GetSize (), modulationType);
229 if (availableSymbols < nrSymbolsRequired
234 else if (availableSymbols < nrSymbolsRequired
237 uint32_t availableByte =
GetBs ()->GetPhy ()->
238 GetNrBytes (availableSymbols, modulationType);
244 packet = connection->Dequeue ();
248 "Base station: Error while scheduling broadcast connection: header CID != connection CID");
249 burst->AddPacket (packet);
250 availableSymbols -= nrSymbolsRequired;
252 if (burst->GetNPackets () != 0)
264 uint32_t nrSymbolsRequired = 0;
269 while (
GetBs ()->GetInitialRangingConnection ()->HasPackets () && availableSymbols > 0)
271 connection =
GetBs ()->GetInitialRangingConnection ();
273 packet = connection->GetQueue ()->Peek (hdr);
274 nrSymbolsRequired =
GetBs ()->GetPhy ()->GetNrSymbols (packet->
GetSize (), modulationType);
277 if (availableSymbols < nrSymbolsRequired
282 else if (availableSymbols < nrSymbolsRequired
285 uint32_t availableByte =
GetBs ()->GetPhy ()->
286 GetNrBytes (availableSymbols, modulationType);
292 packet = connection->Dequeue ();
296 "Base station: Error while scheduling initial ranging connection: header CID != connection CID");
297 burst->AddPacket (packet);
298 availableSymbols -= nrSymbolsRequired;
300 if (burst->GetNPackets ())
312 uint32_t nrSymbolsRequired = 0;
317 std::vector<Ptr<WimaxConnection> >::const_iterator iter;
318 std::vector<Ptr<WimaxConnection> > connections;
320 connections =
GetBs ()->GetConnectionManager ()->GetConnections (
Cid::BASIC);
321 for (iter = connections.begin (); iter != connections.end (); ++iter)
323 while ((*iter)->HasPackets () && availableSymbols > 0)
327 modulationType =
GetBs ()->GetSSManager ()->GetSSRecord (connection->GetCid ())->GetModulationType ();
328 diuc =
GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
331 packet = connection->GetQueue ()->Peek (hdr);
332 nrSymbolsRequired =
GetBs ()->GetPhy ()->GetNrSymbols (packet->
GetSize (), modulationType);
335 if (availableSymbols < nrSymbolsRequired
340 else if (availableSymbols < nrSymbolsRequired
343 uint32_t availableByte =
GetBs ()->GetPhy ()->
344 GetNrBytes (availableSymbols, modulationType);
349 packet = connection->Dequeue ();
353 "Base station: Error while scheduling basic connection: header CID != connection CID");
354 burst->AddPacket (packet);
355 availableSymbols -= nrSymbolsRequired;
357 if (burst->GetNPackets () != 0)
360 burst = Create<PacketBurst> ();
371 uint32_t nrSymbolsRequired = 0;
376 std::vector<Ptr<WimaxConnection> >::const_iterator iter;
377 std::vector<Ptr<WimaxConnection> > connections;
380 for (iter = connections.begin (); iter != connections.end (); ++iter)
382 while ((*iter)->HasPackets () && availableSymbols > 0)
386 modulationType =
GetBs ()->GetSSManager ()->GetSSRecord (connection->GetCid ())->GetModulationType ();
387 diuc =
GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
390 packet = connection->GetQueue ()->Peek (hdr);
391 nrSymbolsRequired =
GetBs ()->GetPhy ()->GetNrSymbols (packet->
GetSize (), modulationType);
394 if (availableSymbols < nrSymbolsRequired
399 else if (availableSymbols < nrSymbolsRequired
402 uint32_t availableByte =
GetBs ()->GetPhy ()->
403 GetNrBytes (availableSymbols, modulationType);
408 packet = connection->Dequeue ();
412 "Base station: Error while scheduling primary connection: header CID != connection CID");
413 burst->AddPacket (packet);
414 availableSymbols -= nrSymbolsRequired;
416 if (burst->GetNPackets () != 0)
429 uint32_t nrSymbolsRequired = 0;
436 std::vector<ServiceFlow*>::iterator iter;
438 std::vector<ServiceFlow*> serviceFlows;
441 for (iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
443 serviceFlowRecord = (*iter)->GetRecord ();
445 if ((*iter)->HasPackets () && ((currentTime - serviceFlowRecord->
GetDlTimeStamp ())
446 +
GetBs ()->GetPhy ()->GetFrameDuration ()) > MilliSeconds ((*iter)->GetMaximumLatency ()))
448 connection = (*iter)->GetConnection ();
451 modulationType = connection->GetServiceFlow ()->GetModulation ();
455 modulationType =
GetBs ()->GetSSManager ()->GetSSRecord (connection->GetCid ())->GetModulationType ();
457 diuc =
GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
460 nrSymbolsRequired = connection->GetServiceFlow ()->GetRecord ()->GetGrantSize ();
463 if (availableSymbols > nrSymbolsRequired)
465 availableSymbols -= nrSymbolsRequired;
466 burst =
CreateUgsBurst (connection->GetServiceFlow (), modulationType, nrSymbolsRequired);
467 if (burst->GetNPackets () != 0)
472 burst = Create<PacketBurst> ();
491 std::vector<Ptr<WimaxConnection> >::const_iterator iter;
492 std::vector<Ptr<WimaxConnection> > connections;
493 std::vector<ServiceFlow*>::iterator iter2;
495 std::vector<ServiceFlow*> serviceFlows;
497 uint32_t symbolsRequired[100];
502 uint32_t totSymbolsRequired = 0;
503 int nbConnection = 0;
505 NS_LOG_INFO (
"\tDL Scheduler for rtPS flows \n" <<
"\t\tavailableSymbols = " << availableSymbols);
509 for (iter2 = serviceFlows.begin (); iter2 != serviceFlows.end (); ++iter2)
512 serviceFlowRecord = (*iter2)->GetRecord ();
514 if ((*iter2)->HasPackets ())
518 rtPSConnection[nbConnection] = (*iter2)->GetConnection ();
521 modulationType_[nbConnection] = rtPSConnection[nbConnection]->GetServiceFlow ()->GetModulation ();
525 modulationType_[nbConnection]
526 =
GetBs ()->GetSSManager ()->GetSSRecord (rtPSConnection[nbConnection]->GetCid ())->GetModulationType ();
529 =
GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType_[nbConnection],
532 dataToSend = rtPSConnection[nbConnection]->GetQueue ()->GetQueueLengthWithMACOverhead ();
533 NS_LOG_INFO (
"\t\tRTPS DL Scheduler for CID = " << rtPSConnection[nbConnection]->GetCid ()
534 <<
"\n\t\t\t dataToSend = " << dataToSend);
536 symbolsRequired[nbConnection] =
GetBs ()->GetPhy ()->GetNrSymbols (dataToSend,
537 modulationType_[nbConnection]);
539 totSymbolsRequired += symbolsRequired[nbConnection];
544 NS_LOG_INFO (
"\t\ttotSymbolsRequired = " << totSymbolsRequired);
547 while (totSymbolsRequired > availableSymbols)
549 NS_LOG_INFO (
"\tDL Channel Saturation: totSymbolsRequired > availableSymbols_rtPS");
550 double delta = double(availableSymbols) / double(totSymbolsRequired);
552 totSymbolsRequired = 0;
553 for (
int i = 0; i < nbConnection; i++)
555 NS_LOG_INFO (
"\t\tprevious symbolsRequired[" << i <<
"] = " << symbolsRequired[i]);
556 symbolsRequired[i] = (uint32_t) std::floor (symbolsRequired[i] * delta);
557 totSymbolsRequired += symbolsRequired[i];
558 NS_LOG_INFO (
"\t\tnew symbolsRequired[" << i <<
"] = " << symbolsRequired[i]);
560 NS_LOG_INFO (
"\t\ttotSymbolsRequired = " << totSymbolsRequired);
564 for (
int i = 0; i < nbConnection; i++)
567 packet = rtPSConnection[i]->GetQueue ()->Peek (hdr);
568 uint32_t symbolsForPacketTransmission = 0;
569 burst = Create<PacketBurst> ();
570 NS_LOG_INFO (
"\t\tCID = " << rtPSConnection[i]->GetCid () <<
" assignedSymbols = " << symbolsRequired[i]);
572 while (symbolsRequired[i] > 0)
574 symbolsForPacketTransmission =
GetBs ()->GetPhy ()
575 ->GetNrSymbols (rtPSConnection[i]->GetQueue ()
580 if (symbolsForPacketTransmission > symbolsRequired[i]
587 else if (symbolsForPacketTransmission > symbolsRequired[i]
592 uint32_t availableByte =
GetBs ()->GetPhy ()->
593 GetNrBytes (symbolsRequired[i], modulationType_[i]);
595 symbolsRequired[i] = 0;
599 packet = rtPSConnection[i]->Dequeue ();
600 symbolsRequired[i] -= symbolsForPacketTransmission;
604 "Base station: Error while scheduling RTPs connection: header CID != connection CID");
605 burst->AddPacket (packet);
608 if (burst->GetNPackets () != 0)
614 availableSymbols -= totSymbolsRequired;
623 uint32_t nrSymbolsRequired = 0;
628 std::vector<ServiceFlow*>::iterator iter;
629 std::vector<ServiceFlow*> serviceFlows;
632 for (iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
634 connection = (*iter)->GetConnection ();
636 while ((*iter)->HasPackets () && availableSymbols > 0)
640 modulationType = connection->GetServiceFlow ()->GetModulation ();
644 modulationType =
GetBs ()->GetSSManager ()->GetSSRecord (connection->GetCid ())->GetModulationType ();
647 diuc =
GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
650 packet = connection->GetQueue ()->Peek (hdr);
651 nrSymbolsRequired =
GetBs ()->GetPhy ()->GetNrSymbols (packet->
GetSize (), modulationType);
653 if (availableSymbols < nrSymbolsRequired)
658 packet = connection->Dequeue ();
660 "Base station: Error while scheduling NRTPs connection: header CID != connection CID");
661 burst->AddPacket (packet);
662 availableSymbols -= nrSymbolsRequired;
664 if (burst->GetNPackets () != 0)
667 burst = Create<PacketBurst> ();
678 uint32_t nrSymbolsRequired = 0;
683 std::vector<ServiceFlow*>::iterator iter;
684 std::vector<ServiceFlow*> serviceFlows;
687 for (iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
689 connection = (*iter)->GetConnection ();
691 while ((*iter)->HasPackets () && availableSymbols > 0)
695 modulationType = connection->GetServiceFlow ()->GetModulation ();
699 modulationType =
GetBs ()->GetSSManager ()->GetSSRecord (connection->GetCid ())->GetModulationType ();
701 diuc =
GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
704 packet = connection->GetQueue ()->Peek (hdr);
705 nrSymbolsRequired =
GetBs ()->GetPhy ()->GetNrSymbols (packet->
GetSize (), modulationType);
707 if (availableSymbols < nrSymbolsRequired)
712 packet = connection->Dequeue ();
714 "Base station: Error while scheduling BE connection: header CID != connection CID");
715 burst->AddPacket (packet);
716 availableSymbols -= nrSymbolsRequired;
718 if (burst->GetNPackets () != 0)
721 burst = Create<PacketBurst> ();
std::list< std::pair< OfdmDlMapIe *, Ptr< PacketBurst > > > * GetDownlinkBursts(void) const
keep track of time values and allow control of global simulation resolution
smart pointer class similar to boost::intrusive_ptr
this class implements a structure to manage some parameters and statistics related to a service flow ...
void BSSchedulerInitialRangingConnection(uint32_t &availableSymbols)
void BSSchedulerUGSConnection(uint32_t &availableSymbols)
#define NS_LOG_COMPONENT_DEFINE(name)
uint32_t GetSize(void) const
void BSSchedulerBroadcastConnection(uint32_t &availableSymbols)
Ptr< WimaxConnection > GetConnection(void) const
bool CheckForFragmentation(Ptr< WimaxConnection > connection, int availableSymbols, WimaxPhy::ModulationType modulationType)
void SetDiuc(uint8_t diuc)
static TypeId GetTypeId(void)
NS_OBJECT_ENSURE_REGISTERED(AntennaModel)
void BSSchedulerRTPSConnection(uint32_t &availableSymbols)
Downlink Scheduler for rtPS connections.
Ptr< PacketBurst > CreateUgsBurst(ServiceFlow *serviceFlow, WimaxPhy::ModulationType modulationType, uint32_t availableSymbols)
void BSSchedulerBasicConnection(uint32_t &availableSymbols)
virtual Ptr< BaseStationNetDevice > GetBs(void)
bool SelectConnection(Ptr< WimaxConnection > &connection)
virtual void SetBs(Ptr< BaseStationNetDevice > bs)
void AddDownlinkBurst(Ptr< const WimaxConnection > connection, uint8_t diuc, WimaxPhy::ModulationType modulationType, Ptr< PacketBurst > burst)
#define NS_ASSERT_MSG(condition, message)
void BSSchedulerPrimaryConnection(uint32_t &availableSymbols)
void Schedule(void)
Schedule function.
void SetDlTimeStamp(Time dlTimeStamp)
Set the DlTimeStamp.
Time GetDlTimeStamp(void) const
#define NS_LOG_DEBUG(msg)
std::list< std::pair< OfdmDlMapIe *, Ptr< PacketBurst > > > * m_downlinkBursts
uint16_t GetIdentifier(void) const
a base class which provides memory management and object aggregation
void BSSchedulerNRTPSConnection(uint32_t &availableSymbols)
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
void BSSchedulerBEConnection(uint32_t &availableSymbols)
bool HasPackets(void) const