From 3c8caec7eee9e85690d894f0773e1c08773fb4da Mon Sep 17 00:00:00 2001 From: William Yang Date: Fri, 4 Oct 2024 23:54:50 +0200 Subject: [PATCH 1/3] feat(setopt): congestion control algorithm --- c_src/quicer_config.c | 10 ++++++++++ c_src/quicer_eterms.h | 1 + c_src/quicer_nif.c | 3 +++ include/quicer.hrl | 4 ++++ include/quicer_types.hrl | 1 + test/prop_quic_types.hrl | 1 + 6 files changed, 20 insertions(+) diff --git a/c_src/quicer_config.c b/c_src/quicer_config.c index 529c7339..6f870020 100644 --- a/c_src/quicer_config.c +++ b/c_src/quicer_config.c @@ -753,6 +753,8 @@ encode_parm_to_eterm(ErlNifEnv *env, Settings->DisconnectTimeoutMs), PropTupleAtomInt(ATOM_QUIC_SETTINGS_KeepAliveIntervalMs, Settings->KeepAliveIntervalMs), + PropTupleAtomInt(ATOM_QUIC_SETTINGS_CongestionControlAlgorithm, + Settings->CongestionControlAlgorithm), PropTupleAtomInt(ATOM_QUIC_SETTINGS_PeerBidiStreamCount, Settings->PeerBidiStreamCount), PropTupleAtomInt(ATOM_QUIC_SETTINGS_PeerUnidiStreamCount, @@ -1160,6 +1162,14 @@ create_settings(ErlNifEnv *env, { Settings->IsSet.KeepAliveIntervalMs = TRUE; } + if (get_uint16_from_map(env, + *emap, + ATOM_QUIC_SETTINGS_CongestionControlAlgorithm, + &Settings->CongestionControlAlgorithm)) + { + Settings->IsSet.CongestionControlAlgorithm = TRUE; + } + if (get_uint16_from_map(env, *emap, ATOM_QUIC_SETTINGS_PeerBidiStreamCount, diff --git a/c_src/quicer_eterms.h b/c_src/quicer_eterms.h index 71b66b2c..e126d48d 100644 --- a/c_src/quicer_eterms.h +++ b/c_src/quicer_eterms.h @@ -254,6 +254,7 @@ extern ERL_NIF_TERM ATOM_QUIC_SETTINGS_InitialRttMs; extern ERL_NIF_TERM ATOM_QUIC_SETTINGS_MaxAckDelayMs; extern ERL_NIF_TERM ATOM_QUIC_SETTINGS_DisconnectTimeoutMs; extern ERL_NIF_TERM ATOM_QUIC_SETTINGS_KeepAliveIntervalMs; +extern ERL_NIF_TERM ATOM_QUIC_SETTINGS_CongestionControlAlgorithm; extern ERL_NIF_TERM ATOM_QUIC_SETTINGS_PeerBidiStreamCount; extern ERL_NIF_TERM ATOM_QUIC_SETTINGS_PeerUnidiStreamCount; extern ERL_NIF_TERM ATOM_QUIC_SETTINGS_RetryMemoryLimit; diff --git a/c_src/quicer_nif.c b/c_src/quicer_nif.c index 545d8857..04e8f34d 100644 --- a/c_src/quicer_nif.c +++ b/c_src/quicer_nif.c @@ -278,6 +278,7 @@ ERL_NIF_TERM ATOM_QUIC_SETTINGS_InitialRttMs; ERL_NIF_TERM ATOM_QUIC_SETTINGS_MaxAckDelayMs; ERL_NIF_TERM ATOM_QUIC_SETTINGS_DisconnectTimeoutMs; ERL_NIF_TERM ATOM_QUIC_SETTINGS_KeepAliveIntervalMs; +ERL_NIF_TERM ATOM_QUIC_SETTINGS_CongestionControlAlgorithm; ERL_NIF_TERM ATOM_QUIC_SETTINGS_PeerBidiStreamCount; ERL_NIF_TERM ATOM_QUIC_SETTINGS_PeerUnidiStreamCount; ERL_NIF_TERM ATOM_QUIC_SETTINGS_RetryMemoryLimit; @@ -687,6 +688,8 @@ ERL_NIF_TERM ATOM_QUIC_SEND_ECN_CONGESTION_COUNT; ATOM(ATOM_QUIC_SETTINGS_MaxAckDelayMs, max_ack_delay_ms); \ ATOM(ATOM_QUIC_SETTINGS_DisconnectTimeoutMs, disconnect_timeout_ms); \ ATOM(ATOM_QUIC_SETTINGS_KeepAliveIntervalMs, keep_alive_interval_ms); \ + ATOM(ATOM_QUIC_SETTINGS_CongestionControlAlgorithm, \ + congestion_control_algorithm); \ ATOM(ATOM_QUIC_SETTINGS_PeerBidiStreamCount, peer_bidi_stream_count); \ ATOM(ATOM_QUIC_SETTINGS_PeerUnidiStreamCount, peer_unidi_stream_count); \ ATOM(ATOM_QUIC_SETTINGS_RetryMemoryLimit, retry_memory_limit); \ diff --git a/include/quicer.hrl b/include/quicer.hrl index fab22754..24de956e 100644 --- a/include/quicer.hrl +++ b/include/quicer.hrl @@ -146,4 +146,8 @@ -define(QUIC_LOAD_BALANCING_COUNT, 3). -define(QUICER_LOAD_BALANCING_IFIP_AS_SERVER_ID, 100). %% User Network Interface IP as Server ID +-define(QUIC_CONGESTION_CONTROL_ALGORITHM_CUBIC, 0). +-define(QUIC_CONGESTION_CONTROL_ALGORITHM_BBR, 1). +-define(QUIC_CONGESTION_CONTROL_ALGORITHM_MAX, 2). + -endif. %% QUICER_HRL diff --git a/include/quicer_types.hrl b/include/quicer_types.hrl index 2b38262d..8a46ee82 100644 --- a/include/quicer_types.hrl +++ b/include/quicer_types.hrl @@ -116,6 +116,7 @@ max_ack_delay_ms => uint32(), disconnect_timeout_ms => uint32(), keep_alive_interval_ms => uint32(), + congestion_control_algorithm => uint16(), peer_bidi_stream_count => uint16(), peer_unidi_stream_count => uint16(), retry_memory_limit => uint16(), diff --git a/test/prop_quic_types.hrl b/test/prop_quic_types.hrl index b11b4940..15323167 100644 --- a/test/prop_quic_types.hrl +++ b/test/prop_quic_types.hrl @@ -77,6 +77,7 @@ | {max_ack_delay_ms, uint32()} | {disconnect_timeout_ms, uint32()} | {keep_alive_interval_ms, uint32()} + | {congestion_control_algorithm, uint16()} | {peer_bidi_stream_count, uint16()} | {peer_unidi_stream_count, uint16()} | {retry_memory_limit, uint16()} From 7200040fb95c63f2fc9346705027df2cce5293e3 Mon Sep 17 00:00:00 2001 From: William Yang Date: Mon, 7 Oct 2024 11:28:41 +0200 Subject: [PATCH 2/3] test(cc-alg): add a test in ct --- include/quicer.hrl | 1 - test/quicer_SUITE.erl | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/include/quicer.hrl b/include/quicer.hrl index 24de956e..9a7f969a 100644 --- a/include/quicer.hrl +++ b/include/quicer.hrl @@ -148,6 +148,5 @@ -define(QUIC_CONGESTION_CONTROL_ALGORITHM_CUBIC, 0). -define(QUIC_CONGESTION_CONTROL_ALGORITHM_BBR, 1). --define(QUIC_CONGESTION_CONTROL_ALGORITHM_MAX, 2). -endif. %% QUICER_HRL diff --git a/test/quicer_SUITE.erl b/test/quicer_SUITE.erl index 74d5d589..fcd8c11e 100644 --- a/test/quicer_SUITE.erl +++ b/test/quicer_SUITE.erl @@ -91,6 +91,7 @@ tc_setopt/1, tc_setopt_remote_addr/1, tc_getopt_settings/1, + tc_setopt_congestion_control_algorithm/1, %% @TODO following two tcs are failing due to: % https://github.com/microsoft/msquic/issues/2033 @@ -3162,6 +3163,42 @@ tc_setopt_global_lb_mode_ifip(_Config) -> quicer:getopt(quic_global, load_balacing_mode) ). +tc_setopt_congestion_control_algorithm(Config) -> + Port = select_port(), + Owner = self(), + {SPid, _Ref} = spawn_monitor( + fun() -> + echo_server(Owner, Config, Port) + end + ), + receive + listener_ready -> + ok + after 5000 -> + ct:fail("listener_timeout") + end, + {ok, Conn} = quicer:connect( + "localhost", + Port, + [ + {congestion_control_algorithm, ?QUIC_CONGESTION_CONTROL_ALGORITHM_BBR} + | default_conn_opts() + ], + 5000 + ), + {ok, Stm} = quicer:start_stream(Conn, []), + {ok, 4} = quicer:send(Stm, <<"ping">>), + + {ok, Settings} = quicer:getopt(Conn, settings), + ?assertMatch( + ?QUIC_CONGESTION_CONTROL_ALGORITHM_BBR, + proplists:get_value(congestion_control_algorithm, Settings) + ), + + quicer:shutdown_connection(Conn), + SPid ! done, + ok. + %%% ==================== %%% Internal helpers %%% ==================== From 308627488ef012b5203b0109356161f7ff8dc613 Mon Sep 17 00:00:00 2001 From: William Yang Date: Mon, 7 Oct 2024 12:40:32 +0200 Subject: [PATCH 3/3] test: maybe fix flaky tests --- test/quicer_SUITE.erl | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/test/quicer_SUITE.erl b/test/quicer_SUITE.erl index fcd8c11e..14c65954 100644 --- a/test/quicer_SUITE.erl +++ b/test/quicer_SUITE.erl @@ -2553,10 +2553,7 @@ tc_event_start_compl_client(Config) -> {ok, Conn} = quicer:connect( "localhost", Port, - [ - {disable_1rtt_encryption, true} - | default_conn_opts() - ], + default_conn_opts(), 5000 ), %% Stream 1 enabled @@ -2616,10 +2613,7 @@ tc_event_start_compl_server(Config) -> {ok, Conn} = quicer:connect( "localhost", Port, - [ - {disable_1rtt_encryption, true} - | default_conn_opts() - ], + default_conn_opts(), 5000 ), %% Stream 1 enabled