Frédéric Lécaille | 0c4e3b0 | 2020-11-23 14:10:37 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * include/haproxy/quic_cc-t.h |
| 3 | * This file contains definitions for QUIC congestion control. |
| 4 | * |
| 5 | * Copyright 2020 HAProxy Technologies, Frédéric Lécaille <flecaille@haproxy.com> |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation, version 2.1 |
| 10 | * exclusively. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | #ifndef _HAPROXY_QUIC_CC_H |
| 23 | #define _HAPROXY_QUIC_CC_H |
| 24 | #ifdef USE_QUIC |
| 25 | #ifndef USE_OPENSSL |
| 26 | #error "Must define USE_OPENSSL" |
| 27 | #endif |
| 28 | |
| 29 | #include <stddef.h> /* size_t */ |
| 30 | #include <stdint.h> |
| 31 | |
| 32 | #include <haproxy/buf-t.h> |
| 33 | |
| 34 | #define QUIC_CC_INFINITE_SSTHESH ((uint64_t)-1) |
| 35 | |
| 36 | extern struct quic_cc_algo quic_cc_algo_nr; |
| 37 | extern struct quic_cc_algo *default_quic_cc_algo; |
| 38 | |
| 39 | enum quic_cc_algo_state_type { |
| 40 | /* Slow start. */ |
| 41 | QUIC_CC_ST_SS, |
| 42 | /* Congestion avoidance. */ |
| 43 | QUIC_CC_ST_CA, |
| 44 | }; |
| 45 | |
| 46 | enum quic_cc_event_type { |
| 47 | /* ACK receipt. */ |
| 48 | QUIC_CC_EVT_ACK, |
| 49 | /* Packet loss. */ |
| 50 | QUIC_CC_EVT_LOSS, |
| 51 | /* ECN-CE. */ |
| 52 | QUIC_CC_EVT_ECN_CE, |
| 53 | }; |
| 54 | |
| 55 | struct quic_cc_event { |
| 56 | enum quic_cc_event_type type; |
| 57 | union { |
| 58 | struct ack { |
| 59 | uint64_t acked; |
| 60 | unsigned int time_sent; |
| 61 | } ack; |
| 62 | struct loss { |
| 63 | unsigned int now_ms; |
| 64 | unsigned int max_ack_delay; |
| 65 | size_t lost_bytes; |
| 66 | unsigned int newest_time_sent; |
| 67 | unsigned int period; |
| 68 | } loss; |
| 69 | }; |
| 70 | }; |
| 71 | |
| 72 | enum quic_cc_algo_type { |
| 73 | QUIC_CC_ALGO_TP_NEWRENO, |
| 74 | }; |
| 75 | |
| 76 | union quic_cc_algo_state { |
| 77 | /* NewReno */ |
| 78 | struct nr { |
| 79 | enum quic_cc_algo_state_type state; |
| 80 | uint64_t cwnd; |
| 81 | uint64_t ssthresh; |
| 82 | uint64_t recovery_start_time; |
| 83 | } nr; |
| 84 | }; |
| 85 | |
| 86 | struct quic_cc { |
| 87 | /* <conn> is there ony for debugging purpose. */ |
| 88 | struct quic_conn *qc; |
| 89 | struct quic_cc_algo *algo; |
| 90 | union quic_cc_algo_state algo_state; |
| 91 | }; |
| 92 | |
| 93 | struct quic_cc_algo { |
| 94 | enum quic_cc_algo_type type; |
| 95 | int (*init)(struct quic_cc *cc); |
| 96 | void (*event)(struct quic_cc *cc, struct quic_cc_event *ev); |
| 97 | void (*state_trace)(struct buffer *buf, const struct quic_cc *cc); |
| 98 | }; |
| 99 | |
| 100 | #endif /* USE_QUIC */ |
| 101 | #endif /* _HAPROXY_QUIC_CC_H */ |