21 #include "ns3/simulator.h"
24 #include "ss-scheduler.h"
25 #include "ss-net-device.h"
26 #include "wimax-phy.h"
27 #include "wimax-mac-queue.h"
28 #include "wimax-connection.h"
29 #include "connection-manager.h"
30 #include "service-flow.h"
31 #include "service-flow-record.h"
32 #include "service-flow-manager.h"
37 NS_OBJECT_ENSURE_REGISTERED (SSScheduler);
39 TypeId SSScheduler::GetTypeId (
void)
41 static TypeId tid = TypeId (
"ns3::SSScheduler")
42 .SetParent<Object> ();
46 SSScheduler::SSScheduler (Ptr<SubscriberStationNetDevice> ss)
52 SSScheduler::~SSScheduler (
void)
63 SSScheduler::SetPollMe (
bool pollMe)
69 SSScheduler::GetPollMe (
void)
const
76 WimaxPhy::ModulationType modulationType,
82 uint16_t nrSymbolsRequired = 0;
86 connection = SelectConnection ();
91 "SS: Error while scheduling packets: The selected connection has no packets");
96 while (connection && connection->HasPackets (packetType))
98 NS_LOG_INFO (
"FRAG_DEBUG: SS Scheduler" << std::endl);
100 uint32_t availableByte = m_ss->GetPhy ()->
101 GetNrBytes (availableSymbols, modulationType);
103 uint32_t requiredByte = connection->GetQueue ()->GetFirstPacketRequiredByte (packetType);
105 NS_LOG_INFO (
"\t availableByte = " << availableByte <<
106 ", requiredByte = " << requiredByte);
108 if (availableByte >= requiredByte)
112 "\n\t Send packet without other fragmentation" << std::endl);
114 packet = connection->Dequeue (packetType);
115 burst->AddPacket (packet);
117 nrSymbolsRequired = m_ss->GetPhy ()->
118 GetNrSymbols (packet->
GetSize (), modulationType);
119 availableSymbols -= nrSymbolsRequired;
123 if (connection->GetType () == Cid::TRANSPORT)
126 "\n\t Check if the fragmentation is possible");
128 uint32_t headerSize = connection->GetQueue ()->GetFirstPacketHdrSize (packetType);
129 if (!connection->GetQueue ()->CheckForFragmentation (packetType))
134 NS_LOG_INFO (
"\t availableByte = " << availableByte <<
135 " headerSize = " << headerSize);
137 if (availableByte > headerSize)
140 packet = connection->Dequeue (packetType, availableByte);
141 burst->AddPacket (packet);
143 nrSymbolsRequired = m_ss->GetPhy ()->
144 GetNrSymbols (packet->
GetSize (), modulationType);
145 availableSymbols -= nrSymbolsRequired;
149 NS_LOG_INFO (
"\t Fragmentation IS NOT possible" << std::endl);
156 "\n\t Fragmentation IS NOT possible, " << std::endl);
165 SSScheduler::SelectConnection (
void)
168 std::vector<ServiceFlow*>::const_iterator iter;
169 std::vector<ServiceFlow*> serviceFlows;
171 NS_LOG_INFO (
"SS Scheduler: Selecting connection...");
172 if (m_ss->GetInitialRangingConnection ()->HasPackets ())
174 NS_LOG_INFO (
"Return GetInitialRangingConnection");
175 return m_ss->GetInitialRangingConnection ();
177 if (m_ss->GetBasicConnection ()->HasPackets ())
180 return m_ss->GetBasicConnection ();
182 if (m_ss->GetPrimaryConnection ()->HasPackets ())
185 return m_ss->GetPrimaryConnection ();
188 serviceFlows = m_ss->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_UGS);
189 for (iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
193 if ((*iter)->HasPackets () && (currentTime
195 (*iter)->GetUnsolicitedGrantInterval ())))
197 NS_LOG_INFO (
"Return UGS SF: CID = " << (*iter)->GetCid () <<
"SFID = "
198 << (*iter)->GetSfid ());
199 return (*iter)->GetConnection ();
206 serviceFlows = m_ss->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_RTPS);
207 for (iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
209 if ((*iter)->HasPackets (MacHeaderType::HEADER_TYPE_GENERIC)
210 && (currentTime + m_ss->GetPhy ()->GetFrameDuration ()
212 (*iter)->GetUnsolicitedPollingInterval ())))
214 NS_LOG_INFO (
"Return RTPS SF: CID = " << (*iter)->GetCid () <<
"SFID = "
215 << (*iter)->GetSfid ());
216 return (*iter)->GetConnection ();
220 serviceFlows = m_ss->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_NRTPS);
221 for (iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
223 if ((*iter)->HasPackets (MacHeaderType::HEADER_TYPE_GENERIC))
225 NS_LOG_INFO (
"Return NRTPS SF: CID = " << (*iter)->GetCid () <<
"SFID = "
226 << (*iter)->GetSfid ());
227 return (*iter)->GetConnection ();
231 serviceFlows = m_ss->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_BE);
232 for (iter = serviceFlows.begin (); iter != serviceFlows.end (); ++iter)
234 if ((*iter)->HasPackets (MacHeaderType::HEADER_TYPE_GENERIC))
236 NS_LOG_INFO (
"Return BE SF: CID = " << (*iter)->GetCid () <<
"SFID = "
237 << (*iter)->GetSfid ());
238 return (*iter)->GetConnection ();
242 if (m_ss->GetBroadcastConnection ()->HasPackets ())
244 return m_ss->GetBroadcastConnection ();
smart pointer class similar to boost::intrusive_ptr
Ptr< PacketBurst > Schedule(uint16_t availableSymbols, WimaxPhy::ModulationType modulationType, MacHeaderType::HeaderType packetType, Ptr< WimaxConnection > &connection)
#define NS_LOG_COMPONENT_DEFINE(name)
uint32_t GetSize(void) const
#define NS_ASSERT_MSG(condition, message)
Time MilliSeconds(uint64_t ms)
create ns3::Time instances in units of milliseconds.