tcp_naivereno.c
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:2k
源码类别:

通讯编程

开发平台:

Visual C++

  1. /* This is a very naive Reno implementation, shown as an example on how to develop a new congestion control algorithm with TCP-Linux.
  2.  *
  3.  * See a mini-tutorial about TCP-Linux at: http://netlab.caltech.edu/projects/ns2tcplinux/
  4.  *
  5.  */
  6. #define NS_PROTOCOL "tcp_naive_reno.c"
  7. #include "ns-linux-c.h"
  8. #include "ns-linux-util.h"
  9. static int alpha = 1;
  10. static int beta = 2;
  11. module_param(alpha, int, 0644);
  12. MODULE_PARM_DESC(alpha, "AI increment size of window (in unit of pkt/round trip time)");
  13. module_param(beta, int, 0644);
  14. MODULE_PARM_DESC(beta, "MD decrement portion of window: every loss the window is reduced by a proportion of 1/beta");
  15. /* opencwnd */
  16. void tcp_naive_reno_cong_avoid(struct tcp_sock *tp, u32 ack, u32 rtt, u32 in_flight, int flag) 
  17. {
  18. if (tp->snd_cwnd < tp->snd_ssthresh) {
  19. tp->snd_cwnd++;
  20. } else {
  21. if (tp->snd_cwnd_cnt >= tp->snd_cwnd) {
  22. tp->snd_cwnd += alpha;
  23. tp->snd_cwnd_cnt = 0;
  24. if (tp->snd_cwnd > tp->snd_cwnd_clamp)
  25. tp->snd_cwnd = tp->snd_cwnd_clamp;
  26. } else {
  27. tp->snd_cwnd_cnt++;
  28. }
  29. }
  30. }
  31. /* ssthreshold should be half of the congestion window after a loss */
  32. u32 tcp_naive_reno_ssthresh(struct tcp_sock *tp)
  33. {
  34. int reduction = tp->snd_cwnd / beta;
  35.         return max(tp->snd_cwnd - reduction, 2U);
  36. }
  37. /* congestion window should be equal to the slow start threshold (after slow start threshold set to half of cwnd before loss). */
  38. u32 tcp_naive_reno_min_cwnd(const struct tcp_sock *tp)
  39. {
  40.         return tp->snd_ssthresh;
  41. }
  42. static struct tcp_congestion_ops tcp_naive_reno = {
  43.         .name           = "naive_reno",
  44.         .ssthresh       = tcp_naive_reno_ssthresh,
  45.         .cong_avoid     = tcp_naive_reno_cong_avoid,
  46.         .min_cwnd       = tcp_naive_reno_min_cwnd
  47. };
  48. int tcp_naive_reno_register(void)
  49. {
  50. tcp_register_congestion_control(&tcp_naive_reno);
  51. return 0;
  52. }
  53. module_init(tcp_naive_reno_register);