1
2
3
4
5
6
7
8
9
10
11
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <unistd.h>
16#include <fcntl.h>
17#include <math.h>
18#include <sys/socket.h>
19#include <netinet/in.h>
20#include <arpa/inet.h>
21#include <string.h>
22
23#include "utils.h"
24#include "tc_core.h"
25
26int tc_setup_estimator(unsigned int A, unsigned int time_const, struct tc_estimator *est)
27{
28 for (est->interval = 0; est->interval <= 5; est->interval++) {
29 if (A <= (1<<est->interval)*(TIME_UNITS_PER_SEC/4))
30 break;
31 }
32 if (est->interval > 5)
33 return -1;
34 est->interval -= 2;
35 for (est->ewma_log = 1; est->ewma_log < 32; est->ewma_log++) {
36 double w = 1.0 - 1.0/(1<<est->ewma_log);
37
38 if (A/(-log(w)) > time_const)
39 break;
40 }
41 est->ewma_log--;
42 if (est->ewma_log == 0 || est->ewma_log >= 31)
43 return -1;
44 return 0;
45}
46