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" |
11 #include "net/quic/congestion_control/loss_detection_interface.h" | 11 #include "net/quic/congestion_control/loss_detection_interface.h" |
12 #include "net/quic/congestion_control/receive_algorithm_interface.h" | 12 #include "net/quic/congestion_control/receive_algorithm_interface.h" |
13 #include "net/quic/congestion_control/send_algorithm_interface.h" | 13 #include "net/quic/congestion_control/send_algorithm_interface.h" |
14 #include "net/quic/crypto/null_encrypter.h" | 14 #include "net/quic/crypto/null_encrypter.h" |
15 #include "net/quic/crypto/quic_decrypter.h" | 15 #include "net/quic/crypto/quic_decrypter.h" |
16 #include "net/quic/crypto/quic_encrypter.h" | 16 #include "net/quic/crypto/quic_encrypter.h" |
| 17 #include "net/quic/quic_ack_notifier.h" |
17 #include "net/quic/quic_flags.h" | 18 #include "net/quic/quic_flags.h" |
18 #include "net/quic/quic_protocol.h" | 19 #include "net/quic/quic_protocol.h" |
19 #include "net/quic/quic_utils.h" | 20 #include "net/quic/quic_utils.h" |
20 #include "net/quic/test_tools/mock_clock.h" | 21 #include "net/quic/test_tools/mock_clock.h" |
21 #include "net/quic/test_tools/mock_random.h" | 22 #include "net/quic/test_tools/mock_random.h" |
22 #include "net/quic/test_tools/quic_config_peer.h" | 23 #include "net/quic/test_tools/quic_config_peer.h" |
23 #include "net/quic/test_tools/quic_connection_peer.h" | 24 #include "net/quic/test_tools/quic_connection_peer.h" |
24 #include "net/quic/test_tools/quic_framer_peer.h" | 25 #include "net/quic/test_tools/quic_framer_peer.h" |
25 #include "net/quic/test_tools/quic_packet_creator_peer.h" | 26 #include "net/quic/test_tools/quic_packet_creator_peer.h" |
26 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" | 27 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" |
27 #include "net/quic/test_tools/quic_test_utils.h" | 28 #include "net/quic/test_tools/quic_test_utils.h" |
28 #include "net/quic/test_tools/simple_quic_framer.h" | 29 #include "net/quic/test_tools/simple_quic_framer.h" |
| 30 #include "net/test/gtest_util.h" |
29 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
31 | 33 |
32 using base::StringPiece; | 34 using base::StringPiece; |
33 using std::map; | 35 using std::map; |
34 using std::string; | 36 using std::string; |
35 using std::vector; | 37 using std::vector; |
36 using testing::AnyNumber; | 38 using testing::AnyNumber; |
37 using testing::AtLeast; | 39 using testing::AtLeast; |
38 using testing::ContainerEq; | 40 using testing::ContainerEq; |
(...skipping 4090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4129 ack_header.fec_group = 1; | 4131 ack_header.fec_group = 1; |
4130 | 4132 |
4131 QuicPacket* packet = | 4133 QuicPacket* packet = |
4132 BuildUnsizedDataPacket(&framer_, ack_header, frames).packet; | 4134 BuildUnsizedDataPacket(&framer_, ack_header, frames).packet; |
4133 | 4135 |
4134 // Take the packet which contains the ACK frame, and construct and deliver an | 4136 // Take the packet which contains the ACK frame, and construct and deliver an |
4135 // FEC packet which allows the ACK packet to be recovered. | 4137 // FEC packet which allows the ACK packet to be recovered. |
4136 ProcessFecPacket(2, 1, true, !kEntropyFlag, packet); | 4138 ProcessFecPacket(2, 1, true, !kEntropyFlag, packet); |
4137 } | 4139 } |
4138 | 4140 |
4139 TEST_P(QuicConnectionTest, NetworkChangeVisitorCallbacksChangeFecState) { | 4141 TEST_P(QuicConnectionTest, NetworkChangeVisitorCwndCallbackChangesFecState) { |
4140 QuicPacketCreator* creator = | 4142 QuicPacketCreator* creator = |
4141 QuicConnectionPeer::GetPacketCreator(&connection_); | 4143 QuicConnectionPeer::GetPacketCreator(&connection_); |
4142 size_t max_packets_per_fec_group = creator->max_packets_per_fec_group(); | 4144 size_t max_packets_per_fec_group = creator->max_packets_per_fec_group(); |
4143 | 4145 |
4144 QuicSentPacketManager::NetworkChangeVisitor* visitor = | 4146 QuicSentPacketManager::NetworkChangeVisitor* visitor = |
4145 QuicSentPacketManagerPeer::GetNetworkChangeVisitor( | 4147 QuicSentPacketManagerPeer::GetNetworkChangeVisitor( |
4146 QuicConnectionPeer::GetSentPacketManager(&connection_)); | 4148 QuicConnectionPeer::GetSentPacketManager(&connection_)); |
4147 EXPECT_TRUE(visitor); | 4149 EXPECT_TRUE(visitor); |
4148 | 4150 |
4149 // Increase FEC group size by increasing congestion window to a large number. | 4151 // Increase FEC group size by increasing congestion window to a large number. |
4150 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( | 4152 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( |
4151 Return(1000 * kDefaultTCPMSS)); | 4153 Return(1000 * kDefaultTCPMSS)); |
4152 visitor->OnCongestionWindowChange(); | 4154 visitor->OnCongestionWindowChange(); |
4153 EXPECT_LT(max_packets_per_fec_group, creator->max_packets_per_fec_group()); | 4155 EXPECT_LT(max_packets_per_fec_group, creator->max_packets_per_fec_group()); |
4154 } | 4156 } |
4155 | 4157 |
| 4158 TEST_P(QuicConnectionTest, NetworkChangeVisitorConfigCallbackChangesFecState) { |
| 4159 QuicSentPacketManager* sent_packet_manager = |
| 4160 QuicConnectionPeer::GetSentPacketManager(&connection_); |
| 4161 QuicSentPacketManager::NetworkChangeVisitor* visitor = |
| 4162 QuicSentPacketManagerPeer::GetNetworkChangeVisitor(sent_packet_manager); |
| 4163 EXPECT_TRUE(visitor); |
| 4164 |
| 4165 QuicPacketGenerator* generator = |
| 4166 QuicConnectionPeer::GetPacketGenerator(&connection_); |
| 4167 EXPECT_EQ(QuicTime::Delta::Zero(), generator->fec_timeout()); |
| 4168 |
| 4169 // Verify that sending a config with a new initial rtt changes fec timeout. |
| 4170 // Create and process a config with a non-zero initial RTT. |
| 4171 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)); |
| 4172 QuicConfig config; |
| 4173 config.SetInitialRoundTripTimeUsToSend(300000); |
| 4174 connection_.SetFromConfig(config); |
| 4175 EXPECT_LT(QuicTime::Delta::Zero(), generator->fec_timeout()); |
| 4176 } |
| 4177 |
| 4178 TEST_P(QuicConnectionTest, NetworkChangeVisitorRttCallbackChangesFecState) { |
| 4179 // Verify that sending a config with a new initial rtt changes fec timeout. |
| 4180 QuicSentPacketManager* sent_packet_manager = |
| 4181 QuicConnectionPeer::GetSentPacketManager(&connection_); |
| 4182 QuicSentPacketManager::NetworkChangeVisitor* visitor = |
| 4183 QuicSentPacketManagerPeer::GetNetworkChangeVisitor(sent_packet_manager); |
| 4184 EXPECT_TRUE(visitor); |
| 4185 |
| 4186 QuicPacketGenerator* generator = |
| 4187 QuicConnectionPeer::GetPacketGenerator(&connection_); |
| 4188 EXPECT_EQ(QuicTime::Delta::Zero(), generator->fec_timeout()); |
| 4189 |
| 4190 // Increase FEC timeout by increasing RTT. |
| 4191 RttStats* rtt_stats = |
| 4192 QuicSentPacketManagerPeer::GetRttStats(sent_packet_manager); |
| 4193 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(300), |
| 4194 QuicTime::Delta::Zero(), QuicTime::Zero()); |
| 4195 visitor->OnRttChange(); |
| 4196 EXPECT_LT(QuicTime::Delta::Zero(), generator->fec_timeout()); |
| 4197 } |
| 4198 |
4156 class MockQuicConnectionDebugVisitor | 4199 class MockQuicConnectionDebugVisitor |
4157 : public QuicConnectionDebugVisitor { | 4200 : public QuicConnectionDebugVisitor { |
4158 public: | 4201 public: |
4159 MOCK_METHOD1(OnFrameAddedToPacket, | 4202 MOCK_METHOD1(OnFrameAddedToPacket, |
4160 void(const QuicFrame&)); | 4203 void(const QuicFrame&)); |
4161 | 4204 |
4162 MOCK_METHOD6(OnPacketSent, | 4205 MOCK_METHOD6(OnPacketSent, |
4163 void(const SerializedPacket&, | 4206 void(const SerializedPacket&, |
4164 QuicPacketSequenceNumber, | 4207 QuicPacketSequenceNumber, |
4165 EncryptionLevel, | 4208 EncryptionLevel, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4241 | 4284 |
4242 // Cancel alarm, and try again with BLOCKED frame. | 4285 // Cancel alarm, and try again with BLOCKED frame. |
4243 ack_alarm->Cancel(); | 4286 ack_alarm->Cancel(); |
4244 QuicBlockedFrame blocked; | 4287 QuicBlockedFrame blocked; |
4245 blocked.stream_id = 3; | 4288 blocked.stream_id = 3; |
4246 EXPECT_CALL(visitor_, OnBlockedFrames(_)); | 4289 EXPECT_CALL(visitor_, OnBlockedFrames(_)); |
4247 ProcessFramePacket(QuicFrame(&blocked)); | 4290 ProcessFramePacket(QuicFrame(&blocked)); |
4248 EXPECT_TRUE(ack_alarm->IsSet()); | 4291 EXPECT_TRUE(ack_alarm->IsSet()); |
4249 } | 4292 } |
4250 | 4293 |
| 4294 TEST_P(QuicConnectionTest, NoDataNoFin) { |
| 4295 ValueRestore<bool> old_flag(&FLAGS_quic_empty_data_no_fin_early_return, true); |
| 4296 // Make sure that a call to SendStreamWithData, with no data and no FIN, does |
| 4297 // not result in a QuicAckNotifier being used-after-free (fail under ASAN). |
| 4298 // Regression test for b/18594622 |
| 4299 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
| 4300 EXPECT_DFATAL( |
| 4301 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), |
| 4302 "Attempt to send empty stream frame"); |
| 4303 } |
| 4304 |
4251 } // namespace | 4305 } // namespace |
4252 } // namespace test | 4306 } // namespace test |
4253 } // namespace net | 4307 } // namespace net |
OLD | NEW |