Frédéric Lécaille | db4bc6b | 2023-03-31 15:21:55 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Fake congestion control algorithm which does nothing except initializing |
| 3 | * the congestion control window to a fixed value. |
| 4 | * |
| 5 | */ |
| 6 | |
| 7 | #include <haproxy/api-t.h> |
| 8 | #include <haproxy/quic_conn-t.h> |
| 9 | #include <haproxy/trace.h> |
| 10 | |
| 11 | #define TRACE_SOURCE &trace_quic |
| 12 | |
| 13 | unsigned int quic_cc_nocc_fixed_cwnd; |
| 14 | |
| 15 | static int quic_cc_nocc_init(struct quic_cc *cc) |
| 16 | { |
| 17 | struct quic_path *path; |
| 18 | |
| 19 | path = container_of(cc, struct quic_path, cc); |
| 20 | path->cwnd = quic_cc_nocc_fixed_cwnd << 10; |
| 21 | return 1; |
| 22 | } |
| 23 | |
| 24 | static void quic_cc_nocc_slow_start(struct quic_cc *cc) |
| 25 | { |
| 26 | } |
| 27 | |
| 28 | /* Slow start callback. */ |
| 29 | static void quic_cc_nocc_ss_cb(struct quic_cc *cc, struct quic_cc_event *ev) |
| 30 | { |
| 31 | TRACE_ENTER(QUIC_EV_CONN_CC, cc->qc); |
| 32 | TRACE_PROTO("CC nocc", QUIC_EV_CONN_CC, cc->qc, ev, cc); |
| 33 | TRACE_LEAVE(QUIC_EV_CONN_CC, cc->qc); |
| 34 | } |
| 35 | |
| 36 | /* Congestion avoidance callback. */ |
| 37 | static void quic_cc_nocc_ca_cb(struct quic_cc *cc, struct quic_cc_event *ev) |
| 38 | { |
| 39 | TRACE_ENTER(QUIC_EV_CONN_CC, cc->qc); |
| 40 | TRACE_PROTO("CC nocc", QUIC_EV_CONN_CC, cc->qc, ev, cc); |
| 41 | TRACE_LEAVE(QUIC_EV_CONN_CC, cc->qc); |
| 42 | } |
| 43 | |
| 44 | /* Recovery period callback. */ |
| 45 | static void quic_cc_nocc_rp_cb(struct quic_cc *cc, struct quic_cc_event *ev) |
| 46 | { |
| 47 | TRACE_ENTER(QUIC_EV_CONN_CC, cc->qc); |
| 48 | TRACE_PROTO("CC nocc", QUIC_EV_CONN_CC, cc->qc, ev, cc); |
| 49 | TRACE_LEAVE(QUIC_EV_CONN_CC, cc->qc); |
| 50 | } |
| 51 | |
| 52 | static void quic_cc_nocc_state_trace(struct buffer *buf, const struct quic_cc *cc) |
| 53 | { |
| 54 | struct quic_path *path; |
| 55 | |
| 56 | path = container_of(cc, struct quic_path, cc); |
| 57 | chunk_appendf(buf, " cwnd=%llu", (unsigned long long)path->cwnd); |
| 58 | } |
| 59 | |
| 60 | static void (*quic_cc_nocc_state_cbs[])(struct quic_cc *cc, |
| 61 | struct quic_cc_event *ev) = { |
| 62 | [QUIC_CC_ST_SS] = quic_cc_nocc_ss_cb, |
| 63 | [QUIC_CC_ST_CA] = quic_cc_nocc_ca_cb, |
| 64 | [QUIC_CC_ST_RP] = quic_cc_nocc_rp_cb, |
| 65 | }; |
| 66 | |
| 67 | static void quic_cc_nocc_event(struct quic_cc *cc, struct quic_cc_event *ev) |
| 68 | { |
Frédéric Lécaille | 7d6270a | 2023-04-02 12:43:22 +0200 | [diff] [blame] | 69 | return quic_cc_nocc_state_cbs[QUIC_CC_ST_SS](cc, ev); |
Frédéric Lécaille | db4bc6b | 2023-03-31 15:21:55 +0200 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | struct quic_cc_algo quic_cc_algo_nocc = { |
| 73 | .type = QUIC_CC_ALGO_TP_NOCC, |
| 74 | .init = quic_cc_nocc_init, |
| 75 | .event = quic_cc_nocc_event, |
| 76 | .slow_start = quic_cc_nocc_slow_start, |
| 77 | .state_trace = quic_cc_nocc_state_trace, |
| 78 | }; |
| 79 | |