Skip to content

Commit

Permalink
Merge pull request #549
Browse files Browse the repository at this point in the history
quicly_stats: count packets received out of order
  • Loading branch information
kazuho committed Feb 19, 2023
2 parents d96bf50 + ec4da46 commit 05d20c7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
4 changes: 4 additions & 0 deletions include/quicly.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,10 @@ struct st_quicly_conn_streamgroup_state_t {
* Total number of Initial and Handshake packets sent. \
*/ \
uint64_t initial_handshake_sent; \
/** \
* Total number of packets received out of order. \
*/ \
uint64_t received_out_of_order; \
} num_packets; \
struct { \
/** \
Expand Down
11 changes: 8 additions & 3 deletions lib/quicly.c
Original file line number Diff line number Diff line change
Expand Up @@ -1426,12 +1426,15 @@ static int record_pn(quicly_ranges_t *ranges, uint64_t pn, int *is_out_of_order)
return 0;
}

static int record_receipt(struct st_quicly_pn_space_t *space, uint64_t pn, int is_ack_only, int64_t now, int64_t *send_ack_at)
static int record_receipt(struct st_quicly_pn_space_t *space, uint64_t pn, int is_ack_only, int64_t now, int64_t *send_ack_at,
uint64_t *received_out_of_order)
{
int ret, ack_now, is_out_of_order;

if ((ret = record_pn(&space->ack_queue, pn, &is_out_of_order)) != 0)
goto Exit;
if (is_out_of_order)
*received_out_of_order += 1;

ack_now = is_out_of_order && !space->ignore_order && !is_ack_only;

Expand Down Expand Up @@ -6108,7 +6111,8 @@ int quicly_accept(quicly_conn_t **conn, quicly_context_t *ctx, struct sockaddr *
(*conn)->super.stats.num_bytes.received += packet->datagram_size;
if ((ret = handle_payload(*conn, QUICLY_EPOCH_INITIAL, payload.base, payload.len, &offending_frame_type, &is_ack_only)) != 0)
goto Exit;
if ((ret = record_receipt(&(*conn)->initial->super, pn, 0, (*conn)->stash.now, &(*conn)->egress.send_ack_at)) != 0)
if ((ret = record_receipt(&(*conn)->initial->super, pn, 0, (*conn)->stash.now, &(*conn)->egress.send_ack_at,
&(*conn)->super.stats.num_packets.received_out_of_order)) != 0)
goto Exit;

Exit:
Expand Down Expand Up @@ -6345,7 +6349,8 @@ int quicly_receive(quicly_conn_t *conn, struct sockaddr *dest_addr, struct socka
if ((ret = handle_payload(conn, epoch, payload.base, payload.len, &offending_frame_type, &is_ack_only)) != 0)
goto Exit;
if (*space != NULL && conn->super.state < QUICLY_STATE_CLOSING) {
if ((ret = record_receipt(*space, pn, is_ack_only, conn->stash.now, &conn->egress.send_ack_at)) != 0)
if ((ret = record_receipt(*space, pn, is_ack_only, conn->stash.now, &conn->egress.send_ack_at,
&conn->super.stats.num_packets.received_out_of_order)) != 0)
goto Exit;
}

Expand Down
22 changes: 11 additions & 11 deletions t/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,20 +515,20 @@ static void do_test_record_receipt(size_t epoch)
{
struct st_quicly_pn_space_t *space =
alloc_pn_space(sizeof(*space), epoch == QUICLY_EPOCH_1RTT ? QUICLY_DEFAULT_PACKET_TOLERANCE : 1);
uint64_t pn = 0;
uint64_t pn = 0, out_of_order_cnt = 0;
int64_t now = 12345, send_ack_at = INT64_MAX;

if (epoch == QUICLY_EPOCH_1RTT) {
/* 2nd packet triggers an ack */
ok(record_receipt(space, pn++, 0, now, &send_ack_at) == 0);
ok(record_receipt(space, pn++, 0, now, &send_ack_at, &out_of_order_cnt) == 0);
ok(send_ack_at == now + QUICLY_DELAYED_ACK_TIMEOUT);
now += 1;
ok(record_receipt(space, pn++, 0, now, &send_ack_at) == 0);
ok(record_receipt(space, pn++, 0, now, &send_ack_at, &out_of_order_cnt) == 0);
ok(send_ack_at == now);
now += 1;
} else {
/* every packet triggers an ack */
ok(record_receipt(space, pn++, 0, now, &send_ack_at) == 0);
ok(record_receipt(space, pn++, 0, now, &send_ack_at, &out_of_order_cnt) == 0);
ok(send_ack_at == now);
now += 1;
}
Expand All @@ -538,23 +538,23 @@ static void do_test_record_receipt(size_t epoch)
send_ack_at = INT64_MAX;

/* ack-only packets do not elicit an ack */
ok(record_receipt(space, pn++, 1, now, &send_ack_at) == 0);
ok(record_receipt(space, pn++, 1, now, &send_ack_at, &out_of_order_cnt) == 0);
ok(send_ack_at == INT64_MAX);
now += 1;
ok(record_receipt(space, pn++, 1, now, &send_ack_at) == 0);
ok(record_receipt(space, pn++, 1, now, &send_ack_at, &out_of_order_cnt) == 0);
ok(send_ack_at == INT64_MAX);
now += 1;
pn++; /* gap */
ok(record_receipt(space, pn++, 1, now, &send_ack_at) == 0);
ok(record_receipt(space, pn++, 1, now, &send_ack_at, &out_of_order_cnt) == 0);
ok(send_ack_at == INT64_MAX);
now += 1;
ok(record_receipt(space, pn++, 1, now, &send_ack_at) == 0);
ok(record_receipt(space, pn++, 1, now, &send_ack_at, &out_of_order_cnt) == 0);
ok(send_ack_at == INT64_MAX);
now += 1;

/* gap triggers an ack */
pn += 1; /* gap */
ok(record_receipt(space, pn++, 0, now, &send_ack_at) == 0);
ok(record_receipt(space, pn++, 0, now, &send_ack_at, &out_of_order_cnt) == 0);
ok(send_ack_at == now);
now += 1;

Expand All @@ -566,10 +566,10 @@ static void do_test_record_receipt(size_t epoch)
if (epoch == QUICLY_EPOCH_1RTT) {
space->ignore_order = 1;
pn++; /* gap */
ok(record_receipt(space, pn++, 0, now, &send_ack_at) == 0);
ok(record_receipt(space, pn++, 0, now, &send_ack_at, &out_of_order_cnt) == 0);
ok(send_ack_at == now + QUICLY_DELAYED_ACK_TIMEOUT);
now += 1;
ok(record_receipt(space, pn++, 0, now, &send_ack_at) == 0);
ok(record_receipt(space, pn++, 0, now, &send_ack_at, &out_of_order_cnt) == 0);
ok(send_ack_at == now);
now += 1;
}
Expand Down

0 comments on commit 05d20c7

Please sign in to comment.