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/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 4129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4140 EXPECT_TRUE(writer_->IsWriteBlocked()); | 4140 EXPECT_TRUE(writer_->IsWriteBlocked()); |
4141 TriggerConnectionClose(); | 4141 TriggerConnectionClose(); |
4142 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 4142 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
4143 } | 4143 } |
4144 | 4144 |
4145 TEST_P(QuicConnectionTest, AckNotifierTriggerCallback) { | 4145 TEST_P(QuicConnectionTest, AckNotifierTriggerCallback) { |
4146 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4146 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
4147 | 4147 |
4148 // Create a delegate which we expect to be called. | 4148 // Create a delegate which we expect to be called. |
4149 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 4149 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
4150 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _, _, _)).Times(1); | 4150 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _)).Times(1); |
4151 | 4151 |
4152 // Send some data, which will register the delegate to be notified. | 4152 // Send some data, which will register the delegate to be notified. |
4153 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); | 4153 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); |
4154 | 4154 |
4155 // Process an ACK from the server which should trigger the callback. | 4155 // Process an ACK from the server which should trigger the callback. |
4156 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 4156 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
4157 QuicAckFrame frame = InitAckFrame(1); | 4157 QuicAckFrame frame = InitAckFrame(1); |
4158 ProcessAckPacket(&frame); | 4158 ProcessAckPacket(&frame); |
4159 } | 4159 } |
4160 | 4160 |
4161 TEST_P(QuicConnectionTest, AckNotifierFailToTriggerCallback) { | 4161 TEST_P(QuicConnectionTest, AckNotifierFailToTriggerCallback) { |
4162 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4162 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
4163 | 4163 |
4164 // Create a delegate which we don't expect to be called. | 4164 // Create a delegate which we don't expect to be called. |
4165 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 4165 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
4166 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _, _, _)).Times(0); | 4166 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _)).Times(0); |
4167 | 4167 |
4168 // Send some data, which will register the delegate to be notified. This will | 4168 // Send some data, which will register the delegate to be notified. This will |
4169 // not be ACKed and so the delegate should never be called. | 4169 // not be ACKed and so the delegate should never be called. |
4170 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); | 4170 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); |
4171 | 4171 |
4172 // Send some other data which we will ACK. | 4172 // Send some other data which we will ACK. |
4173 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); | 4173 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); |
4174 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, nullptr); | 4174 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, nullptr); |
4175 | 4175 |
4176 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 | 4176 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 |
4177 // which we registered to be notified about. | 4177 // which we registered to be notified about. |
4178 QuicAckFrame frame = InitAckFrame(3); | 4178 QuicAckFrame frame = InitAckFrame(3); |
4179 NackPacket(1, &frame); | 4179 NackPacket(1, &frame); |
4180 SequenceNumberSet lost_packets; | 4180 SequenceNumberSet lost_packets; |
4181 lost_packets.insert(1); | 4181 lost_packets.insert(1); |
4182 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 4182 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
4183 .WillOnce(Return(lost_packets)); | 4183 .WillOnce(Return(lost_packets)); |
4184 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 4184 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
4185 ProcessAckPacket(&frame); | 4185 ProcessAckPacket(&frame); |
4186 } | 4186 } |
4187 | 4187 |
4188 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { | 4188 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { |
4189 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4189 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
4190 | 4190 |
4191 // Create a delegate which we expect to be called. | 4191 // Create a delegate which we expect to be called. |
4192 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 4192 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
4193 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _, _, _)).Times(1); | 4193 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _)).Times(1); |
4194 | 4194 |
4195 // Send four packets, and register to be notified on ACK of packet 2. | 4195 // Send four packets, and register to be notified on ACK of packet 2. |
4196 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); | 4196 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); |
4197 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, delegate.get()); | 4197 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, delegate.get()); |
4198 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, nullptr); | 4198 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, nullptr); |
4199 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, nullptr); | 4199 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, nullptr); |
4200 | 4200 |
4201 // Now we receive ACK for packets 1, 3, and 4 and lose 2. | 4201 // Now we receive ACK for packets 1, 3, and 4 and lose 2. |
4202 QuicAckFrame frame = InitAckFrame(4); | 4202 QuicAckFrame frame = InitAckFrame(4); |
4203 NackPacket(2, &frame); | 4203 NackPacket(2, &frame); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4240 clock_.AdvanceTime(DefaultRetransmissionTime()); | 4240 clock_.AdvanceTime(DefaultRetransmissionTime()); |
4241 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 4241 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
4242 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); | 4242 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); |
4243 connection_.GetRetransmissionAlarm()->Fire(); | 4243 connection_.GetRetransmissionAlarm()->Fire(); |
4244 EXPECT_EQ(2u, writer_->header().packet_sequence_number); | 4244 EXPECT_EQ(2u, writer_->header().packet_sequence_number); |
4245 // We do not raise the high water mark yet. | 4245 // We do not raise the high water mark yet. |
4246 EXPECT_EQ(1u, stop_waiting()->least_unacked); | 4246 EXPECT_EQ(1u, stop_waiting()->least_unacked); |
4247 | 4247 |
4248 // Ack the original packet, which will revert the RTO. | 4248 // Ack the original packet, which will revert the RTO. |
4249 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4249 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
4250 EXPECT_CALL(*delegate.get(), OnAckNotification(1, _, 1, _, _)); | 4250 EXPECT_CALL(*delegate.get(), OnAckNotification(1, _, _)); |
4251 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout()); | 4251 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout()); |
4252 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 4252 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
4253 QuicAckFrame ack_frame = InitAckFrame(1); | 4253 QuicAckFrame ack_frame = InitAckFrame(1); |
4254 ProcessAckPacket(&ack_frame); | 4254 ProcessAckPacket(&ack_frame); |
4255 | 4255 |
4256 // Delegate is not notified again when the retransmit is acked. | 4256 // Delegate is not notified again when the retransmit is acked. |
4257 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 4257 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
4258 QuicAckFrame second_ack_frame = InitAckFrame(2); | 4258 QuicAckFrame second_ack_frame = InitAckFrame(2); |
4259 ProcessAckPacket(&second_ack_frame); | 4259 ProcessAckPacket(&second_ack_frame); |
4260 } | 4260 } |
(...skipping 21 matching lines...) Expand all Loading... |
4282 lost_packets.insert(2); | 4282 lost_packets.insert(2); |
4283 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4283 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
4284 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 4284 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
4285 .WillOnce(Return(lost_packets)); | 4285 .WillOnce(Return(lost_packets)); |
4286 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 4286 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
4287 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 4287 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
4288 ProcessAckPacket(&frame); | 4288 ProcessAckPacket(&frame); |
4289 | 4289 |
4290 // Now we get an ACK for packet 2, which was previously nacked. | 4290 // Now we get an ACK for packet 2, which was previously nacked. |
4291 SequenceNumberSet no_lost_packets; | 4291 SequenceNumberSet no_lost_packets; |
4292 EXPECT_CALL(*delegate.get(), OnAckNotification(1, _, 1, _, _)); | 4292 EXPECT_CALL(*delegate.get(), OnAckNotification(1, _, _)); |
4293 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 4293 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
4294 .WillOnce(Return(no_lost_packets)); | 4294 .WillOnce(Return(no_lost_packets)); |
4295 QuicAckFrame second_ack_frame = InitAckFrame(4); | 4295 QuicAckFrame second_ack_frame = InitAckFrame(4); |
4296 ProcessAckPacket(&second_ack_frame); | 4296 ProcessAckPacket(&second_ack_frame); |
4297 | 4297 |
4298 // Verify that the delegate is not notified again when the | 4298 // Verify that the delegate is not notified again when the |
4299 // retransmit is acked. | 4299 // retransmit is acked. |
4300 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 4300 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
4301 .WillOnce(Return(no_lost_packets)); | 4301 .WillOnce(Return(no_lost_packets)); |
4302 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 4302 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
4303 QuicAckFrame third_ack_frame = InitAckFrame(5); | 4303 QuicAckFrame third_ack_frame = InitAckFrame(5); |
4304 ProcessAckPacket(&third_ack_frame); | 4304 ProcessAckPacket(&third_ack_frame); |
4305 } | 4305 } |
4306 | 4306 |
4307 TEST_P(QuicConnectionTest, AckNotifierFECTriggerCallback) { | 4307 TEST_P(QuicConnectionTest, AckNotifierFECTriggerCallback) { |
4308 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4308 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
4309 | 4309 |
4310 // Create a delegate which we expect to be called. | 4310 // Create a delegate which we expect to be called. |
4311 scoped_refptr<MockAckNotifierDelegate> delegate( | 4311 scoped_refptr<MockAckNotifierDelegate> delegate( |
4312 new MockAckNotifierDelegate); | 4312 new MockAckNotifierDelegate); |
4313 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _, _, _)).Times(1); | 4313 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _)).Times(1); |
4314 | 4314 |
4315 // Send some data, which will register the delegate to be notified. | 4315 // Send some data, which will register the delegate to be notified. |
4316 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); | 4316 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); |
4317 connection_.SendStreamDataWithString(2, "bar", 0, !kFin, nullptr); | 4317 connection_.SendStreamDataWithString(2, "bar", 0, !kFin, nullptr); |
4318 | 4318 |
4319 // Process an ACK from the server with a revived packet, which should trigger | 4319 // Process an ACK from the server with a revived packet, which should trigger |
4320 // the callback. | 4320 // the callback. |
4321 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 4321 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
4322 QuicAckFrame frame = InitAckFrame(2); | 4322 QuicAckFrame frame = InitAckFrame(2); |
4323 NackPacket(1, &frame); | 4323 NackPacket(1, &frame); |
4324 frame.revived_packets.insert(1); | 4324 frame.revived_packets.insert(1); |
4325 ProcessAckPacket(&frame); | 4325 ProcessAckPacket(&frame); |
4326 // If the ack is processed again, the notifier should not be called again. | 4326 // If the ack is processed again, the notifier should not be called again. |
4327 ProcessAckPacket(&frame); | 4327 ProcessAckPacket(&frame); |
4328 } | 4328 } |
4329 | 4329 |
4330 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { | 4330 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { |
4331 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4331 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
4332 EXPECT_CALL(visitor_, OnCanWrite()); | 4332 EXPECT_CALL(visitor_, OnCanWrite()); |
4333 | 4333 |
4334 // Create a delegate which we expect to be called. | 4334 // Create a delegate which we expect to be called. |
4335 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 4335 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
4336 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _, _, _)).Times(1); | 4336 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _)).Times(1); |
4337 | 4337 |
4338 // Expect ACKs for 1 packet. | 4338 // Expect ACKs for 1 packet. |
4339 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 4339 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
4340 | 4340 |
4341 // Send one packet, and register to be notified on ACK. | 4341 // Send one packet, and register to be notified on ACK. |
4342 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); | 4342 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); |
4343 | 4343 |
4344 // Ack packet gets dropped, but we receive an FEC packet that covers it. | 4344 // Ack packet gets dropped, but we receive an FEC packet that covers it. |
4345 // Should recover the Ack packet and trigger the notification callback. | 4345 // Should recover the Ack packet and trigger the notification callback. |
4346 QuicFrames frames; | 4346 QuicFrames frames; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4519 // Regression test for b/18594622 | 4519 // Regression test for b/18594622 |
4520 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 4520 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
4521 EXPECT_DFATAL( | 4521 EXPECT_DFATAL( |
4522 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), | 4522 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), |
4523 "Attempt to send empty stream frame"); | 4523 "Attempt to send empty stream frame"); |
4524 } | 4524 } |
4525 | 4525 |
4526 } // namespace | 4526 } // namespace |
4527 } // namespace test | 4527 } // namespace test |
4528 } // namespace net | 4528 } // namespace net |
OLD | NEW |