A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
bs-scheduler-simple.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007,2008 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
18 */
19
20#include "bs-scheduler-simple.h"
21
22#include "bs-net-device.h"
24#include "cid.h"
25#include "connection-manager.h"
27#include "service-flow-record.h"
28#include "service-flow.h"
29#include "ss-manager.h"
30#include "ss-record.h"
31#include "wimax-connection.h"
32#include "wimax-mac-header.h"
33#include "wimax-mac-queue.h"
34
35#include "ns3/log.h"
36#include "ns3/packet-burst.h"
37#include "ns3/simulator.h"
38
39namespace ns3
40{
41
42NS_LOG_COMPONENT_DEFINE("BSSchedulerSimple");
43
44NS_OBJECT_ENSURE_REGISTERED(BSSchedulerSimple);
45
46TypeId
48{
49 static TypeId tid = TypeId("ns3::BSSchedulerSimple")
51 .SetGroupName("Wimax")
52 .AddConstructor<BSSchedulerSimple>();
53 return tid;
54}
55
57 : m_downlinkBursts(new std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst>>>())
58{
59 SetBs(nullptr);
60}
61
63 : m_downlinkBursts(new std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst>>>())
64{
65 // m_downlinkBursts is filled by AddDownlinkBurst and emptied by
66 // wimax-bs-net-device::sendBurst and wimax-ss-net-device::sendBurst
67 SetBs(bs);
68}
69
71{
72 std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst>>>* downlinkBursts = m_downlinkBursts;
73 std::pair<OfdmDlMapIe*, Ptr<PacketBurst>> pair;
74 while (!downlinkBursts->empty())
75 {
76 pair = downlinkBursts->front();
77 pair.second = nullptr;
78 delete pair.first;
79 }
80 SetBs(nullptr);
81 delete m_downlinkBursts;
82 m_downlinkBursts = nullptr;
83}
84
85std::list<std::pair<OfdmDlMapIe*, Ptr<PacketBurst>>>*
87{
88 return m_downlinkBursts;
89}
90
91void
93 uint8_t diuc,
94 WimaxPhy::ModulationType modulationType,
95 Ptr<PacketBurst> burst)
96{
97 auto dlMapIe = new OfdmDlMapIe();
98 dlMapIe->SetCid(connection->GetCid());
99 dlMapIe->SetDiuc(diuc);
100
101 NS_LOG_INFO("BS scheduler, burst size: " << burst->GetSize() << " bytes"
102 << ", pkts: " << burst->GetNPackets()
103 << ", connection: " << connection->GetTypeStr()
104 << ", CID: " << connection->GetCid());
105 if (connection->GetType() == Cid::TRANSPORT)
106 {
107 NS_LOG_INFO(", SFID: " << connection->GetServiceFlow()->GetSfid() << ", service: "
108 << connection->GetServiceFlow()->GetSchedulingTypeStr());
109 }
110 NS_LOG_INFO(", modulation: " << modulationType << ", DIUC: " << (uint32_t)diuc);
111
112 m_downlinkBursts->emplace_back(dlMapIe, burst);
113}
114
115void
117{
118 Ptr<WimaxConnection> connection;
121 uint32_t nrSymbolsRequired = 0;
123 Ptr<Packet> packet;
124 Ptr<PacketBurst> burst;
126 uint32_t availableSymbols = GetBs()->GetNrDlSymbols();
127
128 while (SelectConnection(connection))
129 {
130 if (connection != GetBs()->GetInitialRangingConnection() &&
131 connection != GetBs()->GetBroadcastConnection())
132 {
133 /* determines modulation/DIUC only once per burst as it is always same for a particular
134 * CID */
135 if (connection->GetType() == Cid::MULTICAST)
136 {
137 modulationType = connection->GetServiceFlow()->GetModulation();
138 }
139 else
140 {
141 modulationType =
142 GetBs()->GetSSManager()->GetSSRecord(connection->GetCid())->GetModulationType();
143 }
144 diuc = GetBs()->GetBurstProfileManager()->GetBurstProfile(
145 modulationType,
147 }
148 else if (connection == GetBs()->GetInitialRangingConnection() ||
149 connection == GetBs()->GetBroadcastConnection())
150 {
151 modulationType = WimaxPhy::MODULATION_TYPE_BPSK_12;
153 }
154
155 if (connection->GetType() == Cid::TRANSPORT || connection->GetType() == Cid::MULTICAST)
156 {
157 schedulingType = (ServiceFlow::SchedulingType)connection->GetSchedulingType();
158 }
159
160 if (schedulingType == ServiceFlow::SF_TYPE_UGS)
161 {
162 nrSymbolsRequired = connection->GetServiceFlow()->GetRecord()->GetGrantSize();
163 if (nrSymbolsRequired < availableSymbols)
164 {
165 burst =
166 CreateUgsBurst(connection->GetServiceFlow(), modulationType, nrSymbolsRequired);
167 }
168 else
169 {
170 burst =
171 CreateUgsBurst(connection->GetServiceFlow(), modulationType, availableSymbols);
172 }
173 if (burst->GetNPackets() != 0)
174 {
175 uint32_t BurstSizeSymbols =
176 GetBs()->GetPhy()->GetNrSymbols(burst->GetSize(), modulationType);
177 AddDownlinkBurst(connection, diuc, modulationType, burst);
178
179 if (availableSymbols <= BurstSizeSymbols)
180 {
181 availableSymbols -=
182 BurstSizeSymbols; /// \todo Overflows but don't know how to fix
183 break;
184 }
185 }
186 }
187 else
188 {
189 burst = Create<PacketBurst>();
190 while (connection->HasPackets())
191 {
192 uint32_t FirstPacketSize = connection->GetQueue()->GetFirstPacketRequiredByte(
194 nrSymbolsRequired =
195 GetBs()->GetPhy()->GetNrSymbols(FirstPacketSize, modulationType);
196 if (availableSymbols < nrSymbolsRequired &&
197 CheckForFragmentation(connection, availableSymbols, modulationType))
198 {
199 uint32_t availableByte =
200 GetBs()->GetPhy()->GetNrBytes(availableSymbols, modulationType);
201 packet = connection->Dequeue(MacHeaderType::HEADER_TYPE_GENERIC, availableByte);
202 availableSymbols = 0;
203 }
204 else if (availableSymbols >= nrSymbolsRequired)
205 {
206 packet = connection->Dequeue();
207 availableSymbols -= nrSymbolsRequired;
208 }
209 else
210 {
211 break;
212 }
213 burst->AddPacket(packet);
214 }
215 AddDownlinkBurst(connection, diuc, modulationType, burst);
216 }
217 if (availableSymbols == 0)
218 {
219 break;
220 }
221 }
222
223 if (!m_downlinkBursts->empty())
224 {
226 "BS scheduler, number of bursts: "
227 << m_downlinkBursts->size() << ", symbols left: " << availableSymbols << std::endl
228 << "BS scheduler, queues:"
229 << " IR " << GetBs()->GetInitialRangingConnection()->GetQueue()->GetSize()
230 << " broadcast " << GetBs()->GetBroadcastConnection()->GetQueue()->GetSize()
231 << " basic "
232 << GetBs()->GetConnectionManager()->GetNPackets(Cid::BASIC, ServiceFlow::SF_TYPE_NONE)
233 << " primary "
234 << GetBs()->GetConnectionManager()->GetNPackets(Cid::PRIMARY, ServiceFlow::SF_TYPE_NONE)
235 << " transport "
236 << GetBs()->GetConnectionManager()->GetNPackets(Cid::TRANSPORT,
238 }
239}
240
241bool
243{
244 connection = nullptr;
245 Time currentTime = Simulator::Now();
246 ServiceFlowRecord* serviceFlowRecord;
247 NS_LOG_INFO("BS Scheduler: Selecting connection...");
248 if (GetBs()->GetBroadcastConnection()->HasPackets())
249 {
250 NS_LOG_INFO("Return GetBroadcastConnection");
251 connection = GetBs()->GetBroadcastConnection();
252 return true;
253 }
254 else if (GetBs()->GetInitialRangingConnection()->HasPackets())
255 {
256 NS_LOG_INFO("Return GetInitialRangingConnection");
257 connection = GetBs()->GetInitialRangingConnection();
258 return true;
259 }
260 else
261 {
262 std::vector<Ptr<WimaxConnection>> connections;
263 std::vector<ServiceFlow*> serviceFlows;
264
265 connections = GetBs()->GetConnectionManager()->GetConnections(Cid::BASIC);
266 for (auto iter1 = connections.begin(); iter1 != connections.end(); ++iter1)
267 {
268 if ((*iter1)->HasPackets())
269 {
270 NS_LOG_INFO("Return Basic");
271 connection = *iter1;
272 return true;
273 }
274 }
275
276 connections = GetBs()->GetConnectionManager()->GetConnections(Cid::PRIMARY);
277 for (auto iter1 = connections.begin(); iter1 != connections.end(); ++iter1)
278 {
279 if ((*iter1)->HasPackets())
280 {
281 NS_LOG_INFO("Return Primary");
282 connection = *iter1;
283 return true;
284 }
285 }
286
287 serviceFlows = GetBs()->GetServiceFlowManager()->GetServiceFlows(ServiceFlow::SF_TYPE_UGS);
288 for (auto iter2 = serviceFlows.begin(); iter2 != serviceFlows.end(); ++iter2)
289 {
290 serviceFlowRecord = (*iter2)->GetRecord();
291 NS_LOG_INFO("processing UGS: HAS PACKET="
292 << (*iter2)->HasPackets() << "max Latency = "
293 << MilliSeconds((*iter2)->GetMaximumLatency()) << "Delay = "
294 << ((currentTime - serviceFlowRecord->GetDlTimeStamp()) +
295 GetBs()->GetPhy()->GetFrameDuration()));
296 // if latency would exceed in case grant is allocated in next frame then allocate in
297 // current frame
298 if ((*iter2)->HasPackets() && ((currentTime - serviceFlowRecord->GetDlTimeStamp()) +
299 GetBs()->GetPhy()->GetFrameDuration()) >
300 MilliSeconds((*iter2)->GetMaximumLatency()))
301 {
302 serviceFlowRecord->SetDlTimeStamp(currentTime);
303 connection = (*iter2)->GetConnection();
304 NS_LOG_INFO("Return UGS SF: CID = " << (*iter2)->GetCid()
305 << "SFID = " << (*iter2)->GetSfid());
306 return true;
307 }
308 }
309
310 serviceFlows = GetBs()->GetServiceFlowManager()->GetServiceFlows(ServiceFlow::SF_TYPE_RTPS);
311 for (auto iter2 = serviceFlows.begin(); iter2 != serviceFlows.end(); ++iter2)
312 {
313 serviceFlowRecord = (*iter2)->GetRecord();
314 // if latency would exceed in case poll is allocated in next frame then allocate in
315 // current frame
316 if ((*iter2)->HasPackets() && ((currentTime - serviceFlowRecord->GetDlTimeStamp()) +
317 GetBs()->GetPhy()->GetFrameDuration()) >
318 MilliSeconds((*iter2)->GetMaximumLatency()))
319 {
320 serviceFlowRecord->SetDlTimeStamp(currentTime);
321 connection = (*iter2)->GetConnection();
322 NS_LOG_INFO("Return RTPS SF: CID = " << (*iter2)->GetCid()
323 << "SFID = " << (*iter2)->GetSfid());
324 return true;
325 }
326 }
327
328 serviceFlows =
329 GetBs()->GetServiceFlowManager()->GetServiceFlows(ServiceFlow::SF_TYPE_NRTPS);
330 for (auto iter2 = serviceFlows.begin(); iter2 != serviceFlows.end(); ++iter2)
331 {
332 // unused: serviceFlowRecord = (*iter2)->GetRecord ();
333 if ((*iter2)->HasPackets())
334 {
335 NS_LOG_INFO("Return NRTPS SF: CID = " << (*iter2)->GetCid()
336 << "SFID = " << (*iter2)->GetSfid());
337 connection = (*iter2)->GetConnection();
338 return true;
339 }
340 }
341
342 serviceFlows = GetBs()->GetServiceFlowManager()->GetServiceFlows(ServiceFlow::SF_TYPE_BE);
343 for (auto iter2 = serviceFlows.begin(); iter2 != serviceFlows.end(); ++iter2)
344 {
345 // unused: serviceFlowRecord = (*iter2)->GetRecord ();
346 if ((*iter2)->HasPackets())
347 {
348 NS_LOG_INFO("Return BE SF: CID = " << (*iter2)->GetCid()
349 << "SFID = " << (*iter2)->GetSfid());
350 connection = (*iter2)->GetConnection();
351 return true;
352 }
353 }
354 }
355 NS_LOG_INFO("NO connection is selected!");
356 return false;
357}
358
361 WimaxPhy::ModulationType modulationType,
362 uint32_t availableSymbols)
363{
364 Time timeStamp;
366 Ptr<Packet> packet;
367 Ptr<PacketBurst> burst = Create<PacketBurst>();
368 uint32_t nrSymbolsRequired = 0;
369
370 // serviceFlow->CleanUpQueue ();
371 Ptr<WimaxConnection> connection = serviceFlow->GetConnection();
372 while (serviceFlow->HasPackets())
373 {
374 uint32_t FirstPacketSize =
375 connection->GetQueue()->GetFirstPacketRequiredByte(MacHeaderType::HEADER_TYPE_GENERIC);
376 nrSymbolsRequired = GetBs()->GetPhy()->GetNrSymbols(FirstPacketSize, modulationType);
377 if (availableSymbols < nrSymbolsRequired &&
378 CheckForFragmentation(connection, availableSymbols, modulationType))
379 {
380 uint32_t availableByte =
381 GetBs()->GetPhy()->GetNrBytes(availableSymbols, modulationType);
382 packet = connection->Dequeue(MacHeaderType::HEADER_TYPE_GENERIC, availableByte);
383 availableSymbols = 0;
384 }
385 else
386 {
387 packet = connection->Dequeue();
388 availableSymbols -= nrSymbolsRequired;
389 }
390 burst->AddPacket(packet);
391 if (availableSymbols <= 0)
392 {
393 break;
394 }
395 }
396 return burst;
397}
398
399} // namespace ns3
BaseStation Scheduler.
Definition: bs-scheduler.h:48
virtual Ptr< BaseStationNetDevice > GetBs()
Get the base station.
Definition: bs-scheduler.cc:89
virtual void SetBs(Ptr< BaseStationNetDevice > bs)
Set the base station.
Definition: bs-scheduler.cc:83
bool CheckForFragmentation(Ptr< WimaxConnection > connection, int availableSymbols, WimaxPhy::ModulationType modulationType)
Check if the packet fragmentation is possible for transport connection.
Definition: bs-scheduler.cc:95
BaseStation Scheduler - simplified.
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 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...
std::list< std::pair< OfdmDlMapIe *, Ptr< PacketBurst > > > * m_downlinkBursts
down link bursts
static TypeId GetTypeId()
Get the type ID.
void Schedule() override
the scheduling function for the downlink subframe.
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 .
@ PRIMARY
Definition: cid.h:45
@ TRANSPORT
Definition: cid.h:46
@ MULTICAST
Definition: cid.h:47
@ BASIC
Definition: cid.h:44
This class implements the Generic mac Header as described by IEEE Standard for Local and metropolitan...
This class implements the OFDM DL-MAP information element as described by "IEEE Standard for Local an...
this class implement a burst as a list of packets
Definition: packet-burst.h:37
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
This class implements service flows as described by the IEEE-802.16 standard.
Definition: service-flow.h:43
SchedulingType
section 11.13.11 Service flow scheduling type, page 701
Definition: service-flow.h:62
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.
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
ModulationType
ModulationType enumeration.
Definition: wimax-phy.h:54
@ MODULATION_TYPE_BPSK_12
Definition: wimax-phy.h:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:275
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1331
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.
Definition: wifi-utils.cc:132
STL namespace.
#define list