2 * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include "internal/packet.h"
11 #include "internal/quic_cfq.h"
12 #include "internal/quic_wire.h"
15 static const unsigned char ref_buf[] = {
16 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19
19 static const uint32_t ref_priority[] = {
20 90, 80, 70, 60, 95, 40, 94, 20, 10, 0
23 static const uint32_t ref_pn_space[] = {
24 QUIC_PN_SPACE_INITIAL,
25 QUIC_PN_SPACE_HANDSHAKE,
26 QUIC_PN_SPACE_HANDSHAKE,
27 QUIC_PN_SPACE_INITIAL,
28 QUIC_PN_SPACE_INITIAL,
29 QUIC_PN_SPACE_INITIAL,
30 QUIC_PN_SPACE_INITIAL,
31 QUIC_PN_SPACE_INITIAL,
36 static const uint64_t ref_frame_type[] = {
37 OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID,
38 OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID,
39 OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID,
40 OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID,
41 OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID,
42 OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID,
43 OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID,
44 OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID,
45 OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID,
46 OSSL_QUIC_FRAME_TYPE_RETIRE_CONN_ID,
49 static const uint32_t expect[QUIC_PN_SPACE_NUM][11] = {
50 { 4, 6, 0, 3, 5, 7, UINT32_MAX },
55 static QUIC_CFQ_ITEM *items[QUIC_PN_SPACE_NUM][10];
57 static unsigned char *g_free;
58 static size_t g_free_len;
60 static void free_cb(unsigned char *buf, size_t buf_len, void *arg)
66 static int check(QUIC_CFQ *cfq)
73 for (pn_space = QUIC_PN_SPACE_INITIAL; pn_space < QUIC_PN_SPACE_NUM; ++pn_space)
74 for (i = 0, item = ossl_quic_cfq_get_priority_head(cfq, pn_space);;
75 ++i, item = ossl_quic_cfq_item_get_priority_next(item, pn_space)) {
77 if (expect[pn_space][i] == UINT32_MAX) {
78 if (!TEST_ptr_null(item))
84 items[pn_space][i] = item;
87 || !TEST_ptr_eq(ossl_quic_cfq_item_get_encoded(item),
88 ref_buf + expect[pn_space][i])
89 || !TEST_int_eq(ossl_quic_cfq_item_get_pn_space(item), pn_space)
90 || !TEST_int_eq(ossl_quic_cfq_item_get_state(item),
100 static int test_cfq(void)
103 QUIC_CFQ *cfq = NULL;
104 QUIC_CFQ_ITEM *item, *inext;
108 if (!TEST_ptr(cfq = ossl_quic_cfq_new()))
114 for (i = 0; i < OSSL_NELEM(ref_buf); ++i) {
115 if (!TEST_ptr(item = ossl_quic_cfq_add_frame(cfq, ref_priority[i],
122 || !TEST_int_eq(ossl_quic_cfq_item_get_state(item),
124 || !TEST_uint_eq(ossl_quic_cfq_item_get_pn_space(item),
126 || !TEST_uint64_t_eq(ossl_quic_cfq_item_get_frame_type(item),
128 || !TEST_ptr_eq(ossl_quic_cfq_item_get_encoded(item),
130 || !TEST_size_t_eq(ossl_quic_cfq_item_get_encoded_len(item),
138 for (pn_space = QUIC_PN_SPACE_INITIAL; pn_space < QUIC_PN_SPACE_NUM; ++pn_space)
139 for (item = ossl_quic_cfq_get_priority_head(cfq, pn_space);
140 item != NULL; item = inext) {
141 inext = ossl_quic_cfq_item_get_priority_next(item, pn_space);
143 ossl_quic_cfq_mark_tx(cfq, item);
146 for (pn_space = QUIC_PN_SPACE_INITIAL; pn_space < QUIC_PN_SPACE_NUM; ++pn_space)
147 if (!TEST_ptr_null(ossl_quic_cfq_get_priority_head(cfq, pn_space)))
150 for (pn_space = QUIC_PN_SPACE_INITIAL; pn_space < QUIC_PN_SPACE_NUM; ++pn_space)
151 for (i = 0; i < OSSL_NELEM(items[0]); ++i)
152 if (items[pn_space][i] != NULL)
153 ossl_quic_cfq_mark_lost(cfq, items[pn_space][i], UINT32_MAX);
158 for (pn_space = QUIC_PN_SPACE_INITIAL; pn_space < QUIC_PN_SPACE_NUM; ++pn_space)
159 for (i = 0; i < OSSL_NELEM(items[0]); ++i)
160 if (items[pn_space][i] != NULL)
161 ossl_quic_cfq_release(cfq, items[pn_space][i]);
163 for (pn_space = QUIC_PN_SPACE_INITIAL; pn_space < QUIC_PN_SPACE_NUM; ++pn_space)
164 if (!TEST_ptr_null(ossl_quic_cfq_get_priority_head(cfq, pn_space)))
169 ossl_quic_cfq_free(cfq);
173 int setup_tests(void)