Last active
October 12, 2019 09:02
-
-
Save Gumball12/580f5d4d3f7f49b503fbfb9826f5bf4d to your computer and use it in GitHub Desktop.
compute RTT values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* compute RTT values | |
* (DevRTT, EstimatedRTT, TimeoutInterval) | |
* @author shj <https://github.com/Gumball12> | |
* */ | |
// import module | |
#include <stdio.h> | |
#include <stdlib.h> // for absolute value function 'abs' | |
// define constants | |
#define ALPHA 0.125 | |
#define BETA 0.25 | |
/** | |
* compute RTT values | |
* !WARN: this function is a 'recursive' function | |
* @param sampleRTTs sampleRTT value array | |
* @param prevEstimatedRTT previous estimatedRTT value | |
* @param prevDevRTT previous devRTT value | |
* */ | |
void calcRTT(int *sampleRTTs, double prevEstimatedRTT, double prevDevRTT) { | |
// check sampleRTT array | |
if (sampleRTTs[0] == -1) { // end of recursion | |
return; | |
} | |
// compute RTT values | |
double estimatedRTT = (1 - ALPHA) * prevEstimatedRTT + ALPHA * sampleRTTs[0]; | |
double devRTT = (1 - BETA) * prevDevRTT + BETA * abs(sampleRTTs[0] - estimatedRTT); | |
double timeoutInterval = estimatedRTT + 4 * devRTT; | |
// print RTT values | |
printf("estimatedRTT: %lf, devRTT: %lf, timeoutInterval: %lf\n", estimatedRTT, devRTT, timeoutInterval); | |
// recursion | |
calcRTT(sampleRTTs + 1, estimatedRTT, prevDevRTT); | |
} | |
/** | |
* entry point | |
* */ | |
int main(void) { | |
// init values | |
int sampleRTTs[] = { 106, 120, 140, 90, 115, -1 }; | |
double initEstimatedRTT = 100; | |
// start calculation | |
calcRTT(sampleRTTs, initEstimatedRTT, 10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment