Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * tcp-cct.c
- *
- * A congestion control template utilizing the Linux congestion
- * control kernel module API. This has been tested with Linux
- * kernel 2.6.26.
- *
- * Juergen Schoenwaelder <j.schoenwaelder@jacobs-university.de>
- *
- * Some useful commands:
- *
- * sudo insmod ./tcp-cct.ko # load the compiled kernel module
- * sudo rmmod ./tcp-cct.ko # unload the kernel module
- *
- * TCC=net.ipv4.tcp_congestion_control
- *
- * sysctl $TCC # show the currently used cc algorithm
- * sudo sysctl -w $TCC=cct # change the currently used cc algorithm
- */
- #include <linux/module.h>
- #include <net/tcp.h>
- /*
- * This function sets the slow start threshold.
- */
- static u32 tcp_cct_ssthresh(struct sock *sk)
- {
- struct tcp_sock *tp = tcp_sk(sk);
- printk(KERN_INFO "tcp_cct_ssthresh "
- "snd_cwnd = %d\n", tp->snd_cwnd);
- return tp->snd_cwnd / 2 ;
- }
- /*
- * This function sets the lower bound for congestion window.
- */
- static u32 tcp_cct_min_cwnd(const struct sock *sk)
- {
- const struct tcp_sock *tp = tcp_sk(sk);
- printk(KERN_INFO "tcp_cct_min_cwnd: "
- "snd_cwnd = %d\n", tp->snd_cwnd);
- //return tcp_reno_min_cwnd(sk);
- return tp->snd_ssthresh * 3.0/4.0;
- }
- void tcp_main_slow_start(struct tcp_sock *tp)
- {
- int cnt; /* increase in packets */
- cnt = tp->snd_cwnd; /* exponential increase */
- //tp->bytes_acked = 0;
- tp->snd_cwnd_cnt +=cnt * 1.5;
- printk(KERN_INFO"slow_start:%d",
- tp->snd_cwnd_cnt);
- //tp->snd_cwnd_cnt += cnt;
- while (tp->snd_cwnd_cnt >= tp->snd_cwnd) {
- tp->snd_cwnd_cnt -= tp->snd_cwnd;
- tp->snd_cwnd++;
- }
- }
- void tcp_main_cong_avoid(struct sock *sk, u32 ack, u32 acked, u32 in_flight)
- {
- struct tcp_sock *tp = tcp_sk(sk);
- // if (!tcp_is_cwnd_limited(sk, in_flight))
- // return;
- printk(KERN_INFO "tcp_cct_cong_avoid: "
- "snd_cwnd = %d, snd_ssthresh = %d\n",
- tp->snd_cwnd, tp->snd_ssthresh);
- /* In "safe" area, increase. */
- tcp_main_slow_start(tp);//tcp_cong_avoid_ai(tp, tp->snd_cwnd);
- }
- void init_cct(struct sock *sk)
- {
- struct tcp_sock *tp = tcp_sk(sk);
- tp->snd_cwnd = tp->snd_ssthresh / 2;
- printk(KERN_INFO "init_cct: ssthresh %d cwnd: %d",
- tp->snd_ssthresh, tp->snd_cwnd);
- }
- static struct tcp_congestion_ops tcp_cct = {
- .ssthresh = tcp_cct_ssthresh,
- .cong_avoid = tcp_main_cong_avoid,
- .min_cwnd = tcp_cct_min_cwnd,
- .init = init_cct,
- .owner = THIS_MODULE,
- .name = "cct",
- };
- static int __init tcp_cct_register(void)
- {
- return tcp_register_congestion_control(&tcp_cct);
- }
- static void __exit tcp_cct_unregister(void)
- {
- tcp_unregister_congestion_control(&tcp_cct);
- }
- module_init(tcp_cct_register);
- module_exit(tcp_cct_unregister);
- MODULE_AUTHOR("Juergen Schoenwaelder");
- MODULE_LICENSE("GPL");
- MODULE_DESCRIPTION("Congestion Control Template");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement