21 #include "bs-scheduler-simple.h"
22 #include "ns3/simulator.h"
23 #include "bs-net-device.h"
24 #include "ns3/packet-burst.h"
26 #include "wimax-mac-header.h"
27 #include "ss-record.h"
28 #include "wimax-mac-queue.h"
30 #include "burst-profile-manager.h"
31 #include "wimax-connection.h"
32 #include "connection-manager.h"
33 #include "ss-manager.h"
34 #include "service-flow.h"
35 #include "service-flow-record.h"
36 #include "service-flow-manager.h"
42 NS_OBJECT_ENSURE_REGISTERED (BSSchedulerSimple);
44 TypeId BSSchedulerSimple::GetTypeId (
void)
46 static TypeId tid = TypeId (
"ns3::BSSchedulerSimple").SetParent<Object> ().AddConstructor<BSSchedulerSimple> ();
50 BSSchedulerSimple::BSSchedulerSimple ()
51 : m_downlinkBursts (new std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst> > > ())
56 BSSchedulerSimple::BSSchedulerSimple (Ptr<BaseStationNetDevice> bs)
57 : m_downlinkBursts (new std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst> > > ())
64 BSSchedulerSimple::~BSSchedulerSimple (
void)
66 std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst> > > *downlinkBursts = m_downlinkBursts;
67 std::pair<OfdmDlMapIe*, Ptr<PacketBurst> > pair;
68 while (downlinkBursts->size ())
70 pair = downlinkBursts->front ();
75 delete m_downlinkBursts;
79 std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst> > >*
80 BSSchedulerSimple::GetDownlinkBursts (
void)
const
82 return m_downlinkBursts;
85 void BSSchedulerSimple::AddDownlinkBurst (Ptr<const WimaxConnection> connection,
87 WimaxPhy::ModulationType modulationType,
88 Ptr<PacketBurst> burst)
90 OfdmDlMapIe *dlMapIe =
new OfdmDlMapIe ();
91 dlMapIe->SetCid (connection->GetCid ());
92 dlMapIe->SetDiuc (diuc);
94 NS_LOG_INFO (
"BS scheduler, burst size: " << burst->GetSize () <<
" bytes" <<
", pkts: " << burst->GetNPackets ()
95 <<
", connection: " << connection->GetTypeStr () <<
", CID: " << connection->GetCid ());
96 if (connection->GetType () == Cid::TRANSPORT)
98 NS_LOG_INFO (
", SFID: " << connection->GetServiceFlow ()->GetSfid () <<
", service: "
99 << connection->GetServiceFlow ()->GetSchedulingTypeStr ());
101 NS_LOG_INFO (
", modulation: " << modulationType <<
", DIUC: " << (uint32_t) diuc);
103 m_downlinkBursts->push_back (std::make_pair (dlMapIe, burst));
106 void BSSchedulerSimple::Schedule (
void)
108 Ptr<WimaxConnection> connection;
109 WimaxPhy::ModulationType modulationType = WimaxPhy::MODULATION_TYPE_BPSK_12;
110 uint8_t diuc = OfdmDlBurstProfile::DIUC_BURST_PROFILE_1;
111 uint32_t nrSymbolsRequired = 0;
112 GenericMacHeader hdr;
114 Ptr<PacketBurst> burst;
115 ServiceFlow::SchedulingType schedulingType = ServiceFlow::SF_TYPE_NONE;
116 uint32_t availableSymbols = GetBs ()->GetNrDlSymbols ();
118 while (SelectConnection (connection))
120 if (connection != GetBs ()->GetInitialRangingConnection () && connection != GetBs ()->GetBroadcastConnection ())
123 if (connection->GetType () == Cid::MULTICAST)
125 modulationType = connection->GetServiceFlow ()->GetModulation ();
129 modulationType = GetBs ()->GetSSManager ()->GetSSRecord (connection->GetCid ())->GetModulationType ();
131 diuc = GetBs ()->GetBurstProfileManager ()->GetBurstProfile (modulationType,
132 WimaxNetDevice::DIRECTION_DOWNLINK);
134 else if (connection == GetBs ()->GetInitialRangingConnection () || connection
135 == GetBs ()->GetBroadcastConnection ())
138 modulationType = WimaxPhy::MODULATION_TYPE_BPSK_12;
139 diuc = OfdmDlBurstProfile::DIUC_BURST_PROFILE_1;
142 if (connection->GetType () == Cid::TRANSPORT || connection->GetType () == Cid::MULTICAST)
144 schedulingType = (ServiceFlow::SchedulingType) connection->GetSchedulingType ();
147 if (schedulingType == ServiceFlow::SF_TYPE_UGS)
149 nrSymbolsRequired = connection->GetServiceFlow ()->GetRecord ()->GetGrantSize ();
150 if (nrSymbolsRequired < availableSymbols)
152 burst = CreateUgsBurst (connection->GetServiceFlow (), modulationType, nrSymbolsRequired);
156 burst = CreateUgsBurst (connection->GetServiceFlow (), modulationType, availableSymbols);
158 if (burst->GetNPackets () != 0)
160 uint32_t BurstSizeSymbols = GetBs ()->GetPhy ()->GetNrSymbols (burst->GetSize (), modulationType);
161 AddDownlinkBurst (connection, diuc, modulationType, burst);
163 if (availableSymbols <= BurstSizeSymbols)
165 availableSymbols -= BurstSizeSymbols;
172 burst = Create<PacketBurst> ();
173 while (connection->HasPackets () ==
true)
175 uint32_t FirstPacketSize = connection->GetQueue ()->GetFirstPacketRequiredByte (MacHeaderType::HEADER_TYPE_GENERIC);
176 nrSymbolsRequired = GetBs ()->GetPhy ()->GetNrSymbols (FirstPacketSize, modulationType);
177 if (availableSymbols < nrSymbolsRequired && CheckForFragmentation (connection,
181 uint32_t availableByte = GetBs ()->GetPhy ()->GetNrBytes (availableSymbols, modulationType);
182 packet = connection->Dequeue (MacHeaderType::HEADER_TYPE_GENERIC, availableByte);
183 availableSymbols = 0;
185 else if (availableSymbols >= nrSymbolsRequired)
187 packet = connection->Dequeue ();
188 availableSymbols -= nrSymbolsRequired;
194 burst->AddPacket (packet);
196 AddDownlinkBurst (connection, diuc, modulationType, burst);
198 if (availableSymbols == 0)
205 if (m_downlinkBursts->size ())
207 NS_LOG_DEBUG (
"BS scheduler, number of bursts: " << m_downlinkBursts->size () <<
", symbols left: "
208 << availableSymbols << std::endl <<
"BS scheduler, queues:" <<
" IR "
209 << GetBs ()->GetInitialRangingConnection ()->GetQueue ()->GetSize () <<
" broadcast "
210 << GetBs ()->GetBroadcastConnection ()->GetQueue ()->GetSize () <<
" basic "
211 << GetBs ()->GetConnectionManager ()->GetNPackets (Cid::BASIC, ServiceFlow::SF_TYPE_NONE) <<
" primary "
212 << GetBs ()->GetConnectionManager ()->GetNPackets (Cid::PRIMARY, ServiceFlow::SF_TYPE_NONE) <<
" transport "
213 << GetBs ()->GetConnectionManager ()->GetNPackets (Cid::TRANSPORT, ServiceFlow::SF_TYPE_ALL));
217 bool BSSchedulerSimple::SelectConnection (Ptr<WimaxConnection> &connection)
221 std::vector<Ptr<WimaxConnection> >::const_iterator iter1;
222 std::vector<ServiceFlow*>::iterator iter2;
223 ServiceFlowRecord *serviceFlowRecord;
224 NS_LOG_INFO (
"BS Scheduler: Selecting connection...");
225 if (GetBs ()->GetBroadcastConnection ()->HasPackets ())
228 connection = GetBs ()->GetBroadcastConnection ();
231 else if (GetBs ()->GetInitialRangingConnection ()->HasPackets ())
233 NS_LOG_INFO (
"Return GetInitialRangingConnection");
234 connection = GetBs ()->GetInitialRangingConnection ();
239 std::vector<Ptr<WimaxConnection> > connections;
240 std::vector<ServiceFlow*> serviceFlows;
242 connections = GetBs ()->GetConnectionManager ()->GetConnections (Cid::BASIC);
243 for (iter1 = connections.begin (); iter1 != connections.end (); ++iter1)
245 if ((*iter1)->HasPackets ())
253 connections = GetBs ()->GetConnectionManager ()->GetConnections (Cid::PRIMARY);
254 for (iter1 = connections.begin (); iter1 != connections.end (); ++iter1)
256 if ((*iter1)->HasPackets ())
264 serviceFlows = GetBs ()->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_UGS);
265 for (iter2 = serviceFlows.begin (); iter2 != serviceFlows.end (); ++iter2)
267 serviceFlowRecord = (*iter2)->GetRecord ();
268 NS_LOG_INFO (
"processing UGS: HAS PACKET=" << (*iter2)->HasPackets () <<
"max Latency = "
269 <<
MilliSeconds ((*iter2)->GetMaximumLatency ()) <<
"Delay = " << ((currentTime
270 - serviceFlowRecord->GetDlTimeStamp ()) + GetBs ()->GetPhy ()->GetFrameDuration ()));
272 if ((*iter2)->HasPackets () && ((currentTime - serviceFlowRecord->GetDlTimeStamp ())
273 + GetBs ()->GetPhy ()->GetFrameDuration ()) >
MilliSeconds ((*iter2)->GetMaximumLatency ()))
275 serviceFlowRecord->SetDlTimeStamp (currentTime);
276 connection = (*iter2)->GetConnection ();
277 NS_LOG_INFO (
"Return UGS SF: CID = " << (*iter2)->GetCid () <<
"SFID = " << (*iter2)->GetSfid ());
282 serviceFlows = GetBs ()->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_RTPS);
283 for (iter2 = serviceFlows.begin (); iter2 != serviceFlows.end (); ++iter2)
285 serviceFlowRecord = (*iter2)->GetRecord ();
287 if ((*iter2)->HasPackets () && ((currentTime - serviceFlowRecord->GetDlTimeStamp ())
288 + GetBs ()->GetPhy ()->GetFrameDuration ()) >
MilliSeconds ((*iter2)->GetMaximumLatency ()))
290 serviceFlowRecord->SetDlTimeStamp (currentTime);
291 connection = (*iter2)->GetConnection ();
292 NS_LOG_INFO (
"Return RTPS SF: CID = " << (*iter2)->GetCid () <<
"SFID = " << (*iter2)->GetSfid ());
297 serviceFlows = GetBs ()->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_NRTPS);
298 for (iter2 = serviceFlows.begin (); iter2 != serviceFlows.end (); ++iter2)
300 serviceFlowRecord = (*iter2)->GetRecord ();
301 if ((*iter2)->HasPackets ())
303 NS_LOG_INFO (
"Return NRTPS SF: CID = " << (*iter2)->GetCid () <<
"SFID = " << (*iter2)->GetSfid ());
304 connection = (*iter2)->GetConnection ();
309 serviceFlows = GetBs ()->GetServiceFlowManager ()->GetServiceFlows (ServiceFlow::SF_TYPE_BE);
310 for (iter2 = serviceFlows.begin (); iter2 != serviceFlows.end (); ++iter2)
312 serviceFlowRecord = (*iter2)->GetRecord ();
313 if ((*iter2)->HasPackets ())
315 NS_LOG_INFO (
"Return BE SF: CID = " << (*iter2)->GetCid () <<
"SFID = " << (*iter2)->GetSfid ());
316 connection = (*iter2)->GetConnection ();
325 Ptr<PacketBurst> BSSchedulerSimple::CreateUgsBurst (ServiceFlow *serviceFlow,
326 WimaxPhy::ModulationType modulationType,
327 uint32_t availableSymbols)
330 GenericMacHeader hdr;
332 Ptr<PacketBurst> burst = Create<PacketBurst> ();
333 uint32_t nrSymbolsRequired = 0;
336 Ptr<WimaxConnection> connection = serviceFlow->GetConnection ();
337 while (serviceFlow->HasPackets ())
339 uint32_t FirstPacketSize = connection->GetQueue ()->GetFirstPacketRequiredByte (MacHeaderType::HEADER_TYPE_GENERIC);
340 nrSymbolsRequired = GetBs ()->GetPhy ()->GetNrSymbols (FirstPacketSize,modulationType);
341 if (availableSymbols < nrSymbolsRequired && CheckForFragmentation (connection,
345 uint32_t availableByte = GetBs ()->GetPhy ()->GetNrBytes (availableSymbols, modulationType);
346 packet = connection->Dequeue (MacHeaderType::HEADER_TYPE_GENERIC, availableByte);
347 availableSymbols = 0;
351 packet = connection->Dequeue ();
352 availableSymbols -= nrSymbolsRequired;
354 burst->AddPacket (packet);
355 if (availableSymbols <= 0)
#define NS_LOG_COMPONENT_DEFINE(name)
#define NS_LOG_DEBUG(msg)
Time MilliSeconds(uint64_t ms)
create ns3::Time instances in units of milliseconds.