forked from boucadair/rfc8312bis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tablecode.c
44 lines (33 loc) · 1.08 KB
/
tablecode.c
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
#include <math.h>
#include <stdio.h>
#include <sys/param.h>
static long reno(double p) { return lround(1.2 / pow(p, 0.5)); }
static long hstcp(double p) {
const long cwnd = lround(0.12 / pow(p, 0.835));
const long tcp_friend = reno(p);
return MAX(tcp_friend, cwnd);
}
static long cubic(double C, double RTT, double p) {
double w = pow(RTT, 0.75);
w = w / pow(p, 0.75);
w = w * pow(C * 3.7 / 1.2, 0.25);
const long cwnd = lround(w);
const long tcp_friend = reno(p);
return MAX(tcp_friend, cwnd);
}
static void print_table(int nr, double RTT) {
printf("\n<!--Table %d (RTT=%gs)-->\n", nr, RTT);
printf("| %s | %s | %s | %s | %s | %s |\n", "Loss Rate P", "AIMD", "HSTCP",
"CUBIC (C=0.04)", "CUBIC (C=0.4)", "CUBIC (C=4)");
printf("| ---:| ---:| ---:| ---:| ---:| ---:|\n");
for (long i = 2; i <= 8; i++) {
const double p = pow(10, -i);
printf("| %.1e | %ld | %ld | %ld | %ld | %ld |\n", p, reno(p), hstcp(p),
cubic(0.04, RTT, p), cubic(0.4, RTT, p), cubic(4, RTT, p));
}
}
int main() {
print_table(1, 0.1);
print_table(2, 0.01);
return 0;
}