Parent: [05b0e6] (diff)

Download this file

DTPState.cc    463 lines (363 with data), 9.5 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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
//
// Copyright Š 2014 PRISTINE Consortium (http://ict-pristine.eu)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//
#include "DTPState.h"
Define_Module(DTPState);
DTPState::DTPState() {
initDefaults();
}
void DTPState::initialize(int step)
{
if(step == 0){
cDisplayString& disp = getDisplayString();
disp.setTagArg("p", 0, 240);
disp.setTagArg("p", 1, 50);
maxFlowSDUSize = par("maxSDUSize");
maxFlowPDUSize = par("maxPDUSize");
rtt = par("rtt");
winBased = par("winBased");
rateBased = par("rateBased");
rxPresent = par("rxPresent");
if(rxPresent || winBased || rateBased){
dtcpPresent = true;
//TODO A! create DTCP module here?
}
}
}
void DTPState::initDefaults(){
currentPDU = NULL;
dropDup = 0;
setDRFFlag = true;
dtcpPresent = false;
winBased = false;
rateBased = false;
incompDeliv = false;
lastSDUDelivered = 0;
rcvLeftWinEdge = 0;
maxSeqNumRcvd = 0;
nextSeqNumToSend = 1;
qoSCube = NULL;
seqNumRollOverThresh = INT_MAX - 1;
lastSeqNumSent = 0;
ecnSet = false;
}
void DTPState::clearPDUQ(std::vector<DataTransferPDU*>* pduQ)
{
std::vector<DataTransferPDU*>::iterator itP;
for (itP = pduQ->begin(); itP != pduQ->end();)
{
delete (*itP);
// delete (*it);
itP = pduQ->erase(itP);
}
}
void DTPState::clearReassemblyPDUQ()
{
clearPDUQ(&reassemblyPDUQ);
}
void DTPState::clearGeneratedPDUQ()
{
clearPDUQ(&generatedPDUs);
}
void DTPState::clearPostablePDUQ()
{
clearPDUQ(&postablePDUs);
}
DTPState::~DTPState() {
clearReassemblyPDUQ();
clearGeneratedPDUQ();
clearPostablePDUQ();
}
bool DTPState::isDtcpPresent() const {
return dtcpPresent;
}
void DTPState::setDtcpPresent(bool dtcpPresent) {
this->dtcpPresent = dtcpPresent;
}
bool DTPState::isIncompDeliv() const {
return incompDeliv;
}
void DTPState::setIncompDeliv(bool incompDeliv) {
this->incompDeliv = incompDeliv;
}
unsigned int DTPState::getMaxFlowPduSize() const {
return maxFlowPDUSize;
}
void DTPState::setMaxFlowPduSize(unsigned int maxFlowPduSize) {
maxFlowPDUSize = maxFlowPduSize;
}
unsigned int DTPState::getMaxFlowSduSize() const {
return maxFlowSDUSize;
}
void DTPState::setMaxFlowSduSize(unsigned int maxFlowSduSize) {
maxFlowSDUSize = maxFlowSduSize;
}
unsigned int DTPState::getMaxSeqNumRcvd() const {
return maxSeqNumRcvd;
}
void DTPState::setMaxSeqNumRcvd(unsigned int maxSeqNumRcvd) {
this->maxSeqNumRcvd = (this->maxSeqNumRcvd > maxSeqNumRcvd) ? this->maxSeqNumRcvd : maxSeqNumRcvd;
}
void DTPState::incMaxSeqNumRcvd() {
maxSeqNumRcvd++;
}
void DTPState::incRcvLeftWindowEdge() {
rcvLeftWinEdge++;
}
/*
* Returns value of nextSeqNumToSend and increments it
* @return nextSeqNumToSend
*/
unsigned int DTPState::getNextSeqNumToSend() {
return nextSeqNumToSend++;
}
unsigned int DTPState::getNextSeqNumToSendWithoutIncrement() {
return nextSeqNumToSend;
}
void DTPState::setNextSeqNumToSend(unsigned int nextSeqNumToSend) {
this->nextSeqNumToSend = nextSeqNumToSend;
}
void DTPState::incNextSeqNumToSend(){
//TODO A1 what about threshold?
this->nextSeqNumToSend++;
}
bool DTPState::isPartDeliv() const {
return partDeliv;
}
void DTPState::setPartDeliv(bool partDeliv) {
this->partDeliv = partDeliv;
}
bool DTPState::isRateBased() const {
return rateBased;
}
void DTPState::setRateBased(bool rateBased) {
this->rateBased = rateBased;
}
//bool DTPState::isRateFullfilled() const {
// return rateFullfilled;
//}
//
//void DTPState::setRateFullfilled(bool rateFullfilled) {
// this->rateFullfilled = rateFullfilled;
//}
unsigned int DTPState::getRcvLeftWinEdge() const {
return rcvLeftWinEdge;
}
void DTPState::setRcvLeftWinEdge(unsigned int rcvLeftWinEdge) {
this->rcvLeftWinEdge = rcvLeftWinEdge;
}
bool DTPState::isRxPresent() const {
return rxPresent;
}
void DTPState::setRxPresent(bool rexmsnPresent) {
this->rxPresent = rexmsnPresent;
}
unsigned int DTPState::getSeqNumRollOverThresh() const {
return seqNumRollOverThresh;
}
void DTPState::setSeqNumRollOverThresh(unsigned int seqNumRollOverThresh) {
this->seqNumRollOverThresh = seqNumRollOverThresh;
}
int DTPState::getState() const {
return state;
}
void DTPState::setState(int state) {
this->state = state;
}
bool DTPState::isWinBased() const {
return winBased;
}
void DTPState::setWinBased(bool winBased) {
this->winBased = winBased;
}
bool DTPState::isSetDrfFlag() const
{
return setDRFFlag;
}
double DTPState::getRtt() const
{
//TODO B1 RTT estimator policy
return rtt;
}
void DTPState::setRtt(double rtt)
{
// this->rtt = (this->rtt + rtt)/2;
this->rtt = rtt;
}
void DTPState::setSetDrfFlag(bool setDrfFlag)
{
setDRFFlag = setDrfFlag;
}
unsigned int DTPState::getLastSeqNumSent() const
{
return lastSeqNumSent;
}
void DTPState::setLastSeqNumSent(unsigned int lastSeqNumSent)
{
this->lastSeqNumSent = lastSeqNumSent;
}
bool DTPState::isEcnSet() const
{
return ecnSet;
}
void DTPState::setEcnSet(bool ecnSet)
{
this->ecnSet = ecnSet;
}
const PDU* DTPState::getCurrentPdu() const
{
return currentPDU;
}
void DTPState::setCurrentPdu(PDU* currentPdu)
{
currentPDU = currentPdu;
}
std::vector<DataTransferPDU*>* DTPState::getReassemblyPDUQ()
{
return &reassemblyPDUQ;
}
void DTPState::pushBackToReassemblyPDUQ(DataTransferPDU* pdu)
{
//TODO check if this PDU is already on the queue (I believe the FSM is broken and it might try to add one PDU twice)
reassemblyPDUQ.push_back(pdu);
}
void DTPState::addPDUToReassemblyQ(DataTransferPDU* pdu)
{
if (pdu != NULL)
{
if (reassemblyPDUQ.empty())
{
reassemblyPDUQ.push_back(pdu);
}
else
{
if (reassemblyPDUQ.front()->getSeqNum() > pdu->getSeqNum())
{
reassemblyPDUQ.insert(reassemblyPDUQ.begin(), pdu);
}
else
{
for (std::vector<DataTransferPDU*>::iterator it = reassemblyPDUQ.begin(); it != reassemblyPDUQ.end(); ++it)
{
if ((*it)->getSeqNum() == pdu->getSeqNum())
{
//Not sure if this case could ever happen; EDIT: No, this SHOULD not ever happen.
//Throw Error.
throw cRuntimeError("addPDUTo reassemblyQ with same seqNum. SHOULD not ever happen");
}
else if ((*it)->getSeqNum() > pdu->getSeqNum())
{
/* Put the incoming PDU before one with bigger seqNum */
reassemblyPDUQ.insert(it, pdu);
break;
}
else if (it == --reassemblyPDUQ.end())
{
//'it' is last element
reassemblyPDUQ.insert(it + 1, pdu);
break;
}
}
}
}
}
}
PDUQ_t* DTPState::getGeneratedPDUQ(){
return &generatedPDUs;
}
void DTPState::pushBackToGeneratedPDUQ(DataTransferPDU* pdu)
{
generatedPDUs.push_back(pdu);
}
PDUQ_t* DTPState::getPostablePDUQ(){
return &postablePDUs;
}
void DTPState::pushBackToPostablePDUQ(DataTransferPDU* pdu){
postablePDUs.push_back(pdu);
}
unsigned int DTPState::getDropDup() const
{
return dropDup;
}
const QoSCube* DTPState::getQoSCube() const
{
return qoSCube;
}
unsigned int DTPState::getLastSduDelivered() const
{
return lastSDUDelivered;
}
void DTPState::setLastSduDelivered(unsigned int lastSduDelivered)
{
lastSDUDelivered = lastSduDelivered;
}
void DTPState::setQoSCube(const QoSCube*& qoSCube)
{
this->qoSCube = qoSCube;
}
void DTPState::updateRcvLWE(unsigned int seqNum)
{
//TODO A3
//Update LeftWindowEdge removing allowed gaps;
unsigned int sduGap = qoSCube->getMaxAllowGap();
if (isDtcpPresent())
{
PDUQ_t::iterator it;
PDUQ_t* pduQ = &reassemblyPDUQ;
for (it = pduQ->begin(); it != pduQ->end(); ++it)
{
if ((*it)->getSeqNum() == getRcvLeftWinEdge())
{
incRcvLeftWindowEdge();
}
else if ((*it)->getSeqNum() < getRcvLeftWinEdge())
{
continue;
}
else
{
if (pduQ->size() == 1 || it == pduQ->begin())
{
if ((*it)->getSDUSeqNum() <= getLastSduDelivered() + sduGap)
{
setRcvLeftWinEdge((*it)->getSeqNum());
}
}
else
{
(*(it - 1))->getSDUGap((*it));
}
break;
}
}
}
else
{
setRcvLeftWinEdge(std::max(getRcvLeftWinEdge(), seqNum));
// if(state.getRcvLeftWinEdge() > timer->getSeqNum()){
// throw cRuntimeError("RcvLeftWindowEdge SHOULD not be bigger than seqNum in A-Timer, right?");
// }else{
// state.setRcvLeftWinEdge(timer->getSeqNum());
// }
}
if(getRcvLeftWinEdge() < seqNum){
//TODO B1 Is it correct?
//We did not manage to move the RLWE to seqNum even with A-Timer and allowed gap -> signal error
}
}
void DTPState::handleMessage(cMessage* msg)
{
}