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 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 | 570 |
571 private: | 571 private: |
572 QuicPacketHeader revived_header_; | 572 QuicPacketHeader revived_header_; |
573 }; | 573 }; |
574 | 574 |
575 class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { | 575 class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { |
576 protected: | 576 protected: |
577 QuicConnectionTest() | 577 QuicConnectionTest() |
578 : connection_id_(42), | 578 : connection_id_(42), |
579 framer_(SupportedVersions(version()), QuicTime::Zero(), false), | 579 framer_(SupportedVersions(version()), QuicTime::Zero(), false), |
580 creator_(connection_id_, &framer_, &random_generator_, false), | 580 peer_creator_(connection_id_, &framer_, &random_generator_, false), |
581 send_algorithm_(new StrictMock<MockSendAlgorithm>), | 581 send_algorithm_(new StrictMock<MockSendAlgorithm>), |
582 loss_algorithm_(new MockLossAlgorithm()), | 582 loss_algorithm_(new MockLossAlgorithm()), |
583 helper_(new TestConnectionHelper(&clock_, &random_generator_)), | 583 helper_(new TestConnectionHelper(&clock_, &random_generator_)), |
584 writer_(new TestPacketWriter(version())), | 584 writer_(new TestPacketWriter(version())), |
585 connection_(connection_id_, IPEndPoint(), helper_.get(), | 585 connection_(connection_id_, IPEndPoint(), helper_.get(), |
586 writer_.get(), false, version()), | 586 writer_.get(), false, version()), |
587 frame1_(1, false, 0, MakeIOVector(data1)), | 587 frame1_(1, false, 0, MakeIOVector(data1)), |
588 frame2_(1, false, 3, MakeIOVector(data2)), | 588 frame2_(1, false, 3, MakeIOVector(data2)), |
589 sequence_number_length_(PACKET_6BYTE_SEQUENCE_NUMBER), | 589 sequence_number_length_(PACKET_6BYTE_SEQUENCE_NUMBER), |
590 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { | 590 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 } | 645 } |
646 | 646 |
647 void ProcessPacket(QuicPacketSequenceNumber number) { | 647 void ProcessPacket(QuicPacketSequenceNumber number) { |
648 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); | 648 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); |
649 ProcessDataPacket(number, 0, !kEntropyFlag); | 649 ProcessDataPacket(number, 0, !kEntropyFlag); |
650 } | 650 } |
651 | 651 |
652 QuicPacketEntropyHash ProcessFramePacket(QuicFrame frame) { | 652 QuicPacketEntropyHash ProcessFramePacket(QuicFrame frame) { |
653 QuicFrames frames; | 653 QuicFrames frames; |
654 frames.push_back(QuicFrame(frame)); | 654 frames.push_back(QuicFrame(frame)); |
655 QuicPacketCreatorPeer::SetSendVersionInPacket(&creator_, | 655 QuicPacketCreatorPeer::SetSendVersionInPacket(&peer_creator_, |
656 connection_.is_server()); | 656 connection_.is_server()); |
657 SerializedPacket serialized_packet = creator_.SerializeAllFrames(frames); | 657 SerializedPacket serialized_packet = |
| 658 peer_creator_.SerializeAllFrames(frames); |
658 scoped_ptr<QuicPacket> packet(serialized_packet.packet); | 659 scoped_ptr<QuicPacket> packet(serialized_packet.packet); |
659 scoped_ptr<QuicEncryptedPacket> encrypted( | 660 scoped_ptr<QuicEncryptedPacket> encrypted( |
660 framer_.EncryptPacket(ENCRYPTION_NONE, | 661 framer_.EncryptPacket(ENCRYPTION_NONE, |
661 serialized_packet.sequence_number, *packet)); | 662 serialized_packet.sequence_number, *packet)); |
662 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 663 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
663 return serialized_packet.entropy_hash; | 664 return serialized_packet.entropy_hash; |
664 } | 665 } |
665 | 666 |
666 size_t ProcessDataPacket(QuicPacketSequenceNumber number, | 667 size_t ProcessDataPacket(QuicPacketSequenceNumber number, |
667 QuicFecGroupNumber fec_group, | 668 QuicFecGroupNumber fec_group, |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 QuicConnectionPeer::GetConnectionClosePacket(&connection_) == NULL); | 909 QuicConnectionPeer::GetConnectionClosePacket(&connection_) == NULL); |
909 } | 910 } |
910 | 911 |
911 void BlockOnNextWrite() { | 912 void BlockOnNextWrite() { |
912 writer_->BlockOnNextWrite(); | 913 writer_->BlockOnNextWrite(); |
913 EXPECT_CALL(visitor_, OnWriteBlocked()).Times(AtLeast(1)); | 914 EXPECT_CALL(visitor_, OnWriteBlocked()).Times(AtLeast(1)); |
914 } | 915 } |
915 | 916 |
916 QuicConnectionId connection_id_; | 917 QuicConnectionId connection_id_; |
917 QuicFramer framer_; | 918 QuicFramer framer_; |
918 QuicPacketCreator creator_; | 919 QuicPacketCreator peer_creator_; |
919 MockEntropyCalculator entropy_calculator_; | 920 MockEntropyCalculator entropy_calculator_; |
920 | 921 |
921 MockSendAlgorithm* send_algorithm_; | 922 MockSendAlgorithm* send_algorithm_; |
922 MockLossAlgorithm* loss_algorithm_; | 923 MockLossAlgorithm* loss_algorithm_; |
923 TestReceiveAlgorithm* receive_algorithm_; | 924 TestReceiveAlgorithm* receive_algorithm_; |
924 MockClock clock_; | 925 MockClock clock_; |
925 MockRandom random_generator_; | 926 MockRandom random_generator_; |
926 scoped_ptr<TestConnectionHelper> helper_; | 927 scoped_ptr<TestConnectionHelper> helper_; |
927 scoped_ptr<TestPacketWriter> writer_; | 928 scoped_ptr<TestPacketWriter> writer_; |
928 TestConnection connection_; | 929 TestConnection connection_; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 | 1010 |
1010 ProcessPacket(5); | 1011 ProcessPacket(5); |
1011 EXPECT_EQ(5u, outgoing_ack()->received_info.largest_observed); | 1012 EXPECT_EQ(5u, outgoing_ack()->received_info.largest_observed); |
1012 EXPECT_TRUE(IsMissing(1)); | 1013 EXPECT_TRUE(IsMissing(1)); |
1013 EXPECT_TRUE(IsMissing(4)); | 1014 EXPECT_TRUE(IsMissing(4)); |
1014 | 1015 |
1015 // Pretend at this point the client has gotten acks for 2 and 3 and 1 is a | 1016 // Pretend at this point the client has gotten acks for 2 and 3 and 1 is a |
1016 // packet the peer will not retransmit. It indicates this by sending 'least | 1017 // packet the peer will not retransmit. It indicates this by sending 'least |
1017 // awaiting' is 4. The connection should then realize 1 will not be | 1018 // awaiting' is 4. The connection should then realize 1 will not be |
1018 // retransmitted, and will remove it from the missing list. | 1019 // retransmitted, and will remove it from the missing list. |
1019 creator_.set_sequence_number(5); | 1020 peer_creator_.set_sequence_number(5); |
1020 QuicAckFrame frame = InitAckFrame(1, 4); | 1021 QuicAckFrame frame = InitAckFrame(1, 4); |
1021 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(_, _, _, _)); | 1022 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(_, _, _, _)); |
1022 ProcessAckPacket(&frame); | 1023 ProcessAckPacket(&frame); |
1023 | 1024 |
1024 // Force an ack to be sent. | 1025 // Force an ack to be sent. |
1025 SendAckPacketToPeer(); | 1026 SendAckPacketToPeer(); |
1026 EXPECT_TRUE(IsMissing(4)); | 1027 EXPECT_TRUE(IsMissing(4)); |
1027 } | 1028 } |
1028 | 1029 |
1029 TEST_P(QuicConnectionTest, RejectPacketTooFarOut) { | 1030 TEST_P(QuicConnectionTest, RejectPacketTooFarOut) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 TimeUntilSend(_, _, _)).WillOnce( | 1103 TimeUntilSend(_, _, _)).WillOnce( |
1103 testing::Return(QuicTime::Delta::FromMicroseconds(1))); | 1104 testing::Return(QuicTime::Delta::FromMicroseconds(1))); |
1104 QuicConnectionPeer::SendAck(&connection_); | 1105 QuicConnectionPeer::SendAck(&connection_); |
1105 | 1106 |
1106 // Process an ack with a least unacked of the received ack. | 1107 // Process an ack with a least unacked of the received ack. |
1107 // This causes an ack to be sent when TimeUntilSend returns 0. | 1108 // This causes an ack to be sent when TimeUntilSend returns 0. |
1108 EXPECT_CALL(*send_algorithm_, | 1109 EXPECT_CALL(*send_algorithm_, |
1109 TimeUntilSend(_, _, _)).WillRepeatedly( | 1110 TimeUntilSend(_, _, _)).WillRepeatedly( |
1110 testing::Return(QuicTime::Delta::Zero())); | 1111 testing::Return(QuicTime::Delta::Zero())); |
1111 // Skip a packet and then record an ack. | 1112 // Skip a packet and then record an ack. |
1112 creator_.set_sequence_number(2); | 1113 peer_creator_.set_sequence_number(2); |
1113 QuicAckFrame frame = InitAckFrame(0, 3); | 1114 QuicAckFrame frame = InitAckFrame(0, 3); |
1114 ProcessAckPacket(&frame); | 1115 ProcessAckPacket(&frame); |
1115 } | 1116 } |
1116 | 1117 |
1117 TEST_P(QuicConnectionTest, OutOfOrderReceiptCausesAckSend) { | 1118 TEST_P(QuicConnectionTest, OutOfOrderReceiptCausesAckSend) { |
1118 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1119 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1119 | 1120 |
1120 ProcessPacket(3); | 1121 ProcessPacket(3); |
1121 // Should ack immediately since we have missing packets. | 1122 // Should ack immediately since we have missing packets. |
1122 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 1123 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 } | 1199 } |
1199 | 1200 |
1200 TEST_P(QuicConnectionTest, LeastUnackedLower) { | 1201 TEST_P(QuicConnectionTest, LeastUnackedLower) { |
1201 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1202 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1202 | 1203 |
1203 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); | 1204 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); |
1204 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL); | 1205 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL); |
1205 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL); | 1206 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL); |
1206 | 1207 |
1207 // Start out saying the least unacked is 2. | 1208 // Start out saying the least unacked is 2. |
1208 creator_.set_sequence_number(5); | 1209 peer_creator_.set_sequence_number(5); |
1209 if (version() > QUIC_VERSION_15) { | 1210 if (version() > QUIC_VERSION_15) { |
1210 QuicStopWaitingFrame frame = InitStopWaitingFrame(2); | 1211 QuicStopWaitingFrame frame = InitStopWaitingFrame(2); |
1211 ProcessStopWaitingPacket(&frame); | 1212 ProcessStopWaitingPacket(&frame); |
1212 } else { | 1213 } else { |
1213 QuicAckFrame frame = InitAckFrame(0, 2); | 1214 QuicAckFrame frame = InitAckFrame(0, 2); |
1214 ProcessAckPacket(&frame); | 1215 ProcessAckPacket(&frame); |
1215 } | 1216 } |
1216 | 1217 |
1217 // Change it to 1, but lower the sequence number to fake out-of-order packets. | 1218 // Change it to 1, but lower the sequence number to fake out-of-order packets. |
1218 // This should be fine. | 1219 // This should be fine. |
1219 creator_.set_sequence_number(1); | 1220 peer_creator_.set_sequence_number(1); |
1220 // The scheduler will not process out of order acks, but all packet processing | 1221 // The scheduler will not process out of order acks, but all packet processing |
1221 // causes the connection to try to write. | 1222 // causes the connection to try to write. |
1222 EXPECT_CALL(visitor_, OnCanWrite()); | 1223 EXPECT_CALL(visitor_, OnCanWrite()); |
1223 if (version() > QUIC_VERSION_15) { | 1224 if (version() > QUIC_VERSION_15) { |
1224 QuicStopWaitingFrame frame2 = InitStopWaitingFrame(1); | 1225 QuicStopWaitingFrame frame2 = InitStopWaitingFrame(1); |
1225 ProcessStopWaitingPacket(&frame2); | 1226 ProcessStopWaitingPacket(&frame2); |
1226 } else { | 1227 } else { |
1227 QuicAckFrame frame2 = InitAckFrame(0, 1); | 1228 QuicAckFrame frame2 = InitAckFrame(0, 1); |
1228 ProcessAckPacket(&frame2); | 1229 ProcessAckPacket(&frame2); |
1229 } | 1230 } |
1230 | 1231 |
1231 // Now claim it's one, but set the ordering so it was sent "after" the first | 1232 // Now claim it's one, but set the ordering so it was sent "after" the first |
1232 // one. This should cause a connection error. | 1233 // one. This should cause a connection error. |
1233 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 1234 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
1234 creator_.set_sequence_number(7); | 1235 peer_creator_.set_sequence_number(7); |
1235 if (version() > QUIC_VERSION_15) { | 1236 if (version() > QUIC_VERSION_15) { |
1236 EXPECT_CALL(visitor_, | 1237 EXPECT_CALL(visitor_, |
1237 OnConnectionClosed(QUIC_INVALID_STOP_WAITING_DATA, false)); | 1238 OnConnectionClosed(QUIC_INVALID_STOP_WAITING_DATA, false)); |
1238 QuicStopWaitingFrame frame2 = InitStopWaitingFrame(1); | 1239 QuicStopWaitingFrame frame2 = InitStopWaitingFrame(1); |
1239 ProcessStopWaitingPacket(&frame2); | 1240 ProcessStopWaitingPacket(&frame2); |
1240 } else { | 1241 } else { |
1241 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false)); | 1242 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_ACK_DATA, false)); |
1242 QuicAckFrame frame2 = InitAckFrame(0, 1); | 1243 QuicAckFrame frame2 = InitAckFrame(0, 1); |
1243 ProcessAckPacket(&frame2); | 1244 ProcessAckPacket(&frame2); |
1244 } | 1245 } |
(...skipping 25 matching lines...) Expand all Loading... |
1270 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 1271 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
1271 QuicAckFrame frame(MakeAckFrame(1, 0)); | 1272 QuicAckFrame frame(MakeAckFrame(1, 0)); |
1272 EXPECT_CALL(visitor_, OnCanWrite()).Times(0); | 1273 EXPECT_CALL(visitor_, OnCanWrite()).Times(0); |
1273 ProcessAckPacket(&frame); | 1274 ProcessAckPacket(&frame); |
1274 } | 1275 } |
1275 | 1276 |
1276 TEST_P(QuicConnectionTest, AckAll) { | 1277 TEST_P(QuicConnectionTest, AckAll) { |
1277 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1278 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1278 ProcessPacket(1); | 1279 ProcessPacket(1); |
1279 | 1280 |
1280 creator_.set_sequence_number(1); | 1281 peer_creator_.set_sequence_number(1); |
1281 QuicAckFrame frame1 = InitAckFrame(0, 1); | 1282 QuicAckFrame frame1 = InitAckFrame(0, 1); |
1282 ProcessAckPacket(&frame1); | 1283 ProcessAckPacket(&frame1); |
1283 } | 1284 } |
1284 | 1285 |
1285 TEST_P(QuicConnectionTest, SendingDifferentSequenceNumberLengthsBandwidth) { | 1286 TEST_P(QuicConnectionTest, SendingDifferentSequenceNumberLengthsBandwidth) { |
1286 QuicPacketSequenceNumber last_packet; | 1287 QuicPacketSequenceNumber last_packet; |
| 1288 QuicPacketCreator* creator = |
| 1289 QuicConnectionPeer::GetPacketCreator(&connection_); |
1287 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); | 1290 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); |
1288 EXPECT_EQ(1u, last_packet); | 1291 EXPECT_EQ(1u, last_packet); |
1289 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, | 1292 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, |
1290 connection_.options()->send_sequence_number_length); | 1293 creator->next_sequence_number_length()); |
1291 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, | 1294 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, |
1292 writer_->header().public_header.sequence_number_length); | 1295 writer_->header().public_header.sequence_number_length); |
1293 | 1296 |
1294 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( | 1297 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( |
1295 Return(kMaxPacketSize * 256)); | 1298 Return(kMaxPacketSize * 256)); |
1296 | 1299 |
1297 SendStreamDataToPeer(1, "bar", 3, !kFin, &last_packet); | 1300 SendStreamDataToPeer(1, "bar", 3, !kFin, &last_packet); |
1298 EXPECT_EQ(2u, last_packet); | 1301 EXPECT_EQ(2u, last_packet); |
1299 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER, | 1302 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER, |
1300 connection_.options()->send_sequence_number_length); | 1303 creator->next_sequence_number_length()); |
1301 // The 1 packet lag is due to the sequence number length being recalculated in | 1304 // The 1 packet lag is due to the sequence number length being recalculated in |
1302 // QuicConnection after a packet is sent. | 1305 // QuicConnection after a packet is sent. |
1303 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, | 1306 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, |
1304 writer_->header().public_header.sequence_number_length); | 1307 writer_->header().public_header.sequence_number_length); |
1305 | 1308 |
1306 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( | 1309 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( |
1307 Return(kMaxPacketSize * 256 * 256)); | 1310 Return(kMaxPacketSize * 256 * 256)); |
1308 | 1311 |
1309 SendStreamDataToPeer(1, "foo", 6, !kFin, &last_packet); | 1312 SendStreamDataToPeer(1, "foo", 6, !kFin, &last_packet); |
1310 EXPECT_EQ(3u, last_packet); | 1313 EXPECT_EQ(3u, last_packet); |
1311 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, | 1314 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, |
1312 connection_.options()->send_sequence_number_length); | 1315 creator->next_sequence_number_length()); |
1313 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER, | 1316 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER, |
1314 writer_->header().public_header.sequence_number_length); | 1317 writer_->header().public_header.sequence_number_length); |
1315 | 1318 |
1316 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( | 1319 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( |
1317 Return(kMaxPacketSize * 256 * 256 * 256)); | 1320 Return(kMaxPacketSize * 256 * 256 * 256)); |
1318 | 1321 |
1319 SendStreamDataToPeer(1, "bar", 9, !kFin, &last_packet); | 1322 SendStreamDataToPeer(1, "bar", 9, !kFin, &last_packet); |
1320 EXPECT_EQ(4u, last_packet); | 1323 EXPECT_EQ(4u, last_packet); |
1321 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, | 1324 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, |
1322 connection_.options()->send_sequence_number_length); | 1325 creator->next_sequence_number_length()); |
1323 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, | 1326 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, |
1324 writer_->header().public_header.sequence_number_length); | 1327 writer_->header().public_header.sequence_number_length); |
1325 | 1328 |
1326 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( | 1329 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( |
1327 Return(kMaxPacketSize * 256 * 256 * 256 * 256)); | 1330 Return(kMaxPacketSize * 256 * 256 * 256 * 256)); |
1328 | 1331 |
1329 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet); | 1332 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet); |
1330 EXPECT_EQ(5u, last_packet); | 1333 EXPECT_EQ(5u, last_packet); |
1331 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER, | 1334 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER, |
1332 connection_.options()->send_sequence_number_length); | 1335 creator->next_sequence_number_length()); |
1333 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, | 1336 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, |
1334 writer_->header().public_header.sequence_number_length); | 1337 writer_->header().public_header.sequence_number_length); |
1335 } | 1338 } |
1336 | 1339 |
1337 TEST_P(QuicConnectionTest, SendingDifferentSequenceNumberLengthsUnackedDelta) { | 1340 TEST_P(QuicConnectionTest, SendingDifferentSequenceNumberLengthsUnackedDelta) { |
1338 QuicPacketSequenceNumber last_packet; | 1341 QuicPacketSequenceNumber last_packet; |
| 1342 QuicPacketCreator* creator = |
| 1343 QuicConnectionPeer::GetPacketCreator(&connection_); |
1339 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); | 1344 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); |
1340 EXPECT_EQ(1u, last_packet); | 1345 EXPECT_EQ(1u, last_packet); |
1341 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, | 1346 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, |
1342 connection_.options()->send_sequence_number_length); | 1347 creator->next_sequence_number_length()); |
1343 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, | 1348 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, |
1344 writer_->header().public_header.sequence_number_length); | 1349 writer_->header().public_header.sequence_number_length); |
1345 | 1350 |
1346 QuicConnectionPeer::GetPacketCreator(&connection_)->set_sequence_number(100); | 1351 creator->set_sequence_number(100); |
1347 | 1352 |
1348 SendStreamDataToPeer(1, "bar", 3, !kFin, &last_packet); | 1353 SendStreamDataToPeer(1, "bar", 3, !kFin, &last_packet); |
1349 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER, | 1354 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER, |
1350 connection_.options()->send_sequence_number_length); | 1355 creator->next_sequence_number_length()); |
1351 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, | 1356 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, |
1352 writer_->header().public_header.sequence_number_length); | 1357 writer_->header().public_header.sequence_number_length); |
1353 | 1358 |
1354 QuicConnectionPeer::GetPacketCreator(&connection_)->set_sequence_number( | 1359 creator->set_sequence_number(100 * 256); |
1355 100 * 256); | |
1356 | 1360 |
1357 SendStreamDataToPeer(1, "foo", 6, !kFin, &last_packet); | 1361 SendStreamDataToPeer(1, "foo", 6, !kFin, &last_packet); |
1358 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, | 1362 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, |
1359 connection_.options()->send_sequence_number_length); | 1363 creator->next_sequence_number_length()); |
1360 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER, | 1364 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER, |
1361 writer_->header().public_header.sequence_number_length); | 1365 writer_->header().public_header.sequence_number_length); |
1362 | 1366 |
1363 QuicConnectionPeer::GetPacketCreator(&connection_)->set_sequence_number( | 1367 creator->set_sequence_number(100 * 256 * 256); |
1364 100 * 256 * 256); | |
1365 | 1368 |
1366 SendStreamDataToPeer(1, "bar", 9, !kFin, &last_packet); | 1369 SendStreamDataToPeer(1, "bar", 9, !kFin, &last_packet); |
1367 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, | 1370 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, |
1368 connection_.options()->send_sequence_number_length); | 1371 creator->next_sequence_number_length()); |
1369 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, | 1372 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, |
1370 writer_->header().public_header.sequence_number_length); | 1373 writer_->header().public_header.sequence_number_length); |
1371 | 1374 |
1372 QuicConnectionPeer::GetPacketCreator(&connection_)->set_sequence_number( | 1375 creator->set_sequence_number(100 * 256 * 256 * 256); |
1373 100 * 256 * 256 * 256); | |
1374 | 1376 |
1375 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet); | 1377 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet); |
1376 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER, | 1378 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER, |
1377 connection_.options()->send_sequence_number_length); | 1379 creator->next_sequence_number_length()); |
1378 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, | 1380 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, |
1379 writer_->header().public_header.sequence_number_length); | 1381 writer_->header().public_header.sequence_number_length); |
1380 } | 1382 } |
1381 | 1383 |
1382 TEST_P(QuicConnectionTest, BasicSending) { | 1384 TEST_P(QuicConnectionTest, BasicSending) { |
1383 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1385 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1384 QuicPacketSequenceNumber last_packet; | 1386 QuicPacketSequenceNumber last_packet; |
1385 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 | 1387 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 |
1386 EXPECT_EQ(1u, last_packet); | 1388 EXPECT_EQ(1u, last_packet); |
1387 SendAckPacketToPeer(); // Packet 2 | 1389 SendAckPacketToPeer(); // Packet 2 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1425 | 1427 |
1426 // But if we send more data it should. | 1428 // But if we send more data it should. |
1427 SendStreamDataToPeer(1, "eep", 6, !kFin, &last_packet); // Packet 8 | 1429 SendStreamDataToPeer(1, "eep", 6, !kFin, &last_packet); // Packet 8 |
1428 EXPECT_EQ(8u, last_packet); | 1430 EXPECT_EQ(8u, last_packet); |
1429 SendAckPacketToPeer(); // Packet 9 | 1431 SendAckPacketToPeer(); // Packet 9 |
1430 EXPECT_EQ(7u, least_unacked()); | 1432 EXPECT_EQ(7u, least_unacked()); |
1431 } | 1433 } |
1432 | 1434 |
1433 TEST_P(QuicConnectionTest, FECSending) { | 1435 TEST_P(QuicConnectionTest, FECSending) { |
1434 // All packets carry version info till version is negotiated. | 1436 // All packets carry version info till version is negotiated. |
| 1437 QuicPacketCreator* creator = |
| 1438 QuicConnectionPeer::GetPacketCreator(&connection_); |
1435 size_t payload_length; | 1439 size_t payload_length; |
1436 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining | 1440 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining |
1437 // packet length. The size of the offset field in a stream frame is 0 for | 1441 // packet length. The size of the offset field in a stream frame is 0 for |
1438 // offset 0, and 2 for non-zero offsets up through 16K. Increase | 1442 // offset 0, and 2 for non-zero offsets up through 64K. Increase |
1439 // max_packet_length by 2 so that subsequent packets containing subsequent | 1443 // max_packet_length by 2 so that subsequent packets containing subsequent |
1440 // stream frames with non-zero offets will fit within the packet length. | 1444 // stream frames with non-zero offets will fit within the packet length. |
1441 connection_.options()->max_packet_length = 2 + GetPacketLengthForOneStream( | 1445 size_t length = 2 + GetPacketLengthForOneStream( |
1442 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, | 1446 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, |
1443 IN_FEC_GROUP, &payload_length); | 1447 IN_FEC_GROUP, &payload_length); |
| 1448 creator->set_max_packet_length(length); |
| 1449 |
1444 // And send FEC every two packets. | 1450 // And send FEC every two packets. |
1445 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn( | 1451 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn(creator, 2)); |
1446 QuicConnectionPeer::GetPacketCreator(&connection_), 2)); | |
1447 | 1452 |
1448 // Send 4 data packets and 2 FEC packets. | 1453 // Send 4 data packets and 2 FEC packets. |
1449 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); | 1454 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(6); |
1450 // The first stream frame will have 2 fewer overhead bytes than the other 3. | 1455 // The first stream frame will have 2 fewer overhead bytes than the other 3. |
1451 const string payload(payload_length * 4 + 2, 'a'); | 1456 const string payload(payload_length * 4 + 2, 'a'); |
1452 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); | 1457 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); |
1453 // Expect the FEC group to be closed after SendStreamDataWithString. | 1458 // Expect the FEC group to be closed after SendStreamDataWithString. |
1454 EXPECT_FALSE(creator_.ShouldSendFec(true)); | 1459 EXPECT_FALSE(creator->ShouldSendFec(true)); |
| 1460 EXPECT_TRUE(creator->IsFecProtected()); |
1455 } | 1461 } |
1456 | 1462 |
1457 TEST_P(QuicConnectionTest, FECQueueing) { | 1463 TEST_P(QuicConnectionTest, FECQueueing) { |
1458 // All packets carry version info till version is negotiated. | 1464 // All packets carry version info till version is negotiated. |
1459 size_t payload_length; | 1465 size_t payload_length; |
1460 connection_.options()->max_packet_length = | 1466 QuicPacketCreator* creator = |
1461 GetPacketLengthForOneStream( | 1467 QuicConnectionPeer::GetPacketCreator(&connection_); |
1462 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, | 1468 size_t length = GetPacketLengthForOneStream( |
1463 IN_FEC_GROUP, &payload_length); | 1469 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, |
| 1470 IN_FEC_GROUP, &payload_length); |
| 1471 creator->set_max_packet_length(length); |
1464 // And send FEC every two packets. | 1472 // And send FEC every two packets. |
1465 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn( | 1473 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn(creator, 2)); |
1466 QuicConnectionPeer::GetPacketCreator(&connection_), 2)); | |
1467 | 1474 |
1468 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1475 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
1469 BlockOnNextWrite(); | 1476 BlockOnNextWrite(); |
1470 const string payload(payload_length, 'a'); | 1477 const string payload(payload_length, 'a'); |
1471 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); | 1478 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); |
1472 EXPECT_FALSE(creator_.ShouldSendFec(true)); | 1479 EXPECT_FALSE(creator->ShouldSendFec(true)); |
| 1480 EXPECT_TRUE(creator->IsFecProtected()); |
1473 // Expect the first data packet and the fec packet to be queued. | 1481 // Expect the first data packet and the fec packet to be queued. |
1474 EXPECT_EQ(2u, connection_.NumQueuedPackets()); | 1482 EXPECT_EQ(2u, connection_.NumQueuedPackets()); |
1475 } | 1483 } |
1476 | 1484 |
1477 TEST_P(QuicConnectionTest, AbandonFECFromCongestionWindow) { | 1485 TEST_P(QuicConnectionTest, AbandonFECFromCongestionWindow) { |
1478 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn( | 1486 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn( |
1479 QuicConnectionPeer::GetPacketCreator(&connection_), 1)); | 1487 QuicConnectionPeer::GetPacketCreator(&connection_), 1)); |
1480 | 1488 |
1481 // 1 Data and 1 FEC packet. | 1489 // 1 Data and 1 FEC packet. |
1482 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 1490 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1683 | 1691 |
1684 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( | 1692 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( |
1685 IgnoreResult(InvokeWithoutArgs(&connection_, | 1693 IgnoreResult(InvokeWithoutArgs(&connection_, |
1686 &TestConnection::SendStreamData3)), | 1694 &TestConnection::SendStreamData3)), |
1687 IgnoreResult(InvokeWithoutArgs(&connection_, | 1695 IgnoreResult(InvokeWithoutArgs(&connection_, |
1688 &TestConnection::SendStreamData5)))); | 1696 &TestConnection::SendStreamData5)))); |
1689 | 1697 |
1690 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 1698 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
1691 | 1699 |
1692 // Process an ack to cause the visitor's OnCanWrite to be invoked. | 1700 // Process an ack to cause the visitor's OnCanWrite to be invoked. |
1693 creator_.set_sequence_number(2); | 1701 peer_creator_.set_sequence_number(2); |
1694 QuicAckFrame ack_one = InitAckFrame(0, 0); | 1702 QuicAckFrame ack_one = InitAckFrame(0, 0); |
1695 ProcessAckPacket(&ack_one); | 1703 ProcessAckPacket(&ack_one); |
1696 | 1704 |
1697 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1705 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
1698 EXPECT_FALSE(connection_.HasQueuedData()); | 1706 EXPECT_FALSE(connection_.HasQueuedData()); |
1699 | 1707 |
1700 // Parse the last packet and ensure it's an ack and two stream frames from | 1708 // Parse the last packet and ensure it's an ack and two stream frames from |
1701 // two different streams. | 1709 // two different streams. |
1702 if (version() > QUIC_VERSION_15) { | 1710 if (version() > QUIC_VERSION_15) { |
1703 EXPECT_EQ(4u, writer_->frame_count()); | 1711 EXPECT_EQ(4u, writer_->frame_count()); |
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2541 | 2549 |
2542 TEST_P(QuicConnectionTest, CloseFecGroup) { | 2550 TEST_P(QuicConnectionTest, CloseFecGroup) { |
2543 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2551 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2544 // Don't send missing packet 1. | 2552 // Don't send missing packet 1. |
2545 // Don't send missing packet 2. | 2553 // Don't send missing packet 2. |
2546 ProcessFecProtectedPacket(3, false, !kEntropyFlag); | 2554 ProcessFecProtectedPacket(3, false, !kEntropyFlag); |
2547 // Don't send missing FEC packet 3. | 2555 // Don't send missing FEC packet 3. |
2548 ASSERT_EQ(1u, connection_.NumFecGroups()); | 2556 ASSERT_EQ(1u, connection_.NumFecGroups()); |
2549 | 2557 |
2550 // Now send non-fec protected ack packet and close the group. | 2558 // Now send non-fec protected ack packet and close the group. |
2551 creator_.set_sequence_number(4); | 2559 peer_creator_.set_sequence_number(4); |
2552 if (version() > QUIC_VERSION_15) { | 2560 if (version() > QUIC_VERSION_15) { |
2553 QuicStopWaitingFrame frame = InitStopWaitingFrame(5); | 2561 QuicStopWaitingFrame frame = InitStopWaitingFrame(5); |
2554 ProcessStopWaitingPacket(&frame); | 2562 ProcessStopWaitingPacket(&frame); |
2555 } else { | 2563 } else { |
2556 QuicAckFrame frame = InitAckFrame(0, 5); | 2564 QuicAckFrame frame = InitAckFrame(0, 5); |
2557 ProcessAckPacket(&frame); | 2565 ProcessAckPacket(&frame); |
2558 } | 2566 } |
2559 ASSERT_EQ(0u, connection_.NumFecGroups()); | 2567 ASSERT_EQ(0u, connection_.NumFecGroups()); |
2560 } | 2568 } |
2561 | 2569 |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2863 | 2871 |
2864 // OnCanWrite should send the packet, because it won't consult the send | 2872 // OnCanWrite should send the packet, because it won't consult the send |
2865 // algorithm for queued packets. | 2873 // algorithm for queued packets. |
2866 connection_.OnCanWrite(); | 2874 connection_.OnCanWrite(); |
2867 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2875 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
2868 } | 2876 } |
2869 | 2877 |
2870 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { | 2878 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { |
2871 // All packets carry version info till version is negotiated. | 2879 // All packets carry version info till version is negotiated. |
2872 size_t payload_length; | 2880 size_t payload_length; |
2873 connection_.options()->max_packet_length = | 2881 size_t length = GetPacketLengthForOneStream( |
2874 GetPacketLengthForOneStream( | 2882 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, |
2875 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, | 2883 NOT_IN_FEC_GROUP, &payload_length); |
2876 NOT_IN_FEC_GROUP, &payload_length); | 2884 QuicConnectionPeer::GetPacketCreator(&connection_)->set_max_packet_length( |
| 2885 length); |
2877 | 2886 |
2878 // Queue the first packet. | 2887 // Queue the first packet. |
2879 EXPECT_CALL(*send_algorithm_, | 2888 EXPECT_CALL(*send_algorithm_, |
2880 TimeUntilSend(_, _, _)).WillOnce( | 2889 TimeUntilSend(_, _, _)).WillOnce( |
2881 testing::Return(QuicTime::Delta::FromMicroseconds(10))); | 2890 testing::Return(QuicTime::Delta::FromMicroseconds(10))); |
2882 const string payload(payload_length, 'a'); | 2891 const string payload(payload_length, 'a'); |
2883 EXPECT_EQ(0u, | 2892 EXPECT_EQ(0u, |
2884 connection_.SendStreamDataWithString(3, payload, 0, | 2893 connection_.SendStreamDataWithString(3, payload, 0, |
2885 !kFin, NULL).bytes_consumed); | 2894 !kFin, NULL).bytes_consumed); |
2886 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2895 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
2887 } | 2896 } |
2888 | 2897 |
2889 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { | 2898 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { |
2890 // All packets carry version info till version is negotiated. | 2899 // All packets carry version info till version is negotiated. |
2891 size_t payload_length; | 2900 size_t payload_length; |
2892 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining | 2901 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining |
2893 // packet length. The size of the offset field in a stream frame is 0 for | 2902 // packet length. The size of the offset field in a stream frame is 0 for |
2894 // offset 0, and 2 for non-zero offsets up through 16K. Increase | 2903 // offset 0, and 2 for non-zero offsets up through 16K. Increase |
2895 // max_packet_length by 2 so that subsequent packets containing subsequent | 2904 // max_packet_length by 2 so that subsequent packets containing subsequent |
2896 // stream frames with non-zero offets will fit within the packet length. | 2905 // stream frames with non-zero offets will fit within the packet length. |
2897 connection_.options()->max_packet_length = 2 + GetPacketLengthForOneStream( | 2906 size_t length = 2 + GetPacketLengthForOneStream( |
2898 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, | 2907 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, |
2899 NOT_IN_FEC_GROUP, &payload_length); | 2908 NOT_IN_FEC_GROUP, &payload_length); |
| 2909 QuicConnectionPeer::GetPacketCreator(&connection_)->set_max_packet_length( |
| 2910 length); |
2900 | 2911 |
2901 // Queue the first packet. | 2912 // Queue the first packet. |
2902 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7); | 2913 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7); |
2903 // The first stream frame will have 2 fewer overhead bytes than the other six. | 2914 // The first stream frame will have 2 fewer overhead bytes than the other six. |
2904 const string payload(payload_length * 7 + 2, 'a'); | 2915 const string payload(payload_length * 7 + 2, 'a'); |
2905 EXPECT_EQ(payload.size(), | 2916 EXPECT_EQ(payload.size(), |
2906 connection_.SendStreamDataWithString(1, payload, 0, | 2917 connection_.SendStreamDataWithString(1, payload, 0, |
2907 !kFin, NULL).bytes_consumed); | 2918 !kFin, NULL).bytes_consumed); |
2908 } | 2919 } |
2909 | 2920 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3153 QuicEncryptedPacket encrypted(NULL, 0); | 3164 QuicEncryptedPacket encrypted(NULL, 0); |
3154 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), encrypted); | 3165 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), encrypted); |
3155 // The connection close packet should have error details. | 3166 // The connection close packet should have error details. |
3156 ASSERT_FALSE(writer_->connection_close_frames().empty()); | 3167 ASSERT_FALSE(writer_->connection_close_frames().empty()); |
3157 EXPECT_EQ("Unable to read public flags.", | 3168 EXPECT_EQ("Unable to read public flags.", |
3158 writer_->connection_close_frames()[0].error_details); | 3169 writer_->connection_close_frames()[0].error_details); |
3159 } | 3170 } |
3160 | 3171 |
3161 TEST_P(QuicConnectionTest, MissingPacketsBeforeLeastUnacked) { | 3172 TEST_P(QuicConnectionTest, MissingPacketsBeforeLeastUnacked) { |
3162 // Set the sequence number of the ack packet to be least unacked (4). | 3173 // Set the sequence number of the ack packet to be least unacked (4). |
3163 creator_.set_sequence_number(3); | 3174 peer_creator_.set_sequence_number(3); |
3164 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3175 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3165 if (version() > QUIC_VERSION_15) { | 3176 if (version() > QUIC_VERSION_15) { |
3166 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); | 3177 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); |
3167 ProcessStopWaitingPacket(&frame); | 3178 ProcessStopWaitingPacket(&frame); |
3168 } else { | 3179 } else { |
3169 QuicAckFrame ack = InitAckFrame(0, 4); | 3180 QuicAckFrame ack = InitAckFrame(0, 4); |
3170 ProcessAckPacket(&ack); | 3181 ProcessAckPacket(&ack); |
3171 } | 3182 } |
3172 EXPECT_TRUE(outgoing_ack()->received_info.missing_packets.empty()); | 3183 EXPECT_TRUE(outgoing_ack()->received_info.missing_packets.empty()); |
3173 } | 3184 } |
(...skipping 23 matching lines...) Expand all Loading... |
3197 } | 3208 } |
3198 | 3209 |
3199 TEST_P(QuicConnectionTest, UpdateEntropyForReceivedPackets) { | 3210 TEST_P(QuicConnectionTest, UpdateEntropyForReceivedPackets) { |
3200 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); | 3211 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); |
3201 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3212 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3202 ProcessDataPacket(1, 1, kEntropyFlag); | 3213 ProcessDataPacket(1, 1, kEntropyFlag); |
3203 ProcessDataPacket(5, 1, kEntropyFlag); | 3214 ProcessDataPacket(5, 1, kEntropyFlag); |
3204 ProcessDataPacket(4, 1, !kEntropyFlag); | 3215 ProcessDataPacket(4, 1, !kEntropyFlag); |
3205 EXPECT_EQ(34u, outgoing_ack()->received_info.entropy_hash); | 3216 EXPECT_EQ(34u, outgoing_ack()->received_info.entropy_hash); |
3206 // Make 4th packet my least unacked, and update entropy for 2, 3 packets. | 3217 // Make 4th packet my least unacked, and update entropy for 2, 3 packets. |
3207 creator_.set_sequence_number(5); | 3218 peer_creator_.set_sequence_number(5); |
3208 QuicPacketEntropyHash six_packet_entropy_hash = 0; | 3219 QuicPacketEntropyHash six_packet_entropy_hash = 0; |
3209 QuicPacketEntropyHash kRandomEntropyHash = 129u; | 3220 QuicPacketEntropyHash kRandomEntropyHash = 129u; |
3210 if (version() > QUIC_VERSION_15) { | 3221 if (version() > QUIC_VERSION_15) { |
3211 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); | 3222 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); |
3212 frame.entropy_hash = kRandomEntropyHash; | 3223 frame.entropy_hash = kRandomEntropyHash; |
3213 if (ProcessStopWaitingPacket(&frame)) { | 3224 if (ProcessStopWaitingPacket(&frame)) { |
3214 six_packet_entropy_hash = 1 << 6; | 3225 six_packet_entropy_hash = 1 << 6; |
3215 } | 3226 } |
3216 } else { | 3227 } else { |
3217 QuicAckFrame ack = InitAckFrame(0, 4); | 3228 QuicAckFrame ack = InitAckFrame(0, 4); |
3218 ack.sent_info.entropy_hash = kRandomEntropyHash; | 3229 ack.sent_info.entropy_hash = kRandomEntropyHash; |
3219 if (ProcessAckPacket(&ack)) { | 3230 if (ProcessAckPacket(&ack)) { |
3220 six_packet_entropy_hash = 1 << 6; | 3231 six_packet_entropy_hash = 1 << 6; |
3221 } | 3232 } |
3222 } | 3233 } |
3223 | 3234 |
3224 EXPECT_EQ((kRandomEntropyHash + (1 << 5) + six_packet_entropy_hash), | 3235 EXPECT_EQ((kRandomEntropyHash + (1 << 5) + six_packet_entropy_hash), |
3225 outgoing_ack()->received_info.entropy_hash); | 3236 outgoing_ack()->received_info.entropy_hash); |
3226 } | 3237 } |
3227 | 3238 |
3228 TEST_P(QuicConnectionTest, UpdateEntropyHashUptoCurrentPacket) { | 3239 TEST_P(QuicConnectionTest, UpdateEntropyHashUptoCurrentPacket) { |
3229 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); | 3240 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); |
3230 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3241 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3231 ProcessDataPacket(1, 1, kEntropyFlag); | 3242 ProcessDataPacket(1, 1, kEntropyFlag); |
3232 ProcessDataPacket(5, 1, !kEntropyFlag); | 3243 ProcessDataPacket(5, 1, !kEntropyFlag); |
3233 ProcessDataPacket(22, 1, kEntropyFlag); | 3244 ProcessDataPacket(22, 1, kEntropyFlag); |
3234 EXPECT_EQ(66u, outgoing_ack()->received_info.entropy_hash); | 3245 EXPECT_EQ(66u, outgoing_ack()->received_info.entropy_hash); |
3235 creator_.set_sequence_number(22); | 3246 peer_creator_.set_sequence_number(22); |
3236 QuicPacketEntropyHash kRandomEntropyHash = 85u; | 3247 QuicPacketEntropyHash kRandomEntropyHash = 85u; |
3237 // Current packet is the least unacked packet. | 3248 // Current packet is the least unacked packet. |
3238 QuicPacketEntropyHash ack_entropy_hash; | 3249 QuicPacketEntropyHash ack_entropy_hash; |
3239 if (version() > QUIC_VERSION_15) { | 3250 if (version() > QUIC_VERSION_15) { |
3240 QuicStopWaitingFrame frame = InitStopWaitingFrame(23); | 3251 QuicStopWaitingFrame frame = InitStopWaitingFrame(23); |
3241 frame.entropy_hash = kRandomEntropyHash; | 3252 frame.entropy_hash = kRandomEntropyHash; |
3242 ack_entropy_hash = ProcessStopWaitingPacket(&frame); | 3253 ack_entropy_hash = ProcessStopWaitingPacket(&frame); |
3243 } else { | 3254 } else { |
3244 QuicAckFrame ack = InitAckFrame(0, 23); | 3255 QuicAckFrame ack = InitAckFrame(0, 23); |
3245 ack.sent_info.entropy_hash = kRandomEntropyHash; | 3256 ack.sent_info.entropy_hash = kRandomEntropyHash; |
(...skipping 25 matching lines...) Expand all Loading... |
3271 } | 3282 } |
3272 ProcessDataPacket(i, 1, entropy_flag); | 3283 ProcessDataPacket(i, 1, entropy_flag); |
3273 } | 3284 } |
3274 for (int i = 1; i < 50; ++i) { | 3285 for (int i = 1; i < 50; ++i) { |
3275 EXPECT_EQ(entropy[i], QuicConnectionPeer::ReceivedEntropyHash( | 3286 EXPECT_EQ(entropy[i], QuicConnectionPeer::ReceivedEntropyHash( |
3276 &connection_, i)); | 3287 &connection_, i)); |
3277 } | 3288 } |
3278 } | 3289 } |
3279 | 3290 |
3280 TEST_P(QuicConnectionTest, CheckSentEntropyHash) { | 3291 TEST_P(QuicConnectionTest, CheckSentEntropyHash) { |
3281 creator_.set_sequence_number(1); | 3292 peer_creator_.set_sequence_number(1); |
3282 SequenceNumberSet missing_packets; | 3293 SequenceNumberSet missing_packets; |
3283 QuicPacketEntropyHash entropy_hash = 0; | 3294 QuicPacketEntropyHash entropy_hash = 0; |
3284 QuicPacketSequenceNumber max_sequence_number = 51; | 3295 QuicPacketSequenceNumber max_sequence_number = 51; |
3285 for (QuicPacketSequenceNumber i = 1; i <= max_sequence_number; ++i) { | 3296 for (QuicPacketSequenceNumber i = 1; i <= max_sequence_number; ++i) { |
3286 bool is_missing = i % 10 != 0; | 3297 bool is_missing = i % 10 != 0; |
3287 bool entropy_flag = (i & (i - 1)) != 0; | 3298 bool entropy_flag = (i & (i - 1)) != 0; |
3288 QuicPacketEntropyHash packet_entropy_hash = 0; | 3299 QuicPacketEntropyHash packet_entropy_hash = 0; |
3289 if (entropy_flag) { | 3300 if (entropy_flag) { |
3290 packet_entropy_hash = 1 << (i % 8); | 3301 packet_entropy_hash = 1 << (i % 8); |
3291 } | 3302 } |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3989 QuicBlockedFrame blocked; | 4000 QuicBlockedFrame blocked; |
3990 blocked.stream_id = 3; | 4001 blocked.stream_id = 3; |
3991 EXPECT_CALL(visitor_, OnBlockedFrames(_)); | 4002 EXPECT_CALL(visitor_, OnBlockedFrames(_)); |
3992 ProcessFramePacket(QuicFrame(&blocked)); | 4003 ProcessFramePacket(QuicFrame(&blocked)); |
3993 EXPECT_TRUE(ack_alarm->IsSet()); | 4004 EXPECT_TRUE(ack_alarm->IsSet()); |
3994 } | 4005 } |
3995 | 4006 |
3996 } // namespace | 4007 } // namespace |
3997 } // namespace test | 4008 } // namespace test |
3998 } // namespace net | 4009 } // namespace net |
OLD | NEW |