QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/third_party/quiche/src/quic/core/quic_sent_packet_manager.h" |
| 6 | |
| 7 | #include <memory> |
bnc | 463f235 | 2019-10-10 04:49:34 -0700 | [diff] [blame] | 8 | #include <utility> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10 | #include "net/third_party/quiche/src/quic/platform/api/quic_flags.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11 | #include "net/third_party/quiche/src/quic/platform/api/quic_test.h" |
| 12 | #include "net/third_party/quiche/src/quic/test_tools/quic_config_peer.h" |
| 13 | #include "net/third_party/quiche/src/quic/test_tools/quic_sent_packet_manager_peer.h" |
| 14 | #include "net/third_party/quiche/src/quic/test_tools/quic_test_utils.h" |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 15 | #include "net/third_party/quiche/src/common/platform/api/quiche_arraysize.h" |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 16 | #include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 17 | |
| 18 | using testing::_; |
| 19 | using testing::AnyNumber; |
| 20 | using testing::Invoke; |
| 21 | using testing::InvokeWithoutArgs; |
| 22 | using testing::IsEmpty; |
| 23 | using testing::Not; |
| 24 | using testing::Pointwise; |
| 25 | using testing::Return; |
| 26 | using testing::StrictMock; |
| 27 | using testing::WithArgs; |
| 28 | |
| 29 | namespace quic { |
| 30 | namespace test { |
| 31 | namespace { |
| 32 | // Default packet length. |
| 33 | const uint32_t kDefaultLength = 1000; |
| 34 | |
| 35 | // Stream ID for data sent in CreatePacket(). |
| 36 | const QuicStreamId kStreamId = 7; |
| 37 | |
| 38 | // Matcher to check that the packet number matches the second argument. |
| 39 | MATCHER(PacketNumberEq, "") { |
| 40 | return ::testing::get<0>(arg).packet_number == |
| 41 | QuicPacketNumber(::testing::get<1>(arg)); |
| 42 | } |
| 43 | |
| 44 | class MockDebugDelegate : public QuicSentPacketManager::DebugDelegate { |
| 45 | public: |
wub | 713afae | 2020-04-27 07:48:31 -0700 | [diff] [blame] | 46 | MOCK_METHOD(void, |
| 47 | OnSpuriousPacketRetransmission, |
| 48 | (TransmissionType transmission_type, QuicByteCount byte_size), |
| 49 | (override)); |
| 50 | MOCK_METHOD(void, |
| 51 | OnPacketLoss, |
| 52 | (QuicPacketNumber lost_packet_number, |
| 53 | EncryptionLevel encryption_level, |
| 54 | TransmissionType transmission_type, |
| 55 | QuicTime detection_time), |
| 56 | (override)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 57 | }; |
| 58 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 59 | class QuicSentPacketManagerTest : public QuicTest { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 60 | public: |
| 61 | void RetransmitCryptoPacket(uint64_t packet_number) { |
| 62 | EXPECT_CALL( |
| 63 | *send_algorithm_, |
| 64 | OnPacketSent(_, BytesInFlight(), QuicPacketNumber(packet_number), |
| 65 | kDefaultLength, HAS_RETRANSMITTABLE_DATA)); |
| 66 | SerializedPacket packet(CreatePacket(packet_number, false)); |
| 67 | packet.retransmittable_frames.push_back( |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 68 | QuicFrame(QuicStreamFrame(1, false, 0, quiche::QuicheStringPiece()))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 69 | packet.has_crypto_handshake = IS_HANDSHAKE; |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 70 | manager_.OnPacketSent(&packet, clock_.Now(), HANDSHAKE_RETRANSMISSION, |
| 71 | HAS_RETRANSMITTABLE_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 72 | } |
| 73 | |
fayang | 06bb1b0 | 2019-06-14 14:07:12 -0700 | [diff] [blame] | 74 | void RetransmitDataPacket(uint64_t packet_number, |
| 75 | TransmissionType type, |
| 76 | EncryptionLevel level) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 77 | EXPECT_CALL( |
| 78 | *send_algorithm_, |
| 79 | OnPacketSent(_, BytesInFlight(), QuicPacketNumber(packet_number), |
| 80 | kDefaultLength, HAS_RETRANSMITTABLE_DATA)); |
| 81 | SerializedPacket packet(CreatePacket(packet_number, true)); |
fayang | 06bb1b0 | 2019-06-14 14:07:12 -0700 | [diff] [blame] | 82 | packet.encryption_level = level; |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 83 | manager_.OnPacketSent(&packet, clock_.Now(), type, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 84 | HAS_RETRANSMITTABLE_DATA); |
| 85 | } |
| 86 | |
fayang | 06bb1b0 | 2019-06-14 14:07:12 -0700 | [diff] [blame] | 87 | void RetransmitDataPacket(uint64_t packet_number, TransmissionType type) { |
| 88 | RetransmitDataPacket(packet_number, type, ENCRYPTION_INITIAL); |
| 89 | } |
| 90 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 91 | protected: |
wub | 18773d6 | 2020-01-28 14:14:06 -0800 | [diff] [blame] | 92 | const CongestionControlType kInitialCongestionControlType = kCubicBytes; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 93 | QuicSentPacketManagerTest() |
QUICHE team | 73957f1 | 2019-04-18 16:21:52 -0700 | [diff] [blame] | 94 | : manager_(Perspective::IS_SERVER, |
| 95 | &clock_, |
| 96 | QuicRandom::GetInstance(), |
| 97 | &stats_, |
fayang | 3be090d | 2020-02-11 14:05:08 -0800 | [diff] [blame] | 98 | kInitialCongestionControlType), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 99 | send_algorithm_(new StrictMock<MockSendAlgorithm>), |
| 100 | network_change_visitor_(new StrictMock<MockNetworkChangeVisitor>) { |
| 101 | QuicSentPacketManagerPeer::SetSendAlgorithm(&manager_, send_algorithm_); |
| 102 | // Disable tail loss probes for most tests. |
| 103 | QuicSentPacketManagerPeer::SetMaxTailLossProbes(&manager_, 0); |
| 104 | // Advance the time 1s so the send times are never QuicTime::Zero. |
| 105 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1000)); |
| 106 | manager_.SetNetworkChangeVisitor(network_change_visitor_.get()); |
| 107 | manager_.SetSessionNotifier(¬ifier_); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 108 | |
wub | 18773d6 | 2020-01-28 14:14:06 -0800 | [diff] [blame] | 109 | EXPECT_CALL(*send_algorithm_, GetCongestionControlType()) |
| 110 | .WillRepeatedly(Return(kInitialCongestionControlType)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 111 | EXPECT_CALL(*send_algorithm_, BandwidthEstimate()) |
| 112 | .Times(AnyNumber()) |
| 113 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
| 114 | EXPECT_CALL(*send_algorithm_, InSlowStart()).Times(AnyNumber()); |
| 115 | EXPECT_CALL(*send_algorithm_, InRecovery()).Times(AnyNumber()); |
wub | f4ab965 | 2020-02-20 14:45:43 -0800 | [diff] [blame] | 116 | EXPECT_CALL(*send_algorithm_, OnPacketNeutered(_)).Times(AnyNumber()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 117 | EXPECT_CALL(*network_change_visitor_, OnPathMtuIncreased(1000)) |
| 118 | .Times(AnyNumber()); |
| 119 | EXPECT_CALL(notifier_, IsFrameOutstanding(_)).WillRepeatedly(Return(true)); |
| 120 | EXPECT_CALL(notifier_, HasUnackedCryptoData()) |
| 121 | .WillRepeatedly(Return(false)); |
| 122 | EXPECT_CALL(notifier_, OnStreamFrameRetransmitted(_)).Times(AnyNumber()); |
QUICHE team | 9467db0 | 2019-05-30 09:38:45 -0700 | [diff] [blame] | 123 | EXPECT_CALL(notifier_, OnFrameAcked(_, _, _)).WillRepeatedly(Return(true)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | ~QuicSentPacketManagerTest() override {} |
| 127 | |
ianswett | 9f459cb | 2019-04-21 06:39:59 -0700 | [diff] [blame] | 128 | QuicByteCount BytesInFlight() { return manager_.GetBytesInFlight(); } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 129 | void VerifyUnackedPackets(uint64_t* packets, size_t num_packets) { |
| 130 | if (num_packets == 0) { |
| 131 | EXPECT_TRUE(manager_.unacked_packets().empty()); |
| 132 | EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetNumRetransmittablePackets( |
| 133 | &manager_)); |
| 134 | return; |
| 135 | } |
| 136 | |
| 137 | EXPECT_FALSE(manager_.unacked_packets().empty()); |
| 138 | EXPECT_EQ(QuicPacketNumber(packets[0]), manager_.GetLeastUnacked()); |
| 139 | for (size_t i = 0; i < num_packets; ++i) { |
ianswett | e129b0c | 2019-04-20 00:27:00 -0700 | [diff] [blame] | 140 | EXPECT_TRUE( |
| 141 | manager_.unacked_packets().IsUnacked(QuicPacketNumber(packets[i]))) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 142 | << packets[i]; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | void VerifyRetransmittablePackets(uint64_t* packets, size_t num_packets) { |
| 147 | EXPECT_EQ( |
| 148 | num_packets, |
| 149 | QuicSentPacketManagerPeer::GetNumRetransmittablePackets(&manager_)); |
| 150 | for (size_t i = 0; i < num_packets; ++i) { |
| 151 | EXPECT_TRUE(QuicSentPacketManagerPeer::HasRetransmittableFrames( |
| 152 | &manager_, packets[i])) |
| 153 | << " packets[" << i << "]:" << packets[i]; |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | void ExpectAck(uint64_t largest_observed) { |
| 158 | EXPECT_CALL( |
| 159 | *send_algorithm_, |
| 160 | // Ensure the AckedPacketVector argument contains largest_observed. |
| 161 | OnCongestionEvent(true, _, _, |
| 162 | Pointwise(PacketNumberEq(), {largest_observed}), |
| 163 | IsEmpty())); |
| 164 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 165 | } |
| 166 | |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 167 | void ExpectUpdatedRtt(uint64_t /*largest_observed*/) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 168 | EXPECT_CALL(*send_algorithm_, |
| 169 | OnCongestionEvent(true, _, _, IsEmpty(), IsEmpty())); |
| 170 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 171 | } |
| 172 | |
| 173 | void ExpectAckAndLoss(bool rtt_updated, |
| 174 | uint64_t largest_observed, |
| 175 | uint64_t lost_packet) { |
| 176 | EXPECT_CALL( |
| 177 | *send_algorithm_, |
| 178 | OnCongestionEvent(rtt_updated, _, _, |
| 179 | Pointwise(PacketNumberEq(), {largest_observed}), |
| 180 | Pointwise(PacketNumberEq(), {lost_packet}))); |
| 181 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 182 | } |
| 183 | |
| 184 | // |packets_acked| and |packets_lost| should be in packet number order. |
| 185 | void ExpectAcksAndLosses(bool rtt_updated, |
| 186 | uint64_t* packets_acked, |
| 187 | size_t num_packets_acked, |
| 188 | uint64_t* packets_lost, |
| 189 | size_t num_packets_lost) { |
| 190 | std::vector<QuicPacketNumber> ack_vector; |
| 191 | for (size_t i = 0; i < num_packets_acked; ++i) { |
| 192 | ack_vector.push_back(QuicPacketNumber(packets_acked[i])); |
| 193 | } |
| 194 | std::vector<QuicPacketNumber> lost_vector; |
| 195 | for (size_t i = 0; i < num_packets_lost; ++i) { |
| 196 | lost_vector.push_back(QuicPacketNumber(packets_lost[i])); |
| 197 | } |
| 198 | EXPECT_CALL(*send_algorithm_, |
| 199 | OnCongestionEvent(rtt_updated, _, _, |
| 200 | Pointwise(PacketNumberEq(), ack_vector), |
| 201 | Pointwise(PacketNumberEq(), lost_vector))); |
| 202 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()) |
| 203 | .Times(AnyNumber()); |
| 204 | } |
| 205 | |
| 206 | void RetransmitAndSendPacket(uint64_t old_packet_number, |
| 207 | uint64_t new_packet_number) { |
| 208 | RetransmitAndSendPacket(old_packet_number, new_packet_number, |
| 209 | TLP_RETRANSMISSION); |
| 210 | } |
| 211 | |
| 212 | void RetransmitAndSendPacket(uint64_t old_packet_number, |
| 213 | uint64_t new_packet_number, |
| 214 | TransmissionType transmission_type) { |
| 215 | bool is_lost = false; |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 216 | if (transmission_type == HANDSHAKE_RETRANSMISSION || |
| 217 | transmission_type == TLP_RETRANSMISSION || |
| 218 | transmission_type == RTO_RETRANSMISSION || |
| 219 | transmission_type == PROBING_RETRANSMISSION) { |
| 220 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 221 | .WillOnce(WithArgs<1>( |
| 222 | Invoke([this, new_packet_number](TransmissionType type) { |
| 223 | RetransmitDataPacket(new_packet_number, type); |
| 224 | }))); |
| 225 | } else { |
| 226 | EXPECT_CALL(notifier_, OnFrameLost(_)).Times(1); |
| 227 | is_lost = true; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 228 | } |
| 229 | QuicSentPacketManagerPeer::MarkForRetransmission( |
| 230 | &manager_, old_packet_number, transmission_type); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 231 | if (!is_lost) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 232 | return; |
| 233 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 234 | EXPECT_CALL( |
| 235 | *send_algorithm_, |
| 236 | OnPacketSent(_, BytesInFlight(), QuicPacketNumber(new_packet_number), |
| 237 | kDefaultLength, HAS_RETRANSMITTABLE_DATA)); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 238 | SerializedPacket packet(CreatePacket(new_packet_number, true)); |
| 239 | manager_.OnPacketSent(&packet, clock_.Now(), transmission_type, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 240 | HAS_RETRANSMITTABLE_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | SerializedPacket CreateDataPacket(uint64_t packet_number) { |
| 244 | return CreatePacket(packet_number, true); |
| 245 | } |
| 246 | |
| 247 | SerializedPacket CreatePacket(uint64_t packet_number, bool retransmittable) { |
| 248 | SerializedPacket packet(QuicPacketNumber(packet_number), |
| 249 | PACKET_4BYTE_PACKET_NUMBER, nullptr, kDefaultLength, |
| 250 | false, false); |
| 251 | if (retransmittable) { |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 252 | packet.retransmittable_frames.push_back(QuicFrame( |
| 253 | QuicStreamFrame(kStreamId, false, 0, quiche::QuicheStringPiece()))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 254 | } |
| 255 | return packet; |
| 256 | } |
| 257 | |
zhongyi | 1b2f783 | 2019-06-14 13:31:34 -0700 | [diff] [blame] | 258 | SerializedPacket CreatePingPacket(uint64_t packet_number) { |
| 259 | SerializedPacket packet(QuicPacketNumber(packet_number), |
| 260 | PACKET_4BYTE_PACKET_NUMBER, nullptr, kDefaultLength, |
| 261 | false, false); |
| 262 | packet.retransmittable_frames.push_back(QuicFrame(QuicPingFrame())); |
| 263 | return packet; |
| 264 | } |
| 265 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 266 | void SendDataPacket(uint64_t packet_number) { |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 267 | SendDataPacket(packet_number, ENCRYPTION_INITIAL); |
| 268 | } |
| 269 | |
| 270 | void SendDataPacket(uint64_t packet_number, |
| 271 | EncryptionLevel encryption_level) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 272 | EXPECT_CALL(*send_algorithm_, |
| 273 | OnPacketSent(_, BytesInFlight(), |
| 274 | QuicPacketNumber(packet_number), _, _)); |
| 275 | SerializedPacket packet(CreateDataPacket(packet_number)); |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 276 | packet.encryption_level = encryption_level; |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 277 | manager_.OnPacketSent(&packet, clock_.Now(), NOT_RETRANSMISSION, |
| 278 | HAS_RETRANSMITTABLE_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 279 | } |
| 280 | |
zhongyi | 1b2f783 | 2019-06-14 13:31:34 -0700 | [diff] [blame] | 281 | void SendPingPacket(uint64_t packet_number, |
| 282 | EncryptionLevel encryption_level) { |
| 283 | EXPECT_CALL(*send_algorithm_, |
| 284 | OnPacketSent(_, BytesInFlight(), |
| 285 | QuicPacketNumber(packet_number), _, _)); |
| 286 | SerializedPacket packet(CreatePingPacket(packet_number)); |
| 287 | packet.encryption_level = encryption_level; |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 288 | manager_.OnPacketSent(&packet, clock_.Now(), NOT_RETRANSMISSION, |
| 289 | HAS_RETRANSMITTABLE_DATA); |
zhongyi | 1b2f783 | 2019-06-14 13:31:34 -0700 | [diff] [blame] | 290 | } |
| 291 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 292 | void SendCryptoPacket(uint64_t packet_number) { |
| 293 | EXPECT_CALL( |
| 294 | *send_algorithm_, |
| 295 | OnPacketSent(_, BytesInFlight(), QuicPacketNumber(packet_number), |
| 296 | kDefaultLength, HAS_RETRANSMITTABLE_DATA)); |
| 297 | SerializedPacket packet(CreatePacket(packet_number, false)); |
| 298 | packet.retransmittable_frames.push_back( |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 299 | QuicFrame(QuicStreamFrame(1, false, 0, quiche::QuicheStringPiece()))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 300 | packet.has_crypto_handshake = IS_HANDSHAKE; |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 301 | manager_.OnPacketSent(&packet, clock_.Now(), NOT_RETRANSMISSION, |
| 302 | HAS_RETRANSMITTABLE_DATA); |
| 303 | EXPECT_CALL(notifier_, HasUnackedCryptoData()).WillRepeatedly(Return(true)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | void SendAckPacket(uint64_t packet_number, uint64_t largest_acked) { |
fayang | 06bb1b0 | 2019-06-14 14:07:12 -0700 | [diff] [blame] | 307 | SendAckPacket(packet_number, largest_acked, ENCRYPTION_INITIAL); |
| 308 | } |
| 309 | |
| 310 | void SendAckPacket(uint64_t packet_number, |
| 311 | uint64_t largest_acked, |
| 312 | EncryptionLevel level) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 313 | EXPECT_CALL( |
| 314 | *send_algorithm_, |
| 315 | OnPacketSent(_, BytesInFlight(), QuicPacketNumber(packet_number), |
| 316 | kDefaultLength, NO_RETRANSMITTABLE_DATA)); |
| 317 | SerializedPacket packet(CreatePacket(packet_number, false)); |
| 318 | packet.largest_acked = QuicPacketNumber(largest_acked); |
fayang | 06bb1b0 | 2019-06-14 14:07:12 -0700 | [diff] [blame] | 319 | packet.encryption_level = level; |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 320 | manager_.OnPacketSent(&packet, clock_.Now(), NOT_RETRANSMISSION, |
| 321 | NO_RETRANSMITTABLE_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 322 | } |
| 323 | |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 324 | void EnablePto(QuicTag tag) { |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 325 | QuicConfig config; |
| 326 | QuicTagVector options; |
| 327 | options.push_back(tag); |
| 328 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 329 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 330 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 331 | manager_.SetFromConfig(config); |
fayang | 62f867a | 2019-08-22 12:05:01 -0700 | [diff] [blame] | 332 | EXPECT_TRUE(manager_.pto_enabled()); |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 333 | } |
| 334 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 335 | QuicSentPacketManager manager_; |
| 336 | MockClock clock_; |
| 337 | QuicConnectionStats stats_; |
| 338 | MockSendAlgorithm* send_algorithm_; |
| 339 | std::unique_ptr<MockNetworkChangeVisitor> network_change_visitor_; |
| 340 | StrictMock<MockSessionNotifier> notifier_; |
| 341 | }; |
| 342 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 343 | TEST_F(QuicSentPacketManagerTest, IsUnacked) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 344 | VerifyUnackedPackets(nullptr, 0); |
| 345 | SendDataPacket(1); |
| 346 | |
| 347 | uint64_t unacked[] = {1}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 348 | VerifyUnackedPackets(unacked, QUICHE_ARRAYSIZE(unacked)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 349 | uint64_t retransmittable[] = {1}; |
| 350 | VerifyRetransmittablePackets(retransmittable, |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 351 | QUICHE_ARRAYSIZE(retransmittable)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 352 | } |
| 353 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 354 | TEST_F(QuicSentPacketManagerTest, IsUnAckedRetransmit) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 355 | SendDataPacket(1); |
| 356 | RetransmitAndSendPacket(1, 2); |
| 357 | |
| 358 | EXPECT_TRUE(QuicSentPacketManagerPeer::IsRetransmission(&manager_, 2)); |
| 359 | uint64_t unacked[] = {1, 2}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 360 | VerifyUnackedPackets(unacked, QUICHE_ARRAYSIZE(unacked)); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 361 | std::vector<uint64_t> retransmittable = {1, 2}; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 362 | VerifyRetransmittablePackets(&retransmittable[0], retransmittable.size()); |
| 363 | } |
| 364 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 365 | TEST_F(QuicSentPacketManagerTest, RetransmitThenAck) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 366 | SendDataPacket(1); |
| 367 | RetransmitAndSendPacket(1, 2); |
| 368 | |
| 369 | // Ack 2 but not 1. |
| 370 | ExpectAck(2); |
| 371 | manager_.OnAckFrameStart(QuicPacketNumber(2), QuicTime::Delta::Infinite(), |
| 372 | clock_.Now()); |
| 373 | manager_.OnAckRange(QuicPacketNumber(2), QuicPacketNumber(3)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 374 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 375 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 376 | ENCRYPTION_INITIAL)); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 377 | EXPECT_CALL(notifier_, IsFrameOutstanding(_)).WillRepeatedly(Return(false)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 378 | // Packet 1 is unacked, pending, but not retransmittable. |
| 379 | uint64_t unacked[] = {1}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 380 | VerifyUnackedPackets(unacked, QUICHE_ARRAYSIZE(unacked)); |
ianswett | 67d7a3c | 2019-04-19 10:58:47 -0700 | [diff] [blame] | 381 | EXPECT_TRUE(manager_.HasInFlightPackets()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 382 | VerifyRetransmittablePackets(nullptr, 0); |
| 383 | } |
| 384 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 385 | TEST_F(QuicSentPacketManagerTest, RetransmitThenAckBeforeSend) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 386 | SendDataPacket(1); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 387 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 388 | .WillOnce(WithArgs<1>(Invoke( |
| 389 | [this](TransmissionType type) { RetransmitDataPacket(2, type); }))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 390 | QuicSentPacketManagerPeer::MarkForRetransmission(&manager_, 1, |
| 391 | TLP_RETRANSMISSION); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 392 | // Ack 1. |
| 393 | ExpectAck(1); |
| 394 | manager_.OnAckFrameStart(QuicPacketNumber(1), QuicTime::Delta::Infinite(), |
| 395 | clock_.Now()); |
| 396 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 397 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 398 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 399 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 400 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 401 | EXPECT_CALL(notifier_, IsFrameOutstanding(_)).WillRepeatedly(Return(false)); |
| 402 | uint64_t unacked[] = {2}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 403 | VerifyUnackedPackets(unacked, QUICHE_ARRAYSIZE(unacked)); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 404 | // We do not know packet 2 is a spurious retransmission until it gets acked. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 405 | VerifyRetransmittablePackets(nullptr, 0); |
| 406 | EXPECT_EQ(0u, stats_.packets_spuriously_retransmitted); |
| 407 | } |
| 408 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 409 | TEST_F(QuicSentPacketManagerTest, RetransmitThenStopRetransmittingBeforeSend) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 410 | SendDataPacket(1); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 411 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 412 | QuicSentPacketManagerPeer::MarkForRetransmission(&manager_, 1, |
| 413 | TLP_RETRANSMISSION); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 414 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 415 | EXPECT_CALL(notifier_, IsFrameOutstanding(_)).WillRepeatedly(Return(false)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 416 | |
| 417 | uint64_t unacked[] = {1}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 418 | VerifyUnackedPackets(unacked, QUICHE_ARRAYSIZE(unacked)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 419 | VerifyRetransmittablePackets(nullptr, 0); |
| 420 | EXPECT_EQ(0u, stats_.packets_spuriously_retransmitted); |
| 421 | } |
| 422 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 423 | TEST_F(QuicSentPacketManagerTest, RetransmitThenAckPrevious) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 424 | SendDataPacket(1); |
| 425 | RetransmitAndSendPacket(1, 2); |
| 426 | QuicTime::Delta rtt = QuicTime::Delta::FromMilliseconds(15); |
| 427 | clock_.AdvanceTime(rtt); |
| 428 | |
| 429 | // Ack 1 but not 2. |
| 430 | ExpectAck(1); |
| 431 | manager_.OnAckFrameStart(QuicPacketNumber(1), QuicTime::Delta::Infinite(), |
| 432 | clock_.Now()); |
| 433 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 434 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 435 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 436 | ENCRYPTION_INITIAL)); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 437 | EXPECT_CALL(notifier_, IsFrameOutstanding(_)).WillRepeatedly(Return(false)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 438 | // 2 remains unacked, but no packets have retransmittable data. |
| 439 | uint64_t unacked[] = {2}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 440 | VerifyUnackedPackets(unacked, QUICHE_ARRAYSIZE(unacked)); |
ianswett | 67d7a3c | 2019-04-19 10:58:47 -0700 | [diff] [blame] | 441 | EXPECT_TRUE(manager_.HasInFlightPackets()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 442 | VerifyRetransmittablePackets(nullptr, 0); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 443 | // Ack 2 causes 2 be considered as spurious retransmission. |
| 444 | EXPECT_CALL(notifier_, OnFrameAcked(_, _, _)).WillOnce(Return(false)); |
| 445 | ExpectAck(2); |
| 446 | manager_.OnAckFrameStart(QuicPacketNumber(2), QuicTime::Delta::Infinite(), |
| 447 | clock_.Now()); |
| 448 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(3)); |
| 449 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
| 450 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(2), |
| 451 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 452 | |
| 453 | EXPECT_EQ(1u, stats_.packets_spuriously_retransmitted); |
| 454 | } |
| 455 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 456 | TEST_F(QuicSentPacketManagerTest, RetransmitThenAckPreviousThenNackRetransmit) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 457 | SendDataPacket(1); |
| 458 | RetransmitAndSendPacket(1, 2); |
| 459 | QuicTime::Delta rtt = QuicTime::Delta::FromMilliseconds(15); |
| 460 | clock_.AdvanceTime(rtt); |
| 461 | |
| 462 | // First, ACK packet 1 which makes packet 2 non-retransmittable. |
| 463 | ExpectAck(1); |
| 464 | manager_.OnAckFrameStart(QuicPacketNumber(1), QuicTime::Delta::Infinite(), |
| 465 | clock_.Now()); |
| 466 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 467 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 468 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 469 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 470 | |
| 471 | SendDataPacket(3); |
| 472 | SendDataPacket(4); |
| 473 | SendDataPacket(5); |
| 474 | clock_.AdvanceTime(rtt); |
| 475 | |
| 476 | // Next, NACK packet 2 three times. |
fayang | 3be090d | 2020-02-11 14:05:08 -0800 | [diff] [blame] | 477 | EXPECT_CALL(notifier_, IsFrameOutstanding(_)).WillRepeatedly(Return(false)); |
| 478 | EXPECT_CALL(notifier_, OnFrameLost(_)).Times(1); |
| 479 | ExpectAckAndLoss(true, 3, 2); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 480 | manager_.OnAckFrameStart(QuicPacketNumber(3), QuicTime::Delta::Infinite(), |
| 481 | clock_.Now()); |
| 482 | manager_.OnAckRange(QuicPacketNumber(3), QuicPacketNumber(4)); |
| 483 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 484 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 485 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(2), |
| 486 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 487 | |
| 488 | ExpectAck(4); |
| 489 | manager_.OnAckFrameStart(QuicPacketNumber(4), QuicTime::Delta::Infinite(), |
| 490 | clock_.Now()); |
| 491 | manager_.OnAckRange(QuicPacketNumber(3), QuicPacketNumber(5)); |
| 492 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 493 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 494 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(3), |
| 495 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 496 | |
fayang | 3be090d | 2020-02-11 14:05:08 -0800 | [diff] [blame] | 497 | ExpectAck(5); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 498 | manager_.OnAckFrameStart(QuicPacketNumber(5), QuicTime::Delta::Infinite(), |
| 499 | clock_.Now()); |
| 500 | manager_.OnAckRange(QuicPacketNumber(3), QuicPacketNumber(6)); |
| 501 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 502 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 503 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(4), |
| 504 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 505 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 506 | uint64_t unacked[] = {2}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 507 | VerifyUnackedPackets(unacked, QUICHE_ARRAYSIZE(unacked)); |
ianswett | 67d7a3c | 2019-04-19 10:58:47 -0700 | [diff] [blame] | 508 | EXPECT_FALSE(manager_.HasInFlightPackets()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 509 | VerifyRetransmittablePackets(nullptr, 0); |
| 510 | |
| 511 | // Verify that the retransmission alarm would not fire, |
| 512 | // since there is no retransmittable data outstanding. |
| 513 | EXPECT_EQ(QuicTime::Zero(), manager_.GetRetransmissionTime()); |
| 514 | } |
| 515 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 516 | TEST_F(QuicSentPacketManagerTest, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 517 | DISABLED_RetransmitTwiceThenAckPreviousBeforeSend) { |
| 518 | SendDataPacket(1); |
| 519 | RetransmitAndSendPacket(1, 2); |
| 520 | |
| 521 | // Fire the RTO, which will mark 2 for retransmission (but will not send it). |
| 522 | EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 523 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 524 | manager_.OnRetransmissionTimeout(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 525 | |
| 526 | // Ack 1 but not 2, before 2 is able to be sent. |
| 527 | // Since 1 has been retransmitted, it has already been lost, and so the |
| 528 | // send algorithm is not informed that it has been ACK'd. |
| 529 | ExpectUpdatedRtt(1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 530 | manager_.OnAckFrameStart(QuicPacketNumber(1), QuicTime::Delta::Infinite(), |
| 531 | clock_.Now()); |
| 532 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 533 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 534 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 535 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 536 | |
| 537 | // Since 2 was marked for retransmit, when 1 is acked, 2 is kept for RTT. |
| 538 | uint64_t unacked[] = {2}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 539 | VerifyUnackedPackets(unacked, QUICHE_ARRAYSIZE(unacked)); |
ianswett | 67d7a3c | 2019-04-19 10:58:47 -0700 | [diff] [blame] | 540 | EXPECT_FALSE(manager_.HasInFlightPackets()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 541 | VerifyRetransmittablePackets(nullptr, 0); |
| 542 | |
| 543 | // Verify that the retransmission alarm would not fire, |
| 544 | // since there is no retransmittable data outstanding. |
| 545 | EXPECT_EQ(QuicTime::Zero(), manager_.GetRetransmissionTime()); |
| 546 | } |
| 547 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 548 | TEST_F(QuicSentPacketManagerTest, RetransmitTwiceThenAckFirst) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 549 | StrictMock<MockDebugDelegate> debug_delegate; |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 550 | EXPECT_CALL(debug_delegate, OnSpuriousPacketRetransmission(TLP_RETRANSMISSION, |
| 551 | kDefaultLength)) |
| 552 | .Times(1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 553 | manager_.SetDebugDelegate(&debug_delegate); |
| 554 | |
| 555 | SendDataPacket(1); |
| 556 | RetransmitAndSendPacket(1, 2); |
| 557 | RetransmitAndSendPacket(2, 3); |
| 558 | QuicTime::Delta rtt = QuicTime::Delta::FromMilliseconds(15); |
| 559 | clock_.AdvanceTime(rtt); |
| 560 | |
| 561 | // Ack 1 but not 2 or 3. |
| 562 | ExpectAck(1); |
| 563 | manager_.OnAckFrameStart(QuicPacketNumber(1), QuicTime::Delta::Infinite(), |
| 564 | clock_.Now()); |
| 565 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 566 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 567 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 568 | ENCRYPTION_INITIAL)); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 569 | // Frames in packets 2 and 3 are acked. |
| 570 | EXPECT_CALL(notifier_, IsFrameOutstanding(_)) |
| 571 | .Times(2) |
| 572 | .WillRepeatedly(Return(false)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 573 | |
| 574 | // 2 and 3 remain unacked, but no packets have retransmittable data. |
| 575 | uint64_t unacked[] = {2, 3}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 576 | VerifyUnackedPackets(unacked, QUICHE_ARRAYSIZE(unacked)); |
ianswett | 67d7a3c | 2019-04-19 10:58:47 -0700 | [diff] [blame] | 577 | EXPECT_TRUE(manager_.HasInFlightPackets()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 578 | VerifyRetransmittablePackets(nullptr, 0); |
| 579 | |
| 580 | // Ensure packet 2 is lost when 4 is sent and 3 and 4 are acked. |
| 581 | SendDataPacket(4); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 582 | // No new data gets acked in packet 3. |
| 583 | EXPECT_CALL(notifier_, OnFrameAcked(_, _, _)) |
| 584 | .WillOnce(Return(false)) |
| 585 | .WillRepeatedly(Return(true)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 586 | uint64_t acked[] = {3, 4}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 587 | ExpectAcksAndLosses(true, acked, QUICHE_ARRAYSIZE(acked), nullptr, 0); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 588 | manager_.OnAckFrameStart(QuicPacketNumber(4), QuicTime::Delta::Infinite(), |
| 589 | clock_.Now()); |
| 590 | manager_.OnAckRange(QuicPacketNumber(3), QuicPacketNumber(5)); |
| 591 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 592 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 593 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(2), |
| 594 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 595 | |
| 596 | uint64_t unacked2[] = {2}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 597 | VerifyUnackedPackets(unacked2, QUICHE_ARRAYSIZE(unacked2)); |
ianswett | 67d7a3c | 2019-04-19 10:58:47 -0700 | [diff] [blame] | 598 | EXPECT_TRUE(manager_.HasInFlightPackets()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 599 | |
| 600 | SendDataPacket(5); |
| 601 | ExpectAckAndLoss(true, 5, 2); |
| 602 | EXPECT_CALL(debug_delegate, |
vasilvv | 923b6d2 | 2020-03-23 11:17:58 -0700 | [diff] [blame] | 603 | OnPacketLoss(QuicPacketNumber(2), _, LOSS_RETRANSMISSION, _)); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 604 | // Frames in all packets are acked. |
| 605 | EXPECT_CALL(notifier_, IsFrameOutstanding(_)).WillRepeatedly(Return(false)); |
| 606 | // Notify session that stream frame in packet 2 gets lost although it is |
| 607 | // not outstanding. |
| 608 | EXPECT_CALL(notifier_, OnFrameLost(_)).Times(1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 609 | manager_.OnAckFrameStart(QuicPacketNumber(5), QuicTime::Delta::Infinite(), |
| 610 | clock_.Now()); |
| 611 | manager_.OnAckRange(QuicPacketNumber(3), QuicPacketNumber(6)); |
| 612 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 613 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 614 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(3), |
| 615 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 616 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 617 | uint64_t unacked3[] = {2}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 618 | VerifyUnackedPackets(unacked3, QUICHE_ARRAYSIZE(unacked3)); |
ianswett | 67d7a3c | 2019-04-19 10:58:47 -0700 | [diff] [blame] | 619 | EXPECT_FALSE(manager_.HasInFlightPackets()); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 620 | // Spurious retransmission is detected when packet 3 gets acked. We cannot |
| 621 | // know packet 2 is a spurious until it gets acked. |
| 622 | EXPECT_EQ(1u, stats_.packets_spuriously_retransmitted); |
wub | e330aa4 | 2020-02-27 07:49:09 -0800 | [diff] [blame] | 623 | EXPECT_EQ(1u, stats_.packets_lost); |
| 624 | EXPECT_LT(QuicTime::Delta::Zero(), stats_.total_loss_detection_time); |
wub | aa51f0e | 2020-05-12 15:08:16 -0700 | [diff] [blame] | 625 | EXPECT_LE(1u, stats_.sent_packets_max_sequence_reordering); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 626 | } |
| 627 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 628 | TEST_F(QuicSentPacketManagerTest, AckOriginalTransmission) { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 629 | auto loss_algorithm = std::make_unique<MockLossAlgorithm>(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 630 | QuicSentPacketManagerPeer::SetLossAlgorithm(&manager_, loss_algorithm.get()); |
| 631 | |
| 632 | SendDataPacket(1); |
| 633 | RetransmitAndSendPacket(1, 2); |
| 634 | |
| 635 | // Ack original transmission, but that wasn't lost via fast retransmit, |
| 636 | // so no call on OnSpuriousRetransmission is expected. |
| 637 | { |
| 638 | ExpectAck(1); |
| 639 | EXPECT_CALL(*loss_algorithm, DetectLosses(_, _, _, _, _, _)); |
| 640 | manager_.OnAckFrameStart(QuicPacketNumber(1), QuicTime::Delta::Infinite(), |
| 641 | clock_.Now()); |
| 642 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 643 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 644 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 645 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | SendDataPacket(3); |
| 649 | SendDataPacket(4); |
| 650 | // Ack 4, which causes 3 to be retransmitted. |
| 651 | { |
| 652 | ExpectAck(4); |
| 653 | EXPECT_CALL(*loss_algorithm, DetectLosses(_, _, _, _, _, _)); |
| 654 | manager_.OnAckFrameStart(QuicPacketNumber(4), QuicTime::Delta::Infinite(), |
| 655 | clock_.Now()); |
| 656 | manager_.OnAckRange(QuicPacketNumber(4), QuicPacketNumber(5)); |
| 657 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 658 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 659 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(2), |
| 660 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 661 | RetransmitAndSendPacket(3, 5, LOSS_RETRANSMISSION); |
| 662 | } |
| 663 | |
| 664 | // Ack 3, which causes SpuriousRetransmitDetected to be called. |
| 665 | { |
| 666 | uint64_t acked[] = {3}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 667 | ExpectAcksAndLosses(false, acked, QUICHE_ARRAYSIZE(acked), nullptr, 0); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 668 | EXPECT_CALL(*loss_algorithm, DetectLosses(_, _, _, _, _, _)); |
fayang | cc4ea6a | 2019-10-25 08:44:03 -0700 | [diff] [blame] | 669 | EXPECT_CALL(*loss_algorithm, |
| 670 | SpuriousLossDetected(_, _, _, QuicPacketNumber(3), |
| 671 | QuicPacketNumber(4))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 672 | manager_.OnAckFrameStart(QuicPacketNumber(4), QuicTime::Delta::Infinite(), |
| 673 | clock_.Now()); |
| 674 | manager_.OnAckRange(QuicPacketNumber(3), QuicPacketNumber(5)); |
| 675 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
wub | 02831dc | 2020-02-28 12:00:54 -0800 | [diff] [blame] | 676 | EXPECT_EQ(0u, stats_.packet_spuriously_detected_lost); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 677 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 678 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(3), |
| 679 | ENCRYPTION_INITIAL)); |
wub | 02831dc | 2020-02-28 12:00:54 -0800 | [diff] [blame] | 680 | EXPECT_EQ(1u, stats_.packet_spuriously_detected_lost); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 681 | // Ack 3 will not cause 5 be considered as a spurious retransmission. Ack |
| 682 | // 5 will cause 5 be considered as a spurious retransmission as no new |
| 683 | // data gets acked. |
| 684 | ExpectAck(5); |
| 685 | EXPECT_CALL(*loss_algorithm, DetectLosses(_, _, _, _, _, _)); |
| 686 | EXPECT_CALL(notifier_, OnFrameAcked(_, _, _)).WillOnce(Return(false)); |
| 687 | manager_.OnAckFrameStart(QuicPacketNumber(5), QuicTime::Delta::Infinite(), |
| 688 | clock_.Now()); |
| 689 | manager_.OnAckRange(QuicPacketNumber(3), QuicPacketNumber(6)); |
| 690 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
| 691 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
| 692 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(4), |
| 693 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 694 | } |
| 695 | } |
| 696 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 697 | TEST_F(QuicSentPacketManagerTest, GetLeastUnacked) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 698 | EXPECT_EQ(QuicPacketNumber(1u), manager_.GetLeastUnacked()); |
| 699 | } |
| 700 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 701 | TEST_F(QuicSentPacketManagerTest, GetLeastUnackedUnacked) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 702 | SendDataPacket(1); |
| 703 | EXPECT_EQ(QuicPacketNumber(1u), manager_.GetLeastUnacked()); |
| 704 | } |
| 705 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 706 | TEST_F(QuicSentPacketManagerTest, AckAckAndUpdateRtt) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 707 | EXPECT_FALSE(manager_.largest_packet_peer_knows_is_acked().IsInitialized()); |
| 708 | SendDataPacket(1); |
| 709 | SendAckPacket(2, 1); |
| 710 | |
| 711 | // Now ack the ack and expect an RTT update. |
| 712 | uint64_t acked[] = {1, 2}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 713 | ExpectAcksAndLosses(true, acked, QUICHE_ARRAYSIZE(acked), nullptr, 0); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 714 | manager_.OnAckFrameStart(QuicPacketNumber(2), |
| 715 | QuicTime::Delta::FromMilliseconds(5), clock_.Now()); |
| 716 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(3)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 717 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 718 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 719 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 720 | EXPECT_EQ(QuicPacketNumber(1), manager_.largest_packet_peer_knows_is_acked()); |
| 721 | |
| 722 | SendAckPacket(3, 3); |
| 723 | |
| 724 | // Now ack the ack and expect only an RTT update. |
| 725 | uint64_t acked2[] = {3}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 726 | ExpectAcksAndLosses(true, acked2, QUICHE_ARRAYSIZE(acked2), nullptr, 0); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 727 | manager_.OnAckFrameStart(QuicPacketNumber(3), QuicTime::Delta::Infinite(), |
| 728 | clock_.Now()); |
| 729 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(4)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 730 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 731 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(2), |
| 732 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 733 | EXPECT_EQ(QuicPacketNumber(3u), |
| 734 | manager_.largest_packet_peer_knows_is_acked()); |
| 735 | } |
| 736 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 737 | TEST_F(QuicSentPacketManagerTest, Rtt) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 738 | QuicTime::Delta expected_rtt = QuicTime::Delta::FromMilliseconds(20); |
| 739 | SendDataPacket(1); |
| 740 | clock_.AdvanceTime(expected_rtt); |
| 741 | |
| 742 | ExpectAck(1); |
| 743 | manager_.OnAckFrameStart(QuicPacketNumber(1), QuicTime::Delta::Infinite(), |
| 744 | clock_.Now()); |
| 745 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 746 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 747 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 748 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 749 | EXPECT_EQ(expected_rtt, manager_.GetRttStats()->latest_rtt()); |
| 750 | } |
| 751 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 752 | TEST_F(QuicSentPacketManagerTest, RttWithInvalidDelta) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 753 | // Expect that the RTT is equal to the local time elapsed, since the |
| 754 | // ack_delay_time is larger than the local time elapsed |
| 755 | // and is hence invalid. |
| 756 | QuicTime::Delta expected_rtt = QuicTime::Delta::FromMilliseconds(10); |
| 757 | SendDataPacket(1); |
| 758 | clock_.AdvanceTime(expected_rtt); |
| 759 | |
| 760 | ExpectAck(1); |
| 761 | manager_.OnAckFrameStart(QuicPacketNumber(1), |
| 762 | QuicTime::Delta::FromMilliseconds(11), clock_.Now()); |
| 763 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 764 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 765 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 766 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 767 | EXPECT_EQ(expected_rtt, manager_.GetRttStats()->latest_rtt()); |
| 768 | } |
| 769 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 770 | TEST_F(QuicSentPacketManagerTest, RttWithInfiniteDelta) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 771 | // Expect that the RTT is equal to the local time elapsed, since the |
| 772 | // ack_delay_time is infinite, and is hence invalid. |
| 773 | QuicTime::Delta expected_rtt = QuicTime::Delta::FromMilliseconds(10); |
| 774 | SendDataPacket(1); |
| 775 | clock_.AdvanceTime(expected_rtt); |
| 776 | |
| 777 | ExpectAck(1); |
| 778 | manager_.OnAckFrameStart(QuicPacketNumber(1), QuicTime::Delta::Infinite(), |
| 779 | clock_.Now()); |
| 780 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 781 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 782 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 783 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 784 | EXPECT_EQ(expected_rtt, manager_.GetRttStats()->latest_rtt()); |
| 785 | } |
| 786 | |
wub | 8ee29a0 | 2019-12-12 13:06:48 -0800 | [diff] [blame] | 787 | TEST_F(QuicSentPacketManagerTest, RttWithDeltaExceedingLimit) { |
| 788 | // Initialize min and smoothed rtt to 10ms. |
| 789 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 790 | rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(10), |
| 791 | QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 792 | |
| 793 | QuicTime::Delta send_delta = QuicTime::Delta::FromMilliseconds(100); |
| 794 | QuicTime::Delta ack_delay = |
| 795 | QuicTime::Delta::FromMilliseconds(5) + manager_.peer_max_ack_delay(); |
| 796 | ASSERT_GT(send_delta - rtt_stats->min_rtt(), ack_delay); |
| 797 | SendDataPacket(1); |
| 798 | clock_.AdvanceTime(send_delta); |
| 799 | |
| 800 | ExpectAck(1); |
| 801 | manager_.OnAckFrameStart(QuicPacketNumber(1), ack_delay, clock_.Now()); |
| 802 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
| 803 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
| 804 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 805 | ENCRYPTION_FORWARD_SECURE)); |
| 806 | |
| 807 | QuicTime::Delta expected_rtt_sample = |
wub | 81c9b66 | 2020-02-14 09:08:07 -0800 | [diff] [blame] | 808 | send_delta - manager_.peer_max_ack_delay(); |
wub | 8ee29a0 | 2019-12-12 13:06:48 -0800 | [diff] [blame] | 809 | EXPECT_EQ(expected_rtt_sample, manager_.GetRttStats()->latest_rtt()); |
| 810 | } |
| 811 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 812 | TEST_F(QuicSentPacketManagerTest, RttZeroDelta) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 813 | // Expect that the RTT is the time between send and receive since the |
| 814 | // ack_delay_time is zero. |
| 815 | QuicTime::Delta expected_rtt = QuicTime::Delta::FromMilliseconds(10); |
| 816 | SendDataPacket(1); |
| 817 | clock_.AdvanceTime(expected_rtt); |
| 818 | |
| 819 | ExpectAck(1); |
| 820 | manager_.OnAckFrameStart(QuicPacketNumber(1), QuicTime::Delta::Zero(), |
| 821 | clock_.Now()); |
| 822 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 823 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 824 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 825 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 826 | EXPECT_EQ(expected_rtt, manager_.GetRttStats()->latest_rtt()); |
| 827 | } |
| 828 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 829 | TEST_F(QuicSentPacketManagerTest, TailLossProbeTimeout) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 830 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 831 | return; |
| 832 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 833 | QuicSentPacketManagerPeer::SetMaxTailLossProbes(&manager_, 2); |
| 834 | |
| 835 | // Send 1 packet. |
| 836 | SendDataPacket(1); |
| 837 | |
| 838 | // The first tail loss probe retransmits 1 packet. |
| 839 | manager_.OnRetransmissionTimeout(); |
| 840 | EXPECT_EQ(QuicTime::Delta::Zero(), manager_.TimeUntilSend(clock_.Now())); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 841 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 842 | .WillOnce(WithArgs<1>(Invoke( |
| 843 | [this](TransmissionType type) { RetransmitDataPacket(2, type); }))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 844 | manager_.MaybeRetransmitTailLossProbe(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 845 | |
| 846 | // The second tail loss probe retransmits 1 packet. |
| 847 | manager_.OnRetransmissionTimeout(); |
| 848 | EXPECT_EQ(QuicTime::Delta::Zero(), manager_.TimeUntilSend(clock_.Now())); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 849 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 850 | .WillOnce(WithArgs<1>(Invoke( |
| 851 | [this](TransmissionType type) { RetransmitDataPacket(3, type); }))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 852 | manager_.MaybeRetransmitTailLossProbe(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 853 | EXPECT_CALL(*send_algorithm_, CanSend(_)).WillOnce(Return(false)); |
| 854 | EXPECT_EQ(QuicTime::Delta::Infinite(), manager_.TimeUntilSend(clock_.Now())); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 855 | |
| 856 | // Ack the third and ensure the first two are still pending. |
| 857 | ExpectAck(3); |
| 858 | |
| 859 | manager_.OnAckFrameStart(QuicPacketNumber(3), QuicTime::Delta::Infinite(), |
| 860 | clock_.Now()); |
| 861 | manager_.OnAckRange(QuicPacketNumber(3), QuicPacketNumber(4)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 862 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 863 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 864 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 865 | |
ianswett | 67d7a3c | 2019-04-19 10:58:47 -0700 | [diff] [blame] | 866 | EXPECT_TRUE(manager_.HasInFlightPackets()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 867 | |
| 868 | // Acking two more packets will lose both of them due to nacks. |
| 869 | SendDataPacket(4); |
| 870 | SendDataPacket(5); |
| 871 | uint64_t acked[] = {4, 5}; |
| 872 | uint64_t lost[] = {1, 2}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 873 | ExpectAcksAndLosses(true, acked, QUICHE_ARRAYSIZE(acked), lost, |
| 874 | QUICHE_ARRAYSIZE(lost)); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 875 | // Frames in all packets are acked. |
| 876 | EXPECT_CALL(notifier_, IsFrameOutstanding(_)).WillRepeatedly(Return(false)); |
| 877 | // Notify session that stream frame in packets 1 and 2 get lost although |
| 878 | // they are not outstanding. |
| 879 | EXPECT_CALL(notifier_, OnFrameLost(_)).Times(2); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 880 | manager_.OnAckFrameStart(QuicPacketNumber(5), QuicTime::Delta::Infinite(), |
| 881 | clock_.Now()); |
| 882 | manager_.OnAckRange(QuicPacketNumber(3), QuicPacketNumber(6)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 883 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 884 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(2), |
| 885 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 886 | |
ianswett | 67d7a3c | 2019-04-19 10:58:47 -0700 | [diff] [blame] | 887 | EXPECT_FALSE(manager_.HasInFlightPackets()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 888 | EXPECT_EQ(2u, stats_.tlp_count); |
| 889 | EXPECT_EQ(0u, stats_.rto_count); |
| 890 | } |
| 891 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 892 | TEST_F(QuicSentPacketManagerTest, TailLossProbeThenRTO) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 893 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 894 | return; |
| 895 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 896 | QuicSentPacketManagerPeer::SetMaxTailLossProbes(&manager_, 2); |
| 897 | |
| 898 | // Send 100 packets. |
| 899 | const size_t kNumSentPackets = 100; |
| 900 | for (size_t i = 1; i <= kNumSentPackets; ++i) { |
| 901 | SendDataPacket(i); |
| 902 | } |
| 903 | QuicTime rto_packet_time = clock_.Now(); |
| 904 | // Advance the time. |
| 905 | clock_.AdvanceTime(manager_.GetRetransmissionTime() - clock_.Now()); |
| 906 | |
| 907 | // The first tail loss probe retransmits 1 packet. |
| 908 | manager_.OnRetransmissionTimeout(); |
| 909 | EXPECT_EQ(QuicTime::Delta::Zero(), manager_.TimeUntilSend(clock_.Now())); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 910 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 911 | .WillOnce(WithArgs<1>(Invoke( |
| 912 | [this](TransmissionType type) { RetransmitDataPacket(101, type); }))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 913 | manager_.MaybeRetransmitTailLossProbe(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 914 | EXPECT_CALL(*send_algorithm_, CanSend(_)).WillOnce(Return(false)); |
| 915 | EXPECT_EQ(QuicTime::Delta::Infinite(), manager_.TimeUntilSend(clock_.Now())); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 916 | clock_.AdvanceTime(manager_.GetRetransmissionTime() - clock_.Now()); |
| 917 | |
| 918 | // The second tail loss probe retransmits 1 packet. |
| 919 | manager_.OnRetransmissionTimeout(); |
| 920 | EXPECT_EQ(QuicTime::Delta::Zero(), manager_.TimeUntilSend(clock_.Now())); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 921 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 922 | .WillOnce(WithArgs<1>(Invoke( |
| 923 | [this](TransmissionType type) { RetransmitDataPacket(102, type); }))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 924 | EXPECT_TRUE(manager_.MaybeRetransmitTailLossProbe()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 925 | EXPECT_CALL(*send_algorithm_, CanSend(_)).WillOnce(Return(false)); |
| 926 | EXPECT_EQ(QuicTime::Delta::Infinite(), manager_.TimeUntilSend(clock_.Now())); |
| 927 | |
| 928 | // Ensure the RTO is set based on the correct packet. |
| 929 | rto_packet_time = clock_.Now(); |
| 930 | EXPECT_EQ(rto_packet_time + QuicTime::Delta::FromMilliseconds(500), |
| 931 | manager_.GetRetransmissionTime()); |
| 932 | |
| 933 | // Advance the time enough to ensure all packets are RTO'd. |
| 934 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1000)); |
| 935 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 936 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 937 | .Times(2) |
| 938 | .WillOnce(WithArgs<1>(Invoke( |
| 939 | [this](TransmissionType type) { RetransmitDataPacket(103, type); }))) |
| 940 | .WillOnce(WithArgs<1>(Invoke( |
| 941 | [this](TransmissionType type) { RetransmitDataPacket(104, type); }))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 942 | manager_.OnRetransmissionTimeout(); |
| 943 | EXPECT_EQ(2u, stats_.tlp_count); |
| 944 | EXPECT_EQ(1u, stats_.rto_count); |
fayang | 2a379bf | 2020-05-18 11:49:25 -0700 | [diff] [blame] | 945 | EXPECT_EQ(0u, stats_.max_consecutive_rto_with_forward_progress); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 946 | // There are 2 RTO retransmissions. |
| 947 | EXPECT_EQ(104 * kDefaultLength, manager_.GetBytesInFlight()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 948 | QuicPacketNumber largest_acked = QuicPacketNumber(103); |
| 949 | EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 950 | EXPECT_CALL(*send_algorithm_, |
| 951 | OnCongestionEvent( |
| 952 | true, _, _, Pointwise(PacketNumberEq(), {largest_acked}), _)); |
| 953 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 954 | // Although frames in packet 3 gets acked, it would be kept for another |
| 955 | // RTT. |
| 956 | EXPECT_CALL(notifier_, IsFrameOutstanding(_)).WillRepeatedly(Return(true)); |
| 957 | // Packets [1, 102] are lost, although stream frame in packet 3 is not |
| 958 | // outstanding. |
| 959 | EXPECT_CALL(notifier_, OnFrameLost(_)).Times(102); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 960 | manager_.OnAckFrameStart(QuicPacketNumber(103), QuicTime::Delta::Infinite(), |
| 961 | clock_.Now()); |
| 962 | manager_.OnAckRange(QuicPacketNumber(103), QuicPacketNumber(104)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 963 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 964 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 965 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 966 | // All packets before 103 should be lost. |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 967 | // Packet 104 is still in flight. |
| 968 | EXPECT_EQ(1000u, manager_.GetBytesInFlight()); |
fayang | 2a379bf | 2020-05-18 11:49:25 -0700 | [diff] [blame] | 969 | EXPECT_EQ(1u, stats_.max_consecutive_rto_with_forward_progress); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 970 | } |
| 971 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 972 | TEST_F(QuicSentPacketManagerTest, CryptoHandshakeTimeout) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 973 | // Send 2 crypto packets and 3 data packets. |
| 974 | const size_t kNumSentCryptoPackets = 2; |
| 975 | for (size_t i = 1; i <= kNumSentCryptoPackets; ++i) { |
| 976 | SendCryptoPacket(i); |
| 977 | } |
| 978 | const size_t kNumSentDataPackets = 3; |
| 979 | for (size_t i = 1; i <= kNumSentDataPackets; ++i) { |
| 980 | SendDataPacket(kNumSentCryptoPackets + i); |
| 981 | } |
ianswett | 0cc3680 | 2019-04-20 03:04:09 -0700 | [diff] [blame] | 982 | EXPECT_TRUE(manager_.HasUnackedCryptoPackets()); |
ianswett | 898306b | 2019-04-23 11:05:57 -0700 | [diff] [blame] | 983 | EXPECT_EQ(5 * kDefaultLength, manager_.GetBytesInFlight()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 984 | |
| 985 | // The first retransmits 2 packets. |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 986 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 987 | .Times(2) |
| 988 | .WillOnce(InvokeWithoutArgs([this]() { RetransmitCryptoPacket(6); })) |
| 989 | .WillOnce(InvokeWithoutArgs([this]() { RetransmitCryptoPacket(7); })); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 990 | manager_.OnRetransmissionTimeout(); |
ianswett | 898306b | 2019-04-23 11:05:57 -0700 | [diff] [blame] | 991 | // Expect all 4 handshake packets to be in flight and 3 data packets. |
ianswett | 0400465 | 2019-09-03 18:46:57 -0700 | [diff] [blame] | 992 | EXPECT_EQ(7 * kDefaultLength, manager_.GetBytesInFlight()); |
ianswett | 0cc3680 | 2019-04-20 03:04:09 -0700 | [diff] [blame] | 993 | EXPECT_TRUE(manager_.HasUnackedCryptoPackets()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 994 | |
| 995 | // The second retransmits 2 packets. |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 996 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 997 | .Times(2) |
| 998 | .WillOnce(InvokeWithoutArgs([this]() { RetransmitCryptoPacket(8); })) |
| 999 | .WillOnce(InvokeWithoutArgs([this]() { RetransmitCryptoPacket(9); })); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1000 | manager_.OnRetransmissionTimeout(); |
ianswett | 0400465 | 2019-09-03 18:46:57 -0700 | [diff] [blame] | 1001 | EXPECT_EQ(9 * kDefaultLength, manager_.GetBytesInFlight()); |
ianswett | 0cc3680 | 2019-04-20 03:04:09 -0700 | [diff] [blame] | 1002 | EXPECT_TRUE(manager_.HasUnackedCryptoPackets()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1003 | |
| 1004 | // Now ack the two crypto packets and the speculatively encrypted request, |
| 1005 | // and ensure the first four crypto packets get abandoned, but not lost. |
ianswett | 0400465 | 2019-09-03 18:46:57 -0700 | [diff] [blame] | 1006 | // Crypto packets remain in flight, so any that aren't acked will be lost. |
| 1007 | uint64_t acked[] = {3, 4, 5, 8, 9}; |
| 1008 | uint64_t lost[] = {1, 2, 6}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 1009 | ExpectAcksAndLosses(true, acked, QUICHE_ARRAYSIZE(acked), lost, |
| 1010 | QUICHE_ARRAYSIZE(lost)); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1011 | EXPECT_CALL(notifier_, OnFrameLost(_)).Times(3); |
| 1012 | EXPECT_CALL(notifier_, HasUnackedCryptoData()).WillRepeatedly(Return(false)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1013 | manager_.OnAckFrameStart(QuicPacketNumber(9), QuicTime::Delta::Infinite(), |
| 1014 | clock_.Now()); |
| 1015 | manager_.OnAckRange(QuicPacketNumber(8), QuicPacketNumber(10)); |
| 1016 | manager_.OnAckRange(QuicPacketNumber(3), QuicPacketNumber(6)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 1017 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 1018 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 1019 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1020 | |
ianswett | 0cc3680 | 2019-04-20 03:04:09 -0700 | [diff] [blame] | 1021 | EXPECT_FALSE(manager_.HasUnackedCryptoPackets()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1022 | } |
| 1023 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1024 | TEST_F(QuicSentPacketManagerTest, CryptoHandshakeTimeoutVersionNegotiation) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1025 | // Send 2 crypto packets and 3 data packets. |
| 1026 | const size_t kNumSentCryptoPackets = 2; |
| 1027 | for (size_t i = 1; i <= kNumSentCryptoPackets; ++i) { |
| 1028 | SendCryptoPacket(i); |
| 1029 | } |
| 1030 | const size_t kNumSentDataPackets = 3; |
| 1031 | for (size_t i = 1; i <= kNumSentDataPackets; ++i) { |
| 1032 | SendDataPacket(kNumSentCryptoPackets + i); |
| 1033 | } |
ianswett | 0cc3680 | 2019-04-20 03:04:09 -0700 | [diff] [blame] | 1034 | EXPECT_TRUE(manager_.HasUnackedCryptoPackets()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1035 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1036 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 1037 | .Times(2) |
| 1038 | .WillOnce(InvokeWithoutArgs([this]() { RetransmitCryptoPacket(6); })) |
| 1039 | .WillOnce(InvokeWithoutArgs([this]() { RetransmitCryptoPacket(7); })); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1040 | manager_.OnRetransmissionTimeout(); |
ianswett | 0cc3680 | 2019-04-20 03:04:09 -0700 | [diff] [blame] | 1041 | EXPECT_TRUE(manager_.HasUnackedCryptoPackets()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1042 | |
| 1043 | // Now act like a version negotiation packet arrived, which would cause all |
| 1044 | // unacked packets to be retransmitted. |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1045 | // Mark packets [1, 7] lost. And the frames in 6 and 7 are same as packets 1 |
| 1046 | // and 2, respectively. |
| 1047 | EXPECT_CALL(notifier_, OnFrameLost(_)).Times(7); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1048 | manager_.RetransmitUnackedPackets(ALL_UNACKED_RETRANSMISSION); |
| 1049 | |
| 1050 | // Ensure the first two pending packets are the crypto retransmits. |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1051 | RetransmitCryptoPacket(8); |
| 1052 | RetransmitCryptoPacket(9); |
| 1053 | RetransmitDataPacket(10, ALL_UNACKED_RETRANSMISSION); |
| 1054 | RetransmitDataPacket(11, ALL_UNACKED_RETRANSMISSION); |
| 1055 | RetransmitDataPacket(12, ALL_UNACKED_RETRANSMISSION); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1056 | |
| 1057 | EXPECT_EQ(QuicPacketNumber(1u), manager_.GetLeastUnacked()); |
| 1058 | // Least unacked isn't raised until an ack is received, so ack the |
| 1059 | // crypto packets. |
| 1060 | uint64_t acked[] = {8, 9}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 1061 | ExpectAcksAndLosses(true, acked, QUICHE_ARRAYSIZE(acked), nullptr, 0); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1062 | manager_.OnAckFrameStart(QuicPacketNumber(9), QuicTime::Delta::Infinite(), |
| 1063 | clock_.Now()); |
| 1064 | manager_.OnAckRange(QuicPacketNumber(8), QuicPacketNumber(10)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 1065 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 1066 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 1067 | ENCRYPTION_INITIAL)); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1068 | EXPECT_CALL(notifier_, HasUnackedCryptoData()).WillRepeatedly(Return(false)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1069 | EXPECT_EQ(QuicPacketNumber(10u), manager_.GetLeastUnacked()); |
| 1070 | } |
| 1071 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1072 | TEST_F(QuicSentPacketManagerTest, CryptoHandshakeSpuriousRetransmission) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1073 | // Send 1 crypto packet. |
| 1074 | SendCryptoPacket(1); |
ianswett | 0cc3680 | 2019-04-20 03:04:09 -0700 | [diff] [blame] | 1075 | EXPECT_TRUE(manager_.HasUnackedCryptoPackets()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1076 | |
| 1077 | // Retransmit the crypto packet as 2. |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1078 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 1079 | .WillOnce(InvokeWithoutArgs([this]() { RetransmitCryptoPacket(2); })); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1080 | manager_.OnRetransmissionTimeout(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1081 | |
| 1082 | // Retransmit the crypto packet as 3. |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1083 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 1084 | .WillOnce(InvokeWithoutArgs([this]() { RetransmitCryptoPacket(3); })); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1085 | manager_.OnRetransmissionTimeout(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1086 | |
| 1087 | // Now ack the second crypto packet, and ensure the first gets removed, but |
| 1088 | // the third does not. |
| 1089 | uint64_t acked[] = {2}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 1090 | ExpectAcksAndLosses(true, acked, QUICHE_ARRAYSIZE(acked), nullptr, 0); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1091 | EXPECT_CALL(notifier_, HasUnackedCryptoData()).WillRepeatedly(Return(false)); |
| 1092 | EXPECT_CALL(notifier_, IsFrameOutstanding(_)).WillRepeatedly(Return(false)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1093 | manager_.OnAckFrameStart(QuicPacketNumber(2), QuicTime::Delta::Infinite(), |
| 1094 | clock_.Now()); |
| 1095 | manager_.OnAckRange(QuicPacketNumber(2), QuicPacketNumber(3)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 1096 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 1097 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 1098 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1099 | |
ianswett | 0cc3680 | 2019-04-20 03:04:09 -0700 | [diff] [blame] | 1100 | EXPECT_FALSE(manager_.HasUnackedCryptoPackets()); |
ianswett | 0400465 | 2019-09-03 18:46:57 -0700 | [diff] [blame] | 1101 | uint64_t unacked[] = {1, 3}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 1102 | VerifyUnackedPackets(unacked, QUICHE_ARRAYSIZE(unacked)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1103 | } |
| 1104 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1105 | TEST_F(QuicSentPacketManagerTest, CryptoHandshakeTimeoutUnsentDataPacket) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1106 | // Send 2 crypto packets and 1 data packet. |
| 1107 | const size_t kNumSentCryptoPackets = 2; |
| 1108 | for (size_t i = 1; i <= kNumSentCryptoPackets; ++i) { |
| 1109 | SendCryptoPacket(i); |
| 1110 | } |
| 1111 | SendDataPacket(3); |
ianswett | 0cc3680 | 2019-04-20 03:04:09 -0700 | [diff] [blame] | 1112 | EXPECT_TRUE(manager_.HasUnackedCryptoPackets()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1113 | |
| 1114 | // Retransmit 2 crypto packets, but not the serialized packet. |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1115 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 1116 | .Times(2) |
| 1117 | .WillOnce(InvokeWithoutArgs([this]() { RetransmitCryptoPacket(4); })) |
| 1118 | .WillOnce(InvokeWithoutArgs([this]() { RetransmitCryptoPacket(5); })); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1119 | manager_.OnRetransmissionTimeout(); |
ianswett | 0cc3680 | 2019-04-20 03:04:09 -0700 | [diff] [blame] | 1120 | EXPECT_TRUE(manager_.HasUnackedCryptoPackets()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1121 | } |
| 1122 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1123 | TEST_F(QuicSentPacketManagerTest, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1124 | CryptoHandshakeRetransmissionThenRetransmitAll) { |
| 1125 | // Send 1 crypto packet. |
| 1126 | SendCryptoPacket(1); |
| 1127 | |
ianswett | 0cc3680 | 2019-04-20 03:04:09 -0700 | [diff] [blame] | 1128 | EXPECT_TRUE(manager_.HasUnackedCryptoPackets()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1129 | |
| 1130 | // Retransmit the crypto packet as 2. |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1131 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 1132 | .WillOnce(InvokeWithoutArgs([this]() { RetransmitCryptoPacket(2); })); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1133 | manager_.OnRetransmissionTimeout(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1134 | // Now retransmit all the unacked packets, which occurs when there is a |
| 1135 | // version negotiation. |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1136 | EXPECT_CALL(notifier_, OnFrameLost(_)).Times(2); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1137 | manager_.RetransmitUnackedPackets(ALL_UNACKED_RETRANSMISSION); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1138 | // Both packets 1 and 2 are unackable. |
| 1139 | EXPECT_FALSE(manager_.unacked_packets().IsUnacked(QuicPacketNumber(1))); |
| 1140 | EXPECT_FALSE(manager_.unacked_packets().IsUnacked(QuicPacketNumber(2))); |
ianswett | 0cc3680 | 2019-04-20 03:04:09 -0700 | [diff] [blame] | 1141 | EXPECT_TRUE(manager_.HasUnackedCryptoPackets()); |
ianswett | 67d7a3c | 2019-04-19 10:58:47 -0700 | [diff] [blame] | 1142 | EXPECT_FALSE(manager_.HasInFlightPackets()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1143 | } |
| 1144 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1145 | TEST_F(QuicSentPacketManagerTest, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1146 | CryptoHandshakeRetransmissionThenNeuterAndAck) { |
| 1147 | // Send 1 crypto packet. |
| 1148 | SendCryptoPacket(1); |
| 1149 | |
ianswett | 0cc3680 | 2019-04-20 03:04:09 -0700 | [diff] [blame] | 1150 | EXPECT_TRUE(manager_.HasUnackedCryptoPackets()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1151 | |
| 1152 | // Retransmit the crypto packet as 2. |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1153 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 1154 | .WillOnce(InvokeWithoutArgs([this]() { RetransmitCryptoPacket(2); })); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1155 | manager_.OnRetransmissionTimeout(); |
ianswett | 0cc3680 | 2019-04-20 03:04:09 -0700 | [diff] [blame] | 1156 | EXPECT_TRUE(manager_.HasUnackedCryptoPackets()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1157 | |
| 1158 | // Retransmit the crypto packet as 3. |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1159 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 1160 | .WillOnce(InvokeWithoutArgs([this]() { RetransmitCryptoPacket(3); })); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1161 | manager_.OnRetransmissionTimeout(); |
ianswett | 0cc3680 | 2019-04-20 03:04:09 -0700 | [diff] [blame] | 1162 | EXPECT_TRUE(manager_.HasUnackedCryptoPackets()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1163 | |
| 1164 | // Now neuter all unacked unencrypted packets, which occurs when the |
| 1165 | // connection goes forward secure. |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1166 | EXPECT_CALL(notifier_, HasUnackedCryptoData()).WillRepeatedly(Return(false)); |
| 1167 | EXPECT_CALL(notifier_, IsFrameOutstanding(_)).WillRepeatedly(Return(false)); |
fayang | 93c8394 | 2019-11-07 10:41:16 -0800 | [diff] [blame] | 1168 | manager_.NeuterUnencryptedPackets(); |
ianswett | 0cc3680 | 2019-04-20 03:04:09 -0700 | [diff] [blame] | 1169 | EXPECT_FALSE(manager_.HasUnackedCryptoPackets()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1170 | uint64_t unacked[] = {1, 2, 3}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 1171 | VerifyUnackedPackets(unacked, QUICHE_ARRAYSIZE(unacked)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1172 | VerifyRetransmittablePackets(nullptr, 0); |
ianswett | 0cc3680 | 2019-04-20 03:04:09 -0700 | [diff] [blame] | 1173 | EXPECT_FALSE(manager_.HasUnackedCryptoPackets()); |
ianswett | 67d7a3c | 2019-04-19 10:58:47 -0700 | [diff] [blame] | 1174 | EXPECT_FALSE(manager_.HasInFlightPackets()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1175 | |
| 1176 | // Ensure both packets get discarded when packet 2 is acked. |
| 1177 | uint64_t acked[] = {3}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 1178 | ExpectAcksAndLosses(true, acked, QUICHE_ARRAYSIZE(acked), nullptr, 0); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1179 | manager_.OnAckFrameStart(QuicPacketNumber(3), QuicTime::Delta::Infinite(), |
| 1180 | clock_.Now()); |
| 1181 | manager_.OnAckRange(QuicPacketNumber(3), QuicPacketNumber(4)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 1182 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 1183 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 1184 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1185 | VerifyUnackedPackets(nullptr, 0); |
| 1186 | VerifyRetransmittablePackets(nullptr, 0); |
| 1187 | } |
| 1188 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1189 | TEST_F(QuicSentPacketManagerTest, RetransmissionTimeout) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 1190 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 1191 | return; |
| 1192 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1193 | StrictMock<MockDebugDelegate> debug_delegate; |
| 1194 | manager_.SetDebugDelegate(&debug_delegate); |
| 1195 | |
| 1196 | // Send 100 packets. |
| 1197 | const size_t kNumSentPackets = 100; |
| 1198 | for (size_t i = 1; i <= kNumSentPackets; ++i) { |
| 1199 | SendDataPacket(i); |
| 1200 | } |
| 1201 | |
| 1202 | EXPECT_FALSE(manager_.MaybeRetransmitTailLossProbe()); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1203 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 1204 | .Times(2) |
| 1205 | .WillOnce(WithArgs<1>(Invoke( |
| 1206 | [this](TransmissionType type) { RetransmitDataPacket(101, type); }))) |
| 1207 | .WillOnce(WithArgs<1>(Invoke( |
| 1208 | [this](TransmissionType type) { RetransmitDataPacket(102, type); }))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1209 | manager_.OnRetransmissionTimeout(); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1210 | EXPECT_EQ(102 * kDefaultLength, manager_.GetBytesInFlight()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1211 | |
| 1212 | // Ack a retransmission. |
| 1213 | // Ensure no packets are lost. |
| 1214 | QuicPacketNumber largest_acked = QuicPacketNumber(102); |
| 1215 | EXPECT_CALL(*send_algorithm_, |
| 1216 | OnCongestionEvent(true, _, _, |
| 1217 | Pointwise(PacketNumberEq(), {largest_acked}), |
| 1218 | /*lost_packets=*/IsEmpty())); |
| 1219 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 1220 | EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1221 | // RTO's use loss detection instead of immediately declaring retransmitted |
| 1222 | // packets lost. |
| 1223 | for (int i = 1; i <= 99; ++i) { |
| 1224 | EXPECT_CALL(debug_delegate, |
vasilvv | 923b6d2 | 2020-03-23 11:17:58 -0700 | [diff] [blame] | 1225 | OnPacketLoss(QuicPacketNumber(i), _, LOSS_RETRANSMISSION, _)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1226 | } |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1227 | EXPECT_CALL(notifier_, IsFrameOutstanding(_)).WillRepeatedly(Return(true)); |
| 1228 | // Packets [1, 99] are considered as lost, although stream frame in packet |
| 1229 | // 2 is not outstanding. |
| 1230 | EXPECT_CALL(notifier_, OnFrameLost(_)).Times(99); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1231 | manager_.OnAckFrameStart(QuicPacketNumber(102), QuicTime::Delta::Zero(), |
| 1232 | clock_.Now()); |
| 1233 | manager_.OnAckRange(QuicPacketNumber(102), QuicPacketNumber(103)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 1234 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 1235 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 1236 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1237 | } |
| 1238 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1239 | TEST_F(QuicSentPacketManagerTest, RetransmissionTimeoutOnePacket) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 1240 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 1241 | return; |
| 1242 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1243 | // Set the 1RTO connection option. |
| 1244 | QuicConfig client_config; |
| 1245 | QuicTagVector options; |
| 1246 | options.push_back(k1RTO); |
| 1247 | QuicSentPacketManagerPeer::SetPerspective(&manager_, Perspective::IS_CLIENT); |
| 1248 | client_config.SetConnectionOptionsToSend(options); |
| 1249 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 1250 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 1251 | EXPECT_CALL(*send_algorithm_, PacingRate(_)) |
| 1252 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
| 1253 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
| 1254 | .WillRepeatedly(Return(10 * kDefaultTCPMSS)); |
| 1255 | manager_.SetFromConfig(client_config); |
| 1256 | EXPECT_CALL(*send_algorithm_, CanSend(_)).WillRepeatedly(Return(true)); |
| 1257 | |
| 1258 | StrictMock<MockDebugDelegate> debug_delegate; |
| 1259 | manager_.SetDebugDelegate(&debug_delegate); |
| 1260 | |
| 1261 | // Send 100 packets. |
| 1262 | const size_t kNumSentPackets = 100; |
| 1263 | for (size_t i = 1; i <= kNumSentPackets; ++i) { |
| 1264 | SendDataPacket(i); |
| 1265 | } |
| 1266 | |
| 1267 | EXPECT_FALSE(manager_.MaybeRetransmitTailLossProbe()); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1268 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 1269 | .Times(1) |
| 1270 | .WillOnce(WithArgs<1>(Invoke( |
| 1271 | [this](TransmissionType type) { RetransmitDataPacket(101, type); }))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1272 | manager_.OnRetransmissionTimeout(); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1273 | EXPECT_EQ(101 * kDefaultLength, manager_.GetBytesInFlight()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1274 | } |
| 1275 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1276 | TEST_F(QuicSentPacketManagerTest, NewRetransmissionTimeout) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 1277 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 1278 | return; |
| 1279 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1280 | QuicConfig client_config; |
| 1281 | QuicTagVector options; |
| 1282 | options.push_back(kNRTO); |
| 1283 | QuicSentPacketManagerPeer::SetPerspective(&manager_, Perspective::IS_CLIENT); |
| 1284 | client_config.SetConnectionOptionsToSend(options); |
| 1285 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 1286 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 1287 | EXPECT_CALL(*send_algorithm_, PacingRate(_)) |
| 1288 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
| 1289 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
| 1290 | .WillRepeatedly(Return(10 * kDefaultTCPMSS)); |
| 1291 | manager_.SetFromConfig(client_config); |
| 1292 | EXPECT_TRUE(QuicSentPacketManagerPeer::GetUseNewRto(&manager_)); |
| 1293 | EXPECT_CALL(*send_algorithm_, CanSend(_)).WillRepeatedly(Return(true)); |
| 1294 | |
| 1295 | // Send 100 packets. |
| 1296 | const size_t kNumSentPackets = 100; |
| 1297 | for (size_t i = 1; i <= kNumSentPackets; ++i) { |
| 1298 | SendDataPacket(i); |
| 1299 | } |
| 1300 | |
| 1301 | EXPECT_FALSE(manager_.MaybeRetransmitTailLossProbe()); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1302 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 1303 | .Times(2) |
| 1304 | .WillOnce(WithArgs<1>(Invoke( |
| 1305 | [this](TransmissionType type) { RetransmitDataPacket(101, type); }))) |
| 1306 | .WillOnce(WithArgs<1>(Invoke( |
| 1307 | [this](TransmissionType type) { RetransmitDataPacket(102, type); }))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1308 | manager_.OnRetransmissionTimeout(); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1309 | EXPECT_EQ(102 * kDefaultLength, manager_.GetBytesInFlight()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1310 | |
| 1311 | // Ack a retransmission and expect no call to OnRetransmissionTimeout. |
| 1312 | // This will include packets in the lost packet map. |
| 1313 | QuicPacketNumber largest_acked = QuicPacketNumber(102); |
| 1314 | EXPECT_CALL(*send_algorithm_, |
| 1315 | OnCongestionEvent(true, _, _, |
| 1316 | Pointwise(PacketNumberEq(), {largest_acked}), |
| 1317 | /*lost_packets=*/Not(IsEmpty()))); |
| 1318 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1319 | EXPECT_CALL(notifier_, IsFrameOutstanding(_)).WillRepeatedly(Return(true)); |
| 1320 | // Packets [1, 99] are considered as lost, although stream frame in packet |
| 1321 | // 2 is not outstanding. |
| 1322 | EXPECT_CALL(notifier_, OnFrameLost(_)).Times(99); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1323 | manager_.OnAckFrameStart(QuicPacketNumber(102), QuicTime::Delta::Zero(), |
| 1324 | clock_.Now()); |
| 1325 | manager_.OnAckRange(QuicPacketNumber(102), QuicPacketNumber(103)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 1326 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 1327 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 1328 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1329 | } |
| 1330 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1331 | TEST_F(QuicSentPacketManagerTest, TwoRetransmissionTimeoutsAckSecond) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 1332 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 1333 | return; |
| 1334 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1335 | // Send 1 packet. |
| 1336 | SendDataPacket(1); |
| 1337 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1338 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 1339 | .WillOnce(WithArgs<1>(Invoke( |
| 1340 | [this](TransmissionType type) { RetransmitDataPacket(2, type); }))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1341 | manager_.OnRetransmissionTimeout(); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1342 | EXPECT_EQ(2 * kDefaultLength, manager_.GetBytesInFlight()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1343 | |
| 1344 | // Rto a second time. |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1345 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 1346 | .WillOnce(WithArgs<1>(Invoke( |
| 1347 | [this](TransmissionType type) { RetransmitDataPacket(3, type); }))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1348 | manager_.OnRetransmissionTimeout(); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1349 | EXPECT_EQ(3 * kDefaultLength, manager_.GetBytesInFlight()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1350 | |
| 1351 | // Ack a retransmission and ensure OnRetransmissionTimeout is called. |
| 1352 | EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1353 | ExpectAck(2); |
| 1354 | manager_.OnAckFrameStart(QuicPacketNumber(2), QuicTime::Delta::Zero(), |
| 1355 | clock_.Now()); |
| 1356 | manager_.OnAckRange(QuicPacketNumber(2), QuicPacketNumber(3)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 1357 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 1358 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 1359 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1360 | |
| 1361 | // The original packet and newest should be outstanding. |
ianswett | 9f459cb | 2019-04-21 06:39:59 -0700 | [diff] [blame] | 1362 | EXPECT_EQ(2 * kDefaultLength, manager_.GetBytesInFlight()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1363 | } |
| 1364 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1365 | TEST_F(QuicSentPacketManagerTest, TwoRetransmissionTimeoutsAckFirst) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 1366 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 1367 | return; |
| 1368 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1369 | // Send 1 packet. |
| 1370 | SendDataPacket(1); |
| 1371 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1372 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 1373 | .WillOnce(WithArgs<1>(Invoke( |
| 1374 | [this](TransmissionType type) { RetransmitDataPacket(2, type); }))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1375 | manager_.OnRetransmissionTimeout(); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1376 | EXPECT_EQ(2 * kDefaultLength, manager_.GetBytesInFlight()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1377 | |
| 1378 | // Rto a second time. |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1379 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 1380 | .WillOnce(WithArgs<1>(Invoke( |
| 1381 | [this](TransmissionType type) { RetransmitDataPacket(3, type); }))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1382 | manager_.OnRetransmissionTimeout(); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1383 | EXPECT_EQ(3 * kDefaultLength, manager_.GetBytesInFlight()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1384 | |
| 1385 | // Ack a retransmission and ensure OnRetransmissionTimeout is called. |
| 1386 | EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1387 | ExpectAck(3); |
| 1388 | manager_.OnAckFrameStart(QuicPacketNumber(3), QuicTime::Delta::Zero(), |
| 1389 | clock_.Now()); |
| 1390 | manager_.OnAckRange(QuicPacketNumber(3), QuicPacketNumber(4)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 1391 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 1392 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 1393 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1394 | |
| 1395 | // The first two packets should still be outstanding. |
ianswett | 9f459cb | 2019-04-21 06:39:59 -0700 | [diff] [blame] | 1396 | EXPECT_EQ(2 * kDefaultLength, manager_.GetBytesInFlight()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1397 | } |
| 1398 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1399 | TEST_F(QuicSentPacketManagerTest, GetTransmissionTime) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1400 | EXPECT_EQ(QuicTime::Zero(), manager_.GetRetransmissionTime()); |
| 1401 | } |
| 1402 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1403 | TEST_F(QuicSentPacketManagerTest, GetTransmissionTimeCryptoHandshake) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1404 | QuicTime crypto_packet_send_time = clock_.Now(); |
| 1405 | SendCryptoPacket(1); |
| 1406 | |
| 1407 | // Check the min. |
| 1408 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 1409 | rtt_stats->set_initial_rtt(QuicTime::Delta::FromMilliseconds(1)); |
| 1410 | EXPECT_EQ(clock_.Now() + QuicTime::Delta::FromMilliseconds(10), |
| 1411 | manager_.GetRetransmissionTime()); |
| 1412 | |
| 1413 | // Test with a standard smoothed RTT. |
| 1414 | rtt_stats->set_initial_rtt(QuicTime::Delta::FromMilliseconds(100)); |
| 1415 | |
| 1416 | QuicTime::Delta srtt = rtt_stats->initial_rtt(); |
| 1417 | QuicTime expected_time = clock_.Now() + 1.5 * srtt; |
| 1418 | EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); |
| 1419 | |
| 1420 | // Retransmit the packet by invoking the retransmission timeout. |
| 1421 | clock_.AdvanceTime(1.5 * srtt); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1422 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 1423 | .WillOnce(InvokeWithoutArgs([this]() { RetransmitCryptoPacket(2); })); |
| 1424 | // When session decides what to write, crypto_packet_send_time gets updated. |
| 1425 | crypto_packet_send_time = clock_.Now(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1426 | manager_.OnRetransmissionTimeout(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1427 | |
| 1428 | // The retransmission time should now be twice as far in the future. |
| 1429 | expected_time = crypto_packet_send_time + srtt * 2 * 1.5; |
| 1430 | EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); |
| 1431 | |
| 1432 | // Retransmit the packet for the 2nd time. |
| 1433 | clock_.AdvanceTime(2 * 1.5 * srtt); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1434 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 1435 | .WillOnce(InvokeWithoutArgs([this]() { RetransmitCryptoPacket(3); })); |
| 1436 | // When session decides what to write, crypto_packet_send_time gets updated. |
| 1437 | crypto_packet_send_time = clock_.Now(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1438 | manager_.OnRetransmissionTimeout(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1439 | |
| 1440 | // Verify exponential backoff of the retransmission timeout. |
| 1441 | expected_time = crypto_packet_send_time + srtt * 4 * 1.5; |
| 1442 | EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); |
| 1443 | } |
| 1444 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1445 | TEST_F(QuicSentPacketManagerTest, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1446 | GetConservativeTransmissionTimeCryptoHandshake) { |
| 1447 | QuicConfig config; |
| 1448 | QuicTagVector options; |
| 1449 | options.push_back(kCONH); |
| 1450 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 1451 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 1452 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 1453 | manager_.SetFromConfig(config); |
| 1454 | // Calling SetFromConfig requires mocking out some send algorithm methods. |
| 1455 | EXPECT_CALL(*send_algorithm_, PacingRate(_)) |
| 1456 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
| 1457 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
| 1458 | .WillRepeatedly(Return(10 * kDefaultTCPMSS)); |
| 1459 | |
| 1460 | QuicTime crypto_packet_send_time = clock_.Now(); |
| 1461 | SendCryptoPacket(1); |
| 1462 | |
| 1463 | // Check the min. |
| 1464 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 1465 | rtt_stats->set_initial_rtt(QuicTime::Delta::FromMilliseconds(1)); |
| 1466 | EXPECT_EQ(clock_.Now() + QuicTime::Delta::FromMilliseconds(25), |
| 1467 | manager_.GetRetransmissionTime()); |
| 1468 | |
| 1469 | // Test with a standard smoothed RTT. |
| 1470 | rtt_stats->set_initial_rtt(QuicTime::Delta::FromMilliseconds(100)); |
| 1471 | |
| 1472 | QuicTime::Delta srtt = rtt_stats->initial_rtt(); |
| 1473 | QuicTime expected_time = clock_.Now() + 2 * srtt; |
| 1474 | EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); |
| 1475 | |
| 1476 | // Retransmit the packet by invoking the retransmission timeout. |
| 1477 | clock_.AdvanceTime(2 * srtt); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1478 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 1479 | .WillOnce(InvokeWithoutArgs([this]() { RetransmitCryptoPacket(2); })); |
| 1480 | crypto_packet_send_time = clock_.Now(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1481 | manager_.OnRetransmissionTimeout(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1482 | |
| 1483 | // The retransmission time should now be twice as far in the future. |
| 1484 | expected_time = crypto_packet_send_time + srtt * 2 * 2; |
| 1485 | EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); |
| 1486 | } |
| 1487 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1488 | TEST_F(QuicSentPacketManagerTest, GetTransmissionTimeTailLossProbe) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 1489 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 1490 | return; |
| 1491 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1492 | QuicSentPacketManagerPeer::SetMaxTailLossProbes(&manager_, 2); |
| 1493 | SendDataPacket(1); |
| 1494 | SendDataPacket(2); |
| 1495 | |
| 1496 | // Check the min. |
| 1497 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 1498 | rtt_stats->set_initial_rtt(QuicTime::Delta::FromMilliseconds(1)); |
| 1499 | EXPECT_EQ(clock_.Now() + QuicTime::Delta::FromMilliseconds(10), |
| 1500 | manager_.GetRetransmissionTime()); |
| 1501 | |
| 1502 | // Test with a standard smoothed RTT. |
| 1503 | rtt_stats->set_initial_rtt(QuicTime::Delta::FromMilliseconds(100)); |
| 1504 | QuicTime::Delta srtt = rtt_stats->initial_rtt(); |
| 1505 | QuicTime::Delta expected_tlp_delay = 2 * srtt; |
| 1506 | QuicTime expected_time = clock_.Now() + expected_tlp_delay; |
| 1507 | EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); |
| 1508 | |
| 1509 | // Retransmit the packet by invoking the retransmission timeout. |
| 1510 | clock_.AdvanceTime(expected_tlp_delay); |
| 1511 | manager_.OnRetransmissionTimeout(); |
| 1512 | EXPECT_EQ(QuicTime::Delta::Zero(), manager_.TimeUntilSend(clock_.Now())); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1513 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 1514 | .WillOnce(WithArgs<1>(Invoke( |
| 1515 | [this](TransmissionType type) { RetransmitDataPacket(3, type); }))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1516 | EXPECT_TRUE(manager_.MaybeRetransmitTailLossProbe()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1517 | EXPECT_CALL(*send_algorithm_, CanSend(_)).WillOnce(Return(false)); |
| 1518 | EXPECT_EQ(QuicTime::Delta::Infinite(), manager_.TimeUntilSend(clock_.Now())); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1519 | |
| 1520 | expected_time = clock_.Now() + expected_tlp_delay; |
| 1521 | EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); |
| 1522 | } |
| 1523 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1524 | TEST_F(QuicSentPacketManagerTest, TLPRWithPendingStreamData) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 1525 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 1526 | return; |
| 1527 | } |
zhongyi | 1b2f783 | 2019-06-14 13:31:34 -0700 | [diff] [blame] | 1528 | QuicConfig config; |
| 1529 | QuicTagVector options; |
| 1530 | |
| 1531 | options.push_back(kTLPR); |
| 1532 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 1533 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 1534 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 1535 | EXPECT_CALL(*send_algorithm_, PacingRate(_)) |
| 1536 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
| 1537 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
| 1538 | .WillOnce(Return(10 * kDefaultTCPMSS)); |
| 1539 | manager_.SetFromConfig(config); |
| 1540 | EXPECT_TRUE( |
| 1541 | QuicSentPacketManagerPeer::GetEnableHalfRttTailLossProbe(&manager_)); |
| 1542 | |
| 1543 | QuicSentPacketManagerPeer::SetMaxTailLossProbes(&manager_, 2); |
| 1544 | |
| 1545 | SendDataPacket(1); |
| 1546 | SendDataPacket(2); |
| 1547 | |
| 1548 | // Test with a standard smoothed RTT. |
| 1549 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 1550 | rtt_stats->set_initial_rtt(QuicTime::Delta::FromMilliseconds(100)); |
| 1551 | QuicTime::Delta srtt = rtt_stats->initial_rtt(); |
| 1552 | // With pending stream data, TLPR is used. |
| 1553 | QuicTime::Delta expected_tlp_delay = 0.5 * srtt; |
| 1554 | EXPECT_CALL(notifier_, HasUnackedStreamData()).WillRepeatedly(Return(true)); |
| 1555 | |
| 1556 | EXPECT_EQ(expected_tlp_delay, |
| 1557 | manager_.GetRetransmissionTime() - clock_.Now()); |
| 1558 | |
| 1559 | // Retransmit the packet by invoking the retransmission timeout. |
| 1560 | clock_.AdvanceTime(expected_tlp_delay); |
| 1561 | manager_.OnRetransmissionTimeout(); |
| 1562 | EXPECT_EQ(QuicTime::Delta::Zero(), manager_.TimeUntilSend(clock_.Now())); |
zhongyi | 1b2f783 | 2019-06-14 13:31:34 -0700 | [diff] [blame] | 1563 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 1564 | .WillOnce(WithArgs<1>(Invoke( |
| 1565 | [this](TransmissionType type) { RetransmitDataPacket(3, type); }))); |
| 1566 | EXPECT_TRUE(manager_.MaybeRetransmitTailLossProbe()); |
| 1567 | |
| 1568 | EXPECT_CALL(*send_algorithm_, CanSend(_)).WillOnce(Return(false)); |
| 1569 | EXPECT_EQ(QuicTime::Delta::Infinite(), manager_.TimeUntilSend(clock_.Now())); |
zhongyi | 1b2f783 | 2019-06-14 13:31:34 -0700 | [diff] [blame] | 1570 | |
| 1571 | // 2nd TLP. |
| 1572 | expected_tlp_delay = 2 * srtt; |
| 1573 | EXPECT_EQ(expected_tlp_delay, |
| 1574 | manager_.GetRetransmissionTime() - clock_.Now()); |
| 1575 | } |
| 1576 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1577 | TEST_F(QuicSentPacketManagerTest, TLPRWithoutPendingStreamData) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 1578 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 1579 | return; |
| 1580 | } |
zhongyi | 1b2f783 | 2019-06-14 13:31:34 -0700 | [diff] [blame] | 1581 | QuicConfig config; |
| 1582 | QuicTagVector options; |
| 1583 | |
| 1584 | options.push_back(kTLPR); |
| 1585 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 1586 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 1587 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 1588 | EXPECT_CALL(*send_algorithm_, PacingRate(_)) |
| 1589 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
| 1590 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
| 1591 | .WillOnce(Return(10 * kDefaultTCPMSS)); |
| 1592 | manager_.SetFromConfig(config); |
| 1593 | EXPECT_TRUE( |
| 1594 | QuicSentPacketManagerPeer::GetEnableHalfRttTailLossProbe(&manager_)); |
| 1595 | QuicSentPacketManagerPeer::SetMaxTailLossProbes(&manager_, 2); |
| 1596 | |
| 1597 | SendPingPacket(1, ENCRYPTION_INITIAL); |
| 1598 | SendPingPacket(2, ENCRYPTION_INITIAL); |
| 1599 | |
| 1600 | // Test with a standard smoothed RTT. |
| 1601 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 1602 | rtt_stats->set_initial_rtt(QuicTime::Delta::FromMilliseconds(100)); |
| 1603 | QuicTime::Delta srtt = rtt_stats->initial_rtt(); |
| 1604 | QuicTime::Delta expected_tlp_delay = 0.5 * srtt; |
zhongyi | 9fa2be3 | 2019-09-10 12:39:01 -0700 | [diff] [blame] | 1605 | // With no pending stream data, TLPR is ignored. |
| 1606 | expected_tlp_delay = 2 * srtt; |
zhongyi | 1b2f783 | 2019-06-14 13:31:34 -0700 | [diff] [blame] | 1607 | EXPECT_CALL(notifier_, HasUnackedStreamData()).WillRepeatedly(Return(false)); |
| 1608 | EXPECT_EQ(expected_tlp_delay, |
| 1609 | manager_.GetRetransmissionTime() - clock_.Now()); |
| 1610 | |
| 1611 | // Retransmit the packet by invoking the retransmission timeout. |
| 1612 | clock_.AdvanceTime(expected_tlp_delay); |
| 1613 | manager_.OnRetransmissionTimeout(); |
| 1614 | EXPECT_EQ(QuicTime::Delta::Zero(), manager_.TimeUntilSend(clock_.Now())); |
zhongyi | 1b2f783 | 2019-06-14 13:31:34 -0700 | [diff] [blame] | 1615 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 1616 | .WillOnce(WithArgs<1>(Invoke( |
| 1617 | [this](TransmissionType type) { RetransmitDataPacket(3, type); }))); |
| 1618 | EXPECT_TRUE(manager_.MaybeRetransmitTailLossProbe()); |
| 1619 | EXPECT_CALL(*send_algorithm_, CanSend(_)).WillOnce(Return(false)); |
| 1620 | EXPECT_EQ(QuicTime::Delta::Infinite(), manager_.TimeUntilSend(clock_.Now())); |
zhongyi | 1b2f783 | 2019-06-14 13:31:34 -0700 | [diff] [blame] | 1621 | |
| 1622 | // 2nd TLP. |
| 1623 | expected_tlp_delay = 2 * srtt; |
| 1624 | EXPECT_EQ(expected_tlp_delay, |
| 1625 | manager_.GetRetransmissionTime() - clock_.Now()); |
| 1626 | } |
| 1627 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1628 | TEST_F(QuicSentPacketManagerTest, GetTransmissionTimeSpuriousRTO) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 1629 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 1630 | return; |
| 1631 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1632 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 1633 | rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(100), |
| 1634 | QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 1635 | |
| 1636 | SendDataPacket(1); |
| 1637 | SendDataPacket(2); |
| 1638 | SendDataPacket(3); |
| 1639 | SendDataPacket(4); |
| 1640 | |
| 1641 | QuicTime::Delta expected_rto_delay = |
| 1642 | rtt_stats->smoothed_rtt() + 4 * rtt_stats->mean_deviation(); |
| 1643 | QuicTime expected_time = clock_.Now() + expected_rto_delay; |
| 1644 | EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); |
| 1645 | |
| 1646 | // Retransmit the packet by invoking the retransmission timeout. |
| 1647 | clock_.AdvanceTime(expected_rto_delay); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1648 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 1649 | .Times(2) |
| 1650 | .WillOnce(WithArgs<1>(Invoke( |
| 1651 | [this](TransmissionType type) { RetransmitDataPacket(5, type); }))) |
| 1652 | .WillOnce(WithArgs<1>(Invoke( |
| 1653 | [this](TransmissionType type) { RetransmitDataPacket(6, type); }))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1654 | manager_.OnRetransmissionTimeout(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1655 | // All previous packets are inflight, plus two rto retransmissions. |
ianswett | 9f459cb | 2019-04-21 06:39:59 -0700 | [diff] [blame] | 1656 | EXPECT_EQ(6 * kDefaultLength, manager_.GetBytesInFlight()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1657 | |
| 1658 | // The delay should double the second time. |
| 1659 | expected_time = clock_.Now() + expected_rto_delay + expected_rto_delay; |
| 1660 | // Once we always base the timer on the right edge, leaving the older packets |
| 1661 | // in flight doesn't change the timeout. |
| 1662 | EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); |
| 1663 | |
| 1664 | // Ack a packet before the first RTO and ensure the RTO timeout returns to the |
| 1665 | // original value and OnRetransmissionTimeout is not called or reverted. |
fayang | 0198341 | 2019-12-07 05:50:22 -0800 | [diff] [blame] | 1666 | uint64_t acked[] = {1, 2}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 1667 | ExpectAcksAndLosses(true, acked, QUICHE_ARRAYSIZE(acked), nullptr, 0); |
wub | 8ee29a0 | 2019-12-12 13:06:48 -0800 | [diff] [blame] | 1668 | manager_.OnAckFrameStart(QuicPacketNumber(2), QuicTime::Delta::Zero(), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1669 | clock_.Now()); |
fayang | 0198341 | 2019-12-07 05:50:22 -0800 | [diff] [blame] | 1670 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(3)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 1671 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 1672 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 1673 | ENCRYPTION_INITIAL)); |
fayang | 0198341 | 2019-12-07 05:50:22 -0800 | [diff] [blame] | 1674 | EXPECT_EQ(4 * kDefaultLength, manager_.GetBytesInFlight()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1675 | |
| 1676 | // Wait 2RTTs from now for the RTO, since it's the max of the RTO time |
| 1677 | // and the TLP time. In production, there would always be two TLP's first. |
| 1678 | // Since retransmission was spurious, smoothed_rtt_ is expired, and replaced |
| 1679 | // by the latest RTT sample of 500ms. |
| 1680 | expected_time = clock_.Now() + QuicTime::Delta::FromMilliseconds(1000); |
| 1681 | // Once we always base the timer on the right edge, leaving the older packets |
| 1682 | // in flight doesn't change the timeout. |
| 1683 | EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); |
| 1684 | } |
| 1685 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1686 | TEST_F(QuicSentPacketManagerTest, GetTransmissionDelayMin) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 1687 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 1688 | return; |
| 1689 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1690 | SendDataPacket(1); |
| 1691 | // Provide a 1ms RTT sample. |
| 1692 | const_cast<RttStats*>(manager_.GetRttStats()) |
| 1693 | ->UpdateRtt(QuicTime::Delta::FromMilliseconds(1), QuicTime::Delta::Zero(), |
| 1694 | QuicTime::Zero()); |
| 1695 | QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(200); |
| 1696 | |
| 1697 | // If the delay is smaller than the min, ensure it exponentially backs off |
| 1698 | // from the min. |
| 1699 | for (int i = 0; i < 5; ++i) { |
| 1700 | EXPECT_EQ(delay, |
| 1701 | QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1702 | delay = delay + delay; |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1703 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 1704 | .WillOnce(WithArgs<1>(Invoke([this, i](TransmissionType type) { |
| 1705 | RetransmitDataPacket(i + 2, type); |
| 1706 | }))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1707 | manager_.OnRetransmissionTimeout(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1708 | } |
| 1709 | } |
| 1710 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1711 | TEST_F(QuicSentPacketManagerTest, GetTransmissionDelayMax) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 1712 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 1713 | return; |
| 1714 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1715 | SendDataPacket(1); |
| 1716 | // Provide a 60s RTT sample. |
| 1717 | const_cast<RttStats*>(manager_.GetRttStats()) |
| 1718 | ->UpdateRtt(QuicTime::Delta::FromSeconds(60), QuicTime::Delta::Zero(), |
| 1719 | QuicTime::Zero()); |
| 1720 | |
| 1721 | EXPECT_EQ(QuicTime::Delta::FromSeconds(60), |
| 1722 | QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1723 | } |
| 1724 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1725 | TEST_F(QuicSentPacketManagerTest, GetTransmissionDelayExponentialBackoff) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 1726 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 1727 | return; |
| 1728 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1729 | SendDataPacket(1); |
| 1730 | QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(500); |
| 1731 | |
| 1732 | // Delay should back off exponentially. |
| 1733 | for (int i = 0; i < 5; ++i) { |
| 1734 | EXPECT_EQ(delay, |
| 1735 | QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1736 | delay = delay + delay; |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1737 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 1738 | .WillOnce(WithArgs<1>(Invoke([this, i](TransmissionType type) { |
| 1739 | RetransmitDataPacket(i + 2, type); |
| 1740 | }))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1741 | manager_.OnRetransmissionTimeout(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1742 | } |
| 1743 | } |
| 1744 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1745 | TEST_F(QuicSentPacketManagerTest, RetransmissionDelay) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 1746 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 1747 | return; |
| 1748 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1749 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 1750 | const int64_t kRttMs = 250; |
| 1751 | const int64_t kDeviationMs = 5; |
| 1752 | |
| 1753 | rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kRttMs), |
| 1754 | QuicTime::Delta::Zero(), clock_.Now()); |
| 1755 | |
| 1756 | // Initial value is to set the median deviation to half of the initial rtt, |
| 1757 | // the median in then multiplied by a factor of 4 and finally the smoothed rtt |
| 1758 | // is added which is the initial rtt. |
| 1759 | QuicTime::Delta expected_delay = |
| 1760 | QuicTime::Delta::FromMilliseconds(kRttMs + kRttMs / 2 * 4); |
| 1761 | EXPECT_EQ(expected_delay, |
| 1762 | QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1763 | |
| 1764 | for (int i = 0; i < 100; ++i) { |
| 1765 | // Run to make sure that we converge. |
| 1766 | rtt_stats->UpdateRtt( |
| 1767 | QuicTime::Delta::FromMilliseconds(kRttMs + kDeviationMs), |
| 1768 | QuicTime::Delta::Zero(), clock_.Now()); |
| 1769 | rtt_stats->UpdateRtt( |
| 1770 | QuicTime::Delta::FromMilliseconds(kRttMs - kDeviationMs), |
| 1771 | QuicTime::Delta::Zero(), clock_.Now()); |
| 1772 | } |
| 1773 | expected_delay = QuicTime::Delta::FromMilliseconds(kRttMs + kDeviationMs * 4); |
| 1774 | |
| 1775 | EXPECT_NEAR(kRttMs, rtt_stats->smoothed_rtt().ToMilliseconds(), 1); |
| 1776 | EXPECT_NEAR(expected_delay.ToMilliseconds(), |
| 1777 | QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_) |
| 1778 | .ToMilliseconds(), |
| 1779 | 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1780 | } |
| 1781 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1782 | TEST_F(QuicSentPacketManagerTest, GetLossDelay) { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 1783 | auto loss_algorithm = std::make_unique<MockLossAlgorithm>(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1784 | QuicSentPacketManagerPeer::SetLossAlgorithm(&manager_, loss_algorithm.get()); |
| 1785 | |
| 1786 | EXPECT_CALL(*loss_algorithm, GetLossTimeout()) |
| 1787 | .WillRepeatedly(Return(QuicTime::Zero())); |
| 1788 | SendDataPacket(1); |
| 1789 | SendDataPacket(2); |
| 1790 | |
| 1791 | // Handle an ack which causes the loss algorithm to be evaluated and |
| 1792 | // set the loss timeout. |
| 1793 | ExpectAck(2); |
| 1794 | EXPECT_CALL(*loss_algorithm, DetectLosses(_, _, _, _, _, _)); |
| 1795 | manager_.OnAckFrameStart(QuicPacketNumber(2), QuicTime::Delta::Infinite(), |
| 1796 | clock_.Now()); |
| 1797 | manager_.OnAckRange(QuicPacketNumber(2), QuicPacketNumber(3)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 1798 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 1799 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 1800 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1801 | |
| 1802 | QuicTime timeout(clock_.Now() + QuicTime::Delta::FromMilliseconds(10)); |
| 1803 | EXPECT_CALL(*loss_algorithm, GetLossTimeout()) |
| 1804 | .WillRepeatedly(Return(timeout)); |
| 1805 | EXPECT_EQ(timeout, manager_.GetRetransmissionTime()); |
| 1806 | |
| 1807 | // Fire the retransmission timeout and ensure the loss detection algorithm |
| 1808 | // is invoked. |
| 1809 | EXPECT_CALL(*loss_algorithm, DetectLosses(_, _, _, _, _, _)); |
| 1810 | manager_.OnRetransmissionTimeout(); |
| 1811 | } |
| 1812 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1813 | TEST_F(QuicSentPacketManagerTest, NegotiateIetfLossDetectionFromOptions) { |
fayang | 3be090d | 2020-02-11 14:05:08 -0800 | [diff] [blame] | 1814 | EXPECT_TRUE( |
| 1815 | QuicSentPacketManagerPeer::AdaptiveReorderingThresholdEnabled(&manager_)); |
| 1816 | EXPECT_FALSE( |
| 1817 | QuicSentPacketManagerPeer::AdaptiveTimeThresholdEnabled(&manager_)); |
| 1818 | EXPECT_EQ(kDefaultLossDelayShift, |
| 1819 | QuicSentPacketManagerPeer::GetReorderingShift(&manager_)); |
fayang | b0c7b4b | 2019-09-12 06:45:24 -0700 | [diff] [blame] | 1820 | |
| 1821 | QuicConfig config; |
| 1822 | QuicTagVector options; |
| 1823 | options.push_back(kILD0); |
| 1824 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 1825 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 1826 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 1827 | manager_.SetFromConfig(config); |
| 1828 | |
fayang | b0c7b4b | 2019-09-12 06:45:24 -0700 | [diff] [blame] | 1829 | EXPECT_EQ(3, QuicSentPacketManagerPeer::GetReorderingShift(&manager_)); |
| 1830 | EXPECT_FALSE( |
| 1831 | QuicSentPacketManagerPeer::AdaptiveReorderingThresholdEnabled(&manager_)); |
| 1832 | } |
| 1833 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1834 | TEST_F(QuicSentPacketManagerTest, |
fayang | b0c7b4b | 2019-09-12 06:45:24 -0700 | [diff] [blame] | 1835 | NegotiateIetfLossDetectionOneFourthRttFromOptions) { |
fayang | 3be090d | 2020-02-11 14:05:08 -0800 | [diff] [blame] | 1836 | EXPECT_TRUE( |
| 1837 | QuicSentPacketManagerPeer::AdaptiveReorderingThresholdEnabled(&manager_)); |
| 1838 | EXPECT_FALSE( |
| 1839 | QuicSentPacketManagerPeer::AdaptiveTimeThresholdEnabled(&manager_)); |
| 1840 | EXPECT_EQ(kDefaultLossDelayShift, |
| 1841 | QuicSentPacketManagerPeer::GetReorderingShift(&manager_)); |
fayang | b0c7b4b | 2019-09-12 06:45:24 -0700 | [diff] [blame] | 1842 | |
| 1843 | QuicConfig config; |
| 1844 | QuicTagVector options; |
| 1845 | options.push_back(kILD1); |
| 1846 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 1847 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 1848 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 1849 | manager_.SetFromConfig(config); |
| 1850 | |
fayang | b0c7b4b | 2019-09-12 06:45:24 -0700 | [diff] [blame] | 1851 | EXPECT_EQ(kDefaultLossDelayShift, |
| 1852 | QuicSentPacketManagerPeer::GetReorderingShift(&manager_)); |
| 1853 | EXPECT_FALSE( |
| 1854 | QuicSentPacketManagerPeer::AdaptiveReorderingThresholdEnabled(&manager_)); |
| 1855 | } |
| 1856 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1857 | TEST_F(QuicSentPacketManagerTest, |
fayang | b0c7b4b | 2019-09-12 06:45:24 -0700 | [diff] [blame] | 1858 | NegotiateIetfLossDetectionAdaptiveReorderingThreshold) { |
fayang | 3be090d | 2020-02-11 14:05:08 -0800 | [diff] [blame] | 1859 | EXPECT_TRUE( |
| 1860 | QuicSentPacketManagerPeer::AdaptiveReorderingThresholdEnabled(&manager_)); |
| 1861 | EXPECT_FALSE( |
| 1862 | QuicSentPacketManagerPeer::AdaptiveTimeThresholdEnabled(&manager_)); |
| 1863 | EXPECT_EQ(kDefaultLossDelayShift, |
| 1864 | QuicSentPacketManagerPeer::GetReorderingShift(&manager_)); |
fayang | b0c7b4b | 2019-09-12 06:45:24 -0700 | [diff] [blame] | 1865 | |
| 1866 | QuicConfig config; |
| 1867 | QuicTagVector options; |
| 1868 | options.push_back(kILD2); |
| 1869 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 1870 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 1871 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 1872 | manager_.SetFromConfig(config); |
| 1873 | |
fayang | b0c7b4b | 2019-09-12 06:45:24 -0700 | [diff] [blame] | 1874 | EXPECT_EQ(3, QuicSentPacketManagerPeer::GetReorderingShift(&manager_)); |
| 1875 | EXPECT_TRUE( |
| 1876 | QuicSentPacketManagerPeer::AdaptiveReorderingThresholdEnabled(&manager_)); |
| 1877 | } |
| 1878 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1879 | TEST_F(QuicSentPacketManagerTest, |
fayang | b0c7b4b | 2019-09-12 06:45:24 -0700 | [diff] [blame] | 1880 | NegotiateIetfLossDetectionAdaptiveReorderingThreshold2) { |
fayang | 3be090d | 2020-02-11 14:05:08 -0800 | [diff] [blame] | 1881 | EXPECT_TRUE( |
| 1882 | QuicSentPacketManagerPeer::AdaptiveReorderingThresholdEnabled(&manager_)); |
| 1883 | EXPECT_FALSE( |
| 1884 | QuicSentPacketManagerPeer::AdaptiveTimeThresholdEnabled(&manager_)); |
| 1885 | EXPECT_EQ(kDefaultLossDelayShift, |
| 1886 | QuicSentPacketManagerPeer::GetReorderingShift(&manager_)); |
fayang | b0c7b4b | 2019-09-12 06:45:24 -0700 | [diff] [blame] | 1887 | |
| 1888 | QuicConfig config; |
| 1889 | QuicTagVector options; |
| 1890 | options.push_back(kILD3); |
| 1891 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 1892 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 1893 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 1894 | manager_.SetFromConfig(config); |
fayang | b0c7b4b | 2019-09-12 06:45:24 -0700 | [diff] [blame] | 1895 | EXPECT_EQ(kDefaultLossDelayShift, |
| 1896 | QuicSentPacketManagerPeer::GetReorderingShift(&manager_)); |
| 1897 | EXPECT_TRUE( |
| 1898 | QuicSentPacketManagerPeer::AdaptiveReorderingThresholdEnabled(&manager_)); |
| 1899 | } |
| 1900 | |
fayang | db09565 | 2019-11-04 07:37:36 -0800 | [diff] [blame] | 1901 | TEST_F(QuicSentPacketManagerTest, |
| 1902 | NegotiateIetfLossDetectionAdaptiveReorderingAndTimeThreshold) { |
fayang | 3be090d | 2020-02-11 14:05:08 -0800 | [diff] [blame] | 1903 | EXPECT_TRUE( |
| 1904 | QuicSentPacketManagerPeer::AdaptiveReorderingThresholdEnabled(&manager_)); |
| 1905 | EXPECT_FALSE( |
| 1906 | QuicSentPacketManagerPeer::AdaptiveTimeThresholdEnabled(&manager_)); |
| 1907 | EXPECT_EQ(kDefaultLossDelayShift, |
| 1908 | QuicSentPacketManagerPeer::GetReorderingShift(&manager_)); |
fayang | db09565 | 2019-11-04 07:37:36 -0800 | [diff] [blame] | 1909 | |
| 1910 | QuicConfig config; |
| 1911 | QuicTagVector options; |
| 1912 | options.push_back(kILD4); |
| 1913 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 1914 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 1915 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 1916 | manager_.SetFromConfig(config); |
| 1917 | |
fayang | db09565 | 2019-11-04 07:37:36 -0800 | [diff] [blame] | 1918 | EXPECT_EQ(kDefaultLossDelayShift, |
| 1919 | QuicSentPacketManagerPeer::GetReorderingShift(&manager_)); |
| 1920 | EXPECT_TRUE( |
| 1921 | QuicSentPacketManagerPeer::AdaptiveReorderingThresholdEnabled(&manager_)); |
| 1922 | EXPECT_TRUE( |
| 1923 | QuicSentPacketManagerPeer::AdaptiveTimeThresholdEnabled(&manager_)); |
| 1924 | } |
| 1925 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1926 | TEST_F(QuicSentPacketManagerTest, NegotiateCongestionControlFromOptions) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1927 | QuicConfig config; |
| 1928 | QuicTagVector options; |
| 1929 | |
| 1930 | options.push_back(kRENO); |
| 1931 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 1932 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 1933 | manager_.SetFromConfig(config); |
| 1934 | EXPECT_EQ(kRenoBytes, QuicSentPacketManagerPeer::GetSendAlgorithm(manager_) |
| 1935 | ->GetCongestionControlType()); |
| 1936 | |
| 1937 | options.clear(); |
| 1938 | options.push_back(kTBBR); |
| 1939 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 1940 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 1941 | manager_.SetFromConfig(config); |
| 1942 | EXPECT_EQ(kBBR, QuicSentPacketManagerPeer::GetSendAlgorithm(manager_) |
| 1943 | ->GetCongestionControlType()); |
| 1944 | |
| 1945 | options.clear(); |
| 1946 | options.push_back(kBYTE); |
| 1947 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 1948 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 1949 | manager_.SetFromConfig(config); |
| 1950 | EXPECT_EQ(kCubicBytes, QuicSentPacketManagerPeer::GetSendAlgorithm(manager_) |
| 1951 | ->GetCongestionControlType()); |
| 1952 | options.clear(); |
| 1953 | options.push_back(kRENO); |
| 1954 | options.push_back(kBYTE); |
| 1955 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 1956 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 1957 | manager_.SetFromConfig(config); |
| 1958 | EXPECT_EQ(kRenoBytes, QuicSentPacketManagerPeer::GetSendAlgorithm(manager_) |
| 1959 | ->GetCongestionControlType()); |
| 1960 | } |
| 1961 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 1962 | TEST_F(QuicSentPacketManagerTest, NegotiateClientCongestionControlFromOptions) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1963 | QuicConfig config; |
| 1964 | QuicTagVector options; |
| 1965 | |
| 1966 | // No change if the server receives client options. |
| 1967 | const SendAlgorithmInterface* mock_sender = |
| 1968 | QuicSentPacketManagerPeer::GetSendAlgorithm(manager_); |
| 1969 | options.push_back(kRENO); |
| 1970 | config.SetClientConnectionOptions(options); |
| 1971 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 1972 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 1973 | manager_.SetFromConfig(config); |
| 1974 | EXPECT_EQ(mock_sender, QuicSentPacketManagerPeer::GetSendAlgorithm(manager_)); |
| 1975 | |
| 1976 | // Change the congestion control on the client with client options. |
| 1977 | QuicSentPacketManagerPeer::SetPerspective(&manager_, Perspective::IS_CLIENT); |
| 1978 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 1979 | manager_.SetFromConfig(config); |
| 1980 | EXPECT_EQ(kRenoBytes, QuicSentPacketManagerPeer::GetSendAlgorithm(manager_) |
| 1981 | ->GetCongestionControlType()); |
| 1982 | |
| 1983 | options.clear(); |
| 1984 | options.push_back(kTBBR); |
| 1985 | config.SetClientConnectionOptions(options); |
| 1986 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 1987 | manager_.SetFromConfig(config); |
| 1988 | EXPECT_EQ(kBBR, QuicSentPacketManagerPeer::GetSendAlgorithm(manager_) |
| 1989 | ->GetCongestionControlType()); |
| 1990 | |
| 1991 | options.clear(); |
| 1992 | options.push_back(kBYTE); |
| 1993 | config.SetClientConnectionOptions(options); |
| 1994 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 1995 | manager_.SetFromConfig(config); |
| 1996 | EXPECT_EQ(kCubicBytes, QuicSentPacketManagerPeer::GetSendAlgorithm(manager_) |
| 1997 | ->GetCongestionControlType()); |
| 1998 | |
| 1999 | options.clear(); |
| 2000 | options.push_back(kRENO); |
| 2001 | options.push_back(kBYTE); |
| 2002 | config.SetClientConnectionOptions(options); |
| 2003 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 2004 | manager_.SetFromConfig(config); |
| 2005 | EXPECT_EQ(kRenoBytes, QuicSentPacketManagerPeer::GetSendAlgorithm(manager_) |
| 2006 | ->GetCongestionControlType()); |
| 2007 | } |
| 2008 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2009 | TEST_F(QuicSentPacketManagerTest, NegotiateNoMinTLPFromOptionsAtServer) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2010 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 2011 | return; |
| 2012 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2013 | QuicConfig config; |
| 2014 | QuicTagVector options; |
| 2015 | |
| 2016 | options.push_back(kMAD2); |
| 2017 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 2018 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 2019 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 2020 | EXPECT_CALL(*send_algorithm_, PacingRate(_)) |
| 2021 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
| 2022 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
| 2023 | .WillOnce(Return(10 * kDefaultTCPMSS)); |
| 2024 | manager_.SetFromConfig(config); |
| 2025 | // Set the initial RTT to 1us. |
| 2026 | QuicSentPacketManagerPeer::GetRttStats(&manager_)->set_initial_rtt( |
| 2027 | QuicTime::Delta::FromMicroseconds(1)); |
| 2028 | // The TLP with fewer than 2 packets outstanding includes 1/2 min RTO(200ms). |
| 2029 | EXPECT_EQ(QuicTime::Delta::FromMicroseconds(100002), |
| 2030 | QuicSentPacketManagerPeer::GetTailLossProbeDelay(&manager_)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2031 | |
ianswett | ad65ab9 | 2019-10-28 07:19:07 -0700 | [diff] [blame] | 2032 | // Send two packets, and the TLP should be 1ms. |
| 2033 | QuicTime::Delta expected_tlp_delay = QuicTime::Delta::FromMilliseconds(1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2034 | SendDataPacket(1); |
| 2035 | SendDataPacket(2); |
ianswett | dcc474e | 2019-08-06 08:22:38 -0700 | [diff] [blame] | 2036 | EXPECT_EQ(expected_tlp_delay, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2037 | QuicSentPacketManagerPeer::GetTailLossProbeDelay(&manager_)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2038 | } |
| 2039 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2040 | TEST_F(QuicSentPacketManagerTest, NegotiateNoMinTLPFromOptionsAtClient) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2041 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 2042 | return; |
| 2043 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2044 | QuicConfig client_config; |
| 2045 | QuicTagVector options; |
| 2046 | |
| 2047 | options.push_back(kMAD2); |
| 2048 | QuicSentPacketManagerPeer::SetPerspective(&manager_, Perspective::IS_CLIENT); |
| 2049 | client_config.SetConnectionOptionsToSend(options); |
| 2050 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 2051 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 2052 | EXPECT_CALL(*send_algorithm_, PacingRate(_)) |
| 2053 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
| 2054 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
| 2055 | .WillOnce(Return(10 * kDefaultTCPMSS)); |
| 2056 | manager_.SetFromConfig(client_config); |
| 2057 | // Set the initial RTT to 1us. |
| 2058 | QuicSentPacketManagerPeer::GetRttStats(&manager_)->set_initial_rtt( |
| 2059 | QuicTime::Delta::FromMicroseconds(1)); |
| 2060 | // The TLP with fewer than 2 packets outstanding includes 1/2 min RTO(200ms). |
| 2061 | EXPECT_EQ(QuicTime::Delta::FromMicroseconds(100002), |
| 2062 | QuicSentPacketManagerPeer::GetTailLossProbeDelay(&manager_)); |
ianswett | ad65ab9 | 2019-10-28 07:19:07 -0700 | [diff] [blame] | 2063 | // Send two packets, and the TLP should be 1ms. |
| 2064 | QuicTime::Delta expected_tlp_delay = QuicTime::Delta::FromMilliseconds(1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2065 | SendDataPacket(1); |
| 2066 | SendDataPacket(2); |
ianswett | dcc474e | 2019-08-06 08:22:38 -0700 | [diff] [blame] | 2067 | EXPECT_EQ(expected_tlp_delay, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2068 | QuicSentPacketManagerPeer::GetTailLossProbeDelay(&manager_)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2069 | } |
| 2070 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2071 | TEST_F(QuicSentPacketManagerTest, NegotiateNoMinRTOFromOptionsAtServer) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2072 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 2073 | return; |
| 2074 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2075 | QuicConfig config; |
| 2076 | QuicTagVector options; |
| 2077 | |
| 2078 | options.push_back(kMAD3); |
| 2079 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 2080 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 2081 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 2082 | manager_.SetFromConfig(config); |
| 2083 | // Provide one RTT measurement, because otherwise we use the default of 500ms. |
| 2084 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 2085 | rtt_stats->UpdateRtt(QuicTime::Delta::FromMicroseconds(1), |
| 2086 | QuicTime::Delta::Zero(), QuicTime::Zero()); |
ianswett | ad65ab9 | 2019-10-28 07:19:07 -0700 | [diff] [blame] | 2087 | QuicTime::Delta expected_rto_delay = QuicTime::Delta::FromMilliseconds(1); |
ianswett | dcc474e | 2019-08-06 08:22:38 -0700 | [diff] [blame] | 2088 | EXPECT_EQ(expected_rto_delay, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2089 | QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2090 | // The TLP with fewer than 2 packets outstanding includes 1/2 min RTO(0ms). |
ianswett | ad65ab9 | 2019-10-28 07:19:07 -0700 | [diff] [blame] | 2091 | QuicTime::Delta expected_tlp_delay = QuicTime::Delta::FromMicroseconds(502); |
ianswett | dcc474e | 2019-08-06 08:22:38 -0700 | [diff] [blame] | 2092 | EXPECT_EQ(expected_tlp_delay, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2093 | QuicSentPacketManagerPeer::GetTailLossProbeDelay(&manager_)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2094 | } |
| 2095 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2096 | TEST_F(QuicSentPacketManagerTest, NegotiateNoMinRTOFromOptionsAtClient) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2097 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 2098 | return; |
| 2099 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2100 | QuicConfig client_config; |
| 2101 | QuicTagVector options; |
| 2102 | |
| 2103 | options.push_back(kMAD3); |
| 2104 | QuicSentPacketManagerPeer::SetPerspective(&manager_, Perspective::IS_CLIENT); |
| 2105 | client_config.SetConnectionOptionsToSend(options); |
| 2106 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 2107 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 2108 | manager_.SetFromConfig(client_config); |
| 2109 | // Provide one RTT measurement, because otherwise we use the default of 500ms. |
| 2110 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 2111 | rtt_stats->UpdateRtt(QuicTime::Delta::FromMicroseconds(1), |
| 2112 | QuicTime::Delta::Zero(), QuicTime::Zero()); |
ianswett | ad65ab9 | 2019-10-28 07:19:07 -0700 | [diff] [blame] | 2113 | QuicTime::Delta expected_rto_delay = QuicTime::Delta::FromMilliseconds(1); |
ianswett | dcc474e | 2019-08-06 08:22:38 -0700 | [diff] [blame] | 2114 | EXPECT_EQ(expected_rto_delay, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2115 | QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2116 | // The TLP with fewer than 2 packets outstanding includes 1/2 min RTO(0ms). |
ianswett | ad65ab9 | 2019-10-28 07:19:07 -0700 | [diff] [blame] | 2117 | QuicTime::Delta expected_tlp_delay = QuicTime::Delta::FromMicroseconds(502); |
ianswett | dcc474e | 2019-08-06 08:22:38 -0700 | [diff] [blame] | 2118 | EXPECT_EQ(expected_tlp_delay, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2119 | QuicSentPacketManagerPeer::GetTailLossProbeDelay(&manager_)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2120 | } |
| 2121 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2122 | TEST_F(QuicSentPacketManagerTest, NegotiateNoTLPFromOptionsAtServer) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2123 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 2124 | return; |
| 2125 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2126 | QuicConfig config; |
| 2127 | QuicTagVector options; |
| 2128 | |
| 2129 | options.push_back(kNTLP); |
| 2130 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 2131 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 2132 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 2133 | manager_.SetFromConfig(config); |
| 2134 | EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetMaxTailLossProbes(&manager_)); |
| 2135 | } |
| 2136 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2137 | TEST_F(QuicSentPacketManagerTest, NegotiateNoTLPFromOptionsAtClient) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2138 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 2139 | return; |
| 2140 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2141 | QuicConfig client_config; |
| 2142 | QuicTagVector options; |
| 2143 | |
| 2144 | options.push_back(kNTLP); |
| 2145 | QuicSentPacketManagerPeer::SetPerspective(&manager_, Perspective::IS_CLIENT); |
| 2146 | client_config.SetConnectionOptionsToSend(options); |
| 2147 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 2148 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 2149 | manager_.SetFromConfig(client_config); |
| 2150 | EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetMaxTailLossProbes(&manager_)); |
| 2151 | } |
| 2152 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2153 | TEST_F(QuicSentPacketManagerTest, Negotiate1TLPFromOptionsAtServer) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2154 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 2155 | return; |
| 2156 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2157 | QuicConfig config; |
| 2158 | QuicTagVector options; |
| 2159 | |
| 2160 | options.push_back(k1TLP); |
| 2161 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 2162 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 2163 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 2164 | manager_.SetFromConfig(config); |
| 2165 | EXPECT_EQ(1u, QuicSentPacketManagerPeer::GetMaxTailLossProbes(&manager_)); |
| 2166 | } |
| 2167 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2168 | TEST_F(QuicSentPacketManagerTest, Negotiate1TLPFromOptionsAtClient) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2169 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 2170 | return; |
| 2171 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2172 | QuicConfig client_config; |
| 2173 | QuicTagVector options; |
| 2174 | |
| 2175 | options.push_back(k1TLP); |
| 2176 | QuicSentPacketManagerPeer::SetPerspective(&manager_, Perspective::IS_CLIENT); |
| 2177 | client_config.SetConnectionOptionsToSend(options); |
| 2178 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 2179 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 2180 | manager_.SetFromConfig(client_config); |
| 2181 | EXPECT_EQ(1u, QuicSentPacketManagerPeer::GetMaxTailLossProbes(&manager_)); |
| 2182 | } |
| 2183 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2184 | TEST_F(QuicSentPacketManagerTest, NegotiateTLPRttFromOptionsAtServer) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2185 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 2186 | return; |
| 2187 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2188 | QuicConfig config; |
| 2189 | QuicTagVector options; |
| 2190 | |
| 2191 | options.push_back(kTLPR); |
| 2192 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 2193 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 2194 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 2195 | manager_.SetFromConfig(config); |
| 2196 | EXPECT_TRUE( |
| 2197 | QuicSentPacketManagerPeer::GetEnableHalfRttTailLossProbe(&manager_)); |
| 2198 | } |
| 2199 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2200 | TEST_F(QuicSentPacketManagerTest, NegotiateTLPRttFromOptionsAtClient) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2201 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 2202 | return; |
| 2203 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2204 | QuicConfig client_config; |
| 2205 | QuicTagVector options; |
| 2206 | |
| 2207 | options.push_back(kTLPR); |
| 2208 | QuicSentPacketManagerPeer::SetPerspective(&manager_, Perspective::IS_CLIENT); |
| 2209 | client_config.SetConnectionOptionsToSend(options); |
| 2210 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 2211 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 2212 | manager_.SetFromConfig(client_config); |
| 2213 | EXPECT_TRUE( |
| 2214 | QuicSentPacketManagerPeer::GetEnableHalfRttTailLossProbe(&manager_)); |
| 2215 | } |
| 2216 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2217 | TEST_F(QuicSentPacketManagerTest, NegotiateNewRTOFromOptionsAtServer) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2218 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 2219 | return; |
| 2220 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2221 | EXPECT_FALSE(QuicSentPacketManagerPeer::GetUseNewRto(&manager_)); |
| 2222 | QuicConfig config; |
| 2223 | QuicTagVector options; |
| 2224 | |
| 2225 | options.push_back(kNRTO); |
| 2226 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 2227 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 2228 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 2229 | manager_.SetFromConfig(config); |
| 2230 | EXPECT_TRUE(QuicSentPacketManagerPeer::GetUseNewRto(&manager_)); |
| 2231 | } |
| 2232 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2233 | TEST_F(QuicSentPacketManagerTest, NegotiateNewRTOFromOptionsAtClient) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2234 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 2235 | return; |
| 2236 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2237 | EXPECT_FALSE(QuicSentPacketManagerPeer::GetUseNewRto(&manager_)); |
| 2238 | QuicConfig client_config; |
| 2239 | QuicTagVector options; |
| 2240 | |
| 2241 | options.push_back(kNRTO); |
| 2242 | QuicSentPacketManagerPeer::SetPerspective(&manager_, Perspective::IS_CLIENT); |
| 2243 | client_config.SetConnectionOptionsToSend(options); |
| 2244 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 2245 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 2246 | manager_.SetFromConfig(client_config); |
| 2247 | EXPECT_TRUE(QuicSentPacketManagerPeer::GetUseNewRto(&manager_)); |
| 2248 | } |
| 2249 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2250 | TEST_F(QuicSentPacketManagerTest, UseInitialRoundTripTimeToSend) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2251 | QuicTime::Delta initial_rtt = QuicTime::Delta::FromMilliseconds(325); |
| 2252 | EXPECT_NE(initial_rtt, manager_.GetRttStats()->smoothed_rtt()); |
| 2253 | |
| 2254 | QuicConfig config; |
| 2255 | config.SetInitialRoundTripTimeUsToSend(initial_rtt.ToMicroseconds()); |
| 2256 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 2257 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 2258 | manager_.SetFromConfig(config); |
| 2259 | |
| 2260 | EXPECT_EQ(QuicTime::Delta::Zero(), manager_.GetRttStats()->smoothed_rtt()); |
| 2261 | EXPECT_EQ(initial_rtt, manager_.GetRttStats()->initial_rtt()); |
| 2262 | } |
| 2263 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2264 | TEST_F(QuicSentPacketManagerTest, ResumeConnectionState) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2265 | // The sent packet manager should use the RTT from CachedNetworkParameters if |
| 2266 | // it is provided. |
| 2267 | const QuicTime::Delta kRtt = QuicTime::Delta::FromMilliseconds(1234); |
| 2268 | CachedNetworkParameters cached_network_params; |
| 2269 | cached_network_params.set_min_rtt_ms(kRtt.ToMilliseconds()); |
| 2270 | |
QUICHE team | b4e187c | 2019-11-14 06:22:50 -0800 | [diff] [blame] | 2271 | SendAlgorithmInterface::NetworkParams params; |
| 2272 | params.bandwidth = QuicBandwidth::Zero(); |
| 2273 | params.allow_cwnd_to_decrease = false; |
| 2274 | params.rtt = kRtt; |
| 2275 | |
| 2276 | EXPECT_CALL(*send_algorithm_, AdjustNetworkParameters(params)); |
fayang | be83ecd | 2019-04-26 13:58:09 -0700 | [diff] [blame] | 2277 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
| 2278 | .Times(testing::AnyNumber()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2279 | manager_.ResumeConnectionState(cached_network_params, false); |
| 2280 | EXPECT_EQ(kRtt, manager_.GetRttStats()->initial_rtt()); |
| 2281 | } |
| 2282 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2283 | TEST_F(QuicSentPacketManagerTest, ConnectionMigrationUnspecifiedChange) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2284 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 2285 | QuicTime::Delta default_init_rtt = rtt_stats->initial_rtt(); |
| 2286 | rtt_stats->set_initial_rtt(default_init_rtt * 2); |
| 2287 | EXPECT_EQ(2 * default_init_rtt, rtt_stats->initial_rtt()); |
| 2288 | |
| 2289 | QuicSentPacketManagerPeer::SetConsecutiveRtoCount(&manager_, 1); |
| 2290 | EXPECT_EQ(1u, manager_.GetConsecutiveRtoCount()); |
| 2291 | QuicSentPacketManagerPeer::SetConsecutiveTlpCount(&manager_, 2); |
| 2292 | EXPECT_EQ(2u, manager_.GetConsecutiveTlpCount()); |
| 2293 | |
| 2294 | EXPECT_CALL(*send_algorithm_, OnConnectionMigration()); |
| 2295 | manager_.OnConnectionMigration(IPV4_TO_IPV4_CHANGE); |
| 2296 | |
| 2297 | EXPECT_EQ(default_init_rtt, rtt_stats->initial_rtt()); |
| 2298 | EXPECT_EQ(0u, manager_.GetConsecutiveRtoCount()); |
| 2299 | EXPECT_EQ(0u, manager_.GetConsecutiveTlpCount()); |
| 2300 | } |
| 2301 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2302 | TEST_F(QuicSentPacketManagerTest, ConnectionMigrationIPSubnetChange) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2303 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 2304 | QuicTime::Delta default_init_rtt = rtt_stats->initial_rtt(); |
| 2305 | rtt_stats->set_initial_rtt(default_init_rtt * 2); |
| 2306 | EXPECT_EQ(2 * default_init_rtt, rtt_stats->initial_rtt()); |
| 2307 | |
| 2308 | QuicSentPacketManagerPeer::SetConsecutiveRtoCount(&manager_, 1); |
| 2309 | EXPECT_EQ(1u, manager_.GetConsecutiveRtoCount()); |
| 2310 | QuicSentPacketManagerPeer::SetConsecutiveTlpCount(&manager_, 2); |
| 2311 | EXPECT_EQ(2u, manager_.GetConsecutiveTlpCount()); |
| 2312 | |
| 2313 | manager_.OnConnectionMigration(IPV4_SUBNET_CHANGE); |
| 2314 | |
| 2315 | EXPECT_EQ(2 * default_init_rtt, rtt_stats->initial_rtt()); |
| 2316 | EXPECT_EQ(1u, manager_.GetConsecutiveRtoCount()); |
| 2317 | EXPECT_EQ(2u, manager_.GetConsecutiveTlpCount()); |
| 2318 | } |
| 2319 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2320 | TEST_F(QuicSentPacketManagerTest, ConnectionMigrationPortChange) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2321 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 2322 | QuicTime::Delta default_init_rtt = rtt_stats->initial_rtt(); |
| 2323 | rtt_stats->set_initial_rtt(default_init_rtt * 2); |
| 2324 | EXPECT_EQ(2 * default_init_rtt, rtt_stats->initial_rtt()); |
| 2325 | |
| 2326 | QuicSentPacketManagerPeer::SetConsecutiveRtoCount(&manager_, 1); |
| 2327 | EXPECT_EQ(1u, manager_.GetConsecutiveRtoCount()); |
| 2328 | QuicSentPacketManagerPeer::SetConsecutiveTlpCount(&manager_, 2); |
| 2329 | EXPECT_EQ(2u, manager_.GetConsecutiveTlpCount()); |
| 2330 | |
| 2331 | manager_.OnConnectionMigration(PORT_CHANGE); |
| 2332 | |
| 2333 | EXPECT_EQ(2 * default_init_rtt, rtt_stats->initial_rtt()); |
| 2334 | EXPECT_EQ(1u, manager_.GetConsecutiveRtoCount()); |
| 2335 | EXPECT_EQ(2u, manager_.GetConsecutiveTlpCount()); |
| 2336 | } |
| 2337 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2338 | TEST_F(QuicSentPacketManagerTest, PathMtuIncreased) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2339 | EXPECT_CALL(*send_algorithm_, |
| 2340 | OnPacketSent(_, BytesInFlight(), QuicPacketNumber(1), _, _)); |
| 2341 | SerializedPacket packet(QuicPacketNumber(1), PACKET_4BYTE_PACKET_NUMBER, |
| 2342 | nullptr, kDefaultLength + 100, false, false); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2343 | manager_.OnPacketSent(&packet, clock_.Now(), NOT_RETRANSMISSION, |
| 2344 | HAS_RETRANSMITTABLE_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2345 | |
| 2346 | // Ack the large packet and expect the path MTU to increase. |
| 2347 | ExpectAck(1); |
| 2348 | EXPECT_CALL(*network_change_visitor_, |
| 2349 | OnPathMtuIncreased(kDefaultLength + 100)); |
| 2350 | QuicAckFrame ack_frame = InitAckFrame(1); |
| 2351 | manager_.OnAckFrameStart(QuicPacketNumber(1), QuicTime::Delta::Infinite(), |
| 2352 | clock_.Now()); |
| 2353 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 2354 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 2355 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 2356 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2357 | } |
| 2358 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2359 | TEST_F(QuicSentPacketManagerTest, OnAckRangeSlowPath) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2360 | // Send packets 1 - 20. |
| 2361 | for (size_t i = 1; i <= 20; ++i) { |
| 2362 | SendDataPacket(i); |
| 2363 | } |
| 2364 | // Ack [5, 7), [10, 12), [15, 17). |
| 2365 | uint64_t acked1[] = {5, 6, 10, 11, 15, 16}; |
| 2366 | uint64_t lost1[] = {1, 2, 3, 4, 7, 8, 9, 12, 13}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 2367 | ExpectAcksAndLosses(true, acked1, QUICHE_ARRAYSIZE(acked1), lost1, |
| 2368 | QUICHE_ARRAYSIZE(lost1)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2369 | EXPECT_CALL(notifier_, OnFrameLost(_)).Times(AnyNumber()); |
| 2370 | manager_.OnAckFrameStart(QuicPacketNumber(16), QuicTime::Delta::Infinite(), |
| 2371 | clock_.Now()); |
| 2372 | manager_.OnAckRange(QuicPacketNumber(15), QuicPacketNumber(17)); |
| 2373 | manager_.OnAckRange(QuicPacketNumber(10), QuicPacketNumber(12)); |
| 2374 | manager_.OnAckRange(QuicPacketNumber(5), QuicPacketNumber(7)); |
| 2375 | // Make sure empty range does not harm. |
| 2376 | manager_.OnAckRange(QuicPacketNumber(4), QuicPacketNumber(4)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 2377 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 2378 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 2379 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2380 | |
| 2381 | // Ack [4, 8), [9, 13), [14, 21). |
| 2382 | uint64_t acked2[] = {4, 7, 9, 12, 14, 17, 18, 19, 20}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 2383 | ExpectAcksAndLosses(true, acked2, QUICHE_ARRAYSIZE(acked2), nullptr, 0); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2384 | manager_.OnAckFrameStart(QuicPacketNumber(20), QuicTime::Delta::Infinite(), |
| 2385 | clock_.Now()); |
| 2386 | manager_.OnAckRange(QuicPacketNumber(14), QuicPacketNumber(21)); |
| 2387 | manager_.OnAckRange(QuicPacketNumber(9), QuicPacketNumber(13)); |
| 2388 | manager_.OnAckRange(QuicPacketNumber(4), QuicPacketNumber(8)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 2389 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 2390 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(2), |
| 2391 | ENCRYPTION_INITIAL)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2392 | } |
| 2393 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2394 | TEST_F(QuicSentPacketManagerTest, TolerateReneging) { |
QUICHE team | 9929cc4 | 2019-03-13 08:17:43 -0700 | [diff] [blame] | 2395 | // Send packets 1 - 20. |
| 2396 | for (size_t i = 1; i <= 20; ++i) { |
| 2397 | SendDataPacket(i); |
| 2398 | } |
| 2399 | // Ack [5, 7), [10, 12), [15, 17). |
| 2400 | uint64_t acked1[] = {5, 6, 10, 11, 15, 16}; |
| 2401 | uint64_t lost1[] = {1, 2, 3, 4, 7, 8, 9, 12, 13}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 2402 | ExpectAcksAndLosses(true, acked1, QUICHE_ARRAYSIZE(acked1), lost1, |
| 2403 | QUICHE_ARRAYSIZE(lost1)); |
QUICHE team | 9929cc4 | 2019-03-13 08:17:43 -0700 | [diff] [blame] | 2404 | EXPECT_CALL(notifier_, OnFrameLost(_)).Times(AnyNumber()); |
| 2405 | manager_.OnAckFrameStart(QuicPacketNumber(16), QuicTime::Delta::Infinite(), |
| 2406 | clock_.Now()); |
| 2407 | manager_.OnAckRange(QuicPacketNumber(15), QuicPacketNumber(17)); |
| 2408 | manager_.OnAckRange(QuicPacketNumber(10), QuicPacketNumber(12)); |
| 2409 | manager_.OnAckRange(QuicPacketNumber(5), QuicPacketNumber(7)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 2410 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 2411 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 2412 | ENCRYPTION_INITIAL)); |
QUICHE team | 9929cc4 | 2019-03-13 08:17:43 -0700 | [diff] [blame] | 2413 | |
| 2414 | // Making sure reneged ACK does not harm. Ack [4, 8), [9, 13). |
| 2415 | uint64_t acked2[] = {4, 7, 9, 12}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 2416 | ExpectAcksAndLosses(true, acked2, QUICHE_ARRAYSIZE(acked2), nullptr, 0); |
QUICHE team | 9929cc4 | 2019-03-13 08:17:43 -0700 | [diff] [blame] | 2417 | manager_.OnAckFrameStart(QuicPacketNumber(12), QuicTime::Delta::Infinite(), |
| 2418 | clock_.Now()); |
| 2419 | manager_.OnAckRange(QuicPacketNumber(9), QuicPacketNumber(13)); |
| 2420 | manager_.OnAckRange(QuicPacketNumber(4), QuicPacketNumber(8)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 2421 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 2422 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(2), |
| 2423 | ENCRYPTION_INITIAL)); |
QUICHE team | 9929cc4 | 2019-03-13 08:17:43 -0700 | [diff] [blame] | 2424 | EXPECT_EQ(QuicPacketNumber(16), manager_.GetLargestObserved()); |
| 2425 | } |
| 2426 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2427 | TEST_F(QuicSentPacketManagerTest, MultiplePacketNumberSpaces) { |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 2428 | manager_.EnableMultiplePacketNumberSpacesSupport(); |
fayang | 533cb1b | 2020-01-28 08:05:08 -0800 | [diff] [blame] | 2429 | const QuicUnackedPacketMap* unacked_packets = |
| 2430 | QuicSentPacketManagerPeer::GetUnackedPacketMap(&manager_); |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 2431 | EXPECT_FALSE( |
fayang | 533cb1b | 2020-01-28 08:05:08 -0800 | [diff] [blame] | 2432 | unacked_packets |
| 2433 | ->GetLargestSentRetransmittableOfPacketNumberSpace(INITIAL_DATA) |
| 2434 | .IsInitialized()); |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 2435 | EXPECT_FALSE( |
| 2436 | manager_.GetLargestAckedPacket(ENCRYPTION_INITIAL).IsInitialized()); |
| 2437 | // Send packet 1. |
| 2438 | SendDataPacket(1, ENCRYPTION_INITIAL); |
| 2439 | EXPECT_EQ(QuicPacketNumber(1), |
fayang | 533cb1b | 2020-01-28 08:05:08 -0800 | [diff] [blame] | 2440 | unacked_packets->GetLargestSentRetransmittableOfPacketNumberSpace( |
| 2441 | INITIAL_DATA)); |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 2442 | EXPECT_FALSE( |
fayang | 533cb1b | 2020-01-28 08:05:08 -0800 | [diff] [blame] | 2443 | unacked_packets |
| 2444 | ->GetLargestSentRetransmittableOfPacketNumberSpace(HANDSHAKE_DATA) |
| 2445 | .IsInitialized()); |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 2446 | // Ack packet 1. |
| 2447 | ExpectAck(1); |
| 2448 | manager_.OnAckFrameStart(QuicPacketNumber(1), QuicTime::Delta::Infinite(), |
| 2449 | clock_.Now()); |
| 2450 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 2451 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 2452 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 2453 | ENCRYPTION_INITIAL)); |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 2454 | EXPECT_EQ(QuicPacketNumber(1), |
| 2455 | manager_.GetLargestAckedPacket(ENCRYPTION_INITIAL)); |
| 2456 | EXPECT_FALSE( |
| 2457 | manager_.GetLargestAckedPacket(ENCRYPTION_HANDSHAKE).IsInitialized()); |
| 2458 | // Send packets 2 and 3. |
| 2459 | SendDataPacket(2, ENCRYPTION_HANDSHAKE); |
| 2460 | SendDataPacket(3, ENCRYPTION_HANDSHAKE); |
| 2461 | EXPECT_EQ(QuicPacketNumber(1), |
fayang | 533cb1b | 2020-01-28 08:05:08 -0800 | [diff] [blame] | 2462 | unacked_packets->GetLargestSentRetransmittableOfPacketNumberSpace( |
| 2463 | INITIAL_DATA)); |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 2464 | EXPECT_EQ(QuicPacketNumber(3), |
fayang | 533cb1b | 2020-01-28 08:05:08 -0800 | [diff] [blame] | 2465 | unacked_packets->GetLargestSentRetransmittableOfPacketNumberSpace( |
| 2466 | HANDSHAKE_DATA)); |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 2467 | EXPECT_FALSE( |
fayang | 533cb1b | 2020-01-28 08:05:08 -0800 | [diff] [blame] | 2468 | unacked_packets |
| 2469 | ->GetLargestSentRetransmittableOfPacketNumberSpace(APPLICATION_DATA) |
| 2470 | .IsInitialized()); |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 2471 | // Ack packet 2. |
| 2472 | ExpectAck(2); |
| 2473 | manager_.OnAckFrameStart(QuicPacketNumber(2), QuicTime::Delta::Infinite(), |
| 2474 | clock_.Now()); |
| 2475 | manager_.OnAckRange(QuicPacketNumber(2), QuicPacketNumber(3)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 2476 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 2477 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(2), |
| 2478 | ENCRYPTION_HANDSHAKE)); |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 2479 | EXPECT_EQ(QuicPacketNumber(2), |
| 2480 | manager_.GetLargestAckedPacket(ENCRYPTION_HANDSHAKE)); |
| 2481 | EXPECT_FALSE( |
| 2482 | manager_.GetLargestAckedPacket(ENCRYPTION_ZERO_RTT).IsInitialized()); |
| 2483 | // Ack packet 3. |
| 2484 | ExpectAck(3); |
| 2485 | manager_.OnAckFrameStart(QuicPacketNumber(3), QuicTime::Delta::Infinite(), |
| 2486 | clock_.Now()); |
| 2487 | manager_.OnAckRange(QuicPacketNumber(2), QuicPacketNumber(4)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 2488 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 2489 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(3), |
| 2490 | ENCRYPTION_HANDSHAKE)); |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 2491 | EXPECT_EQ(QuicPacketNumber(3), |
| 2492 | manager_.GetLargestAckedPacket(ENCRYPTION_HANDSHAKE)); |
| 2493 | EXPECT_FALSE( |
| 2494 | manager_.GetLargestAckedPacket(ENCRYPTION_ZERO_RTT).IsInitialized()); |
| 2495 | // Send packets 4 and 5. |
| 2496 | SendDataPacket(4, ENCRYPTION_ZERO_RTT); |
| 2497 | SendDataPacket(5, ENCRYPTION_ZERO_RTT); |
| 2498 | EXPECT_EQ(QuicPacketNumber(1), |
fayang | 533cb1b | 2020-01-28 08:05:08 -0800 | [diff] [blame] | 2499 | unacked_packets->GetLargestSentRetransmittableOfPacketNumberSpace( |
| 2500 | INITIAL_DATA)); |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 2501 | EXPECT_EQ(QuicPacketNumber(3), |
fayang | 533cb1b | 2020-01-28 08:05:08 -0800 | [diff] [blame] | 2502 | unacked_packets->GetLargestSentRetransmittableOfPacketNumberSpace( |
| 2503 | HANDSHAKE_DATA)); |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 2504 | EXPECT_EQ(QuicPacketNumber(5), |
fayang | 533cb1b | 2020-01-28 08:05:08 -0800 | [diff] [blame] | 2505 | unacked_packets->GetLargestSentRetransmittableOfPacketNumberSpace( |
| 2506 | APPLICATION_DATA)); |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 2507 | // Ack packet 5. |
| 2508 | ExpectAck(5); |
| 2509 | manager_.OnAckFrameStart(QuicPacketNumber(5), QuicTime::Delta::Infinite(), |
| 2510 | clock_.Now()); |
| 2511 | manager_.OnAckRange(QuicPacketNumber(5), QuicPacketNumber(6)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 2512 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 2513 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(4), |
| 2514 | ENCRYPTION_FORWARD_SECURE)); |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 2515 | EXPECT_EQ(QuicPacketNumber(3), |
| 2516 | manager_.GetLargestAckedPacket(ENCRYPTION_HANDSHAKE)); |
| 2517 | EXPECT_EQ(QuicPacketNumber(5), |
| 2518 | manager_.GetLargestAckedPacket(ENCRYPTION_ZERO_RTT)); |
| 2519 | EXPECT_EQ(QuicPacketNumber(5), |
| 2520 | manager_.GetLargestAckedPacket(ENCRYPTION_FORWARD_SECURE)); |
| 2521 | |
| 2522 | // Send packets 6 - 8. |
| 2523 | SendDataPacket(6, ENCRYPTION_FORWARD_SECURE); |
| 2524 | SendDataPacket(7, ENCRYPTION_FORWARD_SECURE); |
| 2525 | SendDataPacket(8, ENCRYPTION_FORWARD_SECURE); |
| 2526 | EXPECT_EQ(QuicPacketNumber(1), |
fayang | 533cb1b | 2020-01-28 08:05:08 -0800 | [diff] [blame] | 2527 | unacked_packets->GetLargestSentRetransmittableOfPacketNumberSpace( |
| 2528 | INITIAL_DATA)); |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 2529 | EXPECT_EQ(QuicPacketNumber(3), |
fayang | 533cb1b | 2020-01-28 08:05:08 -0800 | [diff] [blame] | 2530 | unacked_packets->GetLargestSentRetransmittableOfPacketNumberSpace( |
| 2531 | HANDSHAKE_DATA)); |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 2532 | EXPECT_EQ(QuicPacketNumber(8), |
fayang | 533cb1b | 2020-01-28 08:05:08 -0800 | [diff] [blame] | 2533 | unacked_packets->GetLargestSentRetransmittableOfPacketNumberSpace( |
| 2534 | APPLICATION_DATA)); |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 2535 | // Ack all packets. |
| 2536 | uint64_t acked[] = {4, 6, 7, 8}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 2537 | ExpectAcksAndLosses(true, acked, QUICHE_ARRAYSIZE(acked), nullptr, 0); |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 2538 | manager_.OnAckFrameStart(QuicPacketNumber(8), QuicTime::Delta::Infinite(), |
| 2539 | clock_.Now()); |
| 2540 | manager_.OnAckRange(QuicPacketNumber(4), QuicPacketNumber(9)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 2541 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 2542 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(5), |
| 2543 | ENCRYPTION_FORWARD_SECURE)); |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 2544 | EXPECT_EQ(QuicPacketNumber(3), |
| 2545 | manager_.GetLargestAckedPacket(ENCRYPTION_HANDSHAKE)); |
| 2546 | EXPECT_EQ(QuicPacketNumber(8), |
| 2547 | manager_.GetLargestAckedPacket(ENCRYPTION_ZERO_RTT)); |
| 2548 | EXPECT_EQ(QuicPacketNumber(8), |
| 2549 | manager_.GetLargestAckedPacket(ENCRYPTION_FORWARD_SECURE)); |
| 2550 | } |
| 2551 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2552 | TEST_F(QuicSentPacketManagerTest, PacketsGetAckedInWrongPacketNumberSpace) { |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 2553 | manager_.EnableMultiplePacketNumberSpacesSupport(); |
| 2554 | // Send packet 1. |
| 2555 | SendDataPacket(1, ENCRYPTION_INITIAL); |
| 2556 | // Send packets 2 and 3. |
| 2557 | SendDataPacket(2, ENCRYPTION_HANDSHAKE); |
| 2558 | SendDataPacket(3, ENCRYPTION_HANDSHAKE); |
| 2559 | |
| 2560 | // ACK packets 2 and 3 in the wrong packet number space. |
| 2561 | manager_.OnAckFrameStart(QuicPacketNumber(3), QuicTime::Delta::Infinite(), |
| 2562 | clock_.Now()); |
| 2563 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(4)); |
| 2564 | EXPECT_EQ(PACKETS_ACKED_IN_WRONG_PACKET_NUMBER_SPACE, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 2565 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 2566 | ENCRYPTION_INITIAL)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 2567 | } |
| 2568 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2569 | TEST_F(QuicSentPacketManagerTest, PacketsGetAckedInWrongPacketNumberSpace2) { |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 2570 | manager_.EnableMultiplePacketNumberSpacesSupport(); |
| 2571 | // Send packet 1. |
| 2572 | SendDataPacket(1, ENCRYPTION_INITIAL); |
| 2573 | // Send packets 2 and 3. |
| 2574 | SendDataPacket(2, ENCRYPTION_HANDSHAKE); |
| 2575 | SendDataPacket(3, ENCRYPTION_HANDSHAKE); |
| 2576 | |
| 2577 | // ACK packet 1 in the wrong packet number space. |
| 2578 | manager_.OnAckFrameStart(QuicPacketNumber(3), QuicTime::Delta::Infinite(), |
| 2579 | clock_.Now()); |
| 2580 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(4)); |
| 2581 | EXPECT_EQ(PACKETS_ACKED_IN_WRONG_PACKET_NUMBER_SPACE, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 2582 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 2583 | ENCRYPTION_HANDSHAKE)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 2584 | } |
| 2585 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2586 | TEST_F(QuicSentPacketManagerTest, |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 2587 | ToleratePacketsGetAckedInWrongPacketNumberSpace) { |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 2588 | manager_.EnableMultiplePacketNumberSpacesSupport(); |
| 2589 | // Send packet 1. |
| 2590 | SendDataPacket(1, ENCRYPTION_INITIAL); |
| 2591 | // Ack packet 1. |
| 2592 | ExpectAck(1); |
| 2593 | manager_.OnAckFrameStart(QuicPacketNumber(1), QuicTime::Delta::Infinite(), |
| 2594 | clock_.Now()); |
| 2595 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
| 2596 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 2597 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 2598 | ENCRYPTION_INITIAL)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 2599 | |
| 2600 | // Send packets 2 and 3. |
| 2601 | SendDataPacket(2, ENCRYPTION_HANDSHAKE); |
| 2602 | SendDataPacket(3, ENCRYPTION_HANDSHAKE); |
| 2603 | |
| 2604 | // Packet 1 gets acked in the wrong packet number space. Since packet 1 has |
| 2605 | // been acked in the correct packet number space, tolerate it. |
| 2606 | uint64_t acked[] = {2, 3}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 2607 | ExpectAcksAndLosses(true, acked, QUICHE_ARRAYSIZE(acked), nullptr, 0); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 2608 | manager_.OnAckFrameStart(QuicPacketNumber(3), QuicTime::Delta::Infinite(), |
| 2609 | clock_.Now()); |
| 2610 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(4)); |
| 2611 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 2612 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(2), |
| 2613 | ENCRYPTION_HANDSHAKE)); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 2614 | } |
| 2615 | |
fayang | 06bb1b0 | 2019-06-14 14:07:12 -0700 | [diff] [blame] | 2616 | // Regression test for b/133771183. |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2617 | TEST_F(QuicSentPacketManagerTest, PacketInLimbo) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2618 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 2619 | return; |
| 2620 | } |
fayang | 06bb1b0 | 2019-06-14 14:07:12 -0700 | [diff] [blame] | 2621 | QuicSentPacketManagerPeer::SetMaxTailLossProbes(&manager_, 2); |
| 2622 | // Send SHLO. |
| 2623 | SendCryptoPacket(1); |
| 2624 | // Send data packet. |
| 2625 | SendDataPacket(2, ENCRYPTION_FORWARD_SECURE); |
| 2626 | // Send Ack Packet. |
| 2627 | SendAckPacket(3, 1, ENCRYPTION_FORWARD_SECURE); |
| 2628 | // Retransmit SHLO. |
| 2629 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 2630 | .WillOnce(InvokeWithoutArgs([this]() { RetransmitCryptoPacket(4); })); |
| 2631 | manager_.OnRetransmissionTimeout(); |
| 2632 | |
| 2633 | // Successfully decrypt a forward secure packet. |
| 2634 | manager_.SetHandshakeConfirmed(); |
| 2635 | EXPECT_CALL(notifier_, HasUnackedCryptoData()).WillRepeatedly(Return(false)); |
| 2636 | // Send Ack packet. |
| 2637 | SendAckPacket(5, 2, ENCRYPTION_FORWARD_SECURE); |
| 2638 | |
| 2639 | // Retransmission alarm fires. |
| 2640 | manager_.OnRetransmissionTimeout(); |
| 2641 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 2642 | .WillOnce(WithArgs<1>(Invoke([this](TransmissionType type) { |
| 2643 | RetransmitDataPacket(6, type, ENCRYPTION_FORWARD_SECURE); |
| 2644 | }))); |
| 2645 | manager_.MaybeRetransmitTailLossProbe(); |
| 2646 | |
| 2647 | // Received Ack of packets 1, 3 and 4. |
| 2648 | uint64_t acked[] = {1, 3, 4}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 2649 | ExpectAcksAndLosses(true, acked, QUICHE_ARRAYSIZE(acked), nullptr, 0); |
fayang | 06bb1b0 | 2019-06-14 14:07:12 -0700 | [diff] [blame] | 2650 | manager_.OnAckFrameStart(QuicPacketNumber(4), QuicTime::Delta::Infinite(), |
| 2651 | clock_.Now()); |
| 2652 | manager_.OnAckRange(QuicPacketNumber(3), QuicPacketNumber(5)); |
| 2653 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
| 2654 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 2655 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 2656 | ENCRYPTION_INITIAL)); |
fayang | 06bb1b0 | 2019-06-14 14:07:12 -0700 | [diff] [blame] | 2657 | |
| 2658 | uint64_t acked2[] = {5, 6}; |
| 2659 | uint64_t loss[] = {2}; |
fayang | 897605d | 2019-08-21 13:26:45 -0700 | [diff] [blame] | 2660 | // Verify packet 2 is detected lost. |
| 2661 | EXPECT_CALL(notifier_, OnFrameLost(_)).Times(1); |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 2662 | ExpectAcksAndLosses(true, acked2, QUICHE_ARRAYSIZE(acked2), loss, |
| 2663 | QUICHE_ARRAYSIZE(loss)); |
fayang | 06bb1b0 | 2019-06-14 14:07:12 -0700 | [diff] [blame] | 2664 | manager_.OnAckFrameStart(QuicPacketNumber(6), QuicTime::Delta::Infinite(), |
| 2665 | clock_.Now()); |
| 2666 | manager_.OnAckRange(QuicPacketNumber(3), QuicPacketNumber(7)); |
| 2667 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 2668 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(2), |
| 2669 | ENCRYPTION_INITIAL)); |
fayang | 06bb1b0 | 2019-06-14 14:07:12 -0700 | [diff] [blame] | 2670 | } |
| 2671 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2672 | TEST_F(QuicSentPacketManagerTest, RtoFiresNoPacketToRetransmit) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2673 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 2674 | return; |
| 2675 | } |
fayang | a29eb24 | 2019-07-16 12:25:38 -0700 | [diff] [blame] | 2676 | // Send 10 packets. |
| 2677 | for (size_t i = 1; i <= 10; ++i) { |
| 2678 | SendDataPacket(i); |
| 2679 | } |
| 2680 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 2681 | .Times(2) |
| 2682 | .WillOnce(WithArgs<1>(Invoke( |
| 2683 | [this](TransmissionType type) { RetransmitDataPacket(11, type); }))) |
| 2684 | .WillOnce(WithArgs<1>(Invoke( |
| 2685 | [this](TransmissionType type) { RetransmitDataPacket(12, type); }))); |
| 2686 | manager_.OnRetransmissionTimeout(); |
| 2687 | EXPECT_EQ(1u, stats_.rto_count); |
| 2688 | EXPECT_EQ(0u, manager_.pending_timer_transmission_count()); |
| 2689 | |
| 2690 | // RTO fires again, but there is no packet to be RTO retransmitted. |
| 2691 | EXPECT_CALL(notifier_, IsFrameOutstanding(_)).WillRepeatedly(Return(false)); |
| 2692 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)).Times(0); |
| 2693 | manager_.OnRetransmissionTimeout(); |
| 2694 | EXPECT_EQ(2u, stats_.rto_count); |
fayang | e861aee | 2019-10-16 13:40:39 -0700 | [diff] [blame] | 2695 | // Verify a credit is raised up. |
| 2696 | EXPECT_EQ(1u, manager_.pending_timer_transmission_count()); |
fayang | a29eb24 | 2019-07-16 12:25:38 -0700 | [diff] [blame] | 2697 | } |
| 2698 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2699 | TEST_F(QuicSentPacketManagerTest, ComputingProbeTimeout) { |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 2700 | EnablePto(k2PTO); |
| 2701 | EXPECT_CALL(*send_algorithm_, PacingRate(_)) |
| 2702 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
| 2703 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
| 2704 | .WillRepeatedly(Return(10 * kDefaultTCPMSS)); |
| 2705 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 2706 | rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(100), |
| 2707 | QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 2708 | QuicTime::Delta srtt = rtt_stats->smoothed_rtt(); |
| 2709 | |
| 2710 | SendDataPacket(1, ENCRYPTION_FORWARD_SECURE); |
| 2711 | // Verify PTO is correctly set. |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2712 | int pto_rttvar_multiplier = |
| 2713 | GetQuicReloadableFlag(quic_default_on_pto) ? 2 : 4; |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 2714 | QuicTime::Delta expected_pto_delay = |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2715 | srtt + pto_rttvar_multiplier * rtt_stats->mean_deviation() + |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 2716 | QuicTime::Delta::FromMilliseconds(kDefaultDelayedAckTimeMs); |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2717 | QuicTime packet1_sent_time = clock_.Now(); |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 2718 | EXPECT_EQ(clock_.Now() + expected_pto_delay, |
| 2719 | manager_.GetRetransmissionTime()); |
| 2720 | |
| 2721 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
| 2722 | SendDataPacket(2, ENCRYPTION_FORWARD_SECURE); |
| 2723 | // Verify PTO is correctly set based on sent time of packet 2. |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2724 | QuicTime deadline = clock_.Now() + expected_pto_delay; |
| 2725 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 2726 | // Verify PTO is set based on left edge. |
| 2727 | deadline = packet1_sent_time + expected_pto_delay; |
| 2728 | } |
| 2729 | EXPECT_EQ(deadline, manager_.GetRetransmissionTime()); |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 2730 | EXPECT_EQ(0u, stats_.pto_count); |
| 2731 | |
| 2732 | // Invoke PTO. |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2733 | clock_.AdvanceTime(deadline - clock_.Now()); |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 2734 | manager_.OnRetransmissionTimeout(); |
| 2735 | EXPECT_EQ(QuicTime::Delta::Zero(), manager_.TimeUntilSend(clock_.Now())); |
| 2736 | EXPECT_EQ(1u, stats_.pto_count); |
fayang | 2a379bf | 2020-05-18 11:49:25 -0700 | [diff] [blame] | 2737 | EXPECT_EQ(0u, stats_.max_consecutive_rto_with_forward_progress); |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 2738 | |
| 2739 | // Verify two probe packets get sent. |
| 2740 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 2741 | .Times(2) |
| 2742 | .WillOnce(WithArgs<1>(Invoke([this](TransmissionType type) { |
| 2743 | RetransmitDataPacket(3, type, ENCRYPTION_FORWARD_SECURE); |
| 2744 | }))) |
| 2745 | .WillOnce(WithArgs<1>(Invoke([this](TransmissionType type) { |
| 2746 | RetransmitDataPacket(4, type, ENCRYPTION_FORWARD_SECURE); |
| 2747 | }))); |
| 2748 | manager_.MaybeSendProbePackets(); |
| 2749 | // Verify PTO period gets set to twice the current value. |
| 2750 | QuicTime sent_time = clock_.Now(); |
| 2751 | EXPECT_EQ(sent_time + expected_pto_delay * 2, |
| 2752 | manager_.GetRetransmissionTime()); |
| 2753 | |
| 2754 | // Received ACK for packets 1 and 2. |
| 2755 | uint64_t acked[] = {1, 2}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 2756 | ExpectAcksAndLosses(true, acked, QUICHE_ARRAYSIZE(acked), nullptr, 0); |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 2757 | manager_.OnAckFrameStart(QuicPacketNumber(2), QuicTime::Delta::Infinite(), |
| 2758 | clock_.Now()); |
| 2759 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(3)); |
| 2760 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
| 2761 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 2762 | ENCRYPTION_FORWARD_SECURE)); |
| 2763 | expected_pto_delay = |
| 2764 | rtt_stats->SmoothedOrInitialRtt() + |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2765 | std::max(pto_rttvar_multiplier * rtt_stats->mean_deviation(), |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 2766 | QuicTime::Delta::FromMilliseconds(1)) + |
| 2767 | QuicTime::Delta::FromMilliseconds(kDefaultDelayedAckTimeMs); |
| 2768 | |
| 2769 | // Verify PTO is correctly re-armed based on sent time of packet 4. |
| 2770 | EXPECT_EQ(sent_time + expected_pto_delay, manager_.GetRetransmissionTime()); |
fayang | 2a379bf | 2020-05-18 11:49:25 -0700 | [diff] [blame] | 2771 | EXPECT_EQ(1u, stats_.max_consecutive_rto_with_forward_progress); |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 2772 | } |
| 2773 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2774 | TEST_F(QuicSentPacketManagerTest, SendOneProbePacket) { |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 2775 | EnablePto(k1PTO); |
| 2776 | EXPECT_CALL(*send_algorithm_, PacingRate(_)) |
| 2777 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
| 2778 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
| 2779 | .WillRepeatedly(Return(10 * kDefaultTCPMSS)); |
| 2780 | |
| 2781 | SendDataPacket(1, ENCRYPTION_FORWARD_SECURE); |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2782 | QuicTime packet1_sent_time = clock_.Now(); |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 2783 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
| 2784 | SendDataPacket(2, ENCRYPTION_FORWARD_SECURE); |
| 2785 | |
| 2786 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 2787 | rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(100), |
| 2788 | QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 2789 | QuicTime::Delta srtt = rtt_stats->smoothed_rtt(); |
| 2790 | // Verify PTO period is correctly set. |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2791 | int pto_rttvar_multiplier = |
| 2792 | GetQuicReloadableFlag(quic_default_on_pto) ? 2 : 4; |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 2793 | QuicTime::Delta expected_pto_delay = |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2794 | srtt + pto_rttvar_multiplier * rtt_stats->mean_deviation() + |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 2795 | QuicTime::Delta::FromMilliseconds(kDefaultDelayedAckTimeMs); |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2796 | QuicTime deadline = clock_.Now() + expected_pto_delay; |
| 2797 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 2798 | // Verify PTO is set based on left edge. |
| 2799 | deadline = packet1_sent_time + expected_pto_delay; |
| 2800 | } |
| 2801 | EXPECT_EQ(deadline, manager_.GetRetransmissionTime()); |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 2802 | |
| 2803 | // Invoke PTO. |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2804 | clock_.AdvanceTime(deadline - clock_.Now()); |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 2805 | manager_.OnRetransmissionTimeout(); |
| 2806 | EXPECT_EQ(QuicTime::Delta::Zero(), manager_.TimeUntilSend(clock_.Now())); |
| 2807 | |
| 2808 | // Verify one probe packet gets sent. |
| 2809 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 2810 | .WillOnce(WithArgs<1>(Invoke([this](TransmissionType type) { |
| 2811 | RetransmitDataPacket(3, type, ENCRYPTION_FORWARD_SECURE); |
| 2812 | }))); |
| 2813 | manager_.MaybeSendProbePackets(); |
| 2814 | } |
| 2815 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2816 | TEST_F(QuicSentPacketManagerTest, DisableHandshakeModeClient) { |
fayang | 5f13505 | 2019-08-22 17:59:40 -0700 | [diff] [blame] | 2817 | QuicSentPacketManagerPeer::SetPerspective(&manager_, Perspective::IS_CLIENT); |
fayang | af9903b | 2020-05-14 14:34:28 -0700 | [diff] [blame] | 2818 | manager_.EnableMultiplePacketNumberSpacesSupport(); |
fayang | 5f13505 | 2019-08-22 17:59:40 -0700 | [diff] [blame] | 2819 | // Send CHLO. |
| 2820 | SendCryptoPacket(1); |
| 2821 | EXPECT_NE(QuicTime::Zero(), manager_.GetRetransmissionTime()); |
| 2822 | // Ack packet 1. |
| 2823 | ExpectAck(1); |
| 2824 | manager_.OnAckFrameStart(QuicPacketNumber(1), QuicTime::Delta::Infinite(), |
| 2825 | clock_.Now()); |
| 2826 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
| 2827 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
| 2828 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 2829 | ENCRYPTION_INITIAL)); |
| 2830 | EXPECT_EQ(0u, manager_.GetBytesInFlight()); |
| 2831 | // Verify retransmission timeout is not zero because handshake is not |
| 2832 | // confirmed although there is no in flight packet. |
| 2833 | EXPECT_NE(QuicTime::Zero(), manager_.GetRetransmissionTime()); |
| 2834 | // Fire PTO. |
| 2835 | EXPECT_EQ(QuicSentPacketManager::PTO_MODE, |
| 2836 | manager_.OnRetransmissionTimeout()); |
| 2837 | } |
| 2838 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 2839 | TEST_F(QuicSentPacketManagerTest, DisableHandshakeModeServer) { |
fayang | 08a6c95 | 2019-09-18 14:29:45 -0700 | [diff] [blame] | 2840 | manager_.EnableIetfPtoAndLossDetection(); |
fayang | 5f13505 | 2019-08-22 17:59:40 -0700 | [diff] [blame] | 2841 | // Send SHLO. |
| 2842 | SendCryptoPacket(1); |
| 2843 | EXPECT_NE(QuicTime::Zero(), manager_.GetRetransmissionTime()); |
| 2844 | // Ack packet 1. |
| 2845 | ExpectAck(1); |
| 2846 | manager_.OnAckFrameStart(QuicPacketNumber(1), QuicTime::Delta::Infinite(), |
| 2847 | clock_.Now()); |
| 2848 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(2)); |
| 2849 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
| 2850 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 2851 | ENCRYPTION_INITIAL)); |
| 2852 | EXPECT_EQ(0u, manager_.GetBytesInFlight()); |
| 2853 | // Verify retransmission timeout is not set on server side because there is |
| 2854 | // nothing in flight. |
| 2855 | EXPECT_EQ(QuicTime::Zero(), manager_.GetRetransmissionTime()); |
| 2856 | } |
| 2857 | |
fayang | 4c908f0 | 2019-11-01 07:26:17 -0700 | [diff] [blame] | 2858 | TEST_F(QuicSentPacketManagerTest, PtoTimeoutIncludesMaxAckDelay) { |
| 2859 | EnablePto(k1PTO); |
| 2860 | // Use PTOS and PTOA. |
| 2861 | QuicConfig config; |
| 2862 | QuicTagVector options; |
| 2863 | options.push_back(kPTOS); |
| 2864 | options.push_back(kPTOA); |
| 2865 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 2866 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 2867 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 2868 | manager_.SetFromConfig(config); |
| 2869 | EXPECT_TRUE(manager_.skip_packet_number_for_pto()); |
| 2870 | EXPECT_CALL(*send_algorithm_, CanSend(_)).WillRepeatedly(Return(true)); |
| 2871 | |
| 2872 | EXPECT_CALL(*send_algorithm_, PacingRate(_)) |
| 2873 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
| 2874 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
| 2875 | .WillRepeatedly(Return(10 * kDefaultTCPMSS)); |
| 2876 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 2877 | rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(100), |
| 2878 | QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 2879 | QuicTime::Delta srtt = rtt_stats->smoothed_rtt(); |
| 2880 | |
| 2881 | SendDataPacket(1, ENCRYPTION_FORWARD_SECURE); |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2882 | QuicTime packet1_sent_time = clock_.Now(); |
fayang | 4c908f0 | 2019-11-01 07:26:17 -0700 | [diff] [blame] | 2883 | // Verify PTO is correctly set and ack delay is included. |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2884 | int pto_rttvar_multiplier = |
| 2885 | GetQuicReloadableFlag(quic_default_on_pto) ? 2 : 4; |
fayang | 4c908f0 | 2019-11-01 07:26:17 -0700 | [diff] [blame] | 2886 | QuicTime::Delta expected_pto_delay = |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2887 | srtt + pto_rttvar_multiplier * rtt_stats->mean_deviation() + |
fayang | 4c908f0 | 2019-11-01 07:26:17 -0700 | [diff] [blame] | 2888 | QuicTime::Delta::FromMilliseconds(kDefaultDelayedAckTimeMs); |
| 2889 | EXPECT_EQ(clock_.Now() + expected_pto_delay, |
| 2890 | manager_.GetRetransmissionTime()); |
| 2891 | |
| 2892 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
| 2893 | SendDataPacket(2, ENCRYPTION_FORWARD_SECURE); |
| 2894 | // Verify PTO is correctly set based on sent time of packet 2 but ack delay is |
| 2895 | // not included as an immediate ACK is expected. |
| 2896 | expected_pto_delay = expected_pto_delay - QuicTime::Delta::FromMilliseconds( |
| 2897 | kDefaultDelayedAckTimeMs); |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2898 | QuicTime deadline = clock_.Now() + expected_pto_delay; |
| 2899 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 2900 | deadline = packet1_sent_time + expected_pto_delay; |
| 2901 | } |
| 2902 | EXPECT_EQ(deadline, manager_.GetRetransmissionTime()); |
fayang | 4c908f0 | 2019-11-01 07:26:17 -0700 | [diff] [blame] | 2903 | EXPECT_EQ(0u, stats_.pto_count); |
| 2904 | |
| 2905 | // Invoke PTO. |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2906 | clock_.AdvanceTime(deadline - clock_.Now()); |
fayang | 4c908f0 | 2019-11-01 07:26:17 -0700 | [diff] [blame] | 2907 | manager_.OnRetransmissionTimeout(); |
| 2908 | EXPECT_EQ(QuicTime::Delta::Zero(), manager_.TimeUntilSend(clock_.Now())); |
| 2909 | EXPECT_EQ(1u, stats_.pto_count); |
| 2910 | |
| 2911 | // Verify 1 probe packets get sent and packet number gets skipped. |
| 2912 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 2913 | .WillOnce(WithArgs<1>(Invoke([this](TransmissionType type) { |
| 2914 | RetransmitDataPacket(4, type, ENCRYPTION_FORWARD_SECURE); |
| 2915 | }))); |
| 2916 | manager_.MaybeSendProbePackets(); |
| 2917 | // Verify PTO period gets set to twice the current value. Also, ack delay is |
| 2918 | // not included. |
| 2919 | QuicTime sent_time = clock_.Now(); |
| 2920 | EXPECT_EQ(sent_time + expected_pto_delay * 2, |
| 2921 | manager_.GetRetransmissionTime()); |
| 2922 | |
| 2923 | // Received ACK for packets 1 and 2. |
| 2924 | uint64_t acked[] = {1, 2}; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 2925 | ExpectAcksAndLosses(true, acked, QUICHE_ARRAYSIZE(acked), nullptr, 0); |
fayang | 4c908f0 | 2019-11-01 07:26:17 -0700 | [diff] [blame] | 2926 | manager_.OnAckFrameStart(QuicPacketNumber(2), QuicTime::Delta::Infinite(), |
| 2927 | clock_.Now()); |
| 2928 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(3)); |
| 2929 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
| 2930 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 2931 | ENCRYPTION_FORWARD_SECURE)); |
| 2932 | expected_pto_delay = |
| 2933 | rtt_stats->SmoothedOrInitialRtt() + |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2934 | std::max(pto_rttvar_multiplier * rtt_stats->mean_deviation(), |
fayang | 4c908f0 | 2019-11-01 07:26:17 -0700 | [diff] [blame] | 2935 | QuicTime::Delta::FromMilliseconds(1)) + |
| 2936 | QuicTime::Delta::FromMilliseconds(kDefaultDelayedAckTimeMs); |
| 2937 | |
| 2938 | // Verify PTO is correctly re-armed based on sent time of packet 4. Because of |
| 2939 | // PTOS turns out to be spurious, ACK delay is included. |
| 2940 | EXPECT_EQ(sent_time + expected_pto_delay, manager_.GetRetransmissionTime()); |
| 2941 | |
| 2942 | // Received ACK for packets 4. |
| 2943 | ExpectAck(4); |
| 2944 | manager_.OnAckFrameStart(QuicPacketNumber(4), QuicTime::Delta::Infinite(), |
| 2945 | clock_.Now()); |
| 2946 | manager_.OnAckRange(QuicPacketNumber(4), QuicPacketNumber(5)); |
| 2947 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
| 2948 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(4), |
| 2949 | ENCRYPTION_FORWARD_SECURE)); |
| 2950 | EXPECT_EQ(QuicTime::Zero(), manager_.GetRetransmissionTime()); |
| 2951 | // Send more packets, such that peer will do ack decimation. |
| 2952 | std::vector<uint64_t> acked2; |
| 2953 | for (size_t i = 5; i <= 100; ++i) { |
| 2954 | SendDataPacket(i, ENCRYPTION_FORWARD_SECURE); |
| 2955 | acked2.push_back(i); |
| 2956 | } |
| 2957 | // Received ACK for all sent packets. |
| 2958 | ExpectAcksAndLosses(true, &acked2[0], acked2.size(), nullptr, 0); |
| 2959 | manager_.OnAckFrameStart(QuicPacketNumber(100), QuicTime::Delta::Infinite(), |
| 2960 | clock_.Now()); |
| 2961 | manager_.OnAckRange(QuicPacketNumber(5), QuicPacketNumber(101)); |
| 2962 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
| 2963 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(100), |
| 2964 | ENCRYPTION_FORWARD_SECURE)); |
| 2965 | |
| 2966 | expected_pto_delay = |
| 2967 | rtt_stats->SmoothedOrInitialRtt() + |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 2968 | std::max(pto_rttvar_multiplier * rtt_stats->mean_deviation(), |
fayang | 4c908f0 | 2019-11-01 07:26:17 -0700 | [diff] [blame] | 2969 | QuicTime::Delta::FromMilliseconds(1)) + |
| 2970 | QuicTime::Delta::FromMilliseconds(kDefaultDelayedAckTimeMs); |
| 2971 | for (size_t i = 101; i < 110; i++) { |
| 2972 | SendDataPacket(i, ENCRYPTION_FORWARD_SECURE); |
| 2973 | // Verify PTO timeout includes ACK delay as there are less than 10 packets |
| 2974 | // outstanding. |
| 2975 | EXPECT_EQ(clock_.Now() + expected_pto_delay, |
| 2976 | manager_.GetRetransmissionTime()); |
| 2977 | } |
| 2978 | expected_pto_delay = expected_pto_delay - QuicTime::Delta::FromMilliseconds( |
| 2979 | kDefaultDelayedAckTimeMs); |
| 2980 | SendDataPacket(110, ENCRYPTION_FORWARD_SECURE); |
| 2981 | // Verify ACK delay is excluded. |
| 2982 | EXPECT_EQ(clock_.Now() + expected_pto_delay, |
| 2983 | manager_.GetRetransmissionTime()); |
| 2984 | } |
| 2985 | |
fayang | 7085a6d | 2019-11-04 07:03:57 -0800 | [diff] [blame] | 2986 | TEST_F(QuicSentPacketManagerTest, StartExponentialBackoffSince2ndPto) { |
| 2987 | EnablePto(k2PTO); |
| 2988 | QuicConfig config; |
| 2989 | QuicTagVector options; |
| 2990 | options.push_back(kPEB2); |
| 2991 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 2992 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 2993 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 2994 | manager_.SetFromConfig(config); |
| 2995 | |
| 2996 | EXPECT_CALL(*send_algorithm_, PacingRate(_)) |
| 2997 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
| 2998 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
| 2999 | .WillRepeatedly(Return(10 * kDefaultTCPMSS)); |
| 3000 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 3001 | rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(100), |
| 3002 | QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 3003 | QuicTime::Delta srtt = rtt_stats->smoothed_rtt(); |
| 3004 | |
| 3005 | SendDataPacket(1, ENCRYPTION_FORWARD_SECURE); |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3006 | QuicTime packet1_sent_time = clock_.Now(); |
fayang | 7085a6d | 2019-11-04 07:03:57 -0800 | [diff] [blame] | 3007 | // Verify PTO is correctly set. |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3008 | int pto_rttvar_multiplier = |
| 3009 | GetQuicReloadableFlag(quic_default_on_pto) ? 2 : 4; |
fayang | 7085a6d | 2019-11-04 07:03:57 -0800 | [diff] [blame] | 3010 | QuicTime::Delta expected_pto_delay = |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3011 | srtt + pto_rttvar_multiplier * rtt_stats->mean_deviation() + |
fayang | 7085a6d | 2019-11-04 07:03:57 -0800 | [diff] [blame] | 3012 | QuicTime::Delta::FromMilliseconds(kDefaultDelayedAckTimeMs); |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3013 | EXPECT_EQ(packet1_sent_time + expected_pto_delay, |
fayang | 7085a6d | 2019-11-04 07:03:57 -0800 | [diff] [blame] | 3014 | manager_.GetRetransmissionTime()); |
| 3015 | |
| 3016 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
| 3017 | SendDataPacket(2, ENCRYPTION_FORWARD_SECURE); |
| 3018 | // Verify PTO is correctly set based on sent time of packet 2. |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3019 | QuicTime deadline = clock_.Now() + expected_pto_delay; |
| 3020 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 3021 | // Verify PTO is set based on left edge. |
| 3022 | deadline = packet1_sent_time + expected_pto_delay; |
| 3023 | } |
| 3024 | EXPECT_EQ(deadline, manager_.GetRetransmissionTime()); |
fayang | 7085a6d | 2019-11-04 07:03:57 -0800 | [diff] [blame] | 3025 | EXPECT_EQ(0u, stats_.pto_count); |
| 3026 | |
| 3027 | // Invoke PTO. |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3028 | clock_.AdvanceTime(deadline - clock_.Now()); |
fayang | 7085a6d | 2019-11-04 07:03:57 -0800 | [diff] [blame] | 3029 | manager_.OnRetransmissionTimeout(); |
| 3030 | EXPECT_EQ(QuicTime::Delta::Zero(), manager_.TimeUntilSend(clock_.Now())); |
| 3031 | EXPECT_EQ(1u, stats_.pto_count); |
| 3032 | |
| 3033 | // Verify two probe packets get sent. |
| 3034 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 3035 | .Times(2) |
| 3036 | .WillOnce(WithArgs<1>(Invoke([this](TransmissionType type) { |
| 3037 | RetransmitDataPacket(3, type, ENCRYPTION_FORWARD_SECURE); |
| 3038 | }))) |
| 3039 | .WillOnce(WithArgs<1>(Invoke([this](TransmissionType type) { |
| 3040 | RetransmitDataPacket(4, type, ENCRYPTION_FORWARD_SECURE); |
| 3041 | }))); |
| 3042 | manager_.MaybeSendProbePackets(); |
| 3043 | // Verify no exponential backoff. |
| 3044 | EXPECT_EQ(clock_.Now() + expected_pto_delay, |
| 3045 | manager_.GetRetransmissionTime()); |
| 3046 | |
| 3047 | // Invoke 2nd PTO. |
| 3048 | clock_.AdvanceTime(expected_pto_delay); |
| 3049 | manager_.OnRetransmissionTimeout(); |
| 3050 | EXPECT_EQ(QuicTime::Delta::Zero(), manager_.TimeUntilSend(clock_.Now())); |
| 3051 | EXPECT_EQ(2u, stats_.pto_count); |
| 3052 | |
| 3053 | // Verify two probe packets get sent. |
| 3054 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 3055 | .Times(2) |
| 3056 | .WillOnce(WithArgs<1>(Invoke([this](TransmissionType type) { |
| 3057 | RetransmitDataPacket(5, type, ENCRYPTION_FORWARD_SECURE); |
| 3058 | }))) |
| 3059 | .WillOnce(WithArgs<1>(Invoke([this](TransmissionType type) { |
| 3060 | RetransmitDataPacket(6, type, ENCRYPTION_FORWARD_SECURE); |
| 3061 | }))); |
| 3062 | manager_.MaybeSendProbePackets(); |
| 3063 | // Verify still no exponential backoff. |
| 3064 | EXPECT_EQ(clock_.Now() + expected_pto_delay, |
| 3065 | manager_.GetRetransmissionTime()); |
| 3066 | |
| 3067 | // Invoke 3rd PTO. |
| 3068 | clock_.AdvanceTime(expected_pto_delay); |
| 3069 | manager_.OnRetransmissionTimeout(); |
| 3070 | EXPECT_EQ(QuicTime::Delta::Zero(), manager_.TimeUntilSend(clock_.Now())); |
| 3071 | EXPECT_EQ(3u, stats_.pto_count); |
| 3072 | |
| 3073 | // Verify two probe packets get sent. |
| 3074 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 3075 | .Times(2) |
| 3076 | .WillOnce(WithArgs<1>(Invoke([this](TransmissionType type) { |
| 3077 | RetransmitDataPacket(7, type, ENCRYPTION_FORWARD_SECURE); |
| 3078 | }))) |
| 3079 | .WillOnce(WithArgs<1>(Invoke([this](TransmissionType type) { |
| 3080 | RetransmitDataPacket(8, type, ENCRYPTION_FORWARD_SECURE); |
| 3081 | }))); |
| 3082 | manager_.MaybeSendProbePackets(); |
| 3083 | // Verify exponential backoff starts. |
| 3084 | EXPECT_EQ(clock_.Now() + expected_pto_delay * 2, |
| 3085 | manager_.GetRetransmissionTime()); |
| 3086 | |
| 3087 | // Invoke 4th PTO. |
| 3088 | clock_.AdvanceTime(expected_pto_delay * 2); |
| 3089 | manager_.OnRetransmissionTimeout(); |
| 3090 | EXPECT_EQ(QuicTime::Delta::Zero(), manager_.TimeUntilSend(clock_.Now())); |
| 3091 | EXPECT_EQ(4u, stats_.pto_count); |
| 3092 | |
| 3093 | // Verify two probe packets get sent. |
| 3094 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 3095 | .Times(2) |
| 3096 | .WillOnce(WithArgs<1>(Invoke([this](TransmissionType type) { |
| 3097 | RetransmitDataPacket(9, type, ENCRYPTION_FORWARD_SECURE); |
| 3098 | }))) |
| 3099 | .WillOnce(WithArgs<1>(Invoke([this](TransmissionType type) { |
| 3100 | RetransmitDataPacket(10, type, ENCRYPTION_FORWARD_SECURE); |
| 3101 | }))); |
| 3102 | manager_.MaybeSendProbePackets(); |
| 3103 | // Verify exponential backoff continues. |
| 3104 | EXPECT_EQ(clock_.Now() + expected_pto_delay * 4, |
| 3105 | manager_.GetRetransmissionTime()); |
| 3106 | } |
| 3107 | |
fayang | 75db434 | 2019-11-04 13:29:14 -0800 | [diff] [blame] | 3108 | TEST_F(QuicSentPacketManagerTest, PtoTimeoutRttVarMultiple) { |
| 3109 | EnablePto(k1PTO); |
| 3110 | // Use 2 * rttvar |
| 3111 | QuicConfig config; |
| 3112 | QuicTagVector options; |
| 3113 | options.push_back(kPVS1); |
| 3114 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 3115 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3116 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 3117 | manager_.SetFromConfig(config); |
| 3118 | |
| 3119 | EXPECT_CALL(*send_algorithm_, PacingRate(_)) |
| 3120 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
| 3121 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
| 3122 | .WillRepeatedly(Return(10 * kDefaultTCPMSS)); |
| 3123 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 3124 | rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(100), |
| 3125 | QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 3126 | QuicTime::Delta srtt = rtt_stats->smoothed_rtt(); |
| 3127 | |
| 3128 | SendDataPacket(1, ENCRYPTION_FORWARD_SECURE); |
| 3129 | // Verify PTO is correctly set based on 2 times rtt var. |
| 3130 | QuicTime::Delta expected_pto_delay = |
| 3131 | srtt + 2 * rtt_stats->mean_deviation() + |
| 3132 | QuicTime::Delta::FromMilliseconds(kDefaultDelayedAckTimeMs); |
| 3133 | EXPECT_EQ(clock_.Now() + expected_pto_delay, |
| 3134 | manager_.GetRetransmissionTime()); |
| 3135 | } |
| 3136 | |
fayang | 93c8394 | 2019-11-07 10:41:16 -0800 | [diff] [blame] | 3137 | // Regression test for b/143962153 |
| 3138 | TEST_F(QuicSentPacketManagerTest, RtoNotInFlightPacket) { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3139 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 3140 | return; |
| 3141 | } |
fayang | 93c8394 | 2019-11-07 10:41:16 -0800 | [diff] [blame] | 3142 | QuicSentPacketManagerPeer::SetMaxTailLossProbes(&manager_, 2); |
| 3143 | // Send SHLO. |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 3144 | QuicStreamFrame crypto_frame(1, false, 0, quiche::QuicheStringPiece()); |
fayang | 93c8394 | 2019-11-07 10:41:16 -0800 | [diff] [blame] | 3145 | SendCryptoPacket(1); |
| 3146 | // Send data packet. |
| 3147 | SendDataPacket(2, ENCRYPTION_FORWARD_SECURE); |
| 3148 | |
| 3149 | // Successfully decrypt a forward secure packet. |
fayang | e1e81d2 | 2020-01-06 11:41:34 -0800 | [diff] [blame] | 3150 | EXPECT_CALL(notifier_, OnFrameAcked(_, _, _)).Times(1); |
fayang | 93c8394 | 2019-11-07 10:41:16 -0800 | [diff] [blame] | 3151 | manager_.SetHandshakeConfirmed(); |
| 3152 | |
| 3153 | // 1st TLP. |
| 3154 | manager_.OnRetransmissionTimeout(); |
| 3155 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 3156 | .WillOnce(WithArgs<1>(Invoke([this](TransmissionType type) { |
| 3157 | RetransmitDataPacket(3, type, ENCRYPTION_FORWARD_SECURE); |
| 3158 | }))); |
| 3159 | manager_.MaybeRetransmitTailLossProbe(); |
| 3160 | |
| 3161 | // 2nd TLP. |
| 3162 | manager_.OnRetransmissionTimeout(); |
| 3163 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 3164 | .WillOnce(WithArgs<1>(Invoke([this](TransmissionType type) { |
| 3165 | RetransmitDataPacket(4, type, ENCRYPTION_FORWARD_SECURE); |
| 3166 | }))); |
| 3167 | manager_.MaybeRetransmitTailLossProbe(); |
| 3168 | |
| 3169 | // RTO retransmits SHLO although it is not in flight. |
fayang | 93c8394 | 2019-11-07 10:41:16 -0800 | [diff] [blame] | 3170 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
fayang | ac35d45 | 2019-11-08 12:35:15 -0800 | [diff] [blame] | 3171 | .WillOnce(WithArgs<0>(Invoke([&crypto_frame](const QuicFrames& frames) { |
| 3172 | EXPECT_EQ(1u, frames.size()); |
fayang | e1e81d2 | 2020-01-06 11:41:34 -0800 | [diff] [blame] | 3173 | EXPECT_NE(crypto_frame, frames[0].stream_frame); |
fayang | ac35d45 | 2019-11-08 12:35:15 -0800 | [diff] [blame] | 3174 | }))); |
fayang | 93c8394 | 2019-11-07 10:41:16 -0800 | [diff] [blame] | 3175 | manager_.OnRetransmissionTimeout(); |
| 3176 | } |
| 3177 | |
fayang | 4aa2240 | 2020-01-07 11:36:07 -0800 | [diff] [blame] | 3178 | TEST_F(QuicSentPacketManagerTest, Aggressive1Pto) { |
| 3179 | EnablePto(k1PTO); |
| 3180 | // Let the first PTO be aggressive. |
| 3181 | QuicConfig config; |
| 3182 | QuicTagVector options; |
| 3183 | options.push_back(kPTOS); |
| 3184 | options.push_back(kPAG1); |
| 3185 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 3186 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3187 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 3188 | manager_.SetFromConfig(config); |
| 3189 | |
| 3190 | EXPECT_CALL(*send_algorithm_, PacingRate(_)) |
| 3191 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
| 3192 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
| 3193 | .WillRepeatedly(Return(10 * kDefaultTCPMSS)); |
| 3194 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 3195 | rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(100), |
| 3196 | QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 3197 | QuicTime::Delta srtt = rtt_stats->smoothed_rtt(); |
| 3198 | SendDataPacket(1, ENCRYPTION_FORWARD_SECURE); |
| 3199 | // Verify PTO is correctly set. |
| 3200 | QuicTime::Delta expected_pto_delay = 2 * srtt; |
| 3201 | EXPECT_EQ(clock_.Now() + expected_pto_delay, |
| 3202 | manager_.GetRetransmissionTime()); |
| 3203 | |
| 3204 | // Invoke PTO. |
| 3205 | clock_.AdvanceTime(expected_pto_delay); |
| 3206 | manager_.OnRetransmissionTimeout(); |
| 3207 | EXPECT_EQ(QuicTime::Delta::Zero(), manager_.TimeUntilSend(clock_.Now())); |
| 3208 | EXPECT_EQ(1u, stats_.pto_count); |
| 3209 | |
| 3210 | // Verify 1 probe packets get sent and packet number gets skipped. |
| 3211 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 3212 | .WillOnce(WithArgs<1>(Invoke([this](TransmissionType type) { |
| 3213 | RetransmitDataPacket(3, type, ENCRYPTION_FORWARD_SECURE); |
| 3214 | }))); |
| 3215 | manager_.MaybeSendProbePackets(); |
| 3216 | |
| 3217 | // Verify PTO period gets set correctly. |
| 3218 | QuicTime sent_time = clock_.Now(); |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3219 | int pto_rttvar_multiplier = |
| 3220 | GetQuicReloadableFlag(quic_default_on_pto) ? 2 : 4; |
fayang | 4aa2240 | 2020-01-07 11:36:07 -0800 | [diff] [blame] | 3221 | expected_pto_delay = |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3222 | srtt + pto_rttvar_multiplier * rtt_stats->mean_deviation() + |
fayang | 4aa2240 | 2020-01-07 11:36:07 -0800 | [diff] [blame] | 3223 | QuicTime::Delta::FromMilliseconds(kDefaultDelayedAckTimeMs); |
| 3224 | EXPECT_EQ(sent_time + expected_pto_delay * 2, |
| 3225 | manager_.GetRetransmissionTime()); |
| 3226 | } |
| 3227 | |
| 3228 | TEST_F(QuicSentPacketManagerTest, Aggressive2Ptos) { |
| 3229 | EnablePto(k1PTO); |
| 3230 | // Let the first PTO be aggressive. |
| 3231 | QuicConfig config; |
| 3232 | QuicTagVector options; |
| 3233 | options.push_back(kPTOS); |
| 3234 | options.push_back(kPAG2); |
| 3235 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 3236 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3237 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 3238 | manager_.SetFromConfig(config); |
| 3239 | |
| 3240 | EXPECT_CALL(*send_algorithm_, PacingRate(_)) |
| 3241 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
| 3242 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
| 3243 | .WillRepeatedly(Return(10 * kDefaultTCPMSS)); |
| 3244 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 3245 | rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(100), |
| 3246 | QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 3247 | QuicTime::Delta srtt = rtt_stats->smoothed_rtt(); |
| 3248 | SendDataPacket(1, ENCRYPTION_FORWARD_SECURE); |
| 3249 | // Verify PTO is correctly set. |
| 3250 | QuicTime::Delta expected_pto_delay = 2 * srtt; |
| 3251 | EXPECT_EQ(clock_.Now() + expected_pto_delay, |
| 3252 | manager_.GetRetransmissionTime()); |
| 3253 | |
| 3254 | // Invoke PTO. |
| 3255 | clock_.AdvanceTime(expected_pto_delay); |
| 3256 | manager_.OnRetransmissionTimeout(); |
| 3257 | EXPECT_EQ(QuicTime::Delta::Zero(), manager_.TimeUntilSend(clock_.Now())); |
| 3258 | EXPECT_EQ(1u, stats_.pto_count); |
| 3259 | |
| 3260 | // Verify 1 probe packets get sent and packet number gets skipped. |
| 3261 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 3262 | .WillOnce(WithArgs<1>(Invoke([this](TransmissionType type) { |
| 3263 | RetransmitDataPacket(3, type, ENCRYPTION_FORWARD_SECURE); |
| 3264 | }))); |
| 3265 | manager_.MaybeSendProbePackets(); |
| 3266 | |
| 3267 | // Verify PTO period gets set correctly. |
| 3268 | EXPECT_EQ(clock_.Now() + expected_pto_delay, |
| 3269 | manager_.GetRetransmissionTime()); |
| 3270 | |
| 3271 | // Invoke 2nd PTO. |
| 3272 | clock_.AdvanceTime(expected_pto_delay); |
| 3273 | manager_.OnRetransmissionTimeout(); |
| 3274 | EXPECT_EQ(QuicTime::Delta::Zero(), manager_.TimeUntilSend(clock_.Now())); |
| 3275 | EXPECT_EQ(2u, stats_.pto_count); |
| 3276 | |
| 3277 | // Verify 1 probe packets get sent and packet number gets skipped. |
| 3278 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 3279 | .WillOnce(WithArgs<1>(Invoke([this](TransmissionType type) { |
| 3280 | RetransmitDataPacket(5, type, ENCRYPTION_FORWARD_SECURE); |
| 3281 | }))); |
| 3282 | manager_.MaybeSendProbePackets(); |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3283 | int pto_rttvar_multiplier = |
| 3284 | GetQuicReloadableFlag(quic_default_on_pto) ? 2 : 4; |
fayang | 4aa2240 | 2020-01-07 11:36:07 -0800 | [diff] [blame] | 3285 | expected_pto_delay = |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3286 | srtt + pto_rttvar_multiplier * rtt_stats->mean_deviation() + |
fayang | 4aa2240 | 2020-01-07 11:36:07 -0800 | [diff] [blame] | 3287 | QuicTime::Delta::FromMilliseconds(kDefaultDelayedAckTimeMs); |
| 3288 | |
| 3289 | // Verify PTO period gets set correctly. |
| 3290 | EXPECT_EQ(clock_.Now() + expected_pto_delay * 4, |
| 3291 | manager_.GetRetransmissionTime()); |
| 3292 | } |
| 3293 | |
fayang | 402103c | 2020-01-10 13:36:24 -0800 | [diff] [blame] | 3294 | TEST_F(QuicSentPacketManagerTest, IW10ForUpAndDown) { |
| 3295 | SetQuicReloadableFlag(quic_bbr_mitigate_overly_large_bandwidth_sample, true); |
| 3296 | QuicConfig config; |
| 3297 | QuicTagVector options; |
| 3298 | options.push_back(kBWS5); |
| 3299 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 3300 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3301 | EXPECT_CALL(*send_algorithm_, SetInitialCongestionWindowInPackets(10)); |
| 3302 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 3303 | manager_.SetFromConfig(config); |
| 3304 | |
| 3305 | EXPECT_EQ(10u, manager_.initial_congestion_window()); |
| 3306 | } |
| 3307 | |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 3308 | TEST_F(QuicSentPacketManagerTest, ClientMultiplePacketNumberSpacePtoTimeout) { |
| 3309 | manager_.EnableMultiplePacketNumberSpacesSupport(); |
| 3310 | EnablePto(k1PTO); |
| 3311 | EXPECT_CALL(*send_algorithm_, PacingRate(_)) |
| 3312 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
| 3313 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
| 3314 | .WillRepeatedly(Return(10 * kDefaultTCPMSS)); |
| 3315 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 3316 | rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(100), |
| 3317 | QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 3318 | QuicTime::Delta srtt = rtt_stats->smoothed_rtt(); |
fayang | 9a0e1bd | 2020-02-19 13:13:04 -0800 | [diff] [blame] | 3319 | QuicSentPacketManagerPeer::SetPerspective(&manager_, Perspective::IS_CLIENT); |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 3320 | |
| 3321 | // Send packet 1. |
| 3322 | SendDataPacket(1, ENCRYPTION_INITIAL); |
| 3323 | // Verify PTO is correctly set. |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3324 | int pto_rttvar_multiplier = |
| 3325 | GetQuicReloadableFlag(quic_default_on_pto) ? 2 : 4; |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 3326 | QuicTime::Delta expected_pto_delay = |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3327 | srtt + pto_rttvar_multiplier * rtt_stats->mean_deviation() + |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 3328 | QuicTime::Delta::FromMilliseconds(kDefaultDelayedAckTimeMs); |
| 3329 | EXPECT_EQ(clock_.Now() + expected_pto_delay, |
| 3330 | manager_.GetRetransmissionTime()); |
| 3331 | |
| 3332 | // Discard initial key and send packet 2 in handshake. |
| 3333 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
| 3334 | EXPECT_CALL(notifier_, IsFrameOutstanding(_)).WillRepeatedly(Return(false)); |
| 3335 | manager_.NeuterUnencryptedPackets(); |
| 3336 | |
| 3337 | EXPECT_CALL(notifier_, IsFrameOutstanding(_)).WillRepeatedly(Return(true)); |
| 3338 | SendDataPacket(2, ENCRYPTION_HANDSHAKE); |
| 3339 | // Verify PTO is correctly set based on sent time of packet 2. |
| 3340 | EXPECT_EQ(clock_.Now() + expected_pto_delay, |
| 3341 | manager_.GetRetransmissionTime()); |
| 3342 | // Invoke PTO. |
| 3343 | clock_.AdvanceTime(expected_pto_delay); |
| 3344 | manager_.OnRetransmissionTimeout(); |
| 3345 | EXPECT_EQ(QuicTime::Delta::Zero(), manager_.TimeUntilSend(clock_.Now())); |
| 3346 | EXPECT_EQ(1u, stats_.pto_count); |
fayang | af9903b | 2020-05-14 14:34:28 -0700 | [diff] [blame] | 3347 | EXPECT_EQ(1u, stats_.crypto_retransmit_count); |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 3348 | |
| 3349 | // Verify probe packet gets sent. |
| 3350 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 3351 | .WillOnce(WithArgs<1>(Invoke([this](TransmissionType type) { |
| 3352 | RetransmitDataPacket(3, type, ENCRYPTION_HANDSHAKE); |
| 3353 | }))); |
| 3354 | manager_.MaybeSendProbePackets(); |
| 3355 | // Verify PTO period gets set to twice the current value. |
| 3356 | const QuicTime packet3_sent_time = clock_.Now(); |
| 3357 | EXPECT_EQ(packet3_sent_time + expected_pto_delay * 2, |
| 3358 | manager_.GetRetransmissionTime()); |
| 3359 | |
fayang | 9a0e1bd | 2020-02-19 13:13:04 -0800 | [diff] [blame] | 3360 | // Send packet 4 in application data with 0-RTT. |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 3361 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
fayang | 9a0e1bd | 2020-02-19 13:13:04 -0800 | [diff] [blame] | 3362 | SendDataPacket(4, ENCRYPTION_ZERO_RTT); |
fayang | 4283494 | 2020-03-30 10:56:15 -0700 | [diff] [blame] | 3363 | const QuicTime packet4_sent_time = clock_.Now(); |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 3364 | // Verify PTO timeout is still based on packet 3. |
| 3365 | EXPECT_EQ(packet3_sent_time + expected_pto_delay * 2, |
| 3366 | manager_.GetRetransmissionTime()); |
| 3367 | |
| 3368 | // Send packet 5 in handshake. |
| 3369 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
| 3370 | SendDataPacket(5, ENCRYPTION_HANDSHAKE); |
fayang | 9a0e1bd | 2020-02-19 13:13:04 -0800 | [diff] [blame] | 3371 | const QuicTime packet5_sent_time = clock_.Now(); |
| 3372 | // Verify PTO timeout is now based on packet 5 because packet 4 should be |
| 3373 | // ignored. |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 3374 | EXPECT_EQ(clock_.Now() + expected_pto_delay * 2, |
| 3375 | manager_.GetRetransmissionTime()); |
| 3376 | |
fayang | 9a0e1bd | 2020-02-19 13:13:04 -0800 | [diff] [blame] | 3377 | // Send packet 6 in 1-RTT. |
| 3378 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
| 3379 | SendDataPacket(6, ENCRYPTION_FORWARD_SECURE); |
| 3380 | const QuicTime packet6_sent_time = clock_.Now(); |
| 3381 | // Verify PTO timeout is now based on packet 5. |
| 3382 | EXPECT_EQ(packet5_sent_time + expected_pto_delay * 2, |
| 3383 | manager_.GetRetransmissionTime()); |
| 3384 | |
| 3385 | // Send packet 7 in handshake. |
| 3386 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
| 3387 | SendDataPacket(7, ENCRYPTION_HANDSHAKE); |
| 3388 | // Verify PTO timeout is now based on packet 6. |
| 3389 | EXPECT_EQ(packet6_sent_time + expected_pto_delay * 2, |
| 3390 | manager_.GetRetransmissionTime()); |
| 3391 | |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 3392 | // Neuter handshake key. |
| 3393 | manager_.SetHandshakeConfirmed(); |
fayang | 4283494 | 2020-03-30 10:56:15 -0700 | [diff] [blame] | 3394 | // Forward progress has been made, verify PTO counter gets reset. PTO timeout |
| 3395 | // is armed by left edge. |
| 3396 | EXPECT_EQ(packet4_sent_time + expected_pto_delay, |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 3397 | manager_.GetRetransmissionTime()); |
| 3398 | } |
| 3399 | |
| 3400 | TEST_F(QuicSentPacketManagerTest, ServerMultiplePacketNumberSpacePtoTimeout) { |
| 3401 | manager_.EnableMultiplePacketNumberSpacesSupport(); |
| 3402 | EnablePto(k1PTO); |
| 3403 | EXPECT_CALL(*send_algorithm_, PacingRate(_)) |
| 3404 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
| 3405 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
| 3406 | .WillRepeatedly(Return(10 * kDefaultTCPMSS)); |
| 3407 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 3408 | rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(100), |
| 3409 | QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 3410 | QuicTime::Delta srtt = rtt_stats->smoothed_rtt(); |
| 3411 | |
| 3412 | // Send packet 1. |
| 3413 | SendDataPacket(1, ENCRYPTION_INITIAL); |
| 3414 | const QuicTime packet1_sent_time = clock_.Now(); |
| 3415 | // Verify PTO is correctly set. |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3416 | int pto_rttvar_multiplier = |
| 3417 | GetQuicReloadableFlag(quic_default_on_pto) ? 2 : 4; |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 3418 | QuicTime::Delta expected_pto_delay = |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3419 | srtt + pto_rttvar_multiplier * rtt_stats->mean_deviation() + |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 3420 | QuicTime::Delta::FromMilliseconds(kDefaultDelayedAckTimeMs); |
| 3421 | EXPECT_EQ(packet1_sent_time + expected_pto_delay, |
| 3422 | manager_.GetRetransmissionTime()); |
| 3423 | |
| 3424 | // Send packet 2 in handshake. |
| 3425 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
| 3426 | SendDataPacket(2, ENCRYPTION_HANDSHAKE); |
fayang | 9a0e1bd | 2020-02-19 13:13:04 -0800 | [diff] [blame] | 3427 | const QuicTime packet2_sent_time = clock_.Now(); |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 3428 | // Verify PTO timeout is still based on packet 1. |
| 3429 | EXPECT_EQ(packet1_sent_time + expected_pto_delay, |
| 3430 | manager_.GetRetransmissionTime()); |
| 3431 | |
fayang | 9a0e1bd | 2020-02-19 13:13:04 -0800 | [diff] [blame] | 3432 | // Discard initial keys. |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 3433 | EXPECT_CALL(notifier_, IsFrameOutstanding(_)).WillRepeatedly(Return(false)); |
| 3434 | manager_.NeuterUnencryptedPackets(); |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 3435 | |
fayang | 9a0e1bd | 2020-02-19 13:13:04 -0800 | [diff] [blame] | 3436 | // Send packet 3 in 1-RTT. |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 3437 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
| 3438 | SendDataPacket(3, ENCRYPTION_FORWARD_SECURE); |
fayang | 9a0e1bd | 2020-02-19 13:13:04 -0800 | [diff] [blame] | 3439 | // Verify PTO timeout is based on packet 2. |
| 3440 | const QuicTime packet3_sent_time = clock_.Now(); |
| 3441 | EXPECT_EQ(packet2_sent_time + expected_pto_delay, |
| 3442 | manager_.GetRetransmissionTime()); |
| 3443 | |
| 3444 | // Send packet 4 in handshake. |
| 3445 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
| 3446 | SendDataPacket(4, ENCRYPTION_HANDSHAKE); |
| 3447 | // Verify PTO timeout is based on packet 4 as application data is ignored. |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 3448 | EXPECT_EQ(clock_.Now() + expected_pto_delay, |
| 3449 | manager_.GetRetransmissionTime()); |
fayang | 9a0e1bd | 2020-02-19 13:13:04 -0800 | [diff] [blame] | 3450 | |
| 3451 | // Discard handshake keys. |
| 3452 | manager_.SetHandshakeConfirmed(); |
| 3453 | // Verify PTO timeout is now based on packet 3 as handshake is |
| 3454 | // complete/confirmed. |
| 3455 | EXPECT_EQ(packet3_sent_time + expected_pto_delay, |
| 3456 | manager_.GetRetransmissionTime()); |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 3457 | } |
| 3458 | |
fayang | 2ccfbcf | 2020-02-28 12:37:08 -0800 | [diff] [blame] | 3459 | TEST_F(QuicSentPacketManagerTest, ComputingProbeTimeoutByLeftEdge) { |
fayang | 2ccfbcf | 2020-02-28 12:37:08 -0800 | [diff] [blame] | 3460 | EnablePto(k1PTO); |
| 3461 | // Use PTOS and PLE1. |
| 3462 | QuicConfig config; |
| 3463 | QuicTagVector options; |
| 3464 | options.push_back(kPTOS); |
| 3465 | options.push_back(kPLE1); |
| 3466 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 3467 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3468 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 3469 | manager_.SetFromConfig(config); |
| 3470 | EXPECT_TRUE(manager_.skip_packet_number_for_pto()); |
| 3471 | EXPECT_CALL(*send_algorithm_, CanSend(_)).WillRepeatedly(Return(true)); |
| 3472 | EXPECT_CALL(*send_algorithm_, PacingRate(_)) |
| 3473 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
| 3474 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
| 3475 | .WillRepeatedly(Return(10 * kDefaultTCPMSS)); |
| 3476 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 3477 | rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(100), |
| 3478 | QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 3479 | QuicTime::Delta srtt = rtt_stats->smoothed_rtt(); |
| 3480 | |
| 3481 | SendDataPacket(1, ENCRYPTION_FORWARD_SECURE); |
| 3482 | // Verify PTO is correctly set. |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3483 | int pto_rttvar_multiplier = |
| 3484 | GetQuicReloadableFlag(quic_default_on_pto) ? 2 : 4; |
fayang | 2ccfbcf | 2020-02-28 12:37:08 -0800 | [diff] [blame] | 3485 | QuicTime::Delta expected_pto_delay = |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3486 | srtt + pto_rttvar_multiplier * rtt_stats->mean_deviation() + |
fayang | 2ccfbcf | 2020-02-28 12:37:08 -0800 | [diff] [blame] | 3487 | QuicTime::Delta::FromMilliseconds(kDefaultDelayedAckTimeMs); |
| 3488 | const QuicTime packet1_sent_time = clock_.Now(); |
| 3489 | EXPECT_EQ(packet1_sent_time + expected_pto_delay, |
| 3490 | manager_.GetRetransmissionTime()); |
| 3491 | |
| 3492 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
| 3493 | SendDataPacket(2, ENCRYPTION_FORWARD_SECURE); |
| 3494 | // Verify PTO is still based on packet 1. |
| 3495 | EXPECT_EQ(packet1_sent_time + expected_pto_delay, |
| 3496 | manager_.GetRetransmissionTime()); |
| 3497 | EXPECT_EQ(0u, stats_.pto_count); |
| 3498 | |
| 3499 | // Invoke PTO. |
| 3500 | clock_.AdvanceTime(expected_pto_delay); |
| 3501 | manager_.OnRetransmissionTimeout(); |
| 3502 | EXPECT_EQ(QuicTime::Delta::Zero(), manager_.TimeUntilSend(clock_.Now())); |
| 3503 | EXPECT_EQ(1u, stats_.pto_count); |
| 3504 | |
| 3505 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 3506 | .WillOnce(WithArgs<1>(Invoke([this](TransmissionType type) { |
| 3507 | RetransmitDataPacket(3, type, ENCRYPTION_FORWARD_SECURE); |
| 3508 | }))); |
| 3509 | manager_.MaybeSendProbePackets(); |
| 3510 | // Verify PTO period gets set to twice the current value and based on packet3. |
| 3511 | QuicTime packet3_sent_time = clock_.Now(); |
| 3512 | EXPECT_EQ(packet3_sent_time + expected_pto_delay * 2, |
| 3513 | manager_.GetRetransmissionTime()); |
| 3514 | |
| 3515 | // Received ACK for packets 1 and 2. |
| 3516 | uint64_t acked[] = {1, 2}; |
| 3517 | ExpectAcksAndLosses(true, acked, QUICHE_ARRAYSIZE(acked), nullptr, 0); |
| 3518 | manager_.OnAckFrameStart(QuicPacketNumber(2), QuicTime::Delta::Infinite(), |
| 3519 | clock_.Now()); |
| 3520 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(3)); |
| 3521 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
| 3522 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 3523 | ENCRYPTION_FORWARD_SECURE)); |
| 3524 | expected_pto_delay = |
| 3525 | rtt_stats->SmoothedOrInitialRtt() + |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3526 | std::max(pto_rttvar_multiplier * rtt_stats->mean_deviation(), |
fayang | 2ccfbcf | 2020-02-28 12:37:08 -0800 | [diff] [blame] | 3527 | QuicTime::Delta::FromMilliseconds(1)) + |
| 3528 | QuicTime::Delta::FromMilliseconds(kDefaultDelayedAckTimeMs); |
| 3529 | |
| 3530 | // Verify PTO is correctly re-armed based on sent time of packet 4. |
| 3531 | EXPECT_EQ(packet3_sent_time + expected_pto_delay, |
| 3532 | manager_.GetRetransmissionTime()); |
| 3533 | } |
| 3534 | |
fayang | c5d9b2c | 2020-03-02 11:12:26 -0800 | [diff] [blame] | 3535 | TEST_F(QuicSentPacketManagerTest, ComputingProbeTimeoutByLeftEdge2) { |
fayang | c5d9b2c | 2020-03-02 11:12:26 -0800 | [diff] [blame] | 3536 | EnablePto(k1PTO); |
| 3537 | // Use PTOS and PLE2. |
| 3538 | QuicConfig config; |
| 3539 | QuicTagVector options; |
| 3540 | options.push_back(kPTOS); |
| 3541 | options.push_back(kPLE2); |
| 3542 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 3543 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3544 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 3545 | manager_.SetFromConfig(config); |
| 3546 | EXPECT_TRUE(manager_.skip_packet_number_for_pto()); |
| 3547 | EXPECT_CALL(*send_algorithm_, CanSend(_)).WillRepeatedly(Return(true)); |
| 3548 | EXPECT_CALL(*send_algorithm_, PacingRate(_)) |
| 3549 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
| 3550 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
| 3551 | .WillRepeatedly(Return(10 * kDefaultTCPMSS)); |
| 3552 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 3553 | rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(100), |
| 3554 | QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 3555 | QuicTime::Delta srtt = rtt_stats->smoothed_rtt(); |
| 3556 | |
| 3557 | SendDataPacket(1, ENCRYPTION_FORWARD_SECURE); |
| 3558 | // Verify PTO is correctly set. |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3559 | int pto_rttvar_multiplier = |
| 3560 | GetQuicReloadableFlag(quic_default_on_pto) ? 2 : 4; |
fayang | c5d9b2c | 2020-03-02 11:12:26 -0800 | [diff] [blame] | 3561 | QuicTime::Delta expected_pto_delay = |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3562 | srtt + pto_rttvar_multiplier * rtt_stats->mean_deviation() + |
fayang | c5d9b2c | 2020-03-02 11:12:26 -0800 | [diff] [blame] | 3563 | QuicTime::Delta::FromMilliseconds(kDefaultDelayedAckTimeMs); |
| 3564 | const QuicTime packet1_sent_time = clock_.Now(); |
| 3565 | EXPECT_EQ(packet1_sent_time + expected_pto_delay, |
| 3566 | manager_.GetRetransmissionTime()); |
| 3567 | |
| 3568 | // Sent a packet 10ms before PTO expiring. |
| 3569 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds( |
| 3570 | expected_pto_delay.ToMilliseconds() - 10)); |
| 3571 | SendDataPacket(2, ENCRYPTION_FORWARD_SECURE); |
| 3572 | // Verify PTO expands to packet 2 sent time + 1.5 * srtt. |
| 3573 | expected_pto_delay = 1.5 * rtt_stats->smoothed_rtt(); |
| 3574 | EXPECT_EQ(clock_.Now() + expected_pto_delay, |
| 3575 | manager_.GetRetransmissionTime()); |
| 3576 | EXPECT_EQ(0u, stats_.pto_count); |
| 3577 | |
| 3578 | // Invoke PTO. |
| 3579 | clock_.AdvanceTime(expected_pto_delay); |
| 3580 | manager_.OnRetransmissionTimeout(); |
| 3581 | EXPECT_EQ(QuicTime::Delta::Zero(), manager_.TimeUntilSend(clock_.Now())); |
| 3582 | EXPECT_EQ(1u, stats_.pto_count); |
| 3583 | |
| 3584 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 3585 | .WillOnce(WithArgs<1>(Invoke([this](TransmissionType type) { |
| 3586 | RetransmitDataPacket(3, type, ENCRYPTION_FORWARD_SECURE); |
| 3587 | }))); |
| 3588 | manager_.MaybeSendProbePackets(); |
| 3589 | // Verify PTO period gets set to twice the expected value and based on |
| 3590 | // packet3 (right edge). |
| 3591 | expected_pto_delay = |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3592 | srtt + pto_rttvar_multiplier * rtt_stats->mean_deviation() + |
fayang | c5d9b2c | 2020-03-02 11:12:26 -0800 | [diff] [blame] | 3593 | QuicTime::Delta::FromMilliseconds(kDefaultDelayedAckTimeMs); |
| 3594 | QuicTime packet3_sent_time = clock_.Now(); |
| 3595 | EXPECT_EQ(packet3_sent_time + expected_pto_delay * 2, |
| 3596 | manager_.GetRetransmissionTime()); |
| 3597 | |
| 3598 | // Received ACK for packets 1 and 2. |
| 3599 | uint64_t acked[] = {1, 2}; |
| 3600 | ExpectAcksAndLosses(true, acked, QUICHE_ARRAYSIZE(acked), nullptr, 0); |
| 3601 | manager_.OnAckFrameStart(QuicPacketNumber(2), QuicTime::Delta::Infinite(), |
| 3602 | clock_.Now()); |
| 3603 | manager_.OnAckRange(QuicPacketNumber(1), QuicPacketNumber(3)); |
| 3604 | EXPECT_EQ(PACKETS_NEWLY_ACKED, |
| 3605 | manager_.OnAckFrameEnd(clock_.Now(), QuicPacketNumber(1), |
| 3606 | ENCRYPTION_FORWARD_SECURE)); |
| 3607 | expected_pto_delay = |
| 3608 | rtt_stats->SmoothedOrInitialRtt() + |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3609 | std::max(pto_rttvar_multiplier * rtt_stats->mean_deviation(), |
fayang | c5d9b2c | 2020-03-02 11:12:26 -0800 | [diff] [blame] | 3610 | QuicTime::Delta::FromMilliseconds(1)) + |
| 3611 | QuicTime::Delta::FromMilliseconds(kDefaultDelayedAckTimeMs); |
| 3612 | |
| 3613 | // Verify PTO is correctly re-armed based on sent time of packet 3 (left |
| 3614 | // edge). |
| 3615 | EXPECT_EQ(packet3_sent_time + expected_pto_delay, |
| 3616 | manager_.GetRetransmissionTime()); |
| 3617 | } |
| 3618 | |
fayang | c2fd610 | 2020-03-02 17:27:38 -0800 | [diff] [blame] | 3619 | TEST_F(QuicSentPacketManagerTest, ComputingProbeTimeoutUsingStandardDeviation) { |
fayang | c2fd610 | 2020-03-02 17:27:38 -0800 | [diff] [blame] | 3620 | EnablePto(k1PTO); |
| 3621 | // Use PTOS and PSDA. |
| 3622 | QuicConfig config; |
| 3623 | QuicTagVector options; |
| 3624 | options.push_back(kPTOS); |
| 3625 | options.push_back(kPSDA); |
| 3626 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 3627 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3628 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 3629 | manager_.SetFromConfig(config); |
| 3630 | EXPECT_TRUE(manager_.skip_packet_number_for_pto()); |
| 3631 | EXPECT_CALL(*send_algorithm_, CanSend(_)).WillRepeatedly(Return(true)); |
| 3632 | EXPECT_CALL(*send_algorithm_, PacingRate(_)) |
| 3633 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
| 3634 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
| 3635 | .WillRepeatedly(Return(10 * kDefaultTCPMSS)); |
| 3636 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 3637 | rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(100), |
| 3638 | QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 3639 | rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(50), |
| 3640 | QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 3641 | rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(50), |
| 3642 | QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 3643 | rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(75), |
| 3644 | QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 3645 | QuicTime::Delta srtt = rtt_stats->smoothed_rtt(); |
| 3646 | |
| 3647 | SendDataPacket(1, ENCRYPTION_FORWARD_SECURE); |
| 3648 | // Verify PTO is correctly set using standard deviation. |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3649 | int pto_rttvar_multiplier = |
| 3650 | GetQuicReloadableFlag(quic_default_on_pto) ? 2 : 4; |
fayang | c2fd610 | 2020-03-02 17:27:38 -0800 | [diff] [blame] | 3651 | QuicTime::Delta expected_pto_delay = |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3652 | srtt + pto_rttvar_multiplier * rtt_stats->GetStandardOrMeanDeviation() + |
fayang | c2fd610 | 2020-03-02 17:27:38 -0800 | [diff] [blame] | 3653 | QuicTime::Delta::FromMilliseconds(kDefaultDelayedAckTimeMs); |
| 3654 | EXPECT_EQ(clock_.Now() + expected_pto_delay, |
| 3655 | manager_.GetRetransmissionTime()); |
| 3656 | } |
| 3657 | |
fayang | 2ccfbcf | 2020-02-28 12:37:08 -0800 | [diff] [blame] | 3658 | TEST_F(QuicSentPacketManagerTest, |
| 3659 | ComputingProbeTimeoutByLeftEdgeMultiplePacketNumberSpaces) { |
fayang | 2ccfbcf | 2020-02-28 12:37:08 -0800 | [diff] [blame] | 3660 | manager_.EnableMultiplePacketNumberSpacesSupport(); |
| 3661 | EnablePto(k1PTO); |
| 3662 | // Use PTOS and PLE1. |
| 3663 | QuicConfig config; |
| 3664 | QuicTagVector options; |
| 3665 | options.push_back(kPTOS); |
| 3666 | options.push_back(kPLE1); |
| 3667 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 3668 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3669 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 3670 | manager_.SetFromConfig(config); |
| 3671 | EXPECT_TRUE(manager_.skip_packet_number_for_pto()); |
| 3672 | EXPECT_CALL(*send_algorithm_, CanSend(_)).WillRepeatedly(Return(true)); |
| 3673 | EXPECT_CALL(*send_algorithm_, PacingRate(_)) |
| 3674 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
| 3675 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
| 3676 | .WillRepeatedly(Return(10 * kDefaultTCPMSS)); |
| 3677 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 3678 | rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(100), |
| 3679 | QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 3680 | QuicTime::Delta srtt = rtt_stats->smoothed_rtt(); |
| 3681 | |
| 3682 | // Send packet 1. |
| 3683 | SendDataPacket(1, ENCRYPTION_INITIAL); |
| 3684 | const QuicTime packet1_sent_time = clock_.Now(); |
| 3685 | // Verify PTO is correctly set. |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3686 | int pto_rttvar_multiplier = |
| 3687 | GetQuicReloadableFlag(quic_default_on_pto) ? 2 : 4; |
fayang | 2ccfbcf | 2020-02-28 12:37:08 -0800 | [diff] [blame] | 3688 | QuicTime::Delta expected_pto_delay = |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3689 | srtt + pto_rttvar_multiplier * rtt_stats->mean_deviation() + |
fayang | 2ccfbcf | 2020-02-28 12:37:08 -0800 | [diff] [blame] | 3690 | QuicTime::Delta::FromMilliseconds(kDefaultDelayedAckTimeMs); |
| 3691 | EXPECT_EQ(packet1_sent_time + expected_pto_delay, |
| 3692 | manager_.GetRetransmissionTime()); |
| 3693 | |
| 3694 | // Send packet 2 in handshake. |
| 3695 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
| 3696 | SendDataPacket(2, ENCRYPTION_HANDSHAKE); |
| 3697 | const QuicTime packet2_sent_time = clock_.Now(); |
| 3698 | // Verify PTO timeout is still based on packet 1. |
| 3699 | EXPECT_EQ(packet1_sent_time + expected_pto_delay, |
| 3700 | manager_.GetRetransmissionTime()); |
| 3701 | |
| 3702 | // Discard initial keys. |
| 3703 | EXPECT_CALL(notifier_, IsFrameOutstanding(_)).WillRepeatedly(Return(false)); |
| 3704 | manager_.NeuterUnencryptedPackets(); |
| 3705 | |
| 3706 | // Send packet 3 in 1-RTT. |
| 3707 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
| 3708 | SendDataPacket(3, ENCRYPTION_FORWARD_SECURE); |
| 3709 | // Verify PTO timeout is based on packet 2. |
| 3710 | const QuicTime packet3_sent_time = clock_.Now(); |
| 3711 | EXPECT_EQ(packet2_sent_time + expected_pto_delay, |
| 3712 | manager_.GetRetransmissionTime()); |
| 3713 | |
| 3714 | // Send packet 4 in handshake. |
| 3715 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
| 3716 | SendDataPacket(4, ENCRYPTION_HANDSHAKE); |
| 3717 | // Verify PTO timeout is based on packet 4 as application data is ignored. |
| 3718 | EXPECT_EQ(clock_.Now() + expected_pto_delay, |
| 3719 | manager_.GetRetransmissionTime()); |
| 3720 | |
| 3721 | // Discard handshake keys. |
| 3722 | manager_.SetHandshakeConfirmed(); |
| 3723 | // Verify PTO timeout is now based on packet 3 as handshake is |
| 3724 | // complete/confirmed. |
| 3725 | EXPECT_EQ(packet3_sent_time + expected_pto_delay, |
| 3726 | manager_.GetRetransmissionTime()); |
| 3727 | |
| 3728 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
| 3729 | SendDataPacket(5, ENCRYPTION_FORWARD_SECURE); |
| 3730 | // Verify PTO timeout is still based on packet 3. |
| 3731 | EXPECT_EQ(packet3_sent_time + expected_pto_delay, |
| 3732 | manager_.GetRetransmissionTime()); |
| 3733 | } |
| 3734 | |
fayang | c5d9b2c | 2020-03-02 11:12:26 -0800 | [diff] [blame] | 3735 | TEST_F(QuicSentPacketManagerTest, |
| 3736 | ComputingProbeTimeoutByLeftEdge2MultiplePacketNumberSpaces) { |
fayang | c5d9b2c | 2020-03-02 11:12:26 -0800 | [diff] [blame] | 3737 | manager_.EnableMultiplePacketNumberSpacesSupport(); |
| 3738 | EnablePto(k1PTO); |
| 3739 | // Use PTOS and PLE2. |
| 3740 | QuicConfig config; |
| 3741 | QuicTagVector options; |
| 3742 | options.push_back(kPTOS); |
| 3743 | options.push_back(kPLE2); |
| 3744 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 3745 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3746 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 3747 | manager_.SetFromConfig(config); |
| 3748 | EXPECT_TRUE(manager_.skip_packet_number_for_pto()); |
| 3749 | EXPECT_CALL(*send_algorithm_, CanSend(_)).WillRepeatedly(Return(true)); |
| 3750 | EXPECT_CALL(*send_algorithm_, PacingRate(_)) |
| 3751 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
| 3752 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
| 3753 | .WillRepeatedly(Return(10 * kDefaultTCPMSS)); |
| 3754 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 3755 | rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(100), |
| 3756 | QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 3757 | QuicTime::Delta srtt = rtt_stats->smoothed_rtt(); |
| 3758 | |
| 3759 | // Send packet 1. |
| 3760 | SendDataPacket(1, ENCRYPTION_INITIAL); |
| 3761 | const QuicTime packet1_sent_time = clock_.Now(); |
| 3762 | // Verify PTO is correctly set. |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3763 | int pto_rttvar_multiplier = |
| 3764 | GetQuicReloadableFlag(quic_default_on_pto) ? 2 : 4; |
fayang | c5d9b2c | 2020-03-02 11:12:26 -0800 | [diff] [blame] | 3765 | QuicTime::Delta expected_pto_delay = |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3766 | srtt + pto_rttvar_multiplier * rtt_stats->mean_deviation() + |
fayang | c5d9b2c | 2020-03-02 11:12:26 -0800 | [diff] [blame] | 3767 | QuicTime::Delta::FromMilliseconds(kDefaultDelayedAckTimeMs); |
| 3768 | EXPECT_EQ(packet1_sent_time + expected_pto_delay, |
| 3769 | manager_.GetRetransmissionTime()); |
| 3770 | |
| 3771 | // Send packet 2 in handshake. |
| 3772 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
| 3773 | SendDataPacket(2, ENCRYPTION_HANDSHAKE); |
| 3774 | const QuicTime packet2_sent_time = clock_.Now(); |
| 3775 | // Verify PTO timeout is still based on packet 1. |
| 3776 | EXPECT_EQ(packet1_sent_time + expected_pto_delay, |
| 3777 | manager_.GetRetransmissionTime()); |
| 3778 | |
| 3779 | // Discard initial keys. |
| 3780 | EXPECT_CALL(notifier_, IsFrameOutstanding(_)).WillRepeatedly(Return(false)); |
| 3781 | manager_.NeuterUnencryptedPackets(); |
| 3782 | |
| 3783 | // Send packet 3 in 1-RTT. |
| 3784 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
| 3785 | SendDataPacket(3, ENCRYPTION_FORWARD_SECURE); |
| 3786 | // Verify PTO timeout is based on packet 2. |
| 3787 | const QuicTime packet3_sent_time = clock_.Now(); |
| 3788 | EXPECT_EQ(packet2_sent_time + expected_pto_delay, |
| 3789 | manager_.GetRetransmissionTime()); |
| 3790 | |
| 3791 | // Send packet 4 in handshake. |
| 3792 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
| 3793 | SendDataPacket(4, ENCRYPTION_HANDSHAKE); |
| 3794 | // Verify PTO timeout is based on packet 4 as application data is ignored. |
| 3795 | EXPECT_EQ(clock_.Now() + expected_pto_delay, |
| 3796 | manager_.GetRetransmissionTime()); |
| 3797 | |
| 3798 | // Discard handshake keys. |
| 3799 | manager_.SetHandshakeConfirmed(); |
| 3800 | // Verify PTO timeout is now based on packet 3 as handshake is |
| 3801 | // complete/confirmed. |
| 3802 | EXPECT_EQ(packet3_sent_time + expected_pto_delay, |
| 3803 | manager_.GetRetransmissionTime()); |
| 3804 | |
| 3805 | // Send packet 5 10ms before PTO expiring. |
| 3806 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds( |
| 3807 | expected_pto_delay.ToMilliseconds() - 10)); |
| 3808 | SendDataPacket(5, ENCRYPTION_FORWARD_SECURE); |
| 3809 | // Verify PTO timeout expands to packet 5 sent time + 1.5 * srtt. |
| 3810 | EXPECT_EQ(clock_.Now() + 1.5 * rtt_stats->smoothed_rtt(), |
| 3811 | manager_.GetRetransmissionTime()); |
| 3812 | } |
| 3813 | |
wub | f4ab965 | 2020-02-20 14:45:43 -0800 | [diff] [blame] | 3814 | TEST_F(QuicSentPacketManagerTest, SetHandshakeConfirmed) { |
| 3815 | QuicSentPacketManagerPeer::SetPerspective(&manager_, Perspective::IS_CLIENT); |
| 3816 | manager_.EnableMultiplePacketNumberSpacesSupport(); |
| 3817 | |
| 3818 | SendDataPacket(1, ENCRYPTION_INITIAL); |
| 3819 | |
| 3820 | SendDataPacket(2, ENCRYPTION_HANDSHAKE); |
| 3821 | |
| 3822 | EXPECT_CALL(notifier_, OnFrameAcked(_, _, _)) |
| 3823 | .WillOnce( |
| 3824 | Invoke([](const QuicFrame& /*frame*/, QuicTime::Delta ack_delay_time, |
| 3825 | QuicTime receive_timestamp) { |
| 3826 | EXPECT_TRUE(ack_delay_time.IsZero()); |
| 3827 | EXPECT_EQ(receive_timestamp, QuicTime::Zero()); |
| 3828 | return true; |
| 3829 | })); |
| 3830 | |
| 3831 | if (GetQuicReloadableFlag( |
| 3832 | quic_avoid_overestimate_bandwidth_with_aggregation)) { |
| 3833 | EXPECT_CALL(*send_algorithm_, OnPacketNeutered(QuicPacketNumber(2))) |
| 3834 | .Times(1); |
| 3835 | } |
| 3836 | manager_.SetHandshakeConfirmed(); |
| 3837 | } |
| 3838 | |
fayang | d5c2ffb | 2020-02-04 11:49:05 -0800 | [diff] [blame] | 3839 | // Regresstion test for b/148841700. |
| 3840 | TEST_F(QuicSentPacketManagerTest, NeuterUnencryptedPackets) { |
| 3841 | SendCryptoPacket(1); |
| 3842 | SendPingPacket(2, ENCRYPTION_INITIAL); |
| 3843 | // Crypto data has been discarded but ping does not. |
fayang | 1f8619f | 2020-03-16 08:39:58 -0700 | [diff] [blame] | 3844 | EXPECT_CALL(notifier_, OnFrameAcked(_, _, _)) |
| 3845 | .Times(2) |
| 3846 | .WillOnce(Return(false)) |
| 3847 | .WillOnce(Return(true)); |
fayang | d5c2ffb | 2020-02-04 11:49:05 -0800 | [diff] [blame] | 3848 | EXPECT_CALL(notifier_, IsFrameOutstanding(_)).WillRepeatedly(Return(false)); |
wub | f4ab965 | 2020-02-20 14:45:43 -0800 | [diff] [blame] | 3849 | if (GetQuicReloadableFlag( |
| 3850 | quic_avoid_overestimate_bandwidth_with_aggregation)) { |
| 3851 | EXPECT_CALL(*send_algorithm_, OnPacketNeutered(QuicPacketNumber(1))) |
| 3852 | .Times(1); |
| 3853 | } |
fayang | d5c2ffb | 2020-02-04 11:49:05 -0800 | [diff] [blame] | 3854 | manager_.NeuterUnencryptedPackets(); |
| 3855 | } |
| 3856 | |
fayang | 84427fc | 2020-03-09 12:43:26 -0700 | [diff] [blame] | 3857 | TEST_F(QuicSentPacketManagerTest, NoPacketThresholdDetectionForRuntPackets) { |
| 3858 | EXPECT_TRUE( |
| 3859 | QuicSentPacketManagerPeer::UsePacketThresholdForRuntPackets(&manager_)); |
| 3860 | |
fayang | 84427fc | 2020-03-09 12:43:26 -0700 | [diff] [blame] | 3861 | QuicConfig config; |
| 3862 | QuicTagVector options; |
| 3863 | options.push_back(kRUNT); |
| 3864 | QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 3865 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3866 | EXPECT_CALL(*network_change_visitor_, OnCongestionChange()); |
| 3867 | manager_.SetFromConfig(config); |
| 3868 | |
| 3869 | EXPECT_FALSE( |
| 3870 | QuicSentPacketManagerPeer::UsePacketThresholdForRuntPackets(&manager_)); |
| 3871 | } |
| 3872 | |
fayang | 1640cc2 | 2020-03-21 14:11:02 -0700 | [diff] [blame] | 3873 | TEST_F(QuicSentPacketManagerTest, GetPathDegradingDelay) { |
| 3874 | QuicSentPacketManagerPeer::SetMaxTailLossProbes(&manager_, 2); |
| 3875 | // Before RTT sample is available. |
| 3876 | // 2 TLPs + 2 RTOs. |
| 3877 | QuicTime::Delta expected_delay = QuicTime::Delta::Zero(); |
| 3878 | for (size_t i = 0; i < 2; ++i) { |
| 3879 | QuicSentPacketManagerPeer::SetConsecutiveTlpCount(&manager_, i); |
| 3880 | expected_delay = |
| 3881 | expected_delay + |
| 3882 | QuicSentPacketManagerPeer::GetTailLossProbeDelay(&manager_); |
| 3883 | } |
| 3884 | for (size_t i = 0; i < 2; ++i) { |
| 3885 | QuicSentPacketManagerPeer::SetConsecutiveRtoCount(&manager_, i); |
| 3886 | expected_delay = |
| 3887 | expected_delay + |
| 3888 | QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_); |
| 3889 | } |
| 3890 | EXPECT_EQ(expected_delay, manager_.GetPathDegradingDelay()); |
| 3891 | |
| 3892 | expected_delay = QuicTime::Delta::Zero(); |
| 3893 | QuicSentPacketManagerPeer::SetConsecutiveTlpCount(&manager_, 0); |
| 3894 | QuicSentPacketManagerPeer::SetConsecutiveRtoCount(&manager_, 0); |
| 3895 | |
| 3896 | // After RTT sample is available. |
| 3897 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 3898 | rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(100), |
| 3899 | QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 3900 | // 2 TLPs + 2 RTOs. |
| 3901 | for (size_t i = 0; i < 2; ++i) { |
| 3902 | QuicSentPacketManagerPeer::SetConsecutiveTlpCount(&manager_, i); |
| 3903 | expected_delay = |
| 3904 | expected_delay + |
| 3905 | QuicSentPacketManagerPeer::GetTailLossProbeDelay(&manager_); |
| 3906 | } |
| 3907 | for (size_t i = 0; i < 2; ++i) { |
| 3908 | QuicSentPacketManagerPeer::SetConsecutiveRtoCount(&manager_, i); |
| 3909 | expected_delay = |
| 3910 | expected_delay + |
| 3911 | QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_); |
| 3912 | } |
| 3913 | EXPECT_EQ(expected_delay, manager_.GetPathDegradingDelay()); |
| 3914 | } |
| 3915 | |
fayang | 6c7313c | 2020-04-23 12:10:35 -0700 | [diff] [blame] | 3916 | // Regression test for b/154050235. |
| 3917 | TEST_F(QuicSentPacketManagerTest, ExponentialBackoffWithNoRttMeasurement) { |
| 3918 | QuicSentPacketManagerPeer::SetPerspective(&manager_, Perspective::IS_CLIENT); |
fayang | af9903b | 2020-05-14 14:34:28 -0700 | [diff] [blame] | 3919 | manager_.EnableMultiplePacketNumberSpacesSupport(); |
fayang | 6c7313c | 2020-04-23 12:10:35 -0700 | [diff] [blame] | 3920 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 3921 | EXPECT_EQ(QuicTime::Delta::FromMilliseconds(kInitialRttMs), |
| 3922 | rtt_stats->initial_rtt()); |
| 3923 | EXPECT_TRUE(rtt_stats->smoothed_rtt().IsZero()); |
| 3924 | |
| 3925 | SendCryptoPacket(1); |
| 3926 | QuicTime::Delta expected_pto_delay = |
| 3927 | QuicTime::Delta::FromMilliseconds(3 * kInitialRttMs); |
| 3928 | EXPECT_EQ(clock_.Now() + expected_pto_delay, |
| 3929 | manager_.GetRetransmissionTime()); |
| 3930 | |
| 3931 | // Invoke PTO. |
| 3932 | clock_.AdvanceTime(expected_pto_delay); |
| 3933 | manager_.OnRetransmissionTimeout(); |
| 3934 | |
| 3935 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 3936 | .WillOnce(WithArgs<1>(Invoke([this]() { RetransmitCryptoPacket(3); }))); |
| 3937 | manager_.MaybeSendProbePackets(); |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3938 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 3939 | manager_.AdjustPendingTimerTransmissions(); |
| 3940 | } |
fayang | 6c7313c | 2020-04-23 12:10:35 -0700 | [diff] [blame] | 3941 | // Verify exponential backoff of the PTO timeout. |
| 3942 | EXPECT_EQ(clock_.Now() + 2 * expected_pto_delay, |
| 3943 | manager_.GetRetransmissionTime()); |
| 3944 | } |
| 3945 | |
| 3946 | TEST_F(QuicSentPacketManagerTest, PtoDelayWithTinyInitialRtt) { |
fayang | af9903b | 2020-05-14 14:34:28 -0700 | [diff] [blame] | 3947 | manager_.EnableMultiplePacketNumberSpacesSupport(); |
fayang | 6c7313c | 2020-04-23 12:10:35 -0700 | [diff] [blame] | 3948 | RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); |
| 3949 | // Assume client provided a tiny initial RTT. |
| 3950 | rtt_stats->set_initial_rtt(QuicTime::Delta::FromMicroseconds(1)); |
| 3951 | EXPECT_EQ(QuicTime::Delta::FromMicroseconds(1), rtt_stats->initial_rtt()); |
| 3952 | EXPECT_TRUE(rtt_stats->smoothed_rtt().IsZero()); |
| 3953 | |
| 3954 | SendCryptoPacket(1); |
| 3955 | QuicTime::Delta expected_pto_delay = QuicTime::Delta::FromMilliseconds(10); |
| 3956 | // Verify kMinHandshakeTimeoutMs is respected. |
| 3957 | EXPECT_EQ(clock_.Now() + expected_pto_delay, |
| 3958 | manager_.GetRetransmissionTime()); |
| 3959 | |
| 3960 | // Invoke PTO. |
| 3961 | clock_.AdvanceTime(expected_pto_delay); |
| 3962 | manager_.OnRetransmissionTimeout(); |
| 3963 | |
| 3964 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)) |
| 3965 | .WillOnce(WithArgs<1>(Invoke([this]() { RetransmitCryptoPacket(3); }))); |
| 3966 | manager_.MaybeSendProbePackets(); |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 3967 | if (GetQuicReloadableFlag(quic_default_on_pto)) { |
| 3968 | manager_.AdjustPendingTimerTransmissions(); |
| 3969 | } |
fayang | 6c7313c | 2020-04-23 12:10:35 -0700 | [diff] [blame] | 3970 | // Verify exponential backoff of the PTO timeout. |
| 3971 | EXPECT_EQ(clock_.Now() + 2 * expected_pto_delay, |
| 3972 | manager_.GetRetransmissionTime()); |
| 3973 | } |
| 3974 | |
fayang | aecfd53 | 2020-04-28 12:35:12 -0700 | [diff] [blame] | 3975 | TEST_F(QuicSentPacketManagerTest, HandshakeAckCausesInitialKeyDropping) { |
| 3976 | manager_.EnableMultiplePacketNumberSpacesSupport(); |
| 3977 | QuicSentPacketManagerPeer::SetPerspective(&manager_, Perspective::IS_CLIENT); |
| 3978 | // Send INITIAL packet 1. |
| 3979 | SendDataPacket(1, ENCRYPTION_INITIAL); |
| 3980 | QuicTime::Delta expected_pto_delay = |
| 3981 | QuicTime::Delta::FromMilliseconds(3 * kInitialRttMs); |
| 3982 | EXPECT_EQ(clock_.Now() + expected_pto_delay, |
| 3983 | manager_.GetRetransmissionTime()); |
| 3984 | // Send HANDSHAKE ack. |
| 3985 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(10)); |
| 3986 | SendAckPacket(2, /*largest_acked=*/1, ENCRYPTION_HANDSHAKE); |
| 3987 | // Sending HANDSHAKE packet causes dropping of INITIAL key. |
| 3988 | EXPECT_CALL(notifier_, HasUnackedCryptoData()).WillRepeatedly(Return(false)); |
| 3989 | EXPECT_CALL(notifier_, IsFrameOutstanding(_)).WillRepeatedly(Return(false)); |
| 3990 | manager_.NeuterUnencryptedPackets(); |
| 3991 | // There is no in flight packets. |
| 3992 | EXPECT_FALSE(manager_.HasInFlightPackets()); |
| 3993 | // Verify PTO timer gets rearmed from now because of anti-amplification. |
| 3994 | EXPECT_EQ(clock_.Now() + expected_pto_delay, |
| 3995 | manager_.GetRetransmissionTime()); |
| 3996 | |
| 3997 | // Invoke PTO. |
| 3998 | clock_.AdvanceTime(expected_pto_delay); |
| 3999 | manager_.OnRetransmissionTimeout(); |
| 4000 | // Verify nothing to probe (and connection will send PING for current |
| 4001 | // encryption level). |
| 4002 | EXPECT_CALL(notifier_, RetransmitFrames(_, _)).Times(0); |
| 4003 | manager_.MaybeSendProbePackets(); |
| 4004 | } |
| 4005 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4006 | } // namespace |
| 4007 | } // namespace test |
| 4008 | } // namespace quic |