Increase QUIC BBRv2 inflight_hi by bytes_delevered instead of inflight_at_send.  Enabled by B2DL.

Protected by -quic_reloadable_flag_quic_bbr2_use_bytes_delivered.

PiperOrigin-RevId: 343922245
Change-Id: I308eb74f1bcc3c5e3e67cce00beb440516243393
diff --git a/quic/core/congestion_control/bbr2_misc.h b/quic/core/congestion_control/bbr2_misc.h
index 1109e08..0b65f9d 100644
--- a/quic/core/congestion_control/bbr2_misc.h
+++ b/quic/core/congestion_control/bbr2_misc.h
@@ -189,6 +189,9 @@
 
   // Can be enabled by connection option 'B2SL'.
   bool startup_loss_exit_use_max_delivered_for_inflight_hi = false;
+
+  // Can be enabled by connection option 'B2DL'.
+  bool use_bytes_delivered_for_inflight_hi = false;
 };
 
 class QUIC_EXPORT_PRIVATE RoundTripCounter {
diff --git a/quic/core/congestion_control/bbr2_probe_bw.cc b/quic/core/congestion_control/bbr2_probe_bw.cc
index e91339f..f76b5f4 100644
--- a/quic/core/congestion_control/bbr2_probe_bw.cc
+++ b/quic/core/congestion_control/bbr2_probe_bw.cc
@@ -195,14 +195,28 @@
     return NOT_ADAPTED_INVALID_SAMPLE;
   }
 
+  // TODO(ianswett): Rename to bytes_delivered if
+  // use_bytes_delivered_for_inflight_hi is default enabled.
+  QuicByteCount inflight_at_send = BytesInFlight(send_state);
+  if (Params().use_bytes_delivered_for_inflight_hi) {
+    if (congestion_event.last_packet_send_state.total_bytes_acked <=
+        model_->total_bytes_acked()) {
+      inflight_at_send =
+          model_->total_bytes_acked() -
+          congestion_event.last_packet_send_state.total_bytes_acked;
+    } else {
+      QUIC_BUG << "Total_bytes_acked(" << model_->total_bytes_acked()
+               << ") < send_state.total_bytes_acked("
+               << congestion_event.last_packet_send_state.total_bytes_acked
+               << ")";
+    }
+  }
   if (model_->IsInflightTooHigh(congestion_event,
                                 Params().probe_bw_full_loss_count)) {
     if (cycle_.is_sample_from_probing) {
       cycle_.is_sample_from_probing = false;
 
       if (!send_state.is_app_limited) {
-        const QuicByteCount inflight_at_send = BytesInFlight(send_state);
-
         const QuicByteCount inflight_target =
             sender_->GetTargetBytesInflight() * (1.0 - Params().beta);
         if (inflight_at_send >= inflight_target) {
@@ -248,8 +262,6 @@
     return NOT_ADAPTED_INFLIGHT_HIGH_NOT_SET;
   }
 
-  const QuicByteCount inflight_at_send = BytesInFlight(send_state);
-
   // Raise the upper bound for inflight.
   if (inflight_at_send > model_->inflight_hi()) {
     QUIC_DVLOG(3)
diff --git a/quic/core/congestion_control/bbr2_sender.cc b/quic/core/congestion_control/bbr2_sender.cc
index 6cd3037..bea4f9d 100644
--- a/quic/core/congestion_control/bbr2_sender.cc
+++ b/quic/core/congestion_control/bbr2_sender.cc
@@ -150,6 +150,11 @@
       ContainsQuicTag(connection_options, kB2H2)) {
     params_.limit_inflight_hi_by_max_delivered = true;
   }
+  if (GetQuicReloadableFlag(quic_bbr2_use_bytes_delivered) &&
+      ContainsQuicTag(connection_options, kB2DL)) {
+    QUIC_RELOADABLE_FLAG_COUNT(quic_bbr2_use_bytes_delivered);
+    params_.use_bytes_delivered_for_inflight_hi = true;
+  }
   if (ContainsQuicTag(connection_options, kBSAO)) {
     model_.EnableOverestimateAvoidance();
   }
diff --git a/quic/core/crypto/crypto_protocol.h b/quic/core/crypto/crypto_protocol.h
index 8093a68..853c42a 100644
--- a/quic/core/crypto/crypto_protocol.h
+++ b/quic/core/crypto/crypto_protocol.h
@@ -140,6 +140,8 @@
 const QuicTag kBSAO = TAG('B', 'S', 'A', 'O');   // Avoid Overestimation in
                                                  // Bandwidth Sampler with ack
                                                  // aggregation
+const QuicTag kB2DL = TAG('B', '2', 'D', 'L');   // Increase inflight_hi based
+                                                 // on delievered, not inflight.
 const QuicTag kNTLP = TAG('N', 'T', 'L', 'P');   // No tail loss probe
 const QuicTag k1TLP = TAG('1', 'T', 'L', 'P');   // 1 tail loss probe
 const QuicTag k1RTO = TAG('1', 'R', 'T', 'O');   // Send 1 packet upon RTO
diff --git a/quic/core/quic_flags_list.h b/quic/core/quic_flags_list.h
index c5d0a9f..55036ee 100644
--- a/quic/core/quic_flags_list.h
+++ b/quic/core/quic_flags_list.h
@@ -15,6 +15,7 @@
 QUIC_FLAG(FLAGS_quic_reloadable_flag_quic_bbr2_no_exit_startup_on_loss_with_bw_growth, true)
 QUIC_FLAG(FLAGS_quic_reloadable_flag_quic_bbr2_startup_loss_exit_use_max_delivered, true)
 QUIC_FLAG(FLAGS_quic_reloadable_flag_quic_bbr2_support_max_bootstrap_cwnd, true)
+QUIC_FLAG(FLAGS_quic_reloadable_flag_quic_bbr2_use_bytes_delivered, false)
 QUIC_FLAG(FLAGS_quic_reloadable_flag_quic_can_send_ack_frequency, true)
 QUIC_FLAG(FLAGS_quic_reloadable_flag_quic_close_connection_in_on_can_write_with_blocked_writer, true)
 QUIC_FLAG(FLAGS_quic_reloadable_flag_quic_connection_set_initial_self_address, true)