ccid3.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (c) 2005-7 The University of Waikato, Hamilton, New Zealand.
  4. * Copyright (c) 2007 The University of Aberdeen, Scotland, UK
  5. *
  6. * An implementation of the DCCP protocol
  7. *
  8. * This code has been developed by the University of Waikato WAND
  9. * research group. For further information please see https://www.wand.net.nz/
  10. * or e-mail Ian McDonald - [email protected]
  11. *
  12. * This code also uses code from Lulea University, rereleased as GPL by its
  13. * authors:
  14. * Copyright (c) 2003 Nils-Erik Mattsson, Joacim Haggmark, Magnus Erixzon
  15. *
  16. * Changes to meet Linux coding standards, to make it meet latest ccid3 draft
  17. * and to make it work as a loadable module in the DCCP stack written by
  18. * Arnaldo Carvalho de Melo <[email protected]>.
  19. *
  20. * Copyright (c) 2005 Arnaldo Carvalho de Melo <[email protected]>
  21. */
  22. #ifndef _DCCP_CCID3_H_
  23. #define _DCCP_CCID3_H_
  24. #include <linux/ktime.h>
  25. #include <linux/list.h>
  26. #include <linux/types.h>
  27. #include <linux/tfrc.h>
  28. #include "lib/tfrc.h"
  29. #include "../ccid.h"
  30. /* Two seconds as per RFC 5348, 4.2 */
  31. #define TFRC_INITIAL_TIMEOUT (2 * USEC_PER_SEC)
  32. /* Parameter t_mbi from [RFC 3448, 4.3]: backoff interval in seconds */
  33. #define TFRC_T_MBI 64
  34. /*
  35. * The t_delta parameter (RFC 5348, 8.3): delays of less than %USEC_PER_MSEC are
  36. * rounded down to 0, since sk_reset_timer() here uses millisecond granularity.
  37. * Hence we can use a constant t_delta = %USEC_PER_MSEC when HZ >= 500. A coarse
  38. * resolution of HZ < 500 means that the error is below one timer tick (t_gran)
  39. * when using the constant t_delta = t_gran / 2 = %USEC_PER_SEC / (2 * HZ).
  40. */
  41. #if (HZ >= 500)
  42. # define TFRC_T_DELTA USEC_PER_MSEC
  43. #else
  44. # define TFRC_T_DELTA (USEC_PER_SEC / (2 * HZ))
  45. #endif
  46. enum ccid3_options {
  47. TFRC_OPT_LOSS_EVENT_RATE = 192,
  48. TFRC_OPT_LOSS_INTERVALS = 193,
  49. TFRC_OPT_RECEIVE_RATE = 194,
  50. };
  51. /* TFRC sender states */
  52. enum ccid3_hc_tx_states {
  53. TFRC_SSTATE_NO_SENT = 1,
  54. TFRC_SSTATE_NO_FBACK,
  55. TFRC_SSTATE_FBACK,
  56. };
  57. /**
  58. * struct ccid3_hc_tx_sock - CCID3 sender half-connection socket
  59. * @tx_x: Current sending rate in 64 * bytes per second
  60. * @tx_x_recv: Receive rate in 64 * bytes per second
  61. * @tx_x_calc: Calculated rate in bytes per second
  62. * @tx_rtt: Estimate of current round trip time in usecs
  63. * @tx_p: Current loss event rate (0-1) scaled by 1000000
  64. * @tx_s: Packet size in bytes
  65. * @tx_t_rto: Nofeedback Timer setting in usecs
  66. * @tx_t_ipi: Interpacket (send) interval (RFC 3448, 4.6) in usecs
  67. * @tx_state: Sender state, one of %ccid3_hc_tx_states
  68. * @tx_last_win_count: Last window counter sent
  69. * @tx_t_last_win_count: Timestamp of earliest packet
  70. * with last_win_count value sent
  71. * @tx_no_feedback_timer: Handle to no feedback timer
  72. * @tx_t_ld: Time last doubled during slow start
  73. * @tx_t_nom: Nominal send time of next packet
  74. * @tx_hist: Packet history
  75. */
  76. struct ccid3_hc_tx_sock {
  77. u64 tx_x;
  78. u64 tx_x_recv;
  79. u32 tx_x_calc;
  80. u32 tx_rtt;
  81. u32 tx_p;
  82. u32 tx_t_rto;
  83. u32 tx_t_ipi;
  84. u16 tx_s;
  85. enum ccid3_hc_tx_states tx_state:8;
  86. u8 tx_last_win_count;
  87. ktime_t tx_t_last_win_count;
  88. struct timer_list tx_no_feedback_timer;
  89. struct sock *sk;
  90. ktime_t tx_t_ld;
  91. ktime_t tx_t_nom;
  92. struct tfrc_tx_hist_entry *tx_hist;
  93. };
  94. static inline struct ccid3_hc_tx_sock *ccid3_hc_tx_sk(const struct sock *sk)
  95. {
  96. struct ccid3_hc_tx_sock *hctx = ccid_priv(dccp_sk(sk)->dccps_hc_tx_ccid);
  97. BUG_ON(hctx == NULL);
  98. return hctx;
  99. }
  100. /* TFRC receiver states */
  101. enum ccid3_hc_rx_states {
  102. TFRC_RSTATE_NO_DATA = 1,
  103. TFRC_RSTATE_DATA,
  104. };
  105. /**
  106. * struct ccid3_hc_rx_sock - CCID3 receiver half-connection socket
  107. * @rx_last_counter: Tracks window counter (RFC 4342, 8.1)
  108. * @rx_state: Receiver state, one of %ccid3_hc_rx_states
  109. * @rx_bytes_recv: Total sum of DCCP payload bytes
  110. * @rx_x_recv: Receiver estimate of send rate (RFC 3448, sec. 4.3)
  111. * @rx_rtt: Receiver estimate of RTT
  112. * @rx_tstamp_last_feedback: Time at which last feedback was sent
  113. * @rx_hist: Packet history (loss detection + RTT sampling)
  114. * @rx_li_hist: Loss Interval database
  115. * @rx_s: Received packet size in bytes
  116. * @rx_pinv: Inverse of Loss Event Rate (RFC 4342, sec. 8.5)
  117. */
  118. struct ccid3_hc_rx_sock {
  119. u8 rx_last_counter:4;
  120. enum ccid3_hc_rx_states rx_state:8;
  121. u32 rx_bytes_recv;
  122. u32 rx_x_recv;
  123. u32 rx_rtt;
  124. ktime_t rx_tstamp_last_feedback;
  125. struct tfrc_rx_hist rx_hist;
  126. struct tfrc_loss_hist rx_li_hist;
  127. u16 rx_s;
  128. #define rx_pinv rx_li_hist.i_mean
  129. };
  130. static inline struct ccid3_hc_rx_sock *ccid3_hc_rx_sk(const struct sock *sk)
  131. {
  132. struct ccid3_hc_rx_sock *hcrx = ccid_priv(dccp_sk(sk)->dccps_hc_rx_ccid);
  133. BUG_ON(hcrx == NULL);
  134. return hcrx;
  135. }
  136. #endif /* _DCCP_CCID3_H_ */