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

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

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/quic_connection.h" 5 #include "net/quic/quic_connection.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 const int kMinRetransmissionTimeMs = 200; 60 const int kMinRetransmissionTimeMs = 200;
61 61
62 // Used by TestConnection::SendStreamData3. 62 // Used by TestConnection::SendStreamData3.
63 const QuicStreamId kStreamId3 = 3; 63 const QuicStreamId kStreamId3 = 3;
64 // Used by TestConnection::SendStreamData5. 64 // Used by TestConnection::SendStreamData5.
65 const QuicStreamId kStreamId5 = 5; 65 const QuicStreamId kStreamId5 = 5;
66 66
67 class TestReceiveAlgorithm : public ReceiveAlgorithmInterface { 67 class TestReceiveAlgorithm : public ReceiveAlgorithmInterface {
68 public: 68 public:
69 explicit TestReceiveAlgorithm(QuicCongestionFeedbackFrame* feedback) 69 explicit TestReceiveAlgorithm(QuicCongestionFeedbackFrame* feedback)
70 : feedback_(feedback) { 70 : feedback_(feedback) {}
71 }
72 71
73 bool GenerateCongestionFeedback( 72 bool GenerateCongestionFeedback(
74 QuicCongestionFeedbackFrame* congestion_feedback) { 73 QuicCongestionFeedbackFrame* congestion_feedback) {
75 if (feedback_ == NULL) { 74 if (feedback_ == NULL) {
76 return false; 75 return false;
77 } 76 }
78 *congestion_feedback = *feedback_; 77 *congestion_feedback = *feedback_;
79 return true; 78 return true;
80 } 79 }
81 80
82 MOCK_METHOD3(RecordIncomingPacket, 81 MOCK_METHOD3(RecordIncomingPacket,
83 void(QuicByteCount, QuicPacketSequenceNumber, QuicTime)); 82 void(QuicByteCount, QuicPacketSequenceNumber, QuicTime));
84 83
85 private: 84 private:
86 QuicCongestionFeedbackFrame* feedback_; 85 QuicCongestionFeedbackFrame* feedback_;
87 86
88 DISALLOW_COPY_AND_ASSIGN(TestReceiveAlgorithm); 87 DISALLOW_COPY_AND_ASSIGN(TestReceiveAlgorithm);
89 }; 88 };
90 89
91 // TaggingEncrypter appends kTagSize bytes of |tag| to the end of each message. 90 // TaggingEncrypter appends kTagSize bytes of |tag| to the end of each message.
92 class TaggingEncrypter : public QuicEncrypter { 91 class TaggingEncrypter : public QuicEncrypter {
93 public: 92 public:
94 explicit TaggingEncrypter(uint8 tag) 93 explicit TaggingEncrypter(uint8 tag) : tag_(tag) {}
95 : tag_(tag) {
96 }
97 94
98 virtual ~TaggingEncrypter() {} 95 virtual ~TaggingEncrypter() {}
99 96
100 // QuicEncrypter interface. 97 // QuicEncrypter interface.
101 virtual bool SetKey(StringPiece key) OVERRIDE { return true; } 98 virtual bool SetKey(StringPiece key) OVERRIDE { return true; }
102 virtual bool SetNoncePrefix(StringPiece nonce_prefix) OVERRIDE { 99 virtual bool SetNoncePrefix(StringPiece nonce_prefix) OVERRIDE {
103 return true; 100 return true;
104 } 101 }
105 102
106 virtual bool Encrypt(StringPiece nonce, 103 virtual bool Encrypt(StringPiece nonce,
(...skipping 19 matching lines...) Expand all
126 virtual size_t GetNoncePrefixSize() const OVERRIDE { return 0; } 123 virtual size_t GetNoncePrefixSize() const OVERRIDE { return 0; }
127 124
128 virtual size_t GetMaxPlaintextSize(size_t ciphertext_size) const OVERRIDE { 125 virtual size_t GetMaxPlaintextSize(size_t ciphertext_size) const OVERRIDE {
129 return ciphertext_size - kTagSize; 126 return ciphertext_size - kTagSize;
130 } 127 }
131 128
132 virtual size_t GetCiphertextSize(size_t plaintext_size) const OVERRIDE { 129 virtual size_t GetCiphertextSize(size_t plaintext_size) const OVERRIDE {
133 return plaintext_size + kTagSize; 130 return plaintext_size + kTagSize;
134 } 131 }
135 132
136 virtual StringPiece GetKey() const OVERRIDE { 133 virtual StringPiece GetKey() const OVERRIDE { return StringPiece(); }
137 return StringPiece();
138 }
139 134
140 virtual StringPiece GetNoncePrefix() const OVERRIDE { 135 virtual StringPiece GetNoncePrefix() const OVERRIDE { return StringPiece(); }
141 return StringPiece();
142 }
143 136
144 private: 137 private:
145 enum { 138 enum {
146 kTagSize = 12, 139 kTagSize = 12,
147 }; 140 };
148 141
149 const uint8 tag_; 142 const uint8 tag_;
150 143
151 DISALLOW_COPY_AND_ASSIGN(TaggingEncrypter); 144 DISALLOW_COPY_AND_ASSIGN(TaggingEncrypter);
152 }; 145 };
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 StringPiece ciphertext) OVERRIDE { 177 StringPiece ciphertext) OVERRIDE {
185 if (ciphertext.size() < kTagSize) { 178 if (ciphertext.size() < kTagSize) {
186 return NULL; 179 return NULL;
187 } 180 }
188 if (!CheckTag(ciphertext, GetTag(ciphertext))) { 181 if (!CheckTag(ciphertext, GetTag(ciphertext))) {
189 return NULL; 182 return NULL;
190 } 183 }
191 const size_t len = ciphertext.size() - kTagSize; 184 const size_t len = ciphertext.size() - kTagSize;
192 uint8* buf = new uint8[len]; 185 uint8* buf = new uint8[len];
193 memcpy(buf, ciphertext.data(), len); 186 memcpy(buf, ciphertext.data(), len);
194 return new QuicData(reinterpret_cast<char*>(buf), len, 187 return new QuicData(
195 true /* owns buffer */); 188 reinterpret_cast<char*>(buf), len, true /* owns buffer */);
196 } 189 }
197 190
198 virtual StringPiece GetKey() const OVERRIDE { return StringPiece(); } 191 virtual StringPiece GetKey() const OVERRIDE { return StringPiece(); }
199 virtual StringPiece GetNoncePrefix() const OVERRIDE { return StringPiece(); } 192 virtual StringPiece GetNoncePrefix() const OVERRIDE { return StringPiece(); }
200 193
201 protected: 194 protected:
202 virtual uint8 GetTag(StringPiece ciphertext) { 195 virtual uint8 GetTag(StringPiece ciphertext) {
203 return ciphertext.data()[ciphertext.size()-1]; 196 return ciphertext.data()[ciphertext.size() - 1];
204 } 197 }
205 198
206 private: 199 private:
207 enum { 200 enum {
208 kTagSize = 12, 201 kTagSize = 12,
209 }; 202 };
210 203
211 bool CheckTag(StringPiece ciphertext, uint8 tag) { 204 bool CheckTag(StringPiece ciphertext, uint8 tag) {
212 for (size_t i = ciphertext.size() - kTagSize; i < ciphertext.size(); i++) { 205 for (size_t i = ciphertext.size() - kTagSize; i < ciphertext.size(); i++) {
213 if (ciphertext.data()[i] != tag) { 206 if (ciphertext.data()[i] != tag) {
214 return false; 207 return false;
215 } 208 }
216 } 209 }
217 210
218 return true; 211 return true;
219 } 212 }
220 }; 213 };
221 214
222 // StringTaggingDecrypter ensures that the final kTagSize bytes of the message 215 // StringTaggingDecrypter ensures that the final kTagSize bytes of the message
223 // match the expected value. 216 // match the expected value.
224 class StrictTaggingDecrypter : public TaggingDecrypter { 217 class StrictTaggingDecrypter : public TaggingDecrypter {
225 public: 218 public:
226 explicit StrictTaggingDecrypter(uint8 tag) : tag_(tag) {} 219 explicit StrictTaggingDecrypter(uint8 tag) : tag_(tag) {}
227 virtual ~StrictTaggingDecrypter() {} 220 virtual ~StrictTaggingDecrypter() {}
228 221
229 // TaggingQuicDecrypter 222 // TaggingQuicDecrypter
230 virtual uint8 GetTag(StringPiece ciphertext) OVERRIDE { 223 virtual uint8 GetTag(StringPiece ciphertext) OVERRIDE { return tag_; }
231 return tag_;
232 }
233 224
234 private: 225 private:
235 const uint8 tag_; 226 const uint8 tag_;
236 }; 227 };
237 228
238 class TestConnectionHelper : public QuicConnectionHelperInterface { 229 class TestConnectionHelper : public QuicConnectionHelperInterface {
239 public: 230 public:
240 class TestAlarm : public QuicAlarm { 231 class TestAlarm : public QuicAlarm {
241 public: 232 public:
242 explicit TestAlarm(QuicAlarm::Delegate* delegate) 233 explicit TestAlarm(QuicAlarm::Delegate* delegate) : QuicAlarm(delegate) {}
243 : QuicAlarm(delegate) {
244 }
245 234
246 virtual void SetImpl() OVERRIDE {} 235 virtual void SetImpl() OVERRIDE {}
247 virtual void CancelImpl() OVERRIDE {} 236 virtual void CancelImpl() OVERRIDE {}
248 using QuicAlarm::Fire; 237 using QuicAlarm::Fire;
249 }; 238 };
250 239
251 TestConnectionHelper(MockClock* clock, MockRandom* random_generator) 240 TestConnectionHelper(MockClock* clock, MockRandom* random_generator)
252 : clock_(clock), 241 : clock_(clock), random_generator_(random_generator) {
253 random_generator_(random_generator) {
254 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); 242 clock_->AdvanceTime(QuicTime::Delta::FromSeconds(1));
255 } 243 }
256 244
257 // QuicConnectionHelperInterface 245 // QuicConnectionHelperInterface
258 virtual const QuicClock* GetClock() const OVERRIDE { 246 virtual const QuicClock* GetClock() const OVERRIDE { return clock_; }
259 return clock_;
260 }
261 247
262 virtual QuicRandom* GetRandomGenerator() OVERRIDE { 248 virtual QuicRandom* GetRandomGenerator() OVERRIDE {
263 return random_generator_; 249 return random_generator_;
264 } 250 }
265 251
266 virtual QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) OVERRIDE { 252 virtual QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) OVERRIDE {
267 return new TestAlarm(delegate); 253 return new TestAlarm(delegate);
268 } 254 }
269 255
270 private: 256 private:
271 MockClock* clock_; 257 MockClock* clock_;
272 MockRandom* random_generator_; 258 MockRandom* random_generator_;
273 259
274 DISALLOW_COPY_AND_ASSIGN(TestConnectionHelper); 260 DISALLOW_COPY_AND_ASSIGN(TestConnectionHelper);
275 }; 261 };
276 262
277 class TestPacketWriter : public QuicPacketWriter { 263 class TestPacketWriter : public QuicPacketWriter {
278 public: 264 public:
279 explicit TestPacketWriter(QuicVersion version) 265 explicit TestPacketWriter(QuicVersion version)
280 : version_(version), 266 : version_(version),
281 framer_(SupportedVersions(version_)), 267 framer_(SupportedVersions(version_)),
282 last_packet_size_(0), 268 last_packet_size_(0),
283 write_blocked_(false), 269 write_blocked_(false),
284 block_on_next_write_(false), 270 block_on_next_write_(false),
285 is_write_blocked_data_buffered_(false), 271 is_write_blocked_data_buffered_(false),
286 final_bytes_of_last_packet_(0), 272 final_bytes_of_last_packet_(0),
287 final_bytes_of_previous_packet_(0), 273 final_bytes_of_previous_packet_(0),
288 use_tagging_decrypter_(false), 274 use_tagging_decrypter_(false),
289 packets_write_attempts_(0) { 275 packets_write_attempts_(0) {}
290 }
291 276
292 // QuicPacketWriter interface 277 // QuicPacketWriter interface
293 virtual WriteResult WritePacket( 278 virtual WriteResult WritePacket(const char* buffer,
294 const char* buffer, size_t buf_len, 279 size_t buf_len,
295 const IPAddressNumber& self_address, 280 const IPAddressNumber& self_address,
296 const IPEndPoint& peer_address) OVERRIDE { 281 const IPEndPoint& peer_address) OVERRIDE {
297 QuicEncryptedPacket packet(buffer, buf_len); 282 QuicEncryptedPacket packet(buffer, buf_len);
298 ++packets_write_attempts_; 283 ++packets_write_attempts_;
299 284
300 if (packet.length() >= sizeof(final_bytes_of_last_packet_)) { 285 if (packet.length() >= sizeof(final_bytes_of_last_packet_)) {
301 final_bytes_of_previous_packet_ = final_bytes_of_last_packet_; 286 final_bytes_of_previous_packet_ = final_bytes_of_last_packet_;
302 memcpy(&final_bytes_of_last_packet_, packet.data() + packet.length() - 4, 287 memcpy(&final_bytes_of_last_packet_,
288 packet.data() + packet.length() - 4,
303 sizeof(final_bytes_of_last_packet_)); 289 sizeof(final_bytes_of_last_packet_));
304 } 290 }
305 291
306 if (use_tagging_decrypter_) { 292 if (use_tagging_decrypter_) {
307 framer_.framer()->SetDecrypter(new TaggingDecrypter, ENCRYPTION_NONE); 293 framer_.framer()->SetDecrypter(new TaggingDecrypter, ENCRYPTION_NONE);
308 } 294 }
309 EXPECT_TRUE(framer_.ProcessPacket(packet)); 295 EXPECT_TRUE(framer_.ProcessPacket(packet));
310 if (block_on_next_write_) { 296 if (block_on_next_write_) {
311 write_blocked_ = true; 297 write_blocked_ = true;
312 block_on_next_write_ = false; 298 block_on_next_write_ = false;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 } 335 }
350 336
351 const vector<QuicStreamFrame>& stream_frames() const { 337 const vector<QuicStreamFrame>& stream_frames() const {
352 return framer_.stream_frames(); 338 return framer_.stream_frames();
353 } 339 }
354 340
355 const vector<QuicPingFrame>& ping_frames() const { 341 const vector<QuicPingFrame>& ping_frames() const {
356 return framer_.ping_frames(); 342 return framer_.ping_frames();
357 } 343 }
358 344
359 size_t last_packet_size() { 345 size_t last_packet_size() { return last_packet_size_; }
360 return last_packet_size_;
361 }
362 346
363 const QuicVersionNegotiationPacket* version_negotiation_packet() { 347 const QuicVersionNegotiationPacket* version_negotiation_packet() {
364 return framer_.version_negotiation_packet(); 348 return framer_.version_negotiation_packet();
365 } 349 }
366 350
367 void set_is_write_blocked_data_buffered(bool buffered) { 351 void set_is_write_blocked_data_buffered(bool buffered) {
368 is_write_blocked_data_buffered_ = buffered; 352 is_write_blocked_data_buffered_ = buffered;
369 } 353 }
370 354
371 void set_is_server(bool is_server) { 355 void set_is_server(bool is_server) {
372 // We invert is_server here, because the framer needs to parse packets 356 // We invert is_server here, because the framer needs to parse packets
373 // we send. 357 // we send.
374 QuicFramerPeer::SetIsServer(framer_.framer(), !is_server); 358 QuicFramerPeer::SetIsServer(framer_.framer(), !is_server);
375 } 359 }
376 360
377 // final_bytes_of_last_packet_ returns the last four bytes of the previous 361 // final_bytes_of_last_packet_ returns the last four bytes of the previous
378 // packet as a little-endian, uint32. This is intended to be used with a 362 // packet as a little-endian, uint32. This is intended to be used with a
379 // TaggingEncrypter so that tests can determine which encrypter was used for 363 // TaggingEncrypter so that tests can determine which encrypter was used for
380 // a given packet. 364 // a given packet.
381 uint32 final_bytes_of_last_packet() { return final_bytes_of_last_packet_; } 365 uint32 final_bytes_of_last_packet() { return final_bytes_of_last_packet_; }
382 366
383 // Returns the final bytes of the second to last packet. 367 // Returns the final bytes of the second to last packet.
384 uint32 final_bytes_of_previous_packet() { 368 uint32 final_bytes_of_previous_packet() {
385 return final_bytes_of_previous_packet_; 369 return final_bytes_of_previous_packet_;
386 } 370 }
387 371
388 void use_tagging_decrypter() { 372 void use_tagging_decrypter() { use_tagging_decrypter_ = true; }
389 use_tagging_decrypter_ = true;
390 }
391 373
392 uint32 packets_write_attempts() { return packets_write_attempts_; } 374 uint32 packets_write_attempts() { return packets_write_attempts_; }
393 375
394 void Reset() { framer_.Reset(); } 376 void Reset() { framer_.Reset(); }
395 377
396 void SetSupportedVersions(const QuicVersionVector& versions) { 378 void SetSupportedVersions(const QuicVersionVector& versions) {
397 framer_.SetSupportedVersions(versions); 379 framer_.SetSupportedVersions(versions);
398 } 380 }
399 381
400 private: 382 private:
(...skipping 13 matching lines...) Expand all
414 396
415 class TestConnection : public QuicConnection { 397 class TestConnection : public QuicConnection {
416 public: 398 public:
417 TestConnection(QuicConnectionId connection_id, 399 TestConnection(QuicConnectionId connection_id,
418 IPEndPoint address, 400 IPEndPoint address,
419 TestConnectionHelper* helper, 401 TestConnectionHelper* helper,
420 TestPacketWriter* writer, 402 TestPacketWriter* writer,
421 bool is_server, 403 bool is_server,
422 QuicVersion version, 404 QuicVersion version,
423 uint32 flow_control_send_window) 405 uint32 flow_control_send_window)
424 : QuicConnection(connection_id, address, helper, writer, is_server, 406 : QuicConnection(connection_id,
407 address,
408 helper,
409 writer,
410 is_server,
425 SupportedVersions(version), 411 SupportedVersions(version),
426 flow_control_send_window), 412 flow_control_send_window),
427 writer_(writer) { 413 writer_(writer) {
428 // Disable tail loss probes for most tests. 414 // Disable tail loss probes for most tests.
429 QuicSentPacketManagerPeer::SetMaxTailLossProbes( 415 QuicSentPacketManagerPeer::SetMaxTailLossProbes(
430 QuicConnectionPeer::GetSentPacketManager(this), 0); 416 QuicConnectionPeer::GetSentPacketManager(this), 0);
431 writer_->set_is_server(is_server); 417 writer_->set_is_server(is_server);
432 } 418 }
433 419
434 void SendAck() { 420 void SendAck() { QuicConnectionPeer::SendAck(this); }
435 QuicConnectionPeer::SendAck(this);
436 }
437 421
438 void SetReceiveAlgorithm(TestReceiveAlgorithm* receive_algorithm) { 422 void SetReceiveAlgorithm(TestReceiveAlgorithm* receive_algorithm) {
439 QuicConnectionPeer::SetReceiveAlgorithm(this, receive_algorithm); 423 QuicConnectionPeer::SetReceiveAlgorithm(this, receive_algorithm);
440 } 424 }
441 425
442 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { 426 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) {
443 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); 427 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm);
444 } 428 }
445 429
446 void SetLossAlgorithm(LossDetectionInterface* loss_algorithm) { 430 void SetLossAlgorithm(LossDetectionInterface* loss_algorithm) {
447 QuicSentPacketManagerPeer::SetLossAlgorithm( 431 QuicSentPacketManagerPeer::SetLossAlgorithm(
448 QuicConnectionPeer::GetSentPacketManager(this), loss_algorithm); 432 QuicConnectionPeer::GetSentPacketManager(this), loss_algorithm);
449 } 433 }
450 434
451 void SendPacket(EncryptionLevel level, 435 void SendPacket(EncryptionLevel level,
452 QuicPacketSequenceNumber sequence_number, 436 QuicPacketSequenceNumber sequence_number,
453 QuicPacket* packet, 437 QuicPacket* packet,
454 QuicPacketEntropyHash entropy_hash, 438 QuicPacketEntropyHash entropy_hash,
455 HasRetransmittableData retransmittable) { 439 HasRetransmittableData retransmittable) {
456 RetransmittableFrames* retransmittable_frames = 440 RetransmittableFrames* retransmittable_frames =
457 retransmittable == HAS_RETRANSMITTABLE_DATA ? 441 retransmittable == HAS_RETRANSMITTABLE_DATA
458 new RetransmittableFrames() : NULL; 442 ? new RetransmittableFrames()
459 OnSerializedPacket( 443 : NULL;
460 SerializedPacket(sequence_number, PACKET_6BYTE_SEQUENCE_NUMBER, 444 OnSerializedPacket(SerializedPacket(sequence_number,
461 packet, entropy_hash, retransmittable_frames)); 445 PACKET_6BYTE_SEQUENCE_NUMBER,
446 packet,
447 entropy_hash,
448 retransmittable_frames));
462 } 449 }
463 450
464 QuicConsumedData SendStreamDataWithString( 451 QuicConsumedData SendStreamDataWithString(
465 QuicStreamId id, 452 QuicStreamId id,
466 StringPiece data, 453 StringPiece data,
467 QuicStreamOffset offset, 454 QuicStreamOffset offset,
468 bool fin, 455 bool fin,
469 QuicAckNotifier::DelegateInterface* delegate) { 456 QuicAckNotifier::DelegateInterface* delegate) {
470 IOVector data_iov; 457 IOVector data_iov;
471 if (!data.empty()) { 458 if (!data.empty()) {
(...skipping 22 matching lines...) Expand all
494 // split needlessly across packet boundaries). As a result, we have separate 481 // split needlessly across packet boundaries). As a result, we have separate
495 // tests for some cases for this stream. 482 // tests for some cases for this stream.
496 QuicConsumedData SendCryptoStreamData() { 483 QuicConsumedData SendCryptoStreamData() {
497 this->Flush(); 484 this->Flush();
498 QuicConsumedData consumed = 485 QuicConsumedData consumed =
499 SendStreamDataWithString(kCryptoStreamId, "chlo", 0, !kFin, NULL); 486 SendStreamDataWithString(kCryptoStreamId, "chlo", 0, !kFin, NULL);
500 this->Flush(); 487 this->Flush();
501 return consumed; 488 return consumed;
502 } 489 }
503 490
504 bool is_server() { 491 bool is_server() { return QuicConnectionPeer::IsServer(this); }
505 return QuicConnectionPeer::IsServer(this);
506 }
507 492
508 void set_version(QuicVersion version) { 493 void set_version(QuicVersion version) {
509 QuicConnectionPeer::GetFramer(this)->set_version(version); 494 QuicConnectionPeer::GetFramer(this)->set_version(version);
510 } 495 }
511 496
512 void SetSupportedVersions(const QuicVersionVector& versions) { 497 void SetSupportedVersions(const QuicVersionVector& versions) {
513 QuicConnectionPeer::GetFramer(this)->SetSupportedVersions(versions); 498 QuicConnectionPeer::GetFramer(this)->SetSupportedVersions(versions);
514 writer_->SetSupportedVersions(versions); 499 writer_->SetSupportedVersions(versions);
515 } 500 }
516 501
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 // Used for testing packets revived from FEC packets. 547 // Used for testing packets revived from FEC packets.
563 class FecQuicConnectionDebugVisitor 548 class FecQuicConnectionDebugVisitor
564 : public QuicConnectionDebugVisitorInterface { 549 : public QuicConnectionDebugVisitorInterface {
565 public: 550 public:
566 virtual void OnRevivedPacket(const QuicPacketHeader& header, 551 virtual void OnRevivedPacket(const QuicPacketHeader& header,
567 StringPiece data) OVERRIDE { 552 StringPiece data) OVERRIDE {
568 revived_header_ = header; 553 revived_header_ = header;
569 } 554 }
570 555
571 // Public accessor method. 556 // Public accessor method.
572 QuicPacketHeader revived_header() const { 557 QuicPacketHeader revived_header() const { return revived_header_; }
573 return revived_header_;
574 }
575 558
576 private: 559 private:
577 QuicPacketHeader revived_header_; 560 QuicPacketHeader revived_header_;
578 }; 561 };
579 562
580 class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { 563 class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> {
581 protected: 564 protected:
582 QuicConnectionTest() 565 QuicConnectionTest()
583 : connection_id_(42), 566 : connection_id_(42),
584 framer_(SupportedVersions(version()), QuicTime::Zero(), false), 567 framer_(SupportedVersions(version()), QuicTime::Zero(), false),
585 creator_(connection_id_, &framer_, &random_generator_, false), 568 creator_(connection_id_, &framer_, &random_generator_, false),
586 send_algorithm_(new StrictMock<MockSendAlgorithm>), 569 send_algorithm_(new StrictMock<MockSendAlgorithm>),
587 loss_algorithm_(new MockLossAlgorithm()), 570 loss_algorithm_(new MockLossAlgorithm()),
588 helper_(new TestConnectionHelper(&clock_, &random_generator_)), 571 helper_(new TestConnectionHelper(&clock_, &random_generator_)),
589 writer_(new TestPacketWriter(version())), 572 writer_(new TestPacketWriter(version())),
590 connection_(connection_id_, IPEndPoint(), helper_.get(), 573 connection_(connection_id_,
591 writer_.get(), false, version(), 574 IPEndPoint(),
575 helper_.get(),
576 writer_.get(),
577 false,
578 version(),
592 kDefaultFlowControlSendWindow), 579 kDefaultFlowControlSendWindow),
593 frame1_(1, false, 0, MakeIOVector(data1)), 580 frame1_(1, false, 0, MakeIOVector(data1)),
594 frame2_(1, false, 3, MakeIOVector(data2)), 581 frame2_(1, false, 3, MakeIOVector(data2)),
595 sequence_number_length_(PACKET_6BYTE_SEQUENCE_NUMBER), 582 sequence_number_length_(PACKET_6BYTE_SEQUENCE_NUMBER),
596 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { 583 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) {
597 connection_.set_visitor(&visitor_); 584 connection_.set_visitor(&visitor_);
598 connection_.SetSendAlgorithm(send_algorithm_); 585 connection_.SetSendAlgorithm(send_algorithm_);
599 connection_.SetLossAlgorithm(loss_algorithm_); 586 connection_.SetLossAlgorithm(loss_algorithm_);
600 framer_.set_received_entropy_calculator(&entropy_calculator_); 587 framer_.set_received_entropy_calculator(&entropy_calculator_);
601 // Simplify tests by not sending feedback unless specifically configured. 588 // Simplify tests by not sending feedback unless specifically configured.
602 SetFeedback(NULL); 589 SetFeedback(NULL);
603 EXPECT_CALL( 590 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
604 *send_algorithm_, TimeUntilSend(_, _)).WillRepeatedly(Return( 591 .WillRepeatedly(Return(QuicTime::Delta::Zero()));
605 QuicTime::Delta::Zero())); 592 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _))
606 EXPECT_CALL(*receive_algorithm_,
607 RecordIncomingPacket(_, _, _)).Times(AnyNumber());
608 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _))
609 .Times(AnyNumber()); 593 .Times(AnyNumber());
610 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( 594 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(AnyNumber());
611 Return(QuicTime::Delta::Zero())); 595 EXPECT_CALL(*send_algorithm_, RetransmissionDelay())
612 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( 596 .WillRepeatedly(Return(QuicTime::Delta::Zero()));
613 Return(kMaxPacketSize)); 597 EXPECT_CALL(*send_algorithm_, GetCongestionWindow())
598 .WillRepeatedly(Return(kMaxPacketSize));
614 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)) 599 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _))
615 .WillByDefault(Return(true)); 600 .WillByDefault(Return(true));
616 EXPECT_CALL(visitor_, HasPendingWrites()).Times(AnyNumber()); 601 EXPECT_CALL(visitor_, HasPendingWrites()).Times(AnyNumber());
617 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber()); 602 EXPECT_CALL(visitor_, HasPendingHandshake()).Times(AnyNumber());
618 EXPECT_CALL(visitor_, OnCanWrite()).Times(AnyNumber()); 603 EXPECT_CALL(visitor_, OnCanWrite()).Times(AnyNumber());
619 EXPECT_CALL(visitor_, HasOpenDataStreams()).WillRepeatedly(Return(false)); 604 EXPECT_CALL(visitor_, HasOpenDataStreams()).WillRepeatedly(Return(false));
620 605
621 EXPECT_CALL(*loss_algorithm_, GetLossTimeout()) 606 EXPECT_CALL(*loss_algorithm_, GetLossTimeout())
622 .WillRepeatedly(Return(QuicTime::Zero())); 607 .WillRepeatedly(Return(QuicTime::Zero()));
623 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 608 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
624 .WillRepeatedly(Return(SequenceNumberSet())); 609 .WillRepeatedly(Return(SequenceNumberSet()));
625 } 610 }
626 611
627 QuicVersion version() { 612 QuicVersion version() { return GetParam(); }
628 return GetParam();
629 }
630 613
631 QuicAckFrame* outgoing_ack() { 614 QuicAckFrame* outgoing_ack() {
632 outgoing_ack_.reset(QuicConnectionPeer::CreateAckFrame(&connection_)); 615 outgoing_ack_.reset(QuicConnectionPeer::CreateAckFrame(&connection_));
633 return outgoing_ack_.get(); 616 return outgoing_ack_.get();
634 } 617 }
635 618
636 QuicPacketSequenceNumber least_unacked() { 619 QuicPacketSequenceNumber least_unacked() {
637 if (version() <= QUIC_VERSION_15) { 620 if (version() <= QUIC_VERSION_15) {
638 if (writer_->ack_frames().empty()) { 621 if (writer_->ack_frames().empty()) {
639 return 0; 622 return 0;
640 } 623 }
641 return writer_->ack_frames()[0].sent_info.least_unacked; 624 return writer_->ack_frames()[0].sent_info.least_unacked;
642 } 625 }
643 if (writer_->stop_waiting_frames().empty()) { 626 if (writer_->stop_waiting_frames().empty()) {
644 return 0; 627 return 0;
645 } 628 }
646 return writer_->stop_waiting_frames()[0].least_unacked; 629 return writer_->stop_waiting_frames()[0].least_unacked;
647 } 630 }
648 631
649 void use_tagging_decrypter() { 632 void use_tagging_decrypter() { writer_->use_tagging_decrypter(); }
650 writer_->use_tagging_decrypter();
651 }
652 633
653 void ProcessPacket(QuicPacketSequenceNumber number) { 634 void ProcessPacket(QuicPacketSequenceNumber number) {
654 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 635 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1);
655 ProcessDataPacket(number, 0, !kEntropyFlag); 636 ProcessDataPacket(number, 0, !kEntropyFlag);
656 } 637 }
657 638
658 QuicPacketEntropyHash ProcessFramePacket(QuicFrame frame) { 639 QuicPacketEntropyHash ProcessFramePacket(QuicFrame frame) {
659 QuicFrames frames; 640 QuicFrames frames;
660 frames.push_back(QuicFrame(frame)); 641 frames.push_back(QuicFrame(frame));
661 QuicPacketCreatorPeer::SetSendVersionInPacket(&creator_, 642 QuicPacketCreatorPeer::SetSendVersionInPacket(&creator_,
662 connection_.is_server()); 643 connection_.is_server());
663 SerializedPacket serialized_packet = creator_.SerializeAllFrames(frames); 644 SerializedPacket serialized_packet = creator_.SerializeAllFrames(frames);
664 scoped_ptr<QuicPacket> packet(serialized_packet.packet); 645 scoped_ptr<QuicPacket> packet(serialized_packet.packet);
665 scoped_ptr<QuicEncryptedPacket> encrypted( 646 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket(
666 framer_.EncryptPacket(ENCRYPTION_NONE, 647 ENCRYPTION_NONE, serialized_packet.sequence_number, *packet));
667 serialized_packet.sequence_number, *packet));
668 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 648 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
669 return serialized_packet.entropy_hash; 649 return serialized_packet.entropy_hash;
670 } 650 }
671 651
672 size_t ProcessDataPacket(QuicPacketSequenceNumber number, 652 size_t ProcessDataPacket(QuicPacketSequenceNumber number,
673 QuicFecGroupNumber fec_group, 653 QuicFecGroupNumber fec_group,
674 bool entropy_flag) { 654 bool entropy_flag) {
675 return ProcessDataPacketAtLevel(number, fec_group, entropy_flag, 655 return ProcessDataPacketAtLevel(
676 ENCRYPTION_NONE); 656 number, fec_group, entropy_flag, ENCRYPTION_NONE);
677 } 657 }
678 658
679 size_t ProcessDataPacketAtLevel(QuicPacketSequenceNumber number, 659 size_t ProcessDataPacketAtLevel(QuicPacketSequenceNumber number,
680 QuicFecGroupNumber fec_group, 660 QuicFecGroupNumber fec_group,
681 bool entropy_flag, 661 bool entropy_flag,
682 EncryptionLevel level) { 662 EncryptionLevel level) {
683 scoped_ptr<QuicPacket> packet(ConstructDataPacket(number, fec_group, 663 scoped_ptr<QuicPacket> packet(
684 entropy_flag)); 664 ConstructDataPacket(number, fec_group, entropy_flag));
685 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket( 665 scoped_ptr<QuicEncryptedPacket> encrypted(
686 level, number, *packet)); 666 framer_.EncryptPacket(level, number, *packet));
687 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 667 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
688 return encrypted->length(); 668 return encrypted->length();
689 } 669 }
690 670
691 void ProcessClosePacket(QuicPacketSequenceNumber number, 671 void ProcessClosePacket(QuicPacketSequenceNumber number,
692 QuicFecGroupNumber fec_group) { 672 QuicFecGroupNumber fec_group) {
693 scoped_ptr<QuicPacket> packet(ConstructClosePacket(number, fec_group)); 673 scoped_ptr<QuicPacket> packet(ConstructClosePacket(number, fec_group));
694 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket( 674 scoped_ptr<QuicEncryptedPacket> encrypted(
695 ENCRYPTION_NONE, number, *packet)); 675 framer_.EncryptPacket(ENCRYPTION_NONE, number, *packet));
696 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 676 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
697 } 677 }
698 678
699 size_t ProcessFecProtectedPacket(QuicPacketSequenceNumber number, 679 size_t ProcessFecProtectedPacket(QuicPacketSequenceNumber number,
700 bool expect_revival, bool entropy_flag) { 680 bool expect_revival,
681 bool entropy_flag) {
701 if (expect_revival) { 682 if (expect_revival) {
702 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 683 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1);
703 } 684 }
704 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1). 685 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1).RetiresOnSaturation();
705 RetiresOnSaturation();
706 return ProcessDataPacket(number, 1, entropy_flag); 686 return ProcessDataPacket(number, 1, entropy_flag);
707 } 687 }
708 688
709 // Processes an FEC packet that covers the packets that would have been 689 // Processes an FEC packet that covers the packets that would have been
710 // received. 690 // received.
711 size_t ProcessFecPacket(QuicPacketSequenceNumber number, 691 size_t ProcessFecPacket(QuicPacketSequenceNumber number,
712 QuicPacketSequenceNumber min_protected_packet, 692 QuicPacketSequenceNumber min_protected_packet,
713 bool expect_revival, 693 bool expect_revival,
714 bool entropy_flag, 694 bool entropy_flag,
715 QuicPacket* packet) { 695 QuicPacket* packet) {
(...skipping 25 matching lines...) Expand all
741 fec_data.fec_group = header_.fec_group; 721 fec_data.fec_group = header_.fec_group;
742 722
743 // Since all data packets in this test have the same payload, the 723 // Since all data packets in this test have the same payload, the
744 // redundancy is either equal to that payload or the xor of that payload 724 // redundancy is either equal to that payload or the xor of that payload
745 // with itself, depending on the number of packets. 725 // with itself, depending on the number of packets.
746 if (((number - min_protected_packet) % 2) == 0) { 726 if (((number - min_protected_packet) % 2) == 0) {
747 for (size_t i = GetStartOfFecProtectedData( 727 for (size_t i = GetStartOfFecProtectedData(
748 header_.public_header.connection_id_length, 728 header_.public_header.connection_id_length,
749 header_.public_header.version_flag, 729 header_.public_header.version_flag,
750 header_.public_header.sequence_number_length); 730 header_.public_header.sequence_number_length);
751 i < data_packet->length(); ++i) { 731 i < data_packet->length();
732 ++i) {
752 data_packet->mutable_data()[i] ^= data_packet->data()[i]; 733 data_packet->mutable_data()[i] ^= data_packet->data()[i];
753 } 734 }
754 } 735 }
755 fec_data.redundancy = data_packet->FecProtectedData(); 736 fec_data.redundancy = data_packet->FecProtectedData();
756 737
757 scoped_ptr<QuicPacket> fec_packet( 738 scoped_ptr<QuicPacket> fec_packet(
758 framer_.BuildFecPacket(header_, fec_data).packet); 739 framer_.BuildFecPacket(header_, fec_data).packet);
759 scoped_ptr<QuicEncryptedPacket> encrypted( 740 scoped_ptr<QuicEncryptedPacket> encrypted(
760 framer_.EncryptPacket(ENCRYPTION_NONE, number, *fec_packet)); 741 framer_.EncryptPacket(ENCRYPTION_NONE, number, *fec_packet));
761 742
762 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 743 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
763 return encrypted->length(); 744 return encrypted->length();
764 } 745 }
765 746
766 QuicByteCount SendStreamDataToPeer(QuicStreamId id, 747 QuicByteCount SendStreamDataToPeer(QuicStreamId id,
767 StringPiece data, 748 StringPiece data,
768 QuicStreamOffset offset, 749 QuicStreamOffset offset,
769 bool fin, 750 bool fin,
770 QuicPacketSequenceNumber* last_packet) { 751 QuicPacketSequenceNumber* last_packet) {
771 QuicByteCount packet_size; 752 QuicByteCount packet_size;
772 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)) 753 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _))
773 .WillOnce(DoAll(SaveArg<2>(&packet_size), Return(true))); 754 .WillOnce(DoAll(SaveArg<2>(&packet_size), Return(true)));
774 connection_.SendStreamDataWithString(id, data, offset, fin, NULL); 755 connection_.SendStreamDataWithString(id, data, offset, fin, NULL);
775 if (last_packet != NULL) { 756 if (last_packet != NULL) {
776 *last_packet = 757 *last_packet =
777 QuicConnectionPeer::GetPacketCreator(&connection_)->sequence_number(); 758 QuicConnectionPeer::GetPacketCreator(&connection_)->sequence_number();
778 } 759 }
779 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)) 760 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(AnyNumber());
780 .Times(AnyNumber());
781 return packet_size; 761 return packet_size;
782 } 762 }
783 763
784 void SendAckPacketToPeer() { 764 void SendAckPacketToPeer() {
785 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(1); 765 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(1);
786 connection_.SendAck(); 766 connection_.SendAck();
787 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)) 767 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(AnyNumber());
788 .Times(AnyNumber());
789 } 768 }
790 769
791 QuicPacketEntropyHash ProcessAckPacket(QuicAckFrame* frame) { 770 QuicPacketEntropyHash ProcessAckPacket(QuicAckFrame* frame) {
792 return ProcessFramePacket(QuicFrame(frame)); 771 return ProcessFramePacket(QuicFrame(frame));
793 } 772 }
794 773
795 QuicPacketEntropyHash ProcessStopWaitingPacket(QuicStopWaitingFrame* frame) { 774 QuicPacketEntropyHash ProcessStopWaitingPacket(QuicStopWaitingFrame* frame) {
796 return ProcessFramePacket(QuicFrame(frame)); 775 return ProcessFramePacket(QuicFrame(frame));
797 } 776 }
798 777
(...skipping 15 matching lines...) Expand all
814 header_.public_header.connection_id_length = connection_id_length_; 793 header_.public_header.connection_id_length = connection_id_length_;
815 header_.entropy_flag = entropy_flag; 794 header_.entropy_flag = entropy_flag;
816 header_.fec_flag = false; 795 header_.fec_flag = false;
817 header_.packet_sequence_number = number; 796 header_.packet_sequence_number = number;
818 header_.is_in_fec_group = fec_group == 0u ? NOT_IN_FEC_GROUP : IN_FEC_GROUP; 797 header_.is_in_fec_group = fec_group == 0u ? NOT_IN_FEC_GROUP : IN_FEC_GROUP;
819 header_.fec_group = fec_group; 798 header_.fec_group = fec_group;
820 799
821 QuicFrames frames; 800 QuicFrames frames;
822 QuicFrame frame(&frame1_); 801 QuicFrame frame(&frame1_);
823 frames.push_back(frame); 802 frames.push_back(frame);
824 QuicPacket* packet = 803 QuicPacket* packet = framer_.BuildUnsizedDataPacket(header_, frames).packet;
825 framer_.BuildUnsizedDataPacket(header_, frames).packet;
826 EXPECT_TRUE(packet != NULL); 804 EXPECT_TRUE(packet != NULL);
827 return packet; 805 return packet;
828 } 806 }
829 807
830 QuicPacket* ConstructClosePacket(QuicPacketSequenceNumber number, 808 QuicPacket* ConstructClosePacket(QuicPacketSequenceNumber number,
831 QuicFecGroupNumber fec_group) { 809 QuicFecGroupNumber fec_group) {
832 header_.public_header.connection_id = connection_id_; 810 header_.public_header.connection_id = connection_id_;
833 header_.packet_sequence_number = number; 811 header_.packet_sequence_number = number;
834 header_.public_header.reset_flag = false; 812 header_.public_header.reset_flag = false;
835 header_.public_header.version_flag = false; 813 header_.public_header.version_flag = false;
836 header_.entropy_flag = false; 814 header_.entropy_flag = false;
837 header_.fec_flag = false; 815 header_.fec_flag = false;
838 header_.is_in_fec_group = fec_group == 0u ? NOT_IN_FEC_GROUP : IN_FEC_GROUP; 816 header_.is_in_fec_group = fec_group == 0u ? NOT_IN_FEC_GROUP : IN_FEC_GROUP;
839 header_.fec_group = fec_group; 817 header_.fec_group = fec_group;
840 818
841 QuicConnectionCloseFrame qccf; 819 QuicConnectionCloseFrame qccf;
842 qccf.error_code = QUIC_PEER_GOING_AWAY; 820 qccf.error_code = QUIC_PEER_GOING_AWAY;
843 821
844 QuicFrames frames; 822 QuicFrames frames;
845 QuicFrame frame(&qccf); 823 QuicFrame frame(&qccf);
846 frames.push_back(frame); 824 frames.push_back(frame);
847 QuicPacket* packet = 825 QuicPacket* packet = framer_.BuildUnsizedDataPacket(header_, frames).packet;
848 framer_.BuildUnsizedDataPacket(header_, frames).packet;
849 EXPECT_TRUE(packet != NULL); 826 EXPECT_TRUE(packet != NULL);
850 return packet; 827 return packet;
851 } 828 }
852 829
853 void SetFeedback(QuicCongestionFeedbackFrame* feedback) { 830 void SetFeedback(QuicCongestionFeedbackFrame* feedback) {
854 receive_algorithm_ = new TestReceiveAlgorithm(feedback); 831 receive_algorithm_ = new TestReceiveAlgorithm(feedback);
855 connection_.SetReceiveAlgorithm(receive_algorithm_); 832 connection_.SetReceiveAlgorithm(receive_algorithm_);
856 } 833 }
857 834
858 QuicTime::Delta DefaultRetransmissionTime() { 835 QuicTime::Delta DefaultRetransmissionTime() {
859 return QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs); 836 return QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs);
860 } 837 }
861 838
862 QuicTime::Delta DefaultDelayedAckTime() { 839 QuicTime::Delta DefaultDelayedAckTime() {
863 return QuicTime::Delta::FromMilliseconds(kMinRetransmissionTimeMs/2); 840 return QuicTime::Delta::FromMilliseconds(kMinRetransmissionTimeMs / 2);
864 } 841 }
865 842
866 // Initialize a frame acknowledging all packets up to largest_observed. 843 // Initialize a frame acknowledging all packets up to largest_observed.
867 const QuicAckFrame InitAckFrame(QuicPacketSequenceNumber largest_observed, 844 const QuicAckFrame InitAckFrame(QuicPacketSequenceNumber largest_observed,
868 QuicPacketSequenceNumber least_unacked) { 845 QuicPacketSequenceNumber least_unacked) {
869 QuicAckFrame frame(MakeAckFrame(largest_observed, least_unacked)); 846 QuicAckFrame frame(MakeAckFrame(largest_observed, least_unacked));
870 if (largest_observed > 0) { 847 if (largest_observed > 0) {
871 frame.received_info.entropy_hash = 848 frame.received_info.entropy_hash = QuicConnectionPeer::GetSentEntropyHash(
872 QuicConnectionPeer::GetSentEntropyHash(&connection_, largest_observed); 849 &connection_, largest_observed);
873 } 850 }
874 return frame; 851 return frame;
875 } 852 }
876 853
877 const QuicStopWaitingFrame InitStopWaitingFrame( 854 const QuicStopWaitingFrame InitStopWaitingFrame(
878 QuicPacketSequenceNumber least_unacked) { 855 QuicPacketSequenceNumber least_unacked) {
879 QuicStopWaitingFrame frame; 856 QuicStopWaitingFrame frame;
880 frame.least_unacked = least_unacked; 857 frame.least_unacked = least_unacked;
881 return frame; 858 return frame;
882 } 859 }
883 // Explicitly nack a packet. 860 // Explicitly nack a packet.
884 void NackPacket(QuicPacketSequenceNumber missing, QuicAckFrame* frame) { 861 void NackPacket(QuicPacketSequenceNumber missing, QuicAckFrame* frame) {
885 frame->received_info.missing_packets.insert(missing); 862 frame->received_info.missing_packets.insert(missing);
886 frame->received_info.entropy_hash ^= 863 frame->received_info.entropy_hash ^=
887 QuicConnectionPeer::GetSentEntropyHash(&connection_, missing); 864 QuicConnectionPeer::GetSentEntropyHash(&connection_, missing);
888 if (missing > 1) { 865 if (missing > 1) {
889 frame->received_info.entropy_hash ^= 866 frame->received_info.entropy_hash ^=
890 QuicConnectionPeer::GetSentEntropyHash(&connection_, missing - 1); 867 QuicConnectionPeer::GetSentEntropyHash(&connection_, missing - 1);
891 } 868 }
892 } 869 }
893 870
894 // Undo nacking a packet within the frame. 871 // Undo nacking a packet within the frame.
895 void AckPacket(QuicPacketSequenceNumber arrived, QuicAckFrame* frame) { 872 void AckPacket(QuicPacketSequenceNumber arrived, QuicAckFrame* frame) {
896 EXPECT_THAT(frame->received_info.missing_packets, Contains(arrived)); 873 EXPECT_THAT(frame->received_info.missing_packets, Contains(arrived));
897 frame->received_info.missing_packets.erase(arrived); 874 frame->received_info.missing_packets.erase(arrived);
898 frame->received_info.entropy_hash ^= 875 frame->received_info.entropy_hash ^=
899 QuicConnectionPeer::GetSentEntropyHash(&connection_, arrived); 876 QuicConnectionPeer::GetSentEntropyHash(&connection_, arrived);
900 if (arrived > 1) { 877 if (arrived > 1) {
901 frame->received_info.entropy_hash ^= 878 frame->received_info.entropy_hash ^=
902 QuicConnectionPeer::GetSentEntropyHash(&connection_, arrived - 1); 879 QuicConnectionPeer::GetSentEntropyHash(&connection_, arrived - 1);
903 } 880 }
904 } 881 }
905 882
906 void TriggerConnectionClose() { 883 void TriggerConnectionClose() {
907 // Send an erroneous packet to close the connection. 884 // Send an erroneous packet to close the connection.
908 EXPECT_CALL(visitor_, 885 EXPECT_CALL(visitor_,
909 OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false)); 886 OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false));
910 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a 887 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a
911 // packet call to the visitor. 888 // packet call to the visitor.
912 ProcessDataPacket(6000, 0, !kEntropyFlag); 889 ProcessDataPacket(6000, 0, !kEntropyFlag);
913 EXPECT_FALSE( 890 EXPECT_FALSE(QuicConnectionPeer::GetConnectionClosePacket(&connection_) ==
914 QuicConnectionPeer::GetConnectionClosePacket(&connection_) == NULL); 891 NULL);
915 } 892 }
916 893
917 void BlockOnNextWrite() { 894 void BlockOnNextWrite() {
918 writer_->BlockOnNextWrite(); 895 writer_->BlockOnNextWrite();
919 EXPECT_CALL(visitor_, OnWriteBlocked()).Times(AtLeast(1)); 896 EXPECT_CALL(visitor_, OnWriteBlocked()).Times(AtLeast(1));
920 } 897 }
921 898
922 QuicConnectionId connection_id_; 899 QuicConnectionId connection_id_;
923 QuicFramer framer_; 900 QuicFramer framer_;
924 QuicPacketCreator creator_; 901 QuicPacketCreator creator_;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 creator_.set_sequence_number(5); 1002 creator_.set_sequence_number(5);
1026 QuicAckFrame frame = InitAckFrame(0, 4); 1003 QuicAckFrame frame = InitAckFrame(0, 4);
1027 ProcessAckPacket(&frame); 1004 ProcessAckPacket(&frame);
1028 1005
1029 // Force an ack to be sent. 1006 // Force an ack to be sent.
1030 SendAckPacketToPeer(); 1007 SendAckPacketToPeer();
1031 EXPECT_TRUE(IsMissing(4)); 1008 EXPECT_TRUE(IsMissing(4));
1032 } 1009 }
1033 1010
1034 TEST_P(QuicConnectionTest, RejectPacketTooFarOut) { 1011 TEST_P(QuicConnectionTest, RejectPacketTooFarOut) {
1035 EXPECT_CALL(visitor_, 1012 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false));
1036 OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false));
1037 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a 1013 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a
1038 // packet call to the visitor. 1014 // packet call to the visitor.
1039 ProcessDataPacket(6000, 0, !kEntropyFlag); 1015 ProcessDataPacket(6000, 0, !kEntropyFlag);
1040 EXPECT_FALSE( 1016 EXPECT_FALSE(QuicConnectionPeer::GetConnectionClosePacket(&connection_) ==
1041 QuicConnectionPeer::GetConnectionClosePacket(&connection_) == NULL); 1017 NULL);
1042 } 1018 }
1043 1019
1044 TEST_P(QuicConnectionTest, RejectUnencryptedStreamData) { 1020 TEST_P(QuicConnectionTest, RejectUnencryptedStreamData) {
1045 // Process an unencrypted packet from the non-crypto stream. 1021 // Process an unencrypted packet from the non-crypto stream.
1046 frame1_.stream_id = 3; 1022 frame1_.stream_id = 3;
1047 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1023 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1048 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_UNENCRYPTED_STREAM_DATA, 1024 EXPECT_CALL(visitor_,
1049 false)); 1025 OnConnectionClosed(QUIC_UNENCRYPTED_STREAM_DATA, false));
1050 ProcessDataPacket(1, 0, !kEntropyFlag); 1026 ProcessDataPacket(1, 0, !kEntropyFlag);
1051 EXPECT_FALSE( 1027 EXPECT_FALSE(QuicConnectionPeer::GetConnectionClosePacket(&connection_) ==
1052 QuicConnectionPeer::GetConnectionClosePacket(&connection_) == NULL); 1028 NULL);
1053 const vector<QuicConnectionCloseFrame>& connection_close_frames = 1029 const vector<QuicConnectionCloseFrame>& connection_close_frames =
1054 writer_->connection_close_frames(); 1030 writer_->connection_close_frames();
1055 EXPECT_EQ(1u, connection_close_frames.size()); 1031 EXPECT_EQ(1u, connection_close_frames.size());
1056 EXPECT_EQ(QUIC_UNENCRYPTED_STREAM_DATA, 1032 EXPECT_EQ(QUIC_UNENCRYPTED_STREAM_DATA,
1057 connection_close_frames[0].error_code); 1033 connection_close_frames[0].error_code);
1058 } 1034 }
1059 1035
1060 TEST_P(QuicConnectionTest, TruncatedAck) { 1036 TEST_P(QuicConnectionTest, TruncatedAck) {
1061 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1037 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1062 QuicPacketSequenceNumber num_packets = 256 * 2 + 1; 1038 QuicPacketSequenceNumber num_packets = 256 * 2 + 1;
1063 for (QuicPacketSequenceNumber i = 0; i < num_packets; ++i) { 1039 for (QuicPacketSequenceNumber i = 0; i < num_packets; ++i) {
1064 SendStreamDataToPeer(3, "foo", i * 3, !kFin, NULL); 1040 SendStreamDataToPeer(3, "foo", i * 3, !kFin, NULL);
1065 } 1041 }
1066 1042
1067 QuicAckFrame frame = InitAckFrame(num_packets, 1); 1043 QuicAckFrame frame = InitAckFrame(num_packets, 1);
1068 SequenceNumberSet lost_packets; 1044 SequenceNumberSet lost_packets;
1069 // Create an ack with 256 nacks, none adjacent to one another. 1045 // Create an ack with 256 nacks, none adjacent to one another.
1070 for (QuicPacketSequenceNumber i = 1; i <= 256; ++i) { 1046 for (QuicPacketSequenceNumber i = 1; i <= 256; ++i) {
1071 NackPacket(i * 2, &frame); 1047 NackPacket(i * 2, &frame);
1072 if (i < 256) { // Last packet is nacked, but not lost. 1048 if (i < 256) { // Last packet is nacked, but not lost.
1073 lost_packets.insert(i * 2); 1049 lost_packets.insert(i * 2);
1074 } 1050 }
1075 } 1051 }
1076 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 1052 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1077 .WillOnce(Return(lost_packets)); 1053 .WillOnce(Return(lost_packets));
1078 EXPECT_CALL(entropy_calculator_, 1054 EXPECT_CALL(entropy_calculator_, EntropyHash(511))
1079 EntropyHash(511)).WillOnce(testing::Return(0)); 1055 .WillOnce(testing::Return(0));
1080 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_)); 1056 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_));
1081 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(256); 1057 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(256);
1082 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(255); 1058 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(255);
1083 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(255); 1059 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(255);
1084 ProcessAckPacket(&frame); 1060 ProcessAckPacket(&frame);
1085 1061
1086 QuicReceivedPacketManager* received_packet_manager = 1062 QuicReceivedPacketManager* received_packet_manager =
1087 QuicConnectionPeer::GetReceivedPacketManager(&connection_); 1063 QuicConnectionPeer::GetReceivedPacketManager(&connection_);
1088 // A truncated ack will not have the true largest observed. 1064 // A truncated ack will not have the true largest observed.
1089 EXPECT_GT(num_packets, 1065 EXPECT_GT(num_packets,
(...skipping 10 matching lines...) Expand all
1100 ProcessAckPacket(&frame); 1076 ProcessAckPacket(&frame);
1101 EXPECT_EQ(num_packets, 1077 EXPECT_EQ(num_packets,
1102 received_packet_manager->peer_largest_observed_packet()); 1078 received_packet_manager->peer_largest_observed_packet());
1103 } 1079 }
1104 1080
1105 TEST_P(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) { 1081 TEST_P(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) {
1106 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1082 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1107 1083
1108 ProcessPacket(1); 1084 ProcessPacket(1);
1109 // Delay sending, then queue up an ack. 1085 // Delay sending, then queue up an ack.
1110 EXPECT_CALL(*send_algorithm_, 1086 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
1111 TimeUntilSend(_, _)).WillOnce( 1087 .WillOnce(testing::Return(QuicTime::Delta::FromMicroseconds(1)));
1112 testing::Return(QuicTime::Delta::FromMicroseconds(1)));
1113 QuicConnectionPeer::SendAck(&connection_); 1088 QuicConnectionPeer::SendAck(&connection_);
1114 1089
1115 // Process an ack with a least unacked of the received ack. 1090 // Process an ack with a least unacked of the received ack.
1116 // This causes an ack to be sent when TimeUntilSend returns 0. 1091 // This causes an ack to be sent when TimeUntilSend returns 0.
1117 EXPECT_CALL(*send_algorithm_, 1092 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
1118 TimeUntilSend(_, _)).WillRepeatedly( 1093 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero()));
1119 testing::Return(QuicTime::Delta::Zero()));
1120 // Skip a packet and then record an ack. 1094 // Skip a packet and then record an ack.
1121 creator_.set_sequence_number(2); 1095 creator_.set_sequence_number(2);
1122 QuicAckFrame frame = InitAckFrame(0, 3); 1096 QuicAckFrame frame = InitAckFrame(0, 3);
1123 ProcessAckPacket(&frame); 1097 ProcessAckPacket(&frame);
1124 } 1098 }
1125 1099
1126 TEST_P(QuicConnectionTest, OutOfOrderReceiptCausesAckSend) { 1100 TEST_P(QuicConnectionTest, OutOfOrderReceiptCausesAckSend) {
1127 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1101 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1128 1102
1129 ProcessPacket(3); 1103 ProcessPacket(3);
(...skipping 11 matching lines...) Expand all
1141 ProcessPacket(4); 1115 ProcessPacket(4);
1142 // Should not cause an ack. 1116 // Should not cause an ack.
1143 EXPECT_EQ(3u, writer_->packets_write_attempts()); 1117 EXPECT_EQ(3u, writer_->packets_write_attempts());
1144 } 1118 }
1145 1119
1146 TEST_P(QuicConnectionTest, AckReceiptCausesAckSend) { 1120 TEST_P(QuicConnectionTest, AckReceiptCausesAckSend) {
1147 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1121 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1148 1122
1149 QuicPacketSequenceNumber original; 1123 QuicPacketSequenceNumber original;
1150 QuicByteCount packet_size; 1124 QuicByteCount packet_size;
1151 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)) 1125 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).WillOnce(
1152 .WillOnce(DoAll(SaveArg<1>(&original), SaveArg<2>(&packet_size), 1126 DoAll(SaveArg<1>(&original), SaveArg<2>(&packet_size), Return(true)));
1153 Return(true)));
1154 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 1127 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
1155 QuicAckFrame frame = InitAckFrame(original, 1); 1128 QuicAckFrame frame = InitAckFrame(original, 1);
1156 NackPacket(original, &frame); 1129 NackPacket(original, &frame);
1157 // First nack triggers early retransmit. 1130 // First nack triggers early retransmit.
1158 SequenceNumberSet lost_packets; 1131 SequenceNumberSet lost_packets;
1159 lost_packets.insert(1); 1132 lost_packets.insert(1);
1160 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 1133 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1161 .WillOnce(Return(lost_packets)); 1134 .WillOnce(Return(lost_packets));
1162 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_)); 1135 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_));
1163 EXPECT_CALL(*send_algorithm_, OnPacketLost(1, _)).Times(1); 1136 EXPECT_CALL(*send_algorithm_, OnPacketLost(1, _)).Times(1);
1164 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)).Times(1); 1137 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)).Times(1);
1165 QuicPacketSequenceNumber retransmission; 1138 QuicPacketSequenceNumber retransmission;
1166 EXPECT_CALL(*send_algorithm_, 1139 EXPECT_CALL(*send_algorithm_,
1167 OnPacketSent(_, _, packet_size - kQuicVersionSize, _)) 1140 OnPacketSent(_, _, packet_size - kQuicVersionSize, _))
1168 .WillOnce(DoAll(SaveArg<1>(&retransmission), Return(true))); 1141 .WillOnce(DoAll(SaveArg<1>(&retransmission), Return(true)));
1169 1142
1170 ProcessAckPacket(&frame); 1143 ProcessAckPacket(&frame);
1171 1144
1172 QuicAckFrame frame2 = InitAckFrame(retransmission, 1); 1145 QuicAckFrame frame2 = InitAckFrame(retransmission, 1);
1173 NackPacket(original, &frame2); 1146 NackPacket(original, &frame2);
1174 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_)); 1147 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_));
1175 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)); 1148 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _));
1176 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 1149 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1177 .WillOnce(Return(SequenceNumberSet())); 1150 .WillOnce(Return(SequenceNumberSet()));
1178 ProcessAckPacket(&frame2); 1151 ProcessAckPacket(&frame2);
1179 1152
1180 // Now if the peer sends an ack which still reports the retransmitted packet 1153 // Now if the peer sends an ack which still reports the retransmitted packet
1181 // as missing, that will bundle an ack with data after two acks in a row 1154 // as missing, that will bundle an ack with data after two acks in a row
1182 // indicate the high water mark needs to be raised. 1155 // indicate the high water mark needs to be raised.
1183 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, 1156 EXPECT_CALL(*send_algorithm_,
1184 HAS_RETRANSMITTABLE_DATA)); 1157 OnPacketSent(_, _, _, HAS_RETRANSMITTABLE_DATA));
1185 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); 1158 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL);
1186 // No ack sent. 1159 // No ack sent.
1187 EXPECT_EQ(1u, writer_->frame_count()); 1160 EXPECT_EQ(1u, writer_->frame_count());
1188 EXPECT_EQ(1u, writer_->stream_frames().size()); 1161 EXPECT_EQ(1u, writer_->stream_frames().size());
1189 1162
1190 // No more packet loss for the rest of the test. 1163 // No more packet loss for the rest of the test.
1191 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 1164 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1192 .WillRepeatedly(Return(SequenceNumberSet())); 1165 .WillRepeatedly(Return(SequenceNumberSet()));
1193 ProcessAckPacket(&frame2); 1166 ProcessAckPacket(&frame2);
1194 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, 1167 EXPECT_CALL(*send_algorithm_,
1195 HAS_RETRANSMITTABLE_DATA)); 1168 OnPacketSent(_, _, _, HAS_RETRANSMITTABLE_DATA));
1196 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL); 1169 connection_.SendStreamDataWithString(3, "foo", 3, !kFin, NULL);
1197 // Ack bundled. 1170 // Ack bundled.
1198 if (version() > QUIC_VERSION_15) { 1171 if (version() > QUIC_VERSION_15) {
1199 EXPECT_EQ(3u, writer_->frame_count()); 1172 EXPECT_EQ(3u, writer_->frame_count());
1200 } else { 1173 } else {
1201 EXPECT_EQ(2u, writer_->frame_count()); 1174 EXPECT_EQ(2u, writer_->frame_count());
1202 } 1175 }
1203 EXPECT_EQ(1u, writer_->stream_frames().size()); 1176 EXPECT_EQ(1u, writer_->stream_frames().size());
1204 EXPECT_FALSE(writer_->ack_frames().empty()); 1177 EXPECT_FALSE(writer_->ack_frames().empty());
1205 1178
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 1270
1298 TEST_P(QuicConnectionTest, SendingDifferentSequenceNumberLengthsBandwidth) { 1271 TEST_P(QuicConnectionTest, SendingDifferentSequenceNumberLengthsBandwidth) {
1299 QuicPacketSequenceNumber last_packet; 1272 QuicPacketSequenceNumber last_packet;
1300 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); 1273 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet);
1301 EXPECT_EQ(1u, last_packet); 1274 EXPECT_EQ(1u, last_packet);
1302 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, 1275 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER,
1303 connection_.options()->send_sequence_number_length); 1276 connection_.options()->send_sequence_number_length);
1304 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, 1277 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER,
1305 writer_->header().public_header.sequence_number_length); 1278 writer_->header().public_header.sequence_number_length);
1306 1279
1307 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( 1280 EXPECT_CALL(*send_algorithm_, GetCongestionWindow())
1308 Return(kMaxPacketSize * 256)); 1281 .WillRepeatedly(Return(kMaxPacketSize * 256));
1309 1282
1310 SendStreamDataToPeer(1, "bar", 3, !kFin, &last_packet); 1283 SendStreamDataToPeer(1, "bar", 3, !kFin, &last_packet);
1311 EXPECT_EQ(2u, last_packet); 1284 EXPECT_EQ(2u, last_packet);
1312 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER, 1285 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER,
1313 connection_.options()->send_sequence_number_length); 1286 connection_.options()->send_sequence_number_length);
1314 // The 1 packet lag is due to the sequence number length being recalculated in 1287 // The 1 packet lag is due to the sequence number length being recalculated in
1315 // QuicConnection after a packet is sent. 1288 // QuicConnection after a packet is sent.
1316 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, 1289 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER,
1317 writer_->header().public_header.sequence_number_length); 1290 writer_->header().public_header.sequence_number_length);
1318 1291
1319 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( 1292 EXPECT_CALL(*send_algorithm_, GetCongestionWindow())
1320 Return(kMaxPacketSize * 256 * 256)); 1293 .WillRepeatedly(Return(kMaxPacketSize * 256 * 256));
1321 1294
1322 SendStreamDataToPeer(1, "foo", 6, !kFin, &last_packet); 1295 SendStreamDataToPeer(1, "foo", 6, !kFin, &last_packet);
1323 EXPECT_EQ(3u, last_packet); 1296 EXPECT_EQ(3u, last_packet);
1324 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1297 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1325 connection_.options()->send_sequence_number_length); 1298 connection_.options()->send_sequence_number_length);
1326 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER, 1299 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER,
1327 writer_->header().public_header.sequence_number_length); 1300 writer_->header().public_header.sequence_number_length);
1328 1301
1329 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( 1302 EXPECT_CALL(*send_algorithm_, GetCongestionWindow())
1330 Return(kMaxPacketSize * 256 * 256 * 256)); 1303 .WillRepeatedly(Return(kMaxPacketSize * 256 * 256 * 256));
1331 1304
1332 SendStreamDataToPeer(1, "bar", 9, !kFin, &last_packet); 1305 SendStreamDataToPeer(1, "bar", 9, !kFin, &last_packet);
1333 EXPECT_EQ(4u, last_packet); 1306 EXPECT_EQ(4u, last_packet);
1334 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1307 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1335 connection_.options()->send_sequence_number_length); 1308 connection_.options()->send_sequence_number_length);
1336 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1309 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1337 writer_->header().public_header.sequence_number_length); 1310 writer_->header().public_header.sequence_number_length);
1338 1311
1339 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( 1312 EXPECT_CALL(*send_algorithm_, GetCongestionWindow())
1340 Return(kMaxPacketSize * 256 * 256 * 256 * 256)); 1313 .WillRepeatedly(Return(kMaxPacketSize * 256 * 256 * 256 * 256));
1341 1314
1342 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet); 1315 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet);
1343 EXPECT_EQ(5u, last_packet); 1316 EXPECT_EQ(5u, last_packet);
1344 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER, 1317 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER,
1345 connection_.options()->send_sequence_number_length); 1318 connection_.options()->send_sequence_number_length);
1346 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1319 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1347 writer_->header().public_header.sequence_number_length); 1320 writer_->header().public_header.sequence_number_length);
1348 } 1321 }
1349 1322
1350 TEST_P(QuicConnectionTest, SendingDifferentSequenceNumberLengthsUnackedDelta) { 1323 TEST_P(QuicConnectionTest, SendingDifferentSequenceNumberLengthsUnackedDelta) {
1351 QuicPacketSequenceNumber last_packet; 1324 QuicPacketSequenceNumber last_packet;
1352 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); 1325 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet);
1353 EXPECT_EQ(1u, last_packet); 1326 EXPECT_EQ(1u, last_packet);
1354 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, 1327 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER,
1355 connection_.options()->send_sequence_number_length); 1328 connection_.options()->send_sequence_number_length);
1356 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, 1329 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER,
1357 writer_->header().public_header.sequence_number_length); 1330 writer_->header().public_header.sequence_number_length);
1358 1331
1359 QuicConnectionPeer::GetPacketCreator(&connection_)->set_sequence_number(100); 1332 QuicConnectionPeer::GetPacketCreator(&connection_)->set_sequence_number(100);
1360 1333
1361 SendStreamDataToPeer(1, "bar", 3, !kFin, &last_packet); 1334 SendStreamDataToPeer(1, "bar", 3, !kFin, &last_packet);
1362 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER, 1335 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER,
1363 connection_.options()->send_sequence_number_length); 1336 connection_.options()->send_sequence_number_length);
1364 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, 1337 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER,
1365 writer_->header().public_header.sequence_number_length); 1338 writer_->header().public_header.sequence_number_length);
1366 1339
1367 QuicConnectionPeer::GetPacketCreator(&connection_)->set_sequence_number( 1340 QuicConnectionPeer::GetPacketCreator(&connection_)
1368 100 * 256); 1341 ->set_sequence_number(100 * 256);
1369 1342
1370 SendStreamDataToPeer(1, "foo", 6, !kFin, &last_packet); 1343 SendStreamDataToPeer(1, "foo", 6, !kFin, &last_packet);
1371 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1344 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1372 connection_.options()->send_sequence_number_length); 1345 connection_.options()->send_sequence_number_length);
1373 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER, 1346 EXPECT_EQ(PACKET_2BYTE_SEQUENCE_NUMBER,
1374 writer_->header().public_header.sequence_number_length); 1347 writer_->header().public_header.sequence_number_length);
1375 1348
1376 QuicConnectionPeer::GetPacketCreator(&connection_)->set_sequence_number( 1349 QuicConnectionPeer::GetPacketCreator(&connection_)
1377 100 * 256 * 256); 1350 ->set_sequence_number(100 * 256 * 256);
1378 1351
1379 SendStreamDataToPeer(1, "bar", 9, !kFin, &last_packet); 1352 SendStreamDataToPeer(1, "bar", 9, !kFin, &last_packet);
1380 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1353 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1381 connection_.options()->send_sequence_number_length); 1354 connection_.options()->send_sequence_number_length);
1382 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1355 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1383 writer_->header().public_header.sequence_number_length); 1356 writer_->header().public_header.sequence_number_length);
1384 1357
1385 QuicConnectionPeer::GetPacketCreator(&connection_)->set_sequence_number( 1358 QuicConnectionPeer::GetPacketCreator(&connection_)
1386 100 * 256 * 256 * 256); 1359 ->set_sequence_number(100 * 256 * 256 * 256);
1387 1360
1388 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet); 1361 SendStreamDataToPeer(1, "foo", 12, !kFin, &last_packet);
1389 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER, 1362 EXPECT_EQ(PACKET_6BYTE_SEQUENCE_NUMBER,
1390 connection_.options()->send_sequence_number_length); 1363 connection_.options()->send_sequence_number_length);
1391 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER, 1364 EXPECT_EQ(PACKET_4BYTE_SEQUENCE_NUMBER,
1392 writer_->header().public_header.sequence_number_length); 1365 writer_->header().public_header.sequence_number_length);
1393 } 1366 }
1394 1367
1395 TEST_P(QuicConnectionTest, BasicSending) { 1368 TEST_P(QuicConnectionTest, BasicSending) {
1396 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1369 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1445 EXPECT_EQ(7u, least_unacked()); 1418 EXPECT_EQ(7u, least_unacked());
1446 } 1419 }
1447 1420
1448 TEST_P(QuicConnectionTest, FECSending) { 1421 TEST_P(QuicConnectionTest, FECSending) {
1449 if (version() < QUIC_VERSION_15) { 1422 if (version() < QUIC_VERSION_15) {
1450 return; 1423 return;
1451 } 1424 }
1452 // All packets carry version info till version is negotiated. 1425 // All packets carry version info till version is negotiated.
1453 size_t payload_length; 1426 size_t payload_length;
1454 connection_.options()->max_packet_length = 1427 connection_.options()->max_packet_length =
1455 GetPacketLengthForOneStream( 1428 GetPacketLengthForOneStream(connection_.version(),
1456 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, 1429 kIncludeVersion,
1457 IN_FEC_GROUP, &payload_length); 1430 PACKET_1BYTE_SEQUENCE_NUMBER,
1431 IN_FEC_GROUP,
1432 &payload_length);
1458 // And send FEC every two packets. 1433 // And send FEC every two packets.
1459 connection_.options()->max_packets_per_fec_group = 2; 1434 connection_.options()->max_packets_per_fec_group = 2;
1460 1435
1461 // Send 4 data packets and 2 FEC packets. 1436 // Send 4 data packets and 2 FEC packets.
1462 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(6); 1437 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(6);
1463 // The first stream frame will consume 2 fewer bytes than the other three. 1438 // The first stream frame will consume 2 fewer bytes than the other three.
1464 const string payload(payload_length * 4 - 6, 'a'); 1439 const string payload(payload_length * 4 - 6, 'a');
1465 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); 1440 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL);
1466 // Expect the FEC group to be closed after SendStreamDataWithString. 1441 // Expect the FEC group to be closed after SendStreamDataWithString.
1467 EXPECT_FALSE(creator_.ShouldSendFec(true)); 1442 EXPECT_FALSE(creator_.ShouldSendFec(true));
1468 } 1443 }
1469 1444
1470 TEST_P(QuicConnectionTest, FECQueueing) { 1445 TEST_P(QuicConnectionTest, FECQueueing) {
1471 if (version() < QUIC_VERSION_15) { 1446 if (version() < QUIC_VERSION_15) {
1472 return; 1447 return;
1473 } 1448 }
1474 // All packets carry version info till version is negotiated. 1449 // All packets carry version info till version is negotiated.
1475 size_t payload_length; 1450 size_t payload_length;
1476 connection_.options()->max_packet_length = 1451 connection_.options()->max_packet_length =
1477 GetPacketLengthForOneStream( 1452 GetPacketLengthForOneStream(connection_.version(),
1478 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, 1453 kIncludeVersion,
1479 IN_FEC_GROUP, &payload_length); 1454 PACKET_1BYTE_SEQUENCE_NUMBER,
1455 IN_FEC_GROUP,
1456 &payload_length);
1480 // And send FEC every two packets. 1457 // And send FEC every two packets.
1481 connection_.options()->max_packets_per_fec_group = 2; 1458 connection_.options()->max_packets_per_fec_group = 2;
1482 1459
1483 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1460 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1484 BlockOnNextWrite(); 1461 BlockOnNextWrite();
1485 const string payload(payload_length, 'a'); 1462 const string payload(payload_length, 'a');
1486 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL); 1463 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL);
1487 EXPECT_FALSE(creator_.ShouldSendFec(true)); 1464 EXPECT_FALSE(creator_.ShouldSendFec(true));
1488 // Expect the first data packet and the fec packet to be queued. 1465 // Expect the first data packet and the fec packet to be queued.
1489 EXPECT_EQ(2u, connection_.NumQueuedPackets()); 1466 EXPECT_EQ(2u, connection_.NumQueuedPackets());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1584 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 1561 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
1585 } 1562 }
1586 1563
1587 TEST_P(QuicConnectionTest, FramePacking) { 1564 TEST_P(QuicConnectionTest, FramePacking) {
1588 // Block the connection. 1565 // Block the connection.
1589 connection_.GetSendAlarm()->Set( 1566 connection_.GetSendAlarm()->Set(
1590 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1))); 1567 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1)));
1591 1568
1592 // Send an ack and two stream frames in 1 packet by queueing them. 1569 // Send an ack and two stream frames in 1 packet by queueing them.
1593 connection_.SendAck(); 1570 connection_.SendAck();
1594 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 1571 EXPECT_CALL(visitor_, OnCanWrite())
1595 IgnoreResult(InvokeWithoutArgs(&connection_, 1572 .WillOnce(DoAll(IgnoreResult(InvokeWithoutArgs(
1596 &TestConnection::SendStreamData3)), 1573 &connection_, &TestConnection::SendStreamData3)),
1597 IgnoreResult(InvokeWithoutArgs(&connection_, 1574 IgnoreResult(InvokeWithoutArgs(
1598 &TestConnection::SendStreamData5)))); 1575 &connection_, &TestConnection::SendStreamData5))));
1599 1576
1600 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(1); 1577 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(1);
1601 // Unblock the connection. 1578 // Unblock the connection.
1602 connection_.GetSendAlarm()->Fire(); 1579 connection_.GetSendAlarm()->Fire();
1603 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1580 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1604 EXPECT_FALSE(connection_.HasQueuedData()); 1581 EXPECT_FALSE(connection_.HasQueuedData());
1605 1582
1606 // Parse the last packet and ensure it's an ack and two stream frames from 1583 // Parse the last packet and ensure it's an ack and two stream frames from
1607 // two different streams. 1584 // two different streams.
1608 if (version() > QUIC_VERSION_15) { 1585 if (version() > QUIC_VERSION_15) {
(...skipping 10 matching lines...) Expand all
1619 1596
1620 TEST_P(QuicConnectionTest, FramePackingNonCryptoThenCrypto) { 1597 TEST_P(QuicConnectionTest, FramePackingNonCryptoThenCrypto) {
1621 // Block the connection. 1598 // Block the connection.
1622 connection_.GetSendAlarm()->Set( 1599 connection_.GetSendAlarm()->Set(
1623 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1))); 1600 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1)));
1624 1601
1625 // Send an ack and two stream frames (one non-crypto, then one crypto) in 2 1602 // Send an ack and two stream frames (one non-crypto, then one crypto) in 2
1626 // packets by queueing them. 1603 // packets by queueing them.
1627 connection_.SendAck(); 1604 connection_.SendAck();
1628 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 1605 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
1629 IgnoreResult(InvokeWithoutArgs(&connection_, 1606 IgnoreResult(
1630 &TestConnection::SendStreamData3)), 1607 InvokeWithoutArgs(&connection_, &TestConnection::SendStreamData3)),
1631 IgnoreResult(InvokeWithoutArgs(&connection_, 1608 IgnoreResult(InvokeWithoutArgs(&connection_,
1632 &TestConnection::SendCryptoStreamData)))); 1609 &TestConnection::SendCryptoStreamData))));
1633 1610
1634 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(2); 1611 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(2);
1635 // Unblock the connection. 1612 // Unblock the connection.
1636 connection_.GetSendAlarm()->Fire(); 1613 connection_.GetSendAlarm()->Fire();
1637 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1614 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1638 EXPECT_FALSE(connection_.HasQueuedData()); 1615 EXPECT_FALSE(connection_.HasQueuedData());
1639 1616
1640 // Parse the last packet and ensure it's the crypto stream frame. 1617 // Parse the last packet and ensure it's the crypto stream frame.
1641 EXPECT_EQ(1u, writer_->frame_count()); 1618 EXPECT_EQ(1u, writer_->frame_count());
1642 EXPECT_EQ(1u, writer_->stream_frames().size()); 1619 EXPECT_EQ(1u, writer_->stream_frames().size());
1643 EXPECT_EQ(kCryptoStreamId, writer_->stream_frames()[0].stream_id); 1620 EXPECT_EQ(kCryptoStreamId, writer_->stream_frames()[0].stream_id);
1644 } 1621 }
1645 1622
1646 TEST_P(QuicConnectionTest, FramePackingCryptoThenNonCrypto) { 1623 TEST_P(QuicConnectionTest, FramePackingCryptoThenNonCrypto) {
1647 // Block the connection. 1624 // Block the connection.
1648 connection_.GetSendAlarm()->Set( 1625 connection_.GetSendAlarm()->Set(
1649 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1))); 1626 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1)));
1650 1627
1651 // Send an ack and two stream frames (one crypto, then one non-crypto) in 3 1628 // Send an ack and two stream frames (one crypto, then one non-crypto) in 3
1652 // packets by queueing them. 1629 // packets by queueing them.
1653 connection_.SendAck(); 1630 connection_.SendAck();
1654 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 1631 EXPECT_CALL(visitor_, OnCanWrite())
1655 IgnoreResult(InvokeWithoutArgs(&connection_, 1632 .WillOnce(DoAll(IgnoreResult(InvokeWithoutArgs(
1656 &TestConnection::SendCryptoStreamData)), 1633 &connection_, &TestConnection::SendCryptoStreamData)),
1657 IgnoreResult(InvokeWithoutArgs(&connection_, 1634 IgnoreResult(InvokeWithoutArgs(
1658 &TestConnection::SendStreamData3)))); 1635 &connection_, &TestConnection::SendStreamData3))));
1659 1636
1660 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(3); 1637 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(3);
1661 // Unblock the connection. 1638 // Unblock the connection.
1662 connection_.GetSendAlarm()->Fire(); 1639 connection_.GetSendAlarm()->Fire();
1663 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1640 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1664 EXPECT_FALSE(connection_.HasQueuedData()); 1641 EXPECT_FALSE(connection_.HasQueuedData());
1665 1642
1666 // Parse the last packet and ensure it's the stream frame from stream 3. 1643 // Parse the last packet and ensure it's the stream frame from stream 3.
1667 EXPECT_EQ(1u, writer_->frame_count()); 1644 EXPECT_EQ(1u, writer_->frame_count());
1668 EXPECT_EQ(1u, writer_->stream_frames().size()); 1645 EXPECT_EQ(1u, writer_->stream_frames().size());
1669 EXPECT_EQ(kStreamId3, writer_->stream_frames()[0].stream_id); 1646 EXPECT_EQ(kStreamId3, writer_->stream_frames()[0].stream_id);
1670 } 1647 }
1671 1648
1672 TEST_P(QuicConnectionTest, FramePackingFEC) { 1649 TEST_P(QuicConnectionTest, FramePackingFEC) {
1673 if (version() < QUIC_VERSION_15) { 1650 if (version() < QUIC_VERSION_15) {
1674 return; 1651 return;
1675 } 1652 }
1676 // Enable fec. 1653 // Enable fec.
1677 connection_.options()->max_packets_per_fec_group = 6; 1654 connection_.options()->max_packets_per_fec_group = 6;
1678 // Block the connection. 1655 // Block the connection.
1679 connection_.GetSendAlarm()->Set( 1656 connection_.GetSendAlarm()->Set(
1680 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1))); 1657 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1)));
1681 1658
1682 // Send an ack and two stream frames in 1 packet by queueing them. 1659 // Send an ack and two stream frames in 1 packet by queueing them.
1683 connection_.SendAck(); 1660 connection_.SendAck();
1684 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 1661 EXPECT_CALL(visitor_, OnCanWrite())
1685 IgnoreResult(InvokeWithoutArgs(&connection_, 1662 .WillOnce(DoAll(IgnoreResult(InvokeWithoutArgs(
1686 &TestConnection::SendStreamData3)), 1663 &connection_, &TestConnection::SendStreamData3)),
1687 IgnoreResult(InvokeWithoutArgs(&connection_, 1664 IgnoreResult(InvokeWithoutArgs(
1688 &TestConnection::SendStreamData5)))); 1665 &connection_, &TestConnection::SendStreamData5))));
1689 1666
1690 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(2); 1667 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(2);
1691 // Unblock the connection. 1668 // Unblock the connection.
1692 connection_.GetSendAlarm()->Fire(); 1669 connection_.GetSendAlarm()->Fire();
1693 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1670 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1694 EXPECT_FALSE(connection_.HasQueuedData()); 1671 EXPECT_FALSE(connection_.HasQueuedData());
1695 1672
1696 // Parse the last packet and ensure it's in an fec group. 1673 // Parse the last packet and ensure it's in an fec group.
1697 EXPECT_EQ(1u, writer_->header().fec_group); 1674 EXPECT_EQ(1u, writer_->header().fec_group);
1698 EXPECT_EQ(0u, writer_->frame_count()); 1675 EXPECT_EQ(0u, writer_->frame_count());
1699 } 1676 }
1700 1677
1701 TEST_P(QuicConnectionTest, FramePackingAckResponse) { 1678 TEST_P(QuicConnectionTest, FramePackingAckResponse) {
1702 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1679 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1703 // Process a data packet to queue up a pending ack. 1680 // Process a data packet to queue up a pending ack.
1704 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 1681 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1);
1705 ProcessDataPacket(1, 1, kEntropyFlag); 1682 ProcessDataPacket(1, 1, kEntropyFlag);
1706 1683
1707 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 1684 EXPECT_CALL(visitor_, OnCanWrite())
1708 IgnoreResult(InvokeWithoutArgs(&connection_, 1685 .WillOnce(DoAll(IgnoreResult(InvokeWithoutArgs(
1709 &TestConnection::SendStreamData3)), 1686 &connection_, &TestConnection::SendStreamData3)),
1710 IgnoreResult(InvokeWithoutArgs(&connection_, 1687 IgnoreResult(InvokeWithoutArgs(
1711 &TestConnection::SendStreamData5)))); 1688 &connection_, &TestConnection::SendStreamData5))));
1712 1689
1713 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(1); 1690 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(1);
1714 1691
1715 // Process an ack to cause the visitor's OnCanWrite to be invoked. 1692 // Process an ack to cause the visitor's OnCanWrite to be invoked.
1716 creator_.set_sequence_number(2); 1693 creator_.set_sequence_number(2);
1717 QuicAckFrame ack_one = InitAckFrame(0, 0); 1694 QuicAckFrame ack_one = InitAckFrame(0, 0);
1718 ProcessAckPacket(&ack_one); 1695 ProcessAckPacket(&ack_one);
1719 1696
1720 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1697 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1721 EXPECT_FALSE(connection_.HasQueuedData()); 1698 EXPECT_FALSE(connection_.HasQueuedData());
(...skipping 25 matching lines...) Expand all
1747 1724
1748 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1725 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1749 EXPECT_FALSE(connection_.HasQueuedData()); 1726 EXPECT_FALSE(connection_.HasQueuedData());
1750 1727
1751 // Parse the last packet and ensure multiple iovector blocks have 1728 // Parse the last packet and ensure multiple iovector blocks have
1752 // been packed into a single stream frame from one stream. 1729 // been packed into a single stream frame from one stream.
1753 EXPECT_EQ(1u, writer_->frame_count()); 1730 EXPECT_EQ(1u, writer_->frame_count());
1754 EXPECT_EQ(1u, writer_->stream_frames().size()); 1731 EXPECT_EQ(1u, writer_->stream_frames().size());
1755 QuicStreamFrame frame = writer_->stream_frames()[0]; 1732 QuicStreamFrame frame = writer_->stream_frames()[0];
1756 EXPECT_EQ(1u, frame.stream_id); 1733 EXPECT_EQ(1u, frame.stream_id);
1757 EXPECT_EQ("ABCD", string(static_cast<char*> 1734 EXPECT_EQ("ABCD",
1758 (frame.data.iovec()[0].iov_base), 1735 string(static_cast<char*>(frame.data.iovec()[0].iov_base),
1759 (frame.data.iovec()[0].iov_len))); 1736 (frame.data.iovec()[0].iov_len)));
1760 } 1737 }
1761 1738
1762 TEST_P(QuicConnectionTest, FramePackingSendvQueued) { 1739 TEST_P(QuicConnectionTest, FramePackingSendvQueued) {
1763 // Try to send two stream frames in 1 packet by using writev. 1740 // Try to send two stream frames in 1 packet by using writev.
1764 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)); 1741 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _));
1765 1742
1766 BlockOnNextWrite(); 1743 BlockOnNextWrite();
1767 char data[] = "ABCD"; 1744 char data[] = "ABCD";
1768 IOVector data_iov; 1745 IOVector data_iov;
1769 data_iov.AppendNoCoalesce(data, 2); 1746 data_iov.AppendNoCoalesce(data, 2);
(...skipping 25 matching lines...) Expand all
1795 1772
1796 // Parse the last packet and ensure it's one stream frame from one stream. 1773 // Parse the last packet and ensure it's one stream frame from one stream.
1797 EXPECT_EQ(1u, writer_->frame_count()); 1774 EXPECT_EQ(1u, writer_->frame_count());
1798 EXPECT_EQ(1u, writer_->stream_frames().size()); 1775 EXPECT_EQ(1u, writer_->stream_frames().size());
1799 EXPECT_EQ(1u, writer_->stream_frames()[0].stream_id); 1776 EXPECT_EQ(1u, writer_->stream_frames()[0].stream_id);
1800 EXPECT_TRUE(writer_->stream_frames()[0].fin); 1777 EXPECT_TRUE(writer_->stream_frames()[0].fin);
1801 } 1778 }
1802 1779
1803 TEST_P(QuicConnectionTest, OnCanWrite) { 1780 TEST_P(QuicConnectionTest, OnCanWrite) {
1804 // Visitor's OnCanWrite will send data, but will have more pending writes. 1781 // Visitor's OnCanWrite will send data, but will have more pending writes.
1805 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 1782 EXPECT_CALL(visitor_, OnCanWrite())
1806 IgnoreResult(InvokeWithoutArgs(&connection_, 1783 .WillOnce(DoAll(IgnoreResult(InvokeWithoutArgs(
1807 &TestConnection::SendStreamData3)), 1784 &connection_, &TestConnection::SendStreamData3)),
1808 IgnoreResult(InvokeWithoutArgs(&connection_, 1785 IgnoreResult(InvokeWithoutArgs(
1809 &TestConnection::SendStreamData5)))); 1786 &connection_, &TestConnection::SendStreamData5))));
1810 EXPECT_CALL(visitor_, HasPendingWrites()).WillOnce(Return(true)); 1787 EXPECT_CALL(visitor_, HasPendingWrites()).WillOnce(Return(true));
1811 EXPECT_CALL(*send_algorithm_, 1788 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
1812 TimeUntilSend(_, _)).WillRepeatedly( 1789 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero()));
1813 testing::Return(QuicTime::Delta::Zero()));
1814 1790
1815 connection_.OnCanWrite(); 1791 connection_.OnCanWrite();
1816 1792
1817 // Parse the last packet and ensure it's the two stream frames from 1793 // Parse the last packet and ensure it's the two stream frames from
1818 // two different streams. 1794 // two different streams.
1819 EXPECT_EQ(2u, writer_->frame_count()); 1795 EXPECT_EQ(2u, writer_->frame_count());
1820 EXPECT_EQ(2u, writer_->stream_frames().size()); 1796 EXPECT_EQ(2u, writer_->stream_frames().size());
1821 EXPECT_EQ(kStreamId3, writer_->stream_frames()[0].stream_id); 1797 EXPECT_EQ(kStreamId3, writer_->stream_frames()[0].stream_id);
1822 EXPECT_EQ(kStreamId5, writer_->stream_frames()[1].stream_id); 1798 EXPECT_EQ(kStreamId5, writer_->stream_frames()[1].stream_id);
1823 } 1799 }
1824 1800
1825 TEST_P(QuicConnectionTest, RetransmitOnNack) { 1801 TEST_P(QuicConnectionTest, RetransmitOnNack) {
1826 QuicPacketSequenceNumber last_packet; 1802 QuicPacketSequenceNumber last_packet;
1827 QuicByteCount second_packet_size; 1803 QuicByteCount second_packet_size;
1828 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 1 1804 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 1
1829 second_packet_size = 1805 second_packet_size =
1830 SendStreamDataToPeer(3, "foos", 3, !kFin, &last_packet); // Packet 2 1806 SendStreamDataToPeer(3, "foos", 3, !kFin, &last_packet); // Packet 2
1831 SendStreamDataToPeer(3, "fooos", 7, !kFin, &last_packet); // Packet 3 1807 SendStreamDataToPeer(3, "fooos", 7, !kFin, &last_packet); // Packet 3
1832 1808
1833 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1809 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1834 1810
1835 // Don't lose a packet on an ack, and nothing is retransmitted. 1811 // Don't lose a packet on an ack, and nothing is retransmitted.
1836 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_)); 1812 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_));
1837 EXPECT_CALL(*send_algorithm_, OnPacketAcked(1, _)); 1813 EXPECT_CALL(*send_algorithm_, OnPacketAcked(1, _));
1838 QuicAckFrame ack_one = InitAckFrame(1, 0); 1814 QuicAckFrame ack_one = InitAckFrame(1, 0);
1839 ProcessAckPacket(&ack_one); 1815 ProcessAckPacket(&ack_one);
1840 1816
1841 // Lose a packet and ensure it triggers retransmission. 1817 // Lose a packet and ensure it triggers retransmission.
1842 QuicAckFrame nack_two = InitAckFrame(3, 0); 1818 QuicAckFrame nack_two = InitAckFrame(3, 0);
1843 NackPacket(2, &nack_two); 1819 NackPacket(2, &nack_two);
1844 SequenceNumberSet lost_packets; 1820 SequenceNumberSet lost_packets;
1845 lost_packets.insert(2); 1821 lost_packets.insert(2);
1846 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 1822 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1847 .WillOnce(Return(lost_packets)); 1823 .WillOnce(Return(lost_packets));
1848 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_)); 1824 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_));
1849 EXPECT_CALL(*send_algorithm_, OnPacketAcked(3, _)); 1825 EXPECT_CALL(*send_algorithm_, OnPacketAcked(3, _));
1850 EXPECT_CALL(*send_algorithm_, OnPacketLost(2, _)).Times(1); 1826 EXPECT_CALL(*send_algorithm_, OnPacketLost(2, _)).Times(1);
1851 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _)).Times(1); 1827 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(2, _)).Times(1);
1852 EXPECT_CALL(*send_algorithm_, 1828 EXPECT_CALL(*send_algorithm_,
1853 OnPacketSent(_, _, second_packet_size - kQuicVersionSize, _)). 1829 OnPacketSent(_, _, second_packet_size - kQuicVersionSize, _))
1854 Times(1); 1830 .Times(1);
1855 ProcessAckPacket(&nack_two); 1831 ProcessAckPacket(&nack_two);
1856 } 1832 }
1857 1833
1858 TEST_P(QuicConnectionTest, DiscardRetransmit) { 1834 TEST_P(QuicConnectionTest, DiscardRetransmit) {
1859 QuicPacketSequenceNumber last_packet; 1835 QuicPacketSequenceNumber last_packet;
1860 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 1836 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1
1861 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2 1837 SendStreamDataToPeer(1, "foos", 3, !kFin, &last_packet); // Packet 2
1862 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3 1838 SendStreamDataToPeer(1, "fooos", 7, !kFin, &last_packet); // Packet 3
1863 1839
1864 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1840 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1865 1841
1866 // Instigate a loss with an ack. 1842 // Instigate a loss with an ack.
1867 QuicAckFrame nack_two = InitAckFrame(3, 0); 1843 QuicAckFrame nack_two = InitAckFrame(3, 0);
1868 NackPacket(2, &nack_two); 1844 NackPacket(2, &nack_two);
1869 // The first nack should trigger a fast retransmission, but we'll be 1845 // The first nack should trigger a fast retransmission, but we'll be
1870 // write blocked, so the packet will be queued. 1846 // write blocked, so the packet will be queued.
1871 BlockOnNextWrite(); 1847 BlockOnNextWrite();
(...skipping 10 matching lines...) Expand all
1882 1858
1883 // Now, ack the previous transmission. 1859 // Now, ack the previous transmission.
1884 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 1860 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1885 .WillOnce(Return(SequenceNumberSet())); 1861 .WillOnce(Return(SequenceNumberSet()));
1886 QuicAckFrame ack_all = InitAckFrame(3, 0); 1862 QuicAckFrame ack_all = InitAckFrame(3, 0);
1887 ProcessAckPacket(&ack_all); 1863 ProcessAckPacket(&ack_all);
1888 1864
1889 // Unblock the socket and attempt to send the queued packets. However, 1865 // Unblock the socket and attempt to send the queued packets. However,
1890 // since the previous transmission has been acked, we will not 1866 // since the previous transmission has been acked, we will not
1891 // send the retransmission. 1867 // send the retransmission.
1892 EXPECT_CALL(*send_algorithm_, 1868 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(0);
1893 OnPacketSent(_, _, _, _)).Times(0);
1894 1869
1895 writer_->SetWritable(); 1870 writer_->SetWritable();
1896 connection_.OnCanWrite(); 1871 connection_.OnCanWrite();
1897 1872
1898 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1873 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1899 } 1874 }
1900 1875
1901 TEST_P(QuicConnectionTest, RetransmitNackedLargestObserved) { 1876 TEST_P(QuicConnectionTest, RetransmitNackedLargestObserved) {
1902 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1877 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1903 QuicPacketSequenceNumber largest_observed; 1878 QuicPacketSequenceNumber largest_observed;
1904 QuicByteCount packet_size; 1879 QuicByteCount packet_size;
1905 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)) 1880 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).WillOnce(DoAll(
1906 .WillOnce(DoAll(SaveArg<1>(&largest_observed), SaveArg<2>(&packet_size), 1881 SaveArg<1>(&largest_observed), SaveArg<2>(&packet_size), Return(true)));
1907 Return(true)));
1908 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 1882 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
1909 1883
1910 QuicAckFrame frame = InitAckFrame(1, largest_observed); 1884 QuicAckFrame frame = InitAckFrame(1, largest_observed);
1911 NackPacket(largest_observed, &frame); 1885 NackPacket(largest_observed, &frame);
1912 // The first nack should retransmit the largest observed packet. 1886 // The first nack should retransmit the largest observed packet.
1913 SequenceNumberSet lost_packets; 1887 SequenceNumberSet lost_packets;
1914 lost_packets.insert(1); 1888 lost_packets.insert(1);
1915 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 1889 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1916 .WillOnce(Return(lost_packets)); 1890 .WillOnce(Return(lost_packets));
1917 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_)); 1891 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_));
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
2045 ProcessAckPacket(&nack); 2019 ProcessAckPacket(&nack);
2046 } 2020 }
2047 2021
2048 // Test sending multiple acks from the connection to the session. 2022 // Test sending multiple acks from the connection to the session.
2049 TEST_P(QuicConnectionTest, MultipleAcks) { 2023 TEST_P(QuicConnectionTest, MultipleAcks) {
2050 QuicPacketSequenceNumber last_packet; 2024 QuicPacketSequenceNumber last_packet;
2051 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1 2025 SendStreamDataToPeer(1, "foo", 0, !kFin, &last_packet); // Packet 1
2052 EXPECT_EQ(1u, last_packet); 2026 EXPECT_EQ(1u, last_packet);
2053 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 2 2027 SendStreamDataToPeer(3, "foo", 0, !kFin, &last_packet); // Packet 2
2054 EXPECT_EQ(2u, last_packet); 2028 EXPECT_EQ(2u, last_packet);
2055 SendAckPacketToPeer(); // Packet 3 2029 SendAckPacketToPeer(); // Packet 3
2056 SendStreamDataToPeer(5, "foo", 0, !kFin, &last_packet); // Packet 4 2030 SendStreamDataToPeer(5, "foo", 0, !kFin, &last_packet); // Packet 4
2057 EXPECT_EQ(4u, last_packet); 2031 EXPECT_EQ(4u, last_packet);
2058 SendStreamDataToPeer(1, "foo", 3, !kFin, &last_packet); // Packet 5 2032 SendStreamDataToPeer(1, "foo", 3, !kFin, &last_packet); // Packet 5
2059 EXPECT_EQ(5u, last_packet); 2033 EXPECT_EQ(5u, last_packet);
2060 SendStreamDataToPeer(3, "foo", 3, !kFin, &last_packet); // Packet 6 2034 SendStreamDataToPeer(3, "foo", 3, !kFin, &last_packet); // Packet 6
2061 EXPECT_EQ(6u, last_packet); 2035 EXPECT_EQ(6u, last_packet);
2062 2036
2063 // Client will ack packets 1, 2, [!3], 4, 5. 2037 // Client will ack packets 1, 2, [!3], 4, 5.
2064 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_)); 2038 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_));
2065 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(4); 2039 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(4);
2066 QuicAckFrame frame1 = InitAckFrame(5, 0); 2040 QuicAckFrame frame1 = InitAckFrame(5, 0);
2067 NackPacket(3, &frame1); 2041 NackPacket(3, &frame1);
2068 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2042 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2069 ProcessAckPacket(&frame1); 2043 ProcessAckPacket(&frame1);
2070 2044
2071 // Now the client implicitly acks 3, and explicitly acks 6. 2045 // Now the client implicitly acks 3, and explicitly acks 6.
2072 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_)); 2046 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_));
2073 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(2); 2047 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(2);
2074 QuicAckFrame frame2 = InitAckFrame(6, 0); 2048 QuicAckFrame frame2 = InitAckFrame(6, 0);
2075 ProcessAckPacket(&frame2); 2049 ProcessAckPacket(&frame2);
2076 } 2050 }
2077 2051
2078 TEST_P(QuicConnectionTest, DontLatchUnackedPacket) { 2052 TEST_P(QuicConnectionTest, DontLatchUnackedPacket) {
2079 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_)); 2053 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_));
2080 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1); 2054 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1);
2081 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); // Packet 1; 2055 SendStreamDataToPeer(1, "foo", 0, !kFin, NULL); // Packet 1;
2082 // From now on, we send acks, so the send algorithm won't mark them pending. 2056 // From now on, we send acks, so the send algorithm won't mark them pending.
2083 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)) 2057 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _))
2084 .WillByDefault(Return(false)); 2058 .WillByDefault(Return(false));
2085 SendAckPacketToPeer(); // Packet 2 2059 SendAckPacketToPeer(); // Packet 2
2086 2060
2087 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2061 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2088 QuicAckFrame frame = InitAckFrame(1, 0); 2062 QuicAckFrame frame = InitAckFrame(1, 0);
2089 ProcessAckPacket(&frame); 2063 ProcessAckPacket(&frame);
2090 2064
2091 // Verify that our internal state has least-unacked as 2, because we're still 2065 // Verify that our internal state has least-unacked as 2, because we're still
2092 // waiting for a potential ack for 2. 2066 // waiting for a potential ack for 2.
2093 EXPECT_EQ(2u, outgoing_ack()->sent_info.least_unacked); 2067 EXPECT_EQ(2u, outgoing_ack()->sent_info.least_unacked);
2094 2068
(...skipping 10 matching lines...) Expand all
2105 EXPECT_EQ(3u, outgoing_ack()->sent_info.least_unacked); 2079 EXPECT_EQ(3u, outgoing_ack()->sent_info.least_unacked);
2106 // Check that the outgoing ack had its sequence number as least_unacked. 2080 // Check that the outgoing ack had its sequence number as least_unacked.
2107 EXPECT_EQ(3u, least_unacked()); 2081 EXPECT_EQ(3u, least_unacked());
2108 2082
2109 // Ack the ack, which updates the rtt and raises the least unacked. 2083 // Ack the ack, which updates the rtt and raises the least unacked.
2110 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_)); 2084 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_));
2111 frame = InitAckFrame(3, 0); 2085 frame = InitAckFrame(3, 0);
2112 ProcessAckPacket(&frame); 2086 ProcessAckPacket(&frame);
2113 2087
2114 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)) 2088 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _))
2115 .WillByDefault(Return(true)); 2089 .WillByDefault(Return(true));
2116 SendStreamDataToPeer(1, "bar", 3, false, NULL); // Packet 4 2090 SendStreamDataToPeer(1, "bar", 3, false, NULL); // Packet 4
2117 EXPECT_EQ(4u, outgoing_ack()->sent_info.least_unacked); 2091 EXPECT_EQ(4u, outgoing_ack()->sent_info.least_unacked);
2118 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)) 2092 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _))
2119 .WillByDefault(Return(false)); 2093 .WillByDefault(Return(false));
2120 SendAckPacketToPeer(); // Packet 5 2094 SendAckPacketToPeer(); // Packet 5
2121 EXPECT_EQ(4u, least_unacked()); 2095 EXPECT_EQ(4u, least_unacked());
2122 2096
2123 // Send two data packets at the end, and ensure if the last one is acked, 2097 // Send two data packets at the end, and ensure if the last one is acked,
2124 // the least unacked is raised above the ack packets. 2098 // the least unacked is raised above the ack packets.
2125 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)) 2099 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _))
2126 .WillByDefault(Return(true)); 2100 .WillByDefault(Return(true));
2127 SendStreamDataToPeer(1, "bar", 6, false, NULL); // Packet 6 2101 SendStreamDataToPeer(1, "bar", 6, false, NULL); // Packet 6
2128 SendStreamDataToPeer(1, "bar", 9, false, NULL); // Packet 7 2102 SendStreamDataToPeer(1, "bar", 9, false, NULL); // Packet 7
2129 2103
2130 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_)); 2104 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_));
2131 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(2); 2105 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(2);
2132 frame = InitAckFrame(7, 0); 2106 frame = InitAckFrame(7, 0);
2133 NackPacket(5, &frame); 2107 NackPacket(5, &frame);
2134 NackPacket(6, &frame); 2108 NackPacket(6, &frame);
2135 ProcessAckPacket(&frame); 2109 ProcessAckPacket(&frame);
2136 2110
(...skipping 12 matching lines...) Expand all
2149 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); 2123 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2));
2150 } 2124 }
2151 2125
2152 TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingSeqNumLengths) { 2126 TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingSeqNumLengths) {
2153 if (version() < QUIC_VERSION_15) { 2127 if (version() < QUIC_VERSION_15) {
2154 return; 2128 return;
2155 } 2129 }
2156 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2130 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2157 2131
2158 // Set up a debug visitor to the connection. 2132 // Set up a debug visitor to the connection.
2159 scoped_ptr<FecQuicConnectionDebugVisitor> 2133 scoped_ptr<FecQuicConnectionDebugVisitor> fec_visitor(
2160 fec_visitor(new FecQuicConnectionDebugVisitor); 2134 new FecQuicConnectionDebugVisitor);
2161 connection_.set_debug_visitor(fec_visitor.get()); 2135 connection_.set_debug_visitor(fec_visitor.get());
2162 2136
2163 QuicPacketSequenceNumber fec_packet = 0; 2137 QuicPacketSequenceNumber fec_packet = 0;
2164 QuicSequenceNumberLength lengths[] = {PACKET_6BYTE_SEQUENCE_NUMBER, 2138 QuicSequenceNumberLength lengths[] = {
2165 PACKET_4BYTE_SEQUENCE_NUMBER, 2139 PACKET_6BYTE_SEQUENCE_NUMBER, PACKET_4BYTE_SEQUENCE_NUMBER,
2166 PACKET_2BYTE_SEQUENCE_NUMBER, 2140 PACKET_2BYTE_SEQUENCE_NUMBER, PACKET_1BYTE_SEQUENCE_NUMBER};
2167 PACKET_1BYTE_SEQUENCE_NUMBER};
2168 // For each sequence number length size, revive a packet and check sequence 2141 // For each sequence number length size, revive a packet and check sequence
2169 // number length in the revived packet. 2142 // number length in the revived packet.
2170 for (size_t i = 0; i < arraysize(lengths); ++i) { 2143 for (size_t i = 0; i < arraysize(lengths); ++i) {
2171 // Set sequence_number_length_ (for data and FEC packets). 2144 // Set sequence_number_length_ (for data and FEC packets).
2172 sequence_number_length_ = lengths[i]; 2145 sequence_number_length_ = lengths[i];
2173 fec_packet += 2; 2146 fec_packet += 2;
2174 // Don't send missing packet, but send fec packet right after it. 2147 // Don't send missing packet, but send fec packet right after it.
2175 ProcessFecPacket(/*seq_num=*/fec_packet, /*fec_group=*/fec_packet - 1, 2148 ProcessFecPacket(/*seq_num=*/fec_packet,
2176 true, !kEntropyFlag, NULL); 2149 /*fec_group=*/fec_packet - 1,
2150 true,
2151 !kEntropyFlag,
2152 NULL);
2177 // Sequence number length in the revived header should be the same as 2153 // Sequence number length in the revived header should be the same as
2178 // in the original data/fec packet headers. 2154 // in the original data/fec packet headers.
2179 EXPECT_EQ(sequence_number_length_, fec_visitor->revived_header(). 2155 EXPECT_EQ(
2180 public_header.sequence_number_length); 2156 sequence_number_length_,
2157 fec_visitor->revived_header().public_header.sequence_number_length);
2181 } 2158 }
2182 } 2159 }
2183 2160
2184 TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingConnectionIdLengths) { 2161 TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingConnectionIdLengths) {
2185 if (version() < QUIC_VERSION_15) { 2162 if (version() < QUIC_VERSION_15) {
2186 return; 2163 return;
2187 } 2164 }
2188 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2165 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2189 2166
2190 // Set up a debug visitor to the connection. 2167 // Set up a debug visitor to the connection.
2191 scoped_ptr<FecQuicConnectionDebugVisitor> 2168 scoped_ptr<FecQuicConnectionDebugVisitor> fec_visitor(
2192 fec_visitor(new FecQuicConnectionDebugVisitor); 2169 new FecQuicConnectionDebugVisitor);
2193 connection_.set_debug_visitor(fec_visitor.get()); 2170 connection_.set_debug_visitor(fec_visitor.get());
2194 2171
2195 QuicPacketSequenceNumber fec_packet = 0; 2172 QuicPacketSequenceNumber fec_packet = 0;
2196 QuicConnectionIdLength lengths[] = {PACKET_8BYTE_CONNECTION_ID, 2173 QuicConnectionIdLength lengths[] = {
2197 PACKET_4BYTE_CONNECTION_ID, 2174 PACKET_8BYTE_CONNECTION_ID, PACKET_4BYTE_CONNECTION_ID,
2198 PACKET_1BYTE_CONNECTION_ID, 2175 PACKET_1BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID};
2199 PACKET_0BYTE_CONNECTION_ID};
2200 // For each connection id length size, revive a packet and check connection 2176 // For each connection id length size, revive a packet and check connection
2201 // id length in the revived packet. 2177 // id length in the revived packet.
2202 for (size_t i = 0; i < arraysize(lengths); ++i) { 2178 for (size_t i = 0; i < arraysize(lengths); ++i) {
2203 // Set connection id length (for data and FEC packets). 2179 // Set connection id length (for data and FEC packets).
2204 connection_id_length_ = lengths[i]; 2180 connection_id_length_ = lengths[i];
2205 fec_packet += 2; 2181 fec_packet += 2;
2206 // Don't send missing packet, but send fec packet right after it. 2182 // Don't send missing packet, but send fec packet right after it.
2207 ProcessFecPacket(/*seq_num=*/fec_packet, /*fec_group=*/fec_packet - 1, 2183 ProcessFecPacket(/*seq_num=*/fec_packet,
2208 true, !kEntropyFlag, NULL); 2184 /*fec_group=*/fec_packet - 1,
2185 true,
2186 !kEntropyFlag,
2187 NULL);
2209 // Connection id length in the revived header should be the same as 2188 // Connection id length in the revived header should be the same as
2210 // in the original data/fec packet headers. 2189 // in the original data/fec packet headers.
2211 EXPECT_EQ(connection_id_length_, 2190 EXPECT_EQ(connection_id_length_,
2212 fec_visitor->revived_header().public_header.connection_id_length); 2191 fec_visitor->revived_header().public_header.connection_id_length);
2213 } 2192 }
2214 } 2193 }
2215 2194
2216 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) { 2195 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) {
2217 if (version() < QUIC_VERSION_15) { 2196 if (version() < QUIC_VERSION_15) {
2218 return; 2197 return;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2266 ProcessFecPacket(6, 1, false, kEntropyFlag, NULL); 2245 ProcessFecPacket(6, 1, false, kEntropyFlag, NULL);
2267 ProcessFecProtectedPacket(3, false, kEntropyFlag); 2246 ProcessFecProtectedPacket(3, false, kEntropyFlag);
2268 ProcessFecProtectedPacket(4, false, kEntropyFlag); 2247 ProcessFecProtectedPacket(4, false, kEntropyFlag);
2269 ProcessFecProtectedPacket(5, true, !kEntropyFlag); 2248 ProcessFecProtectedPacket(5, true, !kEntropyFlag);
2270 // Ensure entropy is not revived for the missing packet. 2249 // Ensure entropy is not revived for the missing packet.
2271 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); 2250 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2));
2272 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 3)); 2251 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 3));
2273 } 2252 }
2274 2253
2275 TEST_P(QuicConnectionTest, RTO) { 2254 TEST_P(QuicConnectionTest, RTO) {
2276 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( 2255 QuicTime default_retransmission_time =
2277 DefaultRetransmissionTime()); 2256 clock_.ApproximateNow().Add(DefaultRetransmissionTime());
2278 SendStreamDataToPeer(3, "foo", 0, !kFin, NULL); 2257 SendStreamDataToPeer(3, "foo", 0, !kFin, NULL);
2279 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); 2258 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked);
2280 2259
2281 EXPECT_EQ(1u, writer_->header().packet_sequence_number); 2260 EXPECT_EQ(1u, writer_->header().packet_sequence_number);
2282 EXPECT_EQ(default_retransmission_time, 2261 EXPECT_EQ(default_retransmission_time,
2283 connection_.GetRetransmissionAlarm()->deadline()); 2262 connection_.GetRetransmissionAlarm()->deadline());
2284 // Simulate the retransmission alarm firing. 2263 // Simulate the retransmission alarm firing.
2285 clock_.AdvanceTime(DefaultRetransmissionTime()); 2264 clock_.AdvanceTime(DefaultRetransmissionTime());
2286 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2265 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2287 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 2u, _, _)); 2266 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 2u, _, _));
2288 connection_.GetRetransmissionAlarm()->Fire(); 2267 connection_.GetRetransmissionAlarm()->Fire();
2289 EXPECT_EQ(2u, writer_->header().packet_sequence_number); 2268 EXPECT_EQ(2u, writer_->header().packet_sequence_number);
2290 // We do not raise the high water mark yet. 2269 // We do not raise the high water mark yet.
2291 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); 2270 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked);
2292 } 2271 }
2293 2272
2294 TEST_P(QuicConnectionTest, RTOWithSameEncryptionLevel) { 2273 TEST_P(QuicConnectionTest, RTOWithSameEncryptionLevel) {
2295 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( 2274 QuicTime default_retransmission_time =
2296 DefaultRetransmissionTime()); 2275 clock_.ApproximateNow().Add(DefaultRetransmissionTime());
2297 use_tagging_decrypter(); 2276 use_tagging_decrypter();
2298 2277
2299 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at 2278 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at
2300 // the end of the packet. We can test this to check which encrypter was used. 2279 // the end of the packet. We can test this to check which encrypter was used.
2301 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 2280 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
2302 SendStreamDataToPeer(3, "foo", 0, !kFin, NULL); 2281 SendStreamDataToPeer(3, "foo", 0, !kFin, NULL);
2303 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_last_packet()); 2282 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_last_packet());
2304 2283
2305 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); 2284 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
2306 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2285 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
(...skipping 20 matching lines...) Expand all
2327 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); 2306 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet());
2328 } 2307 }
2329 2308
2330 TEST_P(QuicConnectionTest, SendHandshakeMessages) { 2309 TEST_P(QuicConnectionTest, SendHandshakeMessages) {
2331 use_tagging_decrypter(); 2310 use_tagging_decrypter();
2332 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at 2311 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at
2333 // the end of the packet. We can test this to check which encrypter was used. 2312 // the end of the packet. We can test this to check which encrypter was used.
2334 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 2313 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
2335 2314
2336 // Attempt to send a handshake message and have the socket block. 2315 // Attempt to send a handshake message and have the socket block.
2337 EXPECT_CALL(*send_algorithm_, 2316 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
2338 TimeUntilSend(_, _)).WillRepeatedly( 2317 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero()));
2339 testing::Return(QuicTime::Delta::Zero()));
2340 BlockOnNextWrite(); 2318 BlockOnNextWrite();
2341 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 2319 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
2342 // The packet should be serialized, but not queued. 2320 // The packet should be serialized, but not queued.
2343 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2321 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2344 2322
2345 // Switch to the new encrypter. 2323 // Switch to the new encrypter.
2346 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); 2324 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
2347 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2325 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2348 2326
2349 // Now become writeable and flush the packets. 2327 // Now become writeable and flush the packets.
(...skipping 13 matching lines...) Expand all
2363 QuicPacketSequenceNumber sequence_number; 2341 QuicPacketSequenceNumber sequence_number;
2364 SendStreamDataToPeer(3, "foo", 0, !kFin, &sequence_number); 2342 SendStreamDataToPeer(3, "foo", 0, !kFin, &sequence_number);
2365 2343
2366 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, 2344 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE,
2367 new TaggingEncrypter(0x02)); 2345 new TaggingEncrypter(0x02));
2368 connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); 2346 connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE);
2369 2347
2370 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2348 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2371 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(0); 2349 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(0);
2372 2350
2373 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( 2351 QuicTime default_retransmission_time =
2374 DefaultRetransmissionTime()); 2352 clock_.ApproximateNow().Add(DefaultRetransmissionTime());
2375 2353
2376 EXPECT_EQ(default_retransmission_time, 2354 EXPECT_EQ(default_retransmission_time,
2377 connection_.GetRetransmissionAlarm()->deadline()); 2355 connection_.GetRetransmissionAlarm()->deadline());
2378 // Simulate the retransmission alarm firing. 2356 // Simulate the retransmission alarm firing.
2379 clock_.AdvanceTime(DefaultRetransmissionTime()); 2357 clock_.AdvanceTime(DefaultRetransmissionTime());
2380 connection_.GetRetransmissionAlarm()->Fire(); 2358 connection_.GetRetransmissionAlarm()->Fire();
2381 } 2359 }
2382 2360
2383 TEST_P(QuicConnectionTest, RetransmitPacketsWithInitialEncryption) { 2361 TEST_P(QuicConnectionTest, RetransmitPacketsWithInitialEncryption) {
2384 use_tagging_decrypter(); 2362 use_tagging_decrypter();
(...skipping 20 matching lines...) Expand all
2405 const uint8 tag = 0x07; 2383 const uint8 tag = 0x07;
2406 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 2384 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
2407 2385
2408 // Process an encrypted packet which can not yet be decrypted 2386 // Process an encrypted packet which can not yet be decrypted
2409 // which should result in the packet being buffered. 2387 // which should result in the packet being buffered.
2410 ProcessDataPacketAtLevel(1, 0, kEntropyFlag, ENCRYPTION_INITIAL); 2388 ProcessDataPacketAtLevel(1, 0, kEntropyFlag, ENCRYPTION_INITIAL);
2411 2389
2412 // Transition to the new encryption state and process another 2390 // Transition to the new encryption state and process another
2413 // encrypted packet which should result in the original packet being 2391 // encrypted packet which should result in the original packet being
2414 // processed. 2392 // processed.
2415 connection_.SetDecrypter(new StrictTaggingDecrypter(tag), 2393 connection_.SetDecrypter(new StrictTaggingDecrypter(tag), ENCRYPTION_INITIAL);
2416 ENCRYPTION_INITIAL);
2417 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2394 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2418 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 2395 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
2419 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(2); 2396 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(2);
2420 ProcessDataPacketAtLevel(2, 0, kEntropyFlag, ENCRYPTION_INITIAL); 2397 ProcessDataPacketAtLevel(2, 0, kEntropyFlag, ENCRYPTION_INITIAL);
2421 2398
2422 // Finally, process a third packet and note that we do not 2399 // Finally, process a third packet and note that we do not
2423 // reprocess the buffered packet. 2400 // reprocess the buffered packet.
2424 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 2401 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1);
2425 ProcessDataPacketAtLevel(3, 0, kEntropyFlag, ENCRYPTION_INITIAL); 2402 ProcessDataPacketAtLevel(3, 0, kEntropyFlag, ENCRYPTION_INITIAL);
2426 } 2403 }
2427 2404
2428 TEST_P(QuicConnectionTest, TestRetransmitOrder) { 2405 TEST_P(QuicConnectionTest, TestRetransmitOrder) {
2429 QuicByteCount first_packet_size; 2406 QuicByteCount first_packet_size;
2430 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).WillOnce( 2407 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _))
2431 DoAll(SaveArg<2>(&first_packet_size), Return(true))); 2408 .WillOnce(DoAll(SaveArg<2>(&first_packet_size), Return(true)));
2432 2409
2433 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, NULL); 2410 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, NULL);
2434 QuicByteCount second_packet_size; 2411 QuicByteCount second_packet_size;
2435 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).WillOnce( 2412 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _))
2436 DoAll(SaveArg<2>(&second_packet_size), Return(true))); 2413 .WillOnce(DoAll(SaveArg<2>(&second_packet_size), Return(true)));
2437 connection_.SendStreamDataWithString(3, "second_packet", 12, !kFin, NULL); 2414 connection_.SendStreamDataWithString(3, "second_packet", 12, !kFin, NULL);
2438 EXPECT_NE(first_packet_size, second_packet_size); 2415 EXPECT_NE(first_packet_size, second_packet_size);
2439 // Advance the clock by huge time to make sure packets will be retransmitted. 2416 // Advance the clock by huge time to make sure packets will be retransmitted.
2440 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); 2417 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10));
2441 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2418 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2442 { 2419 {
2443 InSequence s; 2420 InSequence s;
2444 EXPECT_CALL(*send_algorithm_, 2421 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, first_packet_size, _));
2445 OnPacketSent(_, _, first_packet_size, _)); 2422 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, second_packet_size, _));
2446 EXPECT_CALL(*send_algorithm_,
2447 OnPacketSent(_, _, second_packet_size, _));
2448 } 2423 }
2449 connection_.GetRetransmissionAlarm()->Fire(); 2424 connection_.GetRetransmissionAlarm()->Fire();
2450 2425
2451 // Advance again and expect the packets to be sent again in the same order. 2426 // Advance again and expect the packets to be sent again in the same order.
2452 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(20)); 2427 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(20));
2453 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2428 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2454 { 2429 {
2455 InSequence s; 2430 InSequence s;
2456 EXPECT_CALL(*send_algorithm_, 2431 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, first_packet_size, _));
2457 OnPacketSent(_, _, first_packet_size, _)); 2432 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, second_packet_size, _));
2458 EXPECT_CALL(*send_algorithm_,
2459 OnPacketSent(_, _, second_packet_size, _));
2460 } 2433 }
2461 connection_.GetRetransmissionAlarm()->Fire(); 2434 connection_.GetRetransmissionAlarm()->Fire();
2462 } 2435 }
2463 2436
2464 TEST_P(QuicConnectionTest, RetransmissionCountCalculation) { 2437 TEST_P(QuicConnectionTest, RetransmissionCountCalculation) {
2465 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2438 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2466 QuicPacketSequenceNumber original_sequence_number; 2439 QuicPacketSequenceNumber original_sequence_number;
2467 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)) 2440 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _))
2468 .WillOnce(DoAll(SaveArg<1>(&original_sequence_number), Return(true))); 2441 .WillOnce(DoAll(SaveArg<1>(&original_sequence_number), Return(true)));
2469 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 2442 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
2470 2443
2471 EXPECT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( 2444 EXPECT_TRUE(QuicConnectionPeer::IsSavedForRetransmission(
2472 &connection_, original_sequence_number)); 2445 &connection_, original_sequence_number));
2473 EXPECT_FALSE(QuicConnectionPeer::IsRetransmission( 2446 EXPECT_FALSE(QuicConnectionPeer::IsRetransmission(&connection_,
2474 &connection_, original_sequence_number)); 2447 original_sequence_number));
2475 // Force retransmission due to RTO. 2448 // Force retransmission due to RTO.
2476 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); 2449 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10));
2477 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2450 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2478 QuicPacketSequenceNumber rto_sequence_number; 2451 QuicPacketSequenceNumber rto_sequence_number;
2479 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)) 2452 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _))
2480 .WillOnce(DoAll(SaveArg<1>(&rto_sequence_number), Return(true))); 2453 .WillOnce(DoAll(SaveArg<1>(&rto_sequence_number), Return(true)));
2481 connection_.GetRetransmissionAlarm()->Fire(); 2454 connection_.GetRetransmissionAlarm()->Fire();
2482 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( 2455 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission(
2483 &connection_, original_sequence_number)); 2456 &connection_, original_sequence_number));
2484 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( 2457 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission(
2485 &connection_, rto_sequence_number)); 2458 &connection_, rto_sequence_number));
2486 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission( 2459 EXPECT_TRUE(
2487 &connection_, rto_sequence_number)); 2460 QuicConnectionPeer::IsRetransmission(&connection_, rto_sequence_number));
2488 // Once by explicit nack. 2461 // Once by explicit nack.
2489 SequenceNumberSet lost_packets; 2462 SequenceNumberSet lost_packets;
2490 lost_packets.insert(rto_sequence_number); 2463 lost_packets.insert(rto_sequence_number);
2491 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 2464 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
2492 .WillOnce(Return(lost_packets)); 2465 .WillOnce(Return(lost_packets));
2493 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_)).Times(1); 2466 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_)).Times(1);
2494 EXPECT_CALL(*send_algorithm_, OnPacketLost(rto_sequence_number, _)).Times(1); 2467 EXPECT_CALL(*send_algorithm_, OnPacketLost(rto_sequence_number, _)).Times(1);
2495 EXPECT_CALL(*send_algorithm_, 2468 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(rto_sequence_number, _))
2496 OnPacketAbandoned(rto_sequence_number, _)).Times(1); 2469 .Times(1);
2497 QuicPacketSequenceNumber nack_sequence_number = 0; 2470 QuicPacketSequenceNumber nack_sequence_number = 0;
2498 // Ack packets might generate some other packets, which are not 2471 // Ack packets might generate some other packets, which are not
2499 // retransmissions. (More ack packets). 2472 // retransmissions. (More ack packets).
2500 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)) 2473 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(AnyNumber());
2501 .Times(AnyNumber());
2502 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)) 2474 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _))
2503 .WillOnce(DoAll(SaveArg<1>(&nack_sequence_number), Return(true))); 2475 .WillOnce(DoAll(SaveArg<1>(&nack_sequence_number), Return(true)));
2504 QuicAckFrame ack = InitAckFrame(rto_sequence_number, 0); 2476 QuicAckFrame ack = InitAckFrame(rto_sequence_number, 0);
2505 // Nack the retransmitted packet. 2477 // Nack the retransmitted packet.
2506 NackPacket(original_sequence_number, &ack); 2478 NackPacket(original_sequence_number, &ack);
2507 NackPacket(rto_sequence_number, &ack); 2479 NackPacket(rto_sequence_number, &ack);
2508 ProcessAckPacket(&ack); 2480 ProcessAckPacket(&ack);
2509 2481
2510 ASSERT_NE(0u, nack_sequence_number); 2482 ASSERT_NE(0u, nack_sequence_number);
2511 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission( 2483 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission(
2512 &connection_, rto_sequence_number)); 2484 &connection_, rto_sequence_number));
2513 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission( 2485 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission(
2514 &connection_, nack_sequence_number)); 2486 &connection_, nack_sequence_number));
2515 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission( 2487 EXPECT_TRUE(
2516 &connection_, nack_sequence_number)); 2488 QuicConnectionPeer::IsRetransmission(&connection_, nack_sequence_number));
2517 } 2489 }
2518 2490
2519 TEST_P(QuicConnectionTest, SetRTOAfterWritingToSocket) { 2491 TEST_P(QuicConnectionTest, SetRTOAfterWritingToSocket) {
2520 BlockOnNextWrite(); 2492 BlockOnNextWrite();
2521 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); 2493 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL);
2522 // Make sure that RTO is not started when the packet is queued. 2494 // Make sure that RTO is not started when the packet is queued.
2523 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2495 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2524 2496
2525 // Test that RTO is started once we write to the socket. 2497 // Test that RTO is started once we write to the socket.
2526 writer_->SetWritable(); 2498 writer_->SetWritable();
2527 connection_.OnCanWrite(); 2499 connection_.OnCanWrite();
2528 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2500 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2529 } 2501 }
2530 2502
2531 TEST_P(QuicConnectionTest, DelayRTOWithAckReceipt) { 2503 TEST_P(QuicConnectionTest, DelayRTOWithAckReceipt) {
2532 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2504 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2533 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)) 2505 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(2);
2534 .Times(2);
2535 connection_.SendStreamDataWithString(2, "foo", 0, !kFin, NULL); 2506 connection_.SendStreamDataWithString(2, "foo", 0, !kFin, NULL);
2536 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, NULL); 2507 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, NULL);
2537 QuicAlarm* retransmission_alarm = connection_.GetRetransmissionAlarm(); 2508 QuicAlarm* retransmission_alarm = connection_.GetRetransmissionAlarm();
2538 EXPECT_TRUE(retransmission_alarm->IsSet()); 2509 EXPECT_TRUE(retransmission_alarm->IsSet());
2539 EXPECT_EQ(clock_.Now().Add(DefaultRetransmissionTime()), 2510 EXPECT_EQ(clock_.Now().Add(DefaultRetransmissionTime()),
2540 retransmission_alarm->deadline()); 2511 retransmission_alarm->deadline());
2541 2512
2542 // Advance the time right before the RTO, then receive an ack for the first 2513 // Advance the time right before the RTO, then receive an ack for the first
2543 // packet to delay the RTO. 2514 // packet to delay the RTO.
2544 clock_.AdvanceTime(DefaultRetransmissionTime()); 2515 clock_.AdvanceTime(DefaultRetransmissionTime());
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
2641 TEST_P(QuicConnectionTest, InitialTimeout) { 2612 TEST_P(QuicConnectionTest, InitialTimeout) {
2642 EXPECT_TRUE(connection_.connected()); 2613 EXPECT_TRUE(connection_.connected());
2643 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false)); 2614 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false));
2644 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)); 2615 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _));
2645 2616
2646 QuicTime default_timeout = clock_.ApproximateNow().Add( 2617 QuicTime default_timeout = clock_.ApproximateNow().Add(
2647 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); 2618 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs));
2648 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); 2619 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline());
2649 2620
2650 // Simulate the timeout alarm firing. 2621 // Simulate the timeout alarm firing.
2651 clock_.AdvanceTime( 2622 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs));
2652 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs));
2653 connection_.GetTimeoutAlarm()->Fire(); 2623 connection_.GetTimeoutAlarm()->Fire();
2654 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 2624 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2655 EXPECT_FALSE(connection_.connected()); 2625 EXPECT_FALSE(connection_.connected());
2656 2626
2657 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 2627 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
2658 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); 2628 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet());
2659 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet()); 2629 EXPECT_FALSE(connection_.GetResumeWritesAlarm()->IsSet());
2660 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2630 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2661 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); 2631 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet());
2662 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 2632 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
2740 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)), 2710 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)),
2741 clock_.ApproximateNow()); 2711 clock_.ApproximateNow());
2742 connection_.GetTimeoutAlarm()->Fire(); 2712 connection_.GetTimeoutAlarm()->Fire();
2743 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); 2713 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet());
2744 EXPECT_FALSE(connection_.connected()); 2714 EXPECT_FALSE(connection_.connected());
2745 } 2715 }
2746 2716
2747 TEST_P(QuicConnectionTest, SendScheduler) { 2717 TEST_P(QuicConnectionTest, SendScheduler) {
2748 // Test that if we send a packet without delay, it is not queued. 2718 // Test that if we send a packet without delay, it is not queued.
2749 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2719 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2750 EXPECT_CALL(*send_algorithm_, 2720 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
2751 TimeUntilSend(_, _)).WillOnce( 2721 .WillOnce(testing::Return(QuicTime::Delta::Zero()));
2752 testing::Return(QuicTime::Delta::Zero()));
2753 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)); 2722 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _));
2754 connection_.SendPacket( 2723 connection_.SendPacket(
2755 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2724 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2756 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2725 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2757 } 2726 }
2758 2727
2759 TEST_P(QuicConnectionTest, SendSchedulerDelay) { 2728 TEST_P(QuicConnectionTest, SendSchedulerDelay) {
2760 // Test that if we send a packet with a delay, it ends up queued. 2729 // Test that if we send a packet with a delay, it ends up queued.
2761 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2730 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2762 EXPECT_CALL(*send_algorithm_, 2731 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
2763 TimeUntilSend(_, _)).WillOnce( 2732 .WillOnce(testing::Return(QuicTime::Delta::FromMicroseconds(1)));
2764 testing::Return(QuicTime::Delta::FromMicroseconds(1)));
2765 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _)).Times(0); 2733 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _)).Times(0);
2766 connection_.SendPacket( 2734 connection_.SendPacket(
2767 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2735 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2768 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2736 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2769 } 2737 }
2770 2738
2771 TEST_P(QuicConnectionTest, SendSchedulerEAGAIN) { 2739 TEST_P(QuicConnectionTest, SendSchedulerEAGAIN) {
2772 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2740 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2773 BlockOnNextWrite(); 2741 BlockOnNextWrite();
2774 EXPECT_CALL(*send_algorithm_, 2742 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
2775 TimeUntilSend(_, _)).WillOnce( 2743 .WillOnce(testing::Return(QuicTime::Delta::Zero()));
2776 testing::Return(QuicTime::Delta::Zero()));
2777 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _)).Times(0); 2744 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _)).Times(0);
2778 connection_.SendPacket( 2745 connection_.SendPacket(
2779 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2746 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2780 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2747 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2781 } 2748 }
2782 2749
2783 TEST_P(QuicConnectionTest, SendSchedulerDelayThenSend) { 2750 TEST_P(QuicConnectionTest, SendSchedulerDelayThenSend) {
2784 // Test that if we send a packet with a delay, it ends up queued. 2751 // Test that if we send a packet with a delay, it ends up queued.
2785 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2752 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2786 EXPECT_CALL(*send_algorithm_, 2753 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
2787 TimeUntilSend(_, _)).WillOnce( 2754 .WillOnce(testing::Return(QuicTime::Delta::FromMicroseconds(1)));
2788 testing::Return(QuicTime::Delta::FromMicroseconds(1)));
2789 connection_.SendPacket( 2755 connection_.SendPacket(
2790 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2756 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2791 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2757 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2792 2758
2793 // Advance the clock to fire the alarm, and configure the scheduler 2759 // Advance the clock to fire the alarm, and configure the scheduler
2794 // to permit the packet to be sent. 2760 // to permit the packet to be sent.
2795 EXPECT_CALL(*send_algorithm_, 2761 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
2796 TimeUntilSend(_, _)).WillRepeatedly( 2762 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero()));
2797 testing::Return(QuicTime::Delta::Zero()));
2798 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); 2763 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1));
2799 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)); 2764 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _));
2800 connection_.GetSendAlarm()->Fire(); 2765 connection_.GetSendAlarm()->Fire();
2801 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2766 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2802 } 2767 }
2803 2768
2804 TEST_P(QuicConnectionTest, SendSchedulerDelayThenRetransmit) { 2769 TEST_P(QuicConnectionTest, SendSchedulerDelayThenRetransmit) {
2805 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) 2770 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
2806 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); 2771 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero()));
2807 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _)); 2772 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 1, _, _));
2808 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); 2773 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL);
2809 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2774 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2810 // Advance the time for retransmission of lost packet. 2775 // Advance the time for retransmission of lost packet.
2811 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(501)); 2776 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(501));
2812 // Test that if we send a retransmit with a delay, it ends up queued in the 2777 // Test that if we send a retransmit with a delay, it ends up queued in the
2813 // sent packet manager, but not yet serialized. 2778 // sent packet manager, but not yet serialized.
2814 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2779 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2815 EXPECT_CALL(*send_algorithm_, 2780 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
2816 TimeUntilSend(_, _)).WillOnce( 2781 .WillOnce(testing::Return(QuicTime::Delta::FromMicroseconds(1)));
2817 testing::Return(QuicTime::Delta::FromMicroseconds(1)));
2818 connection_.GetRetransmissionAlarm()->Fire(); 2782 connection_.GetRetransmissionAlarm()->Fire();
2819 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2783 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2820 2784
2821 // Advance the clock to fire the alarm, and configure the scheduler 2785 // Advance the clock to fire the alarm, and configure the scheduler
2822 // to permit the packet to be sent. 2786 // to permit the packet to be sent.
2823 EXPECT_CALL(*send_algorithm_, 2787 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)).Times(3).WillRepeatedly(
2824 TimeUntilSend(_, _)).Times(3). 2788 testing::Return(QuicTime::Delta::Zero()));
2825 WillRepeatedly(testing::Return(QuicTime::Delta::Zero()));
2826 2789
2827 // Ensure the scheduler is notified this is a retransmit. 2790 // Ensure the scheduler is notified this is a retransmit.
2828 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)); 2791 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _));
2829 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); 2792 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1));
2830 connection_.GetSendAlarm()->Fire(); 2793 connection_.GetSendAlarm()->Fire();
2831 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2794 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2832 } 2795 }
2833 2796
2834 TEST_P(QuicConnectionTest, SendSchedulerDelayAndQueue) { 2797 TEST_P(QuicConnectionTest, SendSchedulerDelayAndQueue) {
2835 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2798 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2836 EXPECT_CALL(*send_algorithm_, 2799 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
2837 TimeUntilSend(_, _)).WillOnce( 2800 .WillOnce(testing::Return(QuicTime::Delta::FromMicroseconds(1)));
2838 testing::Return(QuicTime::Delta::FromMicroseconds(1)));
2839 connection_.SendPacket( 2801 connection_.SendPacket(
2840 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2802 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2841 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2803 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2842 2804
2843 // Attempt to send another packet and make sure that it gets queued. 2805 // Attempt to send another packet and make sure that it gets queued.
2844 packet = ConstructDataPacket(2, 0, !kEntropyFlag); 2806 packet = ConstructDataPacket(2, 0, !kEntropyFlag);
2845 connection_.SendPacket( 2807 connection_.SendPacket(
2846 ENCRYPTION_NONE, 2, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2808 ENCRYPTION_NONE, 2, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2847 EXPECT_EQ(2u, connection_.NumQueuedPackets()); 2809 EXPECT_EQ(2u, connection_.NumQueuedPackets());
2848 } 2810 }
2849 2811
2850 TEST_P(QuicConnectionTest, SendSchedulerDelayThenAckAndSend) { 2812 TEST_P(QuicConnectionTest, SendSchedulerDelayThenAckAndSend) {
2851 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2813 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2852 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2814 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2853 EXPECT_CALL(*send_algorithm_, 2815 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
2854 TimeUntilSend(_, _)).WillOnce( 2816 .WillOnce(testing::Return(QuicTime::Delta::FromMicroseconds(10)));
2855 testing::Return(QuicTime::Delta::FromMicroseconds(10)));
2856 connection_.SendPacket( 2817 connection_.SendPacket(
2857 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2818 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2858 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2819 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2859 2820
2860 // Now send non-retransmitting information, that we're not going to 2821 // Now send non-retransmitting information, that we're not going to
2861 // retransmit 3. The far end should stop waiting for it. 2822 // retransmit 3. The far end should stop waiting for it.
2862 QuicAckFrame frame = InitAckFrame(0, 1); 2823 QuicAckFrame frame = InitAckFrame(0, 1);
2863 EXPECT_CALL(*send_algorithm_, 2824 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
2864 TimeUntilSend(_, _)).WillRepeatedly( 2825 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero()));
2865 testing::Return(QuicTime::Delta::Zero())); 2826 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _));
2866 EXPECT_CALL(*send_algorithm_,
2867 OnPacketSent(_, _, _, _));
2868 ProcessAckPacket(&frame); 2827 ProcessAckPacket(&frame);
2869 2828
2870 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2829 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2871 // Ensure alarm is not set 2830 // Ensure alarm is not set
2872 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet()); 2831 EXPECT_FALSE(connection_.GetSendAlarm()->IsSet());
2873 } 2832 }
2874 2833
2875 TEST_P(QuicConnectionTest, SendSchedulerDelayThenAckAndHold) { 2834 TEST_P(QuicConnectionTest, SendSchedulerDelayThenAckAndHold) {
2876 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2835 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2877 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2836 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2878 EXPECT_CALL(*send_algorithm_, 2837 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
2879 TimeUntilSend(_, _)).WillOnce( 2838 .WillOnce(testing::Return(QuicTime::Delta::FromMicroseconds(10)));
2880 testing::Return(QuicTime::Delta::FromMicroseconds(10)));
2881 connection_.SendPacket( 2839 connection_.SendPacket(
2882 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2840 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2883 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2841 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2884 2842
2885 // Now send non-retransmitting information, that we're not going to 2843 // Now send non-retransmitting information, that we're not going to
2886 // retransmit 3. The far end should stop waiting for it. 2844 // retransmit 3. The far end should stop waiting for it.
2887 QuicAckFrame frame = InitAckFrame(0, 1); 2845 QuicAckFrame frame = InitAckFrame(0, 1);
2888 EXPECT_CALL(*send_algorithm_, 2846 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
2889 TimeUntilSend(_, _)).WillOnce( 2847 .WillOnce(testing::Return(QuicTime::Delta::FromMicroseconds(1)));
2890 testing::Return(QuicTime::Delta::FromMicroseconds(1)));
2891 ProcessAckPacket(&frame); 2848 ProcessAckPacket(&frame);
2892 2849
2893 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2850 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2894 } 2851 }
2895 2852
2896 TEST_P(QuicConnectionTest, SendSchedulerDelayThenOnCanWrite) { 2853 TEST_P(QuicConnectionTest, SendSchedulerDelayThenOnCanWrite) {
2897 // TODO(ianswett): This test is unrealistic, because we would not serialize 2854 // TODO(ianswett): This test is unrealistic, because we would not serialize
2898 // new data if the send algorithm said not to. 2855 // new data if the send algorithm said not to.
2899 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); 2856 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag);
2900 EXPECT_CALL(*send_algorithm_, 2857 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
2901 TimeUntilSend(_, _)).WillOnce( 2858 .WillOnce(testing::Return(QuicTime::Delta::FromMicroseconds(10)));
2902 testing::Return(QuicTime::Delta::FromMicroseconds(10)));
2903 connection_.SendPacket( 2859 connection_.SendPacket(
2904 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2860 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2905 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2861 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2906 2862
2907 // OnCanWrite should send the packet, because it won't consult the send 2863 // OnCanWrite should send the packet, because it won't consult the send
2908 // algorithm for queued packets. 2864 // algorithm for queued packets.
2909 connection_.OnCanWrite(); 2865 connection_.OnCanWrite();
2910 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2866 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2911 } 2867 }
2912 2868
2913 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { 2869 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) {
2914 // All packets carry version info till version is negotiated. 2870 // All packets carry version info till version is negotiated.
2915 size_t payload_length; 2871 size_t payload_length;
2916 connection_.options()->max_packet_length = 2872 connection_.options()->max_packet_length =
2917 GetPacketLengthForOneStream( 2873 GetPacketLengthForOneStream(connection_.version(),
2918 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, 2874 kIncludeVersion,
2919 NOT_IN_FEC_GROUP, &payload_length); 2875 PACKET_1BYTE_SEQUENCE_NUMBER,
2876 NOT_IN_FEC_GROUP,
2877 &payload_length);
2920 2878
2921 // Queue the first packet. 2879 // Queue the first packet.
2922 EXPECT_CALL(*send_algorithm_, 2880 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
2923 TimeUntilSend(_, _)).WillOnce( 2881 .WillOnce(testing::Return(QuicTime::Delta::FromMicroseconds(10)));
2924 testing::Return(QuicTime::Delta::FromMicroseconds(10)));
2925 const string payload(payload_length, 'a'); 2882 const string payload(payload_length, 'a');
2926 EXPECT_EQ(0u, 2883 EXPECT_EQ(0u,
2927 connection_.SendStreamDataWithString(3, payload, 0, 2884 connection_.SendStreamDataWithString(3, payload, 0, !kFin, NULL)
2928 !kFin, NULL).bytes_consumed); 2885 .bytes_consumed);
2929 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2886 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2930 } 2887 }
2931 2888
2932 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { 2889 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) {
2933 // All packets carry version info till version is negotiated. 2890 // All packets carry version info till version is negotiated.
2934 size_t payload_length; 2891 size_t payload_length;
2935 connection_.options()->max_packet_length = 2892 connection_.options()->max_packet_length =
2936 GetPacketLengthForOneStream( 2893 GetPacketLengthForOneStream(connection_.version(),
2937 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, 2894 kIncludeVersion,
2938 NOT_IN_FEC_GROUP, &payload_length); 2895 PACKET_1BYTE_SEQUENCE_NUMBER,
2896 NOT_IN_FEC_GROUP,
2897 &payload_length);
2939 2898
2940 // Queue the first packet. 2899 // Queue the first packet.
2941 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(7); 2900 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(7);
2942 // The first stream frame will consume 2 fewer bytes than the other six. 2901 // The first stream frame will consume 2 fewer bytes than the other six.
2943 const string payload(payload_length * 7 - 12, 'a'); 2902 const string payload(payload_length * 7 - 12, 'a');
2944 EXPECT_EQ(payload.size(), 2903 EXPECT_EQ(payload.size(),
2945 connection_.SendStreamDataWithString(1, payload, 0, 2904 connection_.SendStreamDataWithString(1, payload, 0, !kFin, NULL)
2946 !kFin, NULL).bytes_consumed); 2905 .bytes_consumed);
2947 } 2906 }
2948 2907
2949 TEST_P(QuicConnectionTest, SendDelayedAck) { 2908 TEST_P(QuicConnectionTest, SendDelayedAck) {
2950 QuicTime ack_time = clock_.ApproximateNow().Add(DefaultDelayedAckTime()); 2909 QuicTime ack_time = clock_.ApproximateNow().Add(DefaultDelayedAckTime());
2951 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2910 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2952 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 2911 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
2953 const uint8 tag = 0x07; 2912 const uint8 tag = 0x07;
2954 connection_.SetDecrypter(new StrictTaggingDecrypter(tag), 2913 connection_.SetDecrypter(new StrictTaggingDecrypter(tag), ENCRYPTION_INITIAL);
2955 ENCRYPTION_INITIAL);
2956 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 2914 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
2957 // Process a packet from the non-crypto stream. 2915 // Process a packet from the non-crypto stream.
2958 frame1_.stream_id = 3; 2916 frame1_.stream_id = 3;
2959 2917
2960 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used 2918 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used
2961 // instead of ENCRYPTION_NONE. 2919 // instead of ENCRYPTION_NONE.
2962 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 2920 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1);
2963 ProcessDataPacketAtLevel(1, 0, !kEntropyFlag, ENCRYPTION_INITIAL); 2921 ProcessDataPacketAtLevel(1, 0, !kEntropyFlag, ENCRYPTION_INITIAL);
2964 2922
2965 // Check if delayed ack timer is running for the expected interval. 2923 // Check if delayed ack timer is running for the expected interval.
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
3100 // Check that no packet is sent and the ack alarm isn't set. 3058 // Check that no packet is sent and the ack alarm isn't set.
3101 EXPECT_EQ(0u, writer_->frame_count()); 3059 EXPECT_EQ(0u, writer_->frame_count());
3102 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3060 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3103 writer_->Reset(); 3061 writer_->Reset();
3104 3062
3105 // Send the same ack, but send both data and an ack together. 3063 // Send the same ack, but send both data and an ack together.
3106 ack = InitAckFrame(3, 0); 3064 ack = InitAckFrame(3, 0);
3107 NackPacket(1, &ack); 3065 NackPacket(1, &ack);
3108 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 3066 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
3109 .WillOnce(Return(SequenceNumberSet())); 3067 .WillOnce(Return(SequenceNumberSet()));
3110 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce( 3068 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(IgnoreResult(InvokeWithoutArgs(
3111 IgnoreResult(InvokeWithoutArgs( 3069 &connection_, &TestConnection::EnsureWritableAndSendStreamData5)));
3112 &connection_,
3113 &TestConnection::EnsureWritableAndSendStreamData5)));
3114 ProcessAckPacket(&ack); 3070 ProcessAckPacket(&ack);
3115 3071
3116 // Check that ack is bundled with outgoing data and the delayed ack 3072 // Check that ack is bundled with outgoing data and the delayed ack
3117 // alarm is reset. 3073 // alarm is reset.
3118 if (version() > QUIC_VERSION_15) { 3074 if (version() > QUIC_VERSION_15) {
3119 EXPECT_EQ(3u, writer_->frame_count()); 3075 EXPECT_EQ(3u, writer_->frame_count());
3120 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); 3076 EXPECT_FALSE(writer_->stop_waiting_frames().empty());
3121 } else { 3077 } else {
3122 EXPECT_EQ(2u, writer_->frame_count()); 3078 EXPECT_EQ(2u, writer_->frame_count());
3123 } 3079 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
3182 TEST_P(QuicConnectionTest, Blocked) { 3138 TEST_P(QuicConnectionTest, Blocked) {
3183 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3139 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3184 3140
3185 QuicBlockedFrame blocked; 3141 QuicBlockedFrame blocked;
3186 blocked.stream_id = 3; 3142 blocked.stream_id = 3;
3187 EXPECT_CALL(visitor_, OnBlockedFrames(_)); 3143 EXPECT_CALL(visitor_, OnBlockedFrames(_));
3188 ProcessFramePacket(QuicFrame(&blocked)); 3144 ProcessFramePacket(QuicFrame(&blocked));
3189 } 3145 }
3190 3146
3191 TEST_P(QuicConnectionTest, InvalidPacket) { 3147 TEST_P(QuicConnectionTest, InvalidPacket) {
3192 EXPECT_CALL(visitor_, 3148 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false));
3193 OnConnectionClosed(QUIC_INVALID_PACKET_HEADER, false));
3194 QuicEncryptedPacket encrypted(NULL, 0); 3149 QuicEncryptedPacket encrypted(NULL, 0);
3195 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), encrypted); 3150 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), encrypted);
3196 // The connection close packet should have error details. 3151 // The connection close packet should have error details.
3197 ASSERT_FALSE(writer_->connection_close_frames().empty()); 3152 ASSERT_FALSE(writer_->connection_close_frames().empty());
3198 EXPECT_EQ("Unable to read public flags.", 3153 EXPECT_EQ("Unable to read public flags.",
3199 writer_->connection_close_frames()[0].error_details); 3154 writer_->connection_close_frames()[0].error_details);
3200 } 3155 }
3201 3156
3202 TEST_P(QuicConnectionTest, MissingPacketsBeforeLeastUnacked) { 3157 TEST_P(QuicConnectionTest, MissingPacketsBeforeLeastUnacked) {
3203 // Set the sequence number of the ack packet to be least unacked (4). 3158 // Set the sequence number of the ack packet to be least unacked (4).
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
3307 } 3262 }
3308 if (entropy_flag) { 3263 if (entropy_flag) {
3309 entropy[i] = entropy[i - 1] ^ (1 << (i % 8)); 3264 entropy[i] = entropy[i - 1] ^ (1 << (i % 8));
3310 } else { 3265 } else {
3311 entropy[i] = entropy[i - 1]; 3266 entropy[i] = entropy[i - 1];
3312 } 3267 }
3313 ProcessDataPacket(i, 1, entropy_flag); 3268 ProcessDataPacket(i, 1, entropy_flag);
3314 } 3269 }
3315 // Till 50 since 50th packet is not sent. 3270 // Till 50 since 50th packet is not sent.
3316 for (int i = 1; i < 50; ++i) { 3271 for (int i = 1; i < 50; ++i) {
3317 EXPECT_EQ(entropy[i], QuicConnectionPeer::ReceivedEntropyHash( 3272 EXPECT_EQ(entropy[i],
3318 &connection_, i)); 3273 QuicConnectionPeer::ReceivedEntropyHash(&connection_, i));
3319 } 3274 }
3320 } 3275 }
3321 3276
3322 TEST_P(QuicConnectionTest, CheckSentEntropyHash) { 3277 TEST_P(QuicConnectionTest, CheckSentEntropyHash) {
3323 creator_.set_sequence_number(1); 3278 creator_.set_sequence_number(1);
3324 SequenceNumberSet missing_packets; 3279 SequenceNumberSet missing_packets;
3325 QuicPacketEntropyHash entropy_hash = 0; 3280 QuicPacketEntropyHash entropy_hash = 0;
3326 QuicPacketSequenceNumber max_sequence_number = 51; 3281 QuicPacketSequenceNumber max_sequence_number = 51;
3327 for (QuicPacketSequenceNumber i = 1; i <= max_sequence_number; ++i) { 3282 for (QuicPacketSequenceNumber i = 1; i <= max_sequence_number; ++i) {
3328 bool is_missing = i % 10 != 0; 3283 bool is_missing = i % 10 != 0;
3329 bool entropy_flag = (i & (i - 1)) != 0; 3284 bool entropy_flag = (i & (i - 1)) != 0;
3330 QuicPacketEntropyHash packet_entropy_hash = 0; 3285 QuicPacketEntropyHash packet_entropy_hash = 0;
3331 if (entropy_flag) { 3286 if (entropy_flag) {
3332 packet_entropy_hash = 1 << (i % 8); 3287 packet_entropy_hash = 1 << (i % 8);
3333 } 3288 }
3334 QuicPacket* packet = ConstructDataPacket(i, 0, entropy_flag); 3289 QuicPacket* packet = ConstructDataPacket(i, 0, entropy_flag);
3335 connection_.SendPacket( 3290 connection_.SendPacket(ENCRYPTION_NONE,
3336 ENCRYPTION_NONE, i, packet, packet_entropy_hash, 3291 i,
3337 HAS_RETRANSMITTABLE_DATA); 3292 packet,
3293 packet_entropy_hash,
3294 HAS_RETRANSMITTABLE_DATA);
3338 3295
3339 if (is_missing) { 3296 if (is_missing) {
3340 missing_packets.insert(i); 3297 missing_packets.insert(i);
3341 continue; 3298 continue;
3342 } 3299 }
3343 3300
3344 entropy_hash ^= packet_entropy_hash; 3301 entropy_hash ^= packet_entropy_hash;
3345 } 3302 }
3346 EXPECT_TRUE(QuicConnectionPeer::IsValidEntropy( 3303 EXPECT_TRUE(QuicConnectionPeer::IsValidEntropy(
3347 &connection_, max_sequence_number, missing_packets, entropy_hash)) 3304 &connection_, max_sequence_number, missing_packets, entropy_hash))
3348 << ""; 3305 << "";
3349 } 3306 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
3456 connection_.set_is_server(true); 3413 connection_.set_is_server(true);
3457 BlockOnNextWrite(); 3414 BlockOnNextWrite();
3458 writer_->set_is_write_blocked_data_buffered(true); 3415 writer_->set_is_write_blocked_data_buffered(true);
3459 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 3416 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
3460 EXPECT_EQ(0u, writer_->last_packet_size()); 3417 EXPECT_EQ(0u, writer_->last_packet_size());
3461 EXPECT_FALSE(connection_.HasQueuedData()); 3418 EXPECT_FALSE(connection_.HasQueuedData());
3462 } 3419 }
3463 3420
3464 TEST_P(QuicConnectionTest, ClientHandlesVersionNegotiation) { 3421 TEST_P(QuicConnectionTest, ClientHandlesVersionNegotiation) {
3465 // Start out with some unsupported version. 3422 // Start out with some unsupported version.
3466 QuicConnectionPeer::GetFramer(&connection_)->set_version_for_tests( 3423 QuicConnectionPeer::GetFramer(&connection_)
3467 QUIC_VERSION_UNSUPPORTED); 3424 ->set_version_for_tests(QUIC_VERSION_UNSUPPORTED);
3468 3425
3469 QuicPacketHeader header; 3426 QuicPacketHeader header;
3470 header.public_header.connection_id = connection_id_; 3427 header.public_header.connection_id = connection_id_;
3471 header.public_header.reset_flag = false; 3428 header.public_header.reset_flag = false;
3472 header.public_header.version_flag = true; 3429 header.public_header.version_flag = true;
3473 header.entropy_flag = false; 3430 header.entropy_flag = false;
3474 header.fec_flag = false; 3431 header.fec_flag = false;
3475 header.packet_sequence_number = 12; 3432 header.packet_sequence_number = 12;
3476 header.fec_group = 0; 3433 header.fec_group = 0;
3477 3434
3478 QuicVersionVector supported_versions; 3435 QuicVersionVector supported_versions;
3479 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { 3436 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) {
3480 supported_versions.push_back(kSupportedQuicVersions[i]); 3437 supported_versions.push_back(kSupportedQuicVersions[i]);
3481 } 3438 }
3482 3439
3483 // Send a version negotiation packet. 3440 // Send a version negotiation packet.
3484 scoped_ptr<QuicEncryptedPacket> encrypted( 3441 scoped_ptr<QuicEncryptedPacket> encrypted(
3485 framer_.BuildVersionNegotiationPacket( 3442 framer_.BuildVersionNegotiationPacket(header.public_header,
3486 header.public_header, supported_versions)); 3443 supported_versions));
3487 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 3444 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
3488 3445
3489 // Now force another packet. The connection should transition into 3446 // Now force another packet. The connection should transition into
3490 // NEGOTIATED_VERSION state and tell the packet creator to StopSendingVersion. 3447 // NEGOTIATED_VERSION state and tell the packet creator to StopSendingVersion.
3491 header.public_header.version_flag = false; 3448 header.public_header.version_flag = false;
3492 QuicFrames frames; 3449 QuicFrames frames;
3493 QuicFrame frame(&frame1_); 3450 QuicFrame frame(&frame1_);
3494 frames.push_back(frame); 3451 frames.push_back(frame);
3495 scoped_ptr<QuicPacket> packet( 3452 scoped_ptr<QuicPacket> packet(
3496 framer_.BuildUnsizedDataPacket(header, frames).packet); 3453 framer_.BuildUnsizedDataPacket(header, frames).packet);
(...skipping 16 matching lines...) Expand all
3513 header.packet_sequence_number = 12; 3470 header.packet_sequence_number = 12;
3514 header.fec_group = 0; 3471 header.fec_group = 0;
3515 3472
3516 QuicVersionVector supported_versions; 3473 QuicVersionVector supported_versions;
3517 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { 3474 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) {
3518 supported_versions.push_back(kSupportedQuicVersions[i]); 3475 supported_versions.push_back(kSupportedQuicVersions[i]);
3519 } 3476 }
3520 3477
3521 // Send a version negotiation packet with the version the client started with. 3478 // Send a version negotiation packet with the version the client started with.
3522 // It should be rejected. 3479 // It should be rejected.
3523 EXPECT_CALL(visitor_, 3480 EXPECT_CALL(
3524 OnConnectionClosed(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, 3481 visitor_,
3525 false)); 3482 OnConnectionClosed(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, false));
3526 scoped_ptr<QuicEncryptedPacket> encrypted( 3483 scoped_ptr<QuicEncryptedPacket> encrypted(
3527 framer_.BuildVersionNegotiationPacket( 3484 framer_.BuildVersionNegotiationPacket(header.public_header,
3528 header.public_header, supported_versions)); 3485 supported_versions));
3529 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 3486 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
3530 } 3487 }
3531 3488
3532 TEST_P(QuicConnectionTest, CheckSendStats) { 3489 TEST_P(QuicConnectionTest, CheckSendStats) {
3533 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)); 3490 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _));
3534 connection_.SendStreamDataWithString(3, "first", 0, !kFin, NULL); 3491 connection_.SendStreamDataWithString(3, "first", 0, !kFin, NULL);
3535 size_t first_packet_size = writer_->last_packet_size(); 3492 size_t first_packet_size = writer_->last_packet_size();
3536 3493
3537 EXPECT_CALL(*send_algorithm_, 3494 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _));
3538 OnPacketSent(_, _, _, _));
3539 connection_.SendStreamDataWithString(5, "second", 0, !kFin, NULL); 3495 connection_.SendStreamDataWithString(5, "second", 0, !kFin, NULL);
3540 size_t second_packet_size = writer_->last_packet_size(); 3496 size_t second_packet_size = writer_->last_packet_size();
3541 3497
3542 // 2 retransmissions due to rto, 1 due to explicit nack. 3498 // 2 retransmissions due to rto, 1 due to explicit nack.
3543 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 3499 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
3544 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(3); 3500 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _)).Times(3);
3545 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(1); 3501 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(_, _)).Times(1);
3546 3502
3547 // Retransmit due to RTO. 3503 // Retransmit due to RTO.
3548 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); 3504 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10));
3549 connection_.GetRetransmissionAlarm()->Fire(); 3505 connection_.GetRetransmissionAlarm()->Fire();
3550 3506
3551 // Retransmit due to explicit nacks. 3507 // Retransmit due to explicit nacks.
3552 QuicAckFrame nack_three = InitAckFrame(4, 0); 3508 QuicAckFrame nack_three = InitAckFrame(4, 0);
3553 NackPacket(3, &nack_three); 3509 NackPacket(3, &nack_three);
3554 NackPacket(1, &nack_three); 3510 NackPacket(1, &nack_three);
3555 SequenceNumberSet lost_packets; 3511 SequenceNumberSet lost_packets;
3556 lost_packets.insert(1); 3512 lost_packets.insert(1);
3557 lost_packets.insert(3); 3513 lost_packets.insert(3);
3558 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 3514 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
3559 .WillOnce(Return(lost_packets)); 3515 .WillOnce(Return(lost_packets));
3560 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_)); 3516 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_));
3561 EXPECT_CALL(*send_algorithm_, OnPacketAcked(4, _)).Times(1); 3517 EXPECT_CALL(*send_algorithm_, OnPacketAcked(4, _)).Times(1);
3562 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(2); 3518 EXPECT_CALL(*send_algorithm_, OnPacketLost(_, _)).Times(2);
3563 EXPECT_CALL(visitor_, OnCanWrite()).Times(2); 3519 EXPECT_CALL(visitor_, OnCanWrite()).Times(2);
3564 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3520 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3565 ProcessAckPacket(&nack_three); 3521 ProcessAckPacket(&nack_three);
3566 3522
3567 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce( 3523 EXPECT_CALL(*send_algorithm_, BandwidthEstimate())
3568 Return(QuicBandwidth::Zero())); 3524 .WillOnce(Return(QuicBandwidth::Zero()));
3569 3525
3570 const QuicConnectionStats& stats = connection_.GetStats(); 3526 const QuicConnectionStats& stats = connection_.GetStats();
3571 EXPECT_EQ(3 * first_packet_size + 2 * second_packet_size - kQuicVersionSize, 3527 EXPECT_EQ(3 * first_packet_size + 2 * second_packet_size - kQuicVersionSize,
3572 stats.bytes_sent); 3528 stats.bytes_sent);
3573 EXPECT_EQ(5u, stats.packets_sent); 3529 EXPECT_EQ(5u, stats.packets_sent);
3574 EXPECT_EQ(2 * first_packet_size + second_packet_size - kQuicVersionSize, 3530 EXPECT_EQ(2 * first_packet_size + second_packet_size - kQuicVersionSize,
3575 stats.bytes_retransmitted); 3531 stats.bytes_retransmitted);
3576 EXPECT_EQ(3u, stats.packets_retransmitted); 3532 EXPECT_EQ(3u, stats.packets_retransmitted);
3577 EXPECT_EQ(1u, stats.rto_count); 3533 EXPECT_EQ(1u, stats.rto_count);
3578 } 3534 }
3579 3535
3580 TEST_P(QuicConnectionTest, CheckReceiveStats) { 3536 TEST_P(QuicConnectionTest, CheckReceiveStats) {
3581 if (version() < QUIC_VERSION_15) { 3537 if (version() < QUIC_VERSION_15) {
3582 return; 3538 return;
3583 } 3539 }
3584 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3540 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3585 3541
3586 size_t received_bytes = 0; 3542 size_t received_bytes = 0;
3587 received_bytes += ProcessFecProtectedPacket(1, false, !kEntropyFlag); 3543 received_bytes += ProcessFecProtectedPacket(1, false, !kEntropyFlag);
3588 received_bytes += ProcessFecProtectedPacket(3, false, !kEntropyFlag); 3544 received_bytes += ProcessFecProtectedPacket(3, false, !kEntropyFlag);
3589 // Should be counted against dropped packets. 3545 // Should be counted against dropped packets.
3590 received_bytes += ProcessDataPacket(3, 1, !kEntropyFlag); 3546 received_bytes += ProcessDataPacket(3, 1, !kEntropyFlag);
3591 received_bytes += ProcessFecPacket(4, 1, true, !kEntropyFlag, NULL); 3547 received_bytes += ProcessFecPacket(4, 1, true, !kEntropyFlag, NULL);
3592 3548
3593 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce( 3549 EXPECT_CALL(*send_algorithm_, BandwidthEstimate())
3594 Return(QuicBandwidth::Zero())); 3550 .WillOnce(Return(QuicBandwidth::Zero()));
3595 3551
3596 const QuicConnectionStats& stats = connection_.GetStats(); 3552 const QuicConnectionStats& stats = connection_.GetStats();
3597 EXPECT_EQ(received_bytes, stats.bytes_received); 3553 EXPECT_EQ(received_bytes, stats.bytes_received);
3598 EXPECT_EQ(4u, stats.packets_received); 3554 EXPECT_EQ(4u, stats.packets_received);
3599 3555
3600 EXPECT_EQ(1u, stats.packets_revived); 3556 EXPECT_EQ(1u, stats.packets_revived);
3601 EXPECT_EQ(1u, stats.packets_dropped); 3557 EXPECT_EQ(1u, stats.packets_dropped);
3602 } 3558 }
3603 3559
3604 TEST_P(QuicConnectionTest, TestFecGroupLimits) { 3560 TEST_P(QuicConnectionTest, TestFecGroupLimits) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3637 qccf.error_code = QUIC_PEER_GOING_AWAY; 3593 qccf.error_code = QUIC_PEER_GOING_AWAY;
3638 QuicFrame close_frame(&qccf); 3594 QuicFrame close_frame(&qccf);
3639 QuicFrame stream_frame(&frame1_); 3595 QuicFrame stream_frame(&frame1_);
3640 3596
3641 QuicFrames frames; 3597 QuicFrames frames;
3642 frames.push_back(stream_frame); 3598 frames.push_back(stream_frame);
3643 frames.push_back(close_frame); 3599 frames.push_back(close_frame);
3644 scoped_ptr<QuicPacket> packet( 3600 scoped_ptr<QuicPacket> packet(
3645 framer_.BuildUnsizedDataPacket(header_, frames).packet); 3601 framer_.BuildUnsizedDataPacket(header_, frames).packet);
3646 EXPECT_TRUE(NULL != packet.get()); 3602 EXPECT_TRUE(NULL != packet.get());
3647 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket( 3603 scoped_ptr<QuicEncryptedPacket> encrypted(
3648 ENCRYPTION_NONE, 1, *packet)); 3604 framer_.EncryptPacket(ENCRYPTION_NONE, 1, *packet));
3649 3605
3650 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, true)); 3606 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, true));
3651 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 3607 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1);
3652 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3608 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3653 3609
3654 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 3610 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
3655 } 3611 }
3656 3612
3657 TEST_P(QuicConnectionTest, SelectMutualVersion) { 3613 TEST_P(QuicConnectionTest, SelectMutualVersion) {
3658 connection_.SetSupportedVersions(QuicSupportedVersions()); 3614 connection_.SetSupportedVersions(QuicSupportedVersions());
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
3801 // AckNotifierCallback is triggered by the ack of a packet that timed 3757 // AckNotifierCallback is triggered by the ack of a packet that timed
3802 // out and was retransmitted, even though the retransmission has a 3758 // out and was retransmitted, even though the retransmission has a
3803 // different sequence number. 3759 // different sequence number.
3804 TEST_P(QuicConnectionTest, AckNotifierCallbackForAckAfterRTO) { 3760 TEST_P(QuicConnectionTest, AckNotifierCallbackForAckAfterRTO) {
3805 InSequence s; 3761 InSequence s;
3806 3762
3807 // Create a delegate which we expect to be called. 3763 // Create a delegate which we expect to be called.
3808 scoped_refptr<MockAckNotifierDelegate> delegate( 3764 scoped_refptr<MockAckNotifierDelegate> delegate(
3809 new StrictMock<MockAckNotifierDelegate>); 3765 new StrictMock<MockAckNotifierDelegate>);
3810 3766
3811 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( 3767 QuicTime default_retransmission_time =
3812 DefaultRetransmissionTime()); 3768 clock_.ApproximateNow().Add(DefaultRetransmissionTime());
3813 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, delegate.get()); 3769 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, delegate.get());
3814 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked); 3770 EXPECT_EQ(1u, outgoing_ack()->sent_info.least_unacked);
3815 3771
3816 EXPECT_EQ(1u, writer_->header().packet_sequence_number); 3772 EXPECT_EQ(1u, writer_->header().packet_sequence_number);
3817 EXPECT_EQ(default_retransmission_time, 3773 EXPECT_EQ(default_retransmission_time,
3818 connection_.GetRetransmissionAlarm()->deadline()); 3774 connection_.GetRetransmissionAlarm()->deadline());
3819 // Simulate the retransmission alarm firing. 3775 // Simulate the retransmission alarm firing.
3820 clock_.AdvanceTime(DefaultRetransmissionTime()); 3776 clock_.AdvanceTime(DefaultRetransmissionTime());
3821 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 3777 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
3822 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 2u, _, _)); 3778 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, 2u, _, _));
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
3890 ProcessAckPacket(&third_ack_frame); 3846 ProcessAckPacket(&third_ack_frame);
3891 } 3847 }
3892 3848
3893 TEST_P(QuicConnectionTest, AckNotifierFECTriggerCallback) { 3849 TEST_P(QuicConnectionTest, AckNotifierFECTriggerCallback) {
3894 if (version() < QUIC_VERSION_15) { 3850 if (version() < QUIC_VERSION_15) {
3895 return; 3851 return;
3896 } 3852 }
3897 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3853 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3898 3854
3899 // Create a delegate which we expect to be called. 3855 // Create a delegate which we expect to be called.
3900 scoped_refptr<MockAckNotifierDelegate> delegate( 3856 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate);
3901 new MockAckNotifierDelegate);
3902 EXPECT_CALL(*delegate, OnAckNotification(_, _, _, _, _)).Times(1); 3857 EXPECT_CALL(*delegate, OnAckNotification(_, _, _, _, _)).Times(1);
3903 3858
3904 // Send some data, which will register the delegate to be notified. 3859 // Send some data, which will register the delegate to be notified.
3905 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); 3860 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get());
3906 connection_.SendStreamDataWithString(2, "bar", 0, !kFin, NULL); 3861 connection_.SendStreamDataWithString(2, "bar", 0, !kFin, NULL);
3907 3862
3908 // Process an ACK from the server with a revived packet, which should trigger 3863 // Process an ACK from the server with a revived packet, which should trigger
3909 // the callback. 3864 // the callback.
3910 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_)); 3865 EXPECT_CALL(*send_algorithm_, OnRttUpdated(_));
3911 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1); 3866 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3959 framer_.BuildUnsizedDataPacket(ack_header, frames).packet; 3914 framer_.BuildUnsizedDataPacket(ack_header, frames).packet;
3960 3915
3961 // Take the packet which contains the ACK frame, and construct and deliver an 3916 // Take the packet which contains the ACK frame, and construct and deliver an
3962 // FEC packet which allows the ACK packet to be recovered. 3917 // FEC packet which allows the ACK packet to be recovered.
3963 ProcessFecPacket(2, 1, true, !kEntropyFlag, packet); 3918 ProcessFecPacket(2, 1, true, !kEntropyFlag, packet);
3964 } 3919 }
3965 3920
3966 class MockQuicConnectionDebugVisitor 3921 class MockQuicConnectionDebugVisitor
3967 : public QuicConnectionDebugVisitorInterface { 3922 : public QuicConnectionDebugVisitorInterface {
3968 public: 3923 public:
3969 MOCK_METHOD1(OnFrameAddedToPacket, 3924 MOCK_METHOD1(OnFrameAddedToPacket, void(const QuicFrame&));
3970 void(const QuicFrame&));
3971 3925
3972 MOCK_METHOD5(OnPacketSent, 3926 MOCK_METHOD5(OnPacketSent,
3973 void(QuicPacketSequenceNumber, 3927 void(QuicPacketSequenceNumber,
3974 EncryptionLevel, 3928 EncryptionLevel,
3975 TransmissionType, 3929 TransmissionType,
3976 const QuicEncryptedPacket&, 3930 const QuicEncryptedPacket&,
3977 WriteResult)); 3931 WriteResult));
3978 3932
3979 MOCK_METHOD2(OnPacketRetransmitted, 3933 MOCK_METHOD2(OnPacketRetransmitted,
3980 void(QuicPacketSequenceNumber, 3934 void(QuicPacketSequenceNumber, QuicPacketSequenceNumber));
3981 QuicPacketSequenceNumber));
3982 3935
3983 MOCK_METHOD3(OnPacketReceived, 3936 MOCK_METHOD3(OnPacketReceived,
3984 void(const IPEndPoint&, 3937 void(const IPEndPoint&,
3985 const IPEndPoint&, 3938 const IPEndPoint&,
3986 const QuicEncryptedPacket&)); 3939 const QuicEncryptedPacket&));
3987 3940
3988 MOCK_METHOD1(OnProtocolVersionMismatch, 3941 MOCK_METHOD1(OnProtocolVersionMismatch, void(QuicVersion));
3989 void(QuicVersion));
3990 3942
3991 MOCK_METHOD1(OnPacketHeader, 3943 MOCK_METHOD1(OnPacketHeader, void(const QuicPacketHeader& header));
3992 void(const QuicPacketHeader& header));
3993 3944
3994 MOCK_METHOD1(OnStreamFrame, 3945 MOCK_METHOD1(OnStreamFrame, void(const QuicStreamFrame&));
3995 void(const QuicStreamFrame&));
3996 3946
3997 MOCK_METHOD1(OnAckFrame, 3947 MOCK_METHOD1(OnAckFrame, void(const QuicAckFrame& frame));
3998 void(const QuicAckFrame& frame));
3999 3948
4000 MOCK_METHOD1(OnCongestionFeedbackFrame, 3949 MOCK_METHOD1(OnCongestionFeedbackFrame,
4001 void(const QuicCongestionFeedbackFrame&)); 3950 void(const QuicCongestionFeedbackFrame&));
4002 3951
4003 MOCK_METHOD1(OnStopWaitingFrame, 3952 MOCK_METHOD1(OnStopWaitingFrame, void(const QuicStopWaitingFrame&));
4004 void(const QuicStopWaitingFrame&));
4005 3953
4006 MOCK_METHOD1(OnRstStreamFrame, 3954 MOCK_METHOD1(OnRstStreamFrame, void(const QuicRstStreamFrame&));
4007 void(const QuicRstStreamFrame&));
4008 3955
4009 MOCK_METHOD1(OnConnectionCloseFrame, 3956 MOCK_METHOD1(OnConnectionCloseFrame, void(const QuicConnectionCloseFrame&));
4010 void(const QuicConnectionCloseFrame&));
4011 3957
4012 MOCK_METHOD1(OnPublicResetPacket, 3958 MOCK_METHOD1(OnPublicResetPacket, void(const QuicPublicResetPacket&));
4013 void(const QuicPublicResetPacket&));
4014 3959
4015 MOCK_METHOD1(OnVersionNegotiationPacket, 3960 MOCK_METHOD1(OnVersionNegotiationPacket,
4016 void(const QuicVersionNegotiationPacket&)); 3961 void(const QuicVersionNegotiationPacket&));
4017 3962
4018 MOCK_METHOD2(OnRevivedPacket, 3963 MOCK_METHOD2(OnRevivedPacket,
4019 void(const QuicPacketHeader&, StringPiece payload)); 3964 void(const QuicPacketHeader&, StringPiece payload));
4020 }; 3965 };
4021 3966
4022 TEST_P(QuicConnectionTest, OnPacketHeaderDebugVisitor) { 3967 TEST_P(QuicConnectionTest, OnPacketHeaderDebugVisitor) {
4023 QuicPacketHeader header; 3968 QuicPacketHeader header;
4024 3969
4025 scoped_ptr<MockQuicConnectionDebugVisitor> 3970 scoped_ptr<MockQuicConnectionDebugVisitor> debug_visitor(
4026 debug_visitor(new StrictMock<MockQuicConnectionDebugVisitor>); 3971 new StrictMock<MockQuicConnectionDebugVisitor>);
4027 connection_.set_debug_visitor(debug_visitor.get()); 3972 connection_.set_debug_visitor(debug_visitor.get());
4028 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); 3973 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1);
4029 connection_.OnPacketHeader(header); 3974 connection_.OnPacketHeader(header);
4030 } 3975 }
4031 3976
4032 TEST_P(QuicConnectionTest, Pacing) { 3977 TEST_P(QuicConnectionTest, Pacing) {
4033 ValueRestore<bool> old_flag(&FLAGS_enable_quic_pacing, true); 3978 ValueRestore<bool> old_flag(&FLAGS_enable_quic_pacing, true);
4034 3979
4035 TestConnection server(connection_id_, IPEndPoint(), helper_.get(), 3980 TestConnection server(connection_id_,
4036 writer_.get(), true, version(), 3981 IPEndPoint(),
3982 helper_.get(),
3983 writer_.get(),
3984 true,
3985 version(),
4037 kDefaultFlowControlSendWindow); 3986 kDefaultFlowControlSendWindow);
4038 TestConnection client(connection_id_, IPEndPoint(), helper_.get(), 3987 TestConnection client(connection_id_,
4039 writer_.get(), false, version(), 3988 IPEndPoint(),
3989 helper_.get(),
3990 writer_.get(),
3991 false,
3992 version(),
4040 kDefaultFlowControlSendWindow); 3993 kDefaultFlowControlSendWindow);
4041 EXPECT_TRUE(client.sent_packet_manager().using_pacing()); 3994 EXPECT_TRUE(client.sent_packet_manager().using_pacing());
4042 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); 3995 EXPECT_FALSE(server.sent_packet_manager().using_pacing());
4043 } 3996 }
4044 3997
4045 TEST_P(QuicConnectionTest, ControlFramesInstigateAcks) { 3998 TEST_P(QuicConnectionTest, ControlFramesInstigateAcks) {
4046 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3999 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4047 4000
4048 // Send a WINDOW_UPDATE frame. 4001 // Send a WINDOW_UPDATE frame.
4049 QuicWindowUpdateFrame window_update; 4002 QuicWindowUpdateFrame window_update;
(...skipping 12 matching lines...) Expand all
4062 blocked.stream_id = 3; 4015 blocked.stream_id = 3;
4063 EXPECT_CALL(visitor_, OnBlockedFrames(_)); 4016 EXPECT_CALL(visitor_, OnBlockedFrames(_));
4064 ProcessFramePacket(QuicFrame(&blocked)); 4017 ProcessFramePacket(QuicFrame(&blocked));
4065 EXPECT_TRUE(ack_alarm->IsSet()); 4018 EXPECT_TRUE(ack_alarm->IsSet());
4066 } 4019 }
4067 4020
4068 TEST_P(QuicConnectionTest, InvalidFlowControlWindow) { 4021 TEST_P(QuicConnectionTest, InvalidFlowControlWindow) {
4069 ValueRestore<bool> old_flag(&FLAGS_enable_quic_pacing, true); 4022 ValueRestore<bool> old_flag(&FLAGS_enable_quic_pacing, true);
4070 4023
4071 const uint32 kSmallerFlowControlWindow = kDefaultFlowControlSendWindow - 1; 4024 const uint32 kSmallerFlowControlWindow = kDefaultFlowControlSendWindow - 1;
4072 TestConnection connection(connection_id_, IPEndPoint(), helper_.get(), 4025 TestConnection connection(connection_id_,
4073 writer_.get(), true, version(), 4026 IPEndPoint(),
4027 helper_.get(),
4028 writer_.get(),
4029 true,
4030 version(),
4074 kSmallerFlowControlWindow); 4031 kSmallerFlowControlWindow);
4075 EXPECT_EQ(kDefaultFlowControlSendWindow, 4032 EXPECT_EQ(kDefaultFlowControlSendWindow,
4076 connection.max_flow_control_receive_window_bytes()); 4033 connection.max_flow_control_receive_window_bytes());
4077 } 4034 }
4078 4035
4079 } // namespace 4036 } // namespace
4080 } // namespace test 4037 } // namespace test
4081 } // namespace net 4038 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698