OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/quic_connection.h" | 5 #include "net/quic/quic_connection.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 } | 304 } |
305 | 305 |
306 const vector<QuicStopWaitingFrame>& stop_waiting_frames() const { | 306 const vector<QuicStopWaitingFrame>& stop_waiting_frames() const { |
307 return framer_.stop_waiting_frames(); | 307 return framer_.stop_waiting_frames(); |
308 } | 308 } |
309 | 309 |
310 const vector<QuicConnectionCloseFrame>& connection_close_frames() const { | 310 const vector<QuicConnectionCloseFrame>& connection_close_frames() const { |
311 return framer_.connection_close_frames(); | 311 return framer_.connection_close_frames(); |
312 } | 312 } |
313 | 313 |
| 314 const vector<QuicRstStreamFrame>& rst_stream_frames() const { |
| 315 return framer_.rst_stream_frames(); |
| 316 } |
| 317 |
314 const vector<QuicStreamFrame>& stream_frames() const { | 318 const vector<QuicStreamFrame>& stream_frames() const { |
315 return framer_.stream_frames(); | 319 return framer_.stream_frames(); |
316 } | 320 } |
317 | 321 |
318 const vector<QuicPingFrame>& ping_frames() const { | 322 const vector<QuicPingFrame>& ping_frames() const { |
319 return framer_.ping_frames(); | 323 return framer_.ping_frames(); |
320 } | 324 } |
321 | 325 |
322 size_t last_packet_size() { | 326 size_t last_packet_size() { |
323 return last_packet_size_; | 327 return last_packet_size_; |
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1325 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 1329 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
1326 QuicPacketCreatorPeer::SetSequenceNumber(&peer_creator_, 7); | 1330 QuicPacketCreatorPeer::SetSequenceNumber(&peer_creator_, 7); |
1327 EXPECT_CALL(visitor_, | 1331 EXPECT_CALL(visitor_, |
1328 OnConnectionClosed(QUIC_INVALID_STOP_WAITING_DATA, false)); | 1332 OnConnectionClosed(QUIC_INVALID_STOP_WAITING_DATA, false)); |
1329 QuicStopWaitingFrame frame3 = InitStopWaitingFrame(1); | 1333 QuicStopWaitingFrame frame3 = InitStopWaitingFrame(1); |
1330 ProcessStopWaitingPacket(&frame3); | 1334 ProcessStopWaitingPacket(&frame3); |
1331 } | 1335 } |
1332 | 1336 |
1333 TEST_P(QuicConnectionTest, TooManySentPackets) { | 1337 TEST_P(QuicConnectionTest, TooManySentPackets) { |
1334 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1338 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1335 const QuicPacketCount num_sent_packets = kMaxTrackedPackets + 100; | 1339 |
1336 for (QuicPacketCount i = 0; i < num_sent_packets; ++i) { | 1340 for (int i = 0; i < 1100; ++i) { |
1337 SendStreamDataToPeer(1, "foo", 3 * i, !kFin, nullptr); | 1341 SendStreamDataToPeer(1, "foo", 3 * i, !kFin, nullptr); |
1338 } | 1342 } |
1339 | 1343 |
1340 // Ack packet 1, which leaves more than the limit outstanding. | 1344 // Ack packet 1, which leaves more than the limit outstanding. |
1341 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 1345 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
1342 EXPECT_CALL(visitor_, OnConnectionClosed( | 1346 EXPECT_CALL(visitor_, OnConnectionClosed( |
1343 QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS, false)); | 1347 QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS, false)); |
1344 // We're receive buffer limited, so the connection won't try to write more. | 1348 // We're receive buffer limited, so the connection won't try to write more. |
1345 EXPECT_CALL(visitor_, OnCanWrite()).Times(0); | 1349 EXPECT_CALL(visitor_, OnCanWrite()).Times(0); |
1346 | 1350 |
1347 // Nack every packet except the last one, leaving a huge gap. | 1351 // Nack every packet except the last one, leaving a huge gap. |
1348 QuicAckFrame frame1 = InitAckFrame(num_sent_packets); | 1352 QuicAckFrame frame1 = InitAckFrame(1100); |
1349 for (QuicPacketSequenceNumber i = 1; i < num_sent_packets; ++i) { | 1353 for (QuicPacketSequenceNumber i = 1; i < 1100; ++i) { |
1350 NackPacket(i, &frame1); | 1354 NackPacket(i, &frame1); |
1351 } | 1355 } |
1352 ProcessAckPacket(&frame1); | 1356 ProcessAckPacket(&frame1); |
1353 } | 1357 } |
1354 | 1358 |
1355 TEST_P(QuicConnectionTest, TooManyReceivedPackets) { | 1359 TEST_P(QuicConnectionTest, TooManyReceivedPackets) { |
1356 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1360 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1357 EXPECT_CALL(visitor_, OnConnectionClosed( | 1361 EXPECT_CALL(visitor_, OnConnectionClosed( |
1358 QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS, false)); | 1362 QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS, false)); |
1359 | 1363 |
1360 // Miss every other packet for 5000 packets. | 1364 // Miss every other packet for 1000 packets. |
1361 for (QuicPacketSequenceNumber i = 1; i < kMaxTrackedPackets; ++i) { | 1365 for (QuicPacketSequenceNumber i = 1; i < 1000; ++i) { |
1362 ProcessPacket(i * 2); | 1366 ProcessPacket(i * 2); |
1363 if (!connection_.connected()) { | 1367 if (!connection_.connected()) { |
1364 break; | 1368 break; |
1365 } | 1369 } |
1366 } | 1370 } |
1367 } | 1371 } |
1368 | 1372 |
1369 TEST_P(QuicConnectionTest, LargestObservedLower) { | 1373 TEST_P(QuicConnectionTest, LargestObservedLower) { |
1370 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1374 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1371 | 1375 |
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2195 lost_packets.insert(2); | 2199 lost_packets.insert(2); |
2196 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 2200 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
2197 .WillOnce(Return(lost_packets)); | 2201 .WillOnce(Return(lost_packets)); |
2198 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 2202 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
2199 EXPECT_CALL(*send_algorithm_, | 2203 EXPECT_CALL(*send_algorithm_, |
2200 OnPacketSent(_, _, _, second_packet_size - kQuicVersionSize, _)). | 2204 OnPacketSent(_, _, _, second_packet_size - kQuicVersionSize, _)). |
2201 Times(1); | 2205 Times(1); |
2202 ProcessAckPacket(&nack_two); | 2206 ProcessAckPacket(&nack_two); |
2203 } | 2207 } |
2204 | 2208 |
| 2209 TEST_P(QuicConnectionTest, DoNotSendQueuedPacketForResetStream) { |
| 2210 ValueRestore<bool> old_flag(&FLAGS_quic_do_not_retransmit_for_reset_streams, |
| 2211 true); |
| 2212 |
| 2213 // Block the connection to queue the packet. |
| 2214 BlockOnNextWrite(); |
| 2215 |
| 2216 QuicStreamId stream_id = 2; |
| 2217 connection_.SendStreamDataWithString(stream_id, "foo", 0, !kFin, nullptr); |
| 2218 |
| 2219 // Now that there is a queued packet, reset the stream. |
| 2220 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); |
| 2221 |
| 2222 // Unblock the connection and verify that only the RST_STREAM is sent. |
| 2223 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 2224 writer_->SetWritable(); |
| 2225 connection_.OnCanWrite(); |
| 2226 EXPECT_EQ(1u, writer_->frame_count()); |
| 2227 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); |
| 2228 } |
| 2229 |
| 2230 TEST_P(QuicConnectionTest, DoNotRetransmitForResetStreamOnNack) { |
| 2231 ValueRestore<bool> old_flag(&FLAGS_quic_do_not_retransmit_for_reset_streams, |
| 2232 true); |
| 2233 |
| 2234 QuicStreamId stream_id = 2; |
| 2235 QuicPacketSequenceNumber last_packet; |
| 2236 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); |
| 2237 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet); |
| 2238 SendStreamDataToPeer(stream_id, "fooos", 7, !kFin, &last_packet); |
| 2239 |
| 2240 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 2241 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); |
| 2242 |
| 2243 // Lose a packet and ensure it does not trigger retransmission. |
| 2244 QuicAckFrame nack_two = InitAckFrame(last_packet); |
| 2245 NackPacket(last_packet - 1, &nack_two); |
| 2246 SequenceNumberSet lost_packets; |
| 2247 lost_packets.insert(last_packet - 1); |
| 2248 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2249 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 2250 .WillOnce(Return(lost_packets)); |
| 2251 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 2252 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); |
| 2253 ProcessAckPacket(&nack_two); |
| 2254 } |
| 2255 |
| 2256 TEST_P(QuicConnectionTest, DoNotRetransmitForResetStreamOnRTO) { |
| 2257 ValueRestore<bool> old_flag(&FLAGS_quic_do_not_retransmit_for_reset_streams, |
| 2258 true); |
| 2259 |
| 2260 QuicStreamId stream_id = 2; |
| 2261 QuicPacketSequenceNumber last_packet; |
| 2262 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); |
| 2263 |
| 2264 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 2265 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); |
| 2266 |
| 2267 // Fire the RTO and verify that the RST_STREAM is resent, not stream data. |
| 2268 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 2269 clock_.AdvanceTime(DefaultRetransmissionTime()); |
| 2270 connection_.GetRetransmissionAlarm()->Fire(); |
| 2271 EXPECT_EQ(1u, writer_->frame_count()); |
| 2272 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); |
| 2273 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id); |
| 2274 } |
| 2275 |
| 2276 TEST_P(QuicConnectionTest, DoNotSendPendingRetransmissionForResetStream) { |
| 2277 ValueRestore<bool> old_flag(&FLAGS_quic_do_not_retransmit_for_reset_streams, |
| 2278 true); |
| 2279 |
| 2280 QuicStreamId stream_id = 2; |
| 2281 QuicPacketSequenceNumber last_packet; |
| 2282 SendStreamDataToPeer(stream_id, "foo", 0, !kFin, &last_packet); |
| 2283 SendStreamDataToPeer(stream_id, "foos", 3, !kFin, &last_packet); |
| 2284 BlockOnNextWrite(); |
| 2285 connection_.SendStreamDataWithString(stream_id, "fooos", 7, !kFin, nullptr); |
| 2286 |
| 2287 // Lose a packet which will trigger a pending retransmission. |
| 2288 QuicAckFrame ack = InitAckFrame(last_packet); |
| 2289 NackPacket(last_packet - 1, &ack); |
| 2290 SequenceNumberSet lost_packets; |
| 2291 lost_packets.insert(last_packet - 1); |
| 2292 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2293 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 2294 .WillOnce(Return(lost_packets)); |
| 2295 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 2296 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); |
| 2297 ProcessAckPacket(&ack); |
| 2298 |
| 2299 connection_.SendRstStream(stream_id, QUIC_STREAM_NO_ERROR, 14); |
| 2300 |
| 2301 // Unblock the connection and verify that the RST_STREAM is sent but not the |
| 2302 // second data packet nor a retransmit. |
| 2303 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 2304 writer_->SetWritable(); |
| 2305 connection_.OnCanWrite(); |
| 2306 EXPECT_EQ(1u, writer_->frame_count()); |
| 2307 EXPECT_EQ(1u, writer_->rst_stream_frames().size()); |
| 2308 EXPECT_EQ(stream_id, writer_->rst_stream_frames().front().stream_id); |
| 2309 } |
| 2310 |
2205 TEST_P(QuicConnectionTest, DiscardRetransmit) { | 2311 TEST_P(QuicConnectionTest, DiscardRetransmit) { |
2206 QuicPacketSequenceNumber last_packet; | 2312 QuicPacketSequenceNumber last_packet; |
2207 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 | 2313 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 |
2208 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2 | 2314 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2 |
2209 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3 | 2315 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3 |
2210 | 2316 |
2211 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2317 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2212 | 2318 |
2213 // Instigate a loss with an ack. | 2319 // Instigate a loss with an ack. |
2214 QuicAckFrame nack_two = InitAckFrame(3); | 2320 QuicAckFrame nack_two = InitAckFrame(3); |
(...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3217 // Set up a larger payload than will fit in one packet. | 3323 // Set up a larger payload than will fit in one packet. |
3218 const string payload(connection_.max_packet_length(), 'a'); | 3324 const string payload(connection_.max_packet_length(), 'a'); |
3219 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)).Times(AnyNumber()); | 3325 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)).Times(AnyNumber()); |
3220 | 3326 |
3221 // Now send some packets with no truncation. | 3327 // Now send some packets with no truncation. |
3222 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 3328 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
3223 EXPECT_EQ(payload.size(), | 3329 EXPECT_EQ(payload.size(), |
3224 connection_.SendStreamDataWithString( | 3330 connection_.SendStreamDataWithString( |
3225 3, payload, 0, !kFin, nullptr).bytes_consumed); | 3331 3, payload, 0, !kFin, nullptr).bytes_consumed); |
3226 // Track the size of the second packet here. The overhead will be the largest | 3332 // Track the size of the second packet here. The overhead will be the largest |
3227 // we see in this test, due to the non-truncated CID. | 3333 // we see in this test, due to the non-truncated connection id. |
3228 size_t non_truncated_packet_size = writer_->last_packet_size(); | 3334 size_t non_truncated_packet_size = writer_->last_packet_size(); |
3229 | 3335 |
3230 // Change to a 4 byte CID. | 3336 // Change to a 4 byte connection id. |
3231 QuicConfig config; | 3337 QuicConfig config; |
3232 QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 4); | 3338 QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 4); |
3233 connection_.SetFromConfig(config); | 3339 connection_.SetFromConfig(config); |
3234 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 3340 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
3235 EXPECT_EQ(payload.size(), | 3341 EXPECT_EQ(payload.size(), |
3236 connection_.SendStreamDataWithString( | 3342 connection_.SendStreamDataWithString( |
3237 3, payload, 0, !kFin, nullptr).bytes_consumed); | 3343 3, payload, 0, !kFin, nullptr).bytes_consumed); |
3238 // Verify that we have 8 fewer bytes than in the non-truncated case. The | 3344 // Verify that we have 8 fewer bytes than in the non-truncated case. The |
3239 // first packet got 4 bytes of extra payload due to the truncation, and the | 3345 // first packet got 4 bytes of extra payload due to the truncation, and the |
3240 // headers here are also 4 byte smaller. | 3346 // headers here are also 4 byte smaller. |
3241 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 8); | 3347 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 8); |
3242 | 3348 |
3243 | 3349 // Change to a 1 byte connection id. |
3244 // Change to a 1 byte CID. | |
3245 QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 1); | 3350 QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 1); |
3246 connection_.SetFromConfig(config); | 3351 connection_.SetFromConfig(config); |
3247 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 3352 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
3248 EXPECT_EQ(payload.size(), | 3353 EXPECT_EQ(payload.size(), |
3249 connection_.SendStreamDataWithString( | 3354 connection_.SendStreamDataWithString( |
3250 3, payload, 0, !kFin, nullptr).bytes_consumed); | 3355 3, payload, 0, !kFin, nullptr).bytes_consumed); |
3251 // Just like above, we save 7 bytes on payload, and 7 on truncation. | 3356 // Just like above, we save 7 bytes on payload, and 7 on truncation. |
3252 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 7 * 2); | 3357 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 7 * 2); |
3253 | 3358 |
3254 // Change to a 0 byte CID. | 3359 // Change to a 0 byte connection id. |
3255 QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 0); | 3360 QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 0); |
3256 connection_.SetFromConfig(config); | 3361 connection_.SetFromConfig(config); |
3257 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 3362 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
3258 EXPECT_EQ(payload.size(), | 3363 EXPECT_EQ(payload.size(), |
3259 connection_.SendStreamDataWithString( | 3364 connection_.SendStreamDataWithString( |
3260 3, payload, 0, !kFin, nullptr).bytes_consumed); | 3365 3, payload, 0, !kFin, nullptr).bytes_consumed); |
3261 // Just like above, we save 8 bytes on payload, and 8 on truncation. | 3366 // Just like above, we save 8 bytes on payload, and 8 on truncation. |
3262 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 8 * 2); | 3367 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 8 * 2); |
3263 } | 3368 } |
3264 | 3369 |
(...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4352 // Regression test for b/18594622 | 4457 // Regression test for b/18594622 |
4353 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 4458 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
4354 EXPECT_DFATAL( | 4459 EXPECT_DFATAL( |
4355 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), | 4460 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), |
4356 "Attempt to send empty stream frame"); | 4461 "Attempt to send empty stream frame"); |
4357 } | 4462 } |
4358 | 4463 |
4359 } // namespace | 4464 } // namespace |
4360 } // namespace test | 4465 } // namespace test |
4361 } // namespace net | 4466 } // namespace net |
OLD | NEW |