Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(556)

Side by Side Diff: net/quic/quic_connection_test.cc

Issue 126283002: Land Recent QUIC Changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: removed extra space Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_connection_logger.h ('k') | net/quic/quic_crypto_client_stream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 DISALLOW_COPY_AND_ASSIGN(TestReceiveAlgorithm); 85 DISALLOW_COPY_AND_ASSIGN(TestReceiveAlgorithm);
86 }; 86 };
87 87
88 // TaggingEncrypter appends kTagSize bytes of |tag| to the end of each message. 88 // TaggingEncrypter appends kTagSize bytes of |tag| to the end of each message.
89 class TaggingEncrypter : public QuicEncrypter { 89 class TaggingEncrypter : public QuicEncrypter {
90 public: 90 public:
91 explicit TaggingEncrypter(uint8 tag) 91 explicit TaggingEncrypter(uint8 tag)
92 : tag_(tag) { 92 : tag_(tag) {
93 } 93 }
94 94
95 virtual ~TaggingEncrypter() {} 95 virtual ~TaggingEncrypter() OVERRIDE {}
96 96
97 // QuicEncrypter interface. 97 // QuicEncrypter interface.
98 virtual bool SetKey(StringPiece key) OVERRIDE { return true; } 98 virtual bool SetKey(StringPiece key) OVERRIDE { return true; }
99 virtual bool SetNoncePrefix(StringPiece nonce_prefix) OVERRIDE { 99 virtual bool SetNoncePrefix(StringPiece nonce_prefix) OVERRIDE {
100 return true; 100 return true;
101 } 101 }
102 102
103 virtual bool Encrypt(StringPiece nonce, 103 virtual bool Encrypt(StringPiece nonce,
104 StringPiece associated_data, 104 StringPiece associated_data,
105 StringPiece plaintext, 105 StringPiece plaintext,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 kTagSize = 12, 143 kTagSize = 12,
144 }; 144 };
145 145
146 const uint8 tag_; 146 const uint8 tag_;
147 }; 147 };
148 148
149 // TaggingDecrypter ensures that the final kTagSize bytes of the message all 149 // TaggingDecrypter ensures that the final kTagSize bytes of the message all
150 // have the same value and then removes them. 150 // have the same value and then removes them.
151 class TaggingDecrypter : public QuicDecrypter { 151 class TaggingDecrypter : public QuicDecrypter {
152 public: 152 public:
153 virtual ~TaggingDecrypter() {} 153 virtual ~TaggingDecrypter() OVERRIDE {}
154 154
155 // QuicDecrypter interface 155 // QuicDecrypter interface
156 virtual bool SetKey(StringPiece key) OVERRIDE { return true; } 156 virtual bool SetKey(StringPiece key) OVERRIDE { return true; }
157 virtual bool SetNoncePrefix(StringPiece nonce_prefix) OVERRIDE { 157 virtual bool SetNoncePrefix(StringPiece nonce_prefix) OVERRIDE {
158 return true; 158 return true;
159 } 159 }
160 160
161 virtual bool Decrypt(StringPiece nonce, 161 virtual bool Decrypt(StringPiece nonce,
162 StringPiece associated_data, 162 StringPiece associated_data,
163 StringPiece ciphertext, 163 StringPiece ciphertext,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 212
213 return true; 213 return true;
214 } 214 }
215 }; 215 };
216 216
217 // StringTaggingDecrypter ensures that the final kTagSize bytes of the message 217 // StringTaggingDecrypter ensures that the final kTagSize bytes of the message
218 // match the expected value. 218 // match the expected value.
219 class StrictTaggingDecrypter : public TaggingDecrypter { 219 class StrictTaggingDecrypter : public TaggingDecrypter {
220 public: 220 public:
221 explicit StrictTaggingDecrypter(uint8 tag) : tag_(tag) {} 221 explicit StrictTaggingDecrypter(uint8 tag) : tag_(tag) {}
222 virtual ~StrictTaggingDecrypter() {} 222 virtual ~StrictTaggingDecrypter() OVERRIDE {}
223 223
224 // TaggingQuicDecrypter 224 // TaggingQuicDecrypter
225 virtual uint8 GetTag(StringPiece ciphertext) OVERRIDE { 225 virtual uint8 GetTag(StringPiece ciphertext) OVERRIDE {
226 return tag_; 226 return tag_;
227 } 227 }
228 228
229 private: 229 private:
230 const uint8 tag_; 230 const uint8 tag_;
231 }; 231 };
232 232
(...skipping 1084 matching lines...) Expand 10 before | Expand all | Expand 10 after
1317 connection_.options()->max_packets_per_fec_group = 1; 1317 connection_.options()->max_packets_per_fec_group = 1;
1318 // 1 Data and 1 FEC packet. 1318 // 1 Data and 1 FEC packet.
1319 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); 1319 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
1320 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 1320 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
1321 1321
1322 const QuicTime::Delta retransmission_time = 1322 const QuicTime::Delta retransmission_time =
1323 QuicTime::Delta::FromMilliseconds(5000); 1323 QuicTime::Delta::FromMilliseconds(5000);
1324 clock_.AdvanceTime(retransmission_time); 1324 clock_.AdvanceTime(retransmission_time);
1325 1325
1326 // Abandon FEC packet and data packet. 1326 // Abandon FEC packet and data packet.
1327 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(2); 1327 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
1328 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout());
1329 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 1328 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
1330 EXPECT_CALL(visitor_, OnCanWrite()); 1329 EXPECT_CALL(visitor_, OnCanWrite());
1331 connection_.OnRetransmissionTimeout(); 1330 connection_.OnRetransmissionTimeout();
1332 } 1331 }
1333 1332
1334 TEST_F(QuicConnectionTest, DontAbandonAckedFEC) { 1333 TEST_F(QuicConnectionTest, DontAbandonAckedFEC) {
1335 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1334 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1336 connection_.options()->max_packets_per_fec_group = 1; 1335 connection_.options()->max_packets_per_fec_group = 1;
1337 1336
1338 // 1 Data and 1 FEC packet. 1337 // 1 Data and 1 FEC packet.
1339 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); 1338 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6);
1340 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 1339 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
1341 // Send some more data afterwards to ensure early retransmit doesn't trigger. 1340 // Send some more data afterwards to ensure early retransmit doesn't trigger.
1342 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); 1341 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL);
1343 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL); 1342 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL);
1344 1343
1345 QuicAckFrame ack_fec = InitAckFrame(2, 1); 1344 QuicAckFrame ack_fec = InitAckFrame(2, 1);
1346 // Data packet missing. 1345 // Data packet missing.
1347 // TODO(ianswett): Note that this is not a sensible ack, since if the FEC was 1346 // TODO(ianswett): Note that this is not a sensible ack, since if the FEC was
1348 // received, it would cause the covered packet to be acked as well. 1347 // received, it would cause the covered packet to be acked as well.
1349 NackPacket(1, &ack_fec); 1348 NackPacket(1, &ack_fec);
1350 1349
1351 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(1); 1350 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(1);
1352 ProcessAckPacket(&ack_fec); 1351 ProcessAckPacket(&ack_fec);
1353 clock_.AdvanceTime(DefaultRetransmissionTime()); 1352 clock_.AdvanceTime(DefaultRetransmissionTime());
1354 1353
1355 // Don't abandon the acked FEC packet, but it will abandon 2 the subsequent 1354 // Don't abandon the acked FEC packet, but it will abandon 2 the subsequent
1356 // FEC packets. 1355 // FEC packets.
1357 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(5); 1356 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
1358 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout());
1359 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); 1357 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3);
1360 connection_.GetRetransmissionAlarm()->Fire(); 1358 connection_.GetRetransmissionAlarm()->Fire();
1361 } 1359 }
1362 1360
1363 TEST_F(QuicConnectionTest, DontAbandonAllFEC) { 1361 TEST_F(QuicConnectionTest, AbandonAllFEC) {
1364 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1362 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1365 connection_.options()->max_packets_per_fec_group = 1; 1363 connection_.options()->max_packets_per_fec_group = 1;
1366 1364
1367 // 1 Data and 1 FEC packet. 1365 // 1 Data and 1 FEC packet.
1368 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); 1366 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6);
1369 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 1367 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
1370 // Send some more data afterwards to ensure early retransmit doesn't trigger. 1368 // Send some more data afterwards to ensure early retransmit doesn't trigger.
1371 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); 1369 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL);
1372 // Advance the time so not all the FEC packets are abandoned. 1370 // Advance the time so not all the FEC packets are abandoned.
1373 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); 1371 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1));
1374 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL); 1372 connection_.SendStreamDataWithString(3, "foo", 6, !kFin, NULL);
1375 1373
1376 QuicAckFrame ack_fec = InitAckFrame(5, 1); 1374 QuicAckFrame ack_fec = InitAckFrame(5, 1);
1377 // Ack all data packets, but no fec packets. 1375 // Ack all data packets, but no fec packets.
1378 NackPacket(2, &ack_fec); 1376 NackPacket(2, &ack_fec);
1379 NackPacket(4, &ack_fec); 1377 NackPacket(4, &ack_fec);
1380 1378
1381 // Lose the first FEC packet and ack the three data packets. 1379 // Lose the first FEC packet and ack the three data packets.
1382 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(3); 1380 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _, _)).Times(3);
1383 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _)); 1381 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _));
1384 EXPECT_CALL(*send_algorithm_, OnPacketLost(2, _)); 1382 EXPECT_CALL(*send_algorithm_, OnPacketLost(2, _));
1385 ProcessAckPacket(&ack_fec); 1383 ProcessAckPacket(&ack_fec);
1386 1384
1387 clock_.AdvanceTime(DefaultRetransmissionTime().Subtract( 1385 clock_.AdvanceTime(DefaultRetransmissionTime().Subtract(
1388 QuicTime::Delta::FromMilliseconds(1))); 1386 QuicTime::Delta::FromMilliseconds(1)));
1389 1387
1390 // Don't abandon the acked FEC packet, but it will abandon 1 of the subsequent 1388 // Abandon all packets
1391 // FEC packets. 1389 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(false));
1392 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(4, _));
1393 connection_.GetRetransmissionAlarm()->Fire(); 1390 connection_.GetRetransmissionAlarm()->Fire();
1394 1391
1395 // Ensure the connection's alarm is still set, in order to abandon the third 1392 // Ensure the alarm is not set since all packets have been abandoned.
1396 // FEC packet. 1393 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
1397 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
1398 } 1394 }
1399 1395
1400 TEST_F(QuicConnectionTest, FramePacking) { 1396 TEST_F(QuicConnectionTest, FramePacking) {
1401 // Block the connection. 1397 // Block the connection.
1402 connection_.GetSendAlarm()->Set( 1398 connection_.GetSendAlarm()->Set(
1403 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1))); 1399 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1)));
1404 1400
1405 // Send an ack and two stream frames in 1 packet by queueing them. 1401 // Send an ack and two stream frames in 1 packet by queueing them.
1406 connection_.SendAck(); 1402 connection_.SendAck();
1407 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 1403 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1740 TEST_F(QuicConnectionTest, QueueAfterTwoRTOs) { 1736 TEST_F(QuicConnectionTest, QueueAfterTwoRTOs) {
1741 for (int i = 0; i < 10; ++i) { 1737 for (int i = 0; i < 10; ++i) {
1742 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 1738 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
1743 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, NULL); 1739 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, NULL);
1744 } 1740 }
1745 1741
1746 // Block the congestion window and ensure they're queued. 1742 // Block the congestion window and ensure they're queued.
1747 writer_->set_blocked(true); 1743 writer_->set_blocked(true);
1748 clock_.AdvanceTime(DefaultRetransmissionTime()); 1744 clock_.AdvanceTime(DefaultRetransmissionTime());
1749 // Only one packet should be retransmitted. 1745 // Only one packet should be retransmitted.
1750 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout()); 1746 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
1751 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(10);
1752 connection_.GetRetransmissionAlarm()->Fire(); 1747 connection_.GetRetransmissionAlarm()->Fire();
1753 EXPECT_TRUE(connection_.HasQueuedData()); 1748 EXPECT_TRUE(connection_.HasQueuedData());
1754 1749
1755 // Unblock the congestion window. 1750 // Unblock the congestion window.
1756 writer_->set_blocked(false); 1751 writer_->set_blocked(false);
1757 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( 1752 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(
1758 2 * DefaultRetransmissionTime().ToMicroseconds())); 1753 2 * DefaultRetransmissionTime().ToMicroseconds()));
1759 // Retransmit already retransmitted packets event though the sequence number 1754 // Retransmit already retransmitted packets event though the sequence number
1760 // greater than the largest observed. 1755 // greater than the largest observed.
1761 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10); 1756 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1934 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( 1929 QuicTime default_retransmission_time = clock_.ApproximateNow().Add(
1935 DefaultRetransmissionTime()); 1930 DefaultRetransmissionTime());
1936 SendStreamDataToPeer(3, "foo", 0, !kFin, NULL); 1931 SendStreamDataToPeer(3, "foo", 0, !kFin, NULL);
1937 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); 1932 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked);
1938 1933
1939 EXPECT_EQ(1u, last_header()->packet_sequence_number); 1934 EXPECT_EQ(1u, last_header()->packet_sequence_number);
1940 EXPECT_EQ(default_retransmission_time, 1935 EXPECT_EQ(default_retransmission_time,
1941 connection_.GetRetransmissionAlarm()->deadline()); 1936 connection_.GetRetransmissionAlarm()->deadline());
1942 // Simulate the retransmission alarm firing. 1937 // Simulate the retransmission alarm firing.
1943 clock_.AdvanceTime(DefaultRetransmissionTime()); 1938 clock_.AdvanceTime(DefaultRetransmissionTime());
1944 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout()); 1939 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
1945 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1u, _));
1946 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 2u, _, _, _)); 1940 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 2u, _, _, _));
1947 connection_.GetRetransmissionAlarm()->Fire(); 1941 connection_.GetRetransmissionAlarm()->Fire();
1948 EXPECT_EQ(2u, last_header()->packet_sequence_number); 1942 EXPECT_EQ(2u, last_header()->packet_sequence_number);
1949 // We do not raise the high water mark yet. 1943 // We do not raise the high water mark yet.
1950 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); 1944 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked);
1951 } 1945 }
1952 1946
1953 TEST_F(QuicConnectionTest, RTOWithSameEncryptionLevel) { 1947 TEST_F(QuicConnectionTest, RTOWithSameEncryptionLevel) {
1954 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( 1948 QuicTime default_retransmission_time = clock_.ApproximateNow().Add(
1955 DefaultRetransmissionTime()); 1949 DefaultRetransmissionTime());
1956 use_tagging_decrypter(); 1950 use_tagging_decrypter();
1957 1951
1958 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at 1952 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at
1959 // the end of the packet. We can test this to check which encrypter was used. 1953 // the end of the packet. We can test this to check which encrypter was used.
1960 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 1954 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
1961 SendStreamDataToPeer(3, "foo", 0, !kFin, NULL); 1955 SendStreamDataToPeer(3, "foo", 0, !kFin, NULL);
1962 EXPECT_EQ(0x01010101u, final_bytes_of_last_packet()); 1956 EXPECT_EQ(0x01010101u, final_bytes_of_last_packet());
1963 1957
1964 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); 1958 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
1965 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 1959 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
1966 SendStreamDataToPeer(3, "foo", 0, !kFin, NULL); 1960 SendStreamDataToPeer(3, "foo", 0, !kFin, NULL);
1967 EXPECT_EQ(0x02020202u, final_bytes_of_last_packet()); 1961 EXPECT_EQ(0x02020202u, final_bytes_of_last_packet());
1968 1962
1969 EXPECT_EQ(default_retransmission_time, 1963 EXPECT_EQ(default_retransmission_time,
1970 connection_.GetRetransmissionAlarm()->deadline()); 1964 connection_.GetRetransmissionAlarm()->deadline());
1971 { 1965 {
1972 InSequence s; 1966 InSequence s;
1973 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)); 1967 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
1974 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _));
1975 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout());
1976 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 3, _, RTO_RETRANSMISSION, _)); 1968 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 3, _, RTO_RETRANSMISSION, _));
1977 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 4, _, RTO_RETRANSMISSION, _)); 1969 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 4, _, RTO_RETRANSMISSION, _));
1978 } 1970 }
1979 1971
1980 // Simulate the retransmission alarm firing. 1972 // Simulate the retransmission alarm firing.
1981 clock_.AdvanceTime(DefaultRetransmissionTime()); 1973 clock_.AdvanceTime(DefaultRetransmissionTime());
1982 connection_.GetRetransmissionAlarm()->Fire(); 1974 connection_.GetRetransmissionAlarm()->Fire();
1983 1975
1984 // Packet should have been sent with ENCRYPTION_NONE. 1976 // Packet should have been sent with ENCRYPTION_NONE.
1985 EXPECT_EQ(0x01010101u, final_bytes_of_previous_packet()); 1977 EXPECT_EQ(0x01010101u, final_bytes_of_previous_packet());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2023 DropRetransmitsForNullEncryptedPacketAfterForwardSecure) { 2015 DropRetransmitsForNullEncryptedPacketAfterForwardSecure) {
2024 use_tagging_decrypter(); 2016 use_tagging_decrypter();
2025 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 2017 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
2026 QuicPacketSequenceNumber sequence_number; 2018 QuicPacketSequenceNumber sequence_number;
2027 SendStreamDataToPeer(3, "foo", 0, !kFin, &sequence_number); 2019 SendStreamDataToPeer(3, "foo", 0, !kFin, &sequence_number);
2028 2020
2029 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, 2021 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE,
2030 new TaggingEncrypter(0x02)); 2022 new TaggingEncrypter(0x02));
2031 connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); 2023 connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE);
2032 2024
2033 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout()); 2025 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2034 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); 2026 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0);
2035 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(sequence_number, _)).Times(1);
2036 2027
2037 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( 2028 QuicTime default_retransmission_time = clock_.ApproximateNow().Add(
2038 DefaultRetransmissionTime()); 2029 DefaultRetransmissionTime());
2039 2030
2040 EXPECT_EQ(default_retransmission_time, 2031 EXPECT_EQ(default_retransmission_time,
2041 connection_.GetRetransmissionAlarm()->deadline()); 2032 connection_.GetRetransmissionAlarm()->deadline());
2042 // Simulate the retransmission alarm firing. 2033 // Simulate the retransmission alarm firing.
2043 clock_.AdvanceTime(DefaultRetransmissionTime()); 2034 clock_.AdvanceTime(DefaultRetransmissionTime());
2044 connection_.GetRetransmissionAlarm()->Fire(); 2035 connection_.GetRetransmissionAlarm()->Fire();
2045 } 2036 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2095 DoAll(SaveArg<2>(&first_packet_size), Return(true))); 2086 DoAll(SaveArg<2>(&first_packet_size), Return(true)));
2096 2087
2097 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, NULL); 2088 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, NULL);
2098 QuicByteCount second_packet_size; 2089 QuicByteCount second_packet_size;
2099 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce( 2090 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce(
2100 DoAll(SaveArg<2>(&second_packet_size), Return(true))); 2091 DoAll(SaveArg<2>(&second_packet_size), Return(true)));
2101 connection_.SendStreamDataWithString(3, "second_packet", 12, !kFin, NULL); 2092 connection_.SendStreamDataWithString(3, "second_packet", 12, !kFin, NULL);
2102 EXPECT_NE(first_packet_size, second_packet_size); 2093 EXPECT_NE(first_packet_size, second_packet_size);
2103 // Advance the clock by huge time to make sure packets will be retransmitted. 2094 // Advance the clock by huge time to make sure packets will be retransmitted.
2104 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); 2095 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10));
2105 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout()); 2096 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2106 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(2);
2107 { 2097 {
2108 InSequence s; 2098 InSequence s;
2109 EXPECT_CALL(*send_algorithm_, 2099 EXPECT_CALL(*send_algorithm_,
2110 OnPacketSent(_, _, first_packet_size, _, _)); 2100 OnPacketSent(_, _, first_packet_size, _, _));
2111 EXPECT_CALL(*send_algorithm_, 2101 EXPECT_CALL(*send_algorithm_,
2112 OnPacketSent(_, _, second_packet_size, _, _)); 2102 OnPacketSent(_, _, second_packet_size, _, _));
2113 } 2103 }
2114 connection_.GetRetransmissionAlarm()->Fire(); 2104 connection_.GetRetransmissionAlarm()->Fire();
2115 2105
2116 // Advance again and expect the packets to be sent again in the same order. 2106 // Advance again and expect the packets to be sent again in the same order.
2117 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(20)); 2107 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(20));
2118 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout()); 2108 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2119 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(2);
2120 { 2109 {
2121 InSequence s; 2110 InSequence s;
2122 EXPECT_CALL(*send_algorithm_, 2111 EXPECT_CALL(*send_algorithm_,
2123 OnPacketSent(_, _, first_packet_size, _, _)); 2112 OnPacketSent(_, _, first_packet_size, _, _));
2124 EXPECT_CALL(*send_algorithm_, 2113 EXPECT_CALL(*send_algorithm_,
2125 OnPacketSent(_, _, second_packet_size, _, _)); 2114 OnPacketSent(_, _, second_packet_size, _, _));
2126 } 2115 }
2127 connection_.GetRetransmissionAlarm()->Fire(); 2116 connection_.GetRetransmissionAlarm()->Fire();
2128 } 2117 }
2129 2118
2130 TEST_F(QuicConnectionTest, RetransmissionCountCalculation) { 2119 TEST_F(QuicConnectionTest, RetransmissionCountCalculation) {
2131 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2120 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2132 QuicPacketSequenceNumber original_sequence_number; 2121 QuicPacketSequenceNumber original_sequence_number;
2133 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)) 2122 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, NOT_RETRANSMISSION, _))
2134 .WillOnce(DoAll(SaveArg<1>(&original_sequence_number), Return(true))); 2123 .WillOnce(DoAll(SaveArg<1>(&original_sequence_number), Return(true)));
2135 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 2124 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
2136 2125
2137 EXPECT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( 2126 EXPECT_TRUE(QuicConnectionPeer::IsSavedForRetransmission(
2138 &connection_, original_sequence_number)); 2127 &connection_, original_sequence_number));
2139 EXPECT_FALSE(QuicConnectionPeer::IsRetransmission( 2128 EXPECT_FALSE(QuicConnectionPeer::IsRetransmission(
2140 &connection_, original_sequence_number)); 2129 &connection_, original_sequence_number));
2141 // Force retransmission due to RTO. 2130 // Force retransmission due to RTO.
2142 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); 2131 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10));
2143 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout()); 2132 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2144 EXPECT_CALL(*send_algorithm_,
2145 OnPacketAbandoned(original_sequence_number, _)).Times(1);
2146 QuicPacketSequenceNumber rto_sequence_number; 2133 QuicPacketSequenceNumber rto_sequence_number;
2147 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, RTO_RETRANSMISSION, _)) 2134 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, RTO_RETRANSMISSION, _))
2148 .WillOnce(DoAll(SaveArg<1>(&rto_sequence_number), Return(true))); 2135 .WillOnce(DoAll(SaveArg<1>(&rto_sequence_number), Return(true)));
2149 connection_.GetRetransmissionAlarm()->Fire(); 2136 connection_.GetRetransmissionAlarm()->Fire();
2150 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( 2137 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission(
2151 &connection_, original_sequence_number)); 2138 &connection_, original_sequence_number));
2152 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( 2139 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission(
2153 &connection_, rto_sequence_number)); 2140 &connection_, rto_sequence_number));
2154 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission( 2141 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission(
2155 &connection_, rto_sequence_number)); 2142 &connection_, rto_sequence_number));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2208 QuicAckFrame ack = InitAckFrame(1, 0); 2195 QuicAckFrame ack = InitAckFrame(1, 0);
2209 ProcessAckPacket(&ack); 2196 ProcessAckPacket(&ack);
2210 EXPECT_TRUE(retransmission_alarm->IsSet()); 2197 EXPECT_TRUE(retransmission_alarm->IsSet());
2211 2198
2212 // Move forward past the original RTO and ensure the RTO is still pending. 2199 // Move forward past the original RTO and ensure the RTO is still pending.
2213 clock_.AdvanceTime(DefaultRetransmissionTime()); 2200 clock_.AdvanceTime(DefaultRetransmissionTime());
2214 2201
2215 // Ensure the second packet gets retransmitted when it finally fires. 2202 // Ensure the second packet gets retransmitted when it finally fires.
2216 EXPECT_TRUE(retransmission_alarm->IsSet()); 2203 EXPECT_TRUE(retransmission_alarm->IsSet());
2217 EXPECT_LT(retransmission_alarm->deadline(), clock_.ApproximateNow()); 2204 EXPECT_LT(retransmission_alarm->deadline(), clock_.ApproximateNow());
2218 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout()); 2205 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2219 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, RTO_RETRANSMISSION, _)); 2206 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, RTO_RETRANSMISSION, _));
2220 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _));
2221 // Manually cancel the alarm to simulate a real test. 2207 // Manually cancel the alarm to simulate a real test.
2222 connection_.GetRetransmissionAlarm()->Fire(); 2208 connection_.GetRetransmissionAlarm()->Fire();
2223 2209
2224 // The new retransmitted sequence number should set the RTO to a larger value 2210 // The new retransmitted sequence number should set the RTO to a larger value
2225 // than previously. 2211 // than previously.
2226 EXPECT_TRUE(retransmission_alarm->IsSet()); 2212 EXPECT_TRUE(retransmission_alarm->IsSet());
2227 QuicTime next_rto_time = retransmission_alarm->deadline(); 2213 QuicTime next_rto_time = retransmission_alarm->deadline();
2228 QuicTime expected_rto_time = 2214 QuicTime expected_rto_time =
2229 connection_.sent_packet_manager().GetRetransmissionTime(); 2215 connection_.sent_packet_manager().GetRetransmissionTime();
2230 EXPECT_EQ(next_rto_time, expected_rto_time); 2216 EXPECT_EQ(next_rto_time, expected_rto_time);
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
2419 testing::Return(QuicTime::Delta::Zero())); 2405 testing::Return(QuicTime::Delta::Zero()));
2420 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); 2406 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1));
2421 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 2407 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
2422 connection_.GetSendAlarm()->Fire(); 2408 connection_.GetSendAlarm()->Fire();
2423 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2409 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2424 } 2410 }
2425 2411
2426 TEST_F(QuicConnectionTest, SendSchedulerDelayThenRetransmit) { 2412 TEST_F(QuicConnectionTest, SendSchedulerDelayThenRetransmit) {
2427 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _, _)) 2413 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, NOT_RETRANSMISSION, _, _))
2428 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); 2414 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero()));
2429 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)).Times(1);
2430 EXPECT_CALL(*send_algorithm_, 2415 EXPECT_CALL(*send_algorithm_,
2431 OnPacketSent(_, 1, _, NOT_RETRANSMISSION, _)); 2416 OnPacketSent(_, 1, _, NOT_RETRANSMISSION, _));
2432 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 2417 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
2433 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2418 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2434 // Advance the time for retransmission of lost packet. 2419 // Advance the time for retransmission of lost packet.
2435 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(501)); 2420 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(501));
2436 // Test that if we send a retransmit with a delay, it ends up queued in the 2421 // Test that if we send a retransmit with a delay, it ends up queued in the
2437 // sent packet manager, but not yet serialized. 2422 // sent packet manager, but not yet serialized.
2438 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout()); 2423 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2439 EXPECT_CALL(*send_algorithm_, 2424 EXPECT_CALL(*send_algorithm_,
2440 TimeUntilSend(_, RTO_RETRANSMISSION, _, _)).WillOnce( 2425 TimeUntilSend(_, RTO_RETRANSMISSION, _, _)).WillOnce(
2441 testing::Return(QuicTime::Delta::FromMicroseconds(1))); 2426 testing::Return(QuicTime::Delta::FromMicroseconds(1)));
2442 connection_.GetRetransmissionAlarm()->Fire(); 2427 connection_.GetRetransmissionAlarm()->Fire();
2443 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2428 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2444 2429
2445 // Advance the clock to fire the alarm, and configure the scheduler 2430 // Advance the clock to fire the alarm, and configure the scheduler
2446 // to permit the packet to be sent. 2431 // to permit the packet to be sent.
2447 EXPECT_CALL(*send_algorithm_, 2432 EXPECT_CALL(*send_algorithm_,
2448 TimeUntilSend(_, RTO_RETRANSMISSION, _, _)).Times(2). 2433 TimeUntilSend(_, RTO_RETRANSMISSION, _, _)).Times(2).
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
2994 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); 2979 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _));
2995 connection_.SendStreamDataWithString(3, "first", 0, !kFin, NULL); 2980 connection_.SendStreamDataWithString(3, "first", 0, !kFin, NULL);
2996 size_t first_packet_size = last_sent_packet_size(); 2981 size_t first_packet_size = last_sent_packet_size();
2997 2982
2998 EXPECT_CALL(*send_algorithm_, 2983 EXPECT_CALL(*send_algorithm_,
2999 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _)); 2984 OnPacketSent(_, _, _, NOT_RETRANSMISSION, _));
3000 connection_.SendStreamDataWithString(5, "second", 0, !kFin, NULL); 2985 connection_.SendStreamDataWithString(5, "second", 0, !kFin, NULL);
3001 size_t second_packet_size = last_sent_packet_size(); 2986 size_t second_packet_size = last_sent_packet_size();
3002 2987
3003 // 2 retransmissions due to rto, 1 due to explicit nack. 2988 // 2 retransmissions due to rto, 1 due to explicit nack.
3004 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout()); 2989 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
3005 EXPECT_CALL(*send_algorithm_, 2990 EXPECT_CALL(*send_algorithm_,
3006 OnPacketSent(_, _, _, RTO_RETRANSMISSION, _)).Times(2); 2991 OnPacketSent(_, _, _, RTO_RETRANSMISSION, _)).Times(2);
3007 EXPECT_CALL(*send_algorithm_, 2992 EXPECT_CALL(*send_algorithm_,
3008 OnPacketSent(_, _, _, NACK_RETRANSMISSION, _)); 2993 OnPacketSent(_, _, _, NACK_RETRANSMISSION, _));
3009 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(3); 2994 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(1);
3010 EXPECT_CALL(visitor_, OnCanWrite()).WillRepeatedly(Return(true)); 2995 EXPECT_CALL(visitor_, OnCanWrite()).WillRepeatedly(Return(true));
3011 2996
3012 // Retransmit due to RTO. 2997 // Retransmit due to RTO.
3013 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); 2998 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10));
3014 connection_.GetRetransmissionAlarm()->Fire(); 2999 connection_.GetRetransmissionAlarm()->Fire();
3015 3000
3016 // Retransmit due to explicit nacks. 3001 // Retransmit due to explicit nacks.
3017 QuicAckFrame nack_three = InitAckFrame(4, 0); 3002 QuicAckFrame nack_three = InitAckFrame(4, 0);
3018 NackPacket(3, &nack_three); 3003 NackPacket(3, &nack_three);
3019 NackPacket(1, &nack_three); 3004 NackPacket(1, &nack_three);
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
3370 true); 3355 true);
3371 TestConnection client(guid_, IPEndPoint(), helper_.get(), writer_.get(), 3356 TestConnection client(guid_, IPEndPoint(), helper_.get(), writer_.get(),
3372 false); 3357 false);
3373 EXPECT_TRUE(client.sent_packet_manager().using_pacing()); 3358 EXPECT_TRUE(client.sent_packet_manager().using_pacing());
3374 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); 3359 EXPECT_FALSE(server.sent_packet_manager().using_pacing());
3375 } 3360 }
3376 3361
3377 } // namespace 3362 } // namespace
3378 } // namespace test 3363 } // namespace test
3379 } // namespace net 3364 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection_logger.h ('k') | net/quic/quic_crypto_client_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698