Default enable MTU discovery in QUIC server. Protected by --gfe2_reloadable_flag_quic_enable_mtu_discovery_at_server.

PiperOrigin-RevId: 326728561
Change-Id: I1c054a439badecc47227fbc822e3241bac0bbf0f
diff --git a/quic/core/quic_connection.cc b/quic/core/quic_connection.cc
index b7c9bb4..99c7957 100644
--- a/quic/core/quic_connection.cc
+++ b/quic/core/quic_connection.cc
@@ -544,8 +544,10 @@
   }
   max_undecryptable_packets_ = config.max_undecryptable_packets();
 
-  if (config.HasClientRequestedIndependentOption(kMTUH, perspective_)) {
-    SetMtuDiscoveryTarget(kMtuDiscoveryTargetPacketSizeHigh);
+  if (!GetQuicReloadableFlag(quic_enable_mtu_discovery_at_server)) {
+    if (config.HasClientRequestedIndependentOption(kMTUH, perspective_)) {
+      SetMtuDiscoveryTarget(kMtuDiscoveryTargetPacketSizeHigh);
+    }
   }
   if (config.HasClientRequestedIndependentOption(kMTUL, perspective_)) {
     SetMtuDiscoveryTarget(kMtuDiscoveryTargetPacketSizeLow);
@@ -719,6 +721,12 @@
 
 void QuicConnection::OnConfigNegotiated() {
   sent_packet_manager_.OnConfigNegotiated();
+
+  if (GetQuicReloadableFlag(quic_enable_mtu_discovery_at_server) &&
+      perspective_ == Perspective::IS_SERVER) {
+    QUIC_RELOADABLE_FLAG_COUNT(quic_enable_mtu_discovery_at_server);
+    SetMtuDiscoveryTarget(kMtuDiscoveryTargetPacketSizeHigh);
+  }
 }
 
 QuicBandwidth QuicConnection::MaxPacingRate() const {
@@ -3992,6 +4000,11 @@
   return true;
 }
 
+void QuicConnection::DisableMtuDiscovery() {
+  mtu_discoverer_.Disable();
+  mtu_discovery_alarm_->Cancel();
+}
+
 void QuicConnection::DiscoverMtu() {
   DCHECK(!mtu_discovery_alarm_->IsSet());
 
diff --git a/quic/core/quic_connection.h b/quic/core/quic_connection.h
index e72fb2c..29c29a8 100644
--- a/quic/core/quic_connection.h
+++ b/quic/core/quic_connection.h
@@ -823,6 +823,9 @@
   virtual void SendConnectivityProbingResponsePacket(
       const QuicSocketAddress& peer_address);
 
+  // Disable MTU discovery on this connection.
+  void DisableMtuDiscovery();
+
   // Sends an MTU discovery packet and updates the MTU discovery alarm.
   void DiscoverMtu();
 
diff --git a/quic/core/quic_connection_test.cc b/quic/core/quic_connection_test.cc
index d80ca65..8c12920 100644
--- a/quic/core/quic_connection_test.cc
+++ b/quic/core/quic_connection_test.cc
@@ -864,12 +864,16 @@
   void EnablePathMtuDiscovery(MockSendAlgorithm* send_algorithm) {
     ASSERT_EQ(Perspective::IS_SERVER, perspective());
 
-    QuicConfig config;
-    QuicTagVector connection_options;
-    connection_options.push_back(kMTUH);
-    config.SetInitialReceivedConnectionOptions(connection_options);
-    EXPECT_CALL(*send_algorithm, SetFromConfig(_, _));
-    SetFromConfig(config);
+    if (GetQuicReloadableFlag(quic_enable_mtu_discovery_at_server)) {
+      OnConfigNegotiated();
+    } else {
+      QuicConfig config;
+      QuicTagVector connection_options;
+      connection_options.push_back(kMTUH);
+      config.SetInitialReceivedConnectionOptions(connection_options);
+      EXPECT_CALL(*send_algorithm, SetFromConfig(_, _));
+      SetFromConfig(config);
+    }
 
     // Normally, the pacing would be disabled in the test, but calling
     // SetFromConfig enables it.  Set nearly-infinite bandwidth to make the
diff --git a/quic/test_tools/simulator/quic_endpoint.cc b/quic/test_tools/simulator/quic_endpoint.cc
index aba7b46..0f04427 100644
--- a/quic/test_tools/simulator/quic_endpoint.cc
+++ b/quic/test_tools/simulator/quic_endpoint.cc
@@ -88,6 +88,7 @@
     }
   }
   connection_->SetFromConfig(config);
+  connection_->DisableMtuDiscovery();
 }
 
 QuicByteCount QuicEndpoint::bytes_received() const {