Add hardcoded peer reordering_threshold to QuicConfig.

Ian wants to do experiments in Chrome with a reordering_threshold set at the command line. There will be no way in Quiche to set this value, but there will be a Chrome feature to do so. This is the QUICHE part of that.

PiperOrigin-RevId: 795146325
diff --git a/quiche/quic/core/quic_config.h b/quiche/quic/core/quic_config.h
index 90974b0..443b88b 100644
--- a/quiche/quic/core/quic_config.h
+++ b/quiche/quic/core/quic_config.h
@@ -519,6 +519,13 @@
   bool HasReceivedRetrySourceConnectionId() const;
   QuicConnectionId ReceivedRetrySourceConnectionId() const;
 
+  uint64_t peer_reordering_threshold() const {
+    return peer_reordering_threshold_;
+  }
+  void set_peer_reordering_threshold(uint64_t peer_reordering_threshold) {
+    peer_reordering_threshold_ = peer_reordering_threshold;
+  }
+
   bool negotiated() const;
 
   void SetCreateSessionTagIndicators(QuicTagVector tags);
@@ -724,6 +731,10 @@
   // values means 'discard' data not received.
   int32_t discard_length_received_ = -1;
 
+  // A hardcoded value for reordering threshold, as if the peer had sent an
+  // ACK_FREQUENCY frame with that value.
+  uint64_t peer_reordering_threshold_ = 1;
+
   // Google internal handshake message.
   std::optional<std::string> google_handshake_message_to_send_;
   std::optional<std::string> received_google_handshake_message_;
diff --git a/quiche/quic/core/quic_connection.cc b/quiche/quic/core/quic_connection.cc
index 503252c..697b307 100644
--- a/quiche/quic/core/quic_connection.cc
+++ b/quiche/quic/core/quic_connection.cc
@@ -647,6 +647,14 @@
   }
 
   framer_.set_process_reset_stream_at(config.SupportsReliableStreamReset());
+
+  if (config.peer_reordering_threshold() != 1 &&
+      perspective_ == Perspective::IS_CLIENT && version().UsesTls() &&
+      !config.HasMinAckDelayDraft10ToSend()) {
+    QuicAckFrequencyFrame frame;
+    frame.reordering_threshold = config.peer_reordering_threshold();
+    uber_received_packet_manager_.OnAckFrequencyFrame(frame);
+  }
 }
 
 void QuicConnection::AddDispatcherSentPackets(
diff --git a/quiche/quic/core/quic_connection_test.cc b/quiche/quic/core/quic_connection_test.cc
index 7204be6..050c249 100644
--- a/quiche/quic/core/quic_connection_test.cc
+++ b/quiche/quic/core/quic_connection_test.cc
@@ -18059,6 +18059,20 @@
   EXPECT_TRUE(QuicConnectionPeer::CanReceiveAckFrequencyFrames(&connection_));
 }
 
+TEST_P(QuicConnectionTest, ConfigHardCodedPeerReorderingThreshold) {
+  if (!version().UsesTls()) {
+    return;
+  }
+  QuicConfig config;
+  EXPECT_EQ(QuicConnectionPeer::GetPeerReorderingThreshold(&connection_), 1);
+  config.set_peer_reordering_threshold(10);
+  EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
+  EXPECT_CALL(*send_algorithm_, EnableECT1()).WillOnce(Return(false));
+  EXPECT_CALL(*send_algorithm_, EnableECT0()).WillOnce(Return(false));
+  connection_.SetFromConfig(config);
+  EXPECT_EQ(QuicConnectionPeer::GetPeerReorderingThreshold(&connection_), 10);
+}
+
 // Regression test for b/424538505.
 TEST_P(QuicConnectionTest, LeastUnackedOffByOne) {
   QuicPacketNumber largest_packet_sent;
diff --git a/quiche/quic/test_tools/quic_connection_peer.cc b/quiche/quic/test_tools/quic_connection_peer.cc
index c0d713a..8e51697 100644
--- a/quiche/quic/test_tools/quic_connection_peer.cc
+++ b/quiche/quic/test_tools/quic_connection_peer.cc
@@ -4,6 +4,7 @@
 
 #include "quiche/quic/test_tools/quic_connection_peer.h"
 
+#include <cstdint>
 #include <memory>
 #include <string>
 
@@ -13,6 +14,7 @@
 #include "quiche/quic/core/quic_connection_alarms.h"
 #include "quiche/quic/core/quic_packet_writer.h"
 #include "quiche/quic/core/quic_received_packet_manager.h"
+#include "quiche/quic/core/quic_types.h"
 #include "quiche/quic/platform/api/quic_flags.h"
 #include "quiche/quic/platform/api/quic_socket_address.h"
 #include "quiche/quic/test_tools/quic_connection_id_manager_peer.h"
@@ -614,5 +616,18 @@
       .num_ptos_for_retransmittable_on_wire_timeout_;
 }
 
+// static
+uint64_t QuicConnectionPeer::GetPeerReorderingThreshold(
+    QuicConnection* connection) {
+  if (!connection->version().UsesTls()) {
+    return connection->uber_received_packet_manager_
+        .received_packet_managers_[0]
+        .reordering_threshold_;
+  }
+  return connection->uber_received_packet_manager_
+      .received_packet_managers_[APPLICATION_DATA]
+      .reordering_threshold_;
+}
+
 }  // namespace test
 }  // namespace quic
diff --git a/quiche/quic/test_tools/quic_connection_peer.h b/quiche/quic/test_tools/quic_connection_peer.h
index c1477a8..2b284fa 100644
--- a/quiche/quic/test_tools/quic_connection_peer.h
+++ b/quiche/quic/test_tools/quic_connection_peer.h
@@ -256,6 +256,8 @@
 
   static uint8_t GetNumPtosForRetransmittableOnWireTimeout(
       const QuicConnection* connection);
+
+  static uint64_t GetPeerReorderingThreshold(QuicConnection* connection);
 };
 
 }  // namespace test