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

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

Issue 11125002: Add QuicFramer and friends. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix final comments. Created 8 years, 2 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
« no previous file with comments | « net/quic/quic_framer.cc ('k') | net/quic/quic_protocol.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <algorithm>
6 #include <vector>
7
8 #include "base/hash_tables.h"
9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/stl_util.h"
12 #include "net/quic/quic_framer.h"
13 #include "net/quic/quic_protocol.h"
14 #include "net/quic/quic_utils.h"
15 #include "net/quic/test_tools/quic_test_utils.h"
16
17 using base::hash_set;
18 using base::StringPiece;
19 using std::string;
20 using std::vector;
21
22 namespace net {
23
24 namespace test {
25
26 class TestEncrypter : public QuicEncrypter {
27 public:
28 virtual ~TestEncrypter() {}
29 virtual QuicData* Encrypt(StringPiece associated_data,
30 StringPiece plaintext) {
31 associated_data_ = associated_data.as_string();
32 plaintext_ = plaintext.as_string();
33 return new QuicData(plaintext.data(), plaintext.length());
34 }
35 virtual size_t GetMaxPlaintextSize(size_t ciphertext_size) {
36 return ciphertext_size;
37 }
38 virtual size_t GetCiphertextSize(size_t plaintext_size) {
39 return plaintext_size;
40 }
41 string associated_data_;
42 string plaintext_;
43 };
44
45 class TestDecrypter : public QuicDecrypter {
46 public:
47 virtual ~TestDecrypter() {}
48 virtual QuicData* Decrypt(StringPiece associated_data,
49 StringPiece ciphertext) {
50 associated_data_ = associated_data.as_string();
51 ciphertext_ = ciphertext.as_string();
52 return new QuicData(ciphertext.data(), ciphertext.length());
53 }
54 string associated_data_;
55 string ciphertext_;
56 };
57
58 // The offset of congestion info in our tests, given the size of our usual ack
59 // fragment. This does NOT work for all packets.
60 const int kCongestionInfoOffset = kPacketHeaderSize + 54;
61
62 class TestQuicVisitor : public ::net::QuicFramerVisitorInterface {
63 public:
64 TestQuicVisitor()
65 : error_count_(0),
66 packet_count_(0),
67 fragment_count_(0),
68 fec_count_(0),
69 complete_packets_(0),
70 accept_packet_(true) {
71 }
72
73 ~TestQuicVisitor() {
74 STLDeleteElements(&stream_fragments_);
75 STLDeleteElements(&ack_fragments_);
76 STLDeleteElements(&fec_data_);
77 }
78
79 virtual void OnError(QuicFramer* f) {
80 DLOG(INFO) << "QuicFramer Error: " << QuicUtils::ErrorToString(f->error())
81 << " (" << f->error() << ")";
82 error_count_++;
83 }
84
85 virtual void OnPacket(const IPEndPoint& client_address) {
86 address_ = client_address;
87 }
88
89 virtual bool OnPacketHeader(const QuicPacketHeader& header) {
90 packet_count_++;
91 header_.reset(new QuicPacketHeader(header));
92 return accept_packet_;
93 }
94
95 virtual void OnStreamFragment(const QuicStreamFragment& fragment) {
96 fragment_count_++;
97 stream_fragments_.push_back(new QuicStreamFragment(fragment));
98 }
99
100 virtual void OnFecProtectedPayload(StringPiece payload) {
101 fec_protected_payload_ = payload.as_string();
102 }
103
104 virtual void OnAckFragment(const QuicAckFragment& fragment) {
105 fragment_count_++;
106 ack_fragments_.push_back(new QuicAckFragment(fragment));
107 }
108
109 virtual void OnFecData(const QuicFecData& fec) {
110 fec_count_++;
111 fec_data_.push_back(new QuicFecData(fec));
112 }
113
114 virtual void OnPacketComplete() {
115 complete_packets_++;
116 }
117
118 virtual void OnRstStreamFragment(const QuicRstStreamFragment& fragment) {
119 rst_stream_fragment_ = fragment;
120 }
121
122 virtual void OnConnectionCloseFragment(
123 const QuicConnectionCloseFragment& fragment) {
124 connection_close_fragment_ = fragment;
125 }
126
127 // Counters from the visitor_ callbacks.
128 int error_count_;
129 int packet_count_;
130 int fragment_count_;
131 int fec_count_;
132 int complete_packets_;
133 bool accept_packet_;
134
135 IPEndPoint address_;
136 scoped_ptr<QuicPacketHeader> header_;
137 vector<QuicStreamFragment*> stream_fragments_;
138 vector<QuicAckFragment*> ack_fragments_;
139 vector<QuicFecData*> fec_data_;
140 string fec_protected_payload_;
141 QuicRstStreamFragment rst_stream_fragment_;
142 QuicConnectionCloseFragment connection_close_fragment_;
143 };
144
145 class QuicFramerTest : public ::testing::Test {
146 public:
147 QuicFramerTest()
148 : encrypter_(new test::TestEncrypter()),
149 decrypter_(new test::TestDecrypter()),
150 framer_(decrypter_, encrypter_) {
151 framer_.set_visitor(&visitor_);
152 }
153
154 bool CheckEncryption(StringPiece packet) {
155 StringPiece associated_data(
156 packet.substr(kStartOfHashData,
157 kStartOfEncryptedData - kStartOfHashData));
158 if (associated_data != encrypter_->associated_data_) {
159 LOG(ERROR) << "Encrypted incorrect associated data. expected "
160 << associated_data << " actual: "
161 << encrypter_->associated_data_;
162 return false;
163 }
164 StringPiece plaintext(packet.substr(kStartOfEncryptedData));
165 if (plaintext != encrypter_->plaintext_) {
166 LOG(ERROR) << "Encrypted incorrect plaintext data. expected "
167 << plaintext << " actual: "
168 << encrypter_->plaintext_;
169 return false;
170 }
171 return true;
172 }
173
174 bool CheckDecryption(StringPiece packet) {
175 StringPiece associated_data(
176 packet.substr(kStartOfHashData,
177 kStartOfEncryptedData - kStartOfHashData));
178 if (associated_data != decrypter_->associated_data_) {
179 LOG(ERROR) << "Decrypted incorrect associated data. expected "
180 << associated_data << " actual: "
181 << decrypter_->associated_data_;
182 return false;
183 }
184 StringPiece plaintext(packet.substr(kStartOfEncryptedData));
185 if (plaintext != decrypter_->ciphertext_) {
186 LOG(ERROR) << "Decrypted incorrect chipertext data. expected "
187 << plaintext << " actual: "
188 << decrypter_->ciphertext_;
189 return false;
190 }
191 return true;
192 }
193
194 char* AsChars(unsigned char* data) {
195 return reinterpret_cast<char*>(data);
196 }
197
198 test::TestEncrypter* encrypter_;
199 test::TestDecrypter* decrypter_;
200 QuicFramer framer_;
201 test::TestQuicVisitor visitor_;
202 IPEndPoint address_;
203 };
204
205 TEST_F(QuicFramerTest, EmptyPacket) {
206 char packet[] = { 0x00 };
207 EXPECT_FALSE(framer_.ProcessPacket(address_,
208 QuicEncryptedPacket(packet, 0, false)));
209 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error());
210 }
211
212 TEST_F(QuicFramerTest, LargePacket) {
213 unsigned char packet[kMaxPacketSize + 1] = {
214 // guid
215 0x10, 0x32, 0x54, 0x76,
216 0x98, 0xBA, 0xDC, 0xFE,
217 // packet id
218 0xBC, 0x9A, 0x78, 0x56,
219 0x34, 0x12,
220 // retransmission count
221 0x01,
222 // transmission time
223 0x87, 0x96, 0xA5, 0xB4,
224 0xC3, 0xD2, 0xE1, 0xF0,
225 // flags
226 0x00,
227 // fec group
228 0x00,
229 // fragment count
230 0x01,
231 };
232
233 memset(packet + kPacketHeaderSize, 0, kMaxPacketSize - kPacketHeaderSize + 1);
234
235 EXPECT_FALSE(framer_.ProcessPacket(
236 address_, QuicEncryptedPacket(AsChars(packet),
237 arraysize(packet), false)));
238
239 ASSERT_TRUE(visitor_.header_.get());
240 // Make sure we've parsed the packet header, so we can send an error.
241 EXPECT_EQ(0xFEDCBA9876543210, visitor_.header_->guid);
242 // Make sure the correct error is propogated.
243 EXPECT_EQ(QUIC_PACKET_TOO_LARGE, framer_.error());
244 }
245
246 TEST_F(QuicFramerTest, PacketHeader) {
247 unsigned char packet[] = {
248 // guid
249 0x10, 0x32, 0x54, 0x76,
250 0x98, 0xBA, 0xDC, 0xFE,
251 // packet id
252 0xBC, 0x9A, 0x78, 0x56,
253 0x34, 0x12,
254 // retransmission count
255 0x01,
256 // transmission time
257 0x87, 0x96, 0xA5, 0xB4,
258 0xC3, 0xD2, 0xE1, 0xF0,
259 // flags
260 0x00,
261 // fec group
262 0x00,
263 };
264
265 EXPECT_FALSE(framer_.ProcessPacket(
266 address_, QuicEncryptedPacket(AsChars(packet),
267 arraysize(packet), false)));
268
269 EXPECT_EQ(QUIC_INVALID_FRAGMENT_DATA, framer_.error());
270 ASSERT_TRUE(visitor_.header_.get());
271 EXPECT_EQ(0xFEDCBA9876543210, visitor_.header_->guid);
272 EXPECT_EQ(0x1, visitor_.header_->retransmission_count);
273 EXPECT_EQ(static_cast<uint64>(0x123456789ABC),
274 visitor_.header_->packet_sequence_number);
275 EXPECT_EQ(static_cast<uint64>(0xF0E1D2C3B4A59687),
276 visitor_.header_->transmission_time);
277 EXPECT_EQ(0x00, visitor_.header_->flags);
278 EXPECT_EQ(0x00, visitor_.header_->fec_group);
279
280 // Now test framing boundaries
281 for (int i = 0; i < 25; ++i) {
282 string expected_error;
283 if (i < 8) {
284 expected_error = "Unable to read GUID.";
285 } else if (i < 14) {
286 expected_error = "Unable to read sequence number.";
287 } else if (i < 15) {
288 expected_error = "Unable to read retransmission count.";
289 } else if (i < 23) {
290 expected_error = "Unable to read transmission time.";
291 } else if (i < 24) {
292 expected_error = "Unable to read flags.";
293 } else if (i < 25) {
294 expected_error = "Unable to read fec group.";
295 }
296
297 EXPECT_FALSE(framer_.ProcessPacket(
298 address_, QuicEncryptedPacket(AsChars(packet), i, false)));
299 EXPECT_EQ(expected_error, framer_.detailed_error());
300 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error());
301 }
302 }
303
304 TEST_F(QuicFramerTest, StreamFragment) {
305 unsigned char packet[] = {
306 // guid
307 0x10, 0x32, 0x54, 0x76,
308 0x98, 0xBA, 0xDC, 0xFE,
309 // packet id
310 0xBC, 0x9A, 0x78, 0x56,
311 0x34, 0x12,
312 // retransmission count
313 0x01,
314 // transmission time
315 0x87, 0x96, 0xA5, 0xB4,
316 0xC3, 0xD2, 0xE1, 0xF0,
317 // flags
318 0x00,
319 // fec group
320 0x00,
321
322 // fragment count
323 0x01,
324 // fragment type (stream fragment)
325 0x00,
326 // stream id
327 0x04, 0x03, 0x02, 0x01,
328 // fin
329 0x01,
330 // offset
331 0x54, 0x76, 0x10, 0x32,
332 0xDC, 0xFE, 0x98, 0xBA,
333 // data length
334 0x0c, 0x00,
335 // data
336 'h', 'e', 'l', 'l',
337 'o', ' ', 'w', 'o',
338 'r', 'l', 'd', '!',
339 };
340
341 EXPECT_TRUE(framer_.ProcessPacket(
342 address_, QuicEncryptedPacket(AsChars(packet),
343 arraysize(packet), false)));
344
345 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet))));
346 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
347 ASSERT_TRUE(visitor_.header_.get());
348 ASSERT_EQ(address_, visitor_.address_);
349
350 ASSERT_EQ(1u, visitor_.stream_fragments_.size());
351 EXPECT_EQ(0u, visitor_.ack_fragments_.size());
352 EXPECT_EQ(static_cast<uint64>(0x01020304),
353 visitor_.stream_fragments_[0]->stream_id);
354 EXPECT_TRUE(visitor_.stream_fragments_[0]->fin);
355 EXPECT_EQ(0xBA98FEDC32107654, visitor_.stream_fragments_[0]->offset);
356 EXPECT_EQ("hello world!", visitor_.stream_fragments_[0]->data);
357
358 // Now test framing boundaries
359 for (size_t i = kPacketHeaderSize; i < kPacketHeaderSize + 29; ++i) {
360 string expected_error;
361 if (i < kPacketHeaderSize + 1) {
362 expected_error = "Unable to read fragment count.";
363 } else if (i < kPacketHeaderSize + 2) {
364 expected_error = "Unable to read fragment type.";
365 } else if (i < kPacketHeaderSize + 6) {
366 expected_error = "Unable to read stream_id.";
367 } else if (i < kPacketHeaderSize + 7) {
368 expected_error = "Unable to read fin.";
369 } else if (i < kPacketHeaderSize + 15) {
370 expected_error = "Unable to read offset.";
371 } else if (i < kPacketHeaderSize + 29) {
372 expected_error = "Unable to read fragment data.";
373 }
374
375 EXPECT_FALSE(framer_.ProcessPacket(
376 address_, QuicEncryptedPacket(AsChars(packet), i, false)));
377 EXPECT_EQ(expected_error, framer_.detailed_error());
378 EXPECT_EQ(QUIC_INVALID_FRAGMENT_DATA, framer_.error());
379 }
380 }
381
382 TEST_F(QuicFramerTest, RejectPacket) {
383 visitor_.accept_packet_ = false;
384
385 unsigned char packet[] = {
386 // guid
387 0x10, 0x32, 0x54, 0x76,
388 0x98, 0xBA, 0xDC, 0xFE,
389 // packet id
390 0xBC, 0x9A, 0x78, 0x56,
391 0x34, 0x12,
392 // retransmission count
393 0x01,
394 // transmission time
395 0x87, 0x96, 0xA5, 0xB4,
396 0xC3, 0xD2, 0xE1, 0xF0,
397 // flags
398 0x00,
399 // fec group
400 0x00,
401
402 // fragment count
403 0x01,
404 // fragment type (stream fragment)
405 0x00,
406 // stream id
407 0x04, 0x03, 0x02, 0x01,
408 // fin
409 0x01,
410 // offset
411 0x54, 0x76, 0x10, 0x32,
412 0xDC, 0xFE, 0x98, 0xBA,
413 // data length
414 0x0c, 0x00,
415 // data
416 'h', 'e', 'l', 'l',
417 'o', ' ', 'w', 'o',
418 'r', 'l', 'd', '!',
419 };
420
421 EXPECT_TRUE(framer_.ProcessPacket(
422 address_, QuicEncryptedPacket(AsChars(packet),
423 arraysize(packet), false)));
424
425 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet))));
426 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
427 ASSERT_TRUE(visitor_.header_.get());
428 ASSERT_EQ(address_, visitor_.address_);
429
430 ASSERT_EQ(0u, visitor_.stream_fragments_.size());
431 EXPECT_EQ(0u, visitor_.ack_fragments_.size());
432 }
433
434 TEST_F(QuicFramerTest, RevivedStreamFragment) {
435 unsigned char payload[] = {
436 // fragment count
437 0x01,
438 // fragment type (stream fragment)
439 0x00,
440 // stream id
441 0x04, 0x03, 0x02, 0x01,
442 // fin
443 0x01,
444 // offset
445 0x54, 0x76, 0x10, 0x32,
446 0xDC, 0xFE, 0x98, 0xBA,
447 // data length
448 0x0c, 0x00,
449 // data
450 'h', 'e', 'l', 'l',
451 'o', ' ', 'w', 'o',
452 'r', 'l', 'd', '!',
453 };
454
455 QuicPacketHeader header;
456 header.guid = 0xFEDCBA9876543210;
457 header.retransmission_count = 0x01;
458 header.packet_sequence_number = 0x123456789ABC;
459 header.transmission_time = 0xF0E1D2C3B4A59687;
460 header.flags = PACKET_FLAGS_NONE;
461 header.fec_group = 0;
462
463 // Do not encrypt the payload because the revived payload is post-encryption.
464 EXPECT_TRUE(framer_.ProcessRevivedPacket(address_,
465 header,
466 StringPiece(AsChars(payload),
467 arraysize(payload))));
468
469 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
470 ASSERT_EQ(address_, visitor_.address_);
471 ASSERT_TRUE(visitor_.header_.get());
472 EXPECT_EQ(0xFEDCBA9876543210, visitor_.header_->guid);
473 EXPECT_EQ(0x1, visitor_.header_->retransmission_count);
474 EXPECT_EQ(static_cast<uint64>(0x123456789ABC),
475 visitor_.header_->packet_sequence_number);
476 EXPECT_EQ(static_cast<uint64>(0xF0E1D2C3B4A59687),
477 visitor_.header_->transmission_time);
478 EXPECT_EQ(0x00, visitor_.header_->flags);
479 EXPECT_EQ(0x00, visitor_.header_->fec_group);
480
481
482 ASSERT_EQ(1u, visitor_.stream_fragments_.size());
483 EXPECT_EQ(0u, visitor_.ack_fragments_.size());
484 EXPECT_EQ(static_cast<uint64>(0x01020304),
485 visitor_.stream_fragments_[0]->stream_id);
486 EXPECT_TRUE(visitor_.stream_fragments_[0]->fin);
487 EXPECT_EQ(0xBA98FEDC32107654, visitor_.stream_fragments_[0]->offset);
488 EXPECT_EQ("hello world!", visitor_.stream_fragments_[0]->data);
489 }
490
491 TEST_F(QuicFramerTest, StreamFragmentInFecGroup) {
492 unsigned char packet[] = {
493 // guid
494 0x10, 0x32, 0x54, 0x76,
495 0x98, 0xBA, 0xDC, 0xFE,
496 // packet id
497 0xBC, 0x9A, 0x78, 0x56,
498 0x12, 0x34,
499 // retransmission count
500 0x01,
501 // transmission time
502 0x87, 0x96, 0xA5, 0xB4,
503 0xC3, 0xD2, 0xE1, 0xF0,
504 // flags
505 0x00,
506 // fec group
507 0x02,
508
509 // fragment count
510 0x01,
511 // fragment type (stream fragment)
512 0x00,
513 // stream id
514 0x04, 0x03, 0x02, 0x01,
515 // fin
516 0x01,
517 // offset
518 0x54, 0x76, 0x10, 0x32,
519 0xDC, 0xFE, 0x98, 0xBA,
520 // data length
521 0x0c, 0x00,
522 // data
523 'h', 'e', 'l', 'l',
524 'o', ' ', 'w', 'o',
525 'r', 'l', 'd', '!',
526 };
527
528 EXPECT_TRUE(framer_.ProcessPacket(
529 address_, QuicEncryptedPacket(AsChars(packet),
530 arraysize(packet), false)));
531
532 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet))));
533 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
534 ASSERT_TRUE(visitor_.header_.get());
535 EXPECT_EQ(2, visitor_.header_->fec_group);
536 EXPECT_EQ(string(AsChars(packet) + kStartOfFecProtectedData,
537 arraysize(packet) - kStartOfFecProtectedData),
538 visitor_.fec_protected_payload_);
539 ASSERT_EQ(address_, visitor_.address_);
540
541 ASSERT_EQ(1u, visitor_.stream_fragments_.size());
542 EXPECT_EQ(0u, visitor_.ack_fragments_.size());
543 EXPECT_EQ(static_cast<uint64>(0x01020304),
544 visitor_.stream_fragments_[0]->stream_id);
545 EXPECT_TRUE(visitor_.stream_fragments_[0]->fin);
546 EXPECT_EQ(0xBA98FEDC32107654, visitor_.stream_fragments_[0]->offset);
547 EXPECT_EQ("hello world!", visitor_.stream_fragments_[0]->data);
548 }
549
550 TEST_F(QuicFramerTest, AckFragment) {
551 unsigned char packet[] = {
552 // guid
553 0x10, 0x32, 0x54, 0x76,
554 0x98, 0xBA, 0xDC, 0xFE,
555 // packet id
556 0xBC, 0x9A, 0x78, 0x56,
557 0x34, 0x12,
558 // retransmission count
559 0x01,
560 // transmission time
561 0x87, 0x96, 0xA5, 0xB4,
562 0xC3, 0xD2, 0xE1, 0xF0,
563 // flags
564 0x00,
565 // fec group
566 0x00,
567
568 // fragment count
569 0x01,
570 // fragment type (ack fragment)
571 0x02,
572 // largest received packet sequence number
573 0xBC, 0x9A, 0x78, 0x56,
574 0x34, 0x12,
575 // time delta
576 0x87, 0x96, 0xA5, 0xB4,
577 0xC3, 0xD2, 0xE1, 0xF0,
578 // num_unacked_packets
579 0x02,
580 // unacked packet sequence number
581 0xBA, 0x9A, 0x78, 0x56,
582 0x34, 0x12,
583 // unacked packet sequence number
584 0xBB, 0x9A, 0x78, 0x56,
585 0x34, 0x12,
586 // least packet sequence number awaiting an ack
587 0xA0, 0x9A, 0x78, 0x56,
588 0x34, 0x12,
589 // num non retransmitting packets
590 0x03,
591 // non retransmitting packet sequence number
592 0xAE, 0x9A, 0x78, 0x56,
593 0x34, 0x12,
594 // non retransmitting packet sequence number
595 0xAF, 0x9A, 0x78, 0x56,
596 0x34, 0x12,
597 // non retransmitting packet sequence number
598 0xB0, 0x9A, 0x78, 0x56,
599 0x34, 0x12,
600 // congestion feedback type (none)
601 0x00,
602 };
603
604 EXPECT_TRUE(framer_.ProcessPacket(
605 address_, QuicEncryptedPacket(AsChars(packet),
606 arraysize(packet), false)));
607
608 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet))));
609 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
610 ASSERT_TRUE(visitor_.header_.get());
611
612 EXPECT_EQ(0u, visitor_.stream_fragments_.size());
613 ASSERT_EQ(1u, visitor_.ack_fragments_.size());
614 const QuicAckFragment& fragment = *visitor_.ack_fragments_[0];
615 EXPECT_EQ(static_cast<uint64>(0x0123456789ABC),
616 fragment.received_info.largest_received);
617 EXPECT_EQ(0xF0E1D2C3B4A59687, fragment.received_info.time_received);
618
619 const hash_set<QuicPacketSequenceNumber>* sequence_nums =
620 &fragment.received_info.missing_packets;
621 ASSERT_EQ(2u, sequence_nums->size());
622 EXPECT_TRUE(sequence_nums->find(0x0123456789ABB) != sequence_nums->end());
623 EXPECT_TRUE(sequence_nums->find(0x0123456789ABA) != sequence_nums->end());
624 EXPECT_EQ(static_cast<uint64>(0x0123456789AA0),
625 fragment.sent_info.least_unacked);
626 ASSERT_EQ(3u, fragment.sent_info.non_retransmiting.size());
627 const hash_set<QuicPacketSequenceNumber>* non_retrans =
628 &fragment.sent_info.non_retransmiting;
629 EXPECT_TRUE(non_retrans->find(0x0123456789AB0) != non_retrans->end());
630 EXPECT_TRUE(non_retrans->find(0x0123456789AAF) != non_retrans->end());
631 EXPECT_TRUE(non_retrans->find(0x0123456789AAE) != non_retrans->end());
632 ASSERT_EQ(kNone, fragment.congestion_info.type);
633
634 // Now test framing boundaries
635 for (size_t i = kPacketHeaderSize; i < kPacketHeaderSize + 55; ++i) {
636 string expected_error;
637 if (i < kPacketHeaderSize + 1) {
638 expected_error = "Unable to read fragment count.";
639 } else if (i < kPacketHeaderSize + 2) {
640 expected_error = "Unable to read fragment type.";
641 } else if (i < kPacketHeaderSize + 8) {
642 expected_error = "Unable to read largest received.";
643 } else if (i < kPacketHeaderSize + 16) {
644 expected_error = "Unable to read time received.";
645 } else if (i < kPacketHeaderSize + 17) {
646 expected_error = "Unable to read num unacked packets.";
647 } else if (i < kPacketHeaderSize + 29) {
648 expected_error = "Unable to read sequence number in unacked packets.";
649 } else if (i < kPacketHeaderSize + 35) {
650 expected_error = "Unable to read least unacked.";
651 } else if (i < kPacketHeaderSize + 36) {
652 expected_error = "Unable to read num non-retransmitting.";
653 } else if (i < kPacketHeaderSize + 54) {
654 expected_error = "Unable to read sequence number in non-retransmitting.";
655 } else if (i < kPacketHeaderSize + 55) {
656 expected_error = "Unable to read congestion info type.";
657 }
658
659 EXPECT_FALSE(framer_.ProcessPacket(
660 address_, QuicEncryptedPacket(AsChars(packet), i, false)));
661 EXPECT_EQ(expected_error, framer_.detailed_error());
662 EXPECT_EQ(QUIC_INVALID_FRAGMENT_DATA, framer_.error());
663 }
664 }
665
666 TEST_F(QuicFramerTest, AckFragmentTCP) {
667 unsigned char packet[] = {
668 // guid
669 0x10, 0x32, 0x54, 0x76,
670 0x98, 0xBA, 0xDC, 0xFE,
671 // packet id
672 0xBC, 0x9A, 0x78, 0x56,
673 0x34, 0x12,
674 // retransmission count
675 0x01,
676 // transmission time
677 0x87, 0x96, 0xA5, 0xB4,
678 0xC3, 0xD2, 0xE1, 0xF0,
679 // flags
680 0x00,
681 // fec group
682 0x00,
683
684 // fragment count
685 0x01,
686 // fragment type (ack fragment)
687 0x02,
688 // largest received packet sequence number
689 0xBC, 0x9A, 0x78, 0x56,
690 0x34, 0x12,
691 // time delta
692 0x87, 0x96, 0xA5, 0xB4,
693 0xC3, 0xD2, 0xE1, 0xF0,
694 // num_unacked_packets
695 0x02,
696 // unacked packet sequence number
697 0xBA, 0x9A, 0x78, 0x56,
698 0x34, 0x12,
699 // unacked packet sequence number
700 0xBB, 0x9A, 0x78, 0x56,
701 0x34, 0x12,
702 // least packet sequence number awaiting an ack
703 0xA0, 0x9A, 0x78, 0x56,
704 0x34, 0x12,
705 // num non retransmitting packets
706 0x03,
707 // non retransmitting packet sequence number
708 0xAE, 0x9A, 0x78, 0x56,
709 0x34, 0x12,
710 // non retransmitting packet sequence number
711 0xAF, 0x9A, 0x78, 0x56,
712 0x34, 0x12,
713 // non retransmitting packet sequence number
714 0xB0, 0x9A, 0x78, 0x56,
715 0x34, 0x12,
716 // congestion feedback type (tcp)
717 0x01,
718 // ack_fragment.congestion_info.tcp.accumulated_number_of_lost_packets
719 0x01, 0x02,
720 // ack_fragment.congestion_info.tcp.receive_window
721 0x03, 0x04,
722 };
723
724 EXPECT_TRUE(framer_.ProcessPacket(
725 address_, QuicEncryptedPacket(AsChars(packet),
726 arraysize(packet), false)));
727
728 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet))));
729 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
730 ASSERT_TRUE(visitor_.header_.get());
731
732 EXPECT_EQ(0u, visitor_.stream_fragments_.size());
733 ASSERT_EQ(1u, visitor_.ack_fragments_.size());
734 const QuicAckFragment& fragment = *visitor_.ack_fragments_[0];
735 EXPECT_EQ(static_cast<uint64>(0x0123456789ABC),
736 fragment.received_info.largest_received);
737 EXPECT_EQ(0xF0E1D2C3B4A59687, fragment.received_info.time_received);
738
739 const hash_set<QuicPacketSequenceNumber>* sequence_nums =
740 &fragment.received_info.missing_packets;
741 ASSERT_EQ(2u, sequence_nums->size());
742 EXPECT_TRUE(sequence_nums->find(0x0123456789ABB) != sequence_nums->end());
743 EXPECT_TRUE(sequence_nums->find(0x0123456789ABA) != sequence_nums->end());
744 EXPECT_EQ(static_cast<uint64>(0x0123456789AA0),
745 fragment.sent_info.least_unacked);
746 ASSERT_EQ(3u, fragment.sent_info.non_retransmiting.size());
747 const hash_set<QuicPacketSequenceNumber>* non_retrans =
748 &fragment.sent_info.non_retransmiting;
749 EXPECT_TRUE(non_retrans->find(0x0123456789AB0) != non_retrans->end());
750 EXPECT_TRUE(non_retrans->find(0x0123456789AAF) != non_retrans->end());
751 EXPECT_TRUE(non_retrans->find(0x0123456789AAE) != non_retrans->end());
752 ASSERT_EQ(kTCP, fragment.congestion_info.type);
753 EXPECT_EQ(0x0201,
754 fragment.congestion_info.tcp.accumulated_number_of_lost_packets);
755 EXPECT_EQ(0x0403, fragment.congestion_info.tcp.receive_window);
756
757 // Now test framing boundaries
758 for (size_t i = kCongestionInfoOffset; i < kCongestionInfoOffset + 5; ++i) {
759 string expected_error;
760 if (i < kCongestionInfoOffset + 1) {
761 expected_error = "Unable to read congestion info type.";
762 } else if (i < kCongestionInfoOffset + 3) {
763 expected_error = "Unable to read accumulated number of lost packets.";
764 } else if (i < kCongestionInfoOffset + 5) {
765 expected_error = "Unable to read receive window.";
766 }
767
768 EXPECT_FALSE(framer_.ProcessPacket(
769 address_, QuicEncryptedPacket(AsChars(packet), i, false)));
770 EXPECT_EQ(expected_error, framer_.detailed_error());
771 EXPECT_EQ(QUIC_INVALID_FRAGMENT_DATA, framer_.error());
772 }
773 }
774
775 TEST_F(QuicFramerTest, AckFragmentInterArrival) {
776 unsigned char packet[] = {
777 // guid
778 0x10, 0x32, 0x54, 0x76,
779 0x98, 0xBA, 0xDC, 0xFE,
780 // packet id
781 0xBC, 0x9A, 0x78, 0x56,
782 0x34, 0x12,
783 // retransmission count
784 0x01,
785 // transmission time
786 0x87, 0x96, 0xA5, 0xB4,
787 0xC3, 0xD2, 0xE1, 0xF0,
788 // flags
789 0x00,
790 // fec group
791 0x00,
792
793 // fragment count
794 0x01,
795 // fragment type (ack fragment)
796 0x02,
797 // largest received packet sequence number
798 0xBC, 0x9A, 0x78, 0x56,
799 0x34, 0x12,
800 // time delta
801 0x87, 0x96, 0xA5, 0xB4,
802 0xC3, 0xD2, 0xE1, 0xF0,
803 // num_unacked_packets
804 0x02,
805 // unacked packet sequence number
806 0xBA, 0x9A, 0x78, 0x56,
807 0x34, 0x12,
808 // unacked packet sequence number
809 0xBB, 0x9A, 0x78, 0x56,
810 0x34, 0x12,
811 // least packet sequence number awaiting an ack
812 0xA0, 0x9A, 0x78, 0x56,
813 0x34, 0x12,
814 // num non retransmitting packets
815 0x03,
816 // non retransmitting packet sequence number
817 0xAE, 0x9A, 0x78, 0x56,
818 0x34, 0x12,
819 // non retransmitting packet sequence number
820 0xAF, 0x9A, 0x78, 0x56,
821 0x34, 0x12,
822 // non retransmitting packet sequence number
823 0xB0, 0x9A, 0x78, 0x56,
824 0x34, 0x12,
825 // congestion feedback type (inter arrival)
826 0x02,
827 // accumulated_number_of_lost_packets
828 0x02, 0x03,
829 // offset_time
830 0x04, 0x05,
831 // delta_time
832 0x06, 0x07,
833 };
834
835 EXPECT_TRUE(framer_.ProcessPacket(
836 address_, QuicEncryptedPacket(AsChars(packet),
837 arraysize(packet), false)));
838
839 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet))));
840 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
841 ASSERT_TRUE(visitor_.header_.get());
842
843 EXPECT_EQ(0u, visitor_.stream_fragments_.size());
844 ASSERT_EQ(1u, visitor_.ack_fragments_.size());
845 const QuicAckFragment& fragment = *visitor_.ack_fragments_[0];
846 EXPECT_EQ(static_cast<uint64>(0x0123456789ABC),
847 fragment.received_info.largest_received);
848 EXPECT_EQ(0xF0E1D2C3B4A59687, fragment.received_info.time_received);
849
850 const hash_set<QuicPacketSequenceNumber>* sequence_nums =
851 &fragment.received_info.missing_packets;
852 ASSERT_EQ(2u, sequence_nums->size());
853 EXPECT_TRUE(sequence_nums->find(0x0123456789ABB) != sequence_nums->end());
854 EXPECT_TRUE(sequence_nums->find(0x0123456789ABA) != sequence_nums->end());
855 EXPECT_EQ(static_cast<uint64>(0x0123456789AA0),
856 fragment.sent_info.least_unacked);
857 ASSERT_EQ(3u, fragment.sent_info.non_retransmiting.size());
858 const hash_set<QuicPacketSequenceNumber>* non_retrans =
859 &fragment.sent_info.non_retransmiting;
860 EXPECT_TRUE(non_retrans->find(0x0123456789AB0) != non_retrans->end());
861 EXPECT_TRUE(non_retrans->find(0x0123456789AAF) != non_retrans->end());
862 EXPECT_TRUE(non_retrans->find(0x0123456789AAE) != non_retrans->end());
863 ASSERT_EQ(kInterArrival, fragment.congestion_info.type);
864 EXPECT_EQ(0x0302, fragment.congestion_info.inter_arrival.
865 accumulated_number_of_lost_packets);
866 EXPECT_EQ(0x0504,
867 fragment.congestion_info.inter_arrival.offset_time);
868 EXPECT_EQ(0x0706,
869 fragment.congestion_info.inter_arrival.delta_time);
870
871 // Now test framing boundaries
872 for (size_t i = kCongestionInfoOffset; i < kCongestionInfoOffset + 5; ++i) {
873 string expected_error;
874 if (i < kCongestionInfoOffset + 1) {
875 expected_error = "Unable to read congestion info type.";
876 } else if (i < kCongestionInfoOffset + 3) {
877 expected_error = "Unable to read accumulated number of lost packets.";
878 } else if (i < kCongestionInfoOffset + 5) {
879 expected_error = "Unable to read offset time.";
880 } else if (i < kCongestionInfoOffset + 7) {
881 expected_error = "Unable to read delta time.";
882 }
883 EXPECT_FALSE(framer_.ProcessPacket(
884 address_, QuicEncryptedPacket(AsChars(packet), i, false)));
885 EXPECT_EQ(expected_error, framer_.detailed_error());
886 EXPECT_EQ(QUIC_INVALID_FRAGMENT_DATA, framer_.error());
887 }
888 }
889
890 TEST_F(QuicFramerTest, AckFragmentFixRate) {
891 unsigned char packet[] = {
892 // guid
893 0x10, 0x32, 0x54, 0x76,
894 0x98, 0xBA, 0xDC, 0xFE,
895 // packet id
896 0xBC, 0x9A, 0x78, 0x56,
897 0x34, 0x12,
898 // retransmission count
899 0x01,
900 // transmission time
901 0x87, 0x96, 0xA5, 0xB4,
902 0xC3, 0xD2, 0xE1, 0xF0,
903 // flags
904 0x00,
905 // fec group
906 0x00,
907
908 // fragment count
909 0x01,
910 // fragment type (ack fragment)
911 0x02,
912 // largest received packet sequence number
913 0xBC, 0x9A, 0x78, 0x56,
914 0x34, 0x12,
915 // time delta
916 0x87, 0x96, 0xA5, 0xB4,
917 0xC3, 0xD2, 0xE1, 0xF0,
918 // num_unacked_packets
919 0x02,
920 // unacked packet sequence number
921 0xBA, 0x9A, 0x78, 0x56,
922 0x34, 0x12,
923 // unacked packet sequence number
924 0xBB, 0x9A, 0x78, 0x56,
925 0x34, 0x12,
926 // least packet sequence number awaiting an ack
927 0xA0, 0x9A, 0x78, 0x56,
928 0x34, 0x12,
929 // num non retransmitting packets
930 0x03,
931 // non retransmitting packet sequence number
932 0xAE, 0x9A, 0x78, 0x56,
933 0x34, 0x12,
934 // non retransmitting packet sequence number
935 0xAF, 0x9A, 0x78, 0x56,
936 0x34, 0x12,
937 // non retransmitting packet sequence number
938 0xB0, 0x9A, 0x78, 0x56,
939 0x34, 0x12,
940 // congestion feedback type (fix rate)
941 0x03,
942 // bitrate_in_bytes_per_second;
943 0x01, 0x02, 0x03, 0x04,
944 };
945
946 EXPECT_TRUE(framer_.ProcessPacket(
947 address_, QuicEncryptedPacket(AsChars(packet),
948 arraysize(packet), false)));
949
950 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet))));
951 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
952 ASSERT_TRUE(visitor_.header_.get());
953
954 EXPECT_EQ(0u, visitor_.stream_fragments_.size());
955 ASSERT_EQ(1u, visitor_.ack_fragments_.size());
956 const QuicAckFragment& fragment = *visitor_.ack_fragments_[0];
957 EXPECT_EQ(static_cast<uint64>(0x0123456789ABC),
958 fragment.received_info.largest_received);
959 EXPECT_EQ(0xF0E1D2C3B4A59687, fragment.received_info.time_received);
960
961 const hash_set<QuicPacketSequenceNumber>* sequence_nums =
962 &fragment.received_info.missing_packets;
963 ASSERT_EQ(2u, sequence_nums->size());
964 EXPECT_TRUE(sequence_nums->find(0x0123456789ABB) != sequence_nums->end());
965 EXPECT_TRUE(sequence_nums->find(0x0123456789ABA) != sequence_nums->end());
966 EXPECT_EQ(static_cast<uint64>(0x0123456789AA0),
967 fragment.sent_info.least_unacked);
968 ASSERT_EQ(3u, fragment.sent_info.non_retransmiting.size());
969 const hash_set<QuicPacketSequenceNumber>* non_retrans =
970 &fragment.sent_info.non_retransmiting;
971 EXPECT_TRUE(non_retrans->find(0x0123456789AB0) != non_retrans->end());
972 EXPECT_TRUE(non_retrans->find(0x0123456789AAF) != non_retrans->end());
973 EXPECT_TRUE(non_retrans->find(0x0123456789AAE) != non_retrans->end());
974 ASSERT_EQ(kFixRate, fragment.congestion_info.type);
975 EXPECT_EQ(static_cast<uint32>(0x04030201),
976 fragment.congestion_info.fix_rate.bitrate_in_bytes_per_second);
977
978 // Now test framing boundaries
979 for (size_t i = kCongestionInfoOffset; i < kCongestionInfoOffset + 5; ++i) {
980 string expected_error;
981 if (i < kCongestionInfoOffset + 1) {
982 expected_error = "Unable to read congestion info type.";
983 } else if (i < kCongestionInfoOffset + 5) {
984 expected_error = "Unable to read bitrate.";
985 }
986 EXPECT_FALSE(framer_.ProcessPacket(
987 address_, QuicEncryptedPacket(AsChars(packet), i, false)));
988 EXPECT_EQ(expected_error, framer_.detailed_error());
989 EXPECT_EQ(QUIC_INVALID_FRAGMENT_DATA, framer_.error());
990 }
991 }
992
993
994 TEST_F(QuicFramerTest, AckFragmentInvalidFeedback) {
995 unsigned char packet[] = {
996 // guid
997 0x10, 0x32, 0x54, 0x76,
998 0x98, 0xBA, 0xDC, 0xFE,
999 // packet id
1000 0xBC, 0x9A, 0x78, 0x56,
1001 0x34, 0x12,
1002 // retransmission count
1003 0x01,
1004 // transmission time
1005 0x87, 0x96, 0xA5, 0xB4,
1006 0xC3, 0xD2, 0xE1, 0xF0,
1007 // flags
1008 0x00,
1009 // fec group
1010 0x00,
1011
1012 // fragment count
1013 0x01,
1014 // fragment type (ack fragment)
1015 0x02,
1016 // largest received packet sequence number
1017 0xBC, 0x9A, 0x78, 0x56,
1018 0x34, 0x12,
1019 // time delta
1020 0x87, 0x96, 0xA5, 0xB4,
1021 0xC3, 0xD2, 0xE1, 0xF0,
1022 // num_unacked_packets
1023 0x02,
1024 // unacked packet sequence number
1025 0xBA, 0x9A, 0x78, 0x56,
1026 0x34, 0x12,
1027 // unacked packet sequence number
1028 0xBB, 0x9A, 0x78, 0x56,
1029 0x34, 0x12,
1030 // least packet sequence number awaiting an ack
1031 0xA0, 0x9A, 0x78, 0x56,
1032 0x34, 0x12,
1033 // num non retransmitting packets
1034 0x03,
1035 // non retransmitting packet sequence number
1036 0xAE, 0x9A, 0x78, 0x56,
1037 0x34, 0x12,
1038 // non retransmitting packet sequence number
1039 0xAF, 0x9A, 0x78, 0x56,
1040 0x34, 0x12,
1041 // non retransmitting packet sequence number
1042 0xB0, 0x9A, 0x78, 0x56,
1043 0x34, 0x12,
1044 // congestion feedback type (invalid)
1045 0x04,
1046 };
1047
1048 EXPECT_FALSE(framer_.ProcessPacket(
1049 address_, QuicEncryptedPacket(AsChars(packet),
1050 arraysize(packet), false)));
1051 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet))));
1052 EXPECT_EQ(QUIC_INVALID_FRAGMENT_DATA, framer_.error());
1053 }
1054
1055 TEST_F(QuicFramerTest, RstStreamFragment) {
1056 unsigned char packet[] = {
1057 // guid
1058 0x10, 0x32, 0x54, 0x76,
1059 0x98, 0xBA, 0xDC, 0xFE,
1060 // packet id
1061 0xBC, 0x9A, 0x78, 0x56,
1062 0x34, 0x12,
1063 // retransmission count
1064 0x01,
1065 // transmission time
1066 0x87, 0x96, 0xA5, 0xB4,
1067 0xC3, 0xD2, 0xE1, 0xF0,
1068 // flags
1069 0x00,
1070 // fec group
1071 0x00,
1072
1073 // fragment count
1074 0x01,
1075 // fragment type (rst stream fragment)
1076 0x03,
1077 // stream id
1078 0x04, 0x03, 0x02, 0x01,
1079 // offset
1080 0x54, 0x76, 0x10, 0x32,
1081 0xDC, 0xFE, 0x98, 0xBA,
1082 // details
1083 0x08, 0x07, 0x06, 0x05,
1084 };
1085
1086 EXPECT_TRUE(framer_.ProcessPacket(
1087 address_, QuicEncryptedPacket(AsChars(packet),
1088 arraysize(packet), false)));
1089
1090 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet))));
1091 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1092 ASSERT_TRUE(visitor_.header_.get());
1093 ASSERT_EQ(address_, visitor_.address_);
1094
1095 EXPECT_EQ(static_cast<uint64>(0x01020304),
1096 visitor_.rst_stream_fragment_.stream_id);
1097 EXPECT_EQ(0x05060708, visitor_.rst_stream_fragment_.details);
1098 EXPECT_EQ(0xBA98FEDC32107654, visitor_.rst_stream_fragment_.offset);
1099
1100 // Now test framing boundaries
1101 for (size_t i = kPacketHeaderSize + 3; i < kPacketHeaderSize + 18; ++i) {
1102 string expected_error;
1103 if (i < kPacketHeaderSize + 6) {
1104 expected_error = "Unable to read stream_id.";
1105 } else if (i < kPacketHeaderSize + 14) {
1106 expected_error = "Unable to read offset in rst fragment.";
1107 } else if (i < kPacketHeaderSize + 18) {
1108 expected_error = "Unable to read rst stream details.";
1109 }
1110 EXPECT_FALSE(framer_.ProcessPacket(
1111 address_, QuicEncryptedPacket(AsChars(packet), i, false)));
1112 EXPECT_EQ(expected_error, framer_.detailed_error());
1113 EXPECT_EQ(QUIC_INVALID_RST_STREAM_DATA, framer_.error());
1114 }
1115 }
1116
1117 TEST_F(QuicFramerTest, ConnectionCloseFragment) {
1118 unsigned char packet[] = {
1119 // guid
1120 0x10, 0x32, 0x54, 0x76,
1121 0x98, 0xBA, 0xDC, 0xFE,
1122 // packet id
1123 0xBC, 0x9A, 0x78, 0x56,
1124 0x34, 0x12,
1125 // retransmission count
1126 0x01,
1127 // transmission time
1128 0x87, 0x96, 0xA5, 0xB4,
1129 0xC3, 0xD2, 0xE1, 0xF0,
1130 // flags
1131 0x00,
1132 // fec group
1133 0x00,
1134
1135
1136 // fragment count
1137 0x01,
1138 // fragment type (connection close fragment)
1139 0x04,
1140 // details
1141 0x08, 0x07, 0x06, 0x05,
1142
1143 // Ack fragment.
1144
1145 // largest received packet sequence number
1146 0xBC, 0x9A, 0x78, 0x56,
1147 0x34, 0x12,
1148 // time delta
1149 0x87, 0x96, 0xA5, 0xB4,
1150 0xC3, 0xD2, 0xE1, 0xF0,
1151 // num_unacked_packets
1152 0x02,
1153 // unacked packet sequence number
1154 0xBA, 0x9A, 0x78, 0x56,
1155 0x34, 0x12,
1156 // unacked packet sequence number
1157 0xBB, 0x9A, 0x78, 0x56,
1158 0x34, 0x12,
1159 // least packet sequence number awaiting an ack
1160 0xA0, 0x9A, 0x78, 0x56,
1161 0x34, 0x12,
1162 // num non retransmitting packets
1163 0x03,
1164 // non retransmitting packet sequence number
1165 0xAE, 0x9A, 0x78, 0x56,
1166 0x34, 0x12,
1167 // non retransmitting packet sequence number
1168 0xAF, 0x9A, 0x78, 0x56,
1169 0x34, 0x12,
1170 // non retransmitting packet sequence number
1171 0xB0, 0x9A, 0x78, 0x56,
1172 0x34, 0x12,
1173 // congestion feedback type (inter arrival)
1174 0x02,
1175 // accumulated_number_of_lost_packets
1176 0x02, 0x03,
1177 // offset_time
1178 0x04, 0x05,
1179 // delta_time
1180 0x06, 0x07,
1181 };
1182
1183 EXPECT_TRUE(framer_.ProcessPacket(
1184 address_, QuicEncryptedPacket(AsChars(packet),
1185 arraysize(packet), false)));
1186
1187 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet))));
1188 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1189 ASSERT_TRUE(visitor_.header_.get());
1190
1191 EXPECT_EQ(0u, visitor_.stream_fragments_.size());
1192
1193 EXPECT_EQ(0x05060708, visitor_.connection_close_fragment_.details);
1194
1195 ASSERT_EQ(1u, visitor_.ack_fragments_.size());
1196 const QuicAckFragment& fragment = *visitor_.ack_fragments_[0];
1197 EXPECT_EQ(static_cast<uint64>(0x0123456789ABC),
1198 fragment.received_info.largest_received);
1199 EXPECT_EQ(0xF0E1D2C3B4A59687, fragment.received_info.time_received);
1200
1201 const hash_set<QuicPacketSequenceNumber>* sequence_nums =
1202 &fragment.received_info.missing_packets;
1203 ASSERT_EQ(2u, sequence_nums->size());
1204 EXPECT_TRUE(sequence_nums->find(0x0123456789ABB) != sequence_nums->end());
1205 EXPECT_TRUE(sequence_nums->find(0x0123456789ABA) != sequence_nums->end());
1206 EXPECT_EQ(static_cast<uint64>(0x0123456789AA0),
1207 fragment.sent_info.least_unacked);
1208 ASSERT_EQ(3u, fragment.sent_info.non_retransmiting.size());
1209 const hash_set<QuicPacketSequenceNumber>* non_retrans =
1210 &fragment.sent_info.non_retransmiting;
1211 EXPECT_TRUE(non_retrans->find(0x0123456789AB0) != non_retrans->end());
1212 EXPECT_TRUE(non_retrans->find(0x0123456789AAF) != non_retrans->end());
1213 EXPECT_TRUE(non_retrans->find(0x0123456789AAE) != non_retrans->end());
1214 ASSERT_EQ(kInterArrival, fragment.congestion_info.type);
1215 EXPECT_EQ(0x0302, fragment.congestion_info.inter_arrival.
1216 accumulated_number_of_lost_packets);
1217 EXPECT_EQ(0x0504,
1218 fragment.congestion_info.inter_arrival.offset_time);
1219 EXPECT_EQ(0x0706,
1220 fragment.congestion_info.inter_arrival.delta_time);
1221
1222 // Now test framing boundaries
1223 for (size_t i = kPacketHeaderSize + 3; i < kPacketHeaderSize + 6; ++i) {
1224 string expected_error;
1225 if (i < kPacketHeaderSize + 6) {
1226 expected_error = "Unable to read connection close details.";
1227 }
1228 EXPECT_FALSE(framer_.ProcessPacket(
1229 address_, QuicEncryptedPacket(AsChars(packet), i, false)));
1230 EXPECT_EQ(expected_error, framer_.detailed_error());
1231 EXPECT_EQ(QUIC_INVALID_CONNECTION_CLOSE_DATA, framer_.error());
1232 }
1233 }
1234
1235 TEST_F(QuicFramerTest, FecPacket) {
1236 unsigned char packet[] = {
1237 // guid
1238 0x10, 0x32, 0x54, 0x76,
1239 0x98, 0xBA, 0xDC, 0xFE,
1240 // packet id
1241 0xBC, 0x9A, 0x78, 0x56,
1242 0x34, 0x12,
1243 // retransmission count
1244 0x01,
1245 // transmission time
1246 0x87, 0x96, 0xA5, 0xB4,
1247 0xC3, 0xD2, 0xE1, 0xF0,
1248 // flags (FEC)
1249 0x01,
1250 // fec group
1251 0x01,
1252
1253 // first protected packet
1254 0xBB, 0x9A, 0x78, 0x56,
1255 0x34, 0x12,
1256 // redundancy
1257 'a', 'b', 'c', 'd',
1258 'e', 'f', 'g', 'h',
1259 'i', 'j', 'k', 'l',
1260 'm', 'n', 'o', 'p',
1261 };
1262
1263 EXPECT_TRUE(framer_.ProcessPacket(
1264 address_, QuicEncryptedPacket(AsChars(packet),
1265 arraysize(packet), false)));
1266
1267 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet))));
1268 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1269 ASSERT_TRUE(visitor_.header_.get());
1270
1271 EXPECT_EQ(0u, visitor_.stream_fragments_.size());
1272 EXPECT_EQ(0u, visitor_.ack_fragments_.size());
1273 ASSERT_EQ(1, visitor_.fec_count_);
1274 const QuicFecData& fec_data = *visitor_.fec_data_[0];
1275 EXPECT_EQ(static_cast<uint64>(0x0123456789ABB),
1276 fec_data.first_protected_packet_sequence_number);
1277 EXPECT_EQ("abcdefghijklmnop", fec_data.redundancy);
1278 }
1279
1280 TEST_F(QuicFramerTest, ConstructStreamFragmentPacket) {
1281 QuicPacketHeader header;
1282 header.guid = 0xFEDCBA9876543210;
1283 header.retransmission_count = 0x01;
1284 header.packet_sequence_number = 0x123456789ABC;
1285 header.transmission_time = 0xF0E1D2C3B4A59687;
1286 header.flags = PACKET_FLAGS_NONE;
1287 header.fec_group = 0;
1288
1289 QuicStreamFragment stream_fragment;
1290 stream_fragment.stream_id = 0x01020304;
1291 stream_fragment.fin = true;
1292 stream_fragment.offset = 0xBA98FEDC32107654;
1293 stream_fragment.data = "hello world!";
1294
1295 QuicFragment fragment;
1296 fragment.type = STREAM_FRAGMENT;
1297 fragment.stream_fragment = &stream_fragment;
1298
1299 QuicFragments fragments;
1300 fragments.push_back(fragment);
1301
1302 unsigned char packet[] = {
1303 // guid
1304 0x10, 0x32, 0x54, 0x76,
1305 0x98, 0xBA, 0xDC, 0xFE,
1306 // packet id
1307 0xBC, 0x9A, 0x78, 0x56,
1308 0x34, 0x12,
1309 // retransmission count
1310 0x01,
1311 // transmission time
1312 0x87, 0x96, 0xA5, 0xB4,
1313 0xC3, 0xD2, 0xE1, 0xF0,
1314 // flags
1315 0x00,
1316 // fec group
1317 0x00,
1318
1319 // fragment count
1320 0x01,
1321 // fragment type (stream fragment)
1322 0x00,
1323 // stream id
1324 0x04, 0x03, 0x02, 0x01,
1325 // fin
1326 0x01,
1327 // offset
1328 0x54, 0x76, 0x10, 0x32,
1329 0xDC, 0xFE, 0x98, 0xBA,
1330 // data length
1331 0x0c, 0x00,
1332 // data
1333 'h', 'e', 'l', 'l',
1334 'o', ' ', 'w', 'o',
1335 'r', 'l', 'd', '!',
1336 };
1337
1338 QuicPacket* data;
1339 ASSERT_TRUE(framer_.ConstructFragementDataPacket(header, fragments, &data));
1340
1341 test::CompareCharArraysWithHexError("constructed packet",
1342 data->data(), data->length(),
1343 AsChars(packet), arraysize(packet));
1344
1345 delete data;
1346 }
1347
1348 TEST_F(QuicFramerTest, ConstructAckFragmentPacket) {
1349 QuicPacketHeader header;
1350 header.guid = 0xFEDCBA9876543210;
1351 header.retransmission_count = 0x01;
1352 header.packet_sequence_number = 0x123456789ABC;
1353 header.transmission_time = 0xF0E1D2C3B4A59687;
1354 header.flags = PACKET_FLAGS_NONE;
1355 header.fec_group = 0;
1356
1357 QuicAckFragment ack_fragment;
1358 ack_fragment.received_info.largest_received = 0x0123456789ABC;
1359 ack_fragment.received_info.time_received = 0xF0E1D2C3B4A59687;
1360 ack_fragment.received_info.missing_packets.insert(0x0123456789ABB);
1361 ack_fragment.received_info.missing_packets.insert(0x0123456789ABA);
1362 ack_fragment.sent_info.least_unacked = 0x0123456789AA0;
1363 ack_fragment.sent_info.non_retransmiting.insert(0x0123456789AB0);
1364 ack_fragment.sent_info.non_retransmiting.insert(0x0123456789AAF);
1365 ack_fragment.sent_info.non_retransmiting.insert(0x0123456789AAE);
1366 ack_fragment.congestion_info.type = kNone;
1367
1368 QuicFragment fragment;
1369 fragment.type = ACK_FRAGMENT;
1370 fragment.ack_fragment = &ack_fragment;
1371
1372 QuicFragments fragments;
1373 fragments.push_back(fragment);
1374
1375 unsigned char packet[] = {
1376 // guid
1377 0x10, 0x32, 0x54, 0x76,
1378 0x98, 0xBA, 0xDC, 0xFE,
1379 // packet id
1380 0xBC, 0x9A, 0x78, 0x56,
1381 0x34, 0x12,
1382 // retransmission count
1383 0x01,
1384 // transmission time
1385 0x87, 0x96, 0xA5, 0xB4,
1386 0xC3, 0xD2, 0xE1, 0xF0,
1387 // flags
1388 0x00,
1389 // fec group
1390 0x00,
1391
1392 // fragment count
1393 0x01,
1394 // fragment type (ack fragment)
1395 0x02,
1396 // largest received packet sequence number
1397 0xBC, 0x9A, 0x78, 0x56,
1398 0x34, 0x12,
1399 // time delta
1400 0x87, 0x96, 0xA5, 0xB4,
1401 0xC3, 0xD2, 0xE1, 0xF0,
1402 // num_unacked_packets
1403 0x02,
1404 #if defined(OS_WIN)
1405 // unacked packet sequence number
1406 0xBB, 0x9A, 0x78, 0x56,
1407 0x34, 0x12,
1408 // unacked packet sequence number
1409 0xBA, 0x9A, 0x78, 0x56,
1410 0x34, 0x12,
1411 #else
1412 // unacked packet sequence number
1413 0xBA, 0x9A, 0x78, 0x56,
1414 0x34, 0x12,
1415 // unacked packet sequence number
1416 0xBB, 0x9A, 0x78, 0x56,
1417 0x34, 0x12,
1418 #endif
1419 // least packet sequence number awaiting an ack
1420 0xA0, 0x9A, 0x78, 0x56,
1421 0x34, 0x12,
1422 // num non retransmitting packets
1423 0x03,
1424 #if defined(OS_WIN)
1425 // non retransmitting packet sequence number
1426 0xB0, 0x9A, 0x78, 0x56,
1427 0x34, 0x12,
1428 // non retransmitting packet sequence number
1429 0xAF, 0x9A, 0x78, 0x56,
1430 0x34, 0x12,
1431 // non retransmitting packet sequence number
1432 0xAE, 0x9A, 0x78, 0x56,
1433 0x34, 0x12,
1434 #else
1435 // non retransmitting packet sequence number
1436 0xAE, 0x9A, 0x78, 0x56,
1437 0x34, 0x12,
1438 // non retransmitting packet sequence number
1439 0xAF, 0x9A, 0x78, 0x56,
1440 0x34, 0x12,
1441 // non retransmitting packet sequence number
1442 0xB0, 0x9A, 0x78, 0x56,
1443 0x34, 0x12,
1444 #endif
1445 // congestion feedback type (none)
1446 0x00,
1447 };
1448
1449 QuicPacket* data;
1450 EXPECT_TRUE(framer_.ConstructFragementDataPacket(header, fragments, &data));
1451
1452 test::CompareCharArraysWithHexError("constructed packet",
1453 data->data(), data->length(),
1454 AsChars(packet), arraysize(packet));
1455
1456 delete data;
1457 }
1458
1459 TEST_F(QuicFramerTest, ConstructAckFragmentPacketTCP) {
1460 QuicPacketHeader header;
1461 header.guid = 0xFEDCBA9876543210;
1462 header.retransmission_count = 0x01;
1463 header.packet_sequence_number = 0x123456789ABC;
1464 header.transmission_time = 0xF0E1D2C3B4A59687;
1465 header.flags = PACKET_FLAGS_NONE;
1466 header.fec_group = 0;
1467
1468 QuicAckFragment ack_fragment;
1469 ack_fragment.received_info.largest_received = 0x0123456789ABC;
1470 ack_fragment.received_info.time_received = 0xF0E1D2C3B4A59687;
1471 ack_fragment.received_info.missing_packets.insert(0x0123456789ABB);
1472 ack_fragment.received_info.missing_packets.insert(0x0123456789ABA);
1473 ack_fragment.sent_info.least_unacked = 0x0123456789AA0;
1474 ack_fragment.sent_info.non_retransmiting.insert(0x0123456789AB0);
1475 ack_fragment.sent_info.non_retransmiting.insert(0x0123456789AAF);
1476 ack_fragment.sent_info.non_retransmiting.insert(0x0123456789AAE);
1477 ack_fragment.congestion_info.type = kTCP;
1478 ack_fragment.congestion_info.tcp.accumulated_number_of_lost_packets = 0x0201;
1479 ack_fragment.congestion_info.tcp.receive_window = 0x0403;
1480
1481 QuicFragment fragment;
1482 fragment.type = ACK_FRAGMENT;
1483 fragment.ack_fragment = &ack_fragment;
1484
1485 QuicFragments fragments;
1486 fragments.push_back(fragment);
1487
1488 unsigned char packet[] = {
1489 // guid
1490 0x10, 0x32, 0x54, 0x76,
1491 0x98, 0xBA, 0xDC, 0xFE,
1492 // packet id
1493 0xBC, 0x9A, 0x78, 0x56,
1494 0x34, 0x12,
1495 // retransmission count
1496 0x01,
1497 // transmission time
1498 0x87, 0x96, 0xA5, 0xB4,
1499 0xC3, 0xD2, 0xE1, 0xF0,
1500 // flags
1501 0x00,
1502 // fec group
1503 0x00,
1504
1505 // fragment count
1506 0x01,
1507 // fragment type (ack fragment)
1508 0x02,
1509 // largest received packet sequence number
1510 0xBC, 0x9A, 0x78, 0x56,
1511 0x34, 0x12,
1512 // time delta
1513 0x87, 0x96, 0xA5, 0xB4,
1514 0xC3, 0xD2, 0xE1, 0xF0,
1515 // num_unacked_packets
1516 0x02,
1517 #if defined(OS_WIN)
1518 // unacked packet sequence number
1519 0xBB, 0x9A, 0x78, 0x56,
1520 0x34, 0x12,
1521 // unacked packet sequence number
1522 0xBA, 0x9A, 0x78, 0x56,
1523 0x34, 0x12,
1524 #else
1525 // unacked packet sequence number
1526 0xBA, 0x9A, 0x78, 0x56,
1527 0x34, 0x12,
1528 // unacked packet sequence number
1529 0xBB, 0x9A, 0x78, 0x56,
1530 0x34, 0x12,
1531 #endif
1532 // least packet sequence number awaiting an ack
1533 0xA0, 0x9A, 0x78, 0x56,
1534 0x34, 0x12,
1535 // num non retransmitting packets
1536 0x03,
1537 #if defined(OS_WIN)
1538 // non retransmitting packet sequence number
1539 0xB0, 0x9A, 0x78, 0x56,
1540 0x34, 0x12,
1541 // non retransmitting packet sequence number
1542 0xAF, 0x9A, 0x78, 0x56,
1543 0x34, 0x12,
1544 // non retransmitting packet sequence number
1545 0xAE, 0x9A, 0x78, 0x56,
1546 0x34, 0x12,
1547 #else
1548 // non retransmitting packet sequence number
1549 0xAE, 0x9A, 0x78, 0x56,
1550 0x34, 0x12,
1551 // non retransmitting packet sequence number
1552 0xAF, 0x9A, 0x78, 0x56,
1553 0x34, 0x12,
1554 // non retransmitting packet sequence number
1555 0xB0, 0x9A, 0x78, 0x56,
1556 0x34, 0x12,
1557 #endif
1558 // congestion feedback type (tcp)
1559 0x01,
1560 // ack_fragment.congestion_info.tcp.accumulated_number_of_lost_packets
1561 0x01, 0x02,
1562 // ack_fragment.congestion_info.tcp.receive_window
1563 0x03, 0x04,
1564 };
1565
1566 QuicPacket* data;
1567 EXPECT_TRUE(framer_.ConstructFragementDataPacket(header, fragments, &data));
1568
1569 test::CompareCharArraysWithHexError("constructed packet",
1570 data->data(), data->length(),
1571 AsChars(packet), arraysize(packet));
1572
1573 delete data;
1574 }
1575
1576 TEST_F(QuicFramerTest, ConstructAckFragmentPacketInterArrival) {
1577 QuicPacketHeader header;
1578 header.guid = 0xFEDCBA9876543210;
1579 header.retransmission_count = 0x01;
1580 header.packet_sequence_number = 0x123456789ABC;
1581 header.transmission_time = 0xF0E1D2C3B4A59687;
1582 header.flags = PACKET_FLAGS_NONE;
1583 header.fec_group = 0;
1584
1585 QuicAckFragment ack_fragment;
1586 ack_fragment.received_info.largest_received = 0x0123456789ABC;
1587 ack_fragment.received_info.time_received = 0xF0E1D2C3B4A59687;
1588 ack_fragment.received_info.missing_packets.insert(0x0123456789ABB);
1589 ack_fragment.received_info.missing_packets.insert(0x0123456789ABA);
1590 ack_fragment.sent_info.least_unacked = 0x0123456789AA0;
1591 ack_fragment.sent_info.non_retransmiting.insert(0x0123456789AB0);
1592 ack_fragment.sent_info.non_retransmiting.insert(0x0123456789AAF);
1593 ack_fragment.sent_info.non_retransmiting.insert(0x0123456789AAE);
1594 ack_fragment.congestion_info.type = kInterArrival;
1595 ack_fragment.congestion_info.inter_arrival.accumulated_number_of_lost_packets
1596 = 0x0302;
1597 ack_fragment.congestion_info.inter_arrival.offset_time = 0x0504;
1598 ack_fragment.congestion_info.inter_arrival.delta_time = 0x0706;
1599
1600 QuicFragment fragment;
1601 fragment.type = ACK_FRAGMENT;
1602 fragment.ack_fragment = &ack_fragment;
1603
1604 QuicFragments fragments;
1605 fragments.push_back(fragment);
1606
1607 unsigned char packet[] = {
1608 // guid
1609 0x10, 0x32, 0x54, 0x76,
1610 0x98, 0xBA, 0xDC, 0xFE,
1611 // packet id
1612 0xBC, 0x9A, 0x78, 0x56,
1613 0x34, 0x12,
1614 // retransmission count
1615 0x01,
1616 // transmission time
1617 0x87, 0x96, 0xA5, 0xB4,
1618 0xC3, 0xD2, 0xE1, 0xF0,
1619 // flags
1620 0x00,
1621 // fec group
1622 0x00,
1623
1624 // fragment count
1625 0x01,
1626 // fragment type (ack fragment)
1627 0x02,
1628 // largest received packet sequence number
1629 0xBC, 0x9A, 0x78, 0x56,
1630 0x34, 0x12,
1631 // time delta
1632 0x87, 0x96, 0xA5, 0xB4,
1633 0xC3, 0xD2, 0xE1, 0xF0,
1634 // num_unacked_packets
1635 0x02,
1636 #if defined(OS_WIN)
1637 // unacked packet sequence number
1638 0xBB, 0x9A, 0x78, 0x56,
1639 0x34, 0x12,
1640 // unacked packet sequence number
1641 0xBA, 0x9A, 0x78, 0x56,
1642 0x34, 0x12,
1643 #else
1644 // unacked packet sequence number
1645 0xBA, 0x9A, 0x78, 0x56,
1646 0x34, 0x12,
1647 // unacked packet sequence number
1648 0xBB, 0x9A, 0x78, 0x56,
1649 0x34, 0x12,
1650 #endif
1651 // least packet sequence number awaiting an ack
1652 0xA0, 0x9A, 0x78, 0x56,
1653 0x34, 0x12,
1654 // num non retransmitting packets
1655 0x03,
1656 #if defined(OS_WIN)
1657 // non retransmitting packet sequence number
1658 0xB0, 0x9A, 0x78, 0x56,
1659 0x34, 0x12,
1660 // non retransmitting packet sequence number
1661 0xAF, 0x9A, 0x78, 0x56,
1662 0x34, 0x12,
1663 // non retransmitting packet sequence number
1664 0xAE, 0x9A, 0x78, 0x56,
1665 0x34, 0x12,
1666 #else
1667 // non retransmitting packet sequence number
1668 0xAE, 0x9A, 0x78, 0x56,
1669 0x34, 0x12,
1670 // non retransmitting packet sequence number
1671 0xAF, 0x9A, 0x78, 0x56,
1672 0x34, 0x12,
1673 // non retransmitting packet sequence number
1674 0xB0, 0x9A, 0x78, 0x56,
1675 0x34, 0x12,
1676 #endif
1677 // congestion feedback type (inter arrival)
1678 0x02,
1679 // accumulated_number_of_lost_packets
1680 0x02, 0x03,
1681 // offset_time
1682 0x04, 0x05,
1683 // delta_time
1684 0x06, 0x07,
1685 };
1686
1687 QuicPacket* data;
1688 EXPECT_TRUE(framer_.ConstructFragementDataPacket(header, fragments, &data));
1689
1690 test::CompareCharArraysWithHexError("constructed packet",
1691 data->data(), data->length(),
1692 AsChars(packet), arraysize(packet));
1693
1694 delete data;
1695 }
1696
1697 TEST_F(QuicFramerTest, ConstructAckFragmentPacketFixRate) {
1698 QuicPacketHeader header;
1699 header.guid = 0xFEDCBA9876543210;
1700 header.retransmission_count = 0x01;
1701 header.packet_sequence_number = 0x123456789ABC;
1702 header.transmission_time = 0xF0E1D2C3B4A59687;
1703 header.flags = PACKET_FLAGS_NONE;
1704 header.fec_group = 0;
1705
1706 QuicAckFragment ack_fragment;
1707 ack_fragment.received_info.largest_received = 0x0123456789ABC;
1708 ack_fragment.received_info.time_received = 0xF0E1D2C3B4A59687;
1709 ack_fragment.received_info.missing_packets.insert(0x0123456789ABB);
1710 ack_fragment.received_info.missing_packets.insert(0x0123456789ABA);
1711 ack_fragment.sent_info.least_unacked = 0x0123456789AA0;
1712 ack_fragment.sent_info.non_retransmiting.insert(0x0123456789AB0);
1713 ack_fragment.sent_info.non_retransmiting.insert(0x0123456789AAF);
1714 ack_fragment.sent_info.non_retransmiting.insert(0x0123456789AAE);
1715 ack_fragment.congestion_info.type = kFixRate;
1716 ack_fragment.congestion_info.fix_rate.bitrate_in_bytes_per_second
1717 = 0x04030201;
1718
1719 QuicFragment fragment;
1720 fragment.type = ACK_FRAGMENT;
1721 fragment.ack_fragment = &ack_fragment;
1722
1723 QuicFragments fragments;
1724 fragments.push_back(fragment);
1725
1726 unsigned char packet[] = {
1727 // guid
1728 0x10, 0x32, 0x54, 0x76,
1729 0x98, 0xBA, 0xDC, 0xFE,
1730 // packet id
1731 0xBC, 0x9A, 0x78, 0x56,
1732 0x34, 0x12,
1733 // retransmission count
1734 0x01,
1735 // transmission time
1736 0x87, 0x96, 0xA5, 0xB4,
1737 0xC3, 0xD2, 0xE1, 0xF0,
1738 // flags
1739 0x00,
1740 // fec group
1741 0x00,
1742
1743 // fragment count
1744 0x01,
1745 // fragment type (ack fragment)
1746 0x02,
1747 // largest received packet sequence number
1748 0xBC, 0x9A, 0x78, 0x56,
1749 0x34, 0x12,
1750 // time delta
1751 0x87, 0x96, 0xA5, 0xB4,
1752 0xC3, 0xD2, 0xE1, 0xF0,
1753 // num_unacked_packets
1754 0x02,
1755 #if defined(OS_WIN)
1756 // unacked packet sequence number
1757 0xBB, 0x9A, 0x78, 0x56,
1758 0x34, 0x12,
1759 // unacked packet sequence number
1760 0xBA, 0x9A, 0x78, 0x56,
1761 0x34, 0x12,
1762 #else
1763 // unacked packet sequence number
1764 0xBA, 0x9A, 0x78, 0x56,
1765 0x34, 0x12,
1766 // unacked packet sequence number
1767 0xBB, 0x9A, 0x78, 0x56,
1768 0x34, 0x12,
1769 #endif
1770 // least packet sequence number awaiting an ack
1771 0xA0, 0x9A, 0x78, 0x56,
1772 0x34, 0x12,
1773 // num non retransmitting packets
1774 0x03,
1775 #if defined(OS_WIN)
1776 // non retransmitting packet sequence number
1777 0xB0, 0x9A, 0x78, 0x56,
1778 0x34, 0x12,
1779 // non retransmitting packet sequence number
1780 0xAF, 0x9A, 0x78, 0x56,
1781 0x34, 0x12,
1782 // non retransmitting packet sequence number
1783 0xAE, 0x9A, 0x78, 0x56,
1784 0x34, 0x12,
1785 #else
1786 // non retransmitting packet sequence number
1787 0xAE, 0x9A, 0x78, 0x56,
1788 0x34, 0x12,
1789 // non retransmitting packet sequence number
1790 0xAF, 0x9A, 0x78, 0x56,
1791 0x34, 0x12,
1792 // non retransmitting packet sequence number
1793 0xB0, 0x9A, 0x78, 0x56,
1794 0x34, 0x12,
1795 #endif
1796 // congestion feedback type (fix rate)
1797 0x03,
1798 // bitrate_in_bytes_per_second;
1799 0x01, 0x02, 0x03, 0x04,
1800 };
1801
1802 QuicPacket* data;
1803 EXPECT_TRUE(framer_.ConstructFragementDataPacket(header, fragments, &data));
1804
1805 test::CompareCharArraysWithHexError("constructed packet",
1806 data->data(), data->length(),
1807 AsChars(packet), arraysize(packet));
1808
1809 delete data;
1810 }
1811
1812 TEST_F(QuicFramerTest, ConstructAckFragmentPacketInvalidFeedback) {
1813 QuicPacketHeader header;
1814 header.guid = 0xFEDCBA9876543210;
1815 header.retransmission_count = 0x01;
1816 header.packet_sequence_number = 0x123456789ABC;
1817 header.transmission_time = 0xF0E1D2C3B4A59687;
1818 header.flags = PACKET_FLAGS_NONE;
1819 header.fec_group = 0;
1820
1821 QuicAckFragment ack_fragment;
1822 ack_fragment.received_info.largest_received = 0x0123456789ABC;
1823 ack_fragment.received_info.time_received = 0xF0E1D2C3B4A59687;
1824 ack_fragment.received_info.missing_packets.insert(0x0123456789ABB);
1825 ack_fragment.received_info.missing_packets.insert(0x0123456789ABA);
1826 ack_fragment.sent_info.least_unacked = 0x0123456789AA0;
1827 ack_fragment.sent_info.non_retransmiting.insert(0x0123456789AB0);
1828 ack_fragment.sent_info.non_retransmiting.insert(0x0123456789AAF);
1829 ack_fragment.sent_info.non_retransmiting.insert(0x0123456789AAE);
1830 ack_fragment.congestion_info.type =
1831 static_cast<CongestionFeedbackType>(kFixRate + 1);
1832
1833 QuicFragment fragment;
1834 fragment.type = ACK_FRAGMENT;
1835 fragment.ack_fragment = &ack_fragment;
1836
1837 QuicFragments fragments;
1838 fragments.push_back(fragment);
1839
1840 QuicPacket* data;
1841 EXPECT_FALSE(framer_.ConstructFragementDataPacket(header, fragments, &data));
1842 }
1843
1844 TEST_F(QuicFramerTest, ConstructRstFragmentPacket) {
1845 QuicPacketHeader header;
1846 header.guid = 0xFEDCBA9876543210;
1847 header.retransmission_count = 0x01;
1848 header.packet_sequence_number = 0x123456789ABC;
1849 header.transmission_time = 0xF0E1D2C3B4A59687;
1850 header.flags = PACKET_FLAGS_NONE;
1851 header.fec_group = 0;
1852
1853 QuicRstStreamFragment rst_fragment;
1854 rst_fragment.stream_id = 0x01020304;
1855 rst_fragment.details = static_cast<QuicErrorCode>(0x05060708);
1856 rst_fragment.offset = 0xBA98FEDC32107654;
1857
1858 unsigned char packet[] = {
1859 // guid
1860 0x10, 0x32, 0x54, 0x76,
1861 0x98, 0xBA, 0xDC, 0xFE,
1862 // packet id
1863 0xBC, 0x9A, 0x78, 0x56,
1864 0x34, 0x12,
1865 // retransmission count
1866 0x01,
1867 // transmission time
1868 0x87, 0x96, 0xA5, 0xB4,
1869 0xC3, 0xD2, 0xE1, 0xF0,
1870 // flags
1871 0x00,
1872 // fec group
1873 0x00,
1874
1875 // fragment count
1876 0x01,
1877 // fragment type (rst stream fragment)
1878 0x03,
1879 // stream id
1880 0x04, 0x03, 0x02, 0x01,
1881 // offset
1882 0x54, 0x76, 0x10, 0x32,
1883 0xDC, 0xFE, 0x98, 0xBA,
1884 // details
1885 0x08, 0x07, 0x06, 0x05,
1886 };
1887
1888 QuicFragment fragment(&rst_fragment);
1889
1890 QuicFragments fragments;
1891 fragments.push_back(fragment);
1892
1893 QuicPacket* data;
1894 EXPECT_TRUE(framer_.ConstructFragementDataPacket(header, fragments, &data));
1895
1896 test::CompareCharArraysWithHexError("constructed packet",
1897 data->data(), data->length(),
1898 AsChars(packet), arraysize(packet));
1899
1900 delete data;
1901 }
1902
1903 TEST_F(QuicFramerTest, ConstructCloseFragmentPacket) {
1904 QuicPacketHeader header;
1905 header.guid = 0xFEDCBA9876543210;
1906 header.retransmission_count = 0x01;
1907 header.packet_sequence_number = 0x123456789ABC;
1908 header.transmission_time = 0xF0E1D2C3B4A59687;
1909 header.flags = PACKET_FLAGS_NONE;
1910 header.fec_group = 0;
1911
1912 QuicConnectionCloseFragment close_fragment;
1913 close_fragment.details = static_cast<QuicErrorCode>(0x05060708);
1914
1915 QuicAckFragment* ack_fragment = &close_fragment.ack_fragment;
1916 ack_fragment->received_info.largest_received = 0x0123456789ABC;
1917 ack_fragment->received_info.time_received = 0xF0E1D2C3B4A59687;
1918 ack_fragment->received_info.missing_packets.insert(0x0123456789ABB);
1919 ack_fragment->received_info.missing_packets.insert(0x0123456789ABA);
1920 ack_fragment->sent_info.least_unacked = 0x0123456789AA0;
1921 ack_fragment->sent_info.non_retransmiting.insert(0x0123456789AB0);
1922 ack_fragment->sent_info.non_retransmiting.insert(0x0123456789AAF);
1923 ack_fragment->sent_info.non_retransmiting.insert(0x0123456789AAE);
1924 ack_fragment->congestion_info.type = kInterArrival;
1925 ack_fragment->congestion_info.inter_arrival.accumulated_number_of_lost_packets
1926 = 0x0302;
1927 ack_fragment->congestion_info.inter_arrival.offset_time = 0x0504;
1928 ack_fragment->congestion_info.inter_arrival.delta_time = 0x0706;
1929
1930 QuicFragment fragment(&close_fragment);
1931
1932 QuicFragments fragments;
1933 fragments.push_back(fragment);
1934
1935 unsigned char packet[] = {
1936 // guid
1937 0x10, 0x32, 0x54, 0x76,
1938 0x98, 0xBA, 0xDC, 0xFE,
1939 // packet id
1940 0xBC, 0x9A, 0x78, 0x56,
1941 0x34, 0x12,
1942 // retransmission count
1943 0x01,
1944 // transmission time
1945 0x87, 0x96, 0xA5, 0xB4,
1946 0xC3, 0xD2, 0xE1, 0xF0,
1947 // flags
1948 0x00,
1949 // fec group
1950 0x00,
1951
1952 // fragment count
1953 0x01,
1954 // fragment type (connection close fragment)
1955 0x04,
1956 // details
1957 0x08, 0x07, 0x06, 0x05,
1958
1959 // Ack fragment.
1960
1961 // largest received packet sequence number
1962 0xBC, 0x9A, 0x78, 0x56,
1963 0x34, 0x12,
1964 // time delta
1965 0x87, 0x96, 0xA5, 0xB4,
1966 0xC3, 0xD2, 0xE1, 0xF0,
1967 // num_unacked_packets
1968 0x02,
1969 #if defined(OS_WIN)
1970 // unacked packet sequence number
1971 0xBB, 0x9A, 0x78, 0x56,
1972 0x34, 0x12,
1973 // unacked packet sequence number
1974 0xBA, 0x9A, 0x78, 0x56,
1975 0x34, 0x12,
1976 #else
1977 // unacked packet sequence number
1978 0xBA, 0x9A, 0x78, 0x56,
1979 0x34, 0x12,
1980 // unacked packet sequence number
1981 0xBB, 0x9A, 0x78, 0x56,
1982 0x34, 0x12,
1983 #endif
1984 // least packet sequence number awaiting an ack
1985 0xA0, 0x9A, 0x78, 0x56,
1986 0x34, 0x12,
1987 // num non retransmitting packets
1988 0x03,
1989 #if defined(OS_WIN)
1990 // non retransmitting packet sequence number
1991 0xB0, 0x9A, 0x78, 0x56,
1992 0x34, 0x12,
1993 // non retransmitting packet sequence number
1994 0xAF, 0x9A, 0x78, 0x56,
1995 0x34, 0x12,
1996 // non retransmitting packet sequence number
1997 0xAE, 0x9A, 0x78, 0x56,
1998 0x34, 0x12,
1999 #else
2000 // non retransmitting packet sequence number
2001 0xAE, 0x9A, 0x78, 0x56,
2002 0x34, 0x12,
2003 // non retransmitting packet sequence number
2004 0xAF, 0x9A, 0x78, 0x56,
2005 0x34, 0x12,
2006 // non retransmitting packet sequence number
2007 0xB0, 0x9A, 0x78, 0x56,
2008 0x34, 0x12,
2009 #endif
2010 // congestion feedback type (inter arrival)
2011 0x02,
2012 // accumulated_number_of_lost_packets
2013 0x02, 0x03,
2014 // offset_time
2015 0x04, 0x05,
2016 // delta_time
2017 0x06, 0x07,
2018 };
2019
2020 QuicPacket* data;
2021 EXPECT_TRUE(framer_.ConstructFragementDataPacket(header, fragments, &data));
2022
2023 test::CompareCharArraysWithHexError("constructed packet",
2024 data->data(), data->length(),
2025 AsChars(packet), arraysize(packet));
2026
2027 delete data;
2028 }
2029
2030 TEST_F(QuicFramerTest, ConstructFecPacket) {
2031 QuicPacketHeader header;
2032 header.guid = 0xFEDCBA9876543210;
2033 header.retransmission_count = 0x01;
2034 header.packet_sequence_number = 0x123456789ABC;
2035 header.transmission_time = 0xF0E1D2C3B4A59687;
2036 header.flags = PACKET_FLAGS_FEC;
2037 header.fec_group = 1;
2038
2039 QuicFecData fec_data;
2040 fec_data.fec_group = 1;
2041 fec_data.first_protected_packet_sequence_number = 0x123456789ABB;
2042 fec_data.redundancy = "abcdefghijklmnop";
2043
2044 unsigned char packet[] = {
2045 // guid
2046 0x10, 0x32, 0x54, 0x76,
2047 0x98, 0xBA, 0xDC, 0xFE,
2048 // packet id
2049 0xBC, 0x9A, 0x78, 0x56,
2050 0x34, 0x12,
2051 // retransmission count
2052 0x01,
2053 // transmission time
2054 0x87, 0x96, 0xA5, 0xB4,
2055 0xC3, 0xD2, 0xE1, 0xF0,
2056 // flags
2057 0x01,
2058 // fec group
2059 0x01,
2060 // first protected packet
2061 0xBB, 0x9A, 0x78, 0x56,
2062 0x34, 0x12,
2063 // redundancy
2064 'a', 'b', 'c', 'd',
2065 'e', 'f', 'g', 'h',
2066 'i', 'j', 'k', 'l',
2067 'm', 'n', 'o', 'p',
2068 };
2069
2070 QuicPacket* data;
2071 EXPECT_TRUE(framer_.ConstructFecPacket(header, fec_data, &data));
2072
2073 test::CompareCharArraysWithHexError("constructed packet",
2074 data->data(), data->length(),
2075 AsChars(packet), arraysize(packet));
2076
2077 delete data;
2078 }
2079
2080 TEST_F(QuicFramerTest, IncrementRetransmitCount) {
2081 QuicPacketHeader header;
2082 header.guid = 0xFEDCBA9876543210;
2083 header.retransmission_count = 1;
2084 header.packet_sequence_number = 0x123456789ABC;
2085 header.transmission_time = 0xF0E1D2C3B4A59687;
2086 header.flags = PACKET_FLAGS_NONE;
2087 header.fec_group = 0;
2088
2089 QuicStreamFragment stream_fragment;
2090 stream_fragment.stream_id = 0x01020304;
2091 stream_fragment.fin = true;
2092 stream_fragment.offset = 0xBA98FEDC32107654;
2093 stream_fragment.data = "hello world!";
2094
2095 QuicFragment fragment;
2096 fragment.type = STREAM_FRAGMENT;
2097 fragment.stream_fragment = &stream_fragment;
2098
2099 QuicFragments fragments;
2100 fragments.push_back(fragment);
2101
2102 QuicPacket *original;
2103 ASSERT_TRUE(framer_.ConstructFragementDataPacket(
2104 header, fragments, &original));
2105 EXPECT_EQ(header.retransmission_count, framer_.GetRetransmitCount(original));
2106
2107 header.retransmission_count = 2;
2108 QuicPacket *retransmitted;
2109 ASSERT_TRUE(framer_.ConstructFragementDataPacket(
2110 header, fragments, &retransmitted));
2111
2112 framer_.IncrementRetransmitCount(original);
2113 EXPECT_EQ(header.retransmission_count, framer_.GetRetransmitCount(original));
2114
2115 test::CompareCharArraysWithHexError(
2116 "constructed packet", original->data(), original->length(),
2117 retransmitted->data(), retransmitted->length());
2118 delete original;
2119 delete retransmitted;
2120 }
2121
2122 TEST_F(QuicFramerTest, EncryptPacket) {
2123 unsigned char packet[] = {
2124 // guid
2125 0x10, 0x32, 0x54, 0x76,
2126 0x98, 0xBA, 0xDC, 0xFE,
2127 // packet id
2128 0xBC, 0x9A, 0x78, 0x56,
2129 0x34, 0x12,
2130 // retransmission count
2131 0x01,
2132 // transmission time
2133 0x87, 0x96, 0xA5, 0xB4,
2134 0xC3, 0xD2, 0xE1, 0xF0,
2135 // flags
2136 0x01,
2137 // fec group
2138 0x01,
2139 // first protected packet
2140 0xBB, 0x9A, 0x78, 0x56,
2141 0x34, 0x12,
2142 // redundancy
2143 'a', 'b', 'c', 'd',
2144 'e', 'f', 'g', 'h',
2145 'i', 'j', 'k', 'l',
2146 'm', 'n', 'o', 'p',
2147 };
2148
2149 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket(
2150 QuicPacket(AsChars(packet), arraysize(packet), false)));
2151 ASSERT_TRUE(encrypted.get() != NULL);
2152 EXPECT_TRUE(CheckEncryption(StringPiece(AsChars(packet), arraysize(packet))));
2153 }
2154
2155 } // namespace test
2156
2157 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_framer.cc ('k') | net/quic/quic_protocol.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698