-
Notifications
You must be signed in to change notification settings - Fork 0
/
RTTManager.cc
63 lines (49 loc) · 1.39 KB
/
RTTManager.cc
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
#ifndef RTTMANAGER
#define RTTMANAGER
#include <string.h>
#include <omnetpp.h>
#include "RTTManager.h"
using namespace omnetpp;
#define MIN_ABSOLUTE_DIFFERENCE (double)0.0001
RTTManager::RTTManager() {
rtt = 1; // RFC 6298
stdDesviation = 0;
rto = 1; // 1s
isFirstAckReceived = false;
}
RTTManager::~RTTManager() {
}
double RTTManager::getCurrentRTo(){
std::cout << "RTT :: Current RTO = " << rto << "\n";
return rto;
}
void RTTManager::updateTimeoutRTo(){
rto = getCurrentRTo() * 2;
std::cout << "RTT TIMEOUT RTO = " << rto << "\n";
}
void RTTManager::updateSmoothRTT(double rtMeasurement) {
double alpha = 0.875;
double beta = 0.75;
double absolute = std::abs(rtt - rtMeasurement);
absolute = std::max(absolute, MIN_ABSOLUTE_DIFFERENCE);
stdDesviation = beta * stdDesviation + (1-beta) * absolute;
rtt = alpha * rtt + (1-alpha) * rtMeasurement;
rto = rtt + (4 * stdDesviation);
std::cout << "RTT :: updateEstimation(" << rtMeasurement << ")";
std::cout << " : rtt: " << rtt << " s. stdDesviation: " << stdDesviation;
std::cout << " s. absolute diff: " << absolute << ". rto: " << rto << " s\n";
}
void RTTManager::updateEstimation(double rtMeasurement) {
if (isFirstAckReceived) {
updateSmoothRTT(rtMeasurement);
} else {
rtt = rtMeasurement;
stdDesviation = rtt / 2.0;
rto = rtt * 3.0;
isFirstAckReceived = true;
}
}
double RTTManager::getCurrentRTT(){
return rtt;
}
#endif