mirror of
https://gitea.invidious.io/iv-org/litespeed-quic.git
synced 2024-08-15 00:53:43 +00:00
16a9b66aaa
- [OPTIMIZATION] Merge series of ACKs if possible Parsed single-range ACK frames (that is the majority of frames) are saved in the connection and their processing is deferred until the connection is ticked. If several ACKs come in a series between adjacent ticks, we check whether the latest ACK is a strict superset of the saved ACK. If it is, the older ACK is not processed. If ACK frames can be merged, they are merged and only one of them is either processed or saved. - [OPTIMIZATION] Speed up ACK verification by simplifying send history. Never generate a gap in the sent packet number sequence. This reduces the send history to a single number instead of potentially a series of packet ranges and thereby speeds up ACK verification. By default, detecting a gap in the send history is not fatal: only a single warning is generated per connection. The connection can continue to operate even if the ACK verification code is not able to detect some inconsistencies. - [OPTIMIZATION] Rearrange the lsquic_send_ctl struct The first part of struct lsquic_send_ctl now consists of members that are used in lsquic_send_ctl_got_ack() (in the absense of packet loss, which is the normal case). To speed up reads and writes, we no longer try to save space by using 8- and 16-bit integers. Use regular integer width for everything. - [OPTIMIZATION] Cache size of sent packet. - [OPTIMIZATION] Keep track of the largest ACKed in packet_out Instead of parsing our own ACK frames when packet has been acked, use the value saved in the packet_out structure when the ACK frame was generated. - [OPTIMIZATION] Take RTT sampling conditional out of ACK loop - [OPTIMIZATION] ACK processing: only call clock_gettime() if needed - [OPTIMIZATION] Several code-level optimizations to ACK processing. - Fix: http_client: fix -I flag; switch assert() to abort()
359 lines
13 KiB
C
359 lines
13 KiB
C
/* Copyright (c) 2017 LiteSpeed Technologies Inc. See LICENSE. */
|
|
/*
|
|
* Test how ACK frame is encoded. Receive history module is tested by a
|
|
* separate unit test.
|
|
*/
|
|
|
|
#include <assert.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "lsquic_types.h"
|
|
#include "lsquic_int_types.h"
|
|
#include "lsquic_rechist.h"
|
|
#include "lsquic_parse.h"
|
|
#include "lsquic_util.h"
|
|
#include "lsquic_logger.h"
|
|
#include "lsquic.h"
|
|
|
|
static const struct parse_funcs *const pf = select_pf_by_ver(LSQVER_041);
|
|
|
|
static void
|
|
test1 (void) /* Inverse of quic_framer_test.cc -- NewAckFrameOneAckBlock */
|
|
{
|
|
lsquic_rechist_t rechist;
|
|
lsquic_time_t now = lsquic_time_now();
|
|
lsquic_packno_t largest = 0;
|
|
|
|
lsquic_rechist_init(&rechist, 0);
|
|
|
|
unsigned i;
|
|
for (i = 1; i <= 0x1234; ++i)
|
|
(void) lsquic_rechist_received(&rechist, i, now);
|
|
|
|
const unsigned char expected_ack_frame[] = {
|
|
/* TYPE N LL MM */
|
|
0xA0 | 0 << 4 | 1 << 2 | 1,
|
|
0x00, /* Number of timestamps */
|
|
0x12, 0x34, /* Largest acked */
|
|
0x87, 0xFF, /* Zero delta time */
|
|
0x12, 0x34, /* first ack block length */
|
|
};
|
|
unsigned char outbuf[0x100];
|
|
|
|
int has_missing = -1;
|
|
int w = pf->pf_gen_ack_frame(outbuf, sizeof(outbuf),
|
|
(gaf_rechist_first_f) lsquic_rechist_first,
|
|
(gaf_rechist_next_f) lsquic_rechist_next,
|
|
(gaf_rechist_largest_recv_f) lsquic_rechist_largest_recv,
|
|
&rechist, now + 0x7FF8000, &has_missing, &largest);
|
|
assert(("ACK frame generation successful", w > 0));
|
|
assert(("ACK frame length is correct", w == sizeof(expected_ack_frame)));
|
|
assert(("ACK frame contents are as expected",
|
|
0 == memcmp(outbuf, expected_ack_frame, sizeof(expected_ack_frame))));
|
|
assert(("ACK frame has no missing packets", has_missing == 0));
|
|
assert(largest == 0x1234);
|
|
|
|
lsquic_rechist_cleanup(&rechist);
|
|
}
|
|
|
|
static void
|
|
test2 (void) /* Inverse of quic_framer_test.cc -- NewAckFrameOneAckBlock, minus
|
|
* delta times.
|
|
*/
|
|
{
|
|
lsquic_rechist_t rechist;
|
|
lsquic_time_t now = lsquic_time_now();
|
|
|
|
lsquic_rechist_init(&rechist, 0);
|
|
|
|
/* Encode the following ranges:
|
|
* high low
|
|
* 0x1234 0x1234
|
|
* 0x1232 0x384
|
|
* 0x1F3 0xA
|
|
* 0x4 0x1
|
|
*/
|
|
unsigned i;
|
|
for (i = 4; i >= 1; --i)
|
|
(void) lsquic_rechist_received(&rechist, i, now);
|
|
(void) lsquic_rechist_received(&rechist, 0x1234, now);
|
|
for (i = 0xA; i <= 0x1F3; ++i)
|
|
(void) lsquic_rechist_received(&rechist, i, now);
|
|
for (i = 0x1232; i >= 0x384; --i)
|
|
(void) lsquic_rechist_received(&rechist, i, now);
|
|
|
|
const unsigned char expected_ack_frame[] = {
|
|
/* TYPE N LL MM */
|
|
0xA0 | 1 << 4 | 1 << 2 | 1,
|
|
0x04, /* Num ack blocks ranges. */
|
|
0x00, /* Number of timestamps. */
|
|
0x12, 0x34, /* Largest acked */
|
|
0x00, 0x00, /* Zero delta time. */
|
|
0x00, 0x01, /* First ack block length. */
|
|
0x01, /* Gap to next block. */
|
|
0x0e, 0xaf, /* Ack block length. */
|
|
0xff, /* Gap to next block. */
|
|
0x00, 0x00, /* Ack block length. */
|
|
0x91, /* Gap to next block. */
|
|
0x01, 0xea, /* Ack block length. */
|
|
0x05, /* Gap to next block. */
|
|
0x00, 0x04, /* Ack block length. */
|
|
};
|
|
unsigned char outbuf[0x100];
|
|
|
|
int has_missing = -1;
|
|
lsquic_packno_t largest = 0;
|
|
int w = pf->pf_gen_ack_frame(outbuf, sizeof(outbuf),
|
|
(gaf_rechist_first_f) lsquic_rechist_first,
|
|
(gaf_rechist_next_f) lsquic_rechist_next,
|
|
(gaf_rechist_largest_recv_f) lsquic_rechist_largest_recv,
|
|
&rechist, now, &has_missing, &largest);
|
|
assert(("ACK frame generation successful", w > 0));
|
|
assert(("ACK frame length is correct", w == sizeof(expected_ack_frame)));
|
|
assert(("ACK frame contents are as expected",
|
|
0 == memcmp(outbuf, expected_ack_frame, sizeof(expected_ack_frame))));
|
|
assert(("ACK frame has missing packets", has_missing > 0));
|
|
assert(largest == 0x1234);
|
|
|
|
lsquic_rechist_cleanup(&rechist);
|
|
}
|
|
|
|
static void
|
|
test3 (void)
|
|
{
|
|
lsquic_rechist_t rechist;
|
|
lsquic_time_t now = lsquic_time_now();
|
|
|
|
lsquic_rechist_init(&rechist, 0);
|
|
|
|
/* Encode the following ranges:
|
|
* high low
|
|
* 3 3
|
|
* 1 1
|
|
*/
|
|
(void) lsquic_rechist_received(&rechist, 1, now);
|
|
(void) lsquic_rechist_received(&rechist, 3, now);
|
|
|
|
const unsigned char expected_ack_frame[] = {
|
|
/* TYPE N LL MM */
|
|
0xA0 | 1 << 4 | 0 << 2 | 0,
|
|
0x01, /* Num ack blocks ranges. */
|
|
0x00, /* Number of timestamps. */
|
|
0x03,
|
|
0x00, 0x00, /* Zero delta time. */
|
|
0x01, /* First ack block length. */
|
|
0x01, /* Gap to next block. */
|
|
0x01, /* Ack block length. */
|
|
};
|
|
unsigned char outbuf[0x100];
|
|
|
|
int has_missing = -1;
|
|
lsquic_packno_t largest = 0;
|
|
int w = pf->pf_gen_ack_frame(outbuf, sizeof(outbuf),
|
|
(gaf_rechist_first_f) lsquic_rechist_first,
|
|
(gaf_rechist_next_f) lsquic_rechist_next,
|
|
(gaf_rechist_largest_recv_f) lsquic_rechist_largest_recv,
|
|
&rechist, now, &has_missing, &largest);
|
|
assert(("ACK frame generation successful", w > 0));
|
|
assert(("ACK frame length is correct", w == sizeof(expected_ack_frame)));
|
|
assert(("ACK frame contents are as expected",
|
|
0 == memcmp(outbuf, expected_ack_frame, sizeof(expected_ack_frame))));
|
|
assert(("ACK frame has missing packets", has_missing > 0));
|
|
assert(largest == 0x03);
|
|
|
|
lsquic_rechist_cleanup(&rechist);
|
|
}
|
|
|
|
|
|
static void
|
|
test4 (void)
|
|
{
|
|
lsquic_rechist_t rechist;
|
|
int i;
|
|
|
|
lsquic_rechist_init(&rechist, 0);
|
|
|
|
lsquic_time_t now = lsquic_time_now();
|
|
lsquic_rechist_received(&rechist, 1, now);
|
|
|
|
{
|
|
const unsigned char expected_ack_frame[] = {
|
|
/* TYPE N LL MM */
|
|
0xA0 | 0 << 4 | 0 << 2 | 0,
|
|
0x00, /* Number of timestamps */
|
|
0x01, /* Largest acked */
|
|
0x00, 0x00, /* Delta time */
|
|
0x01, /* Block length */
|
|
};
|
|
unsigned char outbuf[0x100];
|
|
int has_missing = -1;
|
|
lsquic_packno_t largest = 0;
|
|
int w = pf->pf_gen_ack_frame(outbuf, sizeof(outbuf),
|
|
(gaf_rechist_first_f) lsquic_rechist_first,
|
|
(gaf_rechist_next_f) lsquic_rechist_next,
|
|
(gaf_rechist_largest_recv_f) lsquic_rechist_largest_recv,
|
|
&rechist, now, &has_missing, &largest);
|
|
assert(("ACK frame generation successful", w > 0));
|
|
assert(("ACK frame length is correct", w == sizeof(expected_ack_frame)));
|
|
assert(("ACK frame contents are as expected",
|
|
0 == memcmp(outbuf, expected_ack_frame, sizeof(expected_ack_frame))));
|
|
assert(("ACK frame has no missing packets", has_missing == 0));
|
|
assert(largest == 1);
|
|
}
|
|
|
|
for (i = 3; i <= 5; ++i)
|
|
lsquic_rechist_received(&rechist, i, now);
|
|
|
|
{
|
|
const unsigned char expected_ack_frame[] = {
|
|
/* TYPE N LL MM */
|
|
0xA0 | 1 << 4 | 0 << 2 | 0,
|
|
0x01, /* Num ack blocks */
|
|
0x00, /* Number of timestamps */
|
|
0x05, /* Largest acked */
|
|
0x00, 0x00, /* Delta time */
|
|
0x03, /* First block length [3, 5] */
|
|
0x01, /* Gap to next block */
|
|
0x01, /* Second block length [1, 1] */
|
|
};
|
|
unsigned char outbuf[0x100];
|
|
int has_missing = -1;
|
|
lsquic_packno_t largest = 0;
|
|
int w = pf->pf_gen_ack_frame(outbuf, sizeof(outbuf),
|
|
(gaf_rechist_first_f) lsquic_rechist_first,
|
|
(gaf_rechist_next_f) lsquic_rechist_next,
|
|
(gaf_rechist_largest_recv_f) lsquic_rechist_largest_recv,
|
|
&rechist, now, &has_missing, &largest);
|
|
assert(("ACK frame generation successful", w > 0));
|
|
assert(("ACK frame length is correct", w == sizeof(expected_ack_frame)));
|
|
assert(("ACK frame contents are as expected",
|
|
0 == memcmp(outbuf, expected_ack_frame, sizeof(expected_ack_frame))));
|
|
assert(("ACK frame has missing packets", has_missing > 0));
|
|
assert(largest == 5);
|
|
}
|
|
|
|
lsquic_rechist_cleanup(&rechist);
|
|
}
|
|
|
|
|
|
static void
|
|
test_4byte_packnos (void)
|
|
{
|
|
lsquic_packno_t packno;
|
|
lsquic_rechist_t rechist;
|
|
struct packet_interval *pint;
|
|
lsquic_time_t now = lsquic_time_now();
|
|
|
|
lsquic_rechist_init(&rechist, 0);
|
|
|
|
packno = 0x23456789;
|
|
(void) lsquic_rechist_received(&rechist, packno - 33, now);
|
|
pint = TAILQ_FIRST(&rechist.rh_pints.pk_intervals);
|
|
(void) lsquic_rechist_received(&rechist, packno, now);
|
|
|
|
/* Adjust: */
|
|
pint->range.low = 1;
|
|
|
|
const unsigned char expected_ack_frame[] = {
|
|
/* TYPE N LL MM */
|
|
0xA0 | 1 << 4 | 2 << 2 | 2,
|
|
0x01, /* Num ack blocks ranges. */
|
|
0x00, /* Number of timestamps. */
|
|
0x23, 0x45, 0x67, 0x89,
|
|
0x00, 0x00, /* Zero delta time. */
|
|
0x00, 0x00, 0x00, 0x01, /* First ack block length. */
|
|
33 - 1, /* Gap to next block. */
|
|
0x23, 0x45, 0x67, 0x68, /* Ack block length. */
|
|
};
|
|
unsigned char outbuf[0x100];
|
|
|
|
int has_missing = -1;
|
|
lsquic_packno_t largest = 0;
|
|
int w = pf->pf_gen_ack_frame(outbuf, sizeof(outbuf),
|
|
(gaf_rechist_first_f) lsquic_rechist_first,
|
|
(gaf_rechist_next_f) lsquic_rechist_next,
|
|
(gaf_rechist_largest_recv_f) lsquic_rechist_largest_recv,
|
|
&rechist, now, &has_missing, &largest);
|
|
assert(("ACK frame generation successful", w > 0));
|
|
assert(("ACK frame length is correct", w == sizeof(expected_ack_frame)));
|
|
assert(("ACK frame contents are as expected",
|
|
0 == memcmp(outbuf, expected_ack_frame, sizeof(expected_ack_frame))));
|
|
assert(("ACK frame has missing packets", has_missing > 0));
|
|
assert(largest == 0x23456789);
|
|
|
|
lsquic_rechist_cleanup(&rechist);
|
|
}
|
|
|
|
|
|
static void
|
|
test_8byte_packnos (void)
|
|
{
|
|
lsquic_packno_t packno;
|
|
lsquic_rechist_t rechist;
|
|
struct packet_interval *pint;
|
|
lsquic_time_t now = lsquic_time_now();
|
|
|
|
lsquic_rechist_init(&rechist, 0);
|
|
|
|
packno = 0xABCD23456789;
|
|
(void) lsquic_rechist_received(&rechist, packno - 33, now);
|
|
pint = TAILQ_FIRST(&rechist.rh_pints.pk_intervals);
|
|
(void) lsquic_rechist_received(&rechist, packno, now);
|
|
|
|
/* Adjust: */
|
|
pint->range.low = 1;
|
|
|
|
const unsigned char expected_ack_frame[] = {
|
|
/* TYPE N LL MM */
|
|
0xA0 | 1 << 4 | 3 << 2 | 3,
|
|
0x01, /* Num ack blocks ranges. */
|
|
0x00, /* Number of timestamps. */
|
|
0x00, 0x00, 0xAB, 0xCD, 0x23, 0x45, 0x67, 0x89,
|
|
0x00, 0x00, /* Zero delta time. */
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* First ack block length. */
|
|
33 - 1, /* Gap to next block. */
|
|
0x00, 0x00, 0xAB, 0xCD, 0x23, 0x45, 0x67, 0x68, /* Ack block length. */
|
|
};
|
|
unsigned char outbuf[0x100];
|
|
|
|
int has_missing = -1;
|
|
lsquic_packno_t largest = 0;
|
|
int w = pf->pf_gen_ack_frame(outbuf, sizeof(outbuf),
|
|
(gaf_rechist_first_f) lsquic_rechist_first,
|
|
(gaf_rechist_next_f) lsquic_rechist_next,
|
|
(gaf_rechist_largest_recv_f) lsquic_rechist_largest_recv,
|
|
&rechist, now, &has_missing, &largest);
|
|
assert(("ACK frame generation successful", w > 0));
|
|
assert(("ACK frame length is correct", w == sizeof(expected_ack_frame)));
|
|
assert(("ACK frame contents are as expected",
|
|
0 == memcmp(outbuf, expected_ack_frame, sizeof(expected_ack_frame))));
|
|
assert(("ACK frame has missing packets", has_missing > 0));
|
|
assert(largest == 0xABCD23456789ULL);
|
|
|
|
lsquic_rechist_cleanup(&rechist);
|
|
}
|
|
|
|
|
|
int
|
|
main (void)
|
|
{
|
|
lsquic_global_init(LSQUIC_GLOBAL_SERVER);
|
|
lsquic_log_to_fstream(stderr, 0);
|
|
lsq_log_levels[LSQLM_PARSE] = LSQ_LOG_DEBUG;
|
|
|
|
test1();
|
|
|
|
test2();
|
|
|
|
test3();
|
|
|
|
test4();
|
|
|
|
test_4byte_packnos();
|
|
|
|
test_8byte_packnos();
|
|
|
|
return 0;
|
|
}
|