RINASim  October 2016
Documentation of framework for OMNeT++
RTTEstimatorPolicyTCP.cc
Go to the documentation of this file.
1 //
2 // This program is free software: you can redistribute it and/or modify
3 // it under the terms of the GNU Lesser General Public License as published by
4 // the Free Software Foundation, either version 3 of the License, or
5 // (at your option) any later version.
6 //
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 // GNU Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public License
13 // along with this program. If not, see http://www.gnu.org/licenses/.
14 //
15 
16 #include <RTTEstimatorPolicyTCP.h>
19  // TODO Auto-generated constructor stub
21  k = 4;
22  G = 0.1;
23  RTO = 1;
24 
25  sigStatTCPRTO = registerSignal("TCP_RTO");
26 }
27 
29  // TODO Auto-generated destructor stub
30 }
31 
32 bool RTTEstimatorPolicyTCP::run(DTPState* dtpState, DTCPState* dtcpState)
33 {
34  double alpha = 0.125;
35  double beta = 0.25;
36  double newRtt = 0;
37  /* Calculating RTT */
38  ControlPDU* pdu = (ControlPDU*) dtpState->getCurrentPdu();
39  if (pdu->getType() & PDU_SEL_BIT) {
40 
41  } else {
42  if (pdu->getType() & PDU_ACK_BIT) {
43  unsigned int seqNum = ((AckOnlyPDU*) pdu)->getAckNackSeqNum();
44  std::vector<DTCPRxExpiryTimer*>* pduQ =
45  dtcpState->getRxQ();
46  std::vector<DTCPRxExpiryTimer*>::iterator it;
47  bool foundAck = false;
48  for (it = pduQ->begin(); it != pduQ->end(); ++it) {
49  if ((*it)->getPdu()->getSeqNum() == seqNum) {
50  foundAck = true;
51  double now = simTime().dbl();
52  double sent = (*it)->getSent();
53  newRtt = now - sent;
54 
55  newRtt = floor(newRtt * 1000000000);
56  newRtt = newRtt / 1000000000;
57 
58  }
59  }
60  if (!foundAck) {
61  EV
62  << "RTTEstimator: Did not find PDU on RxQ to compare times."
63  << endl;
64  return false;
65  }
66 
67  } else {
68 
69  }
70  }
71  EV << "Current RTT: " << newRtt << endl;
72  /* End */
73 
74  if(state == STATE_FIRST) {
75  RTTVar = newRtt / 2;
76  SRTT = newRtt;
77  state = STATE_NEXT;
78  } else {
79  double t = SRTT - newRtt;
80  if( t < 0 )
81  t *= -1;
82  RTTVar = (1 - beta) * RTTVar + beta * t;
83  SRTT = (1 - alpha) * SRTT + alpha * newRtt;
84  }
85  RTO = SRTT + std::max(G, k * RTTVar);
86 
87  if(RTO < 1)
88  RTO = 1;
89 
90  dtpState->setRtt(newRtt);
91 // dtcpState->RTO = RTO;
92 
93  emit(sigStatTCPRTO, RTO);
94 
95  return false;
96 }
#define STATE_FIRST
virtual bool run(DTPState *dtpState, DTCPState *dtcpState)
#define STATE_NEXT
void setRtt(double rtt)
Definition: DTPState.cc:309
virtual int getType() const
Definition: PDU_m.cc:346
const PDU * getCurrentPdu() const
Definition: DTPState.cc:339
std::vector< DTCPRxExpiryTimer * > * getRxQ()
Definition: DTCPState.cc:264
Register_Class(RTTEstimatorPolicyTCP)