From 68e87a0180ad4d6e9a3f6aa005f1b1d69849da4a Mon Sep 17 00:00:00 2001 From: Kazuho Oku Date: Tue, 16 Jul 2024 18:47:22 +0900 Subject: [PATCH 1/2] record # of packets sent / received per epoch; 1rtt can be calculated by subtracting others from all --- include/quicly.h | 24 ++++++++++++++++++++++-- lib/quicly.c | 31 +++++++++++++++++++++++++------ 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/include/quicly.h b/include/quicly.h index 22fc55a0..11beb391 100644 --- a/include/quicly.h +++ b/include/quicly.h @@ -486,9 +486,29 @@ struct st_quicly_conn_streamgroup_state_t { */ \ uint64_t late_acked; \ /** \ - * Total number of Initial and Handshake packets sent. \ + * Total number of Initial packets received. \ */ \ - uint64_t initial_handshake_sent; \ + uint64_t initial_received; \ + /** \ + * Total number of 0-RTT packets received. \ + */ \ + uint64_t zero_rtt_received; \ + /** \ + * Total number of Handshake packets received. \ + */ \ + uint64_t handshake_received; \ + /** \ + * Total number of Initial packets sent. \ + */ \ + uint64_t initial_sent; \ + /** \ + * Total number of 0-RTT packets sent. \ + */ \ + uint64_t zero_rtt_sent; \ + /** \ + * Total number of Handshake packets sent. \ + */ \ + uint64_t handshake_sent; \ /** \ * Total number of packets received out of order. \ */ \ diff --git a/lib/quicly.c b/lib/quicly.c index 5d1ffa80..74f1ed9a 100644 --- a/lib/quicly.c +++ b/lib/quicly.c @@ -3642,8 +3642,13 @@ static int commit_send_packet(quicly_conn_t *conn, quicly_send_context_t *s, int quicly_encode16(s->dst_payload_from - QUICLY_SEND_PN_SIZE - 2, length); switch (*s->target.first_byte_at & QUICLY_PACKET_TYPE_BITMASK) { case QUICLY_PACKET_TYPE_INITIAL: + conn->super.stats.num_packets.initial_sent++; + break; + case QUICLY_PACKET_TYPE_0RTT: + conn->super.stats.num_packets.zero_rtt_sent++; + break; case QUICLY_PACKET_TYPE_HANDSHAKE: - conn->super.stats.num_packets.initial_handshake_sent++; + conn->super.stats.num_packets.handshake_sent++; break; } } else { @@ -5208,10 +5213,10 @@ static int do_send(quicly_conn_t *conn, quicly_send_context_t *s) conn->super.stats.num_handshake_timeouts++; goto CloseNow; } - if (conn->super.stats.num_packets.initial_handshake_sent > conn->super.ctx->max_initial_handshake_packets) { - QUICLY_PROBE(INITIAL_HANDSHAKE_PACKET_EXCEED, conn, conn->stash.now, conn->super.stats.num_packets.initial_handshake_sent); - QUICLY_LOG_CONN(initial_handshake_packet_exceed, conn, - { PTLS_LOG_ELEMENT_UNSIGNED(num_packets, conn->super.stats.num_packets.initial_handshake_sent); }); + uint64_t initial_handshake_sent = conn->super.stats.num_packets.initial_sent + conn->super.stats.num_packets.handshake_sent; + if (initial_handshake_sent > conn->super.ctx->max_initial_handshake_packets) { + QUICLY_PROBE(INITIAL_HANDSHAKE_PACKET_EXCEED, conn, conn->stash.now, initial_handshake_sent); + QUICLY_LOG_CONN(initial_handshake_packet_exceed, conn, { PTLS_LOG_ELEMENT_UNSIGNED(num_packets, initial_handshake_sent); }); conn->super.stats.num_initial_handshake_exceeded++; goto CloseNow; } @@ -6911,6 +6916,7 @@ int quicly_accept(quicly_conn_t **conn, quicly_context_t *ctx, struct sockaddr * /* handle the input; we ignore is_ack_only, we consult if there's any output from TLS in response to CH anyways */ (*conn)->super.stats.num_packets.received += 1; + (*conn)->super.stats.num_packets.initial_received += 1; if (packet->ecn != 0) (*conn)->super.stats.num_packets.received_ecn_counts[get_ecn_index_from_bits(packet->ecn)] += 1; (*conn)->super.stats.num_bytes.received += packet->datagram_size; @@ -7157,7 +7163,20 @@ int quicly_receive(quicly_conn_t *conn, struct sockaddr *dest_addr, struct socka conn->super.stats.num_packets.received += 1; conn->paths[path_index]->packet_last_received = conn->super.stats.num_packets.received; conn->paths[path_index]->num_packets.received += 1; - if (packet->ecn != 0) + if (QUICLY_PACKET_IS_LONG_HEADER(packet->octets.base[0])) { + switch (packet->octets.base[0] & QUICLY_PACKET_TYPE_BITMASK) { + case QUICLY_PACKET_TYPE_INITIAL: + conn->super.stats.num_packets.initial_received += 1; + break; + case QUICLY_PACKET_TYPE_0RTT: + conn->super.stats.num_packets.zero_rtt_received += 1; + break; + case QUICLY_PACKET_TYPE_HANDSHAKE: + conn->super.stats.num_packets.handshake_received += 1; + break; + } + } + if (packet->ecn != 0) conn->super.stats.num_packets.received_ecn_counts[get_ecn_index_from_bits(packet->ecn)] += 1; /* state updates, that are triggered by the receipt of a packet */ From eb42571443ff7f9a0981098d5a2c8e5b5c8d25dd Mon Sep 17 00:00:00 2001 From: Kazuho Oku Date: Tue, 16 Jul 2024 19:13:35 +0900 Subject: [PATCH 2/2] [cli] report sent / received packets per epoch --- src/cli.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/cli.c b/src/cli.c index 7c835c98..b9e4ebed 100644 --- a/src/cli.c +++ b/src/cli.c @@ -147,8 +147,10 @@ static void dump_stats(FILE *fp, quicly_conn_t *conn) quicly_get_stats(conn, &stats); fprintf(fp, - "packets-received: %" PRIu64 ", received-ecn-ect0: %" PRIu64 ", received-ecn-ect1: %" PRIu64 + "packets-received: %" PRIu64 ", initial-packets-received: %" PRIu64 ", 0rtt-packets-received: %" PRIu64 + ", handshake-packets-received: %" PRIu64 ", received-ecn-ect0: %" PRIu64 ", received-ecn-ect1: %" PRIu64 ", received-ecn-ce: %" PRIu64 ", packets-decryption-failed: %" PRIu64 ", packets-sent: %" PRIu64 + ", initial-packets-sent: %" PRIu64 ", 0rtt-packets-sent: %" PRIu64 ", handshake-packets-sent: %" PRIu64 ", packets-lost: %" PRIu64 ", ack-received: %" PRIu64 ", ack-ecn-ect0: %" PRIu64 ", ack-ecn-ect1: %" PRIu64 ", ack-ecn-ce: %" PRIu64 ", late-acked: %" PRIu64 ", bytes-received: %" PRIu64 ", bytes-sent: %" PRIu64 ", paths-created %" PRIu64 ", paths-validated %" PRIu64 ", paths-promoted: %" PRIu64 ", srtt: %" PRIu32 @@ -156,15 +158,17 @@ static void dump_stats(FILE *fp, quicly_conn_t *conn) ", cwnd-exiting-slow-start: %" PRIu32 ", slow-start-exit-at: %" PRId64 ", jumpstart-cwnd: %" PRIu32 ", jumpstart-exit: %" PRIu32 ", jumpstart-prev-rate: %" PRIu64 ", jumpstart-prev-rtt: %" PRIu32 ", token-sent-rate: %" PRIu64 ", token-sent-rtt: %" PRIu32 "\n", - stats.num_packets.received, stats.num_packets.received_ecn_counts[0], stats.num_packets.received_ecn_counts[1], - stats.num_packets.received_ecn_counts[2], stats.num_packets.decryption_failed, stats.num_packets.sent, - stats.num_packets.lost, stats.num_packets.ack_received, stats.num_packets.acked_ecn_counts[0], - stats.num_packets.acked_ecn_counts[1], stats.num_packets.acked_ecn_counts[2], stats.num_packets.late_acked, - stats.num_bytes.received, stats.num_bytes.sent, stats.num_paths.created, stats.num_paths.validated, - stats.num_paths.promoted, stats.rtt.smoothed, stats.cc.num_loss_episodes, stats.cc.num_ecn_loss_episodes, - stats.delivery_rate.smoothed, stats.cc.cwnd, stats.cc.cwnd_exiting_slow_start, stats.cc.exit_slow_start_at, - stats.jumpstart.cwnd, stats.cc.cwnd_exiting_jumpstart, stats.jumpstart.prev_rate, stats.jumpstart.prev_rtt, - stats.token_sent.rate, stats.token_sent.rtt); + stats.num_packets.received, stats.num_packets.initial_received, stats.num_packets.zero_rtt_received, + stats.num_packets.handshake_received, stats.num_packets.received_ecn_counts[0], + stats.num_packets.received_ecn_counts[1], stats.num_packets.received_ecn_counts[2], stats.num_packets.decryption_failed, + stats.num_packets.sent, stats.num_packets.initial_sent, stats.num_packets.zero_rtt_sent, + stats.num_packets.handshake_sent, stats.num_packets.lost, stats.num_packets.ack_received, + stats.num_packets.acked_ecn_counts[0], stats.num_packets.acked_ecn_counts[1], stats.num_packets.acked_ecn_counts[2], + stats.num_packets.late_acked, stats.num_bytes.received, stats.num_bytes.sent, stats.num_paths.created, + stats.num_paths.validated, stats.num_paths.promoted, stats.rtt.smoothed, stats.cc.num_loss_episodes, + stats.cc.num_ecn_loss_episodes, stats.delivery_rate.smoothed, stats.cc.cwnd, stats.cc.cwnd_exiting_slow_start, + stats.cc.exit_slow_start_at, stats.jumpstart.cwnd, stats.cc.cwnd_exiting_jumpstart, stats.jumpstart.prev_rate, + stats.jumpstart.prev_rtt, stats.token_sent.rate, stats.token_sent.rtt); } static int validate_path(const char *path)