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