test_packno_len.c revision 06b2a236
106b2a236SDmitri Tikhonov/* Copyright (c) 2017 - 2021 LiteSpeed Technologies Inc.  See LICENSE. */
250aadb33SDmitri Tikhonov#include <assert.h>
350aadb33SDmitri Tikhonov#include <stdio.h>
450aadb33SDmitri Tikhonov#include <stdlib.h>
550aadb33SDmitri Tikhonov#include <string.h>
650aadb33SDmitri Tikhonov#include <sys/queue.h>
7461e84d8SAmol Deshpande#ifndef WIN32
850aadb33SDmitri Tikhonov#include <sys/time.h>
9461e84d8SAmol Deshpande#endif
1050aadb33SDmitri Tikhonov
1150aadb33SDmitri Tikhonov#include "lsquic.h"
1250aadb33SDmitri Tikhonov#include "lsquic_types.h"
1350aadb33SDmitri Tikhonov#include "lsquic_packet_common.h"
1450aadb33SDmitri Tikhonov#include "lsquic_parse.h"
1550aadb33SDmitri Tikhonov
1650aadb33SDmitri Tikhonov
17fb96f4ddSDmitri Tikhonovstatic const struct parse_funcs *const pf = select_pf_by_ver(LSQVER_043);
18c7d81ce1SDmitri Tikhonov
19c7d81ce1SDmitri Tikhonov
2050aadb33SDmitri Tikhonovstruct packno_bits_test {
2150aadb33SDmitri Tikhonov    int             pbt_lineno;
2250aadb33SDmitri Tikhonov    /* Inputs: */
235392f7a3SLiteSpeed Tech    lsquic_packno_t pbt_packno,
2450aadb33SDmitri Tikhonov                    pbt_least_unacked;
2550aadb33SDmitri Tikhonov    uint64_t        pbt_n_in_flight;
2650aadb33SDmitri Tikhonov    /* Output: */
27c7d81ce1SDmitri Tikhonov    enum packno_bits pbt_packno_bits;
2850aadb33SDmitri Tikhonov};
2950aadb33SDmitri Tikhonov
3050aadb33SDmitri Tikhonov
3150aadb33SDmitri Tikhonovstatic const struct packno_bits_test pb_tests[] = {
3250aadb33SDmitri Tikhonov
3350aadb33SDmitri Tikhonov    {   .pbt_lineno         = __LINE__,
3450aadb33SDmitri Tikhonov        .pbt_packno         = 1,
3550aadb33SDmitri Tikhonov        .pbt_least_unacked  = 0,
3650aadb33SDmitri Tikhonov        .pbt_n_in_flight    = 0,
37c7d81ce1SDmitri Tikhonov        .pbt_packno_bits    = GQUIC_PACKNO_LEN_1,
3850aadb33SDmitri Tikhonov    },
3950aadb33SDmitri Tikhonov
4050aadb33SDmitri Tikhonov    {   .pbt_lineno         = __LINE__,
4150aadb33SDmitri Tikhonov        .pbt_packno         = 101,
4250aadb33SDmitri Tikhonov        .pbt_least_unacked  = 100,
4350aadb33SDmitri Tikhonov        .pbt_n_in_flight    = 0,
44c7d81ce1SDmitri Tikhonov        .pbt_packno_bits    = GQUIC_PACKNO_LEN_1,
4550aadb33SDmitri Tikhonov    },
4650aadb33SDmitri Tikhonov
4750aadb33SDmitri Tikhonov    {   .pbt_lineno         = __LINE__,
4850aadb33SDmitri Tikhonov        .pbt_packno         = 10001,
4950aadb33SDmitri Tikhonov        .pbt_least_unacked  = 10000,
5050aadb33SDmitri Tikhonov        .pbt_n_in_flight    = 1 << 6,
51c7d81ce1SDmitri Tikhonov        .pbt_packno_bits    = GQUIC_PACKNO_LEN_1,
5250aadb33SDmitri Tikhonov    },
5350aadb33SDmitri Tikhonov
5450aadb33SDmitri Tikhonov    {   .pbt_lineno         = __LINE__,
5550aadb33SDmitri Tikhonov        .pbt_packno         = 10001,
5650aadb33SDmitri Tikhonov        .pbt_least_unacked  = 10000,
5750aadb33SDmitri Tikhonov        .pbt_n_in_flight    = (1 << 6) + 1,
58c7d81ce1SDmitri Tikhonov        .pbt_packno_bits    = GQUIC_PACKNO_LEN_2,
5950aadb33SDmitri Tikhonov    },
6050aadb33SDmitri Tikhonov
6150aadb33SDmitri Tikhonov    {   .pbt_lineno         = __LINE__,
6250aadb33SDmitri Tikhonov        .pbt_packno         = (1 << 16) + 1,
6350aadb33SDmitri Tikhonov        .pbt_least_unacked  = 1 << 16,
6450aadb33SDmitri Tikhonov        .pbt_n_in_flight    = 1 << 14,
65c7d81ce1SDmitri Tikhonov        .pbt_packno_bits    = GQUIC_PACKNO_LEN_2,
6650aadb33SDmitri Tikhonov    },
6750aadb33SDmitri Tikhonov
6850aadb33SDmitri Tikhonov    {   .pbt_lineno         = __LINE__,
6950aadb33SDmitri Tikhonov        .pbt_packno         = (1 << 16) + 1,
7050aadb33SDmitri Tikhonov        .pbt_least_unacked  = 1 << 16,
7150aadb33SDmitri Tikhonov        .pbt_n_in_flight    = (1 << 14) + 1,
72c7d81ce1SDmitri Tikhonov        .pbt_packno_bits    = GQUIC_PACKNO_LEN_4,
7350aadb33SDmitri Tikhonov    },
7450aadb33SDmitri Tikhonov
7550aadb33SDmitri Tikhonov    {   .pbt_lineno         = __LINE__,
7650aadb33SDmitri Tikhonov        .pbt_packno         = (1ULL << 33) + 1,
7750aadb33SDmitri Tikhonov        .pbt_least_unacked  = 1ULL << 33,
7850aadb33SDmitri Tikhonov        .pbt_n_in_flight    = 1ULL << 30,
79c7d81ce1SDmitri Tikhonov        .pbt_packno_bits    = GQUIC_PACKNO_LEN_4,
8050aadb33SDmitri Tikhonov    },
8150aadb33SDmitri Tikhonov
8250aadb33SDmitri Tikhonov    {   .pbt_lineno         = __LINE__,
8350aadb33SDmitri Tikhonov        .pbt_packno         = (1ULL << 33) + 1,
8450aadb33SDmitri Tikhonov        .pbt_least_unacked  = 1ULL << 33,
8550aadb33SDmitri Tikhonov        .pbt_n_in_flight    = (1ULL << 30) + 1,
86c7d81ce1SDmitri Tikhonov        .pbt_packno_bits    = GQUIC_PACKNO_LEN_6,
8750aadb33SDmitri Tikhonov    },
8850aadb33SDmitri Tikhonov
8950aadb33SDmitri Tikhonov    {   .pbt_lineno         = __LINE__,
9050aadb33SDmitri Tikhonov        .pbt_packno         = 100,
9150aadb33SDmitri Tikhonov        .pbt_least_unacked  = 1,
9250aadb33SDmitri Tikhonov        .pbt_n_in_flight    = 3,
93c7d81ce1SDmitri Tikhonov        .pbt_packno_bits    = GQUIC_PACKNO_LEN_2,
9450aadb33SDmitri Tikhonov    },
9550aadb33SDmitri Tikhonov
9650aadb33SDmitri Tikhonov    {   .pbt_lineno         = __LINE__,
9750aadb33SDmitri Tikhonov        .pbt_packno         = 100,
9850aadb33SDmitri Tikhonov        .pbt_least_unacked  = 1,
9950aadb33SDmitri Tikhonov        .pbt_n_in_flight    = 99,
100c7d81ce1SDmitri Tikhonov        .pbt_packno_bits    = GQUIC_PACKNO_LEN_2,
10150aadb33SDmitri Tikhonov    },
10250aadb33SDmitri Tikhonov
10350aadb33SDmitri Tikhonov    {   .pbt_lineno         = __LINE__,
10450aadb33SDmitri Tikhonov        .pbt_packno         = 1 + (1 << 6),
10550aadb33SDmitri Tikhonov        .pbt_least_unacked  = 1,
10650aadb33SDmitri Tikhonov        .pbt_n_in_flight    = 0,
107c7d81ce1SDmitri Tikhonov        .pbt_packno_bits    = GQUIC_PACKNO_LEN_1,
10850aadb33SDmitri Tikhonov    },
10950aadb33SDmitri Tikhonov
11050aadb33SDmitri Tikhonov    {   .pbt_lineno         = __LINE__,
11150aadb33SDmitri Tikhonov        .pbt_packno         = 1 + (1 << 6) + 1,
11250aadb33SDmitri Tikhonov        .pbt_least_unacked  = 1,
11350aadb33SDmitri Tikhonov        .pbt_n_in_flight    = 0,
114c7d81ce1SDmitri Tikhonov        .pbt_packno_bits    = GQUIC_PACKNO_LEN_2,
11550aadb33SDmitri Tikhonov    },
11650aadb33SDmitri Tikhonov
11750aadb33SDmitri Tikhonov    {   .pbt_lineno         = __LINE__,
11850aadb33SDmitri Tikhonov        .pbt_packno         = (1 << 20) + (1 << 14),
11950aadb33SDmitri Tikhonov        .pbt_least_unacked  = 1 << 20,
12050aadb33SDmitri Tikhonov        .pbt_n_in_flight    = 0,
121c7d81ce1SDmitri Tikhonov        .pbt_packno_bits    = GQUIC_PACKNO_LEN_2,
12250aadb33SDmitri Tikhonov    },
12350aadb33SDmitri Tikhonov
12450aadb33SDmitri Tikhonov    {   .pbt_lineno         = __LINE__,
12550aadb33SDmitri Tikhonov        .pbt_packno         = (1 << 20) + (1 << 14) + 1,
12650aadb33SDmitri Tikhonov        .pbt_least_unacked  = 1 << 20,
12750aadb33SDmitri Tikhonov        .pbt_n_in_flight    = 0,
128c7d81ce1SDmitri Tikhonov        .pbt_packno_bits    = GQUIC_PACKNO_LEN_4,
12950aadb33SDmitri Tikhonov    },
13050aadb33SDmitri Tikhonov
13150aadb33SDmitri Tikhonov    {   .pbt_lineno         = __LINE__,
13250aadb33SDmitri Tikhonov        .pbt_packno         = (1 << 20) + (1ULL << 30),
13350aadb33SDmitri Tikhonov        .pbt_least_unacked  = 1 << 20,
13450aadb33SDmitri Tikhonov        .pbt_n_in_flight    = 0,
135c7d81ce1SDmitri Tikhonov        .pbt_packno_bits    = GQUIC_PACKNO_LEN_4,
13650aadb33SDmitri Tikhonov    },
13750aadb33SDmitri Tikhonov
13850aadb33SDmitri Tikhonov    {   .pbt_lineno         = __LINE__,
13950aadb33SDmitri Tikhonov        .pbt_packno         = (1 << 20) + (1ULL << 30) + 1,
14050aadb33SDmitri Tikhonov        .pbt_least_unacked  = 1 << 20,
14150aadb33SDmitri Tikhonov        .pbt_n_in_flight    = 0,
142c7d81ce1SDmitri Tikhonov        .pbt_packno_bits    = GQUIC_PACKNO_LEN_6,
14350aadb33SDmitri Tikhonov    },
14450aadb33SDmitri Tikhonov
14550aadb33SDmitri Tikhonov    /* Tests from Chrome: */
14650aadb33SDmitri Tikhonov    {   .pbt_lineno         = __LINE__,
14750aadb33SDmitri Tikhonov        .pbt_packno         = 65,
14850aadb33SDmitri Tikhonov        .pbt_least_unacked  = 2,
14950aadb33SDmitri Tikhonov        .pbt_n_in_flight    = 7,
150c7d81ce1SDmitri Tikhonov        .pbt_packno_bits    = GQUIC_PACKNO_LEN_1,
15150aadb33SDmitri Tikhonov    },
15250aadb33SDmitri Tikhonov
15350aadb33SDmitri Tikhonov    {   .pbt_lineno         = __LINE__,
15450aadb33SDmitri Tikhonov        .pbt_packno         = 64 * 256 - 1,
15550aadb33SDmitri Tikhonov        .pbt_least_unacked  = 2,
15650aadb33SDmitri Tikhonov        .pbt_n_in_flight    = 7,
157c7d81ce1SDmitri Tikhonov        .pbt_packno_bits    = GQUIC_PACKNO_LEN_2,
15850aadb33SDmitri Tikhonov    },
15950aadb33SDmitri Tikhonov
16050aadb33SDmitri Tikhonov    {   .pbt_lineno         = __LINE__,
16150aadb33SDmitri Tikhonov        .pbt_packno         = 64 * 256 * 256 - 1,
16250aadb33SDmitri Tikhonov        .pbt_least_unacked  = 2,
16350aadb33SDmitri Tikhonov        .pbt_n_in_flight    = 7,
164c7d81ce1SDmitri Tikhonov        .pbt_packno_bits    = GQUIC_PACKNO_LEN_4,
16550aadb33SDmitri Tikhonov    },
16650aadb33SDmitri Tikhonov
16750aadb33SDmitri Tikhonov    {   .pbt_lineno         = __LINE__,
16850aadb33SDmitri Tikhonov        .pbt_packno         = 64ULL * 256 * 256 * 256 * 256 - 1,
16950aadb33SDmitri Tikhonov        .pbt_least_unacked  = 2,
17050aadb33SDmitri Tikhonov        .pbt_n_in_flight    = 7,
171c7d81ce1SDmitri Tikhonov        .pbt_packno_bits    = GQUIC_PACKNO_LEN_6,
17250aadb33SDmitri Tikhonov    },
17350aadb33SDmitri Tikhonov
17450aadb33SDmitri Tikhonov    {   .pbt_lineno         = __LINE__,
17550aadb33SDmitri Tikhonov        .pbt_packno         = 2,
17650aadb33SDmitri Tikhonov        .pbt_least_unacked  = 1,
17750aadb33SDmitri Tikhonov        .pbt_n_in_flight    = 7,
178c7d81ce1SDmitri Tikhonov        .pbt_packno_bits    = GQUIC_PACKNO_LEN_1,
17950aadb33SDmitri Tikhonov    },
18050aadb33SDmitri Tikhonov
18150aadb33SDmitri Tikhonov    {   .pbt_lineno         = __LINE__,
18250aadb33SDmitri Tikhonov        .pbt_packno         = 2,
18350aadb33SDmitri Tikhonov        .pbt_least_unacked  = 1,
18450aadb33SDmitri Tikhonov        .pbt_n_in_flight    = 1896,
185c7d81ce1SDmitri Tikhonov        .pbt_packno_bits    = GQUIC_PACKNO_LEN_2,
18650aadb33SDmitri Tikhonov    },
18750aadb33SDmitri Tikhonov
18850aadb33SDmitri Tikhonov    {   .pbt_lineno         = __LINE__,
18950aadb33SDmitri Tikhonov        .pbt_packno         = 2,
19050aadb33SDmitri Tikhonov        .pbt_least_unacked  = 1,
19150aadb33SDmitri Tikhonov        .pbt_n_in_flight    = 48545,
192c7d81ce1SDmitri Tikhonov        .pbt_packno_bits    = GQUIC_PACKNO_LEN_4,
19350aadb33SDmitri Tikhonov    },
19450aadb33SDmitri Tikhonov
19550aadb33SDmitri Tikhonov    {   .pbt_lineno         = __LINE__,
19650aadb33SDmitri Tikhonov        .pbt_packno         = 2,
19750aadb33SDmitri Tikhonov        .pbt_least_unacked  = 1,
198e0197994SDmitri Tikhonov        .pbt_n_in_flight    = 3181457256ULL,
199c7d81ce1SDmitri Tikhonov        .pbt_packno_bits    = GQUIC_PACKNO_LEN_6,
20050aadb33SDmitri Tikhonov    },
20150aadb33SDmitri Tikhonov
20250aadb33SDmitri Tikhonov};
20350aadb33SDmitri Tikhonov
20450aadb33SDmitri Tikhonov
20550aadb33SDmitri Tikhonovstatic void
20650aadb33SDmitri Tikhonovrun_pbt (int i)
20750aadb33SDmitri Tikhonov{
2085392f7a3SLiteSpeed Tech    const struct parse_funcs *pf = select_pf_by_ver(LSQVER_043);
20950aadb33SDmitri Tikhonov    const struct packno_bits_test *const pbt = &pb_tests[i];
210c7d81ce1SDmitri Tikhonov    enum packno_bits packno_bits = pf->pf_calc_packno_bits(pbt->pbt_packno,
21150aadb33SDmitri Tikhonov                                pbt->pbt_least_unacked, pbt->pbt_n_in_flight);
21250aadb33SDmitri Tikhonov    assert(packno_bits == pbt->pbt_packno_bits);
213c7d81ce1SDmitri Tikhonov    unsigned packet_len = pf->pf_packno_bits2len(packno_bits);
21450aadb33SDmitri Tikhonov    /* Now see if we can restore it back: */
21550aadb33SDmitri Tikhonov    lsquic_packno_t cur_packno = pbt->pbt_packno &
216c7d81ce1SDmitri Tikhonov                        ((1ULL << (packet_len << 3)) - 1);
217a5fa05f9SDmitri Tikhonov    lsquic_packno_t orig_packno = lsquic_restore_packno(cur_packno, packet_len,
21850aadb33SDmitri Tikhonov                                                    pbt->pbt_least_unacked);
21950aadb33SDmitri Tikhonov    assert(orig_packno == pbt->pbt_packno);
22050aadb33SDmitri Tikhonov}
22150aadb33SDmitri Tikhonov
22250aadb33SDmitri Tikhonov
223a5fa05f9SDmitri Tikhonovstruct lsquic_restore_packno_test {
22450aadb33SDmitri Tikhonov    int                         rpt_lineno;
22550aadb33SDmitri Tikhonov    /* Input */
226c7d81ce1SDmitri Tikhonov    enum packno_bits     rpt_packno_bits;
22750aadb33SDmitri Tikhonov    lsquic_packno_t             rpt_cur_packno;
22850aadb33SDmitri Tikhonov    lsquic_packno_t             rpt_max_packno;
22950aadb33SDmitri Tikhonov    /* Output */
23050aadb33SDmitri Tikhonov    lsquic_packno_t             rpt_orig_packno;
23150aadb33SDmitri Tikhonov};
23250aadb33SDmitri Tikhonov
233a5fa05f9SDmitri Tikhonovstatic const struct lsquic_restore_packno_test rp_tests[] =
23450aadb33SDmitri Tikhonov{
23550aadb33SDmitri Tikhonov
23650aadb33SDmitri Tikhonov    {   .rpt_lineno         = __LINE__,
23750aadb33SDmitri Tikhonov        .rpt_max_packno     = 0,
23850aadb33SDmitri Tikhonov        .rpt_cur_packno     = 1,
239c7d81ce1SDmitri Tikhonov        .rpt_packno_bits    = GQUIC_PACKNO_LEN_1,
24050aadb33SDmitri Tikhonov        .rpt_orig_packno    = 1,
24150aadb33SDmitri Tikhonov    },
24250aadb33SDmitri Tikhonov
24350aadb33SDmitri Tikhonov};
24450aadb33SDmitri Tikhonov
24550aadb33SDmitri Tikhonov
24650aadb33SDmitri Tikhonovstatic void
24750aadb33SDmitri Tikhonovrun_rpt (int i)
24850aadb33SDmitri Tikhonov{
249a5fa05f9SDmitri Tikhonov    const struct lsquic_restore_packno_test *const rpt = &rp_tests[i];
250c7d81ce1SDmitri Tikhonov    unsigned packet_len = pf->pf_packno_bits2len(rpt->rpt_packno_bits);
251a5fa05f9SDmitri Tikhonov    lsquic_packno_t orig_packno = lsquic_restore_packno(rpt->rpt_cur_packno,
252c7d81ce1SDmitri Tikhonov                            packet_len, rpt->rpt_max_packno);
25350aadb33SDmitri Tikhonov    assert(orig_packno == rpt->rpt_orig_packno);
25450aadb33SDmitri Tikhonov}
25550aadb33SDmitri Tikhonov
25650aadb33SDmitri Tikhonov
25750aadb33SDmitri Tikhonovstatic void
258c7d81ce1SDmitri Tikhonovtest_restore (enum packno_bits bits)
25950aadb33SDmitri Tikhonov{
26050aadb33SDmitri Tikhonov    unsigned len, n;
26150aadb33SDmitri Tikhonov    enum { OP_PLUS, OP_MINUS, N_OPS } op;
26250aadb33SDmitri Tikhonov    uint64_t epoch, epoch_delta;
263b93f59beSBob Perper    lsquic_packno_t orig_packno, cur_packno, restored_packno;
26450aadb33SDmitri Tikhonov
265b93f59beSBob Perper#ifdef WIN32
266b93f59beSBob Perper    orig_packno = 0;
267b93f59beSBob Perper#endif
268c7d81ce1SDmitri Tikhonov    len = pf->pf_packno_bits2len(bits);
26950aadb33SDmitri Tikhonov    epoch_delta = 1ULL << (len << 3);
27050aadb33SDmitri Tikhonov    epoch = epoch_delta * 11 /* Just some number */;
27150aadb33SDmitri Tikhonov
27250aadb33SDmitri Tikhonov    /* Test current epoch: */
27350aadb33SDmitri Tikhonov    for (op = 0; op < N_OPS; ++op)
27450aadb33SDmitri Tikhonov        for (n = 0; n < 5; ++n)
27550aadb33SDmitri Tikhonov        {
27650aadb33SDmitri Tikhonov            /* Test at the ends of the epoch */
27750aadb33SDmitri Tikhonov            if (op == OP_MINUS)
27850aadb33SDmitri Tikhonov                orig_packno = epoch - epoch_delta / 2 + n;
27950aadb33SDmitri Tikhonov            else if (op == OP_PLUS)
28050aadb33SDmitri Tikhonov                orig_packno = epoch + epoch_delta / 2 - n - 1;
28150aadb33SDmitri Tikhonov            else
28250aadb33SDmitri Tikhonov                assert(0);
28350aadb33SDmitri Tikhonov            cur_packno = orig_packno & (epoch_delta - 1);
284a5fa05f9SDmitri Tikhonov            restored_packno = lsquic_restore_packno(cur_packno, len, epoch);
28550aadb33SDmitri Tikhonov            assert(orig_packno == restored_packno);
28650aadb33SDmitri Tikhonov            /* Test in the middle of the epoch */
28750aadb33SDmitri Tikhonov            if (op == OP_MINUS)
28850aadb33SDmitri Tikhonov                orig_packno = epoch - n;
28950aadb33SDmitri Tikhonov            else
29050aadb33SDmitri Tikhonov                orig_packno = epoch + n;
29150aadb33SDmitri Tikhonov            cur_packno = orig_packno & (epoch_delta - 1);
292a5fa05f9SDmitri Tikhonov            restored_packno = lsquic_restore_packno(cur_packno, len, epoch);
29350aadb33SDmitri Tikhonov            assert(orig_packno == restored_packno);
29450aadb33SDmitri Tikhonov        }
29550aadb33SDmitri Tikhonov
29650aadb33SDmitri Tikhonov    /* Test previous epoch (max is to the left) */
29750aadb33SDmitri Tikhonov    for (n = 0; n < 5; ++n)
29850aadb33SDmitri Tikhonov    {
29950aadb33SDmitri Tikhonov        /* Test at the end of the epoch */
30050aadb33SDmitri Tikhonov        orig_packno = epoch + epoch_delta / 2 - n - 1;
30150aadb33SDmitri Tikhonov        cur_packno = orig_packno & (epoch_delta - 1);
302a5fa05f9SDmitri Tikhonov        restored_packno = lsquic_restore_packno(cur_packno, len, epoch - epoch_delta * 3 / 4);
30350aadb33SDmitri Tikhonov        assert(orig_packno == restored_packno + epoch_delta);
30450aadb33SDmitri Tikhonov        /* Test in the middle of the epoch */
30550aadb33SDmitri Tikhonov        orig_packno = epoch + 2 - n;
30650aadb33SDmitri Tikhonov        cur_packno = orig_packno & (epoch_delta - 1);
307a5fa05f9SDmitri Tikhonov        restored_packno = lsquic_restore_packno(cur_packno, len, epoch - epoch_delta * 3 / 4);
30850aadb33SDmitri Tikhonov        assert(orig_packno == restored_packno + epoch_delta);
30950aadb33SDmitri Tikhonov    }
31050aadb33SDmitri Tikhonov
31150aadb33SDmitri Tikhonov    /* Test previous epoch (max is to the right) */
31250aadb33SDmitri Tikhonov    for (n = 0; n < 5; ++n)
31350aadb33SDmitri Tikhonov    {
31450aadb33SDmitri Tikhonov        /* Test at the end of the epoch */
31550aadb33SDmitri Tikhonov        orig_packno = epoch - epoch_delta / 2 + n;
31650aadb33SDmitri Tikhonov        cur_packno = orig_packno & (epoch_delta - 1);
317a5fa05f9SDmitri Tikhonov        restored_packno = lsquic_restore_packno(cur_packno, len, epoch + epoch_delta * 3 / 4);
31850aadb33SDmitri Tikhonov        assert(orig_packno == restored_packno - epoch_delta);
31950aadb33SDmitri Tikhonov        /* Test in the middle of the epoch */
32050aadb33SDmitri Tikhonov        orig_packno = epoch + 2 - n;
32150aadb33SDmitri Tikhonov        cur_packno = orig_packno & (epoch_delta - 1);
322a5fa05f9SDmitri Tikhonov        restored_packno = lsquic_restore_packno(cur_packno, len, epoch + epoch_delta * 3 / 4);
32350aadb33SDmitri Tikhonov        assert(orig_packno == restored_packno - epoch_delta);
32450aadb33SDmitri Tikhonov    }
32550aadb33SDmitri Tikhonov
32650aadb33SDmitri Tikhonov}
32750aadb33SDmitri Tikhonov
32850aadb33SDmitri Tikhonov
32950aadb33SDmitri Tikhonovint
33050aadb33SDmitri Tikhonovmain (void)
33150aadb33SDmitri Tikhonov{
33250aadb33SDmitri Tikhonov    unsigned i;
33350aadb33SDmitri Tikhonov    for (i = 0; i < sizeof(pb_tests) / sizeof(pb_tests[0]); ++i)
33450aadb33SDmitri Tikhonov        run_pbt(i);
33550aadb33SDmitri Tikhonov    for (i = 0; i < sizeof(rp_tests) / sizeof(rp_tests[0]); ++i)
33650aadb33SDmitri Tikhonov        run_rpt(i);
337c7d81ce1SDmitri Tikhonov    test_restore(GQUIC_PACKNO_LEN_1);
338c7d81ce1SDmitri Tikhonov    test_restore(GQUIC_PACKNO_LEN_2);
339c7d81ce1SDmitri Tikhonov    test_restore(GQUIC_PACKNO_LEN_4);
340c7d81ce1SDmitri Tikhonov    test_restore(GQUIC_PACKNO_LEN_6);
34150aadb33SDmitri Tikhonov    return 0;
34250aadb33SDmitri Tikhonov}
343