litespeed-quic/tests/test_ackgen_gquic_be.c

390 lines
13 KiB
C
Raw Normal View History

2022-05-06 16:49:46 +00:00
/* Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc. See LICENSE. */
2017-09-22 21:00:03 +00:00
/*
* 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>
2020-06-03 04:13:30 +00:00
#ifdef WIN32
#include "vc_compat.h"
#endif
2017-09-22 21:00:03 +00:00
#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_043); // will not work on MSVC
#define pf ((const struct parse_funcs *const)select_pf_by_ver(LSQVER_043))
2017-09-22 21:00:03 +00:00
static void
test1 (void) /* Inverse of quic_framer_test.cc -- NewAckFrameOneAckBlock */
{
lsquic_rechist_t rechist;
lsquic_time_t now = lsquic_time_now();
Latest changes - [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()
2018-03-09 19:17:39 +00:00
lsquic_packno_t largest = 0;
2017-09-22 21:00:03 +00:00
lsquic_rechist_init(&rechist, 0, 0);
2017-09-22 21:00:03 +00:00
unsigned i;
for (i = 1; i <= 0x1234; ++i)
(void) lsquic_rechist_received(&rechist, i, now);
const unsigned char expected_ack_frame[] = {
0x45,
0x12, 0x34, /* Largest acked */
0x87, 0xFF, /* Delta time */
0x12, 0x34, /* Block length */
0x00, /* Number of timestamps */
};
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, NULL);
2017-09-22 21:00:03 +00:00
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));
Latest changes - [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()
2018-03-09 19:17:39 +00:00
assert(largest == 0x1234);
2017-09-22 21:00:03 +00:00
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, 0);
2017-09-22 21:00:03 +00:00
/* 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[] = {
0x65,
0x12, 0x34, /* Largest acked */
0x00, 0x00, /* Zero delta time. */
0x04, /* Num ack blocks ranges. */
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. */
0x00, /* Number of timestamps. */
};
unsigned char outbuf[0x100];
int has_missing = -1;
Latest changes - [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()
2018-03-09 19:17:39 +00:00
lsquic_packno_t largest = 0;
2017-09-22 21:00:03 +00:00
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, NULL);
2017-09-22 21:00:03 +00:00
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));
Latest changes - [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()
2018-03-09 19:17:39 +00:00
assert(largest == 0x1234);
2017-09-22 21:00:03 +00:00
lsquic_rechist_cleanup(&rechist);
}
static void
test3 (void)
{
lsquic_rechist_t rechist;
lsquic_time_t now = lsquic_time_now();
lsquic_rechist_init(&rechist, 0, 0);
2017-09-22 21:00:03 +00:00
/* 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[] = {
0x60,
0x03,
0x00, 0x00, /* Zero delta time. */
0x01, /* Num ack blocks ranges. */
0x01, /* First ack block length. */
0x01, /* Gap to next block. */
0x01, /* Ack block length. */
0x00, /* Number of timestamps. */
};
unsigned char outbuf[0x100];
int has_missing = -1;
Latest changes - [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()
2018-03-09 19:17:39 +00:00
lsquic_packno_t largest = 0;
2017-09-22 21:00:03 +00:00
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, NULL);
2017-09-22 21:00:03 +00:00
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));
Latest changes - [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()
2018-03-09 19:17:39 +00:00
assert(largest == 0x03);
2017-09-22 21:00:03 +00:00
lsquic_rechist_cleanup(&rechist);
}
static void
test4 (void)
{
lsquic_rechist_t rechist;
int i;
lsquic_rechist_init(&rechist, 0, 0);
2017-09-22 21:00:03 +00:00
lsquic_time_t now = lsquic_time_now();
lsquic_rechist_received(&rechist, 1, now);
{
const unsigned char expected_ack_frame[] = {
0x40,
0x01, /* Largest acked */
0x00, 0x00, /* Delta time */
0x01, /* Block length */
0x00, /* Number of timestamps */
};
unsigned char outbuf[0x100];
int has_missing = -1;
Latest changes - [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()
2018-03-09 19:17:39 +00:00
lsquic_packno_t largest = 0;
2017-09-22 21:00:03 +00:00
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, NULL);
2017-09-22 21:00:03 +00:00
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));
Latest changes - [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()
2018-03-09 19:17:39 +00:00
assert(largest == 1);
2017-09-22 21:00:03 +00:00
}
for (i = 3; i <= 5; ++i)
lsquic_rechist_received(&rechist, i, now);
{
const unsigned char expected_ack_frame[] = {
0x60,
0x05, /* Largest acked */
0x00, 0x00, /* Delta time */
0x01, /* Num ack blocks */
0x03, /* First block length [3, 5] */
0x01, /* Gap to next block */
0x01, /* Second block length [1, 1] */
0x00, /* Number of timestamps */
};
unsigned char outbuf[0x100];
int has_missing = -1;
Latest changes - [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()
2018-03-09 19:17:39 +00:00
lsquic_packno_t largest = 0;
2017-09-22 21:00:03 +00:00
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, NULL);
2017-09-22 21:00:03 +00:00
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));
Latest changes - [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()
2018-03-09 19:17:39 +00:00
assert(largest == 5);
2017-09-22 21:00:03 +00:00
}
lsquic_rechist_cleanup(&rechist);
}
static void
test_4byte_packnos (void)
{
lsquic_packno_t packno;
lsquic_rechist_t rechist;
lsquic_time_t now = lsquic_time_now();
lsquic_rechist_init(&rechist, 0, 0);
2017-09-22 21:00:03 +00:00
packno = 0x23456789;
(void) lsquic_rechist_received(&rechist, packno - 33, now);
(void) lsquic_rechist_received(&rechist, packno, now);
/* Adjust: */
rechist.rh_elems[0].re_low = 1;
rechist.rh_elems[0].re_count = packno - 33;
2017-09-22 21:00:03 +00:00
const unsigned char expected_ack_frame[] = {
0x60
| (2 << 2) /* Four-byte largest acked */
| (2 << 0) /* Four-byte ACK block length */
,
0x23, 0x45, 0x67, 0x89,
0x00, 0x00, /* Zero delta time. */
0x01, /* Num ack blocks ranges. */
0x00, 0x00, 0x00, 0x01, /* First ack block length. */
33 - 1, /* Gap to next block. */
0x23, 0x45, 0x67, 0x68, /* Ack block length. */
0x00, /* Number of timestamps. */
};
unsigned char outbuf[0x100];
int has_missing = -1;
Latest changes - [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()
2018-03-09 19:17:39 +00:00
lsquic_packno_t largest = 0;
2017-09-22 21:00:03 +00:00
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, NULL);
2017-09-22 21:00:03 +00:00
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));
Latest changes - [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()
2018-03-09 19:17:39 +00:00
assert(largest == 0x23456789);
2017-09-22 21:00:03 +00:00
lsquic_rechist_cleanup(&rechist);
}
/* lsquic_rechist no longer supports ranges that require integers
* wider than four bytes -- modify the test to use a custom receive
* history.
*/
static const struct lsquic_packno_range test_6byte_ranges[] = {
{ .high = 0xABCD23456789, .low = 0xABCD23456789, },
{ .high = 0xABCD23456789 - 33, .low = 1, },
};
static const struct lsquic_packno_range *
test_6byte_rechist_first (void *rechist)
2017-09-22 21:00:03 +00:00
{
int *next = rechist;
*next = 1;
return &test_6byte_ranges[0];
};
2017-09-22 21:00:03 +00:00
static const struct lsquic_packno_range *
test_6byte_rechist_next (void *rechist)
{
int *next = rechist;
if (*next == 1)
{
++*next;
return &test_6byte_ranges[1];
}
else
return NULL;
}
2017-09-22 21:00:03 +00:00
static lsquic_time_t s_test_6byte_now;
static lsquic_time_t
test_6byte_rechist_largest_recv (void *rechist)
{
return s_test_6byte_now;
}
static void
test_6byte_packnos (void)
{
int rechist = 0;
s_test_6byte_now = lsquic_time_now();
2017-09-22 21:00:03 +00:00
const unsigned char expected_ack_frame[] = {
0x60
| (3 << 2) /* Six-byte largest acked */
| (3 << 0) /* Six-byte ACK block length */
,
0xAB, 0xCD, 0x23, 0x45, 0x67, 0x89,
0x00, 0x00, /* Zero delta time. */
0x01, /* Num ack blocks ranges. */
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* First ack block length. */
33 - 1, /* Gap to next block. */
0xAB, 0xCD, 0x23, 0x45, 0x67, 0x68, /* Ack block length. */
0x00, /* Number of timestamps. */
};
unsigned char outbuf[0x100];
int has_missing = -1;
Latest changes - [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()
2018-03-09 19:17:39 +00:00
lsquic_packno_t largest = 0;
2017-09-22 21:00:03 +00:00
int w = pf->pf_gen_ack_frame(outbuf, sizeof(outbuf),
test_6byte_rechist_first,
test_6byte_rechist_next,
test_6byte_rechist_largest_recv,
&rechist, s_test_6byte_now, &has_missing, &largest, NULL);
2017-09-22 21:00:03 +00:00
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));
Latest changes - [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()
2018-03-09 19:17:39 +00:00
assert(largest == 0xABCD23456789ULL);
2017-09-22 21:00:03 +00:00
}
int
main (void)
{
Latest changes - [API Change] Sendfile-like functionality is gone. The stream no longer opens files and deals with file descriptors. (Among other things, this makes the code more portable.) Three writing functions are provided: lsquic_stream_write lsquic_stream_writev lsquic_stream_writef (NEW) lsquic_stream_writef() is given an abstract reader that has function pointers for size() and read() functions which the user can implement. This is the most flexible way. lsquic_stream_write() and lsquic_stream_writev() are now both implemented as wrappers around lsquic_stream_writef(). - [OPTIMIZATION] When writing to stream, be it within or without the on_write() callback, place data directly into packet buffer, bypassing auxiliary data structures. This reduces amount of memory required, for the amount of data that can be written is limited by the congestion window. To support writes outside the on_write() callback, we keep N outgoing packet buffers per connection which can be written to by any stream. One half of these are reserved for the highest priority stream(s), the other half for all other streams. This way, low-priority streams cannot write instead of high-priority streams and, on the other hand, low-priority streams get a chance to send their packets out. The algorithm is as follows: - When user writes to stream outside of the callback: - If this is the highest priority stream, place it onto the reserved N/2 queue or fail. (The actual size of this queue is dynamic -- MAX(N/2, CWND) -- rather than N/2, allowing high-priority streams to write as much as can be sent.) - If the stream is not the highest priority, try to place the data onto the reserved N/2 queue or fail. - When tick occurs *and* more packets can be scheduled: - Transfer packets from the high N/2 queue to the scheduled queue. - If more scheduling is allowed: - Call on_write callbacks for highest-priority streams, placing resulting packets directly onto the scheduled queue. - If more scheduling is allowed: - Transfer packets from the low N/2 queue to the scheduled queue. - If more scheduling is allowed: - Call on_write callbacks for non-highest-priority streams, placing resulting packets directly onto the scheduled queue The number N is currently 20, but it could be varied based on resource usage. - If stream is created due to incoming headers, make headers readable from on_new. - Outgoing packets are no longer marked non-writeable to prevent placing more than one STREAM frame from the same stream into a single packet. This property is maintained via code flow and an explicit check. Packets for stream data are allocated using a special function. - STREAM frame elision is cheaper, as we only perform it if a reset stream has outgoing packets referencing it. - lsquic_packet_out_t is smaller, as stream_rec elements are now inside a union.
2017-10-31 13:35:58 +00:00
lsquic_global_init(LSQUIC_GLOBAL_SERVER);
2017-09-22 21:00:03 +00:00
lsquic_log_to_fstream(stderr, 0);
lsq_log_levels[LSQLM_PARSE] = LSQ_LOG_DEBUG;
test1();
test2();
test3();
test4();
test_4byte_packnos();
test_6byte_packnos();
return 0;
}