-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtcp_sociopath.c
52 lines (43 loc) · 1.37 KB
/
tcp_sociopath.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
45
46
47
48
49
50
51
52
#include <linux/mm.h>
#include <linux/module.h>
#include <linux/skbuff.h>
#include <linux/inet_diag.h>
#include <net/tcp.h>
static int lambda = 20;
module_param(lambda, int, 0644);
MODULE_PARM_DESC(lambda, "degree of sociopathy");
static u32 tcp_sociopath_ssthresh(struct sock *sk) {
u32 cwnd = tcp_sk(sk)->snd_cwnd;
return max(cwnd-(cwnd/lambda), 2U);
}
static u32 tcp_sociopath_min_cwnd(const struct sock *sk) {
return tcp_sk(sk)->snd_ssthresh+1;
}
static void tcp_sociopath_cong_avoid(struct sock *sk, u32 ack, u32 in_flight) {
struct tcp_sock *tp = tcp_sk(sk);
if (tp->snd_cwnd <= tp->snd_ssthresh) {
if (tp->snd_cwnd < lambda*10) tp->snd_cwnd = lambda*10;
tcp_reno_cong_avoid(sk, ack, in_flight);
} else {
tcp_reno_cong_avoid(sk, ack, in_flight);
}
}
static struct tcp_congestion_ops tcp_sociopath = {
.owner = THIS_MODULE,
.name = "sociopath",
.ssthresh = tcp_sociopath_ssthresh,
.min_cwnd = tcp_sociopath_min_cwnd,
.cong_avoid = tcp_sociopath_cong_avoid
};
static int __init tcp_sociopath_register(void) {
tcp_register_congestion_control(&tcp_sociopath);
return 0;
}
static void __exit tcp_sociopath_unregister(void) {
tcp_unregister_congestion_control(&tcp_sociopath);
}
module_init(tcp_sociopath_register);
module_exit(tcp_sociopath_unregister);
MODULE_AUTHOR("Michael Lucy");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("TCP Sociopath");