Advertisement
ungureanuvladvictor

Untitled

Mar 4th, 2014
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. /*
  2. * tcp-cct.c
  3. *
  4. * A congestion control template utilizing the Linux congestion
  5. * control kernel module API. This has been tested with Linux
  6. * kernel 2.6.26.
  7. *
  8. * Juergen Schoenwaelder <j.schoenwaelder@jacobs-university.de>
  9. *
  10. * Some useful commands:
  11. *
  12. * sudo insmod ./tcp-cct.ko # load the compiled kernel module
  13. * sudo rmmod ./tcp-cct.ko # unload the kernel module
  14. *
  15. * TCC=net.ipv4.tcp_congestion_control
  16. *
  17. * sysctl $TCC # show the currently used cc algorithm
  18. * sudo sysctl -w $TCC=cct # change the currently used cc algorithm
  19. */
  20.  
  21. #include <linux/module.h>
  22. #include <net/tcp.h>
  23.  
  24. /*
  25. * This function sets the slow start threshold.
  26. */
  27.  
  28. static u32 tcp_cct_ssthresh(struct sock *sk)
  29. {
  30. struct tcp_sock *tp = tcp_sk(sk);
  31.  
  32. printk(KERN_INFO "tcp_cct_ssthresh "
  33. "snd_cwnd = %d\n", tp->snd_cwnd);
  34.  
  35. return tp->snd_cwnd / 2 ;
  36. }
  37.  
  38. /*
  39. * This function sets the lower bound for congestion window.
  40. */
  41.  
  42. static u32 tcp_cct_min_cwnd(const struct sock *sk)
  43. {
  44. const struct tcp_sock *tp = tcp_sk(sk);
  45.  
  46. printk(KERN_INFO "tcp_cct_min_cwnd: "
  47. "snd_cwnd = %d\n", tp->snd_cwnd);
  48.  
  49. //return tcp_reno_min_cwnd(sk);
  50. return tp->snd_ssthresh * 3.0/4.0;
  51. }
  52.  
  53.  
  54.  
  55. void tcp_main_slow_start(struct tcp_sock *tp)
  56. {
  57. int cnt; /* increase in packets */
  58.  
  59.  
  60. cnt = tp->snd_cwnd; /* exponential increase */
  61.  
  62.  
  63. //tp->bytes_acked = 0;
  64. tp->snd_cwnd_cnt +=cnt * 1.5;
  65. printk(KERN_INFO"slow_start:%d",
  66. tp->snd_cwnd_cnt);
  67. //tp->snd_cwnd_cnt += cnt;
  68. while (tp->snd_cwnd_cnt >= tp->snd_cwnd) {
  69. tp->snd_cwnd_cnt -= tp->snd_cwnd;
  70. tp->snd_cwnd++;
  71. }
  72. }
  73.  
  74.  
  75.  
  76. void tcp_main_cong_avoid(struct sock *sk, u32 ack, u32 acked, u32 in_flight)
  77. {
  78. struct tcp_sock *tp = tcp_sk(sk);
  79.  
  80.  
  81.  
  82. // if (!tcp_is_cwnd_limited(sk, in_flight))
  83. // return;
  84.  
  85. printk(KERN_INFO "tcp_cct_cong_avoid: "
  86. "snd_cwnd = %d, snd_ssthresh = %d\n",
  87. tp->snd_cwnd, tp->snd_ssthresh);
  88.  
  89. /* In "safe" area, increase. */
  90. tcp_main_slow_start(tp);//tcp_cong_avoid_ai(tp, tp->snd_cwnd);
  91. }
  92.  
  93. void init_cct(struct sock *sk)
  94. {
  95. struct tcp_sock *tp = tcp_sk(sk);
  96. tp->snd_cwnd = tp->snd_ssthresh / 2;
  97. printk(KERN_INFO "init_cct: ssthresh %d cwnd: %d",
  98. tp->snd_ssthresh, tp->snd_cwnd);
  99. }
  100.  
  101. static struct tcp_congestion_ops tcp_cct = {
  102. .ssthresh = tcp_cct_ssthresh,
  103. .cong_avoid = tcp_main_cong_avoid,
  104. .min_cwnd = tcp_cct_min_cwnd,
  105. .init = init_cct,
  106. .owner = THIS_MODULE,
  107. .name = "cct",
  108. };
  109.  
  110. static int __init tcp_cct_register(void)
  111. {
  112. return tcp_register_congestion_control(&tcp_cct);
  113. }
  114.  
  115. static void __exit tcp_cct_unregister(void)
  116. {
  117. tcp_unregister_congestion_control(&tcp_cct);
  118. }
  119.  
  120. module_init(tcp_cct_register);
  121. module_exit(tcp_cct_unregister);
  122.  
  123. MODULE_AUTHOR("Juergen Schoenwaelder");
  124. MODULE_LICENSE("GPL");
  125. MODULE_DESCRIPTION("Congestion Control Template");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement