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 <ostream> | 7 #include <ostream> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 const char data1[] = "foo"; | 59 const char data1[] = "foo"; |
60 const char data2[] = "bar"; | 60 const char data2[] = "bar"; |
61 | 61 |
62 const bool kFin = true; | 62 const bool kFin = true; |
63 const bool kEntropyFlag = true; | 63 const bool kEntropyFlag = true; |
64 | 64 |
65 const QuicPacketEntropyHash kTestEntropyHash = 76; | 65 const QuicPacketEntropyHash kTestEntropyHash = 76; |
66 | 66 |
67 const int kDefaultRetransmissionTimeMs = 500; | 67 const int kDefaultRetransmissionTimeMs = 500; |
68 | 68 |
| 69 const IPEndPoint kPeerAddress = IPEndPoint(Loopback6(), /*port=*/12345); |
| 70 const IPEndPoint kSelfAddress = IPEndPoint(Loopback6(), /*port=*/443); |
| 71 |
69 // TaggingEncrypter appends kTagSize bytes of |tag| to the end of each message. | 72 // TaggingEncrypter appends kTagSize bytes of |tag| to the end of each message. |
70 class TaggingEncrypter : public QuicEncrypter { | 73 class TaggingEncrypter : public QuicEncrypter { |
71 public: | 74 public: |
72 explicit TaggingEncrypter(uint8 tag) | 75 explicit TaggingEncrypter(uint8 tag) |
73 : tag_(tag) { | 76 : tag_(tag) { |
74 } | 77 } |
75 | 78 |
76 ~TaggingEncrypter() override {} | 79 ~TaggingEncrypter() override {} |
77 | 80 |
78 // QuicEncrypter interface. | 81 // QuicEncrypter interface. |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 | 228 |
226 private: | 229 private: |
227 MockClock* clock_; | 230 MockClock* clock_; |
228 MockRandom* random_generator_; | 231 MockRandom* random_generator_; |
229 | 232 |
230 DISALLOW_COPY_AND_ASSIGN(TestConnectionHelper); | 233 DISALLOW_COPY_AND_ASSIGN(TestConnectionHelper); |
231 }; | 234 }; |
232 | 235 |
233 class TestPacketWriter : public QuicPacketWriter { | 236 class TestPacketWriter : public QuicPacketWriter { |
234 public: | 237 public: |
235 TestPacketWriter(QuicVersion version, MockClock *clock) | 238 TestPacketWriter(QuicVersion version, MockClock* clock) |
236 : version_(version), | 239 : version_(version), |
237 framer_(SupportedVersions(version_)), | 240 framer_(SupportedVersions(version_)), |
238 last_packet_size_(0), | 241 last_packet_size_(0), |
239 write_blocked_(false), | 242 write_blocked_(false), |
240 block_on_next_write_(false), | 243 block_on_next_write_(false), |
241 is_write_blocked_data_buffered_(false), | 244 is_write_blocked_data_buffered_(false), |
242 final_bytes_of_last_packet_(0), | 245 final_bytes_of_last_packet_(0), |
243 final_bytes_of_previous_packet_(0), | 246 final_bytes_of_previous_packet_(0), |
244 use_tagging_decrypter_(false), | 247 use_tagging_decrypter_(false), |
245 packets_write_attempts_(0), | 248 packets_write_attempts_(0), |
246 clock_(clock), | 249 clock_(clock), |
247 write_pause_time_delta_(QuicTime::Delta::Zero()) { | 250 write_pause_time_delta_(QuicTime::Delta::Zero()), |
248 } | 251 max_packet_size_(kMaxPacketSize) {} |
249 | 252 |
250 // QuicPacketWriter interface | 253 // QuicPacketWriter interface |
251 WriteResult WritePacket(const char* buffer, | 254 WriteResult WritePacket(const char* buffer, |
252 size_t buf_len, | 255 size_t buf_len, |
253 const IPAddressNumber& self_address, | 256 const IPAddressNumber& self_address, |
254 const IPEndPoint& peer_address) override { | 257 const IPEndPoint& peer_address) override { |
255 QuicEncryptedPacket packet(buffer, buf_len); | 258 QuicEncryptedPacket packet(buffer, buf_len); |
256 ++packets_write_attempts_; | 259 ++packets_write_attempts_; |
257 | 260 |
258 if (packet.length() >= sizeof(final_bytes_of_last_packet_)) { | 261 if (packet.length() >= sizeof(final_bytes_of_last_packet_)) { |
(...skipping 22 matching lines...) Expand all Loading... |
281 } | 284 } |
282 | 285 |
283 bool IsWriteBlockedDataBuffered() const override { | 286 bool IsWriteBlockedDataBuffered() const override { |
284 return is_write_blocked_data_buffered_; | 287 return is_write_blocked_data_buffered_; |
285 } | 288 } |
286 | 289 |
287 bool IsWriteBlocked() const override { return write_blocked_; } | 290 bool IsWriteBlocked() const override { return write_blocked_; } |
288 | 291 |
289 void SetWritable() override { write_blocked_ = false; } | 292 void SetWritable() override { write_blocked_ = false; } |
290 | 293 |
| 294 QuicByteCount GetMaxPacketSize( |
| 295 const IPEndPoint& /*peer_address*/) const override { |
| 296 return max_packet_size_; |
| 297 } |
| 298 |
291 void BlockOnNextWrite() { block_on_next_write_ = true; } | 299 void BlockOnNextWrite() { block_on_next_write_ = true; } |
292 | 300 |
293 // Sets the amount of time that the writer should before the actual write. | 301 // Sets the amount of time that the writer should before the actual write. |
294 void SetWritePauseTimeDelta(QuicTime::Delta delta) { | 302 void SetWritePauseTimeDelta(QuicTime::Delta delta) { |
295 write_pause_time_delta_ = delta; | 303 write_pause_time_delta_ = delta; |
296 } | 304 } |
297 | 305 |
298 const QuicPacketHeader& header() { return framer_.header(); } | 306 const QuicPacketHeader& header() { return framer_.header(); } |
299 | 307 |
300 size_t frame_count() const { return framer_.num_frames(); } | 308 size_t frame_count() const { return framer_.num_frames(); } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 } | 368 } |
361 | 369 |
362 uint32 packets_write_attempts() { return packets_write_attempts_; } | 370 uint32 packets_write_attempts() { return packets_write_attempts_; } |
363 | 371 |
364 void Reset() { framer_.Reset(); } | 372 void Reset() { framer_.Reset(); } |
365 | 373 |
366 void SetSupportedVersions(const QuicVersionVector& versions) { | 374 void SetSupportedVersions(const QuicVersionVector& versions) { |
367 framer_.SetSupportedVersions(versions); | 375 framer_.SetSupportedVersions(versions); |
368 } | 376 } |
369 | 377 |
| 378 void set_max_packet_size(QuicByteCount max_packet_size) { |
| 379 max_packet_size_ = max_packet_size; |
| 380 } |
| 381 |
370 private: | 382 private: |
371 QuicVersion version_; | 383 QuicVersion version_; |
372 SimpleQuicFramer framer_; | 384 SimpleQuicFramer framer_; |
373 size_t last_packet_size_; | 385 size_t last_packet_size_; |
374 bool write_blocked_; | 386 bool write_blocked_; |
375 bool block_on_next_write_; | 387 bool block_on_next_write_; |
376 bool is_write_blocked_data_buffered_; | 388 bool is_write_blocked_data_buffered_; |
377 uint32 final_bytes_of_last_packet_; | 389 uint32 final_bytes_of_last_packet_; |
378 uint32 final_bytes_of_previous_packet_; | 390 uint32 final_bytes_of_previous_packet_; |
379 bool use_tagging_decrypter_; | 391 bool use_tagging_decrypter_; |
380 uint32 packets_write_attempts_; | 392 uint32 packets_write_attempts_; |
381 MockClock *clock_; | 393 MockClock *clock_; |
382 // If non-zero, the clock will pause during WritePacket for this amount of | 394 // If non-zero, the clock will pause during WritePacket for this amount of |
383 // time. | 395 // time. |
384 QuicTime::Delta write_pause_time_delta_; | 396 QuicTime::Delta write_pause_time_delta_; |
| 397 QuicByteCount max_packet_size_; |
385 | 398 |
386 DISALLOW_COPY_AND_ASSIGN(TestPacketWriter); | 399 DISALLOW_COPY_AND_ASSIGN(TestPacketWriter); |
387 }; | 400 }; |
388 | 401 |
389 class TestConnection : public QuicConnection { | 402 class TestConnection : public QuicConnection { |
390 public: | 403 public: |
391 TestConnection(QuicConnectionId connection_id, | 404 TestConnection(QuicConnectionId connection_id, |
392 IPEndPoint address, | 405 IPEndPoint address, |
393 TestConnectionHelper* helper, | 406 TestConnectionHelper* helper, |
394 const PacketWriterFactory& factory, | 407 const PacketWriterFactory& factory, |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 framer_(SupportedVersions(version()), | 668 framer_(SupportedVersions(version()), |
656 QuicTime::Zero(), | 669 QuicTime::Zero(), |
657 Perspective::IS_CLIENT), | 670 Perspective::IS_CLIENT), |
658 peer_creator_(connection_id_, &framer_, &random_generator_), | 671 peer_creator_(connection_id_, &framer_, &random_generator_), |
659 send_algorithm_(new StrictMock<MockSendAlgorithm>), | 672 send_algorithm_(new StrictMock<MockSendAlgorithm>), |
660 loss_algorithm_(new MockLossAlgorithm()), | 673 loss_algorithm_(new MockLossAlgorithm()), |
661 helper_(new TestConnectionHelper(&clock_, &random_generator_)), | 674 helper_(new TestConnectionHelper(&clock_, &random_generator_)), |
662 writer_(new TestPacketWriter(version(), &clock_)), | 675 writer_(new TestPacketWriter(version(), &clock_)), |
663 factory_(writer_.get()), | 676 factory_(writer_.get()), |
664 connection_(connection_id_, | 677 connection_(connection_id_, |
665 IPEndPoint(), | 678 kPeerAddress, |
666 helper_.get(), | 679 helper_.get(), |
667 factory_, | 680 factory_, |
668 Perspective::IS_CLIENT, | 681 Perspective::IS_CLIENT, |
669 version()), | 682 version()), |
670 creator_(QuicConnectionPeer::GetPacketCreator(&connection_)), | 683 creator_(QuicConnectionPeer::GetPacketCreator(&connection_)), |
671 generator_(QuicConnectionPeer::GetPacketGenerator(&connection_)), | 684 generator_(QuicConnectionPeer::GetPacketGenerator(&connection_)), |
672 manager_(QuicConnectionPeer::GetSentPacketManager(&connection_)), | 685 manager_(QuicConnectionPeer::GetSentPacketManager(&connection_)), |
673 frame1_(1, false, 0, StringPiece(data1)), | 686 frame1_(1, false, 0, StringPiece(data1)), |
674 frame2_(1, false, 3, StringPiece(data2)), | 687 frame2_(1, false, 3, StringPiece(data2)), |
675 packet_number_length_(PACKET_6BYTE_PACKET_NUMBER), | 688 packet_number_length_(PACKET_6BYTE_PACKET_NUMBER), |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 QuicPacketEntropyHash ProcessFramePacket(QuicFrame frame) { | 755 QuicPacketEntropyHash ProcessFramePacket(QuicFrame frame) { |
743 QuicFrames frames; | 756 QuicFrames frames; |
744 frames.push_back(QuicFrame(frame)); | 757 frames.push_back(QuicFrame(frame)); |
745 QuicPacketCreatorPeer::SetSendVersionInPacket( | 758 QuicPacketCreatorPeer::SetSendVersionInPacket( |
746 &peer_creator_, connection_.perspective() == Perspective::IS_SERVER); | 759 &peer_creator_, connection_.perspective() == Perspective::IS_SERVER); |
747 | 760 |
748 char buffer[kMaxPacketSize]; | 761 char buffer[kMaxPacketSize]; |
749 SerializedPacket serialized_packet = | 762 SerializedPacket serialized_packet = |
750 peer_creator_.SerializeAllFrames(frames, buffer, kMaxPacketSize); | 763 peer_creator_.SerializeAllFrames(frames, buffer, kMaxPacketSize); |
751 scoped_ptr<QuicEncryptedPacket> encrypted(serialized_packet.packet); | 764 scoped_ptr<QuicEncryptedPacket> encrypted(serialized_packet.packet); |
752 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 765 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); |
753 return serialized_packet.entropy_hash; | 766 return serialized_packet.entropy_hash; |
754 } | 767 } |
755 | 768 |
756 size_t ProcessDataPacket(QuicPacketNumber number, | 769 size_t ProcessDataPacket(QuicPacketNumber number, |
757 QuicFecGroupNumber fec_group, | 770 QuicFecGroupNumber fec_group, |
758 bool entropy_flag) { | 771 bool entropy_flag) { |
759 return ProcessDataPacketAtLevel(number, fec_group, entropy_flag, | 772 return ProcessDataPacketAtLevel(number, fec_group, entropy_flag, |
760 ENCRYPTION_NONE); | 773 ENCRYPTION_NONE); |
761 } | 774 } |
762 | 775 |
763 size_t ProcessDataPacketAtLevel(QuicPacketNumber number, | 776 size_t ProcessDataPacketAtLevel(QuicPacketNumber number, |
764 QuicFecGroupNumber fec_group, | 777 QuicFecGroupNumber fec_group, |
765 bool entropy_flag, | 778 bool entropy_flag, |
766 EncryptionLevel level) { | 779 EncryptionLevel level) { |
767 scoped_ptr<QuicPacket> packet(ConstructDataPacket(number, fec_group, | 780 scoped_ptr<QuicPacket> packet(ConstructDataPacket(number, fec_group, |
768 entropy_flag)); | 781 entropy_flag)); |
769 char buffer[kMaxPacketSize]; | 782 char buffer[kMaxPacketSize]; |
770 scoped_ptr<QuicEncryptedPacket> encrypted( | 783 scoped_ptr<QuicEncryptedPacket> encrypted( |
771 framer_.EncryptPayload(level, number, *packet, buffer, kMaxPacketSize)); | 784 framer_.EncryptPayload(level, number, *packet, buffer, kMaxPacketSize)); |
772 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 785 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); |
773 return encrypted->length(); | 786 return encrypted->length(); |
774 } | 787 } |
775 | 788 |
776 void ProcessClosePacket(QuicPacketNumber number, | 789 void ProcessClosePacket(QuicPacketNumber number, |
777 QuicFecGroupNumber fec_group) { | 790 QuicFecGroupNumber fec_group) { |
778 scoped_ptr<QuicPacket> packet(ConstructClosePacket(number, fec_group)); | 791 scoped_ptr<QuicPacket> packet(ConstructClosePacket(number, fec_group)); |
779 char buffer[kMaxPacketSize]; | 792 char buffer[kMaxPacketSize]; |
780 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( | 793 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( |
781 ENCRYPTION_NONE, number, *packet, buffer, kMaxPacketSize)); | 794 ENCRYPTION_NONE, number, *packet, buffer, kMaxPacketSize)); |
782 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 795 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); |
783 } | 796 } |
784 | 797 |
785 size_t ProcessFecProtectedPacket(QuicPacketNumber number, | 798 size_t ProcessFecProtectedPacket(QuicPacketNumber number, |
786 bool expect_revival, | 799 bool expect_revival, |
787 bool entropy_flag) { | 800 bool entropy_flag) { |
788 if (expect_revival) { | 801 if (expect_revival) { |
789 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 802 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
790 } | 803 } |
791 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1).RetiresOnSaturation(); | 804 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1).RetiresOnSaturation(); |
792 return ProcessDataPacket(number, 1, entropy_flag); | 805 return ProcessDataPacket(number, 1, entropy_flag); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 data_packet->mutable_data()[i] ^= data_packet->data()[i]; | 850 data_packet->mutable_data()[i] ^= data_packet->data()[i]; |
838 } | 851 } |
839 } | 852 } |
840 fec_data.redundancy = data_packet->FecProtectedData(); | 853 fec_data.redundancy = data_packet->FecProtectedData(); |
841 | 854 |
842 scoped_ptr<QuicPacket> fec_packet(framer_.BuildFecPacket(header, fec_data)); | 855 scoped_ptr<QuicPacket> fec_packet(framer_.BuildFecPacket(header, fec_data)); |
843 char buffer[kMaxPacketSize]; | 856 char buffer[kMaxPacketSize]; |
844 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( | 857 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( |
845 ENCRYPTION_NONE, number, *fec_packet, buffer, kMaxPacketSize)); | 858 ENCRYPTION_NONE, number, *fec_packet, buffer, kMaxPacketSize)); |
846 | 859 |
847 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 860 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); |
848 return encrypted->length(); | 861 return encrypted->length(); |
849 } | 862 } |
850 | 863 |
851 QuicByteCount SendStreamDataToPeer(QuicStreamId id, | 864 QuicByteCount SendStreamDataToPeer(QuicStreamId id, |
852 StringPiece data, | 865 StringPiece data, |
853 QuicStreamOffset offset, | 866 QuicStreamOffset offset, |
854 bool fin, | 867 bool fin, |
855 QuicPacketNumber* last_packet) { | 868 QuicPacketNumber* last_packet) { |
856 QuicByteCount packet_size; | 869 QuicByteCount packet_size; |
857 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 870 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 QuicConnectionTest, | 1052 QuicConnectionTest, |
1040 ::testing::ValuesIn(GetTestParams())); | 1053 ::testing::ValuesIn(GetTestParams())); |
1041 | 1054 |
1042 TEST_P(QuicConnectionTest, MaxPacketSize) { | 1055 TEST_P(QuicConnectionTest, MaxPacketSize) { |
1043 EXPECT_EQ(Perspective::IS_CLIENT, connection_.perspective()); | 1056 EXPECT_EQ(Perspective::IS_CLIENT, connection_.perspective()); |
1044 EXPECT_EQ(1350u, connection_.max_packet_length()); | 1057 EXPECT_EQ(1350u, connection_.max_packet_length()); |
1045 } | 1058 } |
1046 | 1059 |
1047 TEST_P(QuicConnectionTest, SmallerServerMaxPacketSize) { | 1060 TEST_P(QuicConnectionTest, SmallerServerMaxPacketSize) { |
1048 QuicConnectionId connection_id = 42; | 1061 QuicConnectionId connection_id = 42; |
1049 TestConnection connection(connection_id, IPEndPoint(), helper_.get(), | 1062 TestConnection connection(connection_id, kPeerAddress, helper_.get(), |
1050 factory_, Perspective::IS_SERVER, version()); | 1063 factory_, Perspective::IS_SERVER, version()); |
1051 EXPECT_EQ(Perspective::IS_SERVER, connection.perspective()); | 1064 EXPECT_EQ(Perspective::IS_SERVER, connection.perspective()); |
1052 EXPECT_EQ(1000u, connection.max_packet_length()); | 1065 EXPECT_EQ(1000u, connection.max_packet_length()); |
1053 } | 1066 } |
1054 | 1067 |
1055 TEST_P(QuicConnectionTest, IncreaseServerMaxPacketSize) { | 1068 TEST_P(QuicConnectionTest, IncreaseServerMaxPacketSize) { |
1056 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1069 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1057 | 1070 |
1058 connection_.set_perspective(Perspective::IS_SERVER); | 1071 connection_.set_perspective(Perspective::IS_SERVER); |
1059 connection_.set_max_packet_length(1000); | 1072 connection_.SetMaxPacketLength(1000); |
1060 | 1073 |
1061 QuicPacketHeader header; | 1074 QuicPacketHeader header; |
1062 header.public_header.connection_id = connection_id_; | 1075 header.public_header.connection_id = connection_id_; |
1063 header.public_header.version_flag = true; | 1076 header.public_header.version_flag = true; |
1064 header.packet_packet_number = 1; | 1077 header.packet_packet_number = 1; |
1065 | 1078 |
1066 QuicFrames frames; | 1079 QuicFrames frames; |
1067 QuicPaddingFrame padding; | 1080 QuicPaddingFrame padding; |
1068 frames.push_back(QuicFrame(&frame1_)); | 1081 frames.push_back(QuicFrame(&frame1_)); |
1069 frames.push_back(QuicFrame(&padding)); | 1082 frames.push_back(QuicFrame(&padding)); |
1070 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); | 1083 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); |
1071 char buffer[kMaxPacketSize]; | 1084 char buffer[kMaxPacketSize]; |
1072 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( | 1085 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( |
1073 ENCRYPTION_NONE, 12, *packet, buffer, kMaxPacketSize)); | 1086 ENCRYPTION_NONE, 12, *packet, buffer, kMaxPacketSize)); |
1074 EXPECT_EQ(kMaxPacketSize, encrypted->length()); | 1087 EXPECT_EQ(kMaxPacketSize, encrypted->length()); |
1075 | 1088 |
1076 framer_.set_version(version()); | 1089 framer_.set_version(version()); |
1077 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 1090 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
1078 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 1091 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); |
1079 | 1092 |
1080 EXPECT_EQ(kMaxPacketSize, connection_.max_packet_length()); | 1093 EXPECT_EQ(kMaxPacketSize, connection_.max_packet_length()); |
1081 } | 1094 } |
1082 | 1095 |
| 1096 TEST_P(QuicConnectionTest, IncreaseServerMaxPacketSizeWhileWriterLimited) { |
| 1097 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1098 |
| 1099 const QuicByteCount lower_max_packet_size = 1240; |
| 1100 writer_->set_max_packet_size(lower_max_packet_size); |
| 1101 connection_.set_perspective(Perspective::IS_SERVER); |
| 1102 connection_.SetMaxPacketLength(1000); |
| 1103 EXPECT_EQ(1000u, connection_.max_packet_length()); |
| 1104 |
| 1105 QuicPacketHeader header; |
| 1106 header.public_header.connection_id = connection_id_; |
| 1107 header.public_header.version_flag = true; |
| 1108 header.packet_packet_number = 1; |
| 1109 |
| 1110 QuicFrames frames; |
| 1111 QuicPaddingFrame padding; |
| 1112 frames.push_back(QuicFrame(&frame1_)); |
| 1113 frames.push_back(QuicFrame(&padding)); |
| 1114 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); |
| 1115 char buffer[kMaxPacketSize]; |
| 1116 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( |
| 1117 ENCRYPTION_NONE, 12, *packet, buffer, kMaxPacketSize)); |
| 1118 EXPECT_EQ(kMaxPacketSize, encrypted->length()); |
| 1119 |
| 1120 framer_.set_version(version()); |
| 1121 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
| 1122 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); |
| 1123 |
| 1124 // Here, the limit imposed by the writer is lower than the size of the packet |
| 1125 // received, so the writer max packet size is used. |
| 1126 EXPECT_EQ(lower_max_packet_size, connection_.max_packet_length()); |
| 1127 } |
| 1128 |
| 1129 TEST_P(QuicConnectionTest, LimitMaxPacketSizeByWriter) { |
| 1130 const QuicByteCount lower_max_packet_size = 1240; |
| 1131 writer_->set_max_packet_size(lower_max_packet_size); |
| 1132 |
| 1133 static_assert(lower_max_packet_size < kDefaultMaxPacketSize, |
| 1134 "Default maximum packet size is too low"); |
| 1135 connection_.SetMaxPacketLength(kDefaultMaxPacketSize); |
| 1136 |
| 1137 EXPECT_EQ(lower_max_packet_size, connection_.max_packet_length()); |
| 1138 } |
| 1139 |
| 1140 TEST_P(QuicConnectionTest, LimitMaxPacketSizeByWriterForNewConnection) { |
| 1141 const QuicConnectionId connection_id = 17; |
| 1142 const QuicByteCount lower_max_packet_size = 1240; |
| 1143 writer_->set_max_packet_size(lower_max_packet_size); |
| 1144 TestConnection connection(connection_id, kPeerAddress, helper_.get(), |
| 1145 factory_, Perspective::IS_CLIENT, version()); |
| 1146 EXPECT_EQ(Perspective::IS_CLIENT, connection.perspective()); |
| 1147 EXPECT_EQ(lower_max_packet_size, connection.max_packet_length()); |
| 1148 } |
| 1149 |
1083 TEST_P(QuicConnectionTest, PacketsInOrder) { | 1150 TEST_P(QuicConnectionTest, PacketsInOrder) { |
1084 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1151 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
1085 | 1152 |
1086 ProcessPacket(1); | 1153 ProcessPacket(1); |
1087 EXPECT_EQ(1u, outgoing_ack()->largest_observed); | 1154 EXPECT_EQ(1u, outgoing_ack()->largest_observed); |
1088 EXPECT_EQ(0u, outgoing_ack()->missing_packets.size()); | 1155 EXPECT_EQ(0u, outgoing_ack()->missing_packets.size()); |
1089 | 1156 |
1090 ProcessPacket(2); | 1157 ProcessPacket(2); |
1091 EXPECT_EQ(2u, outgoing_ack()->largest_observed); | 1158 EXPECT_EQ(2u, outgoing_ack()->largest_observed); |
1092 EXPECT_EQ(0u, outgoing_ack()->missing_packets.size()); | 1159 EXPECT_EQ(0u, outgoing_ack()->missing_packets.size()); |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1651 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining | 1718 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining |
1652 // packet length. The size of the offset field in a stream frame is 0 for | 1719 // packet length. The size of the offset field in a stream frame is 0 for |
1653 // offset 0, and 2 for non-zero offsets up through 64K. Increase | 1720 // offset 0, and 2 for non-zero offsets up through 64K. Increase |
1654 // max_packet_length by 2 so that subsequent packets containing subsequent | 1721 // max_packet_length by 2 so that subsequent packets containing subsequent |
1655 // stream frames with non-zero offets will fit within the packet length. | 1722 // stream frames with non-zero offets will fit within the packet length. |
1656 size_t length = | 1723 size_t length = |
1657 2 + GetPacketLengthForOneStream(connection_.version(), kIncludeVersion, | 1724 2 + GetPacketLengthForOneStream(connection_.version(), kIncludeVersion, |
1658 PACKET_8BYTE_CONNECTION_ID, | 1725 PACKET_8BYTE_CONNECTION_ID, |
1659 PACKET_1BYTE_PACKET_NUMBER, IN_FEC_GROUP, | 1726 PACKET_1BYTE_PACKET_NUMBER, IN_FEC_GROUP, |
1660 &payload_length); | 1727 &payload_length); |
1661 connection_.set_max_packet_length(length); | 1728 connection_.SetMaxPacketLength(length); |
1662 | 1729 |
1663 if (generator_->fec_send_policy() == FEC_ALARM_TRIGGER) { | 1730 if (generator_->fec_send_policy() == FEC_ALARM_TRIGGER) { |
1664 // Send 4 protected data packets. FEC packet is not sent. | 1731 // Send 4 protected data packets. FEC packet is not sent. |
1665 EXPECT_CALL(*send_algorithm_, | 1732 EXPECT_CALL(*send_algorithm_, |
1666 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(4); | 1733 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(4); |
1667 } else { | 1734 } else { |
1668 // Send 4 protected data packets, which should also trigger 1 FEC packet. | 1735 // Send 4 protected data packets, which should also trigger 1 FEC packet. |
1669 EXPECT_CALL(*send_algorithm_, | 1736 EXPECT_CALL(*send_algorithm_, |
1670 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(5); | 1737 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(5); |
1671 } | 1738 } |
1672 // The first stream frame will have 2 fewer overhead bytes than the other 3. | 1739 // The first stream frame will have 2 fewer overhead bytes than the other 3. |
1673 const string payload(payload_length * 4 + 2, 'a'); | 1740 const string payload(payload_length * 4 + 2, 'a'); |
1674 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); | 1741 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); |
1675 // Expect the FEC group to be closed after SendStreamDataWithString. | 1742 // Expect the FEC group to be closed after SendStreamDataWithString. |
1676 EXPECT_FALSE(creator_->IsFecGroupOpen()); | 1743 EXPECT_FALSE(creator_->IsFecGroupOpen()); |
1677 EXPECT_FALSE(creator_->IsFecProtected()); | 1744 EXPECT_FALSE(creator_->IsFecProtected()); |
1678 } | 1745 } |
1679 | 1746 |
1680 TEST_P(QuicConnectionTest, FECQueueing) { | 1747 TEST_P(QuicConnectionTest, FECQueueing) { |
1681 // All packets carry version info till version is negotiated. | 1748 // All packets carry version info till version is negotiated. |
1682 size_t payload_length; | 1749 size_t payload_length; |
1683 size_t length = GetPacketLengthForOneStream( | 1750 size_t length = GetPacketLengthForOneStream( |
1684 connection_.version(), kIncludeVersion, PACKET_8BYTE_CONNECTION_ID, | 1751 connection_.version(), kIncludeVersion, PACKET_8BYTE_CONNECTION_ID, |
1685 PACKET_1BYTE_PACKET_NUMBER, IN_FEC_GROUP, &payload_length); | 1752 PACKET_1BYTE_PACKET_NUMBER, IN_FEC_GROUP, &payload_length); |
1686 connection_.set_max_packet_length(length); | 1753 connection_.SetMaxPacketLength(length); |
1687 EXPECT_TRUE(creator_->IsFecEnabled()); | 1754 EXPECT_TRUE(creator_->IsFecEnabled()); |
1688 | 1755 |
1689 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1756 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
1690 BlockOnNextWrite(); | 1757 BlockOnNextWrite(); |
1691 const string payload(payload_length, 'a'); | 1758 const string payload(payload_length, 'a'); |
1692 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); | 1759 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); |
1693 EXPECT_FALSE(creator_->IsFecGroupOpen()); | 1760 EXPECT_FALSE(creator_->IsFecGroupOpen()); |
1694 EXPECT_FALSE(creator_->IsFecProtected()); | 1761 EXPECT_FALSE(creator_->IsFecProtected()); |
1695 if (generator_->fec_send_policy() == FEC_ALARM_TRIGGER) { | 1762 if (generator_->fec_send_policy() == FEC_ALARM_TRIGGER) { |
1696 // Expect the first data packet to be queued and not the FEC packet. | 1763 // Expect the first data packet to be queued and not the FEC packet. |
(...skipping 1716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3413 const QuicPacketCount packets_between_probes = | 3480 const QuicPacketCount packets_between_probes = |
3414 packets_between_probes_base * ((1 << (i + 1)) - 1); | 3481 packets_between_probes_base * ((1 << (i + 1)) - 1); |
3415 EXPECT_EQ(packets_between_probes + (i + 1), mtu_discovery_packets[i]); | 3482 EXPECT_EQ(packets_between_probes + (i + 1), mtu_discovery_packets[i]); |
3416 } | 3483 } |
3417 | 3484 |
3418 EXPECT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); | 3485 EXPECT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); |
3419 EXPECT_EQ(kDefaultMaxPacketSize, connection_.max_packet_length()); | 3486 EXPECT_EQ(kDefaultMaxPacketSize, connection_.max_packet_length()); |
3420 EXPECT_EQ(kMtuDiscoveryAttempts, connection_.mtu_probe_count()); | 3487 EXPECT_EQ(kMtuDiscoveryAttempts, connection_.mtu_probe_count()); |
3421 } | 3488 } |
3422 | 3489 |
| 3490 // Tests whether MTU discovery works when the writer has a limit on how large a |
| 3491 // packet can be. |
| 3492 TEST_P(QuicConnectionTest, MtuDiscoveryWriterLimited) { |
| 3493 EXPECT_TRUE(connection_.connected()); |
| 3494 |
| 3495 const QuicByteCount mtu_limit = kMtuDiscoveryTargetPacketSizeHigh - 1; |
| 3496 writer_->set_max_packet_size(mtu_limit); |
| 3497 connection_.EnablePathMtuDiscovery(send_algorithm_); |
| 3498 |
| 3499 // Send enough packets so that the next one triggers path MTU discovery. |
| 3500 for (QuicPacketCount i = 0; i < kPacketsBetweenMtuProbesBase - 1; i++) { |
| 3501 SendStreamDataToPeer(3, ".", i, /*fin=*/false, nullptr); |
| 3502 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); |
| 3503 } |
| 3504 |
| 3505 // Trigger the probe. |
| 3506 SendStreamDataToPeer(3, "!", kPacketsBetweenMtuProbesBase, |
| 3507 /*fin=*/false, nullptr); |
| 3508 ASSERT_TRUE(connection_.GetMtuDiscoveryAlarm()->IsSet()); |
| 3509 QuicByteCount probe_size; |
| 3510 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 3511 .WillOnce(DoAll(SaveArg<3>(&probe_size), Return(true))); |
| 3512 connection_.GetMtuDiscoveryAlarm()->Fire(); |
| 3513 EXPECT_EQ(mtu_limit, probe_size); |
| 3514 |
| 3515 const QuicPacketCount probe_sequence_number = |
| 3516 kPacketsBetweenMtuProbesBase + 1; |
| 3517 ASSERT_EQ(probe_sequence_number, creator_->packet_number()); |
| 3518 |
| 3519 // Acknowledge all packets sent so far. |
| 3520 QuicAckFrame probe_ack = InitAckFrame(probe_sequence_number); |
| 3521 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3522 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 3523 ProcessAckPacket(&probe_ack); |
| 3524 EXPECT_EQ(mtu_limit, connection_.max_packet_length()); |
| 3525 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); |
| 3526 |
| 3527 // Send more packets, and ensure that none of them sets the alarm. |
| 3528 for (QuicPacketCount i = 0; i < 4 * kPacketsBetweenMtuProbesBase; i++) { |
| 3529 SendStreamDataToPeer(3, ".", i, /*fin=*/false, nullptr); |
| 3530 ASSERT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); |
| 3531 } |
| 3532 |
| 3533 EXPECT_EQ(1u, connection_.mtu_probe_count()); |
| 3534 } |
| 3535 |
3423 TEST_P(QuicConnectionTest, NoMtuDiscoveryAfterConnectionClosed) { | 3536 TEST_P(QuicConnectionTest, NoMtuDiscoveryAfterConnectionClosed) { |
3424 EXPECT_TRUE(connection_.connected()); | 3537 EXPECT_TRUE(connection_.connected()); |
3425 | 3538 |
3426 // Restore the current value FLAGS_quic_do_path_mtu_discovery after the test. | 3539 // Restore the current value FLAGS_quic_do_path_mtu_discovery after the test. |
3427 ValueRestore<bool> old_flag(&FLAGS_quic_do_path_mtu_discovery, true); | 3540 ValueRestore<bool> old_flag(&FLAGS_quic_do_path_mtu_discovery, true); |
3428 connection_.EnablePathMtuDiscovery(send_algorithm_); | 3541 connection_.EnablePathMtuDiscovery(send_algorithm_); |
3429 | 3542 |
3430 // Send enough packets so that the next one triggers path MTU discovery. | 3543 // Send enough packets so that the next one triggers path MTU discovery. |
3431 for (QuicPacketCount i = 0; i < kPacketsBetweenMtuProbesBase - 1; i++) { | 3544 for (QuicPacketCount i = 0; i < kPacketsBetweenMtuProbesBase - 1; i++) { |
3432 SendStreamDataToPeer(3, ".", i, /*fin=*/false, nullptr); | 3545 SendStreamDataToPeer(3, ".", i, /*fin=*/false, nullptr); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3557 HAS_RETRANSMITTABLE_DATA, false, false); | 3670 HAS_RETRANSMITTABLE_DATA, false, false); |
3558 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 3671 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
3559 } | 3672 } |
3560 | 3673 |
3561 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { | 3674 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { |
3562 // All packets carry version info till version is negotiated. | 3675 // All packets carry version info till version is negotiated. |
3563 size_t payload_length; | 3676 size_t payload_length; |
3564 size_t length = GetPacketLengthForOneStream( | 3677 size_t length = GetPacketLengthForOneStream( |
3565 connection_.version(), kIncludeVersion, PACKET_8BYTE_CONNECTION_ID, | 3678 connection_.version(), kIncludeVersion, PACKET_8BYTE_CONNECTION_ID, |
3566 PACKET_1BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP, &payload_length); | 3679 PACKET_1BYTE_PACKET_NUMBER, NOT_IN_FEC_GROUP, &payload_length); |
3567 connection_.set_max_packet_length(length); | 3680 connection_.SetMaxPacketLength(length); |
3568 | 3681 |
3569 // Queue the first packet. | 3682 // Queue the first packet. |
3570 EXPECT_CALL(*send_algorithm_, | 3683 EXPECT_CALL(*send_algorithm_, |
3571 TimeUntilSend(_, _, _)).WillOnce( | 3684 TimeUntilSend(_, _, _)).WillOnce( |
3572 testing::Return(QuicTime::Delta::FromMicroseconds(10))); | 3685 testing::Return(QuicTime::Delta::FromMicroseconds(10))); |
3573 const string payload(payload_length, 'a'); | 3686 const string payload(payload_length, 'a'); |
3574 EXPECT_EQ(0u, connection_.SendStreamDataWithString(3, payload, 0, !kFin, | 3687 EXPECT_EQ(0u, connection_.SendStreamDataWithString(3, payload, 0, !kFin, |
3575 nullptr).bytes_consumed); | 3688 nullptr).bytes_consumed); |
3576 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 3689 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
3577 } | 3690 } |
3578 | 3691 |
3579 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { | 3692 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { |
3580 // All packets carry version info till version is negotiated. | 3693 // All packets carry version info till version is negotiated. |
3581 size_t payload_length; | 3694 size_t payload_length; |
3582 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining | 3695 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining |
3583 // packet length. The size of the offset field in a stream frame is 0 for | 3696 // packet length. The size of the offset field in a stream frame is 0 for |
3584 // offset 0, and 2 for non-zero offsets up through 16K. Increase | 3697 // offset 0, and 2 for non-zero offsets up through 16K. Increase |
3585 // max_packet_length by 2 so that subsequent packets containing subsequent | 3698 // max_packet_length by 2 so that subsequent packets containing subsequent |
3586 // stream frames with non-zero offets will fit within the packet length. | 3699 // stream frames with non-zero offets will fit within the packet length. |
3587 size_t length = | 3700 size_t length = |
3588 2 + GetPacketLengthForOneStream(connection_.version(), kIncludeVersion, | 3701 2 + GetPacketLengthForOneStream(connection_.version(), kIncludeVersion, |
3589 PACKET_8BYTE_CONNECTION_ID, | 3702 PACKET_8BYTE_CONNECTION_ID, |
3590 PACKET_1BYTE_PACKET_NUMBER, | 3703 PACKET_1BYTE_PACKET_NUMBER, |
3591 NOT_IN_FEC_GROUP, &payload_length); | 3704 NOT_IN_FEC_GROUP, &payload_length); |
3592 connection_.set_max_packet_length(length); | 3705 connection_.SetMaxPacketLength(length); |
3593 | 3706 |
3594 // Queue the first packet. | 3707 // Queue the first packet. |
3595 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7); | 3708 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7); |
3596 // The first stream frame will have 2 fewer overhead bytes than the other six. | 3709 // The first stream frame will have 2 fewer overhead bytes than the other six. |
3597 const string payload(payload_length * 7 + 2, 'a'); | 3710 const string payload(payload_length * 7 + 2, 'a'); |
3598 EXPECT_EQ(payload.size(), | 3711 EXPECT_EQ(payload.size(), |
3599 connection_.SendStreamDataWithString(1, payload, 0, !kFin, nullptr) | 3712 connection_.SendStreamDataWithString(1, payload, 0, !kFin, nullptr) |
3600 .bytes_consumed); | 3713 .bytes_consumed); |
3601 } | 3714 } |
3602 | 3715 |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3865 | 3978 |
3866 TEST_P(QuicConnectionTest, PublicReset) { | 3979 TEST_P(QuicConnectionTest, PublicReset) { |
3867 QuicPublicResetPacket header; | 3980 QuicPublicResetPacket header; |
3868 header.public_header.connection_id = connection_id_; | 3981 header.public_header.connection_id = connection_id_; |
3869 header.public_header.reset_flag = true; | 3982 header.public_header.reset_flag = true; |
3870 header.public_header.version_flag = false; | 3983 header.public_header.version_flag = false; |
3871 header.rejected_packet_number = 10101; | 3984 header.rejected_packet_number = 10101; |
3872 scoped_ptr<QuicEncryptedPacket> packet( | 3985 scoped_ptr<QuicEncryptedPacket> packet( |
3873 framer_.BuildPublicResetPacket(header)); | 3986 framer_.BuildPublicResetPacket(header)); |
3874 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PUBLIC_RESET, true)); | 3987 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PUBLIC_RESET, true)); |
3875 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *packet); | 3988 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *packet); |
3876 } | 3989 } |
3877 | 3990 |
3878 TEST_P(QuicConnectionTest, GoAway) { | 3991 TEST_P(QuicConnectionTest, GoAway) { |
3879 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3992 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3880 | 3993 |
3881 QuicGoAwayFrame goaway; | 3994 QuicGoAwayFrame goaway; |
3882 goaway.last_good_stream_id = 1; | 3995 goaway.last_good_stream_id = 1; |
3883 goaway.error_code = QUIC_PEER_GOING_AWAY; | 3996 goaway.error_code = QUIC_PEER_GOING_AWAY; |
3884 goaway.reason_phrase = "Going away."; | 3997 goaway.reason_phrase = "Going away."; |
3885 EXPECT_CALL(visitor_, OnGoAway(_)); | 3998 EXPECT_CALL(visitor_, OnGoAway(_)); |
(...skipping 16 matching lines...) Expand all Loading... |
3902 QuicBlockedFrame blocked; | 4015 QuicBlockedFrame blocked; |
3903 blocked.stream_id = 3; | 4016 blocked.stream_id = 3; |
3904 EXPECT_CALL(visitor_, OnBlockedFrame(_)); | 4017 EXPECT_CALL(visitor_, OnBlockedFrame(_)); |
3905 ProcessFramePacket(QuicFrame(&blocked)); | 4018 ProcessFramePacket(QuicFrame(&blocked)); |
3906 } | 4019 } |
3907 | 4020 |
3908 TEST_P(QuicConnectionTest, ZeroBytePacket) { | 4021 TEST_P(QuicConnectionTest, ZeroBytePacket) { |
3909 // Don't close the connection for zero byte packets. | 4022 // Don't close the connection for zero byte packets. |
3910 EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(0); | 4023 EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(0); |
3911 QuicEncryptedPacket encrypted(nullptr, 0); | 4024 QuicEncryptedPacket encrypted(nullptr, 0); |
3912 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), encrypted); | 4025 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, encrypted); |
3913 } | 4026 } |
3914 | 4027 |
3915 TEST_P(QuicConnectionTest, MissingPacketsBeforeLeastUnacked) { | 4028 TEST_P(QuicConnectionTest, MissingPacketsBeforeLeastUnacked) { |
3916 // Set the packet number of the ack packet to be least unacked (4). | 4029 // Set the packet number of the ack packet to be least unacked (4). |
3917 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 3); | 4030 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 3); |
3918 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4031 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3919 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); | 4032 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); |
3920 ProcessStopWaitingPacket(&frame); | 4033 ProcessStopWaitingPacket(&frame); |
3921 EXPECT_TRUE(outgoing_ack()->missing_packets.empty()); | 4034 EXPECT_TRUE(outgoing_ack()->missing_packets.empty()); |
3922 } | 4035 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4020 | 4133 |
4021 QuicFrames frames; | 4134 QuicFrames frames; |
4022 frames.push_back(QuicFrame(&frame1_)); | 4135 frames.push_back(QuicFrame(&frame1_)); |
4023 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); | 4136 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); |
4024 char buffer[kMaxPacketSize]; | 4137 char buffer[kMaxPacketSize]; |
4025 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( | 4138 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( |
4026 ENCRYPTION_NONE, 12, *packet, buffer, kMaxPacketSize)); | 4139 ENCRYPTION_NONE, 12, *packet, buffer, kMaxPacketSize)); |
4027 | 4140 |
4028 framer_.set_version(version()); | 4141 framer_.set_version(version()); |
4029 connection_.set_perspective(Perspective::IS_SERVER); | 4142 connection_.set_perspective(Perspective::IS_SERVER); |
4030 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 4143 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); |
4031 EXPECT_TRUE(writer_->version_negotiation_packet() != nullptr); | 4144 EXPECT_TRUE(writer_->version_negotiation_packet() != nullptr); |
4032 | 4145 |
4033 size_t num_versions = arraysize(kSupportedQuicVersions); | 4146 size_t num_versions = arraysize(kSupportedQuicVersions); |
4034 ASSERT_EQ(num_versions, | 4147 ASSERT_EQ(num_versions, |
4035 writer_->version_negotiation_packet()->versions.size()); | 4148 writer_->version_negotiation_packet()->versions.size()); |
4036 | 4149 |
4037 // We expect all versions in kSupportedQuicVersions to be | 4150 // We expect all versions in kSupportedQuicVersions to be |
4038 // included in the packet. | 4151 // included in the packet. |
4039 for (size_t i = 0; i < num_versions; ++i) { | 4152 for (size_t i = 0; i < num_versions; ++i) { |
4040 EXPECT_EQ(kSupportedQuicVersions[i], | 4153 EXPECT_EQ(kSupportedQuicVersions[i], |
(...skipping 13 matching lines...) Expand all Loading... |
4054 QuicFrames frames; | 4167 QuicFrames frames; |
4055 frames.push_back(QuicFrame(&frame1_)); | 4168 frames.push_back(QuicFrame(&frame1_)); |
4056 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); | 4169 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); |
4057 char buffer[kMaxPacketSize]; | 4170 char buffer[kMaxPacketSize]; |
4058 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( | 4171 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( |
4059 ENCRYPTION_NONE, 12, *packet, buffer, kMaxPacketSize)); | 4172 ENCRYPTION_NONE, 12, *packet, buffer, kMaxPacketSize)); |
4060 | 4173 |
4061 framer_.set_version(version()); | 4174 framer_.set_version(version()); |
4062 connection_.set_perspective(Perspective::IS_SERVER); | 4175 connection_.set_perspective(Perspective::IS_SERVER); |
4063 BlockOnNextWrite(); | 4176 BlockOnNextWrite(); |
4064 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 4177 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); |
4065 EXPECT_EQ(0u, writer_->last_packet_size()); | 4178 EXPECT_EQ(0u, writer_->last_packet_size()); |
4066 EXPECT_TRUE(connection_.HasQueuedData()); | 4179 EXPECT_TRUE(connection_.HasQueuedData()); |
4067 | 4180 |
4068 writer_->SetWritable(); | 4181 writer_->SetWritable(); |
4069 connection_.OnCanWrite(); | 4182 connection_.OnCanWrite(); |
4070 EXPECT_TRUE(writer_->version_negotiation_packet() != nullptr); | 4183 EXPECT_TRUE(writer_->version_negotiation_packet() != nullptr); |
4071 | 4184 |
4072 size_t num_versions = arraysize(kSupportedQuicVersions); | 4185 size_t num_versions = arraysize(kSupportedQuicVersions); |
4073 ASSERT_EQ(num_versions, | 4186 ASSERT_EQ(num_versions, |
4074 writer_->version_negotiation_packet()->versions.size()); | 4187 writer_->version_negotiation_packet()->versions.size()); |
(...skipping 20 matching lines...) Expand all Loading... |
4095 frames.push_back(QuicFrame(&frame1_)); | 4208 frames.push_back(QuicFrame(&frame1_)); |
4096 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); | 4209 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); |
4097 char buffer[kMaxPacketSize]; | 4210 char buffer[kMaxPacketSize]; |
4098 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( | 4211 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( |
4099 ENCRYPTION_NONE, 12, *packet, buffer, kMaxPacketSize)); | 4212 ENCRYPTION_NONE, 12, *packet, buffer, kMaxPacketSize)); |
4100 | 4213 |
4101 framer_.set_version(version()); | 4214 framer_.set_version(version()); |
4102 connection_.set_perspective(Perspective::IS_SERVER); | 4215 connection_.set_perspective(Perspective::IS_SERVER); |
4103 BlockOnNextWrite(); | 4216 BlockOnNextWrite(); |
4104 writer_->set_is_write_blocked_data_buffered(true); | 4217 writer_->set_is_write_blocked_data_buffered(true); |
4105 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 4218 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); |
4106 EXPECT_EQ(0u, writer_->last_packet_size()); | 4219 EXPECT_EQ(0u, writer_->last_packet_size()); |
4107 EXPECT_FALSE(connection_.HasQueuedData()); | 4220 EXPECT_FALSE(connection_.HasQueuedData()); |
4108 } | 4221 } |
4109 | 4222 |
4110 TEST_P(QuicConnectionTest, ClientHandlesVersionNegotiation) { | 4223 TEST_P(QuicConnectionTest, ClientHandlesVersionNegotiation) { |
4111 // Start out with some unsupported version. | 4224 // Start out with some unsupported version. |
4112 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests( | 4225 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests( |
4113 QUIC_VERSION_UNSUPPORTED); | 4226 QUIC_VERSION_UNSUPPORTED); |
4114 | 4227 |
4115 QuicPacketHeader header; | 4228 QuicPacketHeader header; |
4116 header.public_header.connection_id = connection_id_; | 4229 header.public_header.connection_id = connection_id_; |
4117 header.public_header.version_flag = true; | 4230 header.public_header.version_flag = true; |
4118 header.packet_packet_number = 12; | 4231 header.packet_packet_number = 12; |
4119 | 4232 |
4120 QuicVersionVector supported_versions; | 4233 QuicVersionVector supported_versions; |
4121 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { | 4234 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { |
4122 supported_versions.push_back(kSupportedQuicVersions[i]); | 4235 supported_versions.push_back(kSupportedQuicVersions[i]); |
4123 } | 4236 } |
4124 | 4237 |
4125 // Send a version negotiation packet. | 4238 // Send a version negotiation packet. |
4126 scoped_ptr<QuicEncryptedPacket> encrypted( | 4239 scoped_ptr<QuicEncryptedPacket> encrypted( |
4127 framer_.BuildVersionNegotiationPacket( | 4240 framer_.BuildVersionNegotiationPacket( |
4128 header.public_header, supported_versions)); | 4241 header.public_header, supported_versions)); |
4129 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 4242 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); |
4130 | 4243 |
4131 // Now force another packet. The connection should transition into | 4244 // Now force another packet. The connection should transition into |
4132 // NEGOTIATED_VERSION state and tell the packet creator to StopSendingVersion. | 4245 // NEGOTIATED_VERSION state and tell the packet creator to StopSendingVersion. |
4133 header.public_header.version_flag = false; | 4246 header.public_header.version_flag = false; |
4134 QuicFrames frames; | 4247 QuicFrames frames; |
4135 frames.push_back(QuicFrame(&frame1_)); | 4248 frames.push_back(QuicFrame(&frame1_)); |
4136 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); | 4249 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); |
4137 char buffer[kMaxPacketSize]; | 4250 char buffer[kMaxPacketSize]; |
4138 encrypted.reset(framer_.EncryptPayload(ENCRYPTION_NONE, 12, *packet, buffer, | 4251 encrypted.reset(framer_.EncryptPayload(ENCRYPTION_NONE, 12, *packet, buffer, |
4139 kMaxPacketSize)); | 4252 kMaxPacketSize)); |
4140 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 4253 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
4141 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4254 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
4142 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 4255 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); |
4143 | 4256 |
4144 ASSERT_FALSE(QuicPacketCreatorPeer::SendVersionInPacket(creator_)); | 4257 ASSERT_FALSE(QuicPacketCreatorPeer::SendVersionInPacket(creator_)); |
4145 } | 4258 } |
4146 | 4259 |
4147 TEST_P(QuicConnectionTest, BadVersionNegotiation) { | 4260 TEST_P(QuicConnectionTest, BadVersionNegotiation) { |
4148 QuicPacketHeader header; | 4261 QuicPacketHeader header; |
4149 header.public_header.connection_id = connection_id_; | 4262 header.public_header.connection_id = connection_id_; |
4150 header.public_header.version_flag = true; | 4263 header.public_header.version_flag = true; |
4151 header.packet_packet_number = 12; | 4264 header.packet_packet_number = 12; |
4152 | 4265 |
4153 QuicVersionVector supported_versions; | 4266 QuicVersionVector supported_versions; |
4154 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { | 4267 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { |
4155 supported_versions.push_back(kSupportedQuicVersions[i]); | 4268 supported_versions.push_back(kSupportedQuicVersions[i]); |
4156 } | 4269 } |
4157 | 4270 |
4158 // Send a version negotiation packet with the version the client started with. | 4271 // Send a version negotiation packet with the version the client started with. |
4159 // It should be rejected. | 4272 // It should be rejected. |
4160 EXPECT_CALL(visitor_, | 4273 EXPECT_CALL(visitor_, |
4161 OnConnectionClosed(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, | 4274 OnConnectionClosed(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, |
4162 false)); | 4275 false)); |
4163 scoped_ptr<QuicEncryptedPacket> encrypted( | 4276 scoped_ptr<QuicEncryptedPacket> encrypted( |
4164 framer_.BuildVersionNegotiationPacket( | 4277 framer_.BuildVersionNegotiationPacket( |
4165 header.public_header, supported_versions)); | 4278 header.public_header, supported_versions)); |
4166 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 4279 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); |
4167 } | 4280 } |
4168 | 4281 |
4169 TEST_P(QuicConnectionTest, CheckSendStats) { | 4282 TEST_P(QuicConnectionTest, CheckSendStats) { |
4170 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 4283 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
4171 connection_.SendStreamDataWithString(3, "first", 0, !kFin, nullptr); | 4284 connection_.SendStreamDataWithString(3, "first", 0, !kFin, nullptr); |
4172 size_t first_packet_size = writer_->last_packet_size(); | 4285 size_t first_packet_size = writer_->last_packet_size(); |
4173 | 4286 |
4174 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 4287 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
4175 connection_.SendStreamDataWithString(5, "second", 0, !kFin, nullptr); | 4288 connection_.SendStreamDataWithString(5, "second", 0, !kFin, nullptr); |
4176 size_t second_packet_size = writer_->last_packet_size(); | 4289 size_t second_packet_size = writer_->last_packet_size(); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4270 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); | 4383 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); |
4271 EXPECT_TRUE(nullptr != packet.get()); | 4384 EXPECT_TRUE(nullptr != packet.get()); |
4272 char buffer[kMaxPacketSize]; | 4385 char buffer[kMaxPacketSize]; |
4273 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( | 4386 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( |
4274 ENCRYPTION_NONE, 1, *packet, buffer, kMaxPacketSize)); | 4387 ENCRYPTION_NONE, 1, *packet, buffer, kMaxPacketSize)); |
4275 | 4388 |
4276 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, true)); | 4389 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, true)); |
4277 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 4390 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
4278 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4391 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
4279 | 4392 |
4280 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 4393 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *encrypted); |
4281 } | 4394 } |
4282 | 4395 |
4283 TEST_P(QuicConnectionTest, SelectMutualVersion) { | 4396 TEST_P(QuicConnectionTest, SelectMutualVersion) { |
4284 connection_.SetSupportedVersions(QuicSupportedVersions()); | 4397 connection_.SetSupportedVersions(QuicSupportedVersions()); |
4285 // Set the connection to speak the lowest quic version. | 4398 // Set the connection to speak the lowest quic version. |
4286 connection_.set_version(QuicVersionMin()); | 4399 connection_.set_version(QuicVersionMin()); |
4287 EXPECT_EQ(QuicVersionMin(), connection_.version()); | 4400 EXPECT_EQ(QuicVersionMin(), connection_.version()); |
4288 | 4401 |
4289 // Pass in available versions which includes a higher mutually supported | 4402 // Pass in available versions which includes a higher mutually supported |
4290 // version. The higher mutually supported version should be selected. | 4403 // version. The higher mutually supported version should be selected. |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4615 QuicPacketHeader header; | 4728 QuicPacketHeader header; |
4616 | 4729 |
4617 scoped_ptr<MockQuicConnectionDebugVisitor> debug_visitor( | 4730 scoped_ptr<MockQuicConnectionDebugVisitor> debug_visitor( |
4618 new MockQuicConnectionDebugVisitor()); | 4731 new MockQuicConnectionDebugVisitor()); |
4619 connection_.set_debug_visitor(debug_visitor.get()); | 4732 connection_.set_debug_visitor(debug_visitor.get()); |
4620 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); | 4733 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); |
4621 connection_.OnPacketHeader(header); | 4734 connection_.OnPacketHeader(header); |
4622 } | 4735 } |
4623 | 4736 |
4624 TEST_P(QuicConnectionTest, Pacing) { | 4737 TEST_P(QuicConnectionTest, Pacing) { |
4625 TestConnection server(connection_id_, IPEndPoint(), helper_.get(), factory_, | 4738 TestConnection server(connection_id_, kSelfAddress, helper_.get(), factory_, |
4626 Perspective::IS_SERVER, version()); | 4739 Perspective::IS_SERVER, version()); |
4627 TestConnection client(connection_id_, IPEndPoint(), helper_.get(), factory_, | 4740 TestConnection client(connection_id_, kPeerAddress, helper_.get(), factory_, |
4628 Perspective::IS_CLIENT, version()); | 4741 Perspective::IS_CLIENT, version()); |
4629 EXPECT_FALSE(client.sent_packet_manager().using_pacing()); | 4742 EXPECT_FALSE(client.sent_packet_manager().using_pacing()); |
4630 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); | 4743 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); |
4631 } | 4744 } |
4632 | 4745 |
4633 TEST_P(QuicConnectionTest, ControlFramesInstigateAcks) { | 4746 TEST_P(QuicConnectionTest, ControlFramesInstigateAcks) { |
4634 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4747 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
4635 | 4748 |
4636 // Send a WINDOW_UPDATE frame. | 4749 // Send a WINDOW_UPDATE frame. |
4637 QuicWindowUpdateFrame window_update; | 4750 QuicWindowUpdateFrame window_update; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4705 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 4818 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
4706 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); | 4819 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); |
4707 EXPECT_TRUE(connection_.goaway_sent()); | 4820 EXPECT_TRUE(connection_.goaway_sent()); |
4708 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); | 4821 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); |
4709 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); | 4822 connection_.SendGoAway(QUIC_PEER_GOING_AWAY, kHeadersStreamId, "Going Away."); |
4710 } | 4823 } |
4711 | 4824 |
4712 } // namespace | 4825 } // namespace |
4713 } // namespace test | 4826 } // namespace test |
4714 } // namespace net | 4827 } // namespace net |
OLD | NEW |