2
0

quic_cc.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. * Copyright 2022-2023 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifndef OSSL_QUIC_CC_H
  10. # define OSSL_QUIC_CC_H
  11. #include "openssl/params.h"
  12. #include "internal/time.h"
  13. #include "internal/quic_predef.h"
  14. # ifndef OPENSSL_NO_QUIC
  15. typedef struct ossl_cc_ack_info_st {
  16. /* The time the packet being acknowledged was originally sent. */
  17. OSSL_TIME tx_time;
  18. /* The size in bytes of the packet being acknowledged. */
  19. size_t tx_size;
  20. } OSSL_CC_ACK_INFO;
  21. typedef struct ossl_cc_loss_info_st {
  22. /* The time the packet being lost was originally sent. */
  23. OSSL_TIME tx_time;
  24. /* The size in bytes of the packet which has been determined lost. */
  25. size_t tx_size;
  26. } OSSL_CC_LOSS_INFO;
  27. typedef struct ossl_cc_ecn_info_st {
  28. /*
  29. * The time at which the largest acked PN (in the incoming ACK frame) was
  30. * sent.
  31. */
  32. OSSL_TIME largest_acked_time;
  33. } OSSL_CC_ECN_INFO;
  34. /* Parameter (read-write): Maximum datagram payload length in bytes. */
  35. #define OSSL_CC_OPTION_MAX_DGRAM_PAYLOAD_LEN "max_dgram_payload_len"
  36. /* Diagnostic (read-only): current congestion window size in bytes. */
  37. #define OSSL_CC_OPTION_CUR_CWND_SIZE "cur_cwnd_size"
  38. /* Diagnostic (read-only): minimum congestion window size in bytes. */
  39. #define OSSL_CC_OPTION_MIN_CWND_SIZE "min_cwnd_size"
  40. /* Diagnostic (read-only): current net bytes in flight. */
  41. #define OSSL_CC_OPTION_CUR_BYTES_IN_FLIGHT "bytes_in_flight"
  42. /* Diagnostic (read-only): method-specific state value. */
  43. #define OSSL_CC_OPTION_CUR_STATE "cur_state"
  44. /*
  45. * Congestion control abstract interface.
  46. *
  47. * This interface is broadly based on the design described in RFC 9002. However,
  48. * the demarcation between the ACKM and the congestion controller does not
  49. * exactly match that delineated in the RFC 9002 pseudocode. Where aspects of
  50. * the demarcation involve the congestion controller accessing internal state of
  51. * the ACKM, the interface has been revised where possible to provide the
  52. * information needed by the congestion controller and avoid needing to give the
  53. * congestion controller access to the ACKM's internal data structures.
  54. *
  55. * Particular changes include:
  56. *
  57. * - In our implementation, it is the responsibility of the ACKM to determine
  58. * if a loss event constitutes persistent congestion.
  59. *
  60. * - In our implementation, it is the responsibility of the ACKM to determine
  61. * if the ECN-CE counter has increased. The congestion controller is simply
  62. * informed when an ECN-CE event occurs.
  63. *
  64. * All of these changes are intended to avoid having a congestion controller
  65. * have to access ACKM internal state.
  66. */
  67. #define OSSL_CC_LOST_FLAG_PERSISTENT_CONGESTION (1U << 0)
  68. struct ossl_cc_method_st {
  69. /*
  70. * Instantiation.
  71. */
  72. OSSL_CC_DATA *(*new)(OSSL_TIME (*now_cb)(void *arg),
  73. void *now_cb_arg);
  74. void (*free)(OSSL_CC_DATA *ccdata);
  75. /*
  76. * Reset of state.
  77. */
  78. void (*reset)(OSSL_CC_DATA *ccdata);
  79. /*
  80. * Escape hatch for option configuration.
  81. *
  82. * params is an array of OSSL_PARAM structures.
  83. *
  84. * Returns 1 on success and 0 on failure.
  85. */
  86. int (*set_input_params)(OSSL_CC_DATA *ccdata,
  87. const OSSL_PARAM *params);
  88. /*
  89. * (Re)bind output (diagnostic) information.
  90. *
  91. * params is an array of OSSL_PARAM structures used to output values. The
  92. * storage locations associated with each parameter are stored internally
  93. * and updated whenever the state of the congestion controller is updated;
  94. * thus, the storage locations associated with the OSSL_PARAMs passed in the
  95. * call to this function must remain valid until the congestion controller
  96. * is freed or those parameters are unbound. A given parameter name may be
  97. * bound to only one location at a time. The params structures themselves
  98. * do not need to remain allocated after this call returns.
  99. *
  100. * Returns 1 on success and 0 on failure.
  101. */
  102. int (*bind_diagnostics)(OSSL_CC_DATA *ccdata,
  103. OSSL_PARAM *params);
  104. /*
  105. * Unbind diagnostic information. The parameters with the given names are
  106. * unbound, cancelling the effects of a previous call to bind_diagnostic().
  107. * params is an array of OSSL_PARAMs. The values of the parameters are
  108. * ignored. If a parameter is already unbound, there is no effect for that
  109. * parameter but other parameters are still unbound.
  110. *
  111. * Returns 1 on success or 0 on failure.
  112. */
  113. int (*unbind_diagnostics)(OSSL_CC_DATA *ccdata,
  114. OSSL_PARAM *params);
  115. /*
  116. * Returns the amount of additional data (above and beyond the data
  117. * currently in flight) which can be sent in bytes. Returns 0 if no more
  118. * data can be sent at this time. The return value of this method
  119. * can vary as time passes.
  120. */
  121. uint64_t (*get_tx_allowance)(OSSL_CC_DATA *ccdata);
  122. /*
  123. * Returns the time at which the return value of get_tx_allowance might be
  124. * higher than its current value. This is not a guarantee and spurious
  125. * wakeups are allowed. Returns ossl_time_infinite() if there is no current
  126. * wakeup deadline.
  127. */
  128. OSSL_TIME (*get_wakeup_deadline)(OSSL_CC_DATA *ccdata);
  129. /*
  130. * The On Data Sent event. num_bytes should be the size of the packet in
  131. * bytes (or the aggregate size of multiple packets which have just been
  132. * sent).
  133. */
  134. int (*on_data_sent)(OSSL_CC_DATA *ccdata,
  135. uint64_t num_bytes);
  136. /*
  137. * The On Data Acked event. See OSSL_CC_ACK_INFO structure for details
  138. * of the information to be passed.
  139. */
  140. int (*on_data_acked)(OSSL_CC_DATA *ccdata,
  141. const OSSL_CC_ACK_INFO *info);
  142. /*
  143. * The On Data Lost event. See OSSL_CC_LOSS_INFO structure for details
  144. * of the information to be passed.
  145. *
  146. * Note: When the ACKM determines that a set of multiple packets has been
  147. * lost, it is useful for a congestion control algorithm to be able to
  148. * process this as a single loss event rather than multiple loss events.
  149. * Thus, calling this function may cause the congestion controller to defer
  150. * state updates under the assumption that subsequent calls to
  151. * on_data_lost() representing further lost packets in the same loss event
  152. * may be forthcoming. Always call on_data_lost_finished() after one or more
  153. * calls to on_data_lost().
  154. */
  155. int (*on_data_lost)(OSSL_CC_DATA *ccdata,
  156. const OSSL_CC_LOSS_INFO *info);
  157. /*
  158. * To be called after a sequence of one or more on_data_lost() calls
  159. * representing multiple packets in a single loss detection incident.
  160. *
  161. * Flags may be 0 or OSSL_CC_LOST_FLAG_PERSISTENT_CONGESTION.
  162. */
  163. int (*on_data_lost_finished)(OSSL_CC_DATA *ccdata, uint32_t flags);
  164. /*
  165. * For use when a PN space is invalidated or a packet must otherwise be
  166. * 'undone' for congestion control purposes without acting as a loss signal.
  167. * Only the size of the packet is needed.
  168. */
  169. int (*on_data_invalidated)(OSSL_CC_DATA *ccdata,
  170. uint64_t num_bytes);
  171. /*
  172. * Called from the ACKM when detecting an increased ECN-CE value in an ACK
  173. * frame. This indicates congestion.
  174. *
  175. * Note that this differs from the RFC's conceptual segregation of the loss
  176. * detection and congestion controller functions, as in our implementation
  177. * the ACKM is responsible for detecting increases to ECN-CE and simply
  178. * tells the congestion controller when ECN-triggered congestion has
  179. * occurred. This allows a slightly more efficient implementation and
  180. * narrower interface between the ACKM and CC.
  181. */
  182. int (*on_ecn)(OSSL_CC_DATA *ccdata,
  183. const OSSL_CC_ECN_INFO *info);
  184. };
  185. extern const OSSL_CC_METHOD ossl_cc_dummy_method;
  186. extern const OSSL_CC_METHOD ossl_cc_newreno_method;
  187. # endif
  188. #endif