From db810bf8459e5d489cf4f4e378b271a62d3cbff2 Mon Sep 17 00:00:00 2001 From: Mike Bishop Date: Thu, 29 Oct 2020 11:03:09 -0400 Subject: [PATCH 1/7] Packet number encoding in appendix, move examples --- draft-ietf-quic-transport.md | 57 ++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/draft-ietf-quic-transport.md b/draft-ietf-quic-transport.md index b242445ee7..59eceab44a 100644 --- a/draft-ietf-quic-transport.md +++ b/draft-ietf-quic-transport.md @@ -4382,17 +4382,10 @@ the difference between the largest acknowledged packet and packet number being sent. A peer receiving the packet will then correctly decode the packet number, unless the packet is delayed in transit such that it arrives after many higher-numbered packets have been received. An endpoint SHOULD use a large -enough packet number encoding to allow the packet number to be recovered even -if the packet arrives after packets that are sent afterwards. - -As a result, the size of the packet number encoding is at least one bit more -than the base-2 logarithm of the number of contiguous unacknowledged packet -numbers, including the new packet. - -For example, if an endpoint has received an acknowledgment for packet 0xabe8bc, -sending a packet with a number of 0xac5c02 requires a packet number encoding -with 16 bits or more; whereas the 24-bit packet number encoding is needed to -send a packet with a number of 0xace8fe. +enough packet number encoding to allow the packet number to be recovered even if +the packet arrives after packets that are sent afterwards. Pseudo-code and +examples for packet number encoding can be found in +{{sample-packet-number-encoding}}. At a receiver, protection of the packet number is removed prior to recovering the full packet number. The full packet number is then reconstructed based on @@ -4402,10 +4395,8 @@ full packet number is necessary to successfully remove packet protection. Once header protection is removed, the packet number is decoded by finding the packet number value that is closest to the next expected packet. The next -expected packet is the highest received packet number plus one. For example, if -the highest successfully authenticated packet had a packet number of 0xa82f30ea, -then a packet containing a 16-bit value of 0x9b32 will be decoded as 0xa82f9b32. -Example pseudo-code for packet number decoding can be found in +expected packet is the highest received packet number plus one. Pseudo-code and +an example for packet number decoding can be found in {{sample-packet-number-decoding}}. @@ -7411,6 +7402,39 @@ The initial contents of this registry are shown in {{iana-error-table}}. --- back +# Sample Packet Number Encoding Algorithm {#sample-packet-number-encoding} + +The pseudo-code in {{alg-encode-pn}} shows how an implementation can select +an appropriate size for packet number encodings. + +The EncodePacketNumber function takes two arguments: + +* full_pn is the full packet number of the packet being sent. +* largest_acked is the largest packet number which has been acknowledged by the + recipient in the current packet number space, if any + +~~~ +EncodePacketNumber(full_pn, largest_acked): + // If no packets in the current space have been + // acknowledged, the full packet number is used. + if largest_acked is None: + return full_pn + + // The number of bits must be at least one more + // than the base-2 logarithm of the number of contiguous + // unacknowledged packet numbers, including the new packet. + num_unacked = full_pn - largest_acked + min_bits = log(num_unacked, 2) + 1 + num_bytes = ceil(min_bits / 8) + return full_pn[-num_bytes:] +~~~ +{: #alg-encode-pn title="Sample Packet Number Encoding Algorithm"} + +For example, if an endpoint has received an acknowledgment for packet 0xabe8bc, +sending a packet with a number of 0xac5c02 requires a packet number encoding +with 16 bits or more; whereas the 24-bit packet number encoding is needed to +send a packet with a number of 0xace8fe. + # Sample Packet Number Decoding Algorithm {#sample-packet-number-decoding} The pseudo-code in {{alg-decode-pn}} shows how an implementation can decode @@ -7444,6 +7468,9 @@ DecodePacketNumber(largest_pn, truncated_pn, pn_nbits): ~~~ {: #alg-decode-pn title="Sample Packet Number Decoding Algorithm"} +For example, if the highest successfully authenticated packet had a packet +number of 0xa82f30ea, then a packet containing a 16-bit value of 0x9b32 will be +decoded as 0xa82f9b32. # Sample ECN Validation Algorithm {#ecn-alg} From 4ff09667a1b7d1b218d5a97c4ee2115d7217311a Mon Sep 17 00:00:00 2001 From: Mike Bishop Date: Thu, 29 Oct 2020 11:17:09 -0400 Subject: [PATCH 2/7] Expand example --- draft-ietf-quic-transport.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/draft-ietf-quic-transport.md b/draft-ietf-quic-transport.md index 59eceab44a..bf4422318c 100644 --- a/draft-ietf-quic-transport.md +++ b/draft-ietf-quic-transport.md @@ -7430,10 +7430,14 @@ EncodePacketNumber(full_pn, largest_acked): ~~~ {: #alg-encode-pn title="Sample Packet Number Encoding Algorithm"} -For example, if an endpoint has received an acknowledgment for packet 0xabe8bc, -sending a packet with a number of 0xac5c02 requires a packet number encoding -with 16 bits or more; whereas the 24-bit packet number encoding is needed to -send a packet with a number of 0xace8fe. +For example, if an endpoint has received an acknowledgment for packet 0xabe8bc +and is sending a packet with a number of 0xac5c02, there are 29,519 (0x734f) +outstanding packets. In order to represent at least twice this range (59,038 +packets, or 0xe69e), 16 bits will be required. + +In the same state, sending a packet with a number of 0xace8fe uses the 24-bit +encoding, because at least 18 bits are required to represent twice the range +(131,182 packets, or 0x2006e). # Sample Packet Number Decoding Algorithm {#sample-packet-number-decoding} From 64c74e5dfac3eb87fb0068476811feb99eac8e30 Mon Sep 17 00:00:00 2001 From: Mike Bishop Date: Fri, 30 Oct 2020 10:44:51 -0400 Subject: [PATCH 3/7] Apply suggestions from code review Co-authored-by: Jana Iyengar Co-authored-by: Martin Thomson --- draft-ietf-quic-transport.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/draft-ietf-quic-transport.md b/draft-ietf-quic-transport.md index bf4422318c..b06eece756 100644 --- a/draft-ietf-quic-transport.md +++ b/draft-ietf-quic-transport.md @@ -7411,7 +7411,7 @@ The EncodePacketNumber function takes two arguments: * full_pn is the full packet number of the packet being sent. * largest_acked is the largest packet number which has been acknowledged by the - recipient in the current packet number space, if any + peer in the current packet number space, if any ~~~ EncodePacketNumber(full_pn, largest_acked): @@ -7433,7 +7433,7 @@ EncodePacketNumber(full_pn, largest_acked): For example, if an endpoint has received an acknowledgment for packet 0xabe8bc and is sending a packet with a number of 0xac5c02, there are 29,519 (0x734f) outstanding packets. In order to represent at least twice this range (59,038 -packets, or 0xe69e), 16 bits will be required. +packets, or 0xe69e), 16 bits are required. In the same state, sending a packet with a number of 0xace8fe uses the 24-bit encoding, because at least 18 bits are required to represent twice the range From 3bc25c1ff62913c7982966dcf259319fd4871324 Mon Sep 17 00:00:00 2001 From: Mike Bishop Date: Fri, 30 Oct 2020 10:48:28 -0400 Subject: [PATCH 4/7] Less python, more handwaving --- draft-ietf-quic-transport.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/draft-ietf-quic-transport.md b/draft-ietf-quic-transport.md index b06eece756..dc6eac0d16 100644 --- a/draft-ietf-quic-transport.md +++ b/draft-ietf-quic-transport.md @@ -7415,18 +7415,21 @@ The EncodePacketNumber function takes two arguments: ~~~ EncodePacketNumber(full_pn, largest_acked): - // If no packets in the current space have been - // acknowledged, the full packet number is used. - if largest_acked is None: - return full_pn // The number of bits must be at least one more // than the base-2 logarithm of the number of contiguous // unacknowledged packet numbers, including the new packet. - num_unacked = full_pn - largest_acked + if largest_acked is None: + num_unacked = full_pn + 1 + else: + num_unacked = full_pn - largest_acked + min_bits = log(num_unacked, 2) + 1 num_bytes = ceil(min_bits / 8) - return full_pn[-num_bytes:] + + // Return the value after truncating the full packet number + // to num_bytes least-significant bytes + return truncate(full_pn, num_bytes) ~~~ {: #alg-encode-pn title="Sample Packet Number Encoding Algorithm"} From 9608dc4f7ee751fd906876d76992dea6ef03b493 Mon Sep 17 00:00:00 2001 From: Martin Thomson Date: Sun, 1 Nov 2020 12:11:21 +1100 Subject: [PATCH 5/7] period Co-authored-by: ianswett --- draft-ietf-quic-transport.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/draft-ietf-quic-transport.md b/draft-ietf-quic-transport.md index dc6eac0d16..82f5bbbdc2 100644 --- a/draft-ietf-quic-transport.md +++ b/draft-ietf-quic-transport.md @@ -7411,7 +7411,7 @@ The EncodePacketNumber function takes two arguments: * full_pn is the full packet number of the packet being sent. * largest_acked is the largest packet number which has been acknowledged by the - peer in the current packet number space, if any + peer in the current packet number space, if any. ~~~ EncodePacketNumber(full_pn, largest_acked): From e2f4433901ab807d1412729d52ad2f830b33d625 Mon Sep 17 00:00:00 2001 From: Mike Bishop Date: Tue, 3 Nov 2020 18:21:20 -0500 Subject: [PATCH 6/7] Truncatencode Co-authored-by: Martin Thomson --- draft-ietf-quic-transport.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/draft-ietf-quic-transport.md b/draft-ietf-quic-transport.md index 82f5bbbdc2..1cf2cec3bc 100644 --- a/draft-ietf-quic-transport.md +++ b/draft-ietf-quic-transport.md @@ -7427,9 +7427,9 @@ EncodePacketNumber(full_pn, largest_acked): min_bits = log(num_unacked, 2) + 1 num_bytes = ceil(min_bits / 8) - // Return the value after truncating the full packet number - // to num_bytes least-significant bytes - return truncate(full_pn, num_bytes) + // Encode the integer value and truncate to the + // num_bytes least-significant bytes. + return encode(full_pn, num_bytes) ~~~ {: #alg-encode-pn title="Sample Packet Number Encoding Algorithm"} From 8cd6bc1e70dce9e0e089d50dcdca30a6c16ce4c7 Mon Sep 17 00:00:00 2001 From: Mike Bishop Date: Tue, 3 Nov 2020 18:27:34 -0500 Subject: [PATCH 7/7] Restore the comment in the original text --- draft-ietf-quic-transport.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/draft-ietf-quic-transport.md b/draft-ietf-quic-transport.md index 1cf2cec3bc..2b87807288 100644 --- a/draft-ietf-quic-transport.md +++ b/draft-ietf-quic-transport.md @@ -4383,9 +4383,12 @@ sent. A peer receiving the packet will then correctly decode the packet number, unless the packet is delayed in transit such that it arrives after many higher-numbered packets have been received. An endpoint SHOULD use a large enough packet number encoding to allow the packet number to be recovered even if -the packet arrives after packets that are sent afterwards. Pseudo-code and -examples for packet number encoding can be found in -{{sample-packet-number-encoding}}. +the packet arrives after packets that are sent afterwards. + +As a result, the size of the packet number encoding is at least one bit more +than the base-2 logarithm of the number of contiguous unacknowledged packet +numbers, including the new packet. Pseudo-code and examples for packet number +encoding can be found in {{sample-packet-number-encoding}}. At a receiver, protection of the packet number is removed prior to recovering the full packet number. The full packet number is then reconstructed based on @@ -7427,8 +7430,8 @@ EncodePacketNumber(full_pn, largest_acked): min_bits = log(num_unacked, 2) + 1 num_bytes = ceil(min_bits / 8) - // Encode the integer value and truncate to the - // num_bytes least-significant bytes. + // Encode the integer value and truncate to + // the num_bytes least-significant bytes. return encode(full_pn, num_bytes) ~~~ {: #alg-encode-pn title="Sample Packet Number Encoding Algorithm"}