This repository was archived by the owner on Feb 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathLcgScheduler.cc
More file actions
368 lines (303 loc) · 15 KB
/
LcgScheduler.cc
File metadata and controls
368 lines (303 loc) · 15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
//
// SimuLTE
//
// This file is part of a software released under the license included in file
// "license.pdf". This license can be also found at http://www.ltesimulator.com/
// The above file and the present reference are part of the software itself,
// and cannot be removed from it.
//
#include "stack/mac/scheduler/LcgScheduler.h"
#include "stack/mac/buffer/LteMacBuffer.h"
using namespace omnetpp;
LcgScheduler::LcgScheduler(LteMacUe* mac)
{
lastExecutionTime_ = 0;
mac_ = mac;
}
LcgScheduler::~LcgScheduler()
{
}
ScheduleList& LcgScheduler::schedule(unsigned int availableBytes, Direction grantDir)
{
/* clean up old schedule decisions
for each cid, this map will store the the amount of sent data (in SDUs)
*/
scheduleList_.clear();
/* clean up old schedule decisions
for each cid, this map will store the the amount of sent data (in bytes, useful for macSduRequest)
*/
scheduledBytesList_.clear();
/*
* Clean up scheduling support status map
*/
statusMap_.clear();
/*
* clean firstSduCid
*/
firstSduCid = 0;
// If true, assure a minimum reserved rate to all connection (LCP first
// phase), if false, provide a best effort service (LCP second phase)
bool priorityService = true;
bool firstSdu = true;
// reserve Bytes for MAC_HEADER
availableBytes -= MAC_HEADER;
LcgMap& lcgMap = mac_->getLcgMap();
if (lcgMap.empty())
return scheduleList_;
// for all traffic classes
for (unsigned short i = 0; i < UNKNOWN_TRAFFIC_TYPE; ++i)
{
// Prepare the iterators to cycle the entire scheduling set
std::pair<LcgMap::iterator, LcgMap::iterator> it_pair;
it_pair = lcgMap.equal_range((LteTrafficClass) i);
LcgMap::iterator it = it_pair.first, et = it_pair.second;
EV << NOW << " LcgScheduler::schedule - Node " << mac_->getMacNodeId() << ", Starting priority service for traffic class " << i << endl;
//! FIXME Allocation of the same resource to flows with same priority not implemented - not suitable with relays
for (; it != et; ++it)
{
// processing all connections of same traffic class
// get the connection virtual buffer
LteMacBuffer* vQueue = it->second.second;
// get the buffer size
unsigned int queueLength = vQueue->getQueueOccupancy(); // in bytes
// connection id of the processed connection
MacCid cid = it->second.first;
// get the Flow descriptor
FlowControlInfo connDesc = mac_->getConnDesc().at(cid);
// TODO get the QoS parameters
// connection must have the same direction of the grant
if (connDesc.getDirection() != grantDir){
continue;
}
// Check whether the virtual buffer is empty
if (queueLength == 0)
{
EV << "LcgScheduler::schedule scheduled connection is no more active " << endl;
continue; // go to next connection
}
unsigned int toServe = queueLength;
// we need to consider also the size of RLC and MAC headers
if (connDesc.getRlcType() == UM)
toServe += RLC_HEADER_UM;
else if (connDesc.getRlcType() == AM)
toServe += RLC_HEADER_AM;
// get a pointer to the appropriate status element: we need a tracing element
// in order to store information about connections and data transmitted. These
// information may be consulted at the end of the LCP algorithm
StatusElem* elem;
if (statusMap_.find(cid) == statusMap_.end())
{
// the element does not exist, initialize it
elem = &statusMap_[cid];
elem->occupancy_ = vQueue->getQueueOccupancy(); // in bytes
elem->sentData_ = 0;
elem->sentSdus_ = 0;
// TODO set bucket from QoS parameters
elem->bucket_ = 1000;
}
else
{
elem = &statusMap_[cid];
}
EV << NOW << " LcgScheduler::schedule Node " << mac_->getMacNodeId() << " , Parameters:" << endl;
EV << "\t Logical Channel ID: " << MacCidToLcid(cid) << endl;
EV << "\t CID: " << cid << endl;
// fprintf(stderr, "\tGroup ID: %d\n", desc->parameters_.groupId_);
// fprintf(stderr, "\tPriority: %d\n", desc->parameters_.priority_);
// fprintf(stderr, "\tMin Reserved Rate: %.0lf bytes/s\n", desc->parameters_.minReservedRate_);
// fprintf(stderr, "\tMax Burst: %.0lf bytes\n", desc->parameters_.maxBurst_);
if (priorityService)
{
// Update bucket value for this connection
// get the actual bucket value and the configured max size
double bucket = elem->bucket_; // TODO parameters -> bucket ;
double maximumBucketSize = 10000.0; // TODO parameters -> maxBurst;
EV << NOW << " LcgScheduler::schedule Bucket size: " << bucket << " bytes (max size " << maximumBucketSize << " bytes) - BEFORE SERVICE " << endl;
// if the connection started before last scheduling event , use the
// global time interval
if (lastExecutionTime_ > 0)
{ // TODO desc->parameters_.startTime_) {
// PBR*(n*TTI) where n is the number of TTI from last update
bucket += /* TODO desc->parameters_.minReservedRate_*/ 100.0 * TTI;
}
// otherwise, set the bucket value accordingly to the start time
else
{
simtime_t localTimeInterval = NOW - 0/* TODO desc->parameters_.startTime_ */;
if (localTimeInterval < 0)
localTimeInterval = 0;
bucket = /* TODO desc->parameters_.minReservedRate_*/ 100.0 * localTimeInterval.dbl();
}
// do not overflow the maximum bucket size
if (bucket > maximumBucketSize)
bucket = maximumBucketSize;
// update connection's bucket
// TODO desc->parameters_.bucket_ = bucket;
// update the tracing element accordingly
elem->bucket_ = 100.0; // TODO desc->parameters_.bucket_;
EV << NOW << " LcgScheduler::schedule Bucket size: " << bucket << " bytes (max size " << maximumBucketSize << " bytes) - AFTER SERVICE " << endl;
}
EV << NOW << " LcgScheduler::schedule - Node " << mac_->getMacNodeId() << ", remaining grant: " << availableBytes << " bytes " << endl;
EV << NOW << " LcgScheduler::schedule - Node " << mac_->getMacNodeId() << " buffer Size: " << toServe << " bytes " << endl;
// If priority service: (availableBytes>0) && (desc->buffer_.occupancy() > 0) && (desc->parameters_.bucket_ > 0)
// If best effort service: (availableBytes>0) && (desc->buffer_.occupancy() > 0)
if ((availableBytes > 0) && (toServe > 0)
&& (!priorityService || 1 /*TODO (desc->parameters_.bucket_ > 0)*/))
{
// Check if it is possible to serve the sdu, depending on the constraint
// of the type of service
// Priority service:
// ( sdu->size() <= availableBytes) && ( sdu->size() <= desc->parameters_.bucket_)
// Best Effort service:
// ( sdu->size() <= availableBytes) && (!priorityService_)
if ((toServe <= availableBytes) /*&& ( !priorityService || ( sduSize <= 0) ) // TODO desc->parameters_.bucket_*/)
{
// remove SDU from virtual buffer
vQueue->popFront();
if (priorityService)
{
// TODO desc->parameters_.bucket_ -= sduSize;
// // update the tracing element accordingly
// TODO elem->bucket_ = 100.0 /* TODO desc->parameters_.bucket_*/;
}
// update the tracing element
elem->occupancy_ = vQueue->getQueueOccupancy();
elem->sentData_ += toServe;
// check if there is space for a SDU
int alloc = toServe;
if (connDesc.getRlcType() == UM)
alloc -= RLC_HEADER_UM;
else if (connDesc.getRlcType() == AM)
alloc -= RLC_HEADER_AM;
if (alloc > 0)
elem->sentSdus_++;
availableBytes -= toServe;
while (!vQueue->isEmpty())
{
// remove SDUs from virtual buffer
vQueue->popFront();
}
toServe = 0;
EV << NOW << " LcgScheduler::schedule - Node " << mac_->getMacNodeId() << ", SDU of size " << elem->sentData_ << " selected for transmission" << endl;
EV << NOW << " LcgScheduler::schedule - Node " << mac_->getMacNodeId() << ", remaining grant: " << availableBytes << " bytes" << endl;
EV << NOW << " LcgScheduler::schedule - Node " << mac_->getMacNodeId() << " buffer Size: " << toServe << " bytes" << endl;
}
else
{
if (priorityService)
{
// TODO desc->parameters_.bucket_ -= sduSize;
// // update the tracing element accordingly
// TODO elem->bucket_ = 100.0 /* TODO desc->parameters_.bucket_*/;
}
// update the tracing element
elem->occupancy_ = vQueue->getQueueOccupancy();
elem->sentData_ += availableBytes;
int alloc = availableBytes;
if (connDesc.getRlcType() == UM)
alloc -= RLC_HEADER_UM;
else if (connDesc.getRlcType() == AM)
alloc -= RLC_HEADER_AM;
// check if there is space for a SDU
if (alloc > 0)
elem->sentSdus_++;
// update buffer
while (alloc > 0)
{
// update pkt info
PacketInfo newPktInfo = vQueue->popFront();
if (newPktInfo.first > alloc)
{
newPktInfo.first = newPktInfo.first - alloc;
vQueue->pushFront(newPktInfo);
alloc = 0;
}
else
{
alloc -= newPktInfo.first;
}
}
toServe -= availableBytes;
availableBytes = 0;
EV << NOW << " LcgScheduler::schedule - Node " << mac_->getMacNodeId() << ", SDU of size " << elem->sentData_ << " selected for transmission" << endl;
EV << NOW << " LcgScheduler::schedule - Node " << mac_->getMacNodeId() << ", remaining grant: " << availableBytes << " bytes" << endl;
EV << NOW << " LcgScheduler::schedule - Node " << mac_->getMacNodeId() << " buffer Size: " << toServe << " bytes" << endl;
}
}
// check if flow is still backlogged
if (availableBytes > 0)
{
// TODO the priority is higher when the associated integer is lower ( e.g. priority 2 is
// greater than 4 )
//
// if ( desc->parameters_.priority_ >= lowestBackloggedPriority_ ) {
//
// if(LteDebug::trace("LcgScheduler::schedule"))
// fprintf(stderr,"%.9f LcgScheduler::schedule - Node %d, this flow priority: %u (old lowest priority %u) - LOWEST FOR NOW\n", NOW, nodeId_, desc->parameters_.priority_, lowestBackloggedPriority_);
//
// // store the new lowest backlogged flow and its priority
// lowestBackloggedFlow_ = fid;
// lowestBackloggedPriority_ = desc->parameters_.priority_;
}
//
//
// if ( highestBackloggedPriority_ == -1 || desc->parameters_.priority_ <= highestBackloggedPriority_ ) {
//
// if(LteDebug::trace("LcgScheduler::schedule"))
// fprintf(stderr,"%.9f LcgScheduler::schedule - Node %d, this flow priority: %u (old highest priority %u) - HIGHEST FOR NOW\n", NOW, nodeId_, desc->parameters_.priority_, highestBackloggedPriority_);
//
// // store the new highest backlogged flow and its priority
// highestBackloggedFlow_ = fid;
// highestBackloggedPriority_ = desc->parameters_.priority_;
// }
//
// }
//
// update the last schedule time
lastExecutionTime_ = NOW;
// signal service for current connection
unsigned int* servicedSdu = nullptr;
if (elem->sentData_ > 0 && firstSdu){
// if current element was scheduled and it is the first add MAC_HEADER
elem->sentData_ += MAC_HEADER;
firstSdu = false;
firstSduCid = cid; // remeber first cid for first sdu
}
if (scheduleList_.find(cid) == scheduleList_.end())
{
// the element does not exist, initialize it
servicedSdu = &scheduleList_[cid];
*servicedSdu = elem->sentSdus_;
}
else
{
// connection already scheduled during this TTI
servicedSdu = &scheduleList_.at(cid);
}
// update scheduled bytes
if (scheduledBytesList_.find(cid) == scheduledBytesList_.end())
{
scheduledBytesList_[cid] = elem->sentData_;
}
else
{
scheduledBytesList_[cid] += elem->sentData_;
}
// If the end of the connections map is reached and we were on priority and on last traffic class
if (priorityService && (it == et) && ((i + 1) == (unsigned short) UNKNOWN_TRAFFIC_TYPE))
{
// the first phase of the LCP algorithm has completed ...
// ... switch to best effort allocation!
priorityService = false;
// reset traffic class
i = 0;
EV << "LcgScheduler::schedule - Node" << mac_->getMacNodeId() << ", Starting best effort service" << endl;
}
} // END of connections cycle
} // END of Traffic Classes cycle
return scheduleList_;
}
ScheduleList& LcgScheduler::getScheduledBytesList()
{
return scheduledBytesList_;
}