23 #include "ns3/simulator.h"
25 #include "ns3/packet-burst.h"
50 .SetGroupName(
"Wimax")
73 std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst> > > *downlinkBursts =
m_downlinkBursts;
74 std::pair<OfdmDlMapIe*, Ptr<PacketBurst> > pair;
75 while (downlinkBursts->size ())
77 pair = downlinkBursts->front ();
87 std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst> > >*
100 dlMapIe->
SetCid (connection->GetCid ());
103 NS_LOG_INFO (
"BS scheduler, burst size: " << burst->GetSize () <<
" bytes" <<
", pkts: " << burst->GetNPackets ()
104 <<
", connection: " << connection->GetTypeStr () <<
", CID: "
105 << connection->GetCid ());
108 NS_LOG_INFO (
", SFID: " << connection->GetServiceFlow ()->GetSfid () <<
", service: "
109 << connection->GetServiceFlow ()->GetSchedulingTypeStr ());
111 NS_LOG_INFO (
", modulation: " << modulationType <<
", DIUC: " << (uint32_t) diuc);
134 uint32_t availableSymbols =
GetBs ()->GetNrDlSymbols ();
155 << availableSymbols << std::endl <<
"BS scheduler, queues:" <<
" IR "
156 <<
GetBs ()->GetInitialRangingConnection ()->GetQueue ()->
GetSize ()
158 <<
GetBs ()->GetBroadcastConnection ()->GetQueue ()->
GetSize ()
171 uint32_t availableSymbols)
177 uint32_t nrSymbolsRequired = 0;
184 nrSymbolsRequired =
GetBs ()->GetPhy ()->GetNrSymbols (FirstPacketSize,modulationType);
189 uint32_t availableByte =
GetBs ()->GetPhy ()->GetNrBytes (availableSymbols, modulationType);
191 availableSymbols = 0;
195 packet = connection->Dequeue ();
196 availableSymbols -= nrSymbolsRequired;
198 burst->AddPacket (packet);
199 if (availableSymbols <= 0)
220 uint32_t nrSymbolsRequired = 0;
225 while (
GetBs ()->GetBroadcastConnection ()->HasPackets () && availableSymbols > 0)
227 connection =
GetBs ()->GetBroadcastConnection ();
229 packet = connection->GetQueue ()->Peek (hdr);
230 nrSymbolsRequired =
GetBs ()->GetPhy ()->GetNrSymbols (packet->
GetSize (), modulationType);
232 if (availableSymbols < nrSymbolsRequired
237 else if (availableSymbols < nrSymbolsRequired
240 uint32_t availableByte =
GetBs ()->GetPhy ()->
241 GetNrBytes (availableSymbols, modulationType);
247 packet = connection->Dequeue ();
251 "Base station: Error while scheduling broadcast connection: header CID != connection CID");
252 burst->AddPacket (packet);
253 availableSymbols -= nrSymbolsRequired;
255 if (burst->GetNPackets () != 0)
267 uint32_t nrSymbolsRequired = 0;
272 while (
GetBs ()->GetInitialRangingConnection ()->HasPackets () && availableSymbols > 0)
274 connection =
GetBs ()->GetInitialRangingConnection ();
276 packet = connection->GetQueue ()->Peek (hdr);
277 nrSymbolsRequired =
GetBs ()->GetPhy ()->GetNrSymbols (packet->
GetSize (), modulationType);
280 if (availableSymbols < nrSymbolsRequired
285 else if (availableSymbols < nrSymbolsRequired
288 uint32_t availableByte =
GetBs ()->GetPhy ()->
289 GetNrBytes (availableSymbols, modulationType);
295 packet = connection->Dequeue ();
299 "Base station: Error while scheduling initial ranging connection: header CID != connection CID");
300 burst->AddPacket (packet);
301 availableSymbols -= nrSymbolsRequired;
303 if (burst->GetNPackets ())
315 uint32_t nrSymbolsRequired = 0;
320 std::vector<Ptr<WimaxConnection> >::const_iterator iter;
321 std::vector<Ptr<WimaxConnection> > connections;
323 connections =
GetBs ()->GetConnectionManager ()->GetConnections (
Cid::BASIC);
324 for (iter = connections.begin (); iter != connections.end (); ++iter)
326 while ((*iter)->HasPackets () && availableSymbols > 0)
330 modulationType =
GetBs ()->GetSSManager ()->GetSSRecord (connection->GetCid ())->GetModulationType ();
331 diuc =
GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
334 packet = connection->GetQueue ()->Peek (hdr);
335 nrSymbolsRequired =
GetBs ()->GetPhy ()->GetNrSymbols (packet->
GetSize (), modulationType);
338 if (availableSymbols < nrSymbolsRequired
343 else if (availableSymbols < nrSymbolsRequired
346 uint32_t availableByte =
GetBs ()->GetPhy ()->
347 GetNrBytes (availableSymbols, modulationType);
352 packet = connection->Dequeue ();
356 "Base station: Error while scheduling basic connection: header CID != connection CID");
357 burst->AddPacket (packet);
358 availableSymbols -= nrSymbolsRequired;
360 if (burst->GetNPackets () != 0)
363 burst = Create<PacketBurst> ();
374 uint32_t nrSymbolsRequired = 0;
379 std::vector<Ptr<WimaxConnection> >::const_iterator iter;
380 std::vector<Ptr<WimaxConnection> > connections;
383 for (iter = connections.begin (); iter != connections.end (); ++iter)
385 while ((*iter)->HasPackets () && availableSymbols > 0)
389 modulationType =
GetBs ()->GetSSManager ()->GetSSRecord (connection->GetCid ())->GetModulationType ();
390 diuc =
GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
393 packet = connection->GetQueue ()->Peek (hdr);
394 nrSymbolsRequired =
GetBs ()->GetPhy ()->GetNrSymbols (packet->
GetSize (), modulationType);
397 if (availableSymbols < nrSymbolsRequired
402 else if (availableSymbols < nrSymbolsRequired
405 uint32_t availableByte =
GetBs ()->GetPhy ()->
406 GetNrBytes (availableSymbols, modulationType);
411 packet = connection->Dequeue ();
415 "Base station: Error while scheduling primary connection: header CID != connection CID");
416 burst->AddPacket (packet);
417 availableSymbols -= nrSymbolsRequired;
419 if (burst->GetNPackets () != 0)
432 uint32_t nrSymbolsRequired = 0;
439 std::vector<ServiceFlow*>::iterator iter;
441 std::vector<ServiceFlow*> serviceFlows;
444 for (iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
446 serviceFlowRecord = (*iter)->GetRecord ();
448 if ((*iter)->HasPackets () && ((currentTime - serviceFlowRecord->
GetDlTimeStamp ())
449 +
GetBs ()->GetPhy ()->GetFrameDuration ()) >
MilliSeconds ((*iter)->GetMaximumLatency ()))
451 connection = (*iter)->GetConnection ();
454 modulationType = connection->GetServiceFlow ()->GetModulation ();
458 modulationType =
GetBs ()->GetSSManager ()->GetSSRecord (connection->GetCid ())->GetModulationType ();
460 diuc =
GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
463 nrSymbolsRequired = connection->GetServiceFlow ()->GetRecord ()->GetGrantSize ();
466 if (availableSymbols > nrSymbolsRequired)
468 availableSymbols -= nrSymbolsRequired;
469 burst =
CreateUgsBurst (connection->GetServiceFlow (), modulationType, nrSymbolsRequired);
470 if (burst->GetNPackets () != 0)
475 burst = Create<PacketBurst> ();
494 std::vector<Ptr<WimaxConnection> > connections;
495 std::vector<ServiceFlow*>::iterator iter2;
497 std::vector<ServiceFlow*> serviceFlows;
499 uint32_t symbolsRequired[100];
504 uint32_t totSymbolsRequired = 0;
505 int nbConnection = 0;
507 NS_LOG_INFO (
"\tDL Scheduler for rtPS flows \n" <<
"\t\tavailableSymbols = " << availableSymbols);
511 for (iter2 = serviceFlows.begin (); iter2 != serviceFlows.end (); ++iter2)
514 serviceFlowRecord = (*iter2)->GetRecord ();
516 if ((*iter2)->HasPackets ())
520 rtPSConnection[nbConnection] = (*iter2)->GetConnection ();
523 modulationType_[nbConnection] = rtPSConnection[nbConnection]->GetServiceFlow ()->GetModulation ();
527 modulationType_[nbConnection]
528 =
GetBs ()->GetSSManager ()->GetSSRecord (rtPSConnection[nbConnection]->GetCid ())->GetModulationType ();
531 =
GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType_[nbConnection],
534 dataToSend = rtPSConnection[nbConnection]->GetQueue ()->GetQueueLengthWithMACOverhead ();
535 NS_LOG_INFO (
"\t\tRTPS DL Scheduler for CID = " << rtPSConnection[nbConnection]->GetCid ()
536 <<
"\n\t\t\t dataToSend = " << dataToSend);
538 symbolsRequired[nbConnection] =
GetBs ()->GetPhy ()->GetNrSymbols (dataToSend,
539 modulationType_[nbConnection]);
541 totSymbolsRequired += symbolsRequired[nbConnection];
546 NS_LOG_INFO (
"\t\ttotSymbolsRequired = " << totSymbolsRequired);
549 while (totSymbolsRequired > availableSymbols)
551 NS_LOG_INFO (
"\tDL Channel Saturation: totSymbolsRequired > availableSymbols_rtPS");
552 double delta = double(availableSymbols) / double(totSymbolsRequired);
554 totSymbolsRequired = 0;
555 for (
int i = 0; i < nbConnection; i++)
557 NS_LOG_INFO (
"\t\tprevious symbolsRequired[" << i <<
"] = " << symbolsRequired[i]);
558 symbolsRequired[i] = (uint32_t) std::floor (symbolsRequired[i] * delta);
559 totSymbolsRequired += symbolsRequired[i];
560 NS_LOG_INFO (
"\t\tnew symbolsRequired[" << i <<
"] = " << symbolsRequired[i]);
562 NS_LOG_INFO (
"\t\ttotSymbolsRequired = " << totSymbolsRequired);
566 for (
int i = 0; i < nbConnection; i++)
569 packet = rtPSConnection[i]->GetQueue ()->Peek (hdr);
570 uint32_t symbolsForPacketTransmission = 0;
571 burst = Create<PacketBurst> ();
572 NS_LOG_INFO (
"\t\tCID = " << rtPSConnection[i]->GetCid () <<
" assignedSymbols = " << symbolsRequired[i]);
574 while (symbolsRequired[i] > 0)
576 symbolsForPacketTransmission =
GetBs ()->GetPhy ()
577 ->GetNrSymbols (rtPSConnection[i]->GetQueue ()
582 if (symbolsForPacketTransmission > symbolsRequired[i]
589 else if (symbolsForPacketTransmission > symbolsRequired[i]
594 uint32_t availableByte =
GetBs ()->GetPhy ()->
595 GetNrBytes (symbolsRequired[i], modulationType_[i]);
597 symbolsRequired[i] = 0;
601 packet = rtPSConnection[i]->Dequeue ();
602 symbolsRequired[i] -= symbolsForPacketTransmission;
606 "Base station: Error while scheduling RTPs connection: header CID != connection CID");
607 burst->AddPacket (packet);
610 if (burst->GetNPackets () != 0)
616 availableSymbols -= totSymbolsRequired;
625 uint32_t nrSymbolsRequired = 0;
630 std::vector<ServiceFlow*>::iterator iter;
631 std::vector<ServiceFlow*> serviceFlows;
634 for (iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
636 connection = (*iter)->GetConnection ();
638 while ((*iter)->HasPackets () && availableSymbols > 0)
642 modulationType = connection->GetServiceFlow ()->GetModulation ();
646 modulationType =
GetBs ()->GetSSManager ()->GetSSRecord (connection->GetCid ())->GetModulationType ();
649 diuc =
GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
652 packet = connection->GetQueue ()->Peek (hdr);
653 nrSymbolsRequired =
GetBs ()->GetPhy ()->GetNrSymbols (packet->
GetSize (), modulationType);
655 if (availableSymbols < nrSymbolsRequired)
660 packet = connection->Dequeue ();
662 "Base station: Error while scheduling NRTPs connection: header CID != connection CID");
663 burst->AddPacket (packet);
664 availableSymbols -= nrSymbolsRequired;
666 if (burst->GetNPackets () != 0)
669 burst = Create<PacketBurst> ();
680 uint32_t nrSymbolsRequired = 0;
685 std::vector<ServiceFlow*>::iterator iter;
686 std::vector<ServiceFlow*> serviceFlows;
689 for (iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
691 connection = (*iter)->GetConnection ();
693 while ((*iter)->HasPackets () && availableSymbols > 0)
697 modulationType = connection->GetServiceFlow ()->GetModulation ();
701 modulationType =
GetBs ()->GetSSManager ()->GetSSRecord (connection->GetCid ())->GetModulationType ();
703 diuc =
GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
706 packet = connection->GetQueue ()->Peek (hdr);
707 nrSymbolsRequired =
GetBs ()->GetPhy ()->GetNrSymbols (packet->
GetSize (), modulationType);
709 if (availableSymbols < nrSymbolsRequired)
714 packet = connection->Dequeue ();
716 "Base station: Error while scheduling BE connection: header CID != connection CID");
717 burst->AddPacket (packet);
718 availableSymbols -= nrSymbolsRequired;
720 if (burst->GetNPackets () != 0)
723 burst = Create<PacketBurst> ();
virtual void SetBs(Ptr< BaseStationNetDevice > bs)
Set the base station.
virtual Ptr< BaseStationNetDevice > GetBs(void)
Get 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.
bool SelectConnection(Ptr< WimaxConnection > &connection)
Selects a connection from the list of connections having packets to be sent .
void BSSchedulerPrimaryConnection(uint32_t &availableSymbols)
schedules the primary connection
void Schedule(void)
Schedule function.
std::list< std::pair< OfdmDlMapIe *, Ptr< PacketBurst > > > * GetDownlinkBursts(void) const
This function returns all the downlink bursts scheduled for the next downlink sub-frame.
Ptr< PacketBurst > CreateUgsBurst(ServiceFlow *serviceFlow, WimaxPhy::ModulationType modulationType, uint32_t availableSymbols)
Creates a downlink UGS burst.
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 BSSchedulerInitialRangingConnection(uint32_t &availableSymbols)
schedules the IR connections
void AddDownlinkBurst(Ptr< const WimaxConnection > connection, uint8_t diuc, WimaxPhy::ModulationType modulationType, Ptr< PacketBurst > burst)
This function adds a downlink burst to the list of downlink bursts scheduled for the next downlink su...
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
static TypeId GetTypeId(void)
Get the type ID.
std::list< std::pair< OfdmDlMapIe *, Ptr< PacketBurst > > > * m_downlinkBursts
down link bursts
uint16_t GetIdentifier(void) 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
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Smart pointer class similar to boost::intrusive_ptr.
This class implements service flows as described by the IEEE-802.16 standard.
bool HasPackets(void) const
Check if packets are present.
Ptr< WimaxConnection > GetConnection(void) 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(void) const
static Time Now(void)
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.