diff options
author | Hugo Landau <hlandau@openssl.org> | 2023-04-21 10:56:48 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2023-05-01 11:03:54 +0100 |
commit | 878df9be67df14c90ef584e5762a8c1f5c8f9749 (patch) | |
tree | 29f19d39fd3315f59bab61ca555073ac2b20f2fa /test | |
parent | b633cf876435f094e4944f30be4dbbc70115f230 (diff) |
QUIC CC: Use OSSL_PARAM
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20423)
Diffstat (limited to 'test')
-rw-r--r-- | test/cc_dummy.c | 68 | ||||
-rw-r--r-- | test/quic_cc_test.c | 62 |
2 files changed, 87 insertions, 43 deletions
diff --git a/test/cc_dummy.c b/test/cc_dummy.c index af0d548379..0331a7cdcf 100644 --- a/test/cc_dummy.c +++ b/test/cc_dummy.c @@ -12,8 +12,11 @@ typedef struct ossl_cc_dummy_st { size_t max_dgram_len; + size_t *p_diag_max_dgram_len; } OSSL_CC_DUMMY; +static void dummy_update_diag(OSSL_CC_DUMMY *d); + static OSSL_CC_DATA *dummy_new(OSSL_TIME (*now_cb)(void *arg), void *now_cb_arg) { @@ -36,39 +39,59 @@ static void dummy_reset(OSSL_CC_DATA *cc) } -static int dummy_set_option_uint(OSSL_CC_DATA *cc, - uint32_t option_id, - uint64_t value) +static int dummy_set_input_params(OSSL_CC_DATA *cc, const OSSL_PARAM *params) { OSSL_CC_DUMMY *d = (OSSL_CC_DUMMY *)cc; + const OSSL_PARAM *p; + size_t value; - switch (option_id) { - case OSSL_CC_OPTION_MAX_DGRAM_PAYLOAD_LEN: - if (value > SIZE_MAX) + p = OSSL_PARAM_locate_const(params, OSSL_CC_OPTION_MAX_DGRAM_PAYLOAD_LEN); + if (p != NULL) { + if (!OSSL_PARAM_get_size_t(p, &value)) + return 0; + if (value < QUIC_MIN_INITIAL_DGRAM_LEN) return 0; - d->max_dgram_len = (size_t)value; - return 1; - - default: - return 0; + d->max_dgram_len = value; + dummy_update_diag(d); } + + return 1; } -static int dummy_get_option_uint(OSSL_CC_DATA *cc, - uint32_t option_id, - uint64_t *value) +static int dummy_bind_diagnostic(OSSL_CC_DATA *cc, OSSL_PARAM *params) { OSSL_CC_DUMMY *d = (OSSL_CC_DUMMY *)cc; + const OSSL_PARAM *p; - switch (option_id) { - case OSSL_CC_OPTION_MAX_DGRAM_PAYLOAD_LEN: - *value = (uint64_t)d->max_dgram_len; - return 1; + p = OSSL_PARAM_locate_const(params, OSSL_CC_OPTION_MAX_DGRAM_PAYLOAD_LEN); + if (p != NULL) { + if (p->data_type != OSSL_PARAM_UNSIGNED_INTEGER + || p->data_size != sizeof(size_t)) + return 0; - default: - return 0; + d->p_diag_max_dgram_len = p->data; } + + dummy_update_diag(d); + return 1; +} + +static int dummy_unbind_diagnostic(OSSL_CC_DATA *cc, OSSL_PARAM *params) +{ + OSSL_CC_DUMMY *d = (OSSL_CC_DUMMY *)cc; + + if (OSSL_PARAM_locate_const(params, OSSL_CC_OPTION_MAX_DGRAM_PAYLOAD_LEN) + != NULL) + d->p_diag_max_dgram_len = NULL; + + return 1; +} + +static void dummy_update_diag(OSSL_CC_DUMMY *d) +{ + if (d->p_diag_max_dgram_len != NULL) + *d->p_diag_max_dgram_len = d->max_dgram_len; } static uint64_t dummy_get_tx_allowance(OSSL_CC_DATA *cc) @@ -115,8 +138,9 @@ const OSSL_CC_METHOD ossl_cc_dummy_method = { dummy_new, dummy_free, dummy_reset, - dummy_set_option_uint, - dummy_get_option_uint, + dummy_set_input_params, + dummy_bind_diagnostic, + dummy_unbind_diagnostic, dummy_get_tx_allowance, dummy_get_wakeup_deadline, dummy_on_data_sent, diff --git a/test/quic_cc_test.c b/test/quic_cc_test.c index 87f9e268d2..ce2507e68d 100644 --- a/test/quic_cc_test.c +++ b/test/quic_cc_test.c @@ -328,11 +328,14 @@ static int test_simulate(void) int have_sim = 0; const OSSL_CC_METHOD *ccm = &ossl_cc_newreno_method; OSSL_CC_DATA *cc = NULL; - uint64_t mdpl = 1472; + size_t mdpl = 1472; uint64_t total_sent = 0, total_to_send, allowance; uint64_t actual_capacity = 16000; /* B/s - 128kb/s */ uint64_t cwnd_sample_sum = 0, cwnd_sample_count = 0; + uint64_t diag_cur_bytes_in_flight = UINT64_MAX; + uint64_t diag_cur_cwnd_size = UINT64_MAX; struct net_sim sim; + OSSL_PARAM params[3], *p = params; fake_time = TIME_BASE; @@ -344,8 +347,21 @@ static int test_simulate(void) have_sim = 1; - if (!TEST_true(ccm->set_option_uint(cc, OSSL_CC_OPTION_MAX_DGRAM_PAYLOAD_LEN, - mdpl))) + *p++ = OSSL_PARAM_construct_size_t(OSSL_CC_OPTION_MAX_DGRAM_PAYLOAD_LEN, + &mdpl); + *p++ = OSSL_PARAM_construct_end(); + + if (!TEST_true(ccm->set_input_params(cc, params))) + goto err; + + p = params; + *p++ = OSSL_PARAM_construct_uint64(OSSL_CC_OPTION_CUR_BYTES_IN_FLIGHT, + &diag_cur_bytes_in_flight); + *p++ = OSSL_PARAM_construct_uint64(OSSL_CC_OPTION_CUR_CWND_SIZE, + &diag_cur_cwnd_size); + *p++ = OSSL_PARAM_construct_end(); + + if (!TEST_true(ccm->bind_diagnostics(cc, params))) goto err; ccm->reset(cc); @@ -399,13 +415,7 @@ static int test_simulate(void) * have at least one MDPL's worth of allowance as nothing is in flight. */ if (rc == 3) { - uint64_t v = 1; - - if (!TEST_true(ccm->get_option_uint(cc, OSSL_CC_OPTION_CUR_BYTES_IN_FLIGHT, - &v))) - goto err; - - if (!TEST_uint64_t_eq(v, 0)) + if (!TEST_uint64_t_eq(diag_cur_bytes_in_flight, 0)) goto err; if (!TEST_uint64_t_ge(ccm->get_tx_allowance(cc), mdpl)) @@ -416,8 +426,8 @@ static int test_simulate(void) { uint64_t v = 1; - if (!TEST_true(ccm->get_option_uint(cc, OSSL_CC_OPTION_CUR_CWND_SIZE, - &v))) + if (!TEST_uint64_t_ne(diag_cur_bytes_in_flight, UINT64_MAX) + || !TEST_uint64_t_ne(diag_cur_cwnd_size, UINT64_MAX)) goto err; cwnd_sample_sum += v; @@ -471,7 +481,10 @@ static int test_sanity(void) const OSSL_CC_METHOD *ccm = &ossl_cc_newreno_method; OSSL_CC_LOSS_INFO loss_info = {0}; OSSL_CC_ACK_INFO ack_info = {0}; - uint64_t allowance, allowance2, v = 1; + uint64_t allowance, allowance2; + OSSL_PARAM params[3], *p = params; + size_t mdpl = 1472, diag_mdpl = SIZE_MAX; + uint64_t diag_cur_bytes_in_flight = UINT64_MAX; fake_time = TIME_BASE; @@ -479,15 +492,24 @@ static int test_sanity(void) goto err; /* Test configuration of options. */ - if (!TEST_true(ccm->set_option_uint(cc, OSSL_CC_OPTION_MAX_DGRAM_PAYLOAD_LEN, - 1472))) + *p++ = OSSL_PARAM_construct_size_t(OSSL_CC_OPTION_MAX_DGRAM_PAYLOAD_LEN, + &mdpl); + *p++ = OSSL_PARAM_construct_end(); + + if (!TEST_true(ccm->set_input_params(cc, params))) goto err; ccm->reset(cc); - if (!TEST_true(ccm->get_option_uint(cc, OSSL_CC_OPTION_MAX_DGRAM_PAYLOAD_LEN, - &v)) - || !TEST_uint64_t_eq(v, 1472)) + p = params; + *p++ = OSSL_PARAM_construct_size_t(OSSL_CC_OPTION_MAX_DGRAM_PAYLOAD_LEN, + &diag_mdpl); + *p++ = OSSL_PARAM_construct_uint64(OSSL_CC_OPTION_CUR_BYTES_IN_FLIGHT, + &diag_cur_bytes_in_flight); + *p++ = OSSL_PARAM_construct_end(); + + if (!TEST_true(ccm->bind_diagnostics(cc, params)) + || !TEST_size_t_eq(diag_mdpl, 1472)) goto err; if (!TEST_uint64_t_ge(allowance = ccm->get_tx_allowance(cc), 1472)) @@ -501,9 +523,7 @@ static int test_sanity(void) goto err; /* No bytes should currently be in flight. */ - if (!TEST_true(ccm->get_option_uint(cc, OSSL_CC_OPTION_CUR_BYTES_IN_FLIGHT, - &v)) - || !TEST_uint64_t_eq(v, 0)) + if (!TEST_uint64_t_eq(diag_cur_bytes_in_flight, 0)) goto err; /* Tell the CC we have sent some data. */ |