37#include "ns3/packet-burst.h"
38#include "ns3/simulator.h"
52 .SetGroupName(
"Wimax")
73 std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst>>>* downlinkBursts =
m_downlinkBursts;
74 std::pair<OfdmDlMapIe*, Ptr<PacketBurst>> pair;
75 while (!downlinkBursts->empty())
77 pair = downlinkBursts->front();
78 pair.second =
nullptr;
87std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst>>>*
100 dlMapIe->
SetCid(connection->GetCid());
103 NS_LOG_INFO(
"BS scheduler, burst size: " << burst->GetSize() <<
" bytes"
104 <<
", pkts: " << burst->GetNPackets()
105 <<
", connection: " << connection->GetTypeStr()
106 <<
", CID: " << connection->GetCid());
109 NS_LOG_INFO(
", SFID: " << connection->GetServiceFlow()->GetSfid() <<
", service: "
110 << connection->GetServiceFlow()->GetSchedulingTypeStr());
155 "BS scheduler, number of bursts: "
156 <<
m_downlinkBursts->size() <<
", symbols left: " << availableSymbols << std::endl
157 <<
"BS scheduler, queues:"
158 <<
" IR " <<
GetBs()->GetInitialRangingConnection()->GetQueue()->
GetSize()
159 <<
" broadcast " <<
GetBs()->GetBroadcastConnection()->GetQueue()->
GetSize()
187 nrSymbolsRequired =
GetBs()->GetPhy()->GetNrSymbols(FirstPacketSize, modulationType);
188 if (availableSymbols < nrSymbolsRequired &&
192 GetBs()->GetPhy()->GetNrBytes(availableSymbols, modulationType);
194 availableSymbols = 0;
198 packet = connection->Dequeue();
199 availableSymbols -= nrSymbolsRequired;
201 burst->AddPacket(packet);
202 if (availableSymbols <= 0)
227 while (
GetBs()->GetBroadcastConnection()->HasPackets() && availableSymbols > 0)
229 connection =
GetBs()->GetBroadcastConnection();
231 packet = connection->GetQueue()->Peek(hdr);
232 nrSymbolsRequired =
GetBs()->GetPhy()->GetNrSymbols(packet->GetSize(), modulationType);
234 if (availableSymbols < nrSymbolsRequired &&
239 else if (availableSymbols < nrSymbolsRequired &&
243 GetBs()->GetPhy()->GetNrBytes(availableSymbols, modulationType);
248 packet = connection->Dequeue();
252 "Base station: Error while scheduling broadcast connection: header CID != "
254 burst->AddPacket(packet);
255 availableSymbols -= nrSymbolsRequired;
257 if (burst->GetNPackets() != 0)
274 while (
GetBs()->GetInitialRangingConnection()->HasPackets() && availableSymbols > 0)
276 connection =
GetBs()->GetInitialRangingConnection();
278 packet = connection->GetQueue()->Peek(hdr);
279 nrSymbolsRequired =
GetBs()->GetPhy()->GetNrSymbols(packet->GetSize(), modulationType);
282 if (availableSymbols < nrSymbolsRequired &&
287 else if (availableSymbols < nrSymbolsRequired &&
291 GetBs()->GetPhy()->GetNrBytes(availableSymbols, modulationType);
296 packet = connection->Dequeue();
300 "Base station: Error while scheduling initial ranging connection: header CID "
301 "!= connection CID");
302 burst->AddPacket(packet);
303 availableSymbols -= nrSymbolsRequired;
305 if (burst->GetNPackets())
322 std::vector<Ptr<WimaxConnection>>::const_iterator iter;
323 std::vector<Ptr<WimaxConnection>> connections;
325 connections =
GetBs()->GetConnectionManager()->GetConnections(
Cid::BASIC);
326 for (iter = connections.begin(); iter != connections.end(); ++iter)
328 while ((*iter)->HasPackets() && availableSymbols > 0)
333 GetBs()->GetSSManager()->GetSSRecord(connection->GetCid())->GetModulationType();
334 diuc =
GetBs()->GetBurstProfileManager()->GetBurstProfile(
338 packet = connection->GetQueue()->Peek(hdr);
339 nrSymbolsRequired =
GetBs()->GetPhy()->GetNrSymbols(packet->GetSize(), modulationType);
342 if (availableSymbols < nrSymbolsRequired &&
347 else if (availableSymbols < nrSymbolsRequired &&
351 GetBs()->GetPhy()->GetNrBytes(availableSymbols, modulationType);
356 packet = connection->Dequeue();
360 "Base station: Error while scheduling basic connection: header CID != "
362 burst->AddPacket(packet);
363 availableSymbols -= nrSymbolsRequired;
365 if (burst->GetNPackets() != 0)
368 burst = Create<PacketBurst>();
384 std::vector<Ptr<WimaxConnection>>::const_iterator iter;
385 std::vector<Ptr<WimaxConnection>> connections;
388 for (iter = connections.begin(); iter != connections.end(); ++iter)
390 while ((*iter)->HasPackets() && availableSymbols > 0)
395 GetBs()->GetSSManager()->GetSSRecord(connection->GetCid())->GetModulationType();
396 diuc =
GetBs()->GetBurstProfileManager()->GetBurstProfile(
400 packet = connection->GetQueue()->Peek(hdr);
401 nrSymbolsRequired =
GetBs()->GetPhy()->GetNrSymbols(packet->GetSize(), modulationType);
404 if (availableSymbols < nrSymbolsRequired &&
409 else if (availableSymbols < nrSymbolsRequired &&
413 GetBs()->GetPhy()->GetNrBytes(availableSymbols, modulationType);
418 packet = connection->Dequeue();
422 "Base station: Error while scheduling primary connection: header CID != "
424 burst->AddPacket(packet);
425 availableSymbols -= nrSymbolsRequired;
427 if (burst->GetNPackets() != 0)
447 std::vector<ServiceFlow*>::iterator iter;
449 std::vector<ServiceFlow*> serviceFlows;
452 for (iter = serviceFlows.begin(); iter != serviceFlows.end(); ++iter)
454 serviceFlowRecord = (*iter)->GetRecord();
457 if ((*iter)->HasPackets() &&
459 GetBs()->GetPhy()->GetFrameDuration()) >
MilliSeconds((*iter)->GetMaximumLatency()))
461 connection = (*iter)->GetConnection();
464 modulationType = connection->GetServiceFlow()->GetModulation();
469 GetBs()->GetSSManager()->GetSSRecord(connection->GetCid())->GetModulationType();
471 diuc =
GetBs()->GetBurstProfileManager()->GetBurstProfile(
475 nrSymbolsRequired = connection->GetServiceFlow()->GetRecord()->GetGrantSize();
478 if (availableSymbols > nrSymbolsRequired)
480 availableSymbols -= nrSymbolsRequired;
482 CreateUgsBurst(connection->GetServiceFlow(), modulationType, nrSymbolsRequired);
483 if (burst->GetNPackets() != 0)
488 burst = Create<PacketBurst>();
505 std::vector<Ptr<WimaxConnection>> connections;
506 std::vector<ServiceFlow*>::iterator iter2;
508 std::vector<ServiceFlow*> serviceFlows;
516 int nbConnection = 0;
519 <<
"\t\tavailableSymbols = " << availableSymbols);
523 for (iter2 = serviceFlows.begin(); iter2 != serviceFlows.end(); ++iter2)
526 serviceFlowRecord = (*iter2)->GetRecord();
528 if ((*iter2)->HasPackets())
532 rtPSConnection[nbConnection] = (*iter2)->GetConnection();
535 modulationType_[nbConnection] =
536 rtPSConnection[nbConnection]->GetServiceFlow()->GetModulation();
540 modulationType_[nbConnection] =
543 ->GetSSRecord(rtPSConnection[nbConnection]->GetCid())
544 ->GetModulationType();
546 diuc_[nbConnection] =
GetBs()->GetBurstProfileManager()->GetBurstProfile(
547 modulationType_[nbConnection],
550 dataToSend = rtPSConnection[nbConnection]->GetQueue()->GetQueueLengthWithMACOverhead();
551 NS_LOG_INFO(
"\t\tRTPS DL Scheduler for CID = " << rtPSConnection[nbConnection]->GetCid()
552 <<
"\n\t\t\t dataToSend = "
555 symbolsRequired[nbConnection] =
556 GetBs()->GetPhy()->GetNrSymbols(dataToSend, modulationType_[nbConnection]);
558 totSymbolsRequired += symbolsRequired[nbConnection];
563 NS_LOG_INFO(
"\t\ttotSymbolsRequired = " << totSymbolsRequired);
566 while (totSymbolsRequired > availableSymbols)
568 NS_LOG_INFO(
"\tDL Channel Saturation: totSymbolsRequired > availableSymbols_rtPS");
569 double delta =
double(availableSymbols) /
double(totSymbolsRequired);
571 totSymbolsRequired = 0;
572 for (
int i = 0; i < nbConnection; i++)
574 NS_LOG_INFO(
"\t\tprevious symbolsRequired[" << i <<
"] = " << symbolsRequired[i]);
575 symbolsRequired[i] = (
uint32_t)std::floor(symbolsRequired[i] * delta);
576 totSymbolsRequired += symbolsRequired[i];
577 NS_LOG_INFO(
"\t\tnew symbolsRequired[" << i <<
"] = " << symbolsRequired[i]);
579 NS_LOG_INFO(
"\t\ttotSymbolsRequired = " << totSymbolsRequired);
583 for (
int i = 0; i < nbConnection; i++)
585 packet = rtPSConnection[i]->GetQueue()->Peek(hdr);
586 uint32_t symbolsForPacketTransmission = 0;
587 burst = Create<PacketBurst>();
588 NS_LOG_INFO(
"\t\tCID = " << rtPSConnection[i]->GetCid()
589 <<
" assignedSymbols = " << symbolsRequired[i]);
591 while (symbolsRequired[i] > 0)
593 symbolsForPacketTransmission =
GetBs()->GetPhy()->GetNrSymbols(
594 rtPSConnection[i]->GetQueue()->GetFirstPacketRequiredByte(
599 if (symbolsForPacketTransmission > symbolsRequired[i] &&
604 else if (symbolsForPacketTransmission > symbolsRequired[i] &&
610 GetBs()->GetPhy()->GetNrBytes(symbolsRequired[i], modulationType_[i]);
613 symbolsRequired[i] = 0;
617 packet = rtPSConnection[i]->Dequeue();
618 symbolsRequired[i] -= symbolsForPacketTransmission;
622 "Base station: Error while scheduling RTPs connection: header CID != "
624 burst->AddPacket(packet);
627 if (burst->GetNPackets() != 0)
633 availableSymbols -= totSymbolsRequired;
647 std::vector<ServiceFlow*>::iterator iter;
648 std::vector<ServiceFlow*> serviceFlows;
651 for (iter = serviceFlows.begin(); iter != serviceFlows.end(); ++iter)
653 connection = (*iter)->GetConnection();
655 while ((*iter)->HasPackets() && availableSymbols > 0)
659 modulationType = connection->GetServiceFlow()->GetModulation();
664 GetBs()->GetSSManager()->GetSSRecord(connection->GetCid())->GetModulationType();
667 diuc =
GetBs()->GetBurstProfileManager()->GetBurstProfile(
671 packet = connection->GetQueue()->Peek(hdr);
672 nrSymbolsRequired =
GetBs()->GetPhy()->GetNrSymbols(packet->GetSize(), modulationType);
674 if (availableSymbols < nrSymbolsRequired)
679 packet = connection->Dequeue();
681 "Base station: Error while scheduling NRTPs connection: header CID != "
683 burst->AddPacket(packet);
684 availableSymbols -= nrSymbolsRequired;
686 if (burst->GetNPackets() != 0)
689 burst = Create<PacketBurst>();
705 std::vector<ServiceFlow*>::iterator iter;
706 std::vector<ServiceFlow*> serviceFlows;
709 for (iter = serviceFlows.begin(); iter != serviceFlows.end(); ++iter)
711 connection = (*iter)->GetConnection();
713 while ((*iter)->HasPackets() && availableSymbols > 0)
717 modulationType = connection->GetServiceFlow()->GetModulation();
722 GetBs()->GetSSManager()->GetSSRecord(connection->GetCid())->GetModulationType();
724 diuc =
GetBs()->GetBurstProfileManager()->GetBurstProfile(
728 packet = connection->GetQueue()->Peek(hdr);
729 nrSymbolsRequired =
GetBs()->GetPhy()->GetNrSymbols(packet->GetSize(), modulationType);
731 if (availableSymbols < nrSymbolsRequired)
736 packet = connection->Dequeue();
738 hdr.
GetCid() == connection->GetCid(),
739 "Base station: Error while scheduling BE connection: header CID != connection CID");
740 burst->AddPacket(packet);
741 availableSymbols -= nrSymbolsRequired;
743 if (burst->GetNPackets() != 0)
746 burst = Create<PacketBurst>();
virtual Ptr< BaseStationNetDevice > GetBs()
Get the base station.
virtual void SetBs(Ptr< BaseStationNetDevice > bs)
Set the base station.
bool CheckForFragmentation(Ptr< WimaxConnection > connection, int availableSymbols, WimaxPhy::ModulationType modulationType)
Check if the packet fragmentation is possible for transport connection.
This class implements a simple downlink scheduler for rtPS flows.
static TypeId GetTypeId()
Get the type ID.
void Schedule() override
Schedule function.
void BSSchedulerPrimaryConnection(uint32_t &availableSymbols)
schedules the primary connection
std::list< std::pair< OfdmDlMapIe *, Ptr< PacketBurst > > > * GetDownlinkBursts() const override
This function returns all the downlink bursts scheduled for the next downlink sub-frame.
void BSSchedulerUGSConnection(uint32_t &availableSymbols)
schedules the UGS connection
void BSSchedulerBEConnection(uint32_t &availableSymbols)
schedules the BE connection
void BSSchedulerBasicConnection(uint32_t &availableSymbols)
schedules the basic connections
void AddDownlinkBurst(Ptr< const WimaxConnection > connection, uint8_t diuc, WimaxPhy::ModulationType modulationType, Ptr< PacketBurst > burst) override
This function adds a downlink burst to the list of downlink bursts scheduled for the next downlink su...
~BSSchedulerRtps() override
void BSSchedulerInitialRangingConnection(uint32_t &availableSymbols)
schedules the IR connections
void BSSchedulerRTPSConnection(uint32_t &availableSymbols)
Downlink Scheduler for rtPS connections.
void BSSchedulerBroadcastConnection(uint32_t &availableSymbols)
schedules the broadcast connections
void BSSchedulerNRTPSConnection(uint32_t &availableSymbols)
schedules the NRTPS connections
Ptr< PacketBurst > CreateUgsBurst(ServiceFlow *serviceFlow, WimaxPhy::ModulationType modulationType, uint32_t availableSymbols) override
Creates a downlink UGS burst.
bool SelectConnection(Ptr< WimaxConnection > &connection) override
Selects a connection from the list of connections having packets to be sent .
std::list< std::pair< OfdmDlMapIe *, Ptr< PacketBurst > > > * m_downlinkBursts
down link bursts
uint16_t GetIdentifier() const
This class implements the OFDM DL-MAP information element as described by "IEEE Standard for Local an...
void SetCid(Cid cid)
Set CID function.
void SetDiuc(uint8_t diuc)
Set DIUC field.
this class implement a burst as a list of packets
Smart pointer class similar to boost::intrusive_ptr.
This class implements service flows as described by the IEEE-802.16 standard.
bool HasPackets() const
Check if packets are present.
Ptr< WimaxConnection > GetConnection() const
Can return a null connection is this service flow has not been associated yet to a connection.
this class implements a structure to manage some parameters and statistics related to a service flow
void SetDlTimeStamp(Time dlTimeStamp)
Set the DlTimeStamp.
Time GetDlTimeStamp() const
static Time Now()
Return the current simulation virtual time.
Simulation virtual time values and global simulation resolution.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
ModulationType
ModulationType enumeration.
@ MODULATION_TYPE_BPSK_12
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t GetSize(Ptr< const Packet > packet, const WifiMacHeader *hdr, bool isAmpdu)
Return the total size of the packet after WifiMacHeader and FCS trailer have been added.