RINASim  October 2016
Documentation of framework for OMNeT++
DTPState.cc
Go to the documentation of this file.
1 // The MIT License (MIT)
2 //
3 // Copyright (c) 2014-2016 Brno University of Technology, PRISTINE project
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 // THE SOFTWARE.
22 
23 #include "DTPState.h"
24 
26 
28 
29 
30  initDefaults();
31 }
32 
33 double DTPState::getMPL() const
34 {
35  return mpl;
36 }
37 
38 void DTPState::setMpl(double mpl)
39 {
40  this->mpl = mpl;
41 }
42 
44 {
45  return blockingPort;
46 }
47 
48 void DTPState::setBlockingPort(bool blockingPort)
49 {
50  this->blockingPort = blockingPort;
51 }
52 
54 {
55  currentPDU = NULL;
56 // dropDup = 0;
57 // lastSDUDelivered = 0;
58  rcvLeftWinEdge = 0;
59  maxSeqNumRcvd = 0;
60  tmpAtimer = nullptr;
61  ecnSet = false;
62 }
63 
64 void DTPState::initialize(int step)
65 {
66  if(step == 0){
67 
68  cDisplayString& disp = getDisplayString();
69  disp.setTagArg("p", 0, 240);
70  disp.setTagArg("p", 1, 50);
71 
72  maxFlowSDUSize = getRINAModule<cModule*>(this, 3, {MOD_EFCP})->par("maxSDUSize");
73  maxFlowPDUSize = getRINAModule<cModule*>(this, 3, {MOD_EFCP})->par("maxPDUSize");
74 // delimitDelay = getRINAModule<cModule*>(this, 3, {MOD_EFCP})->par("delimitDelay");
75 
76  rtt = par("rtt");
77  if(getRINAModule<cModule*>(this, 2, {MOD_EFCP})->hasPar("rtt")){
78  rtt = getRINAModule<cModule*>(this, 2, {MOD_EFCP})->par("rtt");
79 
80  }
81 
82  mpl = par("mpl");
83  if(getRINAModule<cModule*>(this, 2, {MOD_EFCP})->hasPar("mpl")){
84  mpl = getRINAModule<cModule*>(this, 2, {MOD_EFCP})->par("mpl");
85 
86  }
87 
89  dtcpPresent = true;
90 
91  }
92  }
93 }
94 
96 {
97  /* Snd */
98  setDRFFlag = true;
99  nextSeqNumToSend = 1;
100  seqNumRollOverThresh = INT_MAX - 1;
101  lastSeqNumSent = 0;
102 }
103 
105 
106  dtcpPresent = false;
107  incompDeliv = false;
108  qoSCube = nullptr;
109 
110  /* Rcv */
111  currentPDU = NULL;
112  dropDup = 0;
113  lastSDUDelivered = 0;
114  rcvLeftWinEdge = 0;
115  maxSeqNumRcvd = 0;
116  tmpAtimer = nullptr;
117  ecnSet = false;
118 
119 
120  /* Snd */
121  resetSndVars();
122 
123  blockingPort = false;
124 
125 }
126 
127 void DTPState::clearPDUQ(std::vector<DataTransferPDU*>* pduQ)
128 {
129  std::vector<DataTransferPDU*>::iterator itP;
130  for (itP = pduQ->begin(); itP != pduQ->end();)
131  {
132  delete (*itP);
133  // delete (*it);
134  itP = pduQ->erase(itP);
135  }
136 }
137 
138 
139 
141 {
143 }
144 
146 {
148 }
149 
151 {
153 }
154 
156 
160 }
161 
163  return dtcpPresent;
164 }
165 
166 void DTPState::setDtcpPresent(bool dtcpPresent) {
167  this->dtcpPresent = dtcpPresent;
168 }
169 
171  return incompDeliv;
172 }
173 
174 void DTPState::setIncompDeliv(bool incompDeliv) {
175  this->incompDeliv = incompDeliv;
176 }
177 
178 unsigned int DTPState::getMaxFlowPduSize() const {
179  return maxFlowPDUSize;
180 }
181 
182 void DTPState::setMaxFlowPduSize(unsigned int maxFlowPduSize) {
183  maxFlowPDUSize = maxFlowPduSize;
184 }
185 
186 unsigned int DTPState::getMaxFlowSduSize() const {
187  return maxFlowSDUSize;
188 }
189 
190 void DTPState::setMaxFlowSduSize(unsigned int maxFlowSduSize) {
191  maxFlowSDUSize = maxFlowSduSize;
192 }
193 
194 unsigned int DTPState::getMaxSeqNumRcvd() const {
195  return maxSeqNumRcvd;
196 }
197 
198 void DTPState::setMaxSeqNumRcvd(unsigned int maxSeqNumRcvd) {
199 
200  this->maxSeqNumRcvd = (this->maxSeqNumRcvd > maxSeqNumRcvd) ? this->maxSeqNumRcvd : maxSeqNumRcvd;
201 }
202 
204  maxSeqNumRcvd++;
205 }
206 
208  rcvLeftWinEdge++;
209 }
210 
211 /*
212  * Returns value of nextSeqNumToSend and increments it
213  * @return nextSeqNumToSend
214  */
216 
217  return nextSeqNumToSend++;
218 }
219 
221 
222  return nextSeqNumToSend;
223 }
224 
225 void DTPState::setNextSeqNumToSend(unsigned int nextSeqNumToSend) {
226  this->nextSeqNumToSend = nextSeqNumToSend;
227 }
228 
230  //TODO A1 what about threshold?
231  this->nextSeqNumToSend++;
232 }
233 
234 bool DTPState::isPartDeliv() const {
235  return partDeliv;
236 }
237 
238 void DTPState::setPartDeliv(bool partDeliv) {
239  this->partDeliv = partDeliv;
240 }
241 
242 //bool DTPState::isRateBased() const {
243 // return rateBased;
244 //}
245 //
246 //void DTPState::setRateBased(bool rateBased) {
247 // this->rateBased = rateBased;
248 //}
249 
250 //bool DTPState::isRateFullfilled() const {
251 // return rateFullfilled;
252 //}
253 //
254 //void DTPState::setRateFullfilled(bool rateFullfilled) {
255 // this->rateFullfilled = rateFullfilled;
256 //}
257 
258 unsigned int DTPState::getRcvLeftWinEdge() const {
259  return rcvLeftWinEdge;
260 }
261 
262 void DTPState::setRcvLeftWinEdge(unsigned int rcvLeftWinEdge) {
263  this->rcvLeftWinEdge = rcvLeftWinEdge;
264 }
265 
266 //bool DTPState::isRxPresent() const {
267 // return rxPresent;
268 //}
269 //
270 //void DTPState::setRxPresent(bool rexmsnPresent) {
271 // this->rxPresent = rexmsnPresent;
272 //}
273 
274 unsigned int DTPState::getSeqNumRollOverThresh() const {
275  return seqNumRollOverThresh;
276 }
277 
278 void DTPState::setSeqNumRollOverThresh(unsigned int seqNumRollOverThresh) {
279  this->seqNumRollOverThresh = seqNumRollOverThresh;
280 }
281 
282 int DTPState::getState() const {
283  return state;
284 }
285 
286 void DTPState::setState(int state) {
287  this->state = state;
288 }
289 
290 //bool DTPState::isWinBased() const {
291 // return winBased;
292 //}
293 //
294 //void DTPState::setWinBased(bool winBased) {
295 // this->winBased = winBased;
296 //}
297 
299 {
300  return setDRFFlag;
301 }
302 
303 double DTPState::getRtt() const
304 {
305  //TODO B1 RTT estimator policy
306  return rtt;
307 }
308 
309 void DTPState::setRtt(double rtt)
310 {
311  this->rtt = rtt;
312 }
313 
314 void DTPState::setSetDrfFlag(bool setDrfFlag)
315 {
316  setDRFFlag = setDrfFlag;
317 }
318 
319 unsigned int DTPState::getLastSeqNumSent() const
320 {
321  return lastSeqNumSent;
322 }
323 
324 void DTPState::setLastSeqNumSent(unsigned int lastSeqNumSent)
325 {
326  this->lastSeqNumSent = lastSeqNumSent;
327 }
328 
329 bool DTPState::isEcnSet() const
330 {
331  return ecnSet;
332 }
333 
334 void DTPState::setEcnSet(bool ecnSet)
335 {
336  this->ecnSet = ecnSet;
337 }
338 
340 {
341  return currentPDU;
342 }
343 
344 void DTPState::setCurrentPdu(PDU* currentPdu)
345 {
346  currentPDU = currentPdu;
347 }
348 
349 
350 
351 std::vector<DataTransferPDU*>* DTPState::getReassemblyPDUQ()
352 {
353  return &reassemblyPDUQ;
354 }
355 
357 {
358 //TODO A2 check if this PDU is already on the queue (I believe the FSM is broken and it might try to add one PDU twice)
359 
360  take(pdu);
361  reassemblyPDUQ.push_back(pdu);
362 }
363 
365 {
366 
367  if (pdu != NULL)
368  {
369  take(pdu);
370  if (reassemblyPDUQ.empty())
371  {
372  reassemblyPDUQ.push_back(pdu);
373  }
374  else
375  {
376  if (reassemblyPDUQ.front()->getSeqNum() > pdu->getSeqNum())
377  {
378  reassemblyPDUQ.insert(reassemblyPDUQ.begin(), pdu);
379  }
380  else
381  {
382  for (std::vector<DataTransferPDU*>::iterator it = reassemblyPDUQ.begin(); it != reassemblyPDUQ.end(); ++it)
383  {
384  if ((*it)->getSeqNum() == pdu->getSeqNum())
385  {
386  //Not sure if this case could ever happen; EDIT: No, this SHOULD not ever happen.
387  //Throw Error.
388  throw cRuntimeError("addPDUTo reassemblyQ with same seqNum. SHOULD not ever happen");
389  }
390  else if ((*it)->getSeqNum() > pdu->getSeqNum())
391  {
392  /* Put the incoming PDU before one with bigger seqNum */
393  reassemblyPDUQ.insert(it, pdu);
394  break;
395  }
396  else if (it == --reassemblyPDUQ.end())
397  {
398  //'it' is last element
399  reassemblyPDUQ.insert(it + 1, pdu);
400  break;
401  }
402  }
403  }
404  }
405  }
406 }
407 
408 
410 
411  return &generatedPDUs;
412 }
413 
415 {
416  generatedPDUs.push_back(pdu);
417 }
418 
420 
421  return &postablePDUs;
422 }
423 
425  postablePDUs.push_back(pdu);
426 }
427 
428 unsigned int DTPState::getDropDup() const
429 {
430  return dropDup;
431 }
432 
434 {
435  return qoSCube;
436 }
437 
438 unsigned int DTPState::getLastSduDelivered() const
439 {
440  return lastSDUDelivered;
441 }
442 
443 void DTPState::setLastSduDelivered(unsigned int lastSduDelivered)
444 {
445  lastSDUDelivered = lastSduDelivered;
446 }
447 
448 void DTPState::setQoSCube(const QoSCube*& qoSCube)
449 {
450  this->qoSCube = qoSCube;
451 }
452 
453 void DTPState::updateRcvLWE(unsigned int seqNum)
454 {
455 
456 
457  unsigned int sduGap = qoSCube->getMaxAllowGap();
458 
459  PDUQ_t* pduQ = &reassemblyPDUQ;
460 
461  for (auto it = pduQ->begin(); it != pduQ->end(); ++it)
462  {
463  if((rcvLeftWinEdge + 1) + sduGap >= (*it)->getSeqNum())
464  {
465  rcvLeftWinEdge = (*it)->getSeqNum();
466  }
467 
468  }
469 
470  return;
471 }
472 
473 void DTPState::handleMessage(cMessage* msg)
474 {
475 }
476 
477 /* Dirty hacks */
479 {
480  return tmpAtimer;
481 }
482 
484 {
485  this->tmpAtimer = tmpAtimer;
486 }
487 
488 //double DTPState::getDelimitDelay() const
489 //{
490 // return delimitDelay;
491 //}
492 //
493 //void DTPState::setDelimitDelay(double delimitDelay)
494 //{
495 // this->delimitDelay = delimitDelay;
496 //}
497 /* End dirty hacks */
void resetSndVars()
Definition: DTPState.cc:95
PDUQ_t generatedPDUs
Definition: DTPState.h:81
bool isPartDeliv() const
Definition: DTPState.cc:234
bool dtcpPresent
Definition: DTPState.h:73
void setRcvLeftWinEdge(unsigned int rcvLeftWinEdge)
Definition: DTPState.cc:262
int state
Definition: DTPState.h:72
void pushBackToReassemblyPDUQ(DataTransferPDU *pdu)
Definition: DTPState.cc:356
unsigned int getLastSeqNumSent() const
Definition: DTPState.cc:319
unsigned int getMaxFlowSduSize() const
Definition: DTPState.cc:186
bool blockingPort
Definition: DTPState.h:110
PDUQ_t * getPostablePDUQ()
Definition: DTPState.cc:419
unsigned int dropDup
Definition: DTPState.h:96
bool isRateFcOn() const
Definition: QoSCube.cc:478
bool ecnSet
Definition: DTPState.h:109
virtual void handleMessage(cMessage *msg)
Definition: DTPState.cc:473
void setNextSeqNumToSend(unsigned int nextSeqNumToSend)
Definition: DTPState.cc:225
double getMPL() const
Definition: DTPState.cc:33
unsigned int nextSeqNumToSend
Definition: DTPState.h:91
const char * MOD_EFCP
Definition: ExternConsts.cc:40
void setMaxFlowPduSize(unsigned int maxFlowPduSize)
Definition: DTPState.cc:182
ATimer * tmpAtimer
Definition: DTPState.h:116
unsigned int maxSeqNumRcvd
Definition: DTPState.h:89
unsigned int lastSeqNumSent
Definition: DTPState.h:99
bool isEcnSet() const
Definition: DTPState.cc:329
void pushBackToGeneratedPDUQ(DataTransferPDU *pdu)
Definition: DTPState.cc:414
unsigned int getMaxSeqNumRcvd() const
Definition: DTPState.cc:194
unsigned int getNextSeqNumToSend()
Definition: DTPState.cc:215
void setRtt(double rtt)
Definition: DTPState.cc:309
bool partDeliv
Definition: DTPState.h:86
void setEcnSet(bool ecnSet)
Definition: DTPState.cc:334
PDU * currentPDU
Definition: DTPState.h:63
PDUQ_t reassemblyPDUQ
Definition: DTPState.h:80
void setState(int state)
Definition: DTPState.cc:286
unsigned int getSeqNumRollOverThresh() const
Definition: DTPState.cc:274
void setPartDeliv(bool partDeliv)
Definition: DTPState.cc:238
void clearGeneratedPDUQ()
Definition: DTPState.cc:145
unsigned int maxFlowSDUSize
Definition: DTPState.h:68
DTPState()
Definition: DTPState.cc:27
bool isBlockingPort() const
Definition: DTPState.cc:43
bool isSetDrfFlag() const
Definition: DTPState.cc:298
void incNextSeqNumToSend()
Definition: DTPState.cc:229
PDUQ_t * getGeneratedPDUQ()
Definition: DTPState.cc:409
void setMaxFlowSduSize(unsigned int maxFlowSduSize)
Definition: DTPState.cc:190
Definition: PDU.h:42
bool isIncompDeliv() const
Definition: DTPState.cc:170
bool isDtcpPresent() const
Definition: DTPState.cc:162
void clearReassemblyPDUQ()
Definition: DTPState.cc:140
void setQoSCube(const QoSCube *&qoSCube)
Definition: DTPState.cc:448
bool setDRFFlag
Definition: DTPState.h:102
void setIncompDeliv(bool incompDeliv)
Definition: DTPState.cc:174
void setMpl(double mpl)
Definition: DTPState.cc:38
void addPDUToReassemblyQ(DataTransferPDU *pdu)
Definition: DTPState.cc:364
void setSeqNumRollOverThresh(unsigned int seqNumRollOverThresh)
Definition: DTPState.cc:278
unsigned int maxFlowPDUSize
Definition: DTPState.h:69
unsigned int rcvLeftWinEdge
Definition: DTPState.h:88
unsigned int getRcvLeftWinEdge() const
Definition: DTPState.cc:258
const QoSCube * getQoSCube() const
Definition: DTPState.cc:433
void updateRcvLWE(unsigned int seqNum)
Definition: DTPState.cc:453
void incMaxSeqNumRcvd()
Definition: DTPState.cc:203
virtual unsigned int getSeqNum() const
Definition: PDU_m.cc:376
std::vector< DataTransferPDU * > PDUQ_t
void setTmpAtimer(ATimer *tmpAtimer)
Definition: DTPState.cc:483
int getState() const
Definition: DTPState.cc:282
void initDefaults()
Definition: DTPState.cc:104
void setSetDrfFlag(bool setDrfFlag)
Definition: DTPState.cc:314
void pushBackToPostablePDUQ(DataTransferPDU *pdu)
Definition: DTPState.cc:424
double mpl
Definition: DTPState.h:104
const PDU * getCurrentPdu() const
Definition: DTPState.cc:339
double getRtt() const
Definition: DTPState.cc:303
std::vector< DataTransferPDU * > * getReassemblyPDUQ()
Definition: DTPState.cc:351
void clearPostablePDUQ()
Definition: DTPState.cc:150
Class representing QoSCube with all its properties that is primarily used by FA, RMT and RA Specifica...
Definition: QoSCube.h:57
bool isRxOn() const
Definition: QoSCube.cc:483
void setLastSduDelivered(unsigned int lastSduDelivered)
Definition: DTPState.cc:443
unsigned int getMaxFlowPduSize() const
Definition: DTPState.cc:178
void resetRcvVars()
Definition: DTPState.cc:53
unsigned int getDropDup() const
Definition: DTPState.cc:428
Define_Module(DTPState)
unsigned int seqNumRollOverThresh
Definition: DTPState.h:71
ATimer * getTmpAtimer() const
Definition: DTPState.cc:478
virtual ~DTPState()
Definition: DTPState.cc:155
void setLastSeqNumSent(unsigned int lastSeqNumSent)
Definition: DTPState.cc:324
bool isWindowFcOn() const
Definition: QoSCube.cc:488
const QoSCube * qoSCube
Definition: DTPState.h:84
unsigned int lastSDUDelivered
Definition: DTPState.h:92
double rtt
Definition: DTPState.h:103
void incRcvLeftWindowEdge()
Definition: DTPState.cc:207
void clearPDUQ(std::vector< DataTransferPDU * > *pduQ)
Definition: DTPState.cc:127
unsigned int getLastSduDelivered() const
Definition: DTPState.cc:438
void setDtcpPresent(bool dtcpPresent)
Definition: DTPState.cc:166
void setCurrentPdu(PDU *currentPdu)
Definition: DTPState.cc:344
void setBlockingPort(bool blockingPort)
Definition: DTPState.cc:48
virtual void initialize(int step)
Definition: DTPState.cc:64
bool incompDeliv
Definition: DTPState.h:87
int getMaxAllowGap() const
Gets Maximum Allowable Gap in SDUs parameter.
Definition: QoSCube.cc:316
PDUQ_t postablePDUs
Definition: DTPState.h:82
void setMaxSeqNumRcvd(unsigned int maxSeqNumRcvd)
Definition: DTPState.cc:198
unsigned int getNextSeqNumToSendWithoutIncrement()
Definition: DTPState.cc:220