| 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/bind.h" |
| 7 #include "net/base/net_errors.h" | 8 #include "net/base/net_errors.h" |
| 8 #include "net/quic/congestion_control/receive_algorithm_interface.h" | 9 #include "net/quic/congestion_control/receive_algorithm_interface.h" |
| 9 #include "net/quic/congestion_control/send_algorithm_interface.h" | 10 #include "net/quic/congestion_control/send_algorithm_interface.h" |
| 10 #include "net/quic/crypto/null_encrypter.h" | 11 #include "net/quic/crypto/null_encrypter.h" |
| 11 #include "net/quic/crypto/quic_decrypter.h" | 12 #include "net/quic/crypto/quic_decrypter.h" |
| 12 #include "net/quic/crypto/quic_encrypter.h" | 13 #include "net/quic/crypto/quic_encrypter.h" |
| 14 #include "net/quic/crypto/quic_random.h" |
| 13 #include "net/quic/test_tools/mock_clock.h" | 15 #include "net/quic/test_tools/mock_clock.h" |
| 16 #include "net/quic/test_tools/mock_random.h" |
| 14 #include "net/quic/test_tools/quic_connection_peer.h" | 17 #include "net/quic/test_tools/quic_connection_peer.h" |
| 15 #include "net/quic/test_tools/quic_test_utils.h" | 18 #include "net/quic/test_tools/quic_test_utils.h" |
| 16 #include "net/quic/quic_utils.h" | 19 #include "net/quic/quic_utils.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 22 |
| 20 using base::StringPiece; | 23 using base::StringPiece; |
| 21 using std::map; | 24 using std::map; |
| 25 using std::vector; |
| 22 using testing::_; | 26 using testing::_; |
| 23 using testing::AnyNumber; | 27 using testing::AnyNumber; |
| 24 using testing::Between; | 28 using testing::Between; |
| 25 using testing::ContainerEq; | 29 using testing::ContainerEq; |
| 30 using testing::DoAll; |
| 26 using testing::InSequence; | 31 using testing::InSequence; |
| 32 using testing::InvokeWithoutArgs; |
| 27 using testing::Return; | 33 using testing::Return; |
| 28 using testing::StrictMock; | 34 using testing::StrictMock; |
| 29 using testing::SaveArg; | 35 using testing::SaveArg; |
| 30 | 36 |
| 31 namespace net { | 37 namespace net { |
| 32 namespace test { | 38 namespace test { |
| 33 namespace { | 39 namespace { |
| 34 | 40 |
| 35 const char data1[] = "foo"; | 41 const char data1[] = "foo"; |
| 36 const char data2[] = "bar"; | 42 const char data2[] = "bar"; |
| 37 | 43 |
| 44 const bool kFin = true; |
| 45 const bool kForce = true; |
| 46 const bool kIsRetransmission = true; |
| 47 const bool kEntropyFlag = true; |
| 48 const bool kFecEntropyFlag = true; |
| 49 const QuicPacketEntropyHash kTestEntropyHash = 76; |
| 50 |
| 38 class TestReceiveAlgorithm : public ReceiveAlgorithmInterface { | 51 class TestReceiveAlgorithm : public ReceiveAlgorithmInterface { |
| 39 public: | 52 public: |
| 40 explicit TestReceiveAlgorithm(QuicCongestionFeedbackFrame* feedback) | 53 explicit TestReceiveAlgorithm(QuicCongestionFeedbackFrame* feedback) |
| 41 : feedback_(feedback) { | 54 : feedback_(feedback) { |
| 42 } | 55 } |
| 43 | 56 |
| 44 bool GenerateCongestionFeedback( | 57 bool GenerateCongestionFeedback( |
| 45 QuicCongestionFeedbackFrame* congestion_feedback) { | 58 QuicCongestionFeedbackFrame* congestion_feedback) { |
| 46 if (feedback_ == NULL) { | 59 if (feedback_ == NULL) { |
| 47 return false; | 60 return false; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 58 | 71 |
| 59 DISALLOW_COPY_AND_ASSIGN(TestReceiveAlgorithm); | 72 DISALLOW_COPY_AND_ASSIGN(TestReceiveAlgorithm); |
| 60 }; | 73 }; |
| 61 | 74 |
| 62 class TestConnectionHelper : public QuicConnectionHelperInterface { | 75 class TestConnectionHelper : public QuicConnectionHelperInterface { |
| 63 public: | 76 public: |
| 64 TestConnectionHelper(MockClock* clock, MockRandom* random_generator) | 77 TestConnectionHelper(MockClock* clock, MockRandom* random_generator) |
| 65 : clock_(clock), | 78 : clock_(clock), |
| 66 random_generator_(random_generator), | 79 random_generator_(random_generator), |
| 67 retransmission_alarm_(QuicTime::Zero()), | 80 retransmission_alarm_(QuicTime::Zero()), |
| 68 send_alarm_(QuicTime::Zero()), | 81 send_alarm_(QuicTime::FromMilliseconds(-1)), |
| 69 timeout_alarm_(QuicTime::Zero()), | 82 timeout_alarm_(QuicTime::Zero()), |
| 70 blocked_(false) { | 83 blocked_(false) { |
| 71 } | 84 } |
| 72 | 85 |
| 73 // QuicConnectionHelperInterface | 86 // QuicConnectionHelperInterface |
| 74 virtual void SetConnection(QuicConnection* connection) OVERRIDE {} | 87 virtual void SetConnection(QuicConnection* connection) OVERRIDE {} |
| 75 | 88 |
| 76 virtual const QuicClock* GetClock() const OVERRIDE { | 89 virtual const QuicClock* GetClock() const OVERRIDE { |
| 77 return clock_; | 90 return clock_; |
| 78 } | 91 } |
| 79 | 92 |
| 80 virtual QuicRandom* GetRandomGenerator() OVERRIDE { | 93 virtual QuicRandom* GetRandomGenerator() OVERRIDE { |
| 81 return random_generator_; | 94 return random_generator_; |
| 82 } | 95 } |
| 83 | 96 |
| 84 virtual int WritePacketToWire(const QuicEncryptedPacket& packet, | 97 virtual int WritePacketToWire(const QuicEncryptedPacket& packet, |
| 85 int* error) OVERRIDE { | 98 int* error) OVERRIDE { |
| 86 QuicFramer framer(QuicDecrypter::Create(kNULL), | 99 QuicFramer framer(QuicDecrypter::Create(kNULL), |
| 87 QuicEncrypter::Create(kNULL)); | 100 QuicEncrypter::Create(kNULL)); |
| 88 FramerVisitorCapturingAcks visitor; | 101 FramerVisitorCapturingFrames visitor; |
| 89 framer.set_visitor(&visitor); | 102 framer.set_visitor(&visitor); |
| 90 EXPECT_TRUE(framer.ProcessPacket(packet)); | 103 EXPECT_TRUE(framer.ProcessPacket(packet)); |
| 91 header_ = *visitor.header(); | 104 header_ = *visitor.header(); |
| 105 frame_count_ = visitor.frame_count(); |
| 92 if (visitor.ack()) { | 106 if (visitor.ack()) { |
| 93 ack_.reset(new QuicAckFrame(*visitor.ack())); | 107 ack_.reset(new QuicAckFrame(*visitor.ack())); |
| 94 } | 108 } |
| 95 if (visitor.feedback()) { | 109 if (visitor.feedback()) { |
| 96 feedback_.reset(new QuicCongestionFeedbackFrame(*visitor.feedback())); | 110 feedback_.reset(new QuicCongestionFeedbackFrame(*visitor.feedback())); |
| 97 } | 111 } |
| 112 if (visitor.stream_frames() != NULL && !visitor.stream_frames()->empty()) { |
| 113 stream_frames_ = *visitor.stream_frames(); |
| 114 } |
| 98 if (blocked_) { | 115 if (blocked_) { |
| 99 *error = ERR_IO_PENDING; | 116 *error = ERR_IO_PENDING; |
| 100 return -1; | 117 return -1; |
| 101 } | 118 } |
| 102 *error = 0; | 119 *error = 0; |
| 103 return packet.length(); | 120 return packet.length(); |
| 104 } | 121 } |
| 105 | 122 |
| 106 virtual void SetRetransmissionAlarm(QuicTime::Delta delay) OVERRIDE { | 123 virtual void SetRetransmissionAlarm(QuicTime::Delta delay) OVERRIDE { |
| 107 retransmission_alarm_ = clock_->Now().Add(delay); | 124 retransmission_alarm_ = clock_->ApproximateNow().Add(delay); |
| 108 } | 125 } |
| 109 | 126 |
| 110 virtual void SetSendAlarm(QuicTime::Delta delay) OVERRIDE { | 127 virtual void SetSendAlarm(QuicTime::Delta delay) OVERRIDE { |
| 111 send_alarm_ = clock_->Now().Add(delay); | 128 send_alarm_ = clock_->ApproximateNow().Add(delay); |
| 112 } | 129 } |
| 113 | 130 |
| 114 virtual void SetTimeoutAlarm(QuicTime::Delta delay) OVERRIDE { | 131 virtual void SetTimeoutAlarm(QuicTime::Delta delay) OVERRIDE { |
| 115 timeout_alarm_ = clock_->Now().Add(delay); | 132 timeout_alarm_ = clock_->ApproximateNow().Add(delay); |
| 116 } | 133 } |
| 117 | 134 |
| 118 virtual bool IsSendAlarmSet() OVERRIDE { | 135 virtual bool IsSendAlarmSet() OVERRIDE { |
| 119 return send_alarm_ > clock_->Now(); | 136 return send_alarm_ >= clock_->ApproximateNow(); |
| 120 } | 137 } |
| 121 | 138 |
| 122 virtual void UnregisterSendAlarmIfRegistered() OVERRIDE { | 139 virtual void UnregisterSendAlarmIfRegistered() OVERRIDE { |
| 123 send_alarm_ = QuicTime::Zero(); | 140 send_alarm_ = QuicTime::FromMilliseconds(-1); |
| 124 } | 141 } |
| 125 | 142 |
| 126 virtual void SetAckAlarm(QuicTime::Delta delay) OVERRIDE {} | 143 virtual void SetAckAlarm(QuicTime::Delta delay) OVERRIDE {} |
| 127 virtual void ClearAckAlarm() OVERRIDE {} | 144 virtual void ClearAckAlarm() OVERRIDE {} |
| 128 | 145 |
| 129 QuicTime retransmission_alarm() const { | 146 QuicTime retransmission_alarm() const { |
| 130 return retransmission_alarm_; | 147 return retransmission_alarm_; |
| 131 } | 148 } |
| 132 | 149 |
| 133 QuicTime timeout_alarm() const { return timeout_alarm_; } | 150 QuicTime timeout_alarm() const { return timeout_alarm_; } |
| 134 | 151 |
| 135 QuicPacketHeader* header() { return &header_; } | 152 QuicPacketHeader* header() { return &header_; } |
| 136 | 153 |
| 154 size_t frame_count() { return frame_count_; } |
| 155 |
| 137 QuicAckFrame* ack() { return ack_.get(); } | 156 QuicAckFrame* ack() { return ack_.get(); } |
| 138 | 157 |
| 139 QuicCongestionFeedbackFrame* feedback() { return feedback_.get(); } | 158 QuicCongestionFeedbackFrame* feedback() { return feedback_.get(); } |
| 140 | 159 |
| 160 const vector<QuicStreamFrame>* stream_frames() { return &stream_frames_; } |
| 161 |
| 141 void set_blocked(bool blocked) { blocked_ = blocked; } | 162 void set_blocked(bool blocked) { blocked_ = blocked; } |
| 142 | 163 |
| 143 private: | 164 private: |
| 144 MockClock* clock_; | 165 MockClock* clock_; |
| 145 MockRandom* random_generator_; | 166 MockRandom* random_generator_; |
| 146 QuicTime retransmission_alarm_; | 167 QuicTime retransmission_alarm_; |
| 147 QuicTime send_alarm_; | 168 QuicTime send_alarm_; |
| 148 QuicTime timeout_alarm_; | 169 QuicTime timeout_alarm_; |
| 149 QuicPacketHeader header_; | 170 QuicPacketHeader header_; |
| 171 size_t frame_count_; |
| 150 scoped_ptr<QuicAckFrame> ack_; | 172 scoped_ptr<QuicAckFrame> ack_; |
| 151 scoped_ptr<QuicCongestionFeedbackFrame> feedback_; | 173 scoped_ptr<QuicCongestionFeedbackFrame> feedback_; |
| 174 vector<QuicStreamFrame> stream_frames_; |
| 152 bool blocked_; | 175 bool blocked_; |
| 153 | 176 |
| 154 DISALLOW_COPY_AND_ASSIGN(TestConnectionHelper); | 177 DISALLOW_COPY_AND_ASSIGN(TestConnectionHelper); |
| 155 }; | 178 }; |
| 156 | 179 |
| 157 class TestConnection : public QuicConnection { | 180 class TestConnection : public QuicConnection { |
| 158 public: | 181 public: |
| 159 TestConnection(QuicGuid guid, | 182 TestConnection(QuicGuid guid, |
| 160 IPEndPoint address, | 183 IPEndPoint address, |
| 161 TestConnectionHelper* helper) | 184 TestConnectionHelper* helper) |
| 162 : QuicConnection(guid, address, helper) { | 185 : QuicConnection(guid, address, helper) { |
| 163 } | 186 } |
| 164 | 187 |
| 165 void SendAck() { | 188 void SendAck() { |
| 166 QuicConnectionPeer::SendAck(this); | 189 QuicConnectionPeer::SendAck(this); |
| 167 } | 190 } |
| 168 | 191 |
| 169 void SetReceiveAlgorithm(TestReceiveAlgorithm* receive_algorithm) { | 192 void SetReceiveAlgorithm(TestReceiveAlgorithm* receive_algorithm) { |
| 170 QuicConnectionPeer::SetReceiveAlgorithm(this, receive_algorithm); | 193 QuicConnectionPeer::SetReceiveAlgorithm(this, receive_algorithm); |
| 171 } | 194 } |
| 172 | 195 |
| 173 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { | 196 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { |
| 174 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); | 197 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); |
| 175 } | 198 } |
| 176 | 199 |
| 200 QuicConsumedData SendStreamData1() { |
| 201 return SendStreamData(1u, "food", 0, !kFin); |
| 202 } |
| 203 |
| 204 QuicConsumedData SendStreamData2() { |
| 205 return SendStreamData(2u, "food2", 0, !kFin); |
| 206 } |
| 207 |
| 177 using QuicConnection::SendOrQueuePacket; | 208 using QuicConnection::SendOrQueuePacket; |
| 209 using QuicConnection::DontWaitForPacketsBefore; |
| 178 | 210 |
| 179 private: | 211 private: |
| 180 DISALLOW_COPY_AND_ASSIGN(TestConnection); | 212 DISALLOW_COPY_AND_ASSIGN(TestConnection); |
| 181 }; | 213 }; |
| 182 | 214 |
| 183 class QuicConnectionTest : public ::testing::Test { | 215 class QuicConnectionTest : public ::testing::Test { |
| 184 protected: | 216 protected: |
| 185 QuicConnectionTest() | 217 QuicConnectionTest() |
| 186 : guid_(42), | 218 : guid_(42), |
| 187 framer_(QuicDecrypter::Create(kNULL), QuicEncrypter::Create(kNULL)), | 219 framer_(QuicDecrypter::Create(kNULL), QuicEncrypter::Create(kNULL)), |
| 188 creator_(guid_, &framer_), | 220 creator_(guid_, &framer_, QuicRandom::GetInstance()), |
| 189 send_algorithm_(new StrictMock<MockSendAlgorithm>), | 221 send_algorithm_(new StrictMock<MockSendAlgorithm>), |
| 190 helper_(new TestConnectionHelper(&clock_, &random_generator_)), | 222 helper_(new TestConnectionHelper(&clock_, &random_generator_)), |
| 191 connection_(guid_, IPEndPoint(), helper_.get()), | 223 connection_(guid_, IPEndPoint(), helper_.get()), |
| 192 frame1_(1, false, 0, data1), | 224 frame1_(1, false, 0, data1), |
| 193 frame2_(1, false, 3, data2), | 225 frame2_(1, false, 3, data2), |
| 194 accept_packet_(true) { | 226 accept_packet_(true) { |
| 195 connection_.set_visitor(&visitor_); | 227 connection_.set_visitor(&visitor_); |
| 196 connection_.SetSendAlgorithm(send_algorithm_); | 228 connection_.SetSendAlgorithm(send_algorithm_); |
| 197 // Simplify tests by not sending feedback unless specifically configured. | 229 // Simplify tests by not sending feedback unless specifically configured. |
| 198 SetFeedback(NULL); | 230 SetFeedback(NULL); |
| 199 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_)).WillRepeatedly(Return( | 231 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)).WillRepeatedly(Return( |
| 200 QuicTime::Delta::Zero())); | 232 QuicTime::Delta::Zero())); |
| 201 EXPECT_CALL(*receive_algorithm_, | 233 EXPECT_CALL(*receive_algorithm_, |
| 202 RecordIncomingPacket(_, _, _, _)).Times(AnyNumber()); | 234 RecordIncomingPacket(_, _, _, _)).Times(AnyNumber()); |
| 203 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _)).Times(AnyNumber()); | 235 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(AnyNumber()); |
| 204 } | 236 } |
| 205 | 237 |
| 206 QuicAckFrame* outgoing_ack() { | 238 QuicAckFrame* outgoing_ack() { |
| 207 return QuicConnectionPeer::GetOutgoingAck(&connection_); | 239 return QuicConnectionPeer::GetOutgoingAck(&connection_); |
| 208 } | 240 } |
| 209 | 241 |
| 210 QuicAckFrame* last_ack() { | 242 QuicAckFrame* last_ack() { |
| 211 return helper_->ack(); | 243 return helper_->ack(); |
| 212 } | 244 } |
| 213 | 245 |
| 214 QuicCongestionFeedbackFrame* last_feedback() { | 246 QuicCongestionFeedbackFrame* last_feedback() { |
| 215 return helper_->feedback(); | 247 return helper_->feedback(); |
| 216 } | 248 } |
| 217 | 249 |
| 218 QuicPacketHeader* last_header() { | 250 QuicPacketHeader* last_header() { |
| 219 return helper_->header(); | 251 return helper_->header(); |
| 220 } | 252 } |
| 221 | 253 |
| 222 void ProcessPacket(QuicPacketSequenceNumber number) { | 254 void ProcessPacket(QuicPacketSequenceNumber number) { |
| 223 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)) | 255 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)) |
| 224 .WillOnce(Return(accept_packet_)); | 256 .WillOnce(Return(accept_packet_)); |
| 225 ProcessDataPacket(number, 0); | 257 ProcessDataPacket(number, 0, !kEntropyFlag); |
| 258 } |
| 259 |
| 260 QuicPacketEntropyHash ProcessFramePacket(QuicFrame frame) { |
| 261 QuicFrames frames; |
| 262 frames.push_back(QuicFrame(frame)); |
| 263 SerializedPacket serialized_packet = creator_.SerializeAllFrames(frames); |
| 264 scoped_ptr<QuicPacket> packet(serialized_packet.packet); |
| 265 scoped_ptr<QuicEncryptedPacket> encrypted( |
| 266 framer_.EncryptPacket(serialized_packet.sequence_number, *packet)); |
| 267 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
| 268 return serialized_packet.entropy_hash; |
| 226 } | 269 } |
| 227 | 270 |
| 228 void ProcessFecProtectedPacket(QuicPacketSequenceNumber number, | 271 void ProcessFecProtectedPacket(QuicPacketSequenceNumber number, |
| 229 bool expect_revival) { | 272 bool expect_revival) { |
| 230 if (expect_revival) { | 273 if (expect_revival) { |
| 231 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).Times(2).WillRepeatedly( | 274 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).Times(2).WillRepeatedly( |
| 232 Return(accept_packet_)); | 275 Return(accept_packet_)); |
| 233 } else { | 276 } else { |
| 234 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillOnce( | 277 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillOnce( |
| 235 Return(accept_packet_)); | 278 Return(accept_packet_)); |
| 236 } | 279 } |
| 237 ProcessDataPacket(number, 1); | 280 ProcessDataPacket(number, 1, !kEntropyFlag); |
| 238 } | 281 } |
| 239 | 282 |
| 240 void ProcessDataPacket(QuicPacketSequenceNumber number, | 283 void ProcessDataPacket(QuicPacketSequenceNumber number, |
| 241 QuicFecGroupNumber fec_group) { | 284 QuicFecGroupNumber fec_group, |
| 242 scoped_ptr<QuicPacket> packet(ConstructDataPacket(number, fec_group)); | 285 bool entropy_flag) { |
| 243 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket(*packet)); | 286 scoped_ptr<QuicPacket> packet(ConstructDataPacket(number, fec_group, |
| 287 entropy_flag)); |
| 288 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket(number, |
| 289 *packet)); |
| 244 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 290 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
| 245 } | 291 } |
| 246 | 292 |
| 247 void ProcessClosePacket(QuicPacketSequenceNumber number, | 293 void ProcessClosePacket(QuicPacketSequenceNumber number, |
| 248 QuicFecGroupNumber fec_group) { | 294 QuicFecGroupNumber fec_group) { |
| 249 scoped_ptr<QuicPacket> packet(ConstructClosePacket(number, fec_group)); | 295 scoped_ptr<QuicPacket> packet(ConstructClosePacket(number, fec_group)); |
| 250 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket(*packet)); | 296 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket(number, |
| 297 *packet)); |
| 251 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 298 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
| 252 } | 299 } |
| 253 | 300 |
| 301 void ProcessFecProtectedPacket(QuicPacketSequenceNumber number, |
| 302 bool expect_revival, bool entropy_flag) { |
| 303 if (expect_revival) { |
| 304 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillOnce(DoAll( |
| 305 SaveArg<2>(&revived_header_), Return(accept_packet_))); |
| 306 } |
| 307 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillOnce(Return(accept_packet_)) |
| 308 .RetiresOnSaturation(); |
| 309 ProcessDataPacket(number, 1, entropy_flag); |
| 310 } |
| 311 |
| 254 // Sends an FEC packet that covers the packets that would have been sent. | 312 // Sends an FEC packet that covers the packets that would have been sent. |
| 255 void ProcessFecPacket(QuicPacketSequenceNumber number, | 313 void ProcessFecPacket(QuicPacketSequenceNumber number, |
| 256 QuicPacketSequenceNumber min_protected_packet, | 314 QuicPacketSequenceNumber min_protected_packet, |
| 257 bool expect_revival) { | 315 bool expect_revival, |
| 316 bool fec_entropy_flag) { |
| 258 if (expect_revival) { | 317 if (expect_revival) { |
| 259 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillOnce( | 318 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillOnce(DoAll( |
| 260 Return(accept_packet_)); | 319 SaveArg<2>(&revived_header_), Return(accept_packet_))); |
| 261 } | 320 } |
| 262 | 321 |
| 263 // Construct the decrypted data packet so we can compute the correct | 322 // Construct the decrypted data packet so we can compute the correct |
| 264 // redundancy. | 323 // redundancy. |
| 265 scoped_ptr<QuicPacket> data_packet(ConstructDataPacket(number, 1)); | 324 scoped_ptr<QuicPacket> data_packet(ConstructDataPacket(number, 1, |
| 325 !kEntropyFlag)); |
| 266 | 326 |
| 267 header_.public_header.guid = guid_; | 327 header_.public_header.guid = guid_; |
| 268 header_.public_header.flags = PACKET_PUBLIC_FLAGS_NONE; | 328 header_.public_header.reset_flag = false; |
| 269 header_.private_flags = PACKET_PRIVATE_FLAGS_FEC; | 329 header_.public_header.version_flag = false; |
| 330 header_.entropy_flag = kEntropyFlag; |
| 331 header_.fec_flag = true; |
| 332 header_.fec_entropy_flag = fec_entropy_flag; |
| 270 header_.packet_sequence_number = number; | 333 header_.packet_sequence_number = number; |
| 271 header_.fec_group = min_protected_packet; | 334 header_.fec_group = min_protected_packet; |
| 272 QuicFecData fec_data; | 335 QuicFecData fec_data; |
| 273 fec_data.fec_group = header_.fec_group; | 336 fec_data.fec_group = header_.fec_group; |
| 274 // Since all data packets in this test have the same payload, the | 337 // Since all data packets in this test have the same payload, the |
| 275 // redundancy is either equal to that payload or the xor of that payload | 338 // redundancy is either equal to that payload or the xor of that payload |
| 276 // with itself, depending on the number of packets. | 339 // with itself, depending on the number of packets. |
| 277 if (((number - min_protected_packet) % 2) == 0) { | 340 if (((number - min_protected_packet) % 2) == 0) { |
| 278 for (size_t i = kStartOfFecProtectedData; i < data_packet->length(); | 341 for (size_t i = kStartOfFecProtectedData; i < data_packet->length(); |
| 279 ++i) { | 342 ++i) { |
| 280 data_packet->mutable_data()[i] ^= data_packet->data()[i]; | 343 data_packet->mutable_data()[i] ^= data_packet->data()[i]; |
| 281 } | 344 } |
| 282 } | 345 } |
| 283 fec_data.redundancy = data_packet->FecProtectedData(); | 346 fec_data.redundancy = data_packet->FecProtectedData(); |
| 284 scoped_ptr<QuicPacket> fec_packet( | 347 scoped_ptr<QuicPacket> fec_packet( |
| 285 framer_.ConstructFecPacket(header_, fec_data)); | 348 framer_.ConstructFecPacket(header_, fec_data).packet); |
| 286 scoped_ptr<QuicEncryptedPacket> encrypted( | 349 scoped_ptr<QuicEncryptedPacket> encrypted( |
| 287 framer_.EncryptPacket(*fec_packet)); | 350 framer_.EncryptPacket(number, *fec_packet)); |
| 288 | 351 |
| 289 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | 352 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
| 290 } | 353 } |
| 291 | 354 |
| 292 void SendStreamDataToPeer(QuicStreamId id, StringPiece data, | 355 void SendStreamDataToPeer(QuicStreamId id, StringPiece data, |
| 293 QuicStreamOffset offset, bool fin, | 356 QuicStreamOffset offset, bool fin, |
| 294 QuicPacketSequenceNumber* last_packet) { | 357 QuicPacketSequenceNumber* last_packet) { |
| 295 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _)); | 358 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); |
| 296 connection_.SendStreamData(id, data, offset, fin); | 359 connection_.SendStreamData(id, data, offset, fin); |
| 297 if (last_packet != NULL) { | 360 if (last_packet != NULL) { |
| 298 *last_packet = | 361 *last_packet = |
| 299 QuicConnectionPeer::GetPacketCreator(&connection_)->sequence_number(); | 362 QuicConnectionPeer::GetPacketCreator(&connection_)->sequence_number(); |
| 300 } | 363 } |
| 301 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _)).Times(AnyNumber()); | 364 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(AnyNumber()); |
| 302 } | 365 } |
| 303 | 366 |
| 304 void SendAckPacketToPeer() { | 367 void SendAckPacketToPeer() { |
| 305 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _)).Times(1); | 368 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(1); |
| 306 connection_.SendAck(); | 369 connection_.SendAck(); |
| 307 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _)).Times(AnyNumber()); | 370 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(AnyNumber()); |
| 308 } | 371 } |
| 309 | 372 |
| 310 void ProcessAckPacket(QuicAckFrame* frame) { | 373 QuicPacketEntropyHash ProcessAckPacket(QuicAckFrame* frame) { |
| 311 QuicFrames frames; | 374 return ProcessFramePacket(QuicFrame(frame)); |
| 312 frames.push_back(QuicFrame(frame)); | 375 } |
| 313 PacketPair pair = creator_.SerializeAllFrames(frames); | 376 |
| 314 scoped_ptr<QuicPacket> packet(pair.second); | 377 QuicPacketEntropyHash ProcessGoAwayPacket(QuicGoAwayFrame* frame) { |
| 315 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket(*packet)); | 378 return ProcessFramePacket(QuicFrame(frame)); |
| 316 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); | |
| 317 } | 379 } |
| 318 | 380 |
| 319 bool IsMissing(QuicPacketSequenceNumber number) { | 381 bool IsMissing(QuicPacketSequenceNumber number) { |
| 320 return outgoing_ack()->received_info.IsAwaitingPacket(number); | 382 return IsAwaitingPacket(outgoing_ack()->received_info, number); |
| 321 } | 383 } |
| 322 | 384 |
| 323 QuicPacket* ConstructDataPacket(QuicPacketSequenceNumber number, | 385 QuicPacket* ConstructDataPacket(QuicPacketSequenceNumber number, |
| 324 QuicFecGroupNumber fec_group) { | 386 QuicFecGroupNumber fec_group, |
| 387 bool entropy_flag) { |
| 325 header_.public_header.guid = guid_; | 388 header_.public_header.guid = guid_; |
| 326 header_.public_header.flags = PACKET_PUBLIC_FLAGS_NONE; | 389 header_.public_header.reset_flag = false; |
| 327 header_.private_flags = PACKET_PRIVATE_FLAGS_NONE; | 390 header_.public_header.version_flag = false; |
| 391 header_.entropy_flag = entropy_flag; |
| 392 header_.fec_flag = false; |
| 393 header_.fec_entropy_flag = false; |
| 328 header_.packet_sequence_number = number; | 394 header_.packet_sequence_number = number; |
| 329 header_.fec_group = fec_group; | 395 header_.fec_group = fec_group; |
| 330 | 396 |
| 331 QuicFrames frames; | 397 QuicFrames frames; |
| 332 QuicFrame frame(&frame1_); | 398 QuicFrame frame(&frame1_); |
| 333 frames.push_back(frame); | 399 frames.push_back(frame); |
| 334 QuicPacket* packet = framer_.ConstructFrameDataPacket(header_, frames); | 400 QuicPacket* packet = |
| 401 framer_.ConstructFrameDataPacket(header_, frames).packet; |
| 335 EXPECT_TRUE(packet != NULL); | 402 EXPECT_TRUE(packet != NULL); |
| 336 return packet; | 403 return packet; |
| 337 } | 404 } |
| 338 | 405 |
| 339 QuicPacket* ConstructClosePacket(QuicPacketSequenceNumber number, | 406 QuicPacket* ConstructClosePacket(QuicPacketSequenceNumber number, |
| 340 QuicFecGroupNumber fec_group) { | 407 QuicFecGroupNumber fec_group) { |
| 341 header_.public_header.guid = guid_; | 408 header_.public_header.guid = guid_; |
| 342 header_.packet_sequence_number = number; | 409 header_.packet_sequence_number = number; |
| 343 header_.public_header.flags = PACKET_PUBLIC_FLAGS_NONE; | 410 header_.public_header.reset_flag = false; |
| 411 header_.public_header.version_flag = false; |
| 412 header_.entropy_flag = false; |
| 413 header_.fec_flag = false; |
| 414 header_.fec_entropy_flag = false; |
| 344 header_.fec_group = fec_group; | 415 header_.fec_group = fec_group; |
| 345 | 416 |
| 346 QuicConnectionCloseFrame qccf; | 417 QuicConnectionCloseFrame qccf; |
| 347 qccf.error_code = QUIC_CLIENT_GOING_AWAY; | 418 qccf.error_code = QUIC_PEER_GOING_AWAY; |
| 348 qccf.ack_frame = QuicAckFrame(0, 1); | 419 qccf.ack_frame = QuicAckFrame(0, 1); |
| 349 | 420 |
| 350 QuicFrames frames; | 421 QuicFrames frames; |
| 351 QuicFrame frame(&qccf); | 422 QuicFrame frame(&qccf); |
| 352 frames.push_back(frame); | 423 frames.push_back(frame); |
| 353 QuicPacket* packet = framer_.ConstructFrameDataPacket(header_, frames); | 424 QuicPacket* packet = |
| 425 framer_.ConstructFrameDataPacket(header_, frames).packet; |
| 354 EXPECT_TRUE(packet != NULL); | 426 EXPECT_TRUE(packet != NULL); |
| 355 return packet; | 427 return packet; |
| 356 } | 428 } |
| 357 | 429 |
| 358 void SetFeedback(QuicCongestionFeedbackFrame* feedback) { | 430 void SetFeedback(QuicCongestionFeedbackFrame* feedback) { |
| 359 receive_algorithm_ = new TestReceiveAlgorithm(feedback); | 431 receive_algorithm_ = new TestReceiveAlgorithm(feedback); |
| 360 connection_.SetReceiveAlgorithm(receive_algorithm_); | 432 connection_.SetReceiveAlgorithm(receive_algorithm_); |
| 361 } | 433 } |
| 362 | 434 |
| 363 QuicGuid guid_; | 435 QuicGuid guid_; |
| 364 QuicFramer framer_; | 436 QuicFramer framer_; |
| 365 QuicPacketCreator creator_; | 437 QuicPacketCreator creator_; |
| 366 | 438 |
| 367 MockSendAlgorithm* send_algorithm_; | 439 MockSendAlgorithm* send_algorithm_; |
| 368 TestReceiveAlgorithm* receive_algorithm_; | 440 TestReceiveAlgorithm* receive_algorithm_; |
| 369 MockClock clock_; | 441 MockClock clock_; |
| 370 MockRandom random_generator_; | 442 MockRandom random_generator_; |
| 371 scoped_ptr<TestConnectionHelper> helper_; | 443 scoped_ptr<TestConnectionHelper> helper_; |
| 372 TestConnection connection_; | 444 TestConnection connection_; |
| 373 testing::StrictMock<MockConnectionVisitor> visitor_; | 445 testing::StrictMock<MockConnectionVisitor> visitor_; |
| 374 | 446 |
| 375 QuicPacketHeader header_; | 447 QuicPacketHeader header_; |
| 448 QuicPacketHeader revived_header_; |
| 376 QuicStreamFrame frame1_; | 449 QuicStreamFrame frame1_; |
| 377 QuicStreamFrame frame2_; | 450 QuicStreamFrame frame2_; |
| 378 bool accept_packet_; | 451 bool accept_packet_; |
| 379 | 452 |
| 380 private: | 453 private: |
| 381 DISALLOW_COPY_AND_ASSIGN(QuicConnectionTest); | 454 DISALLOW_COPY_AND_ASSIGN(QuicConnectionTest); |
| 382 }; | 455 }; |
| 383 | 456 |
| 384 TEST_F(QuicConnectionTest, PacketsInOrder) { | 457 TEST_F(QuicConnectionTest, PacketsInOrder) { |
| 385 ProcessPacket(1); | 458 ProcessPacket(1); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 } | 498 } |
| 426 | 499 |
| 427 TEST_F(QuicConnectionTest, DuplicatePacket) { | 500 TEST_F(QuicConnectionTest, DuplicatePacket) { |
| 428 ProcessPacket(3); | 501 ProcessPacket(3); |
| 429 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); | 502 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); |
| 430 EXPECT_TRUE(IsMissing(2)); | 503 EXPECT_TRUE(IsMissing(2)); |
| 431 EXPECT_TRUE(IsMissing(1)); | 504 EXPECT_TRUE(IsMissing(1)); |
| 432 | 505 |
| 433 // Send packet 3 again, but do not set the expectation that | 506 // Send packet 3 again, but do not set the expectation that |
| 434 // the visitor OnPacket() will be called. | 507 // the visitor OnPacket() will be called. |
| 435 ProcessDataPacket(3, 0); | 508 ProcessDataPacket(3, 0, !kEntropyFlag); |
| 436 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); | 509 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); |
| 437 EXPECT_TRUE(IsMissing(2)); | 510 EXPECT_TRUE(IsMissing(2)); |
| 438 EXPECT_TRUE(IsMissing(1)); | 511 EXPECT_TRUE(IsMissing(1)); |
| 439 } | 512 } |
| 440 | 513 |
| 441 TEST_F(QuicConnectionTest, PacketsOutOfOrderWithAdditionsAndLeastAwaiting) { | 514 TEST_F(QuicConnectionTest, PacketsOutOfOrderWithAdditionsAndLeastAwaiting) { |
| 442 ProcessPacket(3); | 515 ProcessPacket(3); |
| 443 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); | 516 EXPECT_EQ(3u, outgoing_ack()->received_info.largest_observed); |
| 444 EXPECT_TRUE(IsMissing(2)); | 517 EXPECT_TRUE(IsMissing(2)); |
| 445 EXPECT_TRUE(IsMissing(1)); | 518 EXPECT_TRUE(IsMissing(1)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 462 ProcessAckPacket(&frame); | 535 ProcessAckPacket(&frame); |
| 463 | 536 |
| 464 // Force an ack to be sent. | 537 // Force an ack to be sent. |
| 465 SendAckPacketToPeer(); | 538 SendAckPacketToPeer(); |
| 466 EXPECT_TRUE(IsMissing(4)); | 539 EXPECT_TRUE(IsMissing(4)); |
| 467 } | 540 } |
| 468 | 541 |
| 469 TEST_F(QuicConnectionTest, RejectPacketTooFarOut) { | 542 TEST_F(QuicConnectionTest, RejectPacketTooFarOut) { |
| 470 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a | 543 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a |
| 471 // packet call to the visitor. | 544 // packet call to the visitor. |
| 472 ProcessDataPacket(6000, 0); | 545 ProcessDataPacket(6000, 0, !kEntropyFlag); |
| 473 | 546 |
| 474 SendAckPacketToPeer(); // Packet 2 | 547 SendAckPacketToPeer(); // Packet 2 |
| 475 EXPECT_EQ(0u, outgoing_ack()->received_info.largest_observed); | 548 EXPECT_EQ(0u, outgoing_ack()->received_info.largest_observed); |
| 476 } | 549 } |
| 477 | 550 |
| 478 TEST_F(QuicConnectionTest, TruncatedAck) { | 551 TEST_F(QuicConnectionTest, TruncatedAck) { |
| 479 EXPECT_CALL(visitor_, OnAck(_)).Times(testing::AnyNumber()); | 552 EXPECT_CALL(visitor_, OnAck(_)).Times(testing::AnyNumber()); |
| 480 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); | 553 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); |
| 554 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); |
| 481 for (int i = 0; i < 200; ++i) { | 555 for (int i = 0; i < 200; ++i) { |
| 482 SendStreamDataToPeer(1, "foo", i * 3, false, NULL); | 556 SendStreamDataToPeer(1, "foo", i * 3, !kFin, NULL); |
| 483 } | 557 } |
| 484 | 558 |
| 485 QuicAckFrame frame(0, 1); | 559 QuicAckFrame frame(0, 1); |
| 486 frame.received_info.RecordReceived(193); | 560 frame.received_info.largest_observed = 192; |
| 561 InsertMissingPacketsBetween(&frame.received_info, 1, 192); |
| 562 frame.received_info.entropy_hash = |
| 563 QuicConnectionPeer::GetSentEntropyHash(&connection_, 192) ^ |
| 564 QuicConnectionPeer::GetSentEntropyHash(&connection_, 191); |
| 565 |
| 487 ProcessAckPacket(&frame); | 566 ProcessAckPacket(&frame); |
| 488 | 567 |
| 489 EXPECT_TRUE(QuicConnectionPeer::GetReceivedTruncatedAck(&connection_)); | 568 EXPECT_TRUE(QuicConnectionPeer::GetReceivedTruncatedAck(&connection_)); |
| 490 | 569 |
| 491 frame.received_info.missing_packets.erase(192); | 570 frame.received_info.missing_packets.erase(191); |
| 571 frame.received_info.entropy_hash = |
| 572 QuicConnectionPeer::GetSentEntropyHash(&connection_, 192) ^ |
| 573 QuicConnectionPeer::GetSentEntropyHash(&connection_, 190); |
| 492 | 574 |
| 493 ProcessAckPacket(&frame); | 575 ProcessAckPacket(&frame); |
| 494 EXPECT_FALSE(QuicConnectionPeer::GetReceivedTruncatedAck(&connection_)); | 576 EXPECT_FALSE(QuicConnectionPeer::GetReceivedTruncatedAck(&connection_)); |
| 495 } | 577 } |
| 496 | 578 |
| 497 TEST_F(QuicConnectionTest, LeastUnackedLower) { | 579 TEST_F(QuicConnectionTest, LeastUnackedLower) { |
| 498 SendStreamDataToPeer(1, "foo", 0, false, NULL); | 580 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); |
| 499 SendStreamDataToPeer(1, "bar", 3, false, NULL); | 581 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL); |
| 500 SendStreamDataToPeer(1, "eep", 6, false, NULL); | 582 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL); |
| 501 | 583 |
| 502 // Start out saying the least unacked is 2 | 584 // Start out saying the least unacked is 2 |
| 503 creator_.set_sequence_number(5); | 585 creator_.set_sequence_number(5); |
| 504 QuicAckFrame frame(0, 2); | 586 QuicAckFrame frame(0, 2); |
| 505 ProcessAckPacket(&frame); | 587 ProcessAckPacket(&frame); |
| 506 | 588 |
| 507 // Change it to 1, but lower the sequence number to fake out-of-order packets. | 589 // Change it to 1, but lower the sequence number to fake out-of-order packets. |
| 508 // This should be fine. | 590 // This should be fine. |
| 509 creator_.set_sequence_number(1); | 591 creator_.set_sequence_number(1); |
| 510 QuicAckFrame frame2(0, 1); | 592 QuicAckFrame frame2(0, 1); |
| 511 // The scheduler will not process out of order acks. | 593 // The scheduler will not process out of order acks. |
| 512 ProcessAckPacket(&frame2); | 594 ProcessAckPacket(&frame2); |
| 513 | 595 |
| 514 // Now claim it's one, but set the ordering so it was sent "after" the first | 596 // Now claim it's one, but set the ordering so it was sent "after" the first |
| 515 // one. This should cause a connection error. | 597 // one. This should cause a connection error. |
| 516 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false)); | 598 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false)); |
| 517 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _)); | 599 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); |
| 518 creator_.set_sequence_number(7); | 600 creator_.set_sequence_number(7); |
| 519 ProcessAckPacket(&frame2); | 601 ProcessAckPacket(&frame2); |
| 520 } | 602 } |
| 521 | 603 |
| 522 TEST_F(QuicConnectionTest, LargestObservedLower) { | 604 TEST_F(QuicConnectionTest, LargestObservedLower) { |
| 523 SendStreamDataToPeer(1, "foo", 0, false, NULL); | 605 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); |
| 524 SendStreamDataToPeer(1, "bar", 3, false, NULL); | 606 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL); |
| 525 SendStreamDataToPeer(1, "eep", 6, false, NULL); | 607 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL); |
| 526 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); | 608 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); |
| 527 | 609 |
| 528 // Start out saying the largest observed is 2. | 610 // Start out saying the largest observed is 2. |
| 529 QuicAckFrame frame(2, 0); | 611 QuicAckFrame frame(2, 0); |
| 612 frame.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash( |
| 613 &connection_, 2); |
| 530 EXPECT_CALL(visitor_, OnAck(_)); | 614 EXPECT_CALL(visitor_, OnAck(_)); |
| 531 ProcessAckPacket(&frame); | 615 ProcessAckPacket(&frame); |
| 532 | 616 |
| 533 // Now change it to 1, and it should cause a connection error. | 617 // Now change it to 1, and it should cause a connection error. |
| 534 QuicAckFrame frame2(1, 0); | 618 QuicAckFrame frame2(1, 0); |
| 535 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false)); | 619 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false)); |
| 536 ProcessAckPacket(&frame2); | 620 ProcessAckPacket(&frame2); |
| 537 } | 621 } |
| 538 | 622 |
| 539 TEST_F(QuicConnectionTest, LeastUnackedGreaterThanPacketSequenceNumber) { | 623 TEST_F(QuicConnectionTest, LeastUnackedGreaterThanPacketSequenceNumber) { |
| 540 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false)); | 624 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false)); |
| 541 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _)); | 625 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); |
| 542 // Create an ack with least_unacked is 2 in packet number 1. | 626 // Create an ack with least_unacked is 2 in packet number 1. |
| 543 creator_.set_sequence_number(0); | 627 creator_.set_sequence_number(0); |
| 544 QuicAckFrame frame(0, 2); | 628 QuicAckFrame frame(0, 2); |
| 545 ProcessAckPacket(&frame); | 629 ProcessAckPacket(&frame); |
| 546 } | 630 } |
| 547 | 631 |
| 548 TEST_F(QuicConnectionTest, | 632 TEST_F(QuicConnectionTest, |
| 549 DISABLED_NackSequenceNumberGreaterThanLargestReceived) { | 633 NackSequenceNumberGreaterThanLargestReceived) { |
| 550 SendStreamDataToPeer(1, "foo", 0, false, NULL); | 634 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); |
| 551 SendStreamDataToPeer(1, "bar", 3, false, NULL); | 635 SendStreamDataToPeer(1, "bar", 3, !kFin, NULL); |
| 552 SendStreamDataToPeer(1, "eep", 6, false, NULL); | 636 SendStreamDataToPeer(1, "eep", 6, !kFin, NULL); |
| 553 | 637 |
| 554 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false)); | 638 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false)); |
| 555 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _)); | 639 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); |
| 556 QuicAckFrame frame(0, 1); | 640 QuicAckFrame frame(0, 1); |
| 557 frame.received_info.missing_packets.insert(3); | 641 frame.received_info.missing_packets.insert(3); |
| 558 ProcessAckPacket(&frame); | 642 ProcessAckPacket(&frame); |
| 559 } | 643 } |
| 560 | 644 |
| 561 TEST_F(QuicConnectionTest, AckUnsentData) { | 645 TEST_F(QuicConnectionTest, AckUnsentData) { |
| 562 // Ack a packet which has not been sent. | 646 // Ack a packet which has not been sent. |
| 563 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false)); | 647 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_ACK_DATA, false)); |
| 564 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _)); | 648 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); |
| 565 QuicAckFrame frame(1, 0); | 649 QuicAckFrame frame(1, 0); |
| 566 ProcessAckPacket(&frame); | 650 ProcessAckPacket(&frame); |
| 567 } | 651 } |
| 568 | 652 |
| 569 TEST_F(QuicConnectionTest, AckAll) { | 653 TEST_F(QuicConnectionTest, AckAll) { |
| 570 ProcessPacket(1); | 654 ProcessPacket(1); |
| 571 | 655 |
| 572 creator_.set_sequence_number(1); | 656 creator_.set_sequence_number(1); |
| 573 QuicAckFrame frame1(0, 1); | 657 QuicAckFrame frame1(0, 1); |
| 574 ProcessAckPacket(&frame1); | 658 ProcessAckPacket(&frame1); |
| 575 } | 659 } |
| 576 | 660 |
| 661 TEST_F(QuicConnectionTest, DontWaitForPacketsBefore) { |
| 662 ProcessPacket(2); |
| 663 ProcessPacket(7); |
| 664 EXPECT_TRUE(connection_.DontWaitForPacketsBefore(4)); |
| 665 EXPECT_EQ(3u, outgoing_ack()->received_info.missing_packets.size()); |
| 666 } |
| 667 |
| 577 TEST_F(QuicConnectionTest, BasicSending) { | 668 TEST_F(QuicConnectionTest, BasicSending) { |
| 578 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(6); | 669 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(6); |
| 579 QuicPacketSequenceNumber last_packet; | 670 QuicPacketSequenceNumber last_packet; |
| 580 SendStreamDataToPeer(1, "foo", 0, false, &last_packet); // Packet 1 | 671 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 |
| 581 EXPECT_EQ(1u, last_packet); | 672 EXPECT_EQ(1u, last_packet); |
| 582 SendAckPacketToPeer(); // Packet 2 | 673 SendAckPacketToPeer(); // Packet 2 |
| 583 | 674 |
| 584 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); | 675 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); |
| 585 | 676 |
| 586 SendAckPacketToPeer(); // Packet 3 | 677 SendAckPacketToPeer(); // Packet 3 |
| 587 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); | 678 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); |
| 588 | 679 |
| 589 SendStreamDataToPeer(1u, "bar", 3, false, &last_packet); // Packet 4 | 680 SendStreamDataToPeer(1u, "bar", 3, !kFin, &last_packet); // Packet 4 |
| 590 EXPECT_EQ(4u, last_packet); | 681 EXPECT_EQ(4u, last_packet); |
| 591 SendAckPacketToPeer(); // Packet 5 | 682 SendAckPacketToPeer(); // Packet 5 |
| 592 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); | 683 EXPECT_EQ(1u, last_ack()->sent_info.least_unacked); |
| 593 | 684 |
| 594 QuicConnectionVisitorInterface::AckedPackets expected_acks; | 685 SequenceNumberSet expected_acks; |
| 595 expected_acks.insert(1); | 686 expected_acks.insert(1); |
| 596 | 687 |
| 597 // Client acks up to packet 3 | 688 // Client acks up to packet 3 |
| 598 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); | 689 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); |
| 599 QuicAckFrame frame(3, 0); | 690 QuicAckFrame frame(3, 0); |
| 691 frame.received_info.entropy_hash = |
| 692 QuicConnectionPeer::GetSentEntropyHash(&connection_, 3); |
| 600 ProcessAckPacket(&frame); | 693 ProcessAckPacket(&frame); |
| 601 SendAckPacketToPeer(); // Packet 6 | 694 SendAckPacketToPeer(); // Packet 6 |
| 602 | 695 |
| 603 // As soon as we've acked one, we skip ack packets 2 and 3 and note lack of | 696 // As soon as we've acked one, we skip ack packets 2 and 3 and note lack of |
| 604 // ack for 4. | 697 // ack for 4. |
| 605 EXPECT_EQ(4u, last_ack()->sent_info.least_unacked); | 698 EXPECT_EQ(4u, last_ack()->sent_info.least_unacked); |
| 606 | 699 |
| 607 expected_acks.clear(); | 700 expected_acks.clear(); |
| 608 expected_acks.insert(4); | 701 expected_acks.insert(4); |
| 609 | 702 |
| 610 // Client acks up to packet 4, the last packet | 703 // Client acks up to packet 4, the last packet |
| 611 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); | 704 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); |
| 612 QuicAckFrame frame2(6, 0); | 705 QuicAckFrame frame2(6, 0); |
| 706 frame2.received_info.entropy_hash = |
| 707 QuicConnectionPeer::GetSentEntropyHash(&connection_, 6); |
| 613 ProcessAckPacket(&frame2); // Even parity triggers ack packet 7 | 708 ProcessAckPacket(&frame2); // Even parity triggers ack packet 7 |
| 614 | 709 |
| 615 // The least packet awaiting ack should now be 7 | 710 // The least packet awaiting ack should now be 7 |
| 616 EXPECT_EQ(7u, last_ack()->sent_info.least_unacked); | 711 EXPECT_EQ(7u, last_ack()->sent_info.least_unacked); |
| 617 | 712 |
| 618 // If we force an ack, we shouldn't change our retransmit state. | 713 // If we force an ack, we shouldn't change our retransmit state. |
| 619 SendAckPacketToPeer(); // Packet 8 | 714 SendAckPacketToPeer(); // Packet 8 |
| 620 EXPECT_EQ(8u, last_ack()->sent_info.least_unacked); | 715 EXPECT_EQ(8u, last_ack()->sent_info.least_unacked); |
| 621 | 716 |
| 622 // But if we send more data it should. | 717 // But if we send more data it should. |
| 623 SendStreamDataToPeer(1, "eep", 6, false, &last_packet); // Packet 9 | 718 SendStreamDataToPeer(1, "eep", 6, !kFin, &last_packet); // Packet 9 |
| 624 EXPECT_EQ(9u, last_packet); | 719 EXPECT_EQ(9u, last_packet); |
| 625 SendAckPacketToPeer(); // Packet10 | 720 SendAckPacketToPeer(); // Packet10 |
| 626 EXPECT_EQ(9u, last_ack()->sent_info.least_unacked); | 721 EXPECT_EQ(9u, last_ack()->sent_info.least_unacked); |
| 627 } | 722 } |
| 628 | 723 |
| 629 TEST_F(QuicConnectionTest, FECSending) { | 724 TEST_F(QuicConnectionTest, FECSending) { |
| 630 // Limit to one byte per packet. | 725 // Limit to one byte per packet. |
| 631 size_t ciphertext_size = NullEncrypter().GetCiphertextSize(1); | 726 size_t ciphertext_size = NullEncrypter().GetCiphertextSize(1); |
| 632 connection_.options()->max_packet_length = | 727 connection_.options()->max_packet_length = |
| 633 ciphertext_size + QuicUtils::StreamFramePacketOverhead(1); | 728 ciphertext_size + QuicUtils::StreamFramePacketOverhead(1); |
| 634 // And send FEC every two packets. | 729 // And send FEC every two packets. |
| 635 connection_.options()->max_packets_per_fec_group = 2; | 730 connection_.options()->max_packets_per_fec_group = 2; |
| 636 | 731 |
| 637 // Send 4 data packets and 2 FEC packets. | 732 // Send 4 data packets and 2 FEC packets. |
| 638 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _)).Times(6); | 733 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(6); |
| 639 connection_.SendStreamData(1, "food", 0, false); | 734 connection_.SendStreamData(1, "food", 0, !kFin); |
| 640 // Expect the FEC group to be closed after SendStreamData. | 735 // Expect the FEC group to be closed after SendStreamData. |
| 641 EXPECT_FALSE(creator_.ShouldSendFec(true)); | 736 EXPECT_FALSE(creator_.ShouldSendFec(true)); |
| 642 } | 737 } |
| 643 | 738 |
| 644 TEST_F(QuicConnectionTest, FECQueueing) { | 739 TEST_F(QuicConnectionTest, FECQueueing) { |
| 645 // Limit to one byte per packet. | 740 // Limit to one byte per packet. |
| 646 size_t ciphertext_size = NullEncrypter().GetCiphertextSize(1); | 741 size_t ciphertext_size = NullEncrypter().GetCiphertextSize(1); |
| 647 connection_.options()->max_packet_length = | 742 connection_.options()->max_packet_length = |
| 648 ciphertext_size + QuicUtils::StreamFramePacketOverhead(1); | 743 ciphertext_size + QuicUtils::StreamFramePacketOverhead(1); |
| 649 // And send FEC every two packets. | 744 // And send FEC every two packets. |
| 650 connection_.options()->max_packets_per_fec_group = 2; | 745 connection_.options()->max_packets_per_fec_group = 2; |
| 651 | 746 |
| 652 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 747 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 653 helper_->set_blocked(true); | 748 helper_->set_blocked(true); |
| 654 connection_.SendStreamData(1, "food", 0, false); | 749 connection_.SendStreamData(1, "food", 0, !kFin); |
| 655 EXPECT_FALSE(creator_.ShouldSendFec(true)); | 750 EXPECT_FALSE(creator_.ShouldSendFec(true)); |
| 656 // Expect the first data packet and the fec packet to be queued. | 751 // Expect the first data packet and the fec packet to be queued. |
| 657 EXPECT_EQ(2u, connection_.NumQueuedPackets()); | 752 EXPECT_EQ(2u, connection_.NumQueuedPackets()); |
| 658 } | 753 } |
| 659 | 754 |
| 755 TEST_F(QuicConnectionTest, FramePacking) { |
| 756 // Block the connection. |
| 757 helper_->SetSendAlarm(QuicTime::Delta::FromSeconds(1)); |
| 758 |
| 759 // Send an ack and two stream frames in 1 packet by queueing them. |
| 760 connection_.SendAck(); |
| 761 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( |
| 762 IgnoreResult(InvokeWithoutArgs(&connection_, |
| 763 &TestConnection::SendStreamData1)), |
| 764 IgnoreResult(InvokeWithoutArgs(&connection_, |
| 765 &TestConnection::SendStreamData2)), |
| 766 Return(true))); |
| 767 |
| 768 // Unblock the connection. |
| 769 helper_->UnregisterSendAlarmIfRegistered(); |
| 770 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, !kIsRetransmission)) |
| 771 .Times(1); |
| 772 connection_.OnCanWrite(); |
| 773 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 774 EXPECT_FALSE(connection_.HasQueuedData()); |
| 775 |
| 776 // Parse the last packet and ensure it's an ack and two stream frames from |
| 777 // two different streams. |
| 778 EXPECT_EQ(3u, helper_->frame_count()); |
| 779 EXPECT_TRUE(helper_->ack()); |
| 780 EXPECT_EQ(2u, helper_->stream_frames()->size()); |
| 781 EXPECT_EQ(1u, (*helper_->stream_frames())[0].stream_id); |
| 782 EXPECT_EQ(2u, (*helper_->stream_frames())[1].stream_id); |
| 783 } |
| 784 |
| 785 TEST_F(QuicConnectionTest, FramePackingFEC) { |
| 786 // Enable fec. |
| 787 connection_.options()->max_packets_per_fec_group = 6; |
| 788 // Block the connection. |
| 789 helper_->SetSendAlarm(QuicTime::Delta::FromSeconds(1)); |
| 790 |
| 791 // Send an ack and two stream frames in 1 packet by queueing them. |
| 792 connection_.SendAck(); |
| 793 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( |
| 794 IgnoreResult(InvokeWithoutArgs(&connection_, |
| 795 &TestConnection::SendStreamData1)), |
| 796 IgnoreResult(InvokeWithoutArgs(&connection_, |
| 797 &TestConnection::SendStreamData2)), |
| 798 Return(true))); |
| 799 |
| 800 // Unblock the connection. |
| 801 helper_->UnregisterSendAlarmIfRegistered(); |
| 802 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, !kIsRetransmission)) |
| 803 .Times(2); |
| 804 connection_.OnCanWrite(); |
| 805 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 806 EXPECT_FALSE(connection_.HasQueuedData()); |
| 807 |
| 808 // Parse the last packet and ensure it's in an fec group. |
| 809 EXPECT_EQ(1u, helper_->header()->fec_group); |
| 810 EXPECT_EQ(0u, helper_->frame_count()); |
| 811 } |
| 812 |
| 813 TEST_F(QuicConnectionTest, OnCanWrite) { |
| 814 // Visitor's OnCanWill send data, but will return false. |
| 815 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( |
| 816 IgnoreResult(InvokeWithoutArgs(&connection_, |
| 817 &TestConnection::SendStreamData1)), |
| 818 IgnoreResult(InvokeWithoutArgs(&connection_, |
| 819 &TestConnection::SendStreamData2)), |
| 820 Return(false))); |
| 821 |
| 822 EXPECT_CALL(*send_algorithm_, |
| 823 TimeUntilSend(_, !kIsRetransmission)).WillRepeatedly( |
| 824 testing::Return(QuicTime::Delta::Zero())); |
| 825 |
| 826 // Unblock the connection. |
| 827 connection_.OnCanWrite(); |
| 828 // Parse the last packet and ensure it's the two stream frames from |
| 829 // two different streams. |
| 830 EXPECT_EQ(2u, helper_->frame_count()); |
| 831 EXPECT_EQ(2u, helper_->stream_frames()->size()); |
| 832 EXPECT_EQ(1u, (*helper_->stream_frames())[0].stream_id); |
| 833 EXPECT_EQ(2u, (*helper_->stream_frames())[1].stream_id); |
| 834 } |
| 835 |
| 660 TEST_F(QuicConnectionTest, RetransmitOnNack) { | 836 TEST_F(QuicConnectionTest, RetransmitOnNack) { |
| 661 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); | 837 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); |
| 838 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); |
| 662 QuicPacketSequenceNumber last_packet; | 839 QuicPacketSequenceNumber last_packet; |
| 663 SendStreamDataToPeer(1, "foo", 0, false, &last_packet); // Packet 1 | 840 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 |
| 664 SendStreamDataToPeer(1, "foos", 3, false, &last_packet); // Packet 2 | 841 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2 |
| 665 SendStreamDataToPeer(1, "fooos", 7, false, &last_packet); // Packet 3 | 842 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3 |
| 666 | 843 |
| 667 QuicConnectionVisitorInterface::AckedPackets expected_acks; | 844 SequenceNumberSet expected_acks; |
| 668 expected_acks.insert(1); | 845 expected_acks.insert(1); |
| 669 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); | 846 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); |
| 670 | 847 |
| 671 // Client acks one but not two or three. Right now we only retransmit on | 848 // Client acks one but not two or three. Right now we only retransmit on |
| 672 // explicit nack, so it should not trigger a retransimission. | 849 // explicit nack, so it should not trigger a retransimission. |
| 673 QuicAckFrame ack_one(1, 0); | 850 QuicAckFrame ack_one(1, 0); |
| 851 ack_one.received_info.entropy_hash = |
| 852 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1); |
| 674 ProcessAckPacket(&ack_one); | 853 ProcessAckPacket(&ack_one); |
| 675 ProcessAckPacket(&ack_one); | 854 ProcessAckPacket(&ack_one); |
| 676 ProcessAckPacket(&ack_one); | 855 ProcessAckPacket(&ack_one); |
| 677 | 856 |
| 678 expected_acks.clear(); | 857 expected_acks.clear(); |
| 679 expected_acks.insert(3); | 858 expected_acks.insert(3); |
| 680 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); | 859 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); |
| 681 | 860 |
| 682 // Client acks up to 3 with two explicitly missing. Two nacks should cause no | 861 // Client acks up to 3 with two explicitly missing. Two nacks should cause no |
| 683 // change. | 862 // change. |
| 684 QuicAckFrame nack_two(3, 0); | 863 QuicAckFrame nack_two(3, 0); |
| 685 nack_two.received_info.missing_packets.insert(2); | 864 nack_two.received_info.missing_packets.insert(2); |
| 865 nack_two.received_info.entropy_hash = |
| 866 QuicConnectionPeer::GetSentEntropyHash(&connection_, 3) ^ |
| 867 QuicConnectionPeer::GetSentEntropyHash(&connection_, 2) ^ |
| 868 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1); |
| 686 ProcessAckPacket(&nack_two); | 869 ProcessAckPacket(&nack_two); |
| 687 ProcessAckPacket(&nack_two); | 870 ProcessAckPacket(&nack_two); |
| 688 | 871 |
| 689 // The third nack should trigger a retransimission. | 872 // The third nack should trigger a retransimission. |
| 690 EXPECT_CALL(*send_algorithm_, SentPacket(_, 37, true)).Times(1); | 873 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, 37, kIsRetransmission)) |
| 874 .Times(1); |
| 691 ProcessAckPacket(&nack_two); | 875 ProcessAckPacket(&nack_two); |
| 692 } | 876 } |
| 693 | 877 |
| 694 TEST_F(QuicConnectionTest, RetransmitNackedLargestObserved) { | 878 TEST_F(QuicConnectionTest, RetransmitNackedLargestObserved) { |
| 879 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); |
| 695 QuicPacketSequenceNumber largest_observed; | 880 QuicPacketSequenceNumber largest_observed; |
| 696 QuicByteCount packet_size; | 881 QuicByteCount packet_size; |
| 697 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, false)).WillOnce(DoAll( | 882 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, !kIsRetransmission)) |
| 698 SaveArg<0>(&largest_observed), SaveArg<1>(&packet_size))); | 883 .WillOnce(DoAll(SaveArg<1>(&largest_observed), SaveArg<2>(&packet_size))); |
| 699 connection_.SendStreamData(1, "foo", 0, false); | 884 connection_.SendStreamData(1, "foo", 0, !kFin); |
| 700 QuicAckFrame frame(1, largest_observed); | 885 QuicAckFrame frame(1, largest_observed); |
| 701 frame.received_info.missing_packets.insert(largest_observed); | 886 frame.received_info.missing_packets.insert(largest_observed); |
| 887 frame.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash( |
| 888 &connection_, largest_observed - 1); |
| 702 ProcessAckPacket(&frame); | 889 ProcessAckPacket(&frame); |
| 703 // Second udp packet will force an ack frame. | 890 // Second udp packet will force an ack frame. |
| 704 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, false)); | 891 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, !kIsRetransmission)); |
| 705 ProcessAckPacket(&frame); | 892 ProcessAckPacket(&frame); |
| 706 // Third nack should retransmit the largest observed packet. | 893 // Third nack should retransmit the largest observed packet. |
| 707 EXPECT_CALL(*send_algorithm_, SentPacket(_, packet_size, true)); | 894 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, packet_size, |
| 895 kIsRetransmission)); |
| 708 ProcessAckPacket(&frame); | 896 ProcessAckPacket(&frame); |
| 709 } | 897 } |
| 710 | 898 |
| 711 TEST_F(QuicConnectionTest, LimitPacketsPerNack) { | 899 TEST_F(QuicConnectionTest, LimitPacketsPerNack) { |
| 712 EXPECT_CALL(*send_algorithm_, OnIncomingAck(12, _, _)).Times(1); | 900 EXPECT_CALL(*send_algorithm_, OnIncomingAck(12, _, _)).Times(1); |
| 901 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); |
| 713 int offset = 0; | 902 int offset = 0; |
| 714 // Send packets 1 to 12 | 903 // Send packets 1 to 12 |
| 715 for (int i = 0; i < 12; ++i) { | 904 for (int i = 0; i < 12; ++i) { |
| 716 SendStreamDataToPeer(1, "foo", offset, false, NULL); | 905 SendStreamDataToPeer(1, "foo", offset, !kFin, NULL); |
| 717 offset += 3; | 906 offset += 3; |
| 718 } | 907 } |
| 719 | 908 |
| 720 // Ack 12, nack 1-11 | 909 // Ack 12, nack 1-11 |
| 721 QuicAckFrame nack(12, 0); | 910 QuicAckFrame nack(12, 0); |
| 722 for (int i = 1; i < 12; ++i) { | 911 for (int i = 1; i < 12; ++i) { |
| 723 nack.received_info.missing_packets.insert(i); | 912 nack.received_info.missing_packets.insert(i); |
| 724 } | 913 } |
| 725 | 914 |
| 726 QuicConnectionVisitorInterface::AckedPackets expected_acks; | 915 nack.received_info.entropy_hash = |
| 916 QuicConnectionPeer::GetSentEntropyHash(&connection_, 12) ^ |
| 917 QuicConnectionPeer::GetSentEntropyHash(&connection_, 11); |
| 918 SequenceNumberSet expected_acks; |
| 727 expected_acks.insert(12); | 919 expected_acks.insert(12); |
| 728 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); | 920 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); |
| 729 | 921 |
| 730 // Nack three times. | 922 // Nack three times. |
| 731 ProcessAckPacket(&nack); | 923 ProcessAckPacket(&nack); |
| 732 // The second call will trigger an ack. | 924 // The second call will trigger an ack. |
| 733 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _)).Times(1); | 925 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(1); |
| 734 ProcessAckPacket(&nack); | 926 ProcessAckPacket(&nack); |
| 735 // The third call should trigger retransmitting 10 packets. | 927 // The third call should trigger retransmitting 10 packets. |
| 736 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _)).Times(10); | 928 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(10); |
| 737 ProcessAckPacket(&nack); | 929 ProcessAckPacket(&nack); |
| 738 | 930 |
| 739 // The fourth call should trigger retransmitting the 11th packet and an ack. | 931 // The fourth call should trigger retransmitting the 11th packet and an ack. |
| 740 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _)).Times(2); | 932 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(2); |
| 741 ProcessAckPacket(&nack); | 933 ProcessAckPacket(&nack); |
| 742 } | 934 } |
| 743 | 935 |
| 744 // Test sending multiple acks from the connection to the session. | 936 // Test sending multiple acks from the connection to the session. |
| 745 TEST_F(QuicConnectionTest, MultipleAcks) { | 937 TEST_F(QuicConnectionTest, MultipleAcks) { |
| 746 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(6); | 938 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(6); |
| 939 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); |
| 747 QuicPacketSequenceNumber last_packet; | 940 QuicPacketSequenceNumber last_packet; |
| 748 SendStreamDataToPeer(1u, "foo", 0, false, &last_packet); // Packet 1 | 941 SendStreamDataToPeer(1u, "foo", 0, !kFin, &last_packet); // Packet 1 |
| 749 EXPECT_EQ(1u, last_packet); | 942 EXPECT_EQ(1u, last_packet); |
| 750 SendStreamDataToPeer(3u, "foo", 0, false, &last_packet); // Packet 2 | 943 SendStreamDataToPeer(3u, "foo", 0, !kFin, &last_packet); // Packet 2 |
| 751 EXPECT_EQ(2u, last_packet); | 944 EXPECT_EQ(2u, last_packet); |
| 752 SendAckPacketToPeer(); // Packet 3 | 945 SendAckPacketToPeer(); // Packet 3 |
| 753 SendStreamDataToPeer(5u, "foo", 0, false, &last_packet); // Packet 4 | 946 SendStreamDataToPeer(5u, "foo", 0, !kFin, &last_packet); // Packet 4 |
| 754 EXPECT_EQ(4u, last_packet); | 947 EXPECT_EQ(4u, last_packet); |
| 755 SendStreamDataToPeer(1u, "foo", 3, false, &last_packet); // Packet 5 | 948 SendStreamDataToPeer(1u, "foo", 3, !kFin, &last_packet); // Packet 5 |
| 756 EXPECT_EQ(5u, last_packet); | 949 EXPECT_EQ(5u, last_packet); |
| 757 SendStreamDataToPeer(3u, "foo", 3, false, &last_packet); // Packet 6 | 950 SendStreamDataToPeer(3u, "foo", 3, !kFin, &last_packet); // Packet 6 |
| 758 EXPECT_EQ(6u, last_packet); | 951 EXPECT_EQ(6u, last_packet); |
| 759 | 952 |
| 760 // Client will ack packets 1, [!2], 3, 4, 5 | 953 // Client will ack packets 1, [!2], 3, 4, 5 |
| 761 QuicAckFrame frame1(5, 0); | 954 QuicAckFrame frame1(5, 0); |
| 762 frame1.received_info.missing_packets.insert(2); | 955 frame1.received_info.missing_packets.insert(2); |
| 956 frame1.received_info.entropy_hash = |
| 957 QuicConnectionPeer::GetSentEntropyHash(&connection_, 5) ^ |
| 958 QuicConnectionPeer::GetSentEntropyHash(&connection_, 2) ^ |
| 959 QuicConnectionPeer::GetSentEntropyHash(&connection_, 1); |
| 763 | 960 |
| 764 // The connection should pass up acks for 1, 4, 5. 2 is not acked, and 3 was | 961 // The connection should pass up acks for 1, 4, 5. 2 is not acked, and 3 was |
| 765 // an ackframe so should not be passed up. | 962 // an ackframe so should not be passed up. |
| 766 QuicConnectionVisitorInterface::AckedPackets expected_acks; | 963 SequenceNumberSet expected_acks; |
| 767 expected_acks.insert(1); | 964 expected_acks.insert(1); |
| 768 expected_acks.insert(4); | 965 expected_acks.insert(4); |
| 769 expected_acks.insert(5); | 966 expected_acks.insert(5); |
| 770 | 967 |
| 771 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); | 968 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); |
| 772 ProcessAckPacket(&frame1); | 969 ProcessAckPacket(&frame1); |
| 773 | 970 |
| 774 // Now the client implicitly acks 2, and explicitly acks 6 | 971 // Now the client implicitly acks 2, and explicitly acks 6 |
| 775 QuicAckFrame frame2(6, 0); | 972 QuicAckFrame frame2(6, 0); |
| 973 frame2.received_info.entropy_hash = |
| 974 QuicConnectionPeer::GetSentEntropyHash(&connection_, 6); |
| 776 expected_acks.clear(); | 975 expected_acks.clear(); |
| 777 // Both acks should be passed up. | 976 // Both acks should be passed up. |
| 778 expected_acks.insert(2); | 977 expected_acks.insert(2); |
| 779 expected_acks.insert(6); | 978 expected_acks.insert(6); |
| 780 | 979 |
| 781 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); | 980 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); |
| 782 ProcessAckPacket(&frame2); | 981 ProcessAckPacket(&frame2); |
| 783 } | 982 } |
| 784 | 983 |
| 785 TEST_F(QuicConnectionTest, DontLatchUnackedPacket) { | 984 TEST_F(QuicConnectionTest, DontLatchUnackedPacket) { |
| 786 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); | 985 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); |
| 787 SendStreamDataToPeer(1, "foo", 0, false, NULL); // Packet 1; | 986 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); // Packet 1; |
| 788 SendAckPacketToPeer(); // Packet 2 | 987 SendAckPacketToPeer(); // Packet 2 |
| 789 | 988 |
| 790 // This sets least unacked to 2, the ack packet. | 989 // This sets least unacked to 3 (unsent packet), since we don't need |
| 791 QuicConnectionVisitorInterface::AckedPackets expected_acks; | 990 // an ack for Packet 2 (ack packet). |
| 991 SequenceNumberSet expected_acks; |
| 792 expected_acks.insert(1); | 992 expected_acks.insert(1); |
| 793 // Client acks packet 1 | 993 // Client acks packet 1 |
| 794 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); | 994 EXPECT_CALL(visitor_, OnAck(ContainerEq(expected_acks))); |
| 795 QuicAckFrame frame(1, 0); | 995 QuicAckFrame frame(1, 0); |
| 996 frame.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash( |
| 997 &connection_, 1); |
| 796 ProcessAckPacket(&frame); | 998 ProcessAckPacket(&frame); |
| 797 | 999 |
| 798 // Verify that our internal state has least-unacked as 2. | 1000 // Verify that our internal state has least-unacked as 3. |
| 799 QuicAckFrame* outgoing_ack = QuicConnectionPeer::GetOutgoingAck(&connection_); | 1001 EXPECT_EQ(3u, outgoing_ack()->sent_info.least_unacked); |
| 800 EXPECT_EQ(2u, outgoing_ack->sent_info.least_unacked); | |
| 801 | 1002 |
| 802 // When we send an ack, we make sure our least-unacked makes sense. In this | 1003 // When we send an ack, we make sure our least-unacked makes sense. In this |
| 803 // case since we're not waiting on an ack for 2 and all packets are acked, we | 1004 // case since we're not waiting on an ack for 2 and all packets are acked, we |
| 804 // set it to 3. | 1005 // set it to 3. |
| 805 SendAckPacketToPeer(); // Packet 3 | 1006 SendAckPacketToPeer(); // Packet 3 |
| 806 EXPECT_EQ(3u, outgoing_ack->sent_info.least_unacked); | 1007 // Since this was an ack packet, we set least_unacked to 4. |
| 1008 EXPECT_EQ(4u, outgoing_ack()->sent_info.least_unacked); |
| 1009 // Check that the outgoing ack had its sequence number as least_unacked. |
| 807 EXPECT_EQ(3u, last_ack()->sent_info.least_unacked); | 1010 EXPECT_EQ(3u, last_ack()->sent_info.least_unacked); |
| 1011 |
| 1012 SendStreamDataToPeer(1, "bar", 3, false, NULL); // Packet 4 |
| 1013 EXPECT_EQ(4u, outgoing_ack()->sent_info.least_unacked); |
| 1014 SendAckPacketToPeer(); // Packet 5 |
| 1015 EXPECT_EQ(4u, last_ack()->sent_info.least_unacked); |
| 808 } | 1016 } |
| 809 | 1017 |
| 810 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterFecPacket) { | 1018 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterFecPacket) { |
| 811 // Don't send missing packet 1. | 1019 // Don't send missing packet 1. |
| 812 ProcessFecPacket(2, 1, true); | 1020 ProcessFecPacket(2, 1, true, !kFecEntropyFlag); |
| 1021 EXPECT_FALSE(revived_header_.entropy_flag); |
| 813 } | 1022 } |
| 814 | 1023 |
| 815 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) { | 1024 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) { |
| 816 ProcessFecProtectedPacket(1, false); | 1025 ProcessFecProtectedPacket(1, false, kEntropyFlag); |
| 817 // Don't send missing packet 2. | 1026 // Don't send missing packet 2. |
| 818 ProcessFecPacket(3, 1, true); | 1027 ProcessFecPacket(3, 1, true, !kFecEntropyFlag); |
| 1028 EXPECT_TRUE(revived_header_.entropy_flag); |
| 819 } | 1029 } |
| 820 | 1030 |
| 821 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacketsThenFecPacket) { | 1031 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacketsThenFecPacket) { |
| 822 ProcessFecProtectedPacket(1, false); | 1032 ProcessFecProtectedPacket(1, false, !kEntropyFlag); |
| 823 // Don't send missing packet 2. | 1033 // Don't send missing packet 2. |
| 824 ProcessFecProtectedPacket(3, false); | 1034 ProcessFecProtectedPacket(3, false, !kEntropyFlag); |
| 825 ProcessFecPacket(4, 1, true); | 1035 ProcessFecPacket(4, 1, true, kFecEntropyFlag); |
| 1036 EXPECT_TRUE(revived_header_.entropy_flag); |
| 826 } | 1037 } |
| 827 | 1038 |
| 828 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacket) { | 1039 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPacket) { |
| 829 // Don't send missing packet 1. | 1040 // Don't send missing packet 1. |
| 830 ProcessFecPacket(3, 1, false); // out of order | 1041 ProcessFecPacket(3, 1, false, !kFecEntropyFlag); |
| 831 ProcessFecProtectedPacket(2, true); | 1042 // out of order |
| 1043 ProcessFecProtectedPacket(2, true, !kEntropyFlag); |
| 1044 EXPECT_FALSE(revived_header_.entropy_flag); |
| 832 } | 1045 } |
| 833 | 1046 |
| 834 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPackets) { | 1047 TEST_F(QuicConnectionTest, ReviveMissingPacketAfterDataPackets) { |
| 835 ProcessFecProtectedPacket(1, false); | 1048 ProcessFecProtectedPacket(1, false, !kEntropyFlag); |
| 836 // Don't send missing packet 2. | 1049 // Don't send missing packet 2. |
| 837 ProcessFecPacket(6, 1, false); | 1050 ProcessFecPacket(6, 1, false, kFecEntropyFlag); |
| 838 ProcessFecProtectedPacket(3, false); | 1051 ProcessFecProtectedPacket(3, false, kEntropyFlag); |
| 839 ProcessFecProtectedPacket(4, false); | 1052 ProcessFecProtectedPacket(4, false, kEntropyFlag); |
| 840 ProcessFecProtectedPacket(5, true); | 1053 ProcessFecProtectedPacket(5, true, !kEntropyFlag); |
| 1054 EXPECT_TRUE(revived_header_.entropy_flag); |
| 841 } | 1055 } |
| 842 | 1056 |
| 843 TEST_F(QuicConnectionTest, TestRetransmit) { | 1057 TEST_F(QuicConnectionTest, TestRetransmit) { |
| 844 // TODO(rch): make this work | |
| 845 // FLAGS_fake_packet_loss_percentage = 100; | |
| 846 const QuicTime::Delta kDefaultRetransmissionTime = | 1058 const QuicTime::Delta kDefaultRetransmissionTime = |
| 847 QuicTime::Delta::FromMilliseconds(500); | 1059 QuicTime::Delta::FromMilliseconds(500); |
| 848 | 1060 |
| 849 QuicTime default_retransmission_time = clock_.Now().Add( | 1061 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( |
| 850 kDefaultRetransmissionTime); | 1062 kDefaultRetransmissionTime); |
| 851 | 1063 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); |
| 852 QuicAckFrame* outgoing_ack = QuicConnectionPeer::GetOutgoingAck(&connection_); | 1064 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); |
| 853 SendStreamDataToPeer(1, "foo", 0, false, NULL); | |
| 854 EXPECT_EQ(1u, outgoing_ack->sent_info.least_unacked); | |
| 855 | 1065 |
| 856 EXPECT_EQ(1u, last_header()->packet_sequence_number); | 1066 EXPECT_EQ(1u, last_header()->packet_sequence_number); |
| 857 EXPECT_EQ(default_retransmission_time, helper_->retransmission_alarm()); | 1067 EXPECT_EQ(default_retransmission_time, helper_->retransmission_alarm()); |
| 858 // Simulate the retransimission alarm firing | 1068 // Simulate the retransimission alarm firing |
| 859 clock_.AdvanceTime(kDefaultRetransmissionTime); | 1069 clock_.AdvanceTime(kDefaultRetransmissionTime); |
| 860 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _)); | 1070 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); |
| 861 connection_.RetransmitPacket(1); | 1071 connection_.RetransmitPacket(1); |
| 862 EXPECT_EQ(2u, last_header()->packet_sequence_number); | 1072 EXPECT_EQ(2u, last_header()->packet_sequence_number); |
| 863 EXPECT_EQ(2u, outgoing_ack->sent_info.least_unacked); | 1073 EXPECT_EQ(2u, outgoing_ack()->sent_info.least_unacked); |
| 864 } | 1074 } |
| 865 | 1075 |
| 866 TEST_F(QuicConnectionTest, TestRetransmitOrder) { | 1076 TEST_F(QuicConnectionTest, TestRetransmitOrder) { |
| 867 QuicByteCount first_packet_size; | 1077 QuicByteCount first_packet_size; |
| 868 EXPECT_CALL(*send_algorithm_, SentPacket(_,_,_)).WillOnce( | 1078 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).WillOnce( |
| 869 SaveArg<1>(&first_packet_size)); | 1079 SaveArg<2>(&first_packet_size)); |
| 870 connection_.SendStreamData(1, "first_packet", 0, false); | 1080 connection_.SendStreamData(1, "first_packet", 0, !kFin); |
| 871 QuicByteCount second_packet_size; | 1081 QuicByteCount second_packet_size; |
| 872 EXPECT_CALL(*send_algorithm_, SentPacket(_,_,_)).WillOnce( | 1082 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).WillOnce( |
| 873 SaveArg<1>(&second_packet_size)); | 1083 SaveArg<2>(&second_packet_size)); |
| 874 connection_.SendStreamData(1, "second_packet", 12, false); | 1084 connection_.SendStreamData(1, "second_packet", 12, !kFin); |
| 875 EXPECT_NE(first_packet_size, second_packet_size); | 1085 EXPECT_NE(first_packet_size, second_packet_size); |
| 876 // Advance the clock by huge time to make sure packets will be retransmitted. | 1086 // Advance the clock by huge time to make sure packets will be retransmitted. |
| 877 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); | 1087 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); |
| 878 { | 1088 { |
| 879 InSequence s; | 1089 InSequence s; |
| 880 EXPECT_CALL(*send_algorithm_, SentPacket(_, first_packet_size, _)); | 1090 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, first_packet_size, _)); |
| 881 EXPECT_CALL(*send_algorithm_, SentPacket(_, second_packet_size, _)); | 1091 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, second_packet_size, _)); |
| 882 } | 1092 } |
| 883 connection_.OnRetransmissionTimeout(); | 1093 connection_.OnRetransmissionTimeout(); |
| 884 } | 1094 } |
| 885 | 1095 |
| 886 TEST_F(QuicConnectionTest, TestRetransmissionCountCalculation) { | 1096 TEST_F(QuicConnectionTest, TestRetransmissionCountCalculation) { |
| 1097 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); |
| 887 QuicPacketSequenceNumber original_sequence_number; | 1098 QuicPacketSequenceNumber original_sequence_number; |
| 888 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, false)).WillOnce( | 1099 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, !kIsRetransmission)) |
| 889 SaveArg<0>(&original_sequence_number)); | 1100 .WillOnce(SaveArg<1>(&original_sequence_number)); |
| 890 connection_.SendStreamData(1, "foo", 0, false); | 1101 connection_.SendStreamData(1, "foo", 0, !kFin); |
| 891 EXPECT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( | 1102 EXPECT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( |
| 892 &connection_, original_sequence_number)); | 1103 &connection_, original_sequence_number)); |
| 893 EXPECT_EQ(0u, QuicConnectionPeer::GetRetransmissionCount( | 1104 EXPECT_EQ(0u, QuicConnectionPeer::GetRetransmissionCount( |
| 894 &connection_, original_sequence_number)); | 1105 &connection_, original_sequence_number)); |
| 895 // Force retransmission due to RTO. | 1106 // Force retransmission due to RTO. |
| 896 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); | 1107 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); |
| 897 QuicPacketSequenceNumber rto_sequence_number; | 1108 QuicPacketSequenceNumber rto_sequence_number; |
| 898 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, true)).WillOnce( | 1109 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, kIsRetransmission)) |
| 899 SaveArg<0>(&rto_sequence_number)); | 1110 .WillOnce(SaveArg<1>(&rto_sequence_number)); |
| 900 connection_.OnRetransmissionTimeout(); | 1111 connection_.OnRetransmissionTimeout(); |
| 901 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( | 1112 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( |
| 902 &connection_, original_sequence_number)); | 1113 &connection_, original_sequence_number)); |
| 903 EXPECT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( | 1114 EXPECT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( |
| 904 &connection_, rto_sequence_number)); | 1115 &connection_, rto_sequence_number)); |
| 905 EXPECT_EQ(1u, QuicConnectionPeer::GetRetransmissionCount( | 1116 EXPECT_EQ(1u, QuicConnectionPeer::GetRetransmissionCount( |
| 906 &connection_, rto_sequence_number)); | 1117 &connection_, rto_sequence_number)); |
| 907 // Once by explicit nack. | 1118 // Once by explicit nack. |
| 908 QuicPacketSequenceNumber nack_sequence_number; | 1119 QuicPacketSequenceNumber nack_sequence_number; |
| 909 // Ack packets might generate some other packets, which are not | 1120 // Ack packets might generate some other packets, which are not |
| 910 // retransmissions. (More ack packets). | 1121 // retransmissions. (More ack packets). |
| 911 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, false)).Times(AnyNumber()); | 1122 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, !kIsRetransmission)) |
| 912 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, true)).WillOnce( | 1123 .Times(AnyNumber()); |
| 913 SaveArg<0>(&nack_sequence_number)); | 1124 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, kIsRetransmission)) |
| 1125 .WillOnce(SaveArg<1>(&nack_sequence_number)); |
| 914 QuicAckFrame ack(rto_sequence_number, 0); | 1126 QuicAckFrame ack(rto_sequence_number, 0); |
| 915 // Ack the retransmitted packet. | 1127 // Ack the retransmitted packet. |
| 916 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); | 1128 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); |
| 917 ack.received_info.missing_packets.insert(rto_sequence_number); | 1129 ack.received_info.missing_packets.insert(rto_sequence_number); |
| 1130 ack.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash( |
| 1131 &connection_, rto_sequence_number - 1); |
| 918 for (int i = 0; i < 3; i++) { | 1132 for (int i = 0; i < 3; i++) { |
| 919 ProcessAckPacket(&ack); | 1133 ProcessAckPacket(&ack); |
| 920 } | 1134 } |
| 921 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( | 1135 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( |
| 922 &connection_, rto_sequence_number)); | 1136 &connection_, rto_sequence_number)); |
| 923 EXPECT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( | 1137 EXPECT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( |
| 924 &connection_, nack_sequence_number)); | 1138 &connection_, nack_sequence_number)); |
| 925 EXPECT_EQ(2u, QuicConnectionPeer::GetRetransmissionCount( | 1139 EXPECT_EQ(2u, QuicConnectionPeer::GetRetransmissionCount( |
| 926 &connection_, nack_sequence_number)); | 1140 &connection_, nack_sequence_number)); |
| 927 } | 1141 } |
| 928 | 1142 |
| 929 TEST_F(QuicConnectionTest, SetRTOAfterWritingToSocket) { | 1143 TEST_F(QuicConnectionTest, SetRTOAfterWritingToSocket) { |
| 930 helper_->set_blocked(true); | 1144 helper_->set_blocked(true); |
| 931 connection_.SendStreamData(1, "foo", 0, false); | 1145 connection_.SendStreamData(1, "foo", 0, !kFin); |
| 932 // Make sure that RTO is not started when the packet is queued. | 1146 // Make sure that RTO is not started when the packet is queued. |
| 933 EXPECT_EQ(0u, QuicConnectionPeer::GetNumRetransmissionTimeouts(&connection_)); | 1147 EXPECT_EQ(0u, QuicConnectionPeer::GetNumRetransmissionTimeouts(&connection_)); |
| 934 | 1148 |
| 935 // Test that RTO is started once we write to the socket. | 1149 // Test that RTO is started once we write to the socket. |
| 936 helper_->set_blocked(false); | 1150 helper_->set_blocked(false); |
| 937 EXPECT_CALL(visitor_, OnCanWrite()); | 1151 EXPECT_CALL(visitor_, OnCanWrite()); |
| 938 connection_.OnCanWrite(); | 1152 connection_.OnCanWrite(); |
| 939 EXPECT_EQ(1u, QuicConnectionPeer::GetNumRetransmissionTimeouts(&connection_)); | 1153 EXPECT_EQ(1u, QuicConnectionPeer::GetNumRetransmissionTimeouts(&connection_)); |
| 940 } | 1154 } |
| 941 | 1155 |
| 942 TEST_F(QuicConnectionTest, TestQueued) { | 1156 TEST_F(QuicConnectionTest, TestQueued) { |
| 943 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1157 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 944 helper_->set_blocked(true); | 1158 helper_->set_blocked(true); |
| 945 connection_.SendStreamData(1, "foo", 0, false); | 1159 connection_.SendStreamData(1, "foo", 0, !kFin); |
| 946 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1160 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 947 | 1161 |
| 948 // Attempt to send all packets, but since we're actually still | 1162 // Attempt to send all packets, but since we're actually still |
| 949 // blocked, they should all remain queued. | 1163 // blocked, they should all remain queued. |
| 950 EXPECT_FALSE(connection_.OnCanWrite()); | 1164 EXPECT_FALSE(connection_.OnCanWrite()); |
| 951 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1165 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 952 | 1166 |
| 953 // Unblock the writes and actually send. | 1167 // Unblock the writes and actually send. |
| 954 helper_->set_blocked(false); | 1168 helper_->set_blocked(false); |
| 955 EXPECT_CALL(visitor_, OnCanWrite()); | 1169 EXPECT_CALL(visitor_, OnCanWrite()); |
| 956 EXPECT_TRUE(connection_.OnCanWrite()); | 1170 EXPECT_TRUE(connection_.OnCanWrite()); |
| 957 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1171 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 958 } | 1172 } |
| 959 | 1173 |
| 960 TEST_F(QuicConnectionTest, CloseFecGroup) { | 1174 TEST_F(QuicConnectionTest, CloseFecGroup) { |
| 961 // Don't send missing packet 1 | 1175 // Don't send missing packet 1 |
| 962 // Don't send missing packet 2 | 1176 // Don't send missing packet 2 |
| 963 ProcessFecProtectedPacket(3, false); | 1177 ProcessFecProtectedPacket(3, false, !kEntropyFlag); |
| 964 // Don't send missing FEC packet 3 | 1178 // Don't send missing FEC packet 3 |
| 965 ASSERT_EQ(1u, connection_.NumFecGroups()); | 1179 ASSERT_EQ(1u, connection_.NumFecGroups()); |
| 966 | 1180 |
| 967 // Now send non-fec protected ack packet and close the group | 1181 // Now send non-fec protected ack packet and close the group |
| 968 QuicAckFrame frame(0, 5); | 1182 QuicAckFrame frame(0, 5); |
| 969 creator_.set_sequence_number(4); | 1183 creator_.set_sequence_number(4); |
| 970 ProcessAckPacket(&frame); | 1184 ProcessAckPacket(&frame); |
| 971 ASSERT_EQ(0u, connection_.NumFecGroups()); | 1185 ASSERT_EQ(0u, connection_.NumFecGroups()); |
| 972 } | 1186 } |
| 973 | 1187 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 991 SendAckPacketToPeer(); | 1205 SendAckPacketToPeer(); |
| 992 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _, _)); | 1206 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _, _)); |
| 993 ProcessPacket(1); | 1207 ProcessPacket(1); |
| 994 } | 1208 } |
| 995 | 1209 |
| 996 TEST_F(QuicConnectionTest, DontUpdateQuicCongestionFeedbackFrameForRevived) { | 1210 TEST_F(QuicConnectionTest, DontUpdateQuicCongestionFeedbackFrameForRevived) { |
| 997 SendAckPacketToPeer(); | 1211 SendAckPacketToPeer(); |
| 998 // Process an FEC packet, and revive the missing data packet | 1212 // Process an FEC packet, and revive the missing data packet |
| 999 // but only contact the receive_algorithm once. | 1213 // but only contact the receive_algorithm once. |
| 1000 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _, _)); | 1214 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _, _)); |
| 1001 ProcessFecPacket(2, 1, true); | 1215 ProcessFecPacket(2, 1, true, !kEntropyFlag); |
| 1002 } | 1216 } |
| 1003 | 1217 |
| 1004 TEST_F(QuicConnectionTest, InitialTimeout) { | 1218 TEST_F(QuicConnectionTest, InitialTimeout) { |
| 1005 EXPECT_TRUE(connection_.connected()); | 1219 EXPECT_TRUE(connection_.connected()); |
| 1006 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false)); | 1220 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false)); |
| 1007 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _)); | 1221 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); |
| 1008 | 1222 |
| 1009 QuicTime default_timeout = clock_.Now().Add( | 1223 QuicTime default_timeout = clock_.ApproximateNow().Add( |
| 1010 QuicTime::Delta::FromMicroseconds(kDefaultTimeoutUs)); | 1224 QuicTime::Delta::FromMicroseconds(kDefaultTimeoutUs)); |
| 1011 EXPECT_EQ(default_timeout, helper_->timeout_alarm()); | 1225 EXPECT_EQ(default_timeout, helper_->timeout_alarm()); |
| 1012 | 1226 |
| 1013 // Simulate the timeout alarm firing | 1227 // Simulate the timeout alarm firing |
| 1014 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(kDefaultTimeoutUs)); | 1228 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(kDefaultTimeoutUs)); |
| 1015 EXPECT_TRUE(connection_.CheckForTimeout()); | 1229 EXPECT_TRUE(connection_.CheckForTimeout()); |
| 1016 EXPECT_FALSE(connection_.connected()); | 1230 EXPECT_FALSE(connection_.connected()); |
| 1017 } | 1231 } |
| 1018 | 1232 |
| 1019 TEST_F(QuicConnectionTest, TimeoutAfterSend) { | 1233 TEST_F(QuicConnectionTest, TimeoutAfterSend) { |
| 1020 EXPECT_TRUE(connection_.connected()); | 1234 EXPECT_TRUE(connection_.connected()); |
| 1021 | 1235 |
| 1022 QuicTime default_timeout = clock_.Now().Add( | 1236 QuicTime default_timeout = clock_.ApproximateNow().Add( |
| 1023 QuicTime::Delta::FromMicroseconds(kDefaultTimeoutUs)); | 1237 QuicTime::Delta::FromMicroseconds(kDefaultTimeoutUs)); |
| 1024 | 1238 |
| 1025 // When we send a packet, the timeout will change to 5000 + kDefaultTimeout. | 1239 // When we send a packet, the timeout will change to 5000 + kDefaultTimeout. |
| 1026 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); | 1240 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
| 1027 | 1241 |
| 1028 // Send an ack so we don't set the retransimission alarm. | 1242 // Send an ack so we don't set the retransimission alarm. |
| 1029 SendAckPacketToPeer(); | 1243 SendAckPacketToPeer(); |
| 1030 EXPECT_EQ(default_timeout, helper_->timeout_alarm()); | 1244 EXPECT_EQ(default_timeout, helper_->timeout_alarm()); |
| 1031 | 1245 |
| 1032 // The original alarm will fire. We should not time out because we had a | 1246 // The original alarm will fire. We should not time out because we had a |
| 1033 // network event at t=5000. The alarm will reregister. | 1247 // network event at t=5000. The alarm will reregister. |
| 1034 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( | 1248 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( |
| 1035 kDefaultTimeoutUs - 5000)); | 1249 kDefaultTimeoutUs - 5000)); |
| 1036 EXPECT_EQ(default_timeout, clock_.Now()); | 1250 EXPECT_EQ(default_timeout, clock_.ApproximateNow()); |
| 1037 EXPECT_FALSE(connection_.CheckForTimeout()); | 1251 EXPECT_FALSE(connection_.CheckForTimeout()); |
| 1038 EXPECT_TRUE(connection_.connected()); | 1252 EXPECT_TRUE(connection_.connected()); |
| 1039 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)), | 1253 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)), |
| 1040 helper_->timeout_alarm()); | 1254 helper_->timeout_alarm()); |
| 1041 | 1255 |
| 1042 // This time, we should time out. | 1256 // This time, we should time out. |
| 1043 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false)); | 1257 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false)); |
| 1044 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _)); | 1258 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); |
| 1045 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); | 1259 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
| 1046 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)), | 1260 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)), |
| 1047 clock_.Now()); | 1261 clock_.ApproximateNow()); |
| 1048 EXPECT_TRUE(connection_.CheckForTimeout()); | 1262 EXPECT_TRUE(connection_.CheckForTimeout()); |
| 1049 EXPECT_FALSE(connection_.connected()); | 1263 EXPECT_FALSE(connection_.connected()); |
| 1050 } | 1264 } |
| 1051 | 1265 |
| 1052 // TODO(ianswett): Add scheduler tests when should_retransmit is false. | 1266 // TODO(ianswett): Add scheduler tests when should_retransmit is false. |
| 1053 TEST_F(QuicConnectionTest, SendScheduler) { | 1267 TEST_F(QuicConnectionTest, SendScheduler) { |
| 1054 // Test that if we send a packet without delay, it is not queued. | 1268 // Test that if we send a packet without delay, it is not queued. |
| 1055 QuicPacket* packet = ConstructDataPacket(1, 0); | 1269 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
| 1056 EXPECT_CALL(*send_algorithm_, TimeUntilSend(false)).WillOnce(testing::Return( | 1270 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, !kIsRetransmission)).WillOnce( |
| 1057 QuicTime::Delta::Zero())); | 1271 testing::Return(QuicTime::Delta::Zero())); |
| 1058 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _)); | 1272 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); |
| 1059 connection_.SendOrQueuePacket(1, packet, false); | 1273 connection_.SendOrQueuePacket(1, packet, kTestEntropyHash); |
| 1060 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1274 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1061 } | 1275 } |
| 1062 | 1276 |
| 1063 TEST_F(QuicConnectionTest, SendSchedulerDelay) { | 1277 TEST_F(QuicConnectionTest, SendSchedulerDelay) { |
| 1064 // Test that if we send a packet with a delay, it ends up queued. | 1278 // Test that if we send a packet with a delay, it ends up queued. |
| 1065 QuicPacket* packet = ConstructDataPacket(1, 0); | 1279 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
| 1066 EXPECT_CALL(*send_algorithm_, TimeUntilSend(false)).WillOnce(testing::Return( | 1280 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, !kIsRetransmission)).WillOnce( |
| 1067 QuicTime::Delta::FromMicroseconds(1))); | 1281 testing::Return(QuicTime::Delta::FromMicroseconds(1))); |
| 1068 EXPECT_CALL(*send_algorithm_, SentPacket(1, _, _)).Times(0); | 1282 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, _)).Times(0); |
| 1069 connection_.SendOrQueuePacket(1, packet, false); | 1283 connection_.SendOrQueuePacket(1, packet, kTestEntropyHash); |
| 1070 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1284 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 1071 } | 1285 } |
| 1072 | 1286 |
| 1073 TEST_F(QuicConnectionTest, SendSchedulerForce) { | 1287 TEST_F(QuicConnectionTest, SendSchedulerForce) { |
| 1074 // Test that if we force send a packet, it is not queued. | 1288 // Test that if we force send a packet, it is not queued. |
| 1075 QuicPacket* packet = ConstructDataPacket(1, 0); | 1289 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
| 1076 EXPECT_CALL(*send_algorithm_, TimeUntilSend(true)).Times(0); | 1290 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, kIsRetransmission)).Times(0); |
| 1077 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _)); | 1291 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); |
| 1078 connection_.SendOrQueuePacket(1, packet, true); | 1292 connection_.SendOrQueuePacket(1, packet, kTestEntropyHash); |
| 1293 // XXX: fixme. was: connection_.SendOrQueuePacket(1, packet, kForce); |
| 1079 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1294 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1080 } | 1295 } |
| 1081 | 1296 |
| 1082 TEST_F(QuicConnectionTest, SendSchedulerEAGAIN) { | 1297 TEST_F(QuicConnectionTest, SendSchedulerEAGAIN) { |
| 1083 QuicPacket* packet = ConstructDataPacket(1, 0); | 1298 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
| 1084 helper_->set_blocked(true); | 1299 helper_->set_blocked(true); |
| 1085 EXPECT_CALL(*send_algorithm_, TimeUntilSend(false)).WillOnce(testing::Return( | 1300 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, !kIsRetransmission)).WillOnce( |
| 1086 QuicTime::Delta::Zero())); | 1301 testing::Return(QuicTime::Delta::Zero())); |
| 1087 EXPECT_CALL(*send_algorithm_, SentPacket(1, _, _)).Times(0); | 1302 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, _)).Times(0); |
| 1088 connection_.SendOrQueuePacket(1, packet, false); | 1303 connection_.SendOrQueuePacket(1, packet, kTestEntropyHash); |
| 1089 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1304 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 1090 } | 1305 } |
| 1091 | 1306 |
| 1092 TEST_F(QuicConnectionTest, SendSchedulerDelayThenSend) { | 1307 TEST_F(QuicConnectionTest, SendSchedulerDelayThenSend) { |
| 1093 // Test that if we send a packet with a delay, it ends up queued. | 1308 // Test that if we send a packet with a delay, it ends up queued. |
| 1094 QuicPacket* packet = ConstructDataPacket(1, 0); | 1309 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
| 1095 EXPECT_CALL(*send_algorithm_, TimeUntilSend(false)).WillOnce(testing::Return( | 1310 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, !kIsRetransmission)).WillOnce( |
| 1096 QuicTime::Delta::FromMicroseconds(1))); | 1311 testing::Return(QuicTime::Delta::FromMicroseconds(1))); |
| 1097 connection_.SendOrQueuePacket(1, packet, false); | 1312 connection_.SendOrQueuePacket(1, packet, kTestEntropyHash); |
| 1098 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1313 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 1099 | 1314 |
| 1100 // Advance the clock to fire the alarm, and configure the scheduler | 1315 // Advance the clock to fire the alarm, and configure the scheduler |
| 1101 // to permit the packet to be sent. | 1316 // to permit the packet to be sent. |
| 1102 EXPECT_CALL(*send_algorithm_, TimeUntilSend(false)).WillOnce(testing::Return( | 1317 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, !kIsRetransmission)).WillOnce( |
| 1103 QuicTime::Delta::Zero())); | 1318 testing::Return(QuicTime::Delta::Zero())); |
| 1104 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); | 1319 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); |
| 1105 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _)); | 1320 helper_->UnregisterSendAlarmIfRegistered(); |
| 1321 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); |
| 1106 EXPECT_CALL(visitor_, OnCanWrite()); | 1322 EXPECT_CALL(visitor_, OnCanWrite()); |
| 1107 connection_.OnCanWrite(); | 1323 connection_.OnCanWrite(); |
| 1108 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1324 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1109 } | 1325 } |
| 1110 | 1326 |
| 1111 TEST_F(QuicConnectionTest, SendSchedulerDelayThenRetransmit) { | 1327 TEST_F(QuicConnectionTest, SendSchedulerDelayThenRetransmit) { |
| 1112 // Fake packet loss. | 1328 EXPECT_CALL(*send_algorithm_, |
| 1113 EXPECT_CALL(*send_algorithm_, TimeUntilSend(false)).WillOnce(testing::Return( | 1329 TimeUntilSend(_, !kIsRetransmission)).WillRepeatedly( |
| 1114 QuicTime::Delta::Zero())); | 1330 testing::Return(QuicTime::Delta::Zero())); |
| 1115 EXPECT_CALL(*send_algorithm_, SentPacket(1, _, false)); | 1331 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, !kIsRetransmission)); |
| 1116 connection_.SendStreamData(1, "foo", 0, false); | 1332 connection_.SendStreamData(1, "foo", 0, !kFin); |
| 1117 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1333 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1118 // Advance the time for retransmission of lost packet. | 1334 // Advance the time for retransmission of lost packet. |
| 1119 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(501)); | 1335 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(501)); |
| 1120 // Test that if we send a retransmit with a delay, it ends up queued. | 1336 // Test that if we send a retransmit with a delay, it ends up queued. |
| 1121 EXPECT_CALL(*send_algorithm_, TimeUntilSend(true)).WillOnce(testing::Return( | 1337 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, kIsRetransmission)).WillOnce( |
| 1122 QuicTime::Delta::FromMicroseconds(1))); | 1338 testing::Return(QuicTime::Delta::FromMicroseconds(1))); |
| 1123 connection_.OnRetransmissionTimeout(); | 1339 connection_.OnRetransmissionTimeout(); |
| 1124 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1340 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 1125 | 1341 |
| 1126 // Advance the clock to fire the alarm, and configure the scheduler | 1342 // Advance the clock to fire the alarm, and configure the scheduler |
| 1127 // to permit the packet to be sent. | 1343 // to permit the packet to be sent. |
| 1128 EXPECT_CALL(*send_algorithm_, TimeUntilSend(true)).WillOnce(testing::Return( | 1344 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, kIsRetransmission)).WillOnce( |
| 1129 QuicTime::Delta::Zero())); | 1345 testing::Return(QuicTime::Delta::Zero())); |
| 1130 | 1346 |
| 1131 // Ensure the scheduler is notified this is a retransmit. | 1347 // Ensure the scheduler is notified this is a retransmit. |
| 1132 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, true)); | 1348 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, kIsRetransmission)); |
| 1133 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); | 1349 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); |
| 1350 helper_->UnregisterSendAlarmIfRegistered(); |
| 1134 EXPECT_CALL(visitor_, OnCanWrite()); | 1351 EXPECT_CALL(visitor_, OnCanWrite()); |
| 1135 connection_.OnCanWrite(); | 1352 connection_.OnCanWrite(); |
| 1136 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1353 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1137 } | 1354 } |
| 1138 | 1355 |
| 1139 TEST_F(QuicConnectionTest, SendSchedulerDelayAndQueue) { | 1356 TEST_F(QuicConnectionTest, SendSchedulerDelayAndQueue) { |
| 1140 QuicPacket* packet = ConstructDataPacket(1, 0); | 1357 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
| 1141 EXPECT_CALL(*send_algorithm_, TimeUntilSend(false)).WillOnce(testing::Return( | 1358 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, !kIsRetransmission)).WillOnce( |
| 1142 QuicTime::Delta::FromMicroseconds(1))); | 1359 testing::Return(QuicTime::Delta::FromMicroseconds(1))); |
| 1143 connection_.SendOrQueuePacket(1, packet, false); | 1360 connection_.SendOrQueuePacket(1, packet, kTestEntropyHash); |
| 1144 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1361 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 1145 | 1362 |
| 1146 // Attempt to send another packet and make sure that it gets queued. | 1363 // Attempt to send another packet and make sure that it gets queued. |
| 1147 packet = ConstructDataPacket(2, 0); | 1364 packet = ConstructDataPacket(2, 0, !kEntropyFlag); |
| 1148 connection_.SendOrQueuePacket(2, packet, false); | 1365 connection_.SendOrQueuePacket(2, packet, kTestEntropyHash); |
| 1149 EXPECT_EQ(2u, connection_.NumQueuedPackets()); | 1366 EXPECT_EQ(2u, connection_.NumQueuedPackets()); |
| 1150 } | 1367 } |
| 1151 | 1368 |
| 1152 TEST_F(QuicConnectionTest, SendSchedulerDelayThenAckAndSend) { | 1369 TEST_F(QuicConnectionTest, SendSchedulerDelayThenAckAndSend) { |
| 1153 QuicPacket* packet = ConstructDataPacket(1, 0); | 1370 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
| 1154 EXPECT_CALL(*send_algorithm_, TimeUntilSend(false)).WillOnce(testing::Return( | 1371 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, !kIsRetransmission)).WillOnce( |
| 1155 QuicTime::Delta::FromMicroseconds(10))); | 1372 testing::Return(QuicTime::Delta::FromMicroseconds(10))); |
| 1156 connection_.SendOrQueuePacket(1, packet, false); | 1373 connection_.SendOrQueuePacket(1, packet, kTestEntropyHash); |
| 1157 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1374 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 1158 | 1375 |
| 1159 // Now send non-retransmitting information, that we're not going to | 1376 // Now send non-retransmitting information, that we're not going to |
| 1160 // retransmit 3. The far end should stop waiting for it. | 1377 // retransmit 3. The far end should stop waiting for it. |
| 1161 QuicAckFrame frame(0, 1); | 1378 QuicAckFrame frame(0, 1); |
| 1162 EXPECT_CALL(*send_algorithm_, | 1379 EXPECT_CALL(*send_algorithm_, |
| 1163 TimeUntilSend(false)).WillRepeatedly( | 1380 TimeUntilSend(_, !kIsRetransmission)).WillRepeatedly( |
| 1164 testing::Return(QuicTime::Delta::Zero())); | 1381 testing::Return(QuicTime::Delta::Zero())); |
| 1165 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _)); | 1382 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); |
| 1166 EXPECT_CALL(visitor_, OnCanWrite()); | 1383 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(Return(true)); |
| 1167 ProcessAckPacket(&frame); | 1384 ProcessAckPacket(&frame); |
| 1168 | 1385 |
| 1169 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1386 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1170 // Ensure alarm is not set | 1387 // Ensure alarm is not set |
| 1171 EXPECT_FALSE(helper_->IsSendAlarmSet()); | 1388 EXPECT_FALSE(helper_->IsSendAlarmSet()); |
| 1172 } | 1389 } |
| 1173 | 1390 |
| 1174 TEST_F(QuicConnectionTest, SendSchedulerDelayThenAckAndHold) { | 1391 TEST_F(QuicConnectionTest, SendSchedulerDelayThenAckAndHold) { |
| 1175 QuicPacket* packet = ConstructDataPacket(1, 0); | 1392 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
| 1176 EXPECT_CALL(*send_algorithm_, TimeUntilSend(false)).WillOnce(testing::Return( | 1393 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, !kIsRetransmission)).WillOnce( |
| 1177 QuicTime::Delta::FromMicroseconds(10))); | 1394 testing::Return(QuicTime::Delta::FromMicroseconds(10))); |
| 1178 connection_.SendOrQueuePacket(1, packet, false); | 1395 connection_.SendOrQueuePacket(1, packet, kTestEntropyHash); |
| 1179 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1396 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 1180 | 1397 |
| 1181 // Now send non-retransmitting information, that we're not going to | 1398 // Now send non-retransmitting information, that we're not going to |
| 1182 // retransmit 3. The far end should stop waiting for it. | 1399 // retransmit 3. The far end should stop waiting for it. |
| 1183 QuicAckFrame frame(0, 1); | 1400 QuicAckFrame frame(0, 1); |
| 1184 EXPECT_CALL(*send_algorithm_, TimeUntilSend(false)).WillOnce(testing::Return( | 1401 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, !kIsRetransmission)).WillOnce( |
| 1185 QuicTime::Delta::FromMicroseconds(1))); | 1402 testing::Return(QuicTime::Delta::FromMicroseconds(1))); |
| 1186 ProcessAckPacket(&frame); | 1403 ProcessAckPacket(&frame); |
| 1187 | 1404 |
| 1188 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1405 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 1189 } | 1406 } |
| 1190 | 1407 |
| 1191 TEST_F(QuicConnectionTest, SendSchedulerDelayThenOnCanWrite) { | 1408 TEST_F(QuicConnectionTest, SendSchedulerDelayThenOnCanWrite) { |
| 1192 QuicPacket* packet = ConstructDataPacket(1, 0); | 1409 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
| 1193 EXPECT_CALL(*send_algorithm_, TimeUntilSend(false)).WillOnce(testing::Return( | 1410 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, !kIsRetransmission)).WillOnce( |
| 1194 QuicTime::Delta::FromMicroseconds(10))); | 1411 testing::Return(QuicTime::Delta::FromMicroseconds(10))); |
| 1195 connection_.SendOrQueuePacket(1, packet, false); | 1412 connection_.SendOrQueuePacket(1, packet, kTestEntropyHash); |
| 1196 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1413 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 1197 | 1414 |
| 1198 // OnCanWrite should not send the packet (because of the delay) | 1415 // OnCanWrite should not send the packet (because of the delay) |
| 1199 // but should still return true. | 1416 // but should still return true. |
| 1200 EXPECT_CALL(visitor_, OnCanWrite()); | 1417 EXPECT_CALL(visitor_, OnCanWrite()); |
| 1201 EXPECT_TRUE(connection_.OnCanWrite()); | 1418 EXPECT_TRUE(connection_.OnCanWrite()); |
| 1202 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1419 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 1203 } | 1420 } |
| 1204 | 1421 |
| 1205 TEST_F(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { | 1422 TEST_F(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { |
| 1206 // Limit to one byte per packet. | 1423 // Limit to one byte per packet. |
| 1207 size_t ciphertext_size = NullEncrypter().GetCiphertextSize(1); | 1424 size_t ciphertext_size = NullEncrypter().GetCiphertextSize(1); |
| 1208 connection_.options()->max_packet_length = | 1425 connection_.options()->max_packet_length = |
| 1209 ciphertext_size + QuicUtils::StreamFramePacketOverhead(1); | 1426 ciphertext_size + QuicUtils::StreamFramePacketOverhead(1); |
| 1210 | 1427 |
| 1211 // Queue the first packet. | 1428 // Queue the first packet. |
| 1212 EXPECT_CALL(*send_algorithm_, TimeUntilSend(false)).WillOnce(testing::Return( | 1429 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, !kIsRetransmission)).WillOnce( |
| 1213 QuicTime::Delta::FromMicroseconds(10))); | 1430 testing::Return(QuicTime::Delta::FromMicroseconds(10))); |
| 1214 EXPECT_EQ(1u, connection_.SendStreamData( | 1431 EXPECT_EQ(0u, connection_.SendStreamData( |
| 1215 1, "EnoughDataToQueue", 0, false).bytes_consumed); | 1432 1, "EnoughDataToQueue", 0, !kFin).bytes_consumed); |
| 1216 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1433 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1217 } | 1434 } |
| 1218 | 1435 |
| 1219 TEST_F(QuicConnectionTest, LoopThroughSendingPackets) { | 1436 TEST_F(QuicConnectionTest, LoopThroughSendingPackets) { |
| 1220 // Limit to one byte per packet. | 1437 // Limit to one byte per packet. |
| 1221 size_t ciphertext_size = NullEncrypter().GetCiphertextSize(1); | 1438 size_t ciphertext_size = NullEncrypter().GetCiphertextSize(1); |
| 1222 connection_.options()->max_packet_length = | 1439 connection_.options()->max_packet_length = |
| 1223 ciphertext_size + QuicUtils::StreamFramePacketOverhead(1); | 1440 ciphertext_size + QuicUtils::StreamFramePacketOverhead(1); |
| 1224 | 1441 |
| 1225 // Queue the first packet. | 1442 // Queue the first packet. |
| 1226 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _)).Times(17); | 1443 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(17); |
| 1227 EXPECT_EQ(17u, connection_.SendStreamData( | 1444 EXPECT_EQ(17u, connection_.SendStreamData( |
| 1228 1, "EnoughDataToQueue", 0, false).bytes_consumed); | 1445 1, "EnoughDataToQueue", 0, !kFin).bytes_consumed); |
| 1229 } | 1446 } |
| 1230 | 1447 |
| 1231 TEST_F(QuicConnectionTest, NoAckForClose) { | 1448 TEST_F(QuicConnectionTest, NoAckForClose) { |
| 1232 ProcessPacket(1); | 1449 ProcessPacket(1); |
| 1233 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(0); | 1450 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(0); |
| 1234 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CLIENT_GOING_AWAY, true)); | 1451 EXPECT_CALL(visitor_, ConnectionClose(QUIC_PEER_GOING_AWAY, true)); |
| 1235 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _)).Times(0); | 1452 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(0); |
| 1236 ProcessClosePacket(2, 0); | 1453 ProcessClosePacket(2, 0); |
| 1237 } | 1454 } |
| 1238 | 1455 |
| 1239 TEST_F(QuicConnectionTest, SendWhenDisconnected) { | 1456 TEST_F(QuicConnectionTest, SendWhenDisconnected) { |
| 1240 EXPECT_TRUE(connection_.connected()); | 1457 EXPECT_TRUE(connection_.connected()); |
| 1241 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CLIENT_GOING_AWAY, false)); | 1458 EXPECT_CALL(visitor_, ConnectionClose(QUIC_PEER_GOING_AWAY, false)); |
| 1242 connection_.CloseConnection(QUIC_CLIENT_GOING_AWAY, false); | 1459 connection_.CloseConnection(QUIC_PEER_GOING_AWAY, false); |
| 1243 EXPECT_FALSE(connection_.connected()); | 1460 EXPECT_FALSE(connection_.connected()); |
| 1244 QuicPacket* packet = ConstructDataPacket(1, 0); | 1461 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
| 1245 EXPECT_CALL(*send_algorithm_, SentPacket(1, _, _)).Times(0); | 1462 EXPECT_CALL(*send_algorithm_, SentPacket(_, 1, _, _)).Times(0); |
| 1246 connection_.SendOrQueuePacket(1, packet, false); | 1463 connection_.SendOrQueuePacket(1, packet, kTestEntropyHash); |
| 1247 } | 1464 } |
| 1248 | 1465 |
| 1249 TEST_F(QuicConnectionTest, PublicReset) { | 1466 TEST_F(QuicConnectionTest, PublicReset) { |
| 1250 QuicPublicResetPacket header; | 1467 QuicPublicResetPacket header; |
| 1251 header.public_header.guid = guid_; | 1468 header.public_header.guid = guid_; |
| 1252 header.public_header.flags = PACKET_PUBLIC_FLAGS_RST; | 1469 header.public_header.reset_flag = true; |
| 1470 header.public_header.version_flag = false; |
| 1253 header.rejected_sequence_number = 10101; | 1471 header.rejected_sequence_number = 10101; |
| 1254 scoped_ptr<QuicEncryptedPacket> packet( | 1472 scoped_ptr<QuicEncryptedPacket> packet( |
| 1255 framer_.ConstructPublicResetPacket(header)); | 1473 framer_.ConstructPublicResetPacket(header)); |
| 1256 EXPECT_CALL(visitor_, ConnectionClose(QUIC_PUBLIC_RESET, true)); | 1474 EXPECT_CALL(visitor_, ConnectionClose(QUIC_PUBLIC_RESET, true)); |
| 1257 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *packet); | 1475 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *packet); |
| 1258 } | 1476 } |
| 1259 | 1477 |
| 1478 TEST_F(QuicConnectionTest, GoAway) { |
| 1479 QuicGoAwayFrame goaway; |
| 1480 goaway.last_good_stream_id = 1; |
| 1481 goaway.error_code = QUIC_PEER_GOING_AWAY; |
| 1482 goaway.reason_phrase = "Going away."; |
| 1483 EXPECT_CALL(visitor_, OnGoAway(_)); |
| 1484 ProcessGoAwayPacket(&goaway); |
| 1485 } |
| 1486 |
| 1487 TEST_F(QuicConnectionTest, MissingPacketsBeforeLeastUnacked) { |
| 1488 QuicAckFrame ack(0, 4); |
| 1489 // Set the sequence number of the ack packet to be least unacked (4) |
| 1490 creator_.set_sequence_number(3); |
| 1491 ProcessAckPacket(&ack); |
| 1492 EXPECT_TRUE(outgoing_ack()->received_info.missing_packets.empty()); |
| 1493 } |
| 1494 |
| 1495 TEST_F(QuicConnectionTest, ReceivedEntropyHashCalculation) { |
| 1496 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillRepeatedly(Return(true)); |
| 1497 ProcessDataPacket(1, 1, kEntropyFlag); |
| 1498 ProcessDataPacket(4, 1, kEntropyFlag); |
| 1499 ProcessDataPacket(3, 1, !kEntropyFlag); |
| 1500 ProcessDataPacket(7, 1, kEntropyFlag); |
| 1501 EXPECT_EQ(146u, outgoing_ack()->received_info.entropy_hash); |
| 1502 } |
| 1503 |
| 1504 TEST_F(QuicConnectionTest, UpdateEntropyForReceivedPackets) { |
| 1505 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillRepeatedly(Return(true)); |
| 1506 ProcessDataPacket(1, 1, kEntropyFlag); |
| 1507 ProcessDataPacket(5, 1, kEntropyFlag); |
| 1508 ProcessDataPacket(4, 1, !kEntropyFlag); |
| 1509 EXPECT_EQ(34u, outgoing_ack()->received_info.entropy_hash); |
| 1510 // Make 4th packet my least unacked, and update entropy for 2, 3 packets. |
| 1511 QuicAckFrame ack(0, 4); |
| 1512 QuicPacketEntropyHash kRandomEntropyHash = 129u; |
| 1513 ack.sent_info.entropy_hash = kRandomEntropyHash; |
| 1514 creator_.set_sequence_number(5); |
| 1515 QuicPacketEntropyHash six_packet_entropy_hash = 0; |
| 1516 if (ProcessAckPacket(&ack)) { |
| 1517 six_packet_entropy_hash = 1 << 6; |
| 1518 }; |
| 1519 |
| 1520 EXPECT_EQ((kRandomEntropyHash + (1 << 5) + six_packet_entropy_hash), |
| 1521 outgoing_ack()->received_info.entropy_hash); |
| 1522 } |
| 1523 |
| 1524 TEST_F(QuicConnectionTest, UpdateEntropyHashUptoCurrentPacket) { |
| 1525 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillRepeatedly(Return(true)); |
| 1526 ProcessDataPacket(1, 1, kEntropyFlag); |
| 1527 ProcessDataPacket(5, 1, !kEntropyFlag); |
| 1528 ProcessDataPacket(22, 1, kEntropyFlag); |
| 1529 EXPECT_EQ(66u, outgoing_ack()->received_info.entropy_hash); |
| 1530 creator_.set_sequence_number(22); |
| 1531 QuicPacketEntropyHash kRandomEntropyHash = 85u; |
| 1532 // Current packet is the least unacked packet. |
| 1533 QuicAckFrame ack(0, 23); |
| 1534 ack.sent_info.entropy_hash = kRandomEntropyHash; |
| 1535 QuicPacketEntropyHash ack_entropy_hash = ProcessAckPacket(&ack); |
| 1536 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash), |
| 1537 outgoing_ack()->received_info.entropy_hash); |
| 1538 ProcessDataPacket(25, 1, kEntropyFlag); |
| 1539 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash + (1 << (25 % 8))), |
| 1540 outgoing_ack()->received_info.entropy_hash); |
| 1541 } |
| 1542 |
| 1543 TEST_F(QuicConnectionTest, EntropyCalculationForTruncatedAck) { |
| 1544 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).WillRepeatedly(Return(true)); |
| 1545 QuicPacketEntropyHash entropy[51]; |
| 1546 entropy[0] = 0; |
| 1547 for (int i = 1; i < 51; ++i) { |
| 1548 bool should_send = i % 10 != 0; |
| 1549 bool entropy_flag = (i & (i - 1)) != 0; |
| 1550 if (!should_send) { |
| 1551 entropy[i] = entropy[i - 1]; |
| 1552 continue; |
| 1553 } |
| 1554 if (entropy_flag) { |
| 1555 entropy[i] = entropy[i - 1] ^ (1 << (i % 8)); |
| 1556 } else { |
| 1557 entropy[i] = entropy[i - 1]; |
| 1558 } |
| 1559 ProcessDataPacket(i, 1, entropy_flag); |
| 1560 } |
| 1561 // Till 50 since 50th packet is not sent. |
| 1562 for (int i = 1; i < 50; ++i) { |
| 1563 EXPECT_EQ(entropy[i], QuicConnectionPeer::ReceivedEntropyHash( |
| 1564 &connection_, i)); |
| 1565 } |
| 1566 } |
| 1567 |
| 1568 TEST_F(QuicConnectionTest, CheckSentEntropyHash) { |
| 1569 creator_.set_sequence_number(1); |
| 1570 SequenceNumberSet missing_packets; |
| 1571 QuicPacketEntropyHash entropy_hash = 0; |
| 1572 QuicPacketSequenceNumber max_sequence_number = 51; |
| 1573 for (QuicPacketSequenceNumber i = 1; i <= max_sequence_number; ++i) { |
| 1574 bool is_missing = i % 10 != 0; |
| 1575 bool entropy_flag = (i & (i - 1)) != 0; |
| 1576 QuicPacketEntropyHash packet_entropy_hash = 0; |
| 1577 if (entropy_flag) { |
| 1578 packet_entropy_hash = 1 << (i % 8); |
| 1579 } |
| 1580 QuicPacket* packet = ConstructDataPacket(i, 0, entropy_flag); |
| 1581 connection_.SendOrQueuePacket(i, packet, packet_entropy_hash); |
| 1582 |
| 1583 if (is_missing) { |
| 1584 missing_packets.insert(i); |
| 1585 continue; |
| 1586 } |
| 1587 |
| 1588 entropy_hash ^= packet_entropy_hash; |
| 1589 } |
| 1590 EXPECT_TRUE(QuicConnectionPeer::IsValidEntropy( |
| 1591 &connection_, max_sequence_number, missing_packets, entropy_hash)) |
| 1592 << ""; |
| 1593 } |
| 1594 |
| 1260 } // namespace | 1595 } // namespace |
| 1261 } // namespace test | 1596 } // namespace test |
| 1262 } // namespace net | 1597 } // namespace net |
| OLD | NEW |