QUIC TXP/CHANNEL: Generate MAX_STREAMS using RXFC
[openssl.git] / test / quic_txp_test.c
1 /*
2  * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
3  *
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
8  */
9 #include "internal/packet.h"
10 #include "internal/quic_txp.h"
11 #include "internal/quic_statm.h"
12 #include "internal/quic_demux.h"
13 #include "internal/quic_record_rx.h"
14 #include "testutil.h"
15 #include "quic_record_test_util.h"
16
17 static const QUIC_CONN_ID scid_1 = {
18     1, { 0x5f }
19 };
20
21 static const QUIC_CONN_ID dcid_1 = {
22     8, { 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8 }
23 };
24
25 static const QUIC_CONN_ID cid_1 = {
26     8, { 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8 }
27 };
28
29 static const unsigned char reset_token_1[16] = {
30     0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11,
31     0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x12,
32 };
33
34 static const unsigned char secret_1[32] = {
35     0x01
36 };
37
38 static OSSL_TIME fake_now(void *arg)
39 {
40     return ossl_time_now(); /* TODO */
41 }
42
43 struct helper {
44     OSSL_QUIC_TX_PACKETISER         *txp;
45     OSSL_QUIC_TX_PACKETISER_ARGS    args;
46     OSSL_QTX_ARGS                   qtx_args;
47     BIO                             *bio1, *bio2;
48     QUIC_TXFC                       conn_txfc;
49     QUIC_RXFC                       conn_rxfc, stream_rxfc;
50     QUIC_RXFC                       max_streams_bidi_rxfc, max_streams_uni_rxfc;
51     OSSL_STATM                      statm;
52     OSSL_CC_DATA                    *cc_data;
53     const OSSL_CC_METHOD            *cc_method;
54     QUIC_STREAM_MAP                 qsm;
55     char                            have_statm, have_qsm;
56     QUIC_DEMUX                      *demux;
57     OSSL_QRX                        *qrx;
58     OSSL_QRX_ARGS                   qrx_args;
59     OSSL_QRX_PKT                    *qrx_pkt;
60     PACKET                          pkt;
61     uint64_t                        frame_type;
62     union {
63         uint64_t                        max_data;
64         OSSL_QUIC_FRAME_NEW_CONN_ID     new_conn_id;
65         OSSL_QUIC_FRAME_ACK             ack;
66         struct {
67             const unsigned char *token;
68             size_t              token_len;
69         } new_token;
70         OSSL_QUIC_FRAME_CRYPTO          crypto;
71         OSSL_QUIC_FRAME_STREAM          stream;
72         OSSL_QUIC_FRAME_STOP_SENDING    stop_sending;
73         OSSL_QUIC_FRAME_RESET_STREAM    reset_stream;
74         OSSL_QUIC_FRAME_CONN_CLOSE      conn_close;
75     } frame;
76     OSSL_QUIC_ACK_RANGE     ack_ranges[16];
77 };
78
79 static void helper_cleanup(struct helper *h)
80 {
81     size_t i;
82     uint32_t pn_space;
83
84     ossl_qrx_pkt_release(h->qrx_pkt);
85     h->qrx_pkt = NULL;
86
87     for (pn_space = QUIC_PN_SPACE_INITIAL;
88          pn_space < QUIC_PN_SPACE_NUM;
89          ++pn_space)
90         ossl_ackm_on_pkt_space_discarded(h->args.ackm, pn_space);
91
92     ossl_quic_tx_packetiser_free(h->txp);
93     ossl_qtx_free(h->args.qtx);
94     ossl_quic_txpim_free(h->args.txpim);
95     ossl_quic_cfq_free(h->args.cfq);
96     if (h->cc_data != NULL)
97         h->cc_method->free(h->cc_data);
98     if (h->have_statm)
99         ossl_statm_destroy(&h->statm);
100     if (h->have_qsm)
101         ossl_quic_stream_map_cleanup(&h->qsm);
102     for (i = 0; i < QUIC_PN_SPACE_NUM; ++i)
103         ossl_quic_sstream_free(h->args.crypto[i]);
104     ossl_ackm_free(h->args.ackm);
105     ossl_qrx_free(h->qrx);
106     ossl_quic_demux_free(h->demux);
107     BIO_free(h->bio1);
108     BIO_free(h->bio2);
109 }
110
111 static int helper_init(struct helper *h)
112 {
113     int rc = 0;
114     size_t i;
115
116     memset(h, 0, sizeof(*h));
117
118     /* Initialisation */
119     if (!TEST_true(BIO_new_bio_dgram_pair(&h->bio1, 0, &h->bio2, 0)))
120         goto err;
121
122     h->qtx_args.bio    = h->bio1;
123     h->qtx_args.mdpl   = 1200;
124
125     if (!TEST_ptr(h->args.qtx = ossl_qtx_new(&h->qtx_args)))
126         goto err;
127
128     if (!TEST_ptr(h->args.txpim = ossl_quic_txpim_new()))
129         goto err;
130
131     if (!TEST_ptr(h->args.cfq = ossl_quic_cfq_new()))
132         goto err;
133
134     if (!TEST_true(ossl_quic_txfc_init(&h->conn_txfc, NULL)))
135         goto err;
136
137     if (!TEST_true(ossl_quic_rxfc_init(&h->conn_rxfc, NULL,
138                                        2 * 1024 * 1024,
139                                        10 * 1024 * 1024,
140                                        fake_now,
141                                        NULL)))
142         goto err;
143
144     if (!TEST_true(ossl_quic_rxfc_init(&h->stream_rxfc, &h->conn_rxfc,
145                                        1 * 1024 * 1024,
146                                        5 * 1024 * 1024,
147                                        fake_now,
148                                        NULL)))
149         goto err;
150
151     if (!TEST_true(ossl_quic_rxfc_init(&h->max_streams_bidi_rxfc, NULL,
152                                        100, 100,
153                                        fake_now,
154                                        NULL)))
155         goto err;
156
157     if (!TEST_true(ossl_quic_rxfc_init(&h->max_streams_uni_rxfc, NULL,
158                                        100, 100,
159                                        fake_now,
160                                        NULL)))
161
162     if (!TEST_true(ossl_statm_init(&h->statm)))
163         goto err;
164
165     h->have_statm = 1;
166
167     h->cc_method = &ossl_cc_dummy_method;
168     if (!TEST_ptr(h->cc_data = h->cc_method->new(fake_now, NULL)))
169         goto err;
170
171     if (!TEST_ptr(h->args.ackm = ossl_ackm_new(fake_now, NULL,
172                                                &h->statm,
173                                                h->cc_method,
174                                                h->cc_data)))
175         goto err;
176
177     if (!TEST_true(ossl_quic_stream_map_init(&h->qsm, NULL, NULL)))
178         goto err;
179
180     h->have_qsm = 1;
181
182     for (i = 0; i < QUIC_PN_SPACE_NUM; ++i)
183         if (!TEST_ptr(h->args.crypto[i] = ossl_quic_sstream_new(4096)))
184             goto err;
185
186     h->args.cur_scid                = scid_1;
187     h->args.cur_dcid                = dcid_1;
188     h->args.qsm                     = &h->qsm;
189     h->args.conn_txfc               = &h->conn_txfc;
190     h->args.conn_rxfc               = &h->conn_rxfc;
191     h->args.max_streams_bidi_rxfc   = &h->max_streams_bidi_rxfc;
192     h->args.max_streams_uni_rxfc    = &h->max_streams_uni_rxfc;
193     h->args.cc_method               = h->cc_method;
194     h->args.cc_data                 = h->cc_data;
195     h->args.now                     = fake_now;
196
197     if (!TEST_ptr(h->txp = ossl_quic_tx_packetiser_new(&h->args)))
198         goto err;
199
200     if (!TEST_ptr(h->demux = ossl_quic_demux_new(h->bio2, 8,
201                                                  fake_now, NULL)))
202         goto err;
203
204     h->qrx_args.demux                  = h->demux;
205     h->qrx_args.short_conn_id_len      = 8;
206     h->qrx_args.max_deferred           = 32;
207
208     if (!TEST_ptr(h->qrx = ossl_qrx_new(&h->qrx_args)))
209         goto err;
210
211     if (!TEST_true(ossl_qrx_add_dst_conn_id(h->qrx, &dcid_1)))
212         goto err;
213
214     rc = 1;
215 err:
216     if (!rc)
217         helper_cleanup(h);
218
219     return rc;
220 }
221
222 #define OPK_END                     0   /* End of Script */
223 #define OPK_TXP_GENERATE            1   /* Call generate, expect packet output */
224 #define OPK_TXP_GENERATE_NONE       2   /* Call generate, expect no packet output */
225 #define OPK_RX_PKT                  3   /* Receive, expect packet */
226 #define OPK_RX_PKT_NONE             4   /* Receive, expect no packet */
227 #define OPK_EXPECT_DGRAM_LEN        5   /* Expect received datagram length in range */
228 #define OPK_EXPECT_FRAME            6   /* Expect next frame is of type */
229 #define OPK_EXPECT_INITIAL_TOKEN    7   /* Expect initial token buffer match */
230 #define OPK_EXPECT_HDR              8   /* Expect header structure match */
231 #define OPK_CHECK                   9   /* Call check function */
232 #define OPK_NEXT_FRAME              10  /* Next frame */
233 #define OPK_EXPECT_NO_FRAME         11  /* Expect no further frames */
234 #define OPK_PROVIDE_SECRET          12  /* Provide secret to QTX and QRX */
235 #define OPK_DISCARD_EL              13  /* Discard QTX EL */
236 #define OPK_CRYPTO_SEND             14  /* Push data into crypto send stream */
237 #define OPK_STREAM_NEW              15  /* Create new application stream */
238 #define OPK_STREAM_SEND             16  /* Push data into application send stream */
239 #define OPK_STREAM_FIN              17  /* Mark stream as finished */
240 #define OPK_STOP_SENDING            18  /* Mark stream for STOP_SENDING */
241 #define OPK_RESET_STREAM            19  /* Mark stream for RESET_STREAM */
242 #define OPK_CONN_TXFC_BUMP          20  /* Bump connection TXFC CWM */
243 #define OPK_STREAM_TXFC_BUMP        21  /* Bump stream TXFC CWM */
244 #define OPK_HANDSHAKE_COMPLETE      22  /* Mark handshake as complete */
245
246 struct script_op {
247     uint32_t opcode;
248     uint64_t arg0, arg1;
249     const void *buf;
250     size_t buf_len;
251     int (*check_func)(struct helper *h);
252 };
253
254 #define OP_END      \
255     { OPK_END }
256 #define OP_TXP_GENERATE(archetype) \
257     { OPK_TXP_GENERATE, (archetype) },
258 #define OP_TXP_GENERATE_NONE(archetype) \
259     { OPK_TXP_GENERATE_NONE, (archetype) },
260 #define OP_RX_PKT() \
261     { OPK_RX_PKT },
262 #define OP_RX_PKT_NONE() \
263     { OPK_RX_PKT_NONE },
264 #define OP_EXPECT_DGRAM_LEN(lo, hi) \
265     { OPK_EXPECT_DGRAM_LEN, (lo), (hi) },
266 #define OP_EXPECT_FRAME(frame_type) \
267     { OPK_EXPECT_FRAME, (frame_type) },
268 #define OP_EXPECT_INITIAL_TOKEN(buf) \
269     { OPK_EXPECT_INITIAL_TOKEN, sizeof(buf), 0, buf },
270 #define OP_EXPECT_HDR(hdr) \
271     { OPK_EXPECT_HDR, 0, 0, &(hdr) },
272 #define OP_CHECK(func) \
273     { OPK_CHECK, 0, 0, NULL, 0, (func) },
274 #define OP_NEXT_FRAME() \
275     { OPK_NEXT_FRAME },
276 #define OP_EXPECT_NO_FRAME() \
277     { OPK_EXPECT_NO_FRAME },
278 #define OP_PROVIDE_SECRET(el, suite, secret) \
279     { OPK_PROVIDE_SECRET, (el), (suite), (secret), sizeof(secret) },
280 #define OP_DISCARD_EL(el) \
281     { OPK_DISCARD_EL, (el) },
282 #define OP_CRYPTO_SEND(pn_space, buf) \
283     { OPK_CRYPTO_SEND, (pn_space), 0, (buf), sizeof(buf) },
284 #define OP_STREAM_NEW(id) \
285     { OPK_STREAM_NEW, (id) },
286 #define OP_STREAM_SEND(id, buf) \
287     { OPK_STREAM_SEND, (id), 0, (buf), sizeof(buf) },
288 #define OP_STREAM_FIN(id) \
289     { OPK_STREAM_FIN, (id) },
290 #define OP_STOP_SENDING(id, aec) \
291     { OPK_STOP_SENDING, (id), (aec) },
292 #define OP_RESET_STREAM(id, aec) \
293     { OPK_RESET_STREAM, (id), (aec) },
294 #define OP_CONN_TXFC_BUMP(cwm) \
295     { OPK_CONN_TXFC_BUMP, (cwm) },
296 #define OP_STREAM_TXFC_BUMP(id, cwm) \
297     { OPK_STREAM_TXFC_BUMP, (cwm), (id) },
298 #define OP_HANDSHAKE_COMPLETE() \
299     { OPK_HANDSHAKE_COMPLETE },
300
301 static int schedule_handshake_done(struct helper *h)
302 {
303     ossl_quic_tx_packetiser_schedule_handshake_done(h->txp);
304     return 1;
305 }
306
307 static int schedule_ack_eliciting_app(struct helper *h)
308 {
309     ossl_quic_tx_packetiser_schedule_ack_eliciting(h->txp, QUIC_PN_SPACE_APP);
310     return 1;
311 }
312
313 /* 1. 1-RTT, Single Handshake Done Frame */
314 static const struct script_op script_1[] = {
315     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
316     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
317     OP_CHECK(schedule_handshake_done)
318     OP_TXP_GENERATE(TX_PACKETISER_ARCHETYPE_NORMAL)
319     OP_RX_PKT()
320     /* Should not be long */
321     OP_EXPECT_DGRAM_LEN(21, 32)
322     OP_NEXT_FRAME()
323     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE)
324     OP_EXPECT_NO_FRAME()
325     OP_RX_PKT_NONE()
326     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
327     OP_END
328 };
329
330 /* 2. 1-RTT, Forced ACK-Eliciting Frame */
331 static const struct script_op script_2[] = {
332     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
333     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
334     OP_CHECK(schedule_ack_eliciting_app)
335     OP_TXP_GENERATE(TX_PACKETISER_ARCHETYPE_NORMAL)
336     OP_RX_PKT()
337     /* Should not be long */
338     OP_EXPECT_DGRAM_LEN(21, 32)
339     /* A PING frame should have been added */
340     OP_NEXT_FRAME()
341     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_PING)
342     OP_EXPECT_NO_FRAME()
343     OP_RX_PKT_NONE()
344     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
345     OP_END
346 };
347
348 /* 3. 1-RTT, MAX_DATA */
349 static int schedule_max_data(struct helper *h)
350 {
351     uint64_t cwm;
352
353     cwm = ossl_quic_rxfc_get_cwm(&h->stream_rxfc);
354
355     if (!TEST_true(ossl_quic_rxfc_on_rx_stream_frame(&h->stream_rxfc, cwm, 0))
356         || !TEST_true(ossl_quic_rxfc_on_retire(&h->stream_rxfc, cwm,
357                                                ossl_ticks2time(OSSL_TIME_MS))))
358         return 0;
359
360     return 1;
361 }
362
363 static const struct script_op script_3[] = {
364     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
365     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
366     OP_CHECK(schedule_max_data)
367     OP_TXP_GENERATE(TX_PACKETISER_ARCHETYPE_NORMAL)
368     OP_RX_PKT()
369     /* Should not be long */
370     OP_EXPECT_DGRAM_LEN(21, 40)
371     /* A PING frame should have been added */
372     OP_NEXT_FRAME()
373     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_MAX_DATA)
374     OP_EXPECT_NO_FRAME()
375     OP_RX_PKT_NONE()
376     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
377     OP_END
378 };
379
380 /* 4. 1-RTT, CFQ (NEW_CONN_ID) */
381 static void free_buf_mem(unsigned char *buf, size_t buf_len, void *arg)
382 {
383     BUF_MEM_free((BUF_MEM *)arg);
384 }
385
386 static int schedule_cfq_new_conn_id(struct helper *h)
387 {
388     int rc = 0;
389     QUIC_CFQ_ITEM *cfq_item;
390     WPACKET wpkt;
391     BUF_MEM *buf_mem = NULL;
392     char have_wpkt = 0;
393     size_t l = 0;
394     OSSL_QUIC_FRAME_NEW_CONN_ID ncid = {0};
395
396     ncid.seq_num         = 1234;
397     ncid.retire_prior_to = 2345;
398     ncid.conn_id         = cid_1;
399     memcpy(ncid.stateless_reset_token, reset_token_1, sizeof(reset_token_1));
400
401     if (!TEST_ptr(buf_mem = BUF_MEM_new()))
402         goto err;
403
404     if (!TEST_true(WPACKET_init(&wpkt, buf_mem)))
405         goto err;
406
407     have_wpkt = 1;
408     if (!TEST_true(ossl_quic_wire_encode_frame_new_conn_id(&wpkt, &ncid)))
409         goto err;
410
411     if (!TEST_true(WPACKET_get_total_written(&wpkt, &l)))
412         goto err;
413
414     if (!TEST_ptr(cfq_item = ossl_quic_cfq_add_frame(h->args.cfq, 1,
415                                                      QUIC_PN_SPACE_APP,
416                                                      OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID,
417                                                      (unsigned char *)buf_mem->data, l,
418                                                      free_buf_mem,
419                                                      buf_mem)))
420         goto err;
421
422     rc = 1;
423 err:
424     if (have_wpkt)
425         WPACKET_cleanup(&wpkt);
426     return rc;
427 }
428
429 static int check_cfq_new_conn_id(struct helper *h)
430 {
431     if (!TEST_uint64_t_eq(h->frame.new_conn_id.seq_num, 1234)
432         || !TEST_uint64_t_eq(h->frame.new_conn_id.retire_prior_to, 2345)
433         || !TEST_mem_eq(&h->frame.new_conn_id.conn_id, sizeof(cid_1),
434                         &cid_1, sizeof(cid_1))
435         || !TEST_mem_eq(&h->frame.new_conn_id.stateless_reset_token,
436                         sizeof(reset_token_1),
437                         reset_token_1,
438                         sizeof(reset_token_1)))
439         return 0;
440
441     return 1;
442 }
443
444 static const struct script_op script_4[] = {
445     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
446     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
447     OP_CHECK(schedule_cfq_new_conn_id)
448     OP_TXP_GENERATE(TX_PACKETISER_ARCHETYPE_NORMAL)
449     OP_RX_PKT()
450     OP_EXPECT_DGRAM_LEN(21, 128)
451     OP_NEXT_FRAME()
452     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID)
453     OP_CHECK(check_cfq_new_conn_id)
454     OP_EXPECT_NO_FRAME()
455     OP_RX_PKT_NONE()
456     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
457     OP_END
458 };
459
460 /* 5. 1-RTT, CFQ (NEW_TOKEN) */
461 static const unsigned char token_1[] = {
462     0x10, 0x11, 0x12, 0x13, 0x14, 0x15
463 };
464
465 static int schedule_cfq_new_token(struct helper *h)
466 {
467     int rc = 0;
468     QUIC_CFQ_ITEM *cfq_item;
469     WPACKET wpkt;
470     BUF_MEM *buf_mem = NULL;
471     char have_wpkt = 0;
472     size_t l = 0;
473
474     if (!TEST_ptr(buf_mem = BUF_MEM_new()))
475         goto err;
476
477     if (!TEST_true(WPACKET_init(&wpkt, buf_mem)))
478         goto err;
479
480     have_wpkt = 1;
481     if (!TEST_true(ossl_quic_wire_encode_frame_new_token(&wpkt, token_1,
482                                                          sizeof(token_1))))
483         goto err;
484
485     if (!TEST_true(WPACKET_get_total_written(&wpkt, &l)))
486         goto err;
487
488     if (!TEST_ptr(cfq_item = ossl_quic_cfq_add_frame(h->args.cfq, 1,
489                                                      QUIC_PN_SPACE_APP,
490                                                      OSSL_QUIC_FRAME_TYPE_NEW_TOKEN,
491                                                      (unsigned char *)buf_mem->data, l,
492                                                      free_buf_mem,
493                                                      buf_mem)))
494         goto err;
495
496     rc = 1;
497 err:
498     if (have_wpkt)
499         WPACKET_cleanup(&wpkt);
500     return rc;
501 }
502
503 static int check_cfq_new_token(struct helper *h)
504 {
505     if (!TEST_mem_eq(h->frame.new_token.token,
506                      h->frame.new_token.token_len,
507                      token_1,
508                      sizeof(token_1)))
509         return 0;
510
511     return 1;
512 }
513
514 static const struct script_op script_5[] = {
515     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
516     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
517     OP_CHECK(schedule_cfq_new_token)
518     OP_TXP_GENERATE(TX_PACKETISER_ARCHETYPE_NORMAL)
519     OP_RX_PKT()
520     OP_EXPECT_DGRAM_LEN(21, 512)
521     OP_NEXT_FRAME()
522     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_NEW_TOKEN)
523     OP_CHECK(check_cfq_new_token)
524     OP_EXPECT_NO_FRAME()
525     OP_RX_PKT_NONE()
526     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
527     OP_END
528 };
529
530 /* 6. 1-RTT, ACK */
531 static int schedule_ack(struct helper *h)
532 {
533     size_t i;
534     OSSL_ACKM_RX_PKT rx_pkt = {0};
535
536     /* Stimulate ACK emission by simulating a few received packets. */
537     for (i = 0; i < 5; ++i) {
538         rx_pkt.pkt_num          = i;
539         rx_pkt.time             = fake_now(NULL);
540         rx_pkt.pkt_space        = QUIC_PN_SPACE_APP;
541         rx_pkt.is_ack_eliciting = 1;
542
543         if (!TEST_true(ossl_ackm_on_rx_packet(h->args.ackm, &rx_pkt)))
544             return 0;
545     }
546
547     return 1;
548 }
549
550 static const struct script_op script_6[] = {
551     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
552     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
553     OP_CHECK(schedule_ack)
554     OP_TXP_GENERATE(TX_PACKETISER_ARCHETYPE_NORMAL)
555     OP_RX_PKT()
556     OP_EXPECT_DGRAM_LEN(21, 512)
557     OP_NEXT_FRAME()
558     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_ACK_WITHOUT_ECN)
559     OP_EXPECT_NO_FRAME()
560     OP_RX_PKT_NONE()
561     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
562     OP_END
563 };
564
565 /* 7. 1-RTT, ACK, NEW_TOKEN */
566 static const struct script_op script_7[] = {
567     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
568     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
569     OP_CHECK(schedule_cfq_new_token)
570     OP_CHECK(schedule_ack)
571     OP_TXP_GENERATE(TX_PACKETISER_ARCHETYPE_NORMAL)
572     OP_RX_PKT()
573     OP_EXPECT_DGRAM_LEN(21, 512)
574     /* ACK must come before NEW_TOKEN */
575     OP_NEXT_FRAME()
576     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_ACK_WITHOUT_ECN)
577     OP_NEXT_FRAME()
578     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_NEW_TOKEN)
579     OP_EXPECT_NO_FRAME()
580     OP_RX_PKT_NONE()
581     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
582     OP_END
583 };
584
585 /* 8. 1-RTT, CRYPTO */
586 static const unsigned char crypto_1[] = {
587     0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09
588 };
589
590 static const struct script_op script_8[] = {
591     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
592     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
593     OP_CRYPTO_SEND(QUIC_PN_SPACE_APP, crypto_1)
594     OP_TXP_GENERATE(TX_PACKETISER_ARCHETYPE_NORMAL)
595     OP_RX_PKT()
596     OP_EXPECT_DGRAM_LEN(21, 512)
597     OP_NEXT_FRAME()
598     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_CRYPTO)
599     OP_EXPECT_NO_FRAME()
600     OP_RX_PKT_NONE()
601     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
602     OP_END
603 };
604
605 /* 9. 1-RTT, STREAM */
606 static const unsigned char stream_9[] = {
607     0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x7a, 0x7b
608 };
609
610 static int check_stream_9(struct helper *h)
611 {
612     if (!TEST_mem_eq(h->frame.stream.data, (size_t)h->frame.stream.len,
613                      stream_9, sizeof(stream_9)))
614         return 0;
615
616     return 1;
617 }
618
619 static const struct script_op script_9[] = {
620     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
621     OP_HANDSHAKE_COMPLETE()
622     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
623     OP_STREAM_NEW(42)
624     OP_STREAM_SEND(42, stream_9)
625     /* Still no output because of TXFC */
626     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
627     /* Now grant a TXFC budget */
628     OP_CONN_TXFC_BUMP(1000)
629     OP_STREAM_TXFC_BUMP(42, 1000)
630     OP_TXP_GENERATE(TX_PACKETISER_ARCHETYPE_NORMAL)
631     OP_RX_PKT()
632     OP_EXPECT_DGRAM_LEN(21, 512)
633     OP_NEXT_FRAME()
634     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_STREAM)
635     OP_CHECK(check_stream_9)
636     OP_EXPECT_NO_FRAME()
637     OP_RX_PKT_NONE()
638     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
639     OP_END
640 };
641
642 /* 10. 1-RTT, STREAM, round robin */
643 /* The data below is randomly generated data. */
644 static const unsigned char stream_10a[1300] = {
645     0x40, 0x0d, 0xb6, 0x0d, 0x25, 0x5f, 0xdd, 0xb9, 0x05, 0x79, 0xa8, 0xe3,
646     0x79, 0x32, 0xb2, 0xa7, 0x30, 0x6d, 0x29, 0xf6, 0xba, 0x50, 0xbe, 0x83,
647     0xcb, 0x56, 0xec, 0xd6, 0xc7, 0x80, 0x84, 0xa2, 0x2f, 0xeb, 0xc4, 0x37,
648     0x40, 0x44, 0xef, 0xd8, 0x78, 0xbb, 0x92, 0x80, 0x22, 0x33, 0xc0, 0xce,
649     0x33, 0x5b, 0x75, 0x8c, 0xa5, 0x1a, 0x7a, 0x2a, 0xa9, 0x88, 0xaf, 0xf6,
650     0x3a, 0xe2, 0x5e, 0x60, 0x52, 0x6d, 0xef, 0x7f, 0x2a, 0x9a, 0xaa, 0x17,
651     0x0e, 0x12, 0x51, 0x82, 0x08, 0x2f, 0x0f, 0x5b, 0xff, 0xf5, 0x7c, 0x7c,
652     0x89, 0x04, 0xfb, 0xa7, 0x80, 0x4e, 0xda, 0x12, 0x89, 0x01, 0x4a, 0x81,
653     0x84, 0x78, 0x15, 0xa9, 0x12, 0x28, 0x69, 0x4a, 0x25, 0xe5, 0x8b, 0x69,
654     0xc2, 0x9f, 0xb6, 0x59, 0x49, 0xe3, 0x53, 0x90, 0xef, 0xc9, 0xb8, 0x40,
655     0xdd, 0x62, 0x5f, 0x99, 0x68, 0xd2, 0x0a, 0x77, 0xde, 0xf3, 0x11, 0x39,
656     0x7f, 0x93, 0x8b, 0x81, 0x69, 0x36, 0xa7, 0x76, 0xa4, 0x10, 0x56, 0x51,
657     0xe5, 0x45, 0x3a, 0x42, 0x49, 0x6c, 0xc6, 0xa0, 0xb4, 0x13, 0x46, 0x59,
658     0x0e, 0x48, 0x60, 0xc9, 0xff, 0x70, 0x10, 0x8d, 0x6a, 0xf9, 0x5b, 0x94,
659     0xc2, 0x9e, 0x49, 0x19, 0x56, 0xf2, 0xc1, 0xff, 0x08, 0x3f, 0x9e, 0x26,
660     0x8e, 0x99, 0x71, 0xc4, 0x25, 0xb1, 0x4e, 0xcc, 0x7e, 0x5f, 0xf0, 0x4e,
661     0x25, 0xa2, 0x2f, 0x3f, 0x68, 0xaa, 0xcf, 0xbd, 0x19, 0x19, 0x1c, 0x92,
662     0xa0, 0xb6, 0xb8, 0x32, 0xb1, 0x0b, 0x91, 0x05, 0xa9, 0xf8, 0x1a, 0x4b,
663     0x74, 0x09, 0xf9, 0x57, 0xd0, 0x1c, 0x38, 0x10, 0x05, 0x54, 0xd8, 0x4e,
664     0x12, 0x67, 0xcc, 0x43, 0xa3, 0x81, 0xa9, 0x3a, 0x12, 0x57, 0xe7, 0x4b,
665     0x0e, 0xe5, 0x51, 0xf9, 0x5f, 0xd4, 0x46, 0x73, 0xa2, 0x78, 0xb7, 0x00,
666     0x24, 0x69, 0x35, 0x10, 0x1e, 0xb8, 0xa7, 0x4a, 0x9b, 0xbc, 0xfc, 0x04,
667     0x6f, 0x1a, 0xb0, 0x4f, 0x12, 0xc9, 0x2b, 0x3b, 0x94, 0x85, 0x1b, 0x8e,
668     0xba, 0xac, 0xfd, 0x10, 0x22, 0x68, 0x90, 0x17, 0x13, 0x44, 0x18, 0x2f,
669     0x33, 0x37, 0x1a, 0x89, 0xc0, 0x2c, 0x14, 0x59, 0xb2, 0xaf, 0xc0, 0x6b,
670     0xdc, 0x28, 0xe1, 0xe9, 0xc1, 0x0c, 0xb4, 0x80, 0x90, 0xb9, 0x1f, 0x45,
671     0xb4, 0x63, 0x9a, 0x0e, 0xfa, 0x33, 0xf5, 0x75, 0x3a, 0x4f, 0xc3, 0x8c,
672     0x70, 0xdb, 0xd7, 0xbf, 0xf6, 0xb8, 0x7f, 0xcc, 0xe5, 0x85, 0xb6, 0xae,
673     0x25, 0x60, 0x18, 0x5b, 0xf1, 0x51, 0x1a, 0x85, 0xc1, 0x7f, 0xf3, 0xbe,
674     0xb6, 0x82, 0x38, 0xe3, 0xd2, 0xff, 0x8a, 0xc4, 0xdb, 0x08, 0xe6, 0x96,
675     0xd5, 0x3d, 0x1f, 0xc5, 0x12, 0x35, 0x45, 0x75, 0x5d, 0x17, 0x4e, 0xe1,
676     0xb8, 0xc9, 0xf0, 0x45, 0x95, 0x0b, 0x03, 0xcb, 0x85, 0x47, 0xaf, 0xc7,
677     0x88, 0xb6, 0xc1, 0x2c, 0xb8, 0x9b, 0xe6, 0x8b, 0x51, 0xd5, 0x2e, 0x71,
678     0xba, 0xc9, 0xa9, 0x37, 0x5e, 0x1c, 0x2c, 0x03, 0xf0, 0xc7, 0xc1, 0xd3,
679     0x72, 0xaa, 0x4d, 0x19, 0xd6, 0x51, 0x64, 0x12, 0xeb, 0x39, 0xeb, 0x45,
680     0xe9, 0xb4, 0x84, 0x08, 0xb6, 0x6c, 0xc7, 0x3e, 0xf0, 0x88, 0x64, 0xc2,
681     0x91, 0xb7, 0xa5, 0x86, 0x66, 0x83, 0xd5, 0xd3, 0x41, 0x24, 0xb2, 0x1c,
682     0x9a, 0x18, 0x10, 0x0e, 0xa5, 0xc9, 0xef, 0xcd, 0x06, 0xce, 0xa8, 0xaf,
683     0x22, 0x52, 0x25, 0x0b, 0x99, 0x3d, 0xe9, 0x26, 0xda, 0xa9, 0x47, 0xd1,
684     0x4b, 0xa6, 0x4c, 0xfc, 0x80, 0xaf, 0x6a, 0x59, 0x4b, 0x35, 0xa4, 0x93,
685     0x39, 0x5b, 0xfa, 0x91, 0x9d, 0xdf, 0x9d, 0x3c, 0xfb, 0x53, 0xca, 0x18,
686     0x19, 0xe4, 0xda, 0x95, 0x47, 0x5a, 0x37, 0x59, 0xd7, 0xd2, 0xe4, 0x75,
687     0x45, 0x0d, 0x03, 0x7f, 0xa0, 0xa9, 0xa0, 0x71, 0x06, 0xb1, 0x9d, 0x46,
688     0xbd, 0xcf, 0x4a, 0x8b, 0x73, 0xc1, 0x45, 0x5c, 0x00, 0x61, 0xfd, 0xd1,
689     0xa4, 0xa2, 0x3e, 0xaa, 0xbe, 0x72, 0xf1, 0x7a, 0x1a, 0x76, 0x88, 0x5c,
690     0x9e, 0x74, 0x6d, 0x2a, 0x34, 0xfc, 0xf7, 0x41, 0x28, 0xe8, 0xa3, 0x43,
691     0x4d, 0x43, 0x1d, 0x6c, 0x36, 0xb1, 0x45, 0x71, 0x5a, 0x3c, 0xd3, 0x28,
692     0x44, 0xe4, 0x9b, 0xbf, 0x54, 0x16, 0xc3, 0x99, 0x6c, 0x42, 0xd8, 0x20,
693     0xb6, 0x20, 0x5f, 0x6e, 0xbc, 0xba, 0x88, 0x5e, 0x2f, 0xa5, 0xd1, 0x82,
694     0x5c, 0x92, 0xd0, 0x79, 0xfd, 0xcc, 0x61, 0x49, 0xd0, 0x73, 0x92, 0xe6,
695     0x98, 0xe3, 0x80, 0x7a, 0xf9, 0x56, 0x63, 0x33, 0x19, 0xda, 0x54, 0x13,
696     0xf0, 0x21, 0xa8, 0x15, 0xf6, 0xb7, 0x43, 0x7c, 0x1c, 0x1e, 0xb1, 0x89,
697     0x8d, 0xce, 0x20, 0x54, 0x81, 0x80, 0xb5, 0x8f, 0x9b, 0xb1, 0x09, 0x92,
698     0xdb, 0x25, 0x6f, 0x30, 0x29, 0x08, 0x1a, 0x05, 0x08, 0xf4, 0x83, 0x8b,
699     0x1e, 0x2d, 0xfd, 0xe4, 0xb2, 0x76, 0xc8, 0x4d, 0xf3, 0xa6, 0x49, 0x5f,
700     0x2c, 0x99, 0x78, 0xbd, 0x07, 0xef, 0xc8, 0xd9, 0xb5, 0x70, 0x3b, 0x0a,
701     0xcb, 0xbd, 0xa0, 0xea, 0x15, 0xfb, 0xd1, 0x6e, 0x61, 0x83, 0xcb, 0x90,
702     0xd0, 0xa3, 0x81, 0x28, 0xdc, 0xd5, 0x84, 0xae, 0x55, 0x28, 0x13, 0x9e,
703     0xc6, 0xd8, 0xf4, 0x67, 0xd6, 0x0d, 0xd4, 0x69, 0xac, 0xf6, 0x35, 0x95,
704     0x99, 0x44, 0x26, 0x72, 0x36, 0x55, 0xf9, 0x42, 0xa6, 0x1b, 0x00, 0x93,
705     0x00, 0x19, 0x2f, 0x70, 0xd3, 0x16, 0x66, 0x4e, 0x80, 0xbb, 0xb6, 0x84,
706     0xa1, 0x2c, 0x09, 0xfb, 0x41, 0xdf, 0x63, 0xde, 0x62, 0x3e, 0xd0, 0xa8,
707     0xd8, 0x0c, 0x03, 0x06, 0xa9, 0x82, 0x17, 0x9c, 0xd2, 0xa9, 0xd5, 0x6f,
708     0xcc, 0xc0, 0xf2, 0x5d, 0xb1, 0xba, 0xf8, 0x2e, 0x37, 0x8b, 0xe6, 0x5d,
709     0x9f, 0x1b, 0xfb, 0x53, 0x0a, 0x96, 0xbe, 0x69, 0x31, 0x19, 0x8f, 0x44,
710     0x1b, 0xc2, 0x42, 0x7e, 0x65, 0x12, 0x1d, 0x52, 0x1e, 0xe2, 0xc0, 0x86,
711     0x70, 0x88, 0xe5, 0xf6, 0x87, 0x5d, 0x03, 0x4b, 0x12, 0x3c, 0x2d, 0xaf,
712     0x09, 0xf5, 0x4f, 0x82, 0x2e, 0x2e, 0xbe, 0x07, 0xe8, 0x8d, 0x57, 0x6e,
713     0xc0, 0xeb, 0xf9, 0x37, 0xac, 0x89, 0x01, 0xb7, 0xc6, 0x52, 0x1c, 0x86,
714     0xe5, 0xbc, 0x1f, 0xbd, 0xde, 0xa2, 0x42, 0xb6, 0x73, 0x85, 0x6f, 0x06,
715     0x36, 0x56, 0x40, 0x2b, 0xea, 0x16, 0x8c, 0xf4, 0x7b, 0x65, 0x6a, 0xca,
716     0x3c, 0x56, 0x68, 0x01, 0xe3, 0x9c, 0xbb, 0xb9, 0x45, 0x54, 0xcd, 0x13,
717     0x74, 0xad, 0x80, 0x40, 0xbc, 0xd0, 0x74, 0xb4, 0x31, 0xe4, 0xca, 0xd5,
718     0xf8, 0x4f, 0x08, 0x5b, 0xc4, 0x15, 0x1a, 0x51, 0x3b, 0xc6, 0x40, 0xc8,
719     0xea, 0x76, 0x30, 0x95, 0xb7, 0x76, 0xa4, 0xda, 0x20, 0xdb, 0x75, 0x1c,
720     0xf4, 0x87, 0x24, 0x29, 0x54, 0xc6, 0x59, 0x0c, 0xf0, 0xed, 0xf5, 0x3d,
721     0xce, 0x95, 0x23, 0x30, 0x49, 0x91, 0xa7, 0x7b, 0x22, 0xb5, 0xd7, 0x71,
722     0xb0, 0x60, 0xe1, 0xf0, 0x84, 0x74, 0x0e, 0x2f, 0xa8, 0x79, 0x35, 0xb9,
723     0x03, 0xb5, 0x2c, 0xdc, 0x60, 0x48, 0x12, 0xd9, 0x14, 0x5a, 0x58, 0x5d,
724     0x95, 0xc6, 0x47, 0xfd, 0xaf, 0x09, 0xc2, 0x67, 0xa5, 0x09, 0xae, 0xff,
725     0x4b, 0xd5, 0x6c, 0x2f, 0x1d, 0x33, 0x31, 0xcb, 0xdb, 0xcf, 0xf5, 0xf6,
726     0xbc, 0x90, 0xb2, 0x15, 0xd4, 0x34, 0xeb, 0xde, 0x0e, 0x8f, 0x3d, 0xea,
727     0xa4, 0x9b, 0x29, 0x8a, 0xf9, 0x4a, 0xac, 0x38, 0x1e, 0x46, 0xb2, 0x2d,
728     0xa2, 0x61, 0xc5, 0x99, 0x5e, 0x85, 0x36, 0x85, 0xb0, 0xb1, 0x6b, 0xc4,
729     0x06, 0x68, 0xc7, 0x9b, 0x54, 0xb9, 0xc8, 0x9d, 0xf3, 0x1a, 0xe0, 0x67,
730     0x0e, 0x4d, 0x5c, 0x13, 0x54, 0xa4, 0x62, 0x62, 0x6f, 0xae, 0x0e, 0x86,
731     0xa2, 0xe0, 0x31, 0xc7, 0x72, 0xa1, 0xbb, 0x87, 0x3e, 0x61, 0x96, 0xb7,
732     0x53, 0xf9, 0x34, 0xcb, 0xfd, 0x6c, 0x67, 0x25, 0x73, 0x61, 0x75, 0x4f,
733     0xab, 0x37, 0x08, 0xef, 0x35, 0x5a, 0x03, 0xe5, 0x08, 0x43, 0xec, 0xdc,
734     0xb5, 0x2c, 0x1f, 0xe6, 0xeb, 0xc6, 0x06, 0x0b, 0xed, 0xad, 0x74, 0xf4,
735     0x55, 0xef, 0xe0, 0x2e, 0x83, 0x00, 0xdb, 0x32, 0xde, 0xe9, 0xe4, 0x2f,
736     0xf5, 0x20, 0x6d, 0x72, 0x47, 0xf4, 0x68, 0xa6, 0x7f, 0x3e, 0x6a, 0x5a,
737     0x21, 0x76, 0x31, 0x97, 0xa0, 0xc6, 0x7d, 0x03, 0xf7, 0x27, 0x45, 0x5a,
738     0x75, 0x03, 0xc1, 0x5c, 0x94, 0x2b, 0x37, 0x9f, 0x46, 0x8f, 0xc3, 0xa7,
739     0x50, 0xe4, 0xe7, 0x23, 0xf7, 0x20, 0xa2, 0x8e, 0x4b, 0xfd, 0x7a, 0xa7,
740     0x8a, 0x54, 0x7b, 0x32, 0xef, 0x0e, 0x82, 0xb9, 0xf9, 0x14, 0x62, 0x68,
741     0x32, 0x9e, 0x55, 0xc0, 0xd8, 0xc7, 0x41, 0x9c, 0x67, 0x95, 0xbf, 0xc3,
742     0x86, 0x74, 0x70, 0x64, 0x44, 0x23, 0x77, 0x79, 0x82, 0x23, 0x1c, 0xf4,
743     0xa1, 0x05, 0xd3, 0x98, 0x89, 0xde, 0x7d, 0xb3, 0x5b, 0xef, 0x38, 0xd2,
744     0x07, 0xbc, 0x5a, 0x69, 0xa3, 0xe4, 0x37, 0x9b, 0x53, 0xff, 0x04, 0x6b,
745     0xd9, 0xd8, 0x32, 0x89, 0xf7, 0x82, 0x77, 0xcf, 0xe6, 0xff, 0xf4, 0x15,
746     0x54, 0x91, 0x65, 0x96, 0x49, 0xd7, 0x0a, 0xa4, 0xf3, 0x55, 0x2b, 0xc1,
747     0x48, 0xc1, 0x7e, 0x56, 0x69, 0x27, 0xf4, 0xd1, 0x47, 0x1f, 0xde, 0x86,
748     0x15, 0x67, 0x04, 0x9d, 0x41, 0x1f, 0xe8, 0xe1, 0x23, 0xe4, 0x56, 0xb9,
749     0xdb, 0x4e, 0xe4, 0x84, 0x6c, 0x63, 0x39, 0xad, 0x44, 0x6d, 0x4e, 0x28,
750     0xcd, 0xf6, 0xac, 0xec, 0xc2, 0xad, 0xcd, 0xc3, 0xed, 0x03, 0x63, 0x5d,
751     0xef, 0x1d, 0x40, 0x8d, 0x9a, 0x02, 0x67, 0x4b, 0x55, 0xb5, 0xfe, 0x75,
752     0xb6, 0x53, 0x34, 0x1d, 0x7b, 0x26, 0x23, 0xfe, 0xb9, 0x21, 0xd3, 0xe0,
753     0xa0, 0x1a, 0x85, 0xe5
754 };
755
756 static const unsigned char stream_10b[1300] = {
757     0x18, 0x00, 0xd7, 0xfb, 0x12, 0xda, 0xdb, 0x68, 0xeb, 0x38, 0x4d, 0xf6,
758     0xb2, 0x45, 0x74, 0x4c, 0xcc, 0xe7, 0xa7, 0xc1, 0x26, 0x84, 0x3d, 0xdf,
759     0x7d, 0xc5, 0xe9, 0xd4, 0x31, 0xa2, 0x51, 0x38, 0x95, 0xe2, 0x68, 0x11,
760     0x9d, 0xd1, 0x52, 0xb5, 0xef, 0x76, 0xe0, 0x3d, 0x11, 0x50, 0xd7, 0xb2,
761     0xc1, 0x7d, 0x12, 0xaf, 0x02, 0x52, 0x97, 0x03, 0xf3, 0x2e, 0x54, 0xdf,
762     0xa0, 0x40, 0x76, 0x52, 0x82, 0x23, 0x3c, 0xbd, 0x20, 0x6d, 0x0a, 0x6f,
763     0x81, 0xfc, 0x41, 0x9d, 0x2e, 0xa7, 0x2c, 0x78, 0x9c, 0xd8, 0x56, 0xb0,
764     0x31, 0x35, 0xc8, 0x53, 0xef, 0xf9, 0x43, 0x17, 0xc0, 0x8c, 0x2c, 0x8f,
765     0x4a, 0x68, 0xe8, 0x9f, 0xbd, 0x3f, 0xf2, 0x18, 0xb8, 0xe6, 0x55, 0xea,
766     0x2a, 0x37, 0x3e, 0xac, 0xb0, 0x75, 0xd4, 0x75, 0x12, 0x82, 0xec, 0x21,
767     0xb9, 0xce, 0xe5, 0xc1, 0x62, 0x49, 0xd5, 0xf1, 0xca, 0xd4, 0x32, 0x76,
768     0x34, 0x5f, 0x3e, 0xc9, 0xb3, 0x54, 0xe4, 0xd0, 0xa9, 0x7d, 0x0c, 0x64,
769     0x48, 0x0a, 0x74, 0x38, 0x03, 0xd0, 0x20, 0xac, 0xe3, 0x58, 0x3d, 0x4b,
770     0xa7, 0x46, 0xac, 0x57, 0x63, 0x12, 0x17, 0xcb, 0x96, 0xed, 0xc9, 0x39,
771     0x64, 0xde, 0xff, 0xc6, 0xb2, 0x40, 0x2c, 0xf9, 0x1d, 0xa6, 0x94, 0x2a,
772     0x16, 0x4d, 0x7f, 0x22, 0x91, 0x8b, 0xfe, 0x83, 0x77, 0x02, 0x68, 0x62,
773     0x27, 0x77, 0x2e, 0xe9, 0xce, 0xbc, 0x20, 0xe8, 0xfb, 0xf8, 0x4e, 0x17,
774     0x07, 0xe1, 0xaa, 0x29, 0xb7, 0x50, 0xcf, 0xb0, 0x6a, 0xcf, 0x01, 0xec,
775     0xbf, 0xff, 0xb5, 0x9f, 0x00, 0x64, 0x80, 0xbb, 0xa6, 0xe4, 0xa2, 0x1e,
776     0xe4, 0xf8, 0xa3, 0x0d, 0xc7, 0x65, 0x45, 0xb7, 0x01, 0x33, 0x80, 0x37,
777     0x11, 0x16, 0x34, 0xc1, 0x06, 0xc5, 0xd3, 0xc4, 0x70, 0x62, 0x75, 0xd8,
778     0xa3, 0xba, 0x84, 0x9f, 0x81, 0x9f, 0xda, 0x01, 0x83, 0x42, 0x84, 0x05,
779     0x69, 0x68, 0xb0, 0x74, 0x73, 0x0f, 0x68, 0x39, 0xd3, 0x11, 0xc5, 0x55,
780     0x3e, 0xf2, 0xb7, 0xf4, 0xa6, 0xed, 0x0b, 0x50, 0xbe, 0x44, 0xf8, 0x67,
781     0x48, 0x46, 0x5e, 0x71, 0x07, 0xcf, 0xca, 0x8a, 0xbc, 0xa4, 0x3c, 0xd2,
782     0x4a, 0x80, 0x2e, 0x4f, 0xc5, 0x3b, 0x61, 0xc1, 0x7e, 0x93, 0x9e, 0xe0,
783     0x05, 0xfb, 0x10, 0xe8, 0x53, 0xff, 0x16, 0x5e, 0x18, 0xe0, 0x9f, 0x39,
784     0xbf, 0xaa, 0x80, 0x6d, 0xb7, 0x9f, 0x51, 0x91, 0xa0, 0xf6, 0xce, 0xad,
785     0xed, 0x56, 0x15, 0xb9, 0x12, 0x57, 0x60, 0xa6, 0xae, 0x54, 0x6e, 0x36,
786     0xf3, 0xe0, 0x05, 0xd8, 0x3e, 0x6d, 0x08, 0x36, 0xc9, 0x79, 0x64, 0x51,
787     0x63, 0x92, 0xa8, 0xa1, 0xbf, 0x55, 0x26, 0x80, 0x75, 0x44, 0x33, 0x33,
788     0xfb, 0xb7, 0xec, 0xf9, 0xc6, 0x01, 0xf9, 0xd5, 0x93, 0xfc, 0xb7, 0x43,
789     0xa2, 0x38, 0x0d, 0x17, 0x75, 0x67, 0xec, 0xc9, 0x98, 0xd6, 0x25, 0xe6,
790     0xb9, 0xed, 0x61, 0xa4, 0xee, 0x2c, 0xda, 0x27, 0xbd, 0xff, 0x86, 0x1e,
791     0x45, 0x64, 0xfe, 0xcf, 0x0c, 0x9b, 0x7b, 0x75, 0x5f, 0xf1, 0xe0, 0xba,
792     0x77, 0x8c, 0x03, 0x8f, 0xb4, 0x3a, 0xb6, 0x9c, 0xda, 0x9a, 0x83, 0xcb,
793     0xe9, 0xcb, 0x3f, 0xf4, 0x10, 0x99, 0x5b, 0xe1, 0x19, 0x8f, 0x6b, 0x95,
794     0x50, 0xe6, 0x78, 0xc9, 0x35, 0xb6, 0x87, 0xd8, 0x9e, 0x17, 0x30, 0x96,
795     0x70, 0xa3, 0x04, 0x69, 0x1c, 0xa2, 0x6c, 0xd4, 0x88, 0x48, 0x44, 0x14,
796     0x94, 0xd4, 0xc9, 0x4d, 0xe3, 0x82, 0x7e, 0x62, 0xf0, 0x0a, 0x18, 0x4d,
797     0xd0, 0xd6, 0x63, 0xa3, 0xdf, 0xea, 0x28, 0xf4, 0x00, 0x75, 0x70, 0x78,
798     0x08, 0x70, 0x3f, 0xff, 0x84, 0x86, 0x72, 0xea, 0x4f, 0x15, 0x8c, 0x17,
799     0x60, 0x5f, 0xa1, 0x50, 0xa0, 0xfc, 0x6f, 0x8a, 0x46, 0xfc, 0x01, 0x8d,
800     0x7c, 0xdc, 0x69, 0x6a, 0xd3, 0x74, 0x69, 0x76, 0x77, 0xdd, 0xe4, 0x9c,
801     0x49, 0x1e, 0x6f, 0x7d, 0x31, 0x14, 0xd9, 0xe9, 0xe7, 0x17, 0x66, 0x82,
802     0x1b, 0xf1, 0x0f, 0xe2, 0xba, 0xd2, 0x28, 0xd1, 0x6f, 0x48, 0xc7, 0xac,
803     0x08, 0x4e, 0xee, 0x94, 0x66, 0x99, 0x34, 0x16, 0x5d, 0x95, 0xae, 0xe3,
804     0x59, 0x79, 0x7f, 0x8e, 0x9f, 0xe3, 0xdb, 0xff, 0xdc, 0x4d, 0xb0, 0xbf,
805     0xf9, 0xf3, 0x3e, 0xec, 0xcf, 0x50, 0x3d, 0x2d, 0xba, 0x94, 0x1f, 0x1a,
806     0xab, 0xa4, 0xf4, 0x67, 0x43, 0x7e, 0xb9, 0x65, 0x20, 0x13, 0xb1, 0xd9,
807     0x88, 0x4a, 0x24, 0x13, 0x84, 0x86, 0xae, 0x2b, 0x0c, 0x6c, 0x7e, 0xd4,
808     0x25, 0x6e, 0xaa, 0x8d, 0x0c, 0x54, 0x99, 0xde, 0x1d, 0xac, 0x8c, 0x5c,
809     0x73, 0x94, 0xd9, 0x75, 0xcb, 0x5a, 0x54, 0x3d, 0xeb, 0xff, 0xc1, 0x95,
810     0x53, 0xb5, 0x39, 0xf7, 0xe5, 0xf1, 0x77, 0xd1, 0x42, 0x82, 0x4b, 0xb0,
811     0xab, 0x19, 0x28, 0xff, 0x53, 0x28, 0x87, 0x46, 0xc6, 0x6f, 0x05, 0x06,
812     0xa6, 0x0c, 0x97, 0x93, 0x68, 0x38, 0xe1, 0x61, 0xed, 0xf8, 0x90, 0x13,
813     0xa3, 0x6f, 0xf2, 0x08, 0x37, 0xd7, 0x05, 0x25, 0x34, 0x43, 0x57, 0x72,
814     0xfd, 0x6c, 0xc2, 0x19, 0x26, 0xe7, 0x50, 0x30, 0xb8, 0x6d, 0x09, 0x71,
815     0x83, 0x75, 0xd4, 0x11, 0x25, 0x29, 0xc6, 0xee, 0xb2, 0x51, 0x1c, 0x1c,
816     0x9e, 0x2d, 0x09, 0xb9, 0x73, 0x2b, 0xbf, 0xda, 0xc8, 0x1e, 0x2b, 0xe5,
817     0x3f, 0x1e, 0x63, 0xe9, 0xc0, 0x6d, 0x04, 0x3a, 0x48, 0x61, 0xa8, 0xc6,
818     0x16, 0x8d, 0x69, 0xc0, 0x67, 0x0c, 0x3b, 0xc4, 0x05, 0x36, 0xa1, 0x30,
819     0x62, 0x92, 0x4d, 0x44, 0x31, 0x66, 0x46, 0xda, 0xef, 0x0f, 0x4e, 0xfb,
820     0x78, 0x6a, 0xa9, 0x5b, 0xf8, 0x56, 0x26, 0x74, 0x16, 0xab, 0x17, 0x93,
821     0x3c, 0x36, 0xbb, 0xa2, 0xbf, 0xad, 0xba, 0xb1, 0xfe, 0xc4, 0x9f, 0x75,
822     0x47, 0x1e, 0x99, 0x7e, 0x32, 0xe8, 0xd4, 0x6c, 0xa4, 0xf8, 0xd2, 0xe4,
823     0xb2, 0x51, 0xbb, 0xb2, 0xd7, 0xce, 0x94, 0xaf, 0x7f, 0xe6, 0x2c, 0x13,
824     0xae, 0xd2, 0x29, 0x30, 0x7b, 0xfd, 0x25, 0x61, 0xf9, 0xe8, 0x35, 0x2d,
825     0x1a, 0xc9, 0x81, 0xa5, 0xfe, 0xce, 0xf6, 0x17, 0xc5, 0xfb, 0x8c, 0x79,
826     0x67, 0xa8, 0x5f, 0x5c, 0x31, 0xbc, 0xfc, 0xf3, 0x6b, 0xd3, 0x0d, 0xe0,
827     0x62, 0xab, 0x86, 0xc3, 0x17, 0x5a, 0xba, 0x97, 0x86, 0x8f, 0x65, 0xd6,
828     0xbd, 0x0c, 0xa1, 0xfb, 0x7f, 0x7c, 0xdc, 0xcb, 0x94, 0x30, 0x0b, 0x04,
829     0x54, 0xc4, 0x31, 0xa1, 0xca, 0x1e, 0xc5, 0xf0, 0xb6, 0x08, 0xd7, 0x2e,
830     0xa1, 0x90, 0x41, 0xce, 0xd9, 0xef, 0x3a, 0x58, 0x01, 0x1a, 0x73, 0x18,
831     0xad, 0xdc, 0x20, 0x25, 0x95, 0x1a, 0xfe, 0x61, 0xf1, 0x58, 0x32, 0x8b,
832     0x43, 0x59, 0xd6, 0x21, 0xdb, 0xa9, 0x8e, 0x54, 0xe6, 0x21, 0xcf, 0xd3,
833     0x6b, 0x59, 0x29, 0x9b, 0x3e, 0x6c, 0x7f, 0xe2, 0x29, 0x72, 0x8c, 0xd1,
834     0x3e, 0x9a, 0x84, 0x98, 0xb0, 0xf3, 0x20, 0x30, 0x34, 0x71, 0xa7, 0x5b,
835     0xf0, 0x26, 0xe1, 0xf4, 0x76, 0x65, 0xc9, 0xd7, 0xe4, 0xb9, 0x25, 0x48,
836     0xc2, 0x7e, 0xa6, 0x0b, 0x0d, 0x05, 0x68, 0xa1, 0x96, 0x61, 0x0b, 0x4c,
837     0x2f, 0x1a, 0xe3, 0x56, 0x71, 0x89, 0x48, 0x66, 0xd8, 0xd0, 0x69, 0x37,
838     0x7a, 0xdf, 0xdb, 0xed, 0xad, 0x82, 0xaa, 0x40, 0x25, 0x47, 0x3e, 0x75,
839     0xa6, 0x0e, 0xf5, 0x2f, 0xa7, 0x4e, 0x97, 0xa2, 0x5f, 0x01, 0x99, 0x48,
840     0x3a, 0x63, 0x18, 0x20, 0x61, 0x72, 0xe4, 0xcf, 0x4b, 0x3b, 0x99, 0x36,
841     0xe1, 0xf3, 0xbf, 0xae, 0x2b, 0x6b, 0xa1, 0x94, 0xa0, 0x15, 0x94, 0xd6,
842     0xe0, 0xba, 0x71, 0xa2, 0x85, 0xa0, 0x8c, 0x5e, 0x58, 0xe2, 0xde, 0x6b,
843     0x08, 0x68, 0x90, 0x82, 0x71, 0x8d, 0xfd, 0x12, 0xa2, 0x49, 0x87, 0x70,
844     0xee, 0x2a, 0x08, 0xe2, 0x26, 0xaf, 0xeb, 0x85, 0x35, 0xd2, 0x0e, 0xfd,
845     0x2b, 0x6f, 0xc0, 0xfe, 0x41, 0xbb, 0xd7, 0x0a, 0xa3, 0x8d, 0x8b, 0xec,
846     0x44, 0x9f, 0x46, 0x59, 0x4d, 0xac, 0x04, 0x1e, 0xde, 0x10, 0x7b, 0x17,
847     0x0a, 0xb0, 0xcc, 0x26, 0x0c, 0xa9, 0x3c, 0x5f, 0xd8, 0xe6, 0x52, 0xd3,
848     0xfd, 0x0b, 0x66, 0x75, 0x06, 0x84, 0x23, 0x64, 0x2b, 0x80, 0x68, 0xf9,
849     0xcb, 0xcd, 0x04, 0x07, 0xf7, 0xe0, 0x07, 0xb4, 0xc6, 0xa0, 0x08, 0xd0,
850     0x76, 0x16, 0x77, 0xd8, 0x48, 0xf0, 0x45, 0x4e, 0xe2, 0xf2, 0x88, 0xcd,
851     0x0f, 0xbd, 0x7d, 0xb6, 0xbe, 0x4e, 0x9e, 0x5d, 0x6c, 0x47, 0x26, 0x34,
852     0x94, 0xfb, 0xc5, 0x4f, 0x5c, 0xb5, 0xb5, 0xfc, 0x99, 0x34, 0x71, 0xe5,
853     0xe1, 0x36, 0x0c, 0xd2, 0x95, 0xb8, 0x93, 0x3c, 0x5d, 0x2d, 0x71, 0x55,
854     0x0b, 0x96, 0x4e, 0x9f, 0x07, 0x9a, 0x38, 0x9a, 0xcc, 0x24, 0xb5, 0xac,
855     0x05, 0x8b, 0x1c, 0x61, 0xd4, 0xf2, 0xdf, 0x9e, 0x11, 0xe3, 0x7d, 0x64,
856     0x2f, 0xe5, 0x13, 0xd4, 0x0a, 0xe9, 0x32, 0x26, 0xa8, 0x93, 0x21, 0x59,
857     0xf3, 0x41, 0x48, 0x0a, 0xbd, 0x59, 0x8f, 0xf8, 0x72, 0xab, 0xd3, 0x65,
858     0x8e, 0xdc, 0xaa, 0x0c, 0xc0, 0x01, 0x36, 0xb7, 0xf5, 0x84, 0x27, 0x9a,
859     0x98, 0x89, 0x73, 0x3a, 0xeb, 0x55, 0x15, 0xc9, 0x3d, 0xe1, 0xf8, 0xea,
860     0xf6, 0x11, 0x28, 0xe0, 0x80, 0x93, 0xcc, 0xba, 0xe1, 0xf1, 0x81, 0xbc,
861     0xa4, 0x30, 0xbc, 0x98, 0xe8, 0x9e, 0x8d, 0x17, 0x7e, 0xb7, 0xb1, 0x27,
862     0x6f, 0xcf, 0x9c, 0x0d, 0x1d, 0x01, 0xea, 0x45, 0xc0, 0x90, 0xda, 0x53,
863     0xf6, 0xde, 0xdf, 0x12, 0xa1, 0x23, 0x3d, 0x92, 0x89, 0x77, 0xa7, 0x2a,
864     0xe7, 0x45, 0x24, 0xdd, 0xf2, 0x17, 0x10, 0xca, 0x6e, 0x14, 0xb2, 0x77,
865     0x08, 0xc4, 0x18, 0xcd
866 };
867
868 static uint64_t stream_10a_off, stream_10b_off;
869
870 static int check_stream_10a(struct helper *h)
871 {
872     /*
873      * Must have filled or almost filled the packet (using default MDPL of
874      * 1200).
875      */
876     if (!TEST_uint64_t_ge(h->frame.stream.len, 1150)
877         || !TEST_uint64_t_le(h->frame.stream.len, 1200))
878         return 0;
879
880     if (!TEST_mem_eq(h->frame.stream.data, (size_t)h->frame.stream.len,
881                      stream_10a, (size_t)h->frame.stream.len))
882         return 0;
883
884     stream_10a_off = h->frame.stream.offset + h->frame.stream.len;
885     return 1;
886 }
887
888 static int check_stream_10b(struct helper *h)
889 {
890     if (!TEST_uint64_t_ge(h->frame.stream.len, 1150)
891         || !TEST_uint64_t_le(h->frame.stream.len, 1200))
892         return 0;
893
894     if (!TEST_mem_eq(h->frame.stream.data, (size_t)h->frame.stream.len,
895                      stream_10b, (size_t)h->frame.stream.len))
896         return 0;
897
898     stream_10b_off = h->frame.stream.offset + h->frame.stream.len;
899     return 1;
900 }
901
902 static int check_stream_10c(struct helper *h)
903 {
904     if (!TEST_uint64_t_ge(h->frame.stream.len, 5)
905         || !TEST_uint64_t_le(h->frame.stream.len, 200))
906         return 0;
907
908     if (!TEST_mem_eq(h->frame.stream.data, (size_t)h->frame.stream.len,
909                      stream_10a + stream_10a_off, (size_t)h->frame.stream.len))
910         return 0;
911
912     return 1;
913 }
914
915 static int check_stream_10d(struct helper *h)
916 {
917     if (!TEST_uint64_t_ge(h->frame.stream.len, 5)
918         || !TEST_uint64_t_le(h->frame.stream.len, 200))
919         return 0;
920
921     if (!TEST_mem_eq(h->frame.stream.data, (size_t)h->frame.stream.len,
922                      stream_10b + stream_10b_off, (size_t)h->frame.stream.len))
923         return 0;
924
925     return 1;
926 }
927
928 static const struct script_op script_10[] = {
929     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
930     OP_HANDSHAKE_COMPLETE()
931     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
932     OP_STREAM_NEW(42)
933     OP_STREAM_NEW(43)
934     OP_CONN_TXFC_BUMP(10000)
935     OP_STREAM_TXFC_BUMP(42, 5000)
936     OP_STREAM_TXFC_BUMP(43, 5000)
937     OP_STREAM_SEND(42, stream_10a)
938     OP_STREAM_SEND(43, stream_10b)
939
940     /* First packet containing data from stream 42 */
941     OP_TXP_GENERATE(TX_PACKETISER_ARCHETYPE_NORMAL)
942     OP_RX_PKT()
943     OP_EXPECT_DGRAM_LEN(1100, 1200)
944     OP_NEXT_FRAME()
945     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_STREAM)
946     OP_CHECK(check_stream_10a)
947     OP_EXPECT_NO_FRAME()
948
949     /* Second packet containing data from stream 43 */
950     OP_TXP_GENERATE(TX_PACKETISER_ARCHETYPE_NORMAL)
951     OP_RX_PKT()
952     OP_EXPECT_DGRAM_LEN(1100, 1200)
953     OP_NEXT_FRAME()
954     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_STREAM)
955     OP_CHECK(check_stream_10b)
956     OP_EXPECT_NO_FRAME()
957
958     /* Third packet containing data from stream 42 */
959     OP_TXP_GENERATE(TX_PACKETISER_ARCHETYPE_NORMAL)
960     OP_RX_PKT()
961     OP_EXPECT_DGRAM_LEN(200, 500)
962     OP_NEXT_FRAME()
963     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_STREAM_OFF_LEN)
964     OP_CHECK(check_stream_10c)
965     OP_NEXT_FRAME()
966     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_STREAM_OFF)
967     OP_CHECK(check_stream_10d)
968     OP_EXPECT_NO_FRAME()
969
970     OP_RX_PKT_NONE()
971     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
972
973     OP_END
974 };
975
976 /* 11. Initial, CRYPTO */
977 static const struct script_op script_11[] = {
978     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_INITIAL, QRL_SUITE_AES128GCM, secret_1)
979     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
980     OP_CRYPTO_SEND(QUIC_PN_SPACE_INITIAL, crypto_1)
981     OP_TXP_GENERATE(TX_PACKETISER_ARCHETYPE_NORMAL)
982     OP_RX_PKT()
983     OP_EXPECT_DGRAM_LEN(1200, 1200)
984     OP_NEXT_FRAME()
985     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_CRYPTO)
986     OP_EXPECT_NO_FRAME()
987     OP_RX_PKT_NONE()
988     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
989     OP_END
990 };
991
992 /* 12. 1-RTT, STOP_SENDING */
993 static int check_stream_12(struct helper *h)
994 {
995     if (!TEST_uint64_t_eq(h->frame.stop_sending.stream_id, 42)
996         || !TEST_uint64_t_eq(h->frame.stop_sending.app_error_code, 4568))
997         return 0;
998
999     return 1;
1000 }
1001
1002 static const struct script_op script_12[] = {
1003     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
1004     OP_HANDSHAKE_COMPLETE()
1005     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
1006     OP_STREAM_NEW(42)
1007     OP_STOP_SENDING(42, 4568)
1008     OP_TXP_GENERATE(TX_PACKETISER_ARCHETYPE_NORMAL)
1009     OP_RX_PKT()
1010     OP_EXPECT_DGRAM_LEN(21, 128)
1011     OP_NEXT_FRAME()
1012     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_STOP_SENDING)
1013     OP_CHECK(check_stream_12)
1014     OP_EXPECT_NO_FRAME()
1015     OP_RX_PKT_NONE()
1016     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
1017     OP_END
1018 };
1019
1020 /* 13. 1-RTT, RESET_STREAM */
1021 static const unsigned char stream_13[] = {
1022     0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, 0x7a, 0x7b
1023 };
1024
1025 static ossl_unused int check_stream_13(struct helper *h)
1026 {
1027     if (!TEST_uint64_t_eq(h->frame.reset_stream.stream_id, 42)
1028         || !TEST_uint64_t_eq(h->frame.reset_stream.app_error_code, 4568)
1029         || !TEST_uint64_t_eq(h->frame.reset_stream.final_size, 8))
1030         return 0;
1031
1032     return 1;
1033 }
1034
1035 static const struct script_op script_13[] = {
1036     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
1037     OP_HANDSHAKE_COMPLETE()
1038     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
1039     OP_STREAM_NEW(42)
1040     OP_CONN_TXFC_BUMP(8)
1041     OP_STREAM_TXFC_BUMP(42, 8)
1042     OP_STREAM_SEND(42, stream_13)
1043     OP_RESET_STREAM(42, 4568)
1044     OP_TXP_GENERATE(TX_PACKETISER_ARCHETYPE_NORMAL)
1045     OP_RX_PKT()
1046     OP_EXPECT_DGRAM_LEN(21, 128)
1047     OP_NEXT_FRAME()
1048     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_RESET_STREAM)
1049     OP_CHECK(check_stream_13)
1050     OP_NEXT_FRAME()
1051     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_STREAM)
1052     OP_EXPECT_NO_FRAME()
1053     OP_RX_PKT_NONE()
1054     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
1055     OP_END
1056 };
1057
1058 /* 14. 1-RTT, CONNECTION_CLOSE */
1059 static int gen_conn_close(struct helper *h)
1060 {
1061     OSSL_QUIC_FRAME_CONN_CLOSE f = {0};
1062
1063     f.error_code     = 2345;
1064     f.frame_type     = OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE;
1065     f.reason         = "Reason string";
1066     f.reason_len     = strlen(f.reason);
1067
1068     if (!TEST_true(ossl_quic_tx_packetiser_schedule_conn_close(h->txp, &f)))
1069         return 0;
1070
1071     return 1;
1072 }
1073
1074 static int check_14(struct helper *h)
1075 {
1076     if (!TEST_int_eq(h->frame.conn_close.is_app, 0)
1077         || !TEST_uint64_t_eq(h->frame.conn_close.frame_type,
1078                              OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE)
1079         || !TEST_uint64_t_eq(h->frame.conn_close.error_code, 2345)
1080         || !TEST_mem_eq(h->frame.conn_close.reason, h->frame.conn_close.reason_len,
1081                         "Reason string", 13))
1082         return 0;
1083
1084     return 1;
1085 }
1086
1087 static const struct script_op script_14[] = {
1088     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
1089     OP_HANDSHAKE_COMPLETE()
1090     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
1091     OP_CHECK(gen_conn_close)
1092     OP_TXP_GENERATE(TX_PACKETISER_ARCHETYPE_NORMAL)
1093     OP_RX_PKT()
1094     OP_EXPECT_DGRAM_LEN(21, 512)
1095     OP_NEXT_FRAME()
1096     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_TRANSPORT)
1097     OP_CHECK(check_14)
1098     OP_EXPECT_NO_FRAME()
1099     OP_RX_PKT_NONE()
1100     OP_END
1101 };
1102
1103 /* 15. INITIAL, Anti-Deadlock Probe Simulation */
1104 static int gen_probe_initial(struct helper *h)
1105 {
1106     OSSL_ACKM_PROBE_INFO *probe = ossl_ackm_get0_probe_request(h->args.ackm);
1107
1108     /*
1109      * Pretend the ACKM asked for an anti-deadlock Initial probe.
1110      * We test output of this in the ACKM unit tests.
1111      */
1112     ++probe->anti_deadlock_initial;
1113     return 1;
1114 }
1115
1116 static const struct script_op script_15[] = {
1117     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_INITIAL, QRL_SUITE_AES128GCM, secret_1)
1118     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
1119     OP_CHECK(gen_probe_initial)
1120     OP_TXP_GENERATE(TX_PACKETISER_ARCHETYPE_NORMAL)
1121     OP_RX_PKT()
1122     OP_EXPECT_DGRAM_LEN(1200, 1200)
1123     OP_NEXT_FRAME()
1124     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_PING)
1125     OP_EXPECT_NO_FRAME()
1126     OP_RX_PKT_NONE()
1127     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
1128     OP_END
1129 };
1130
1131 /* 16. HANDSHAKE, Anti-Deadlock Probe Simulation */
1132 static int gen_probe_handshake(struct helper *h)
1133 {
1134     OSSL_ACKM_PROBE_INFO *probe = ossl_ackm_get0_probe_request(h->args.ackm);
1135
1136     /*
1137      * Pretend the ACKM asked for an anti-deadlock Handshake probe.
1138      * We test output of this in the ACKM unit tests.
1139      */
1140     ++probe->anti_deadlock_handshake;
1141     return 1;
1142 }
1143
1144 static const struct script_op script_16[] = {
1145     OP_DISCARD_EL(QUIC_ENC_LEVEL_INITIAL)
1146     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_HANDSHAKE, QRL_SUITE_AES128GCM, secret_1)
1147     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
1148     OP_CHECK(gen_probe_handshake)
1149     OP_TXP_GENERATE(TX_PACKETISER_ARCHETYPE_NORMAL)
1150     OP_RX_PKT()
1151     OP_EXPECT_DGRAM_LEN(21, 512)
1152     OP_NEXT_FRAME()
1153     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_PING)
1154     OP_EXPECT_NO_FRAME()
1155     OP_RX_PKT_NONE()
1156     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
1157     OP_END
1158 };
1159
1160 /* 17. 1-RTT, Probe Simulation */
1161 static int gen_probe_1rtt(struct helper *h)
1162 {
1163     OSSL_ACKM_PROBE_INFO *probe = ossl_ackm_get0_probe_request(h->args.ackm);
1164
1165     /*
1166      * Pretend the ACKM asked for a 1-RTT PTO probe.
1167      * We test output of this in the ACKM unit tests.
1168      */
1169     ++probe->pto[QUIC_PN_SPACE_APP];
1170     return 1;
1171 }
1172
1173 static const struct script_op script_17[] = {
1174     OP_DISCARD_EL(QUIC_ENC_LEVEL_INITIAL)
1175     OP_DISCARD_EL(QUIC_ENC_LEVEL_HANDSHAKE)
1176     OP_PROVIDE_SECRET(QUIC_ENC_LEVEL_1RTT, QRL_SUITE_AES128GCM, secret_1)
1177     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
1178     OP_CHECK(gen_probe_1rtt)
1179     OP_TXP_GENERATE(TX_PACKETISER_ARCHETYPE_NORMAL)
1180     OP_RX_PKT()
1181     OP_EXPECT_DGRAM_LEN(21, 512)
1182     OP_NEXT_FRAME()
1183     OP_EXPECT_FRAME(OSSL_QUIC_FRAME_TYPE_PING)
1184     OP_EXPECT_NO_FRAME()
1185     OP_RX_PKT_NONE()
1186     OP_TXP_GENERATE_NONE(TX_PACKETISER_ARCHETYPE_NORMAL)
1187     OP_END
1188 };
1189
1190 static const struct script_op *const scripts[] = {
1191     script_1,
1192     script_2,
1193     script_3,
1194     script_4,
1195     script_5,
1196     script_6,
1197     script_7,
1198     script_8,
1199     script_9,
1200     script_10,
1201     script_11,
1202     script_12,
1203     script_13,
1204     script_14,
1205     script_15,
1206     script_16,
1207     script_17
1208 };
1209
1210 static void skip_padding(struct helper *h)
1211 {
1212     uint64_t frame_type;
1213
1214     if (!ossl_quic_wire_peek_frame_header(&h->pkt, &frame_type))
1215         return; /* EOF */
1216
1217     if (frame_type == OSSL_QUIC_FRAME_TYPE_PADDING)
1218         ossl_quic_wire_decode_padding(&h->pkt);
1219 }
1220
1221 static int run_script(const struct script_op *script)
1222 {
1223     int testresult = 0, have_helper = 0, sent_ack_eliciting = 0;
1224     struct helper h;
1225     const struct script_op *op;
1226
1227     if (!helper_init(&h))
1228         goto err;
1229
1230     have_helper = 1;
1231     for (op = script; op->opcode != OPK_END; ++op) {
1232         switch (op->opcode) {
1233         case OPK_TXP_GENERATE:
1234             if (!TEST_int_eq(ossl_quic_tx_packetiser_generate(h.txp, (int)op->arg0,
1235                                                               &sent_ack_eliciting),
1236                              TX_PACKETISER_RES_SENT_PKT))
1237                 goto err;
1238
1239             ossl_qtx_finish_dgram(h.args.qtx);
1240             ossl_qtx_flush_net(h.args.qtx);
1241             break;
1242         case OPK_TXP_GENERATE_NONE:
1243             if (!TEST_int_eq(ossl_quic_tx_packetiser_generate(h.txp, (int)op->arg0,
1244                                                               &sent_ack_eliciting),
1245                              TX_PACKETISER_RES_NO_PKT))
1246                 goto err;
1247
1248             break;
1249         case OPK_RX_PKT:
1250             ossl_quic_demux_pump(h.demux);
1251             ossl_qrx_pkt_release(h.qrx_pkt);
1252             h.qrx_pkt = NULL;
1253             if (!TEST_true(ossl_qrx_read_pkt(h.qrx, &h.qrx_pkt)))
1254                 goto err;
1255             if (!TEST_true(PACKET_buf_init(&h.pkt,
1256                                            h.qrx_pkt->hdr->data,
1257                                            h.qrx_pkt->hdr->len)))
1258                 goto err;
1259             h.frame_type = UINT64_MAX;
1260             break;
1261         case OPK_RX_PKT_NONE:
1262             ossl_quic_demux_pump(h.demux);
1263             if (!TEST_false(ossl_qrx_read_pkt(h.qrx, &h.qrx_pkt)))
1264                 goto err;
1265             h.frame_type = UINT64_MAX;
1266             break;
1267         case OPK_EXPECT_DGRAM_LEN:
1268             if (!TEST_size_t_ge(h.qrx_pkt->datagram_len, (size_t)op->arg0)
1269                 || !TEST_size_t_le(h.qrx_pkt->datagram_len, (size_t)op->arg1))
1270                 goto err;
1271             break;
1272         case OPK_EXPECT_FRAME:
1273             if (!TEST_uint64_t_eq(h.frame_type, op->arg0))
1274                 goto err;
1275             break;
1276         case OPK_EXPECT_INITIAL_TOKEN:
1277             if (!TEST_mem_eq(h.qrx_pkt->hdr->token, h.qrx_pkt->hdr->token_len,
1278                              op->buf, (size_t)op->arg0))
1279                 goto err;
1280             break;
1281         case OPK_EXPECT_HDR:
1282             if (!TEST_true(cmp_pkt_hdr(h.qrx_pkt->hdr, op->buf,
1283                                        NULL, 0, 0)))
1284                 goto err;
1285             break;
1286         case OPK_CHECK:
1287             if (!TEST_true(op->check_func(&h)))
1288                 goto err;
1289             break;
1290         case OPK_NEXT_FRAME:
1291             skip_padding(&h);
1292             if (!ossl_quic_wire_peek_frame_header(&h.pkt, &h.frame_type)) {
1293                 h.frame_type = UINT64_MAX;
1294                 break;
1295             }
1296
1297             switch (h.frame_type) {
1298             case OSSL_QUIC_FRAME_TYPE_HANDSHAKE_DONE:
1299                 if (!TEST_true(ossl_quic_wire_decode_frame_handshake_done(&h.pkt)))
1300                     goto err;
1301                 break;
1302             case OSSL_QUIC_FRAME_TYPE_PING:
1303                 if (!TEST_true(ossl_quic_wire_decode_frame_ping(&h.pkt)))
1304                     goto err;
1305                 break;
1306             case OSSL_QUIC_FRAME_TYPE_MAX_DATA:
1307                 if (!TEST_true(ossl_quic_wire_decode_frame_max_data(&h.pkt,
1308                                                                     &h.frame.max_data)))
1309                     goto err;
1310                 break;
1311             case OSSL_QUIC_FRAME_TYPE_NEW_CONN_ID:
1312                 if (!TEST_true(ossl_quic_wire_decode_frame_new_conn_id(&h.pkt,
1313                                                                        &h.frame.new_conn_id)))
1314                     goto err;
1315                 break;
1316             case OSSL_QUIC_FRAME_TYPE_NEW_TOKEN:
1317                 if (!TEST_true(ossl_quic_wire_decode_frame_new_token(&h.pkt,
1318                                                                      &h.frame.new_token.token,
1319                                                                      &h.frame.new_token.token_len)))
1320                     goto err;
1321                 break;
1322             case OSSL_QUIC_FRAME_TYPE_ACK_WITH_ECN:
1323             case OSSL_QUIC_FRAME_TYPE_ACK_WITHOUT_ECN:
1324                 h.frame.ack.ack_ranges      = h.ack_ranges;
1325                 h.frame.ack.num_ack_ranges  = OSSL_NELEM(h.ack_ranges);
1326                 if (!TEST_true(ossl_quic_wire_decode_frame_ack(&h.pkt,
1327                                                                h.args.ack_delay_exponent,
1328                                                                &h.frame.ack,
1329                                                                NULL)))
1330                     goto err;
1331                 break;
1332             case OSSL_QUIC_FRAME_TYPE_CRYPTO:
1333                 if (!TEST_true(ossl_quic_wire_decode_frame_crypto(&h.pkt, &h.frame.crypto)))
1334                     goto err;
1335                 break;
1336
1337             case OSSL_QUIC_FRAME_TYPE_STREAM:
1338             case OSSL_QUIC_FRAME_TYPE_STREAM_FIN:
1339             case OSSL_QUIC_FRAME_TYPE_STREAM_LEN:
1340             case OSSL_QUIC_FRAME_TYPE_STREAM_LEN_FIN:
1341             case OSSL_QUIC_FRAME_TYPE_STREAM_OFF:
1342             case OSSL_QUIC_FRAME_TYPE_STREAM_OFF_FIN:
1343             case OSSL_QUIC_FRAME_TYPE_STREAM_OFF_LEN:
1344             case OSSL_QUIC_FRAME_TYPE_STREAM_OFF_LEN_FIN:
1345                 if (!TEST_true(ossl_quic_wire_decode_frame_stream(&h.pkt, &h.frame.stream)))
1346                     goto err;
1347                 break;
1348
1349             case OSSL_QUIC_FRAME_TYPE_STOP_SENDING:
1350                 if (!TEST_true(ossl_quic_wire_decode_frame_stop_sending(&h.pkt,
1351                                                                         &h.frame.stop_sending)))
1352                     goto err;
1353                 break;
1354
1355             case OSSL_QUIC_FRAME_TYPE_RESET_STREAM:
1356                 if (!TEST_true(ossl_quic_wire_decode_frame_reset_stream(&h.pkt,
1357                                                                         &h.frame.reset_stream)))
1358                     goto err;
1359                 break;
1360
1361             case OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_TRANSPORT:
1362             case OSSL_QUIC_FRAME_TYPE_CONN_CLOSE_APP:
1363                 if (!TEST_true(ossl_quic_wire_decode_frame_conn_close(&h.pkt,
1364                                                                       &h.frame.conn_close)))
1365                     goto err;
1366                 break;
1367
1368             default:
1369                 TEST_error("unknown frame type");
1370                 goto err;
1371             }
1372             break;
1373         case OPK_EXPECT_NO_FRAME:
1374             skip_padding(&h);
1375             if (!TEST_size_t_eq(PACKET_remaining(&h.pkt), 0))
1376                 goto err;
1377             break;
1378         case OPK_PROVIDE_SECRET:
1379             if (!TEST_true(ossl_qtx_provide_secret(h.args.qtx,
1380                                                    (uint32_t)op->arg0,
1381                                                    (uint32_t)op->arg1,
1382                                                    NULL, op->buf, op->buf_len)))
1383                 goto err;
1384             if (!TEST_true(ossl_qrx_provide_secret(h.qrx,
1385                                                    (uint32_t)op->arg0,
1386                                                    (uint32_t)op->arg1,
1387                                                    NULL, op->buf, op->buf_len)))
1388                 goto err;
1389             break;
1390         case OPK_DISCARD_EL:
1391             if (!TEST_true(ossl_quic_tx_packetiser_discard_enc_level(h.txp,
1392                                                                      (uint32_t)op->arg0)))
1393                 goto err;
1394             /*
1395              * We do not discard on the QRX here, the object is to test the
1396              * TXP so if the TXP does erroneously send at a discarded EL we
1397              * want to know about it.
1398              */
1399             break;
1400         case OPK_CRYPTO_SEND:
1401             {
1402                 size_t consumed = 0;
1403
1404                 if (!TEST_true(ossl_quic_sstream_append(h.args.crypto[op->arg0],
1405                                                         op->buf, op->buf_len,
1406                                                         &consumed)))
1407                     goto err;
1408
1409                 if (!TEST_size_t_eq(consumed, op->buf_len))
1410                     goto err;
1411             }
1412             break;
1413         case OPK_STREAM_NEW:
1414             {
1415                 QUIC_STREAM *s;
1416
1417                 if (!TEST_ptr(s = ossl_quic_stream_map_alloc(h.args.qsm, op->arg0,
1418                                                              QUIC_STREAM_DIR_BIDI)))
1419                     goto err;
1420
1421                 if (!TEST_ptr(s->sstream = ossl_quic_sstream_new(512 * 1024))
1422                     || !TEST_true(ossl_quic_txfc_init(&s->txfc, &h.conn_txfc))
1423                     || !TEST_true(ossl_quic_rxfc_init(&s->rxfc, &h.conn_rxfc,
1424                                                       1 * 1024 * 1024,
1425                                                       16 * 1024 * 1024,
1426                                                       fake_now, NULL))) {
1427                     ossl_quic_sstream_free(s->sstream);
1428                     ossl_quic_stream_map_release(h.args.qsm, s);
1429                     goto err;
1430                 }
1431             }
1432             break;
1433         case OPK_STREAM_SEND:
1434             {
1435                 QUIC_STREAM *s;
1436                 size_t consumed = 0;
1437
1438                 if (!TEST_ptr(s = ossl_quic_stream_map_get_by_id(h.args.qsm,
1439                                                                  op->arg0)))
1440                     goto err;
1441
1442                 if (!TEST_true(ossl_quic_sstream_append(s->sstream, op->buf,
1443                                                         op->buf_len, &consumed)))
1444                     goto err;
1445
1446                 if (!TEST_size_t_eq(consumed, op->buf_len))
1447                     goto err;
1448
1449                 ossl_quic_stream_map_update_state(h.args.qsm, s);
1450             }
1451             break;
1452         case OPK_STREAM_FIN:
1453             {
1454                 QUIC_STREAM *s;
1455
1456                 if (!TEST_ptr(s = ossl_quic_stream_map_get_by_id(h.args.qsm,
1457                                                                  op->arg0)))
1458                     goto err;
1459
1460                 ossl_quic_sstream_fin(s->sstream);
1461             }
1462             break;
1463         case OPK_STOP_SENDING:
1464             {
1465                 QUIC_STREAM *s;
1466
1467                 if (!TEST_ptr(s = ossl_quic_stream_map_get_by_id(h.args.qsm,
1468                                                                  op->arg0)))
1469                     goto err;
1470
1471                 if (!TEST_true(ossl_quic_stream_stop_sending(s, op->arg1)))
1472                     goto err;
1473
1474                 ossl_quic_stream_map_update_state(h.args.qsm, s);
1475
1476                 if (!TEST_true(s->active))
1477                     goto err;
1478             }
1479             break;
1480         case OPK_RESET_STREAM:
1481             {
1482                 QUIC_STREAM *s;
1483
1484                 if (!TEST_ptr(s = ossl_quic_stream_map_get_by_id(h.args.qsm,
1485                                                                  op->arg0)))
1486                     goto err;
1487
1488                 if (!TEST_true(ossl_quic_stream_reset(s, op->arg1)))
1489                     goto err;
1490
1491                 ossl_quic_stream_map_update_state(h.args.qsm, s);
1492
1493                 if (!TEST_true(s->active))
1494                     goto err;
1495             }
1496             break;
1497         case OPK_CONN_TXFC_BUMP:
1498             if (!TEST_true(ossl_quic_txfc_bump_cwm(h.args.conn_txfc, op->arg0)))
1499                 goto err;
1500
1501             break;
1502         case OPK_STREAM_TXFC_BUMP:
1503             {
1504                 QUIC_STREAM *s;
1505
1506                 if (!TEST_ptr(s = ossl_quic_stream_map_get_by_id(h.args.qsm,
1507                                                                  op->arg1)))
1508                     goto err;
1509
1510                 if (!TEST_true(ossl_quic_txfc_bump_cwm(&s->txfc, op->arg0)))
1511                     goto err;
1512
1513                 ossl_quic_stream_map_update_state(h.args.qsm, s);
1514             }
1515             break;
1516         case OPK_HANDSHAKE_COMPLETE:
1517             ossl_quic_tx_packetiser_notify_handshake_complete(h.txp);
1518             break;
1519         default:
1520             TEST_error("bad opcode");
1521             goto err;
1522         }
1523     }
1524
1525     testresult = 1;
1526 err:
1527     if (have_helper)
1528         helper_cleanup(&h);
1529     return testresult;
1530 }
1531
1532 static int test_script(int idx)
1533 {
1534     return run_script(scripts[idx]);
1535 }
1536
1537 int setup_tests(void)
1538 {
1539     ADD_ALL_TESTS(test_script, OSSL_NELEM(scripts));
1540     return 1;
1541 }