quic_cc behaviour (quic v1.9.1)
View SourceQUIC congestion control behavior and facade.
This module defines the behavior for pluggable congestion control algorithms and provides a facade that delegates to the selected implementation.
Available Algorithms
- newreno (default): RFC 9002 NewReno implementation - bbr: BBRv3 (future implementation)
Usage
%% Create with default algorithm (NewReno)
State = quic_cc:new(),
State = quic_cc:new(#{initial_window => 65536}),
%% Create with explicit algorithm
State = quic_cc:new(newreno, #{}),
State = quic_cc:new(bbr, #{}).
Summary
Functions
Get the algorithm name for this CC state.
Get the available congestion window.
Get bytes currently in flight.
Check if we can send more bytes.
Check if a control message can be sent.
Get the current congestion window.
Detect persistent congestion from lost packets.
Get the current ECN-CE counter.
Get pacing tokens for sending.
Check if in recovery phase.
Check if in slow start phase.
Get the current max datagram size.
Get minimum recovery duration setting.
Create a new congestion control state with default algorithm (NewReno).
Create a new congestion control state with options. Uses the algorithm specified in options, or NewReno by default.
Create a new congestion control state with explicit algorithm.
Handle a congestion event (packet loss detected).
Handle ECN-CE signal.
Record that a packet was sent.
Process acknowledged packets.
Process acknowledged packets with largest acked sent time.
Process lost packets.
Batched on_packet_sent for a run: one update for newreno, a fold for other algorithms.
Handle persistent congestion.
Check if pacing allows sending.
Calculate pacing delay.
Fused send check (cwnd + pacing) for the hot send path. See the behavior callback for the return shape.
Batched send_check: approve up to MaxK packets of Size in one pass. Native for newreno; other algorithms fold send_check/3 with identical results.
Get the slow start threshold.
Update congestion control state when MTU changes.
Update pacing rate based on smoothed RTT.
Types
-type cc_algorithm() :: newreno | bbr | cubic.
-type cc_opts() :: #{initial_window => pos_integer(), minimum_window => pos_integer(), min_recovery_duration => non_neg_integer(), max_datagram_size => pos_integer(), algorithm => cc_algorithm()}.
-opaque cc_state()
Callbacks
-callback available_cwnd(State :: term()) -> non_neg_integer().
-callback bytes_in_flight(State :: term()) -> non_neg_integer().
-callback can_send(State :: term(), Size :: non_neg_integer()) -> boolean().
-callback can_send_control(State :: term(), Size :: non_neg_integer()) -> boolean().
-callback cwnd(State :: term()) -> non_neg_integer().
-callback detect_persistent_congestion(LostInfo :: [{non_neg_integer(), non_neg_integer()}], PTO :: non_neg_integer(), State :: term()) -> boolean().
-callback ecn_ce_counter(State :: term()) -> non_neg_integer().
-callback get_pacing_tokens(State :: term(), Size :: non_neg_integer()) -> {non_neg_integer(), State :: term()}.
-callback max_datagram_size(State :: term()) -> pos_integer().
-callback min_recovery_duration(State :: term()) -> non_neg_integer().
-callback on_congestion_event(State :: term(), SentTime :: non_neg_integer()) -> State :: term().
-callback on_ecn_ce(State :: term(), ECNCE :: non_neg_integer()) -> State :: term().
-callback on_packet_sent(State :: term(), Size :: non_neg_integer()) -> State :: term().
-callback on_packets_acked(State :: term(), AckedBytes :: non_neg_integer()) -> State :: term().
-callback on_packets_acked(State :: term(), AckedBytes :: non_neg_integer(), LargestAckedSentTime :: non_neg_integer()) -> State :: term().
-callback on_packets_lost(State :: term(), LostBytes :: non_neg_integer()) -> State :: term().
-callback pacing_allows(State :: term(), Size :: non_neg_integer()) -> boolean().
-callback pacing_delay(State :: term(), Size :: non_neg_integer()) -> non_neg_integer().
-callback send_check(State :: term(), Size :: non_neg_integer(), Urgency :: non_neg_integer()) -> {ok, State :: term()} | {blocked_cwnd, non_neg_integer()} | {blocked_pacing, non_neg_integer()}.
-callback ssthresh(State :: term()) -> non_neg_integer() | infinity.
-callback update_mtu(State :: term(), NewMTU :: pos_integer()) -> State :: term().
-callback update_pacing_rate(State :: term(), SmoothedRTT :: non_neg_integer()) -> State :: term().
Functions
-spec algorithm(cc_state()) -> cc_algorithm().
Get the algorithm name for this CC state.
-spec available_cwnd(cc_state()) -> non_neg_integer().
Get the available congestion window.
-spec bytes_in_flight(cc_state()) -> non_neg_integer().
Get bytes currently in flight.
-spec can_send(cc_state(), non_neg_integer()) -> boolean().
Check if we can send more bytes.
-spec can_send_control(cc_state(), non_neg_integer()) -> boolean().
Check if a control message can be sent.
-spec cwnd(cc_state()) -> non_neg_integer().
Get the current congestion window.
-spec detect_persistent_congestion([{non_neg_integer(), non_neg_integer()}], non_neg_integer(), cc_state()) -> boolean().
Detect persistent congestion from lost packets.
-spec ecn_ce_counter(cc_state()) -> non_neg_integer().
Get the current ECN-CE counter.
-spec get_pacing_tokens(cc_state(), non_neg_integer()) -> {non_neg_integer(), cc_state()}.
Get pacing tokens for sending.
Check if in recovery phase.
Check if in slow start phase.
-spec max_datagram_size(cc_state()) -> pos_integer().
Get the current max datagram size.
-spec min_recovery_duration(cc_state()) -> non_neg_integer().
Get minimum recovery duration setting.
-spec new() -> cc_state().
Create a new congestion control state with default algorithm (NewReno).
Create a new congestion control state with options. Uses the algorithm specified in options, or NewReno by default.
Options: - algorithm: CC algorithm (newreno | bbr), default: newreno - max_datagram_size: Maximum datagram size (default: 1200) - initial_window: Override initial congestion window - minimum_window: Lower bound for cwnd after congestion events - min_recovery_duration: Minimum time in recovery before exit (ms)
-spec new(cc_algorithm(), cc_opts()) -> cc_state().
Create a new congestion control state with explicit algorithm.
Algorithm: newreno | bbr Options: Same as new/1 (algorithm option is ignored)
-spec on_congestion_event(cc_state(), non_neg_integer()) -> cc_state().
Handle a congestion event (packet loss detected).
-spec on_ecn_ce(cc_state(), non_neg_integer()) -> cc_state().
Handle ECN-CE signal.
-spec on_packet_sent(cc_state(), non_neg_integer()) -> cc_state().
Record that a packet was sent.
-spec on_packets_acked(cc_state(), non_neg_integer()) -> cc_state().
Process acknowledged packets.
-spec on_packets_acked(cc_state(), non_neg_integer(), non_neg_integer()) -> cc_state().
Process acknowledged packets with largest acked sent time.
-spec on_packets_lost(cc_state(), non_neg_integer()) -> cc_state().
Process lost packets.
-spec on_packets_sent(cc_state(), [non_neg_integer()]) -> cc_state().
Batched on_packet_sent for a run: one update for newreno, a fold for other algorithms.
Handle persistent congestion.
-spec pacing_allows(cc_state(), non_neg_integer()) -> boolean().
Check if pacing allows sending.
-spec pacing_delay(cc_state(), non_neg_integer()) -> non_neg_integer().
Calculate pacing delay.
-spec send_check(cc_state(), non_neg_integer(), non_neg_integer()) -> {ok, cc_state()} | {blocked_cwnd, non_neg_integer()} | {blocked_pacing, non_neg_integer()}.
Fused send check (cwnd + pacing) for the hot send path. See the behavior callback for the return shape.
-spec send_check_run(cc_state(), non_neg_integer(), non_neg_integer(), non_neg_integer()) -> {non_neg_integer(), cc_state()}.
Batched send_check: approve up to MaxK packets of Size in one pass. Native for newreno; other algorithms fold send_check/3 with identical results.
-spec ssthresh(cc_state()) -> non_neg_integer() | infinity.
Get the slow start threshold.
-spec update_mtu(cc_state(), pos_integer()) -> cc_state().
Update congestion control state when MTU changes.
-spec update_pacing_rate(cc_state(), non_neg_integer()) -> cc_state().
Update pacing rate based on smoothed RTT.