Skip to content

Commit

Permalink
added reordering threshold in ack frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurav2699 committed Nov 28, 2024
1 parent 434e533 commit d6cde24
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/core/ack_tracker.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ QuicAckTrackerAckPacket(
// 1. The packet included an IMMEDIATE_ACK frame.
// 2. ACK delay is disabled (MaxAckDelayMs == 0).
// 3. We have received 'PacketTolerance' ACK eliciting packets.
// 4. We received an ACK eliciting packet that doesn't directly follow the
// previously received packet number. So we assume there might have
// been loss and should indicate this info to the peer. This logic is
// disabled if 'IgnoreReordering' is TRUE.
// 4. We had received an ACK eliciting packet that is out of order and the
// gap between the smallest Unreported Missing packet and the Largest
// Unacked is greater than or equal to the Reordering Threshold value. This logic is
// disabled if 'IgnoreReordering' is TRUE or the Reordering Threshold is 0.
// 5. The delayed ACK timer fires after the configured time.
//
// If we don't queue an immediate ACK and this is the first ACK eliciting
Expand All @@ -196,11 +196,12 @@ QuicAckTrackerAckPacket(
Connection->Settings.MaxAckDelayMs == 0 ||
(Tracker->AckElicitingPacketsToAcknowledge >= (uint16_t)Connection->PacketTolerance) ||
(!Connection->State.IgnoreReordering &&
Connection->ReorderingThreshold > 0 &&
(NewLargestPacketNumber &&
QuicRangeSize(&Tracker->PacketNumbersToAck) > 1 && // There are more than two ranges, i.e. a gap somewhere.
QuicRangeGet(
&Tracker->PacketNumbersToAck,
QuicRangeSize(&Tracker->PacketNumbersToAck) - 1)->Count == 1))) { // The gap is right before the last packet number.
QuicRangeSize(&Tracker->PacketNumbersToAck) - 1)->Count == Connection->ReorderingThreshold))) {
//
// Send the ACK immediately.
//
Expand Down
7 changes: 7 additions & 0 deletions src/core/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ QuicConnAlloc(
Connection->AckDelayExponent = QUIC_ACK_DELAY_EXPONENT;
Connection->PacketTolerance = QUIC_MIN_ACK_SEND_NUMBER;
Connection->PeerPacketTolerance = QUIC_MIN_ACK_SEND_NUMBER;
Connection->ReorderingThreshold = QUIC_MIN_REORDERING_THRESHOLD;
Connection->PeerReorderingThreshold = QUIC_MIN_REORDERING_THRESHOLD;
Connection->PeerTransportParams.AckDelayExponent = QUIC_TP_ACK_DELAY_EXPONENT_DEFAULT;
Connection->ReceiveQueueTail = &Connection->ReceiveQueue;
QuicSettingsCopy(&Connection->Settings, &MsQuicLib.Settings);
Expand Down Expand Up @@ -5245,6 +5247,11 @@ QuicConnRecvFrames(
} else {
Connection->PacketTolerance = UINT8_MAX; // Cap to 0xFF for space savings.
}
if(Frame.ReorderingThreshold < UINT8_MAX) {
Connection->ReorderingThreshold = (uint8_t)Frame.ReorderingThreshold;
} else {
Connection->ReorderingThreshold = UINT8_MAX; // Cap to 0xFF for space savings.

Check warning on line 5253 in src/core/connection.c

View check run for this annotation

Codecov / codecov/patch

src/core/connection.c#L5253

Added line #L5253 was not covered by tests
}
QuicTraceLogConnInfo(
UpdatePacketTolerance,
Connection,
Expand Down
15 changes: 15 additions & 0 deletions src/core/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,21 @@ typedef struct QUIC_CONNECTION {
//
uint64_t NextRecvAckFreqSeqNum;

//
// The maximum number of packets that can be out of order before an immediate
// acknowledgment (ACK) is triggered. If no specific instructions (ACK_FREQUENCY
// frames) are received from the peer, the receiver will immediately acknowledge
// any out-of-order packets, which means the default value is 1. A value of 0
// means out-of-order packets do not trigger an immediate ACK.
//
uint8_t ReorderingThreshold;

//
// The maximum number of packets that the peer can be out of order before an immediate
// acknowledgment (ACK) is triggered.
//
uint8_t PeerReorderingThreshold;

//
// The sequence number to use for the next source CID.
//
Expand Down
8 changes: 6 additions & 2 deletions src/core/frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,7 @@ QuicAckFrequencyFrameEncode(
QuicVarIntSize(Frame->SequenceNumber) +
QuicVarIntSize(Frame->PacketTolerance) +
QuicVarIntSize(Frame->UpdateMaxAckDelay) +
QuicVarIntSize(Frame->ReorderingThreshold) +
sizeof(QUIC_ACK_FREQUENCY_EXTRAS);

if (BufferLength < *Offset + RequiredLength) {
Expand All @@ -1279,6 +1280,7 @@ QuicAckFrequencyFrameEncode(
Buffer = QuicVarIntEncode(Frame->SequenceNumber, Buffer);
Buffer = QuicVarIntEncode(Frame->PacketTolerance, Buffer);
Buffer = QuicVarIntEncode(Frame->UpdateMaxAckDelay, Buffer);
Buffer = QuicVarIntEncode(Frame->ReorderingThreshold, Buffer);
QuicUint8Encode(Extras.Value, Buffer);
*Offset += RequiredLength;

Expand All @@ -1299,6 +1301,7 @@ QuicAckFrequencyFrameDecode(
if (!QuicVarIntDecode(BufferLength, Buffer, Offset, &Frame->SequenceNumber) ||
!QuicVarIntDecode(BufferLength, Buffer, Offset, &Frame->PacketTolerance) ||
!QuicVarIntDecode(BufferLength, Buffer, Offset, &Frame->UpdateMaxAckDelay) ||
!QuicVarIntDecode(BufferLength, Buffer, Offset, &Frame->ReorderingThreshold) ||
!QuicUint8tDecode(BufferLength, Buffer, Offset, &Extras.Value)) {
return FALSE;
}
Expand Down Expand Up @@ -1963,13 +1966,14 @@ QuicFrameLog(

QuicTraceLogVerbose(
FrameLogAckFrequency,
"[%c][%cX][%llu] ACK_FREQUENCY SeqNum:%llu PktTolerance:%llu MaxAckDelay:%llu IgnoreOrder:%hhu IgnoreCE:%hhu",
"[%c][%cX][%llu] ACK_FREQUENCY SeqNum:%llu PktTolerance:%llu MaxAckDelay:%llu ReorderThreshold: %llu IgnoreOrder:%hhu IgnoreCE:%hhu",
PtkConnPre(Connection),
PktRxPre(Rx),
PacketNumber,
Frame.SequenceNumber,
Frame.PacketTolerance,
Frame.UpdateMaxAckDelay,
Frame.ReorderingThreshold,
Frame.IgnoreOrder,
Frame.IgnoreCE);
break;
Expand Down Expand Up @@ -2006,7 +2010,7 @@ QuicFrameLog(
Frame.Timestamp);
break;
}

case QUIC_FRAME_RELIABLE_RESET_STREAM: {
QUIC_RELIABLE_RESET_STREAM_EX Frame;
if (!QuicReliableResetFrameDecode(PacketLength, Packet, Offset, &Frame)) {
Expand Down
1 change: 1 addition & 0 deletions src/core/frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,7 @@ typedef struct QUIC_ACK_FREQUENCY_EX {
QUIC_VAR_INT SequenceNumber;
QUIC_VAR_INT PacketTolerance;
QUIC_VAR_INT UpdateMaxAckDelay; // In microseconds (us)
QUIC_VAR_INT ReorderingThreshold;
BOOLEAN IgnoreOrder;
BOOLEAN IgnoreCE;

Expand Down
6 changes: 6 additions & 0 deletions src/core/quicdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ typedef struct QUIC_RX_PACKET QUIC_RX_PACKET;
//
#define QUIC_MIN_ACK_SEND_NUMBER 2

//
// The value for Reordering threshold when no ACK_FREQUENCY frame is received.
// This means that the receiver will immediately acknowledge any out-of-order packets.
//
#define QUIC_MIN_REORDERING_THRESHOLD 1

//
// The size of the stateless reset token.
//
Expand Down
1 change: 1 addition & 0 deletions src/core/send.c
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,7 @@ QuicSendWriteFrames(
Frame.SequenceNumber = Connection->SendAckFreqSeqNum;
Frame.PacketTolerance = Connection->PeerPacketTolerance;
Frame.UpdateMaxAckDelay = MS_TO_US(QuicConnGetAckDelay(Connection));
Frame.ReorderingThreshold = Connection->PeerReorderingThreshold;
Frame.IgnoreOrder = FALSE;
Frame.IgnoreCE = FALSE;

Expand Down

0 comments on commit d6cde24

Please sign in to comment.