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

Side by Side Diff: net/quic/quic_framer_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_framer.h" 5 #include "net/quic/quic_framer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // Size in bytes of the stream frame fields for an arbitrary StreamID and 47 // Size in bytes of the stream frame fields for an arbitrary StreamID and
48 // offset and the last frame in a packet. 48 // offset and the last frame in a packet.
49 size_t GetMinStreamFrameSize(QuicVersion version) { 49 size_t GetMinStreamFrameSize(QuicVersion version) {
50 return kQuicFrameTypeSize + kQuicMaxStreamIdSize + kQuicMaxStreamOffsetSize; 50 return kQuicFrameTypeSize + kQuicMaxStreamIdSize + kQuicMaxStreamOffsetSize;
51 } 51 }
52 52
53 // Index into the sequence number offset in the header. 53 // Index into the sequence number offset in the header.
54 size_t GetSequenceNumberOffset(QuicConnectionIdLength connection_id_length, 54 size_t GetSequenceNumberOffset(QuicConnectionIdLength connection_id_length,
55 bool include_version) { 55 bool include_version) {
56 return kConnectionIdOffset + connection_id_length + 56 return kConnectionIdOffset + connection_id_length +
57 (include_version ? kQuicVersionSize : 0); 57 (include_version ? kQuicVersionSize : 0);
58 } 58 }
59 59
60 size_t GetSequenceNumberOffset(bool include_version) { 60 size_t GetSequenceNumberOffset(bool include_version) {
61 return GetSequenceNumberOffset(PACKET_8BYTE_CONNECTION_ID, include_version); 61 return GetSequenceNumberOffset(PACKET_8BYTE_CONNECTION_ID, include_version);
62 } 62 }
63 63
64 // Index into the private flags offset in the data packet header. 64 // Index into the private flags offset in the data packet header.
65 size_t GetPrivateFlagsOffset(QuicConnectionIdLength connection_id_length, 65 size_t GetPrivateFlagsOffset(QuicConnectionIdLength connection_id_length,
66 bool include_version) { 66 bool include_version) {
67 return GetSequenceNumberOffset(connection_id_length, include_version) + 67 return GetSequenceNumberOffset(connection_id_length, include_version) +
68 PACKET_6BYTE_SEQUENCE_NUMBER; 68 PACKET_6BYTE_SEQUENCE_NUMBER;
69 } 69 }
70 70
71 size_t GetPrivateFlagsOffset(bool include_version) { 71 size_t GetPrivateFlagsOffset(bool include_version) {
72 return GetPrivateFlagsOffset(PACKET_8BYTE_CONNECTION_ID, include_version); 72 return GetPrivateFlagsOffset(PACKET_8BYTE_CONNECTION_ID, include_version);
73 } 73 }
74 74
75 size_t GetPrivateFlagsOffset(bool include_version, 75 size_t GetPrivateFlagsOffset(bool include_version,
76 QuicSequenceNumberLength sequence_number_length) { 76 QuicSequenceNumberLength sequence_number_length) {
77 return GetSequenceNumberOffset(PACKET_8BYTE_CONNECTION_ID, include_version) + 77 return GetSequenceNumberOffset(PACKET_8BYTE_CONNECTION_ID, include_version) +
78 sequence_number_length; 78 sequence_number_length;
79 } 79 }
80 80
81 // Index into the fec group offset in the header. 81 // Index into the fec group offset in the header.
82 size_t GetFecGroupOffset(QuicConnectionIdLength connection_id_length, 82 size_t GetFecGroupOffset(QuicConnectionIdLength connection_id_length,
83 bool include_version) { 83 bool include_version) {
84 return GetPrivateFlagsOffset(connection_id_length, include_version) + 84 return GetPrivateFlagsOffset(connection_id_length, include_version) +
85 kPrivateFlagsSize; 85 kPrivateFlagsSize;
86 } 86 }
87 87
88 size_t GetFecGroupOffset(bool include_version) { 88 size_t GetFecGroupOffset(bool include_version) {
89 return GetPrivateFlagsOffset(PACKET_8BYTE_CONNECTION_ID, include_version) + 89 return GetPrivateFlagsOffset(PACKET_8BYTE_CONNECTION_ID, include_version) +
90 kPrivateFlagsSize; 90 kPrivateFlagsSize;
91 } 91 }
92 92
93 size_t GetFecGroupOffset(bool include_version, 93 size_t GetFecGroupOffset(bool include_version,
94 QuicSequenceNumberLength sequence_number_length) { 94 QuicSequenceNumberLength sequence_number_length) {
95 return GetPrivateFlagsOffset(include_version, sequence_number_length) + 95 return GetPrivateFlagsOffset(include_version, sequence_number_length) +
96 kPrivateFlagsSize; 96 kPrivateFlagsSize;
97 } 97 }
98 98
99 // Index into the message tag of the public reset packet. 99 // Index into the message tag of the public reset packet.
100 // Public resets always have full connection_ids. 100 // Public resets always have full connection_ids.
101 const size_t kPublicResetPacketMessageTagOffset = 101 const size_t kPublicResetPacketMessageTagOffset =
102 kConnectionIdOffset + PACKET_8BYTE_CONNECTION_ID; 102 kConnectionIdOffset + PACKET_8BYTE_CONNECTION_ID;
103 103
104 class TestEncrypter : public QuicEncrypter { 104 class TestEncrypter : public QuicEncrypter {
105 public: 105 public:
106 virtual ~TestEncrypter() {} 106 virtual ~TestEncrypter() {}
107 virtual bool SetKey(StringPiece key) OVERRIDE { 107 virtual bool SetKey(StringPiece key) OVERRIDE { return true; }
108 return true;
109 }
110 virtual bool SetNoncePrefix(StringPiece nonce_prefix) OVERRIDE { 108 virtual bool SetNoncePrefix(StringPiece nonce_prefix) OVERRIDE {
111 return true; 109 return true;
112 } 110 }
113 virtual bool Encrypt(StringPiece nonce, 111 virtual bool Encrypt(StringPiece nonce,
114 StringPiece associated_data, 112 StringPiece associated_data,
115 StringPiece plaintext, 113 StringPiece plaintext,
116 unsigned char* output) OVERRIDE { 114 unsigned char* output) OVERRIDE {
117 CHECK(false) << "Not implemented"; 115 CHECK(false) << "Not implemented";
118 return false; 116 return false;
119 } 117 }
120 virtual QuicData* EncryptPacket(QuicPacketSequenceNumber sequence_number, 118 virtual QuicData* EncryptPacket(QuicPacketSequenceNumber sequence_number,
121 StringPiece associated_data, 119 StringPiece associated_data,
122 StringPiece plaintext) OVERRIDE { 120 StringPiece plaintext) OVERRIDE {
123 sequence_number_ = sequence_number; 121 sequence_number_ = sequence_number;
124 associated_data_ = associated_data.as_string(); 122 associated_data_ = associated_data.as_string();
125 plaintext_ = plaintext.as_string(); 123 plaintext_ = plaintext.as_string();
126 return new QuicData(plaintext.data(), plaintext.length()); 124 return new QuicData(plaintext.data(), plaintext.length());
127 } 125 }
128 virtual size_t GetKeySize() const OVERRIDE { 126 virtual size_t GetKeySize() const OVERRIDE { return 0; }
129 return 0; 127 virtual size_t GetNoncePrefixSize() const OVERRIDE { return 0; }
130 }
131 virtual size_t GetNoncePrefixSize() const OVERRIDE {
132 return 0;
133 }
134 virtual size_t GetMaxPlaintextSize(size_t ciphertext_size) const OVERRIDE { 128 virtual size_t GetMaxPlaintextSize(size_t ciphertext_size) const OVERRIDE {
135 return ciphertext_size; 129 return ciphertext_size;
136 } 130 }
137 virtual size_t GetCiphertextSize(size_t plaintext_size) const OVERRIDE { 131 virtual size_t GetCiphertextSize(size_t plaintext_size) const OVERRIDE {
138 return plaintext_size; 132 return plaintext_size;
139 } 133 }
140 virtual StringPiece GetKey() const OVERRIDE { 134 virtual StringPiece GetKey() const OVERRIDE { return StringPiece(); }
141 return StringPiece(); 135 virtual StringPiece GetNoncePrefix() const OVERRIDE { return StringPiece(); }
142 }
143 virtual StringPiece GetNoncePrefix() const OVERRIDE {
144 return StringPiece();
145 }
146 QuicPacketSequenceNumber sequence_number_; 136 QuicPacketSequenceNumber sequence_number_;
147 string associated_data_; 137 string associated_data_;
148 string plaintext_; 138 string plaintext_;
149 }; 139 };
150 140
151 class TestDecrypter : public QuicDecrypter { 141 class TestDecrypter : public QuicDecrypter {
152 public: 142 public:
153 virtual ~TestDecrypter() {} 143 virtual ~TestDecrypter() {}
154 virtual bool SetKey(StringPiece key) OVERRIDE { 144 virtual bool SetKey(StringPiece key) OVERRIDE { return true; }
155 return true;
156 }
157 virtual bool SetNoncePrefix(StringPiece nonce_prefix) OVERRIDE { 145 virtual bool SetNoncePrefix(StringPiece nonce_prefix) OVERRIDE {
158 return true; 146 return true;
159 } 147 }
160 virtual bool Decrypt(StringPiece nonce, 148 virtual bool Decrypt(StringPiece nonce,
161 StringPiece associated_data, 149 StringPiece associated_data,
162 StringPiece ciphertext, 150 StringPiece ciphertext,
163 unsigned char* output, 151 unsigned char* output,
164 size_t* output_length) OVERRIDE { 152 size_t* output_length) OVERRIDE {
165 CHECK(false) << "Not implemented"; 153 CHECK(false) << "Not implemented";
166 return false; 154 return false;
167 } 155 }
168 virtual QuicData* DecryptPacket(QuicPacketSequenceNumber sequence_number, 156 virtual QuicData* DecryptPacket(QuicPacketSequenceNumber sequence_number,
169 StringPiece associated_data, 157 StringPiece associated_data,
170 StringPiece ciphertext) OVERRIDE { 158 StringPiece ciphertext) OVERRIDE {
171 sequence_number_ = sequence_number; 159 sequence_number_ = sequence_number;
172 associated_data_ = associated_data.as_string(); 160 associated_data_ = associated_data.as_string();
173 ciphertext_ = ciphertext.as_string(); 161 ciphertext_ = ciphertext.as_string();
174 return new QuicData(ciphertext.data(), ciphertext.length()); 162 return new QuicData(ciphertext.data(), ciphertext.length());
175 } 163 }
176 virtual StringPiece GetKey() const OVERRIDE { 164 virtual StringPiece GetKey() const OVERRIDE { return StringPiece(); }
177 return StringPiece(); 165 virtual StringPiece GetNoncePrefix() const OVERRIDE { return StringPiece(); }
178 }
179 virtual StringPiece GetNoncePrefix() const OVERRIDE {
180 return StringPiece();
181 }
182 QuicPacketSequenceNumber sequence_number_; 166 QuicPacketSequenceNumber sequence_number_;
183 string associated_data_; 167 string associated_data_;
184 string ciphertext_; 168 string ciphertext_;
185 }; 169 };
186 170
187 class TestQuicVisitor : public ::net::QuicFramerVisitorInterface { 171 class TestQuicVisitor : public ::net::QuicFramerVisitorInterface {
188 public: 172 public:
189 TestQuicVisitor() 173 TestQuicVisitor()
190 : error_count_(0), 174 : error_count_(0),
191 version_mismatch_(0), 175 version_mismatch_(0),
192 packet_count_(0), 176 packet_count_(0),
193 frame_count_(0), 177 frame_count_(0),
194 fec_count_(0), 178 fec_count_(0),
195 complete_packets_(0), 179 complete_packets_(0),
196 revived_packets_(0), 180 revived_packets_(0),
197 accept_packet_(true), 181 accept_packet_(true),
198 accept_public_header_(true) { 182 accept_public_header_(true) {}
199 }
200 183
201 virtual ~TestQuicVisitor() { 184 virtual ~TestQuicVisitor() {
202 STLDeleteElements(&stream_frames_); 185 STLDeleteElements(&stream_frames_);
203 STLDeleteElements(&ack_frames_); 186 STLDeleteElements(&ack_frames_);
204 STLDeleteElements(&congestion_feedback_frames_); 187 STLDeleteElements(&congestion_feedback_frames_);
205 STLDeleteElements(&stop_waiting_frames_); 188 STLDeleteElements(&stop_waiting_frames_);
206 STLDeleteElements(&ping_frames_); 189 STLDeleteElements(&ping_frames_);
207 STLDeleteElements(&fec_data_); 190 STLDeleteElements(&fec_data_);
208 } 191 }
209 192
210 virtual void OnError(QuicFramer* f) OVERRIDE { 193 virtual void OnError(QuicFramer* f) OVERRIDE {
211 DVLOG(1) << "QuicFramer Error: " << QuicUtils::ErrorToString(f->error()) 194 DVLOG(1) << "QuicFramer Error: " << QuicUtils::ErrorToString(f->error())
212 << " (" << f->error() << ")"; 195 << " (" << f->error() << ")";
213 ++error_count_; 196 ++error_count_;
214 } 197 }
215 198
216 virtual void OnPacket() OVERRIDE {} 199 virtual void OnPacket() OVERRIDE {}
217 200
218 virtual void OnPublicResetPacket( 201 virtual void OnPublicResetPacket(
219 const QuicPublicResetPacket& packet) OVERRIDE { 202 const QuicPublicResetPacket& packet) OVERRIDE {
220 public_reset_packet_.reset(new QuicPublicResetPacket(packet)); 203 public_reset_packet_.reset(new QuicPublicResetPacket(packet));
221 } 204 }
222 205
223 virtual void OnVersionNegotiationPacket( 206 virtual void OnVersionNegotiationPacket(
224 const QuicVersionNegotiationPacket& packet) OVERRIDE { 207 const QuicVersionNegotiationPacket& packet) OVERRIDE {
225 version_negotiation_packet_.reset(new QuicVersionNegotiationPacket(packet)); 208 version_negotiation_packet_.reset(new QuicVersionNegotiationPacket(packet));
226 } 209 }
227 210
228 virtual void OnRevivedPacket() OVERRIDE { 211 virtual void OnRevivedPacket() OVERRIDE { ++revived_packets_; }
229 ++revived_packets_;
230 }
231 212
232 virtual bool OnProtocolVersionMismatch(QuicVersion version) OVERRIDE { 213 virtual bool OnProtocolVersionMismatch(QuicVersion version) OVERRIDE {
233 DVLOG(1) << "QuicFramer Version Mismatch, version: " << version; 214 DVLOG(1) << "QuicFramer Version Mismatch, version: " << version;
234 ++version_mismatch_; 215 ++version_mismatch_;
235 return true; 216 return true;
236 } 217 }
237 218
238 virtual bool OnUnauthenticatedPublicHeader( 219 virtual bool OnUnauthenticatedPublicHeader(
239 const QuicPacketPublicHeader& header) OVERRIDE { 220 const QuicPacketPublicHeader& header) OVERRIDE {
240 public_header_.reset(new QuicPacketPublicHeader(header)); 221 public_header_.reset(new QuicPacketPublicHeader(header));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 ++frame_count_; 269 ++frame_count_;
289 ping_frames_.push_back(new QuicPingFrame(frame)); 270 ping_frames_.push_back(new QuicPingFrame(frame));
290 return true; 271 return true;
291 } 272 }
292 273
293 virtual void OnFecData(const QuicFecData& fec) OVERRIDE { 274 virtual void OnFecData(const QuicFecData& fec) OVERRIDE {
294 ++fec_count_; 275 ++fec_count_;
295 fec_data_.push_back(new QuicFecData(fec)); 276 fec_data_.push_back(new QuicFecData(fec));
296 } 277 }
297 278
298 virtual void OnPacketComplete() OVERRIDE { 279 virtual void OnPacketComplete() OVERRIDE { ++complete_packets_; }
299 ++complete_packets_;
300 }
301 280
302 virtual bool OnRstStreamFrame(const QuicRstStreamFrame& frame) OVERRIDE { 281 virtual bool OnRstStreamFrame(const QuicRstStreamFrame& frame) OVERRIDE {
303 rst_stream_frame_ = frame; 282 rst_stream_frame_ = frame;
304 return true; 283 return true;
305 } 284 }
306 285
307 virtual bool OnConnectionCloseFrame( 286 virtual bool OnConnectionCloseFrame(
308 const QuicConnectionCloseFrame& frame) OVERRIDE { 287 const QuicConnectionCloseFrame& frame) OVERRIDE {
309 connection_close_frame_ = frame; 288 connection_close_frame_ = frame;
310 return true; 289 return true;
311 } 290 }
312 291
313 virtual bool OnGoAwayFrame(const QuicGoAwayFrame& frame) OVERRIDE { 292 virtual bool OnGoAwayFrame(const QuicGoAwayFrame& frame) OVERRIDE {
314 goaway_frame_ = frame; 293 goaway_frame_ = frame;
315 return true; 294 return true;
316 } 295 }
317 296
318 virtual bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) 297 virtual bool OnWindowUpdateFrame(
319 OVERRIDE { 298 const QuicWindowUpdateFrame& frame) OVERRIDE {
320 window_update_frame_ = frame; 299 window_update_frame_ = frame;
321 return true; 300 return true;
322 } 301 }
323 302
324 virtual bool OnBlockedFrame(const QuicBlockedFrame& frame) OVERRIDE { 303 virtual bool OnBlockedFrame(const QuicBlockedFrame& frame) OVERRIDE {
325 blocked_frame_ = frame; 304 blocked_frame_ = frame;
326 return true; 305 return true;
327 } 306 }
328 307
329 // Counters from the visitor_ callbacks. 308 // Counters from the visitor_ callbacks.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 framer_.set_version(version_); 345 framer_.set_version(version_);
367 framer_.SetDecrypter(decrypter_, ENCRYPTION_NONE); 346 framer_.SetDecrypter(decrypter_, ENCRYPTION_NONE);
368 framer_.SetEncrypter(ENCRYPTION_NONE, encrypter_); 347 framer_.SetEncrypter(ENCRYPTION_NONE, encrypter_);
369 framer_.set_visitor(&visitor_); 348 framer_.set_visitor(&visitor_);
370 framer_.set_received_entropy_calculator(&entropy_calculator_); 349 framer_.set_received_entropy_calculator(&entropy_calculator_);
371 } 350 }
372 351
373 // Helper function to get unsigned char representation of digit in the 352 // Helper function to get unsigned char representation of digit in the
374 // units place of the current QUIC version number. 353 // units place of the current QUIC version number.
375 unsigned char GetQuicVersionDigitOnes() { 354 unsigned char GetQuicVersionDigitOnes() {
376 return static_cast<unsigned char> ('0' + version_%10); 355 return static_cast<unsigned char>('0' + version_ % 10);
377 } 356 }
378 357
379 // Helper function to get unsigned char representation of digit in the 358 // Helper function to get unsigned char representation of digit in the
380 // tens place of the current QUIC version number. 359 // tens place of the current QUIC version number.
381 unsigned char GetQuicVersionDigitTens() { 360 unsigned char GetQuicVersionDigitTens() {
382 return static_cast<unsigned char> ('0' + (version_/10)%10); 361 return static_cast<unsigned char>('0' + (version_ / 10) % 10);
383 } 362 }
384 363
385 bool CheckEncryption(QuicPacketSequenceNumber sequence_number, 364 bool CheckEncryption(QuicPacketSequenceNumber sequence_number,
386 QuicPacket* packet) { 365 QuicPacket* packet) {
387 if (sequence_number != encrypter_->sequence_number_) { 366 if (sequence_number != encrypter_->sequence_number_) {
388 LOG(ERROR) << "Encrypted incorrect packet sequence number. expected " 367 LOG(ERROR) << "Encrypted incorrect packet sequence number. expected "
389 << sequence_number << " actual: " 368 << sequence_number
390 << encrypter_->sequence_number_; 369 << " actual: " << encrypter_->sequence_number_;
391 return false; 370 return false;
392 } 371 }
393 if (packet->AssociatedData() != encrypter_->associated_data_) { 372 if (packet->AssociatedData() != encrypter_->associated_data_) {
394 LOG(ERROR) << "Encrypted incorrect associated data. expected " 373 LOG(ERROR) << "Encrypted incorrect associated data. expected "
395 << packet->AssociatedData() << " actual: " 374 << packet->AssociatedData()
396 << encrypter_->associated_data_; 375 << " actual: " << encrypter_->associated_data_;
397 return false; 376 return false;
398 } 377 }
399 if (packet->Plaintext() != encrypter_->plaintext_) { 378 if (packet->Plaintext() != encrypter_->plaintext_) {
400 LOG(ERROR) << "Encrypted incorrect plaintext data. expected " 379 LOG(ERROR) << "Encrypted incorrect plaintext data. expected "
401 << packet->Plaintext() << " actual: " 380 << packet->Plaintext()
402 << encrypter_->plaintext_; 381 << " actual: " << encrypter_->plaintext_;
403 return false; 382 return false;
404 } 383 }
405 return true; 384 return true;
406 } 385 }
407 386
408 bool CheckDecryption(const QuicEncryptedPacket& encrypted, 387 bool CheckDecryption(const QuicEncryptedPacket& encrypted,
409 bool includes_version) { 388 bool includes_version) {
410 if (visitor_.header_->packet_sequence_number != 389 if (visitor_.header_->packet_sequence_number !=
411 decrypter_->sequence_number_) { 390 decrypter_->sequence_number_) {
412 LOG(ERROR) << "Decrypted incorrect packet sequence number. expected " 391 LOG(ERROR) << "Decrypted incorrect packet sequence number. expected "
413 << visitor_.header_->packet_sequence_number << " actual: " 392 << visitor_.header_->packet_sequence_number
414 << decrypter_->sequence_number_; 393 << " actual: " << decrypter_->sequence_number_;
415 return false; 394 return false;
416 } 395 }
417 if (QuicFramer::GetAssociatedDataFromEncryptedPacket( 396 if (QuicFramer::GetAssociatedDataFromEncryptedPacket(
418 encrypted, PACKET_8BYTE_CONNECTION_ID, 397 encrypted,
419 includes_version, PACKET_6BYTE_SEQUENCE_NUMBER) != 398 PACKET_8BYTE_CONNECTION_ID,
420 decrypter_->associated_data_) { 399 includes_version,
400 PACKET_6BYTE_SEQUENCE_NUMBER) != decrypter_->associated_data_) {
421 LOG(ERROR) << "Decrypted incorrect associated data. expected " 401 LOG(ERROR) << "Decrypted incorrect associated data. expected "
422 << QuicFramer::GetAssociatedDataFromEncryptedPacket( 402 << QuicFramer::GetAssociatedDataFromEncryptedPacket(
423 encrypted, PACKET_8BYTE_CONNECTION_ID, 403 encrypted,
424 includes_version, PACKET_6BYTE_SEQUENCE_NUMBER) 404 PACKET_8BYTE_CONNECTION_ID,
405 includes_version,
406 PACKET_6BYTE_SEQUENCE_NUMBER)
425 << " actual: " << decrypter_->associated_data_; 407 << " actual: " << decrypter_->associated_data_;
426 return false; 408 return false;
427 } 409 }
428 StringPiece ciphertext(encrypted.AsStringPiece().substr( 410 StringPiece ciphertext(encrypted.AsStringPiece().substr(
429 GetStartOfEncryptedData(PACKET_8BYTE_CONNECTION_ID, includes_version, 411 GetStartOfEncryptedData(PACKET_8BYTE_CONNECTION_ID,
412 includes_version,
430 PACKET_6BYTE_SEQUENCE_NUMBER))); 413 PACKET_6BYTE_SEQUENCE_NUMBER)));
431 if (ciphertext != decrypter_->ciphertext_) { 414 if (ciphertext != decrypter_->ciphertext_) {
432 LOG(ERROR) << "Decrypted incorrect ciphertext data. expected " 415 LOG(ERROR) << "Decrypted incorrect ciphertext data. expected "
433 << ciphertext << " actual: " 416 << ciphertext << " actual: " << decrypter_->ciphertext_;
434 << decrypter_->ciphertext_;
435 return false; 417 return false;
436 } 418 }
437 return true; 419 return true;
438 } 420 }
439 421
440 char* AsChars(unsigned char* data) { 422 char* AsChars(unsigned char* data) { return reinterpret_cast<char*>(data); }
441 return reinterpret_cast<char*>(data);
442 }
443 423
444 void CheckProcessingFails(unsigned char* packet, 424 void CheckProcessingFails(unsigned char* packet,
445 size_t len, 425 size_t len,
446 string expected_error, 426 string expected_error,
447 QuicErrorCode error_code) { 427 QuicErrorCode error_code) {
448 QuicEncryptedPacket encrypted(AsChars(packet), len, false); 428 QuicEncryptedPacket encrypted(AsChars(packet), len, false);
449 EXPECT_FALSE(framer_.ProcessPacket(encrypted)) << "len: " << len; 429 EXPECT_FALSE(framer_.ProcessPacket(encrypted)) << "len: " << len;
450 EXPECT_EQ(expected_error, framer_.detailed_error()) << "len: " << len; 430 EXPECT_EQ(expected_error, framer_.detailed_error()) << "len: " << len;
451 EXPECT_EQ(error_code, framer_.error()) << "len: " << len; 431 EXPECT_EQ(error_code, framer_.error()) << "len: " << len;
452 } 432 }
453 433
454 // Checks if the supplied string matches data in the supplied StreamFrame. 434 // Checks if the supplied string matches data in the supplied StreamFrame.
455 void CheckStreamFrameData(string str, QuicStreamFrame* frame) { 435 void CheckStreamFrameData(string str, QuicStreamFrame* frame) {
456 scoped_ptr<string> frame_data(frame->GetDataAsString()); 436 scoped_ptr<string> frame_data(frame->GetDataAsString());
457 EXPECT_EQ(str, *frame_data); 437 EXPECT_EQ(str, *frame_data);
458 } 438 }
459 439
460 void CheckStreamFrameBoundaries(unsigned char* packet, 440 void CheckStreamFrameBoundaries(unsigned char* packet,
461 size_t stream_id_size, 441 size_t stream_id_size,
462 bool include_version) { 442 bool include_version) {
463 // Now test framing boundaries 443 // Now test framing boundaries
464 for (size_t i = kQuicFrameTypeSize; 444 for (size_t i = kQuicFrameTypeSize;
465 i < GetMinStreamFrameSize(framer_.version()); ++i) { 445 i < GetMinStreamFrameSize(framer_.version());
446 ++i) {
466 string expected_error; 447 string expected_error;
467 if (i < kQuicFrameTypeSize + stream_id_size) { 448 if (i < kQuicFrameTypeSize + stream_id_size) {
468 expected_error = "Unable to read stream_id."; 449 expected_error = "Unable to read stream_id.";
469 } else if (i < kQuicFrameTypeSize + stream_id_size + 450 } else if (i < kQuicFrameTypeSize + stream_id_size +
470 kQuicMaxStreamOffsetSize) { 451 kQuicMaxStreamOffsetSize) {
471 expected_error = "Unable to read offset."; 452 expected_error = "Unable to read offset.";
472 } else { 453 } else {
473 expected_error = "Unable to read frame data."; 454 expected_error = "Unable to read frame data.";
474 } 455 }
475 CheckProcessingFails( 456 CheckProcessingFails(packet,
476 packet, 457 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
477 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, include_version, 458 include_version,
478 PACKET_6BYTE_SEQUENCE_NUMBER, 459 PACKET_6BYTE_SEQUENCE_NUMBER,
479 NOT_IN_FEC_GROUP), 460 NOT_IN_FEC_GROUP),
480 expected_error, QUIC_INVALID_STREAM_DATA); 461 expected_error,
462 QUIC_INVALID_STREAM_DATA);
481 } 463 }
482 } 464 }
483 465
484 void CheckCalculatePacketSequenceNumber( 466 void CheckCalculatePacketSequenceNumber(
485 QuicPacketSequenceNumber expected_sequence_number, 467 QuicPacketSequenceNumber expected_sequence_number,
486 QuicPacketSequenceNumber last_sequence_number) { 468 QuicPacketSequenceNumber last_sequence_number) {
487 QuicPacketSequenceNumber wire_sequence_number = 469 QuicPacketSequenceNumber wire_sequence_number =
488 expected_sequence_number & kMask; 470 expected_sequence_number & kMask;
489 QuicFramerPeer::SetLastSequenceNumber(&framer_, last_sequence_number); 471 QuicFramerPeer::SetLastSequenceNumber(&framer_, last_sequence_number);
490 EXPECT_EQ(expected_sequence_number, 472 EXPECT_EQ(expected_sequence_number,
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 585
604 // Large numbers should not wrap either. 586 // Large numbers should not wrap either.
605 for (uint64 j = 0; j < 10; j++) { 587 for (uint64 j = 0; j < 10; j++) {
606 uint64 num = kEpoch - 1 - j; 588 uint64 num = kEpoch - 1 - j;
607 CheckCalculatePacketSequenceNumber(max_epoch + num, last); 589 CheckCalculatePacketSequenceNumber(max_epoch + num, last);
608 } 590 }
609 } 591 }
610 } 592 }
611 593
612 TEST_P(QuicFramerTest, EmptyPacket) { 594 TEST_P(QuicFramerTest, EmptyPacket) {
613 char packet[] = { 0x00 }; 595 char packet[] = {0x00};
614 QuicEncryptedPacket encrypted(packet, 0, false); 596 QuicEncryptedPacket encrypted(packet, 0, false);
615 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 597 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
616 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); 598 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error());
617 } 599 }
618 600
619 TEST_P(QuicFramerTest, LargePacket) { 601 TEST_P(QuicFramerTest, LargePacket) {
620 unsigned char packet[kMaxPacketSize + 1] = { 602 unsigned char packet[kMaxPacketSize + 1] = {
621 // public flags (8 byte connection_id) 603 // public flags (8 byte connection_id)
622 0x3C, 604 0x3C,
623 // connection_id 605 // connection_id
624 0x10, 0x32, 0x54, 0x76, 606 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
625 0x98, 0xBA, 0xDC, 0xFE, 607 // packet sequence number
626 // packet sequence number 608 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
627 0xBC, 0x9A, 0x78, 0x56, 609 // private flags
628 0x34, 0x12, 610 0x00,
629 // private flags
630 0x00,
631 }; 611 };
632 612
633 memset(packet + GetPacketHeaderSize( 613 memset(packet + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
634 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 614 !kIncludeVersion,
635 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 0, 615 PACKET_6BYTE_SEQUENCE_NUMBER,
636 kMaxPacketSize - GetPacketHeaderSize( 616 NOT_IN_FEC_GROUP),
637 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 617 0,
638 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP) + 1); 618 kMaxPacketSize - GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
619 !kIncludeVersion,
620 PACKET_6BYTE_SEQUENCE_NUMBER,
621 NOT_IN_FEC_GROUP) +
622 1);
639 623
640 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 624 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
641 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 625 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
642 626
643 ASSERT_TRUE(visitor_.header_.get()); 627 ASSERT_TRUE(visitor_.header_.get());
644 // Make sure we've parsed the packet header, so we can send an error. 628 // Make sure we've parsed the packet header, so we can send an error.
645 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210), 629 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
646 visitor_.header_->public_header.connection_id); 630 visitor_.header_->public_header.connection_id);
647 // Make sure the correct error is propagated. 631 // Make sure the correct error is propagated.
648 EXPECT_EQ(QUIC_PACKET_TOO_LARGE, framer_.error()); 632 EXPECT_EQ(QUIC_PACKET_TOO_LARGE, framer_.error());
649 } 633 }
650 634
651 TEST_P(QuicFramerTest, PacketHeader) { 635 TEST_P(QuicFramerTest, PacketHeader) {
652 unsigned char packet[] = { 636 unsigned char packet[] = {// public flags (8 byte connection_id)
653 // public flags (8 byte connection_id) 637 0x3C,
654 0x3C, 638 // connection_id
655 // connection_id 639 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
656 0x10, 0x32, 0x54, 0x76, 640 // packet sequence number
657 0x98, 0xBA, 0xDC, 0xFE, 641 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
658 // packet sequence number 642 // private flags
659 0xBC, 0x9A, 0x78, 0x56, 643 0x00,
660 0x34, 0x12,
661 // private flags
662 0x00,
663 }; 644 };
664 645
665 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 646 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
666 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 647 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
667 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); 648 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
668 ASSERT_TRUE(visitor_.header_.get()); 649 ASSERT_TRUE(visitor_.header_.get());
669 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210), 650 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
670 visitor_.header_->public_header.connection_id); 651 visitor_.header_->public_header.connection_id);
671 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 652 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
672 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 653 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
673 EXPECT_FALSE(visitor_.header_->fec_flag); 654 EXPECT_FALSE(visitor_.header_->fec_flag);
674 EXPECT_FALSE(visitor_.header_->entropy_flag); 655 EXPECT_FALSE(visitor_.header_->entropy_flag);
675 EXPECT_EQ(0, visitor_.header_->entropy_hash); 656 EXPECT_EQ(0, visitor_.header_->entropy_hash);
676 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 657 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
677 visitor_.header_->packet_sequence_number); 658 visitor_.header_->packet_sequence_number);
678 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); 659 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
679 EXPECT_EQ(0x00u, visitor_.header_->fec_group); 660 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
680 661
681 // Now test framing boundaries 662 // Now test framing boundaries
682 for (size_t i = 0; 663 for (size_t i = 0; i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
683 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 664 !kIncludeVersion,
684 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); 665 PACKET_6BYTE_SEQUENCE_NUMBER,
666 NOT_IN_FEC_GROUP);
685 ++i) { 667 ++i) {
686 string expected_error; 668 string expected_error;
687 if (i < kConnectionIdOffset) { 669 if (i < kConnectionIdOffset) {
688 expected_error = "Unable to read public flags."; 670 expected_error = "Unable to read public flags.";
689 } else if (i < GetSequenceNumberOffset(!kIncludeVersion)) { 671 } else if (i < GetSequenceNumberOffset(!kIncludeVersion)) {
690 expected_error = "Unable to read ConnectionId."; 672 expected_error = "Unable to read ConnectionId.";
691 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion)) { 673 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion)) {
692 expected_error = "Unable to read sequence number."; 674 expected_error = "Unable to read sequence number.";
693 } else if (i < GetFecGroupOffset(!kIncludeVersion)) { 675 } else if (i < GetFecGroupOffset(!kIncludeVersion)) {
694 expected_error = "Unable to read private flags."; 676 expected_error = "Unable to read private flags.";
695 } else { 677 } else {
696 expected_error = "Unable to read first fec protected packet offset."; 678 expected_error = "Unable to read first fec protected packet offset.";
697 } 679 }
698 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); 680 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
699 } 681 }
700 } 682 }
701 683
702 TEST_P(QuicFramerTest, PacketHeaderWith4ByteConnectionId) { 684 TEST_P(QuicFramerTest, PacketHeaderWith4ByteConnectionId) {
703 QuicFramerPeer::SetLastSerializedConnectionId( 685 QuicFramerPeer::SetLastSerializedConnectionId(
704 &framer_, GG_UINT64_C(0xFEDCBA9876543210)); 686 &framer_, GG_UINT64_C(0xFEDCBA9876543210));
705 687
706 unsigned char packet[] = { 688 unsigned char packet[] = {// public flags (4 byte connection_id)
707 // public flags (4 byte connection_id) 689 0x38,
708 0x38, 690 // connection_id
709 // connection_id 691 0x10, 0x32, 0x54, 0x76,
710 0x10, 0x32, 0x54, 0x76, 692 // packet sequence number
711 // packet sequence number 693 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
712 0xBC, 0x9A, 0x78, 0x56, 694 // private flags
713 0x34, 0x12, 695 0x00,
714 // private flags
715 0x00,
716 }; 696 };
717 697
718 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 698 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
719 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 699 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
720 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); 700 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
721 ASSERT_TRUE(visitor_.header_.get()); 701 ASSERT_TRUE(visitor_.header_.get());
722 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210), 702 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
723 visitor_.header_->public_header.connection_id); 703 visitor_.header_->public_header.connection_id);
724 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 704 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
725 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 705 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
726 EXPECT_FALSE(visitor_.header_->fec_flag); 706 EXPECT_FALSE(visitor_.header_->fec_flag);
727 EXPECT_FALSE(visitor_.header_->entropy_flag); 707 EXPECT_FALSE(visitor_.header_->entropy_flag);
728 EXPECT_EQ(0, visitor_.header_->entropy_hash); 708 EXPECT_EQ(0, visitor_.header_->entropy_hash);
729 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 709 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
730 visitor_.header_->packet_sequence_number); 710 visitor_.header_->packet_sequence_number);
731 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); 711 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
732 EXPECT_EQ(0x00u, visitor_.header_->fec_group); 712 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
733 713
734 // Now test framing boundaries 714 // Now test framing boundaries
735 for (size_t i = 0; 715 for (size_t i = 0; i < GetPacketHeaderSize(PACKET_4BYTE_CONNECTION_ID,
736 i < GetPacketHeaderSize(PACKET_4BYTE_CONNECTION_ID, !kIncludeVersion, 716 !kIncludeVersion,
737 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); 717 PACKET_6BYTE_SEQUENCE_NUMBER,
718 NOT_IN_FEC_GROUP);
738 ++i) { 719 ++i) {
739 string expected_error; 720 string expected_error;
740 if (i < kConnectionIdOffset) { 721 if (i < kConnectionIdOffset) {
741 expected_error = "Unable to read public flags."; 722 expected_error = "Unable to read public flags.";
742 } else if (i < GetSequenceNumberOffset(PACKET_4BYTE_CONNECTION_ID, 723 } else if (i < GetSequenceNumberOffset(PACKET_4BYTE_CONNECTION_ID,
743 !kIncludeVersion)) { 724 !kIncludeVersion)) {
744 expected_error = "Unable to read ConnectionId."; 725 expected_error = "Unable to read ConnectionId.";
745 } else if (i < GetPrivateFlagsOffset(PACKET_4BYTE_CONNECTION_ID, 726 } else if (i < GetPrivateFlagsOffset(PACKET_4BYTE_CONNECTION_ID,
746 !kIncludeVersion)) { 727 !kIncludeVersion)) {
747 expected_error = "Unable to read sequence number."; 728 expected_error = "Unable to read sequence number.";
748 } else if (i < GetFecGroupOffset(PACKET_4BYTE_CONNECTION_ID, 729 } else if (i < GetFecGroupOffset(PACKET_4BYTE_CONNECTION_ID,
749 !kIncludeVersion)) { 730 !kIncludeVersion)) {
750 expected_error = "Unable to read private flags."; 731 expected_error = "Unable to read private flags.";
751 } else { 732 } else {
752 expected_error = "Unable to read first fec protected packet offset."; 733 expected_error = "Unable to read first fec protected packet offset.";
753 } 734 }
754 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); 735 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
755 } 736 }
756 } 737 }
757 738
758 TEST_P(QuicFramerTest, PacketHeader1ByteConnectionId) { 739 TEST_P(QuicFramerTest, PacketHeader1ByteConnectionId) {
759 QuicFramerPeer::SetLastSerializedConnectionId( 740 QuicFramerPeer::SetLastSerializedConnectionId(
760 &framer_, GG_UINT64_C(0xFEDCBA9876543210)); 741 &framer_, GG_UINT64_C(0xFEDCBA9876543210));
761 742
762 unsigned char packet[] = { 743 unsigned char packet[] = {// public flags (1 byte connection_id)
763 // public flags (1 byte connection_id) 744 0x34,
764 0x34, 745 // connection_id
765 // connection_id 746 0x10,
766 0x10, 747 // packet sequence number
767 // packet sequence number 748 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
768 0xBC, 0x9A, 0x78, 0x56, 749 // private flags
769 0x34, 0x12, 750 0x00,
770 // private flags
771 0x00,
772 }; 751 };
773 752
774 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 753 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
775 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 754 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
776 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); 755 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
777 ASSERT_TRUE(visitor_.header_.get()); 756 ASSERT_TRUE(visitor_.header_.get());
778 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210), 757 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
779 visitor_.header_->public_header.connection_id); 758 visitor_.header_->public_header.connection_id);
780 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 759 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
781 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 760 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
782 EXPECT_FALSE(visitor_.header_->fec_flag); 761 EXPECT_FALSE(visitor_.header_->fec_flag);
783 EXPECT_FALSE(visitor_.header_->entropy_flag); 762 EXPECT_FALSE(visitor_.header_->entropy_flag);
784 EXPECT_EQ(0, visitor_.header_->entropy_hash); 763 EXPECT_EQ(0, visitor_.header_->entropy_hash);
785 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 764 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
786 visitor_.header_->packet_sequence_number); 765 visitor_.header_->packet_sequence_number);
787 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); 766 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
788 EXPECT_EQ(0x00u, visitor_.header_->fec_group); 767 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
789 768
790 // Now test framing boundaries 769 // Now test framing boundaries
791 for (size_t i = 0; 770 for (size_t i = 0; i < GetPacketHeaderSize(PACKET_1BYTE_CONNECTION_ID,
792 i < GetPacketHeaderSize(PACKET_1BYTE_CONNECTION_ID, !kIncludeVersion, 771 !kIncludeVersion,
793 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); 772 PACKET_6BYTE_SEQUENCE_NUMBER,
773 NOT_IN_FEC_GROUP);
794 ++i) { 774 ++i) {
795 string expected_error; 775 string expected_error;
796 if (i < kConnectionIdOffset) { 776 if (i < kConnectionIdOffset) {
797 expected_error = "Unable to read public flags."; 777 expected_error = "Unable to read public flags.";
798 } else if (i < GetSequenceNumberOffset(PACKET_1BYTE_CONNECTION_ID, 778 } else if (i < GetSequenceNumberOffset(PACKET_1BYTE_CONNECTION_ID,
799 !kIncludeVersion)) { 779 !kIncludeVersion)) {
800 expected_error = "Unable to read ConnectionId."; 780 expected_error = "Unable to read ConnectionId.";
801 } else if (i < GetPrivateFlagsOffset(PACKET_1BYTE_CONNECTION_ID, 781 } else if (i < GetPrivateFlagsOffset(PACKET_1BYTE_CONNECTION_ID,
802 !kIncludeVersion)) { 782 !kIncludeVersion)) {
803 expected_error = "Unable to read sequence number."; 783 expected_error = "Unable to read sequence number.";
804 } else if (i < GetFecGroupOffset(PACKET_1BYTE_CONNECTION_ID, 784 } else if (i < GetFecGroupOffset(PACKET_1BYTE_CONNECTION_ID,
805 !kIncludeVersion)) { 785 !kIncludeVersion)) {
806 expected_error = "Unable to read private flags."; 786 expected_error = "Unable to read private flags.";
807 } else { 787 } else {
808 expected_error = "Unable to read first fec protected packet offset."; 788 expected_error = "Unable to read first fec protected packet offset.";
809 } 789 }
810 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); 790 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
811 } 791 }
812 } 792 }
813 793
814 TEST_P(QuicFramerTest, PacketHeaderWith0ByteConnectionId) { 794 TEST_P(QuicFramerTest, PacketHeaderWith0ByteConnectionId) {
815 QuicFramerPeer::SetLastSerializedConnectionId( 795 QuicFramerPeer::SetLastSerializedConnectionId(
816 &framer_, GG_UINT64_C(0xFEDCBA9876543210)); 796 &framer_, GG_UINT64_C(0xFEDCBA9876543210));
817 797
818 unsigned char packet[] = { 798 unsigned char packet[] = {// public flags (0 byte connection_id)
819 // public flags (0 byte connection_id) 799 0x30,
820 0x30, 800 // connection_id
821 // connection_id 801 // packet sequence number
822 // packet sequence number 802 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
823 0xBC, 0x9A, 0x78, 0x56, 803 // private flags
824 0x34, 0x12, 804 0x00,
825 // private flags
826 0x00,
827 }; 805 };
828 806
829 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 807 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
830 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 808 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
831 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); 809 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
832 ASSERT_TRUE(visitor_.header_.get()); 810 ASSERT_TRUE(visitor_.header_.get());
833 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210), 811 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
834 visitor_.header_->public_header.connection_id); 812 visitor_.header_->public_header.connection_id);
835 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 813 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
836 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 814 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
837 EXPECT_FALSE(visitor_.header_->fec_flag); 815 EXPECT_FALSE(visitor_.header_->fec_flag);
838 EXPECT_FALSE(visitor_.header_->entropy_flag); 816 EXPECT_FALSE(visitor_.header_->entropy_flag);
839 EXPECT_EQ(0, visitor_.header_->entropy_hash); 817 EXPECT_EQ(0, visitor_.header_->entropy_hash);
840 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 818 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
841 visitor_.header_->packet_sequence_number); 819 visitor_.header_->packet_sequence_number);
842 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); 820 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
843 EXPECT_EQ(0x00u, visitor_.header_->fec_group); 821 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
844 822
845 // Now test framing boundaries 823 // Now test framing boundaries
846 for (size_t i = 0; 824 for (size_t i = 0; i < GetPacketHeaderSize(PACKET_0BYTE_CONNECTION_ID,
847 i < GetPacketHeaderSize(PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, 825 !kIncludeVersion,
848 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); 826 PACKET_6BYTE_SEQUENCE_NUMBER,
827 NOT_IN_FEC_GROUP);
849 ++i) { 828 ++i) {
850 string expected_error; 829 string expected_error;
851 if (i < kConnectionIdOffset) { 830 if (i < kConnectionIdOffset) {
852 expected_error = "Unable to read public flags."; 831 expected_error = "Unable to read public flags.";
853 } else if (i < GetSequenceNumberOffset(PACKET_0BYTE_CONNECTION_ID, 832 } else if (i < GetSequenceNumberOffset(PACKET_0BYTE_CONNECTION_ID,
854 !kIncludeVersion)) { 833 !kIncludeVersion)) {
855 expected_error = "Unable to read ConnectionId."; 834 expected_error = "Unable to read ConnectionId.";
856 } else if (i < GetPrivateFlagsOffset(PACKET_0BYTE_CONNECTION_ID, 835 } else if (i < GetPrivateFlagsOffset(PACKET_0BYTE_CONNECTION_ID,
857 !kIncludeVersion)) { 836 !kIncludeVersion)) {
858 expected_error = "Unable to read sequence number."; 837 expected_error = "Unable to read sequence number.";
859 } else if (i < GetFecGroupOffset(PACKET_0BYTE_CONNECTION_ID, 838 } else if (i < GetFecGroupOffset(PACKET_0BYTE_CONNECTION_ID,
860 !kIncludeVersion)) { 839 !kIncludeVersion)) {
861 expected_error = "Unable to read private flags."; 840 expected_error = "Unable to read private flags.";
862 } else { 841 } else {
863 expected_error = "Unable to read first fec protected packet offset."; 842 expected_error = "Unable to read first fec protected packet offset.";
864 } 843 }
865 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); 844 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
866 } 845 }
867 } 846 }
868 847
869 TEST_P(QuicFramerTest, PacketHeaderWithVersionFlag) { 848 TEST_P(QuicFramerTest, PacketHeaderWithVersionFlag) {
870 unsigned char packet[] = { 849 unsigned char packet[] = {
871 // public flags (version) 850 // public flags (version)
872 0x3D, 851 0x3D,
873 // connection_id 852 // connection_id
874 0x10, 0x32, 0x54, 0x76, 853 0x10, 0x32, 0x54, 0x76,
875 0x98, 0xBA, 0xDC, 0xFE, 854 0x98, 0xBA, 0xDC, 0xFE,
876 // version tag 855 // version tag
877 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), 856 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
878 // packet sequence number 857 // packet sequence number
879 0xBC, 0x9A, 0x78, 0x56, 858 0xBC, 0x9A, 0x78, 0x56,
880 0x34, 0x12, 859 0x34, 0x12,
881 // private flags 860 // private flags
882 0x00, 861 0x00,
883 }; 862 };
884 863
885 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 864 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
886 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 865 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
887 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); 866 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
888 ASSERT_TRUE(visitor_.header_.get()); 867 ASSERT_TRUE(visitor_.header_.get());
889 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210), 868 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
890 visitor_.header_->public_header.connection_id); 869 visitor_.header_->public_header.connection_id);
891 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 870 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
892 EXPECT_TRUE(visitor_.header_->public_header.version_flag); 871 EXPECT_TRUE(visitor_.header_->public_header.version_flag);
893 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]); 872 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]);
894 EXPECT_FALSE(visitor_.header_->fec_flag); 873 EXPECT_FALSE(visitor_.header_->fec_flag);
895 EXPECT_FALSE(visitor_.header_->entropy_flag); 874 EXPECT_FALSE(visitor_.header_->entropy_flag);
896 EXPECT_EQ(0, visitor_.header_->entropy_hash); 875 EXPECT_EQ(0, visitor_.header_->entropy_hash);
897 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 876 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
898 visitor_.header_->packet_sequence_number); 877 visitor_.header_->packet_sequence_number);
899 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); 878 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
900 EXPECT_EQ(0x00u, visitor_.header_->fec_group); 879 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
901 880
902 // Now test framing boundaries 881 // Now test framing boundaries
903 for (size_t i = 0; 882 for (size_t i = 0; i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
904 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, kIncludeVersion, 883 kIncludeVersion,
905 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); 884 PACKET_6BYTE_SEQUENCE_NUMBER,
885 NOT_IN_FEC_GROUP);
906 ++i) { 886 ++i) {
907 string expected_error; 887 string expected_error;
908 if (i < kConnectionIdOffset) { 888 if (i < kConnectionIdOffset) {
909 expected_error = "Unable to read public flags."; 889 expected_error = "Unable to read public flags.";
910 } else if (i < kVersionOffset) { 890 } else if (i < kVersionOffset) {
911 expected_error = "Unable to read ConnectionId."; 891 expected_error = "Unable to read ConnectionId.";
912 } else if (i < GetSequenceNumberOffset(kIncludeVersion)) { 892 } else if (i < GetSequenceNumberOffset(kIncludeVersion)) {
913 expected_error = "Unable to read protocol version."; 893 expected_error = "Unable to read protocol version.";
914 } else if (i < GetPrivateFlagsOffset(kIncludeVersion)) { 894 } else if (i < GetPrivateFlagsOffset(kIncludeVersion)) {
915 expected_error = "Unable to read sequence number."; 895 expected_error = "Unable to read sequence number.";
916 } else if (i < GetFecGroupOffset(kIncludeVersion)) { 896 } else if (i < GetFecGroupOffset(kIncludeVersion)) {
917 expected_error = "Unable to read private flags."; 897 expected_error = "Unable to read private flags.";
918 } else { 898 } else {
919 expected_error = "Unable to read first fec protected packet offset."; 899 expected_error = "Unable to read first fec protected packet offset.";
920 } 900 }
921 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); 901 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
922 } 902 }
923 } 903 }
924 904
925 TEST_P(QuicFramerTest, PacketHeaderWith4ByteSequenceNumber) { 905 TEST_P(QuicFramerTest, PacketHeaderWith4ByteSequenceNumber) {
926 QuicFramerPeer::SetLastSequenceNumber(&framer_, 906 QuicFramerPeer::SetLastSequenceNumber(&framer_, GG_UINT64_C(0x123456789ABA));
927 GG_UINT64_C(0x123456789ABA));
928 907
929 unsigned char packet[] = { 908 unsigned char packet[] = {
930 // public flags (8 byte connection_id and 4 byte sequence number) 909 // public flags (8 byte connection_id and 4 byte sequence number)
931 0x2C, 910 0x2C,
932 // connection_id 911 // connection_id
933 0x10, 0x32, 0x54, 0x76, 912 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
934 0x98, 0xBA, 0xDC, 0xFE, 913 // packet sequence number
935 // packet sequence number 914 0xBC, 0x9A, 0x78, 0x56,
936 0xBC, 0x9A, 0x78, 0x56, 915 // private flags
937 // private flags 916 0x00,
938 0x00,
939 }; 917 };
940 918
941 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 919 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
942 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 920 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
943 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); 921 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
944 ASSERT_TRUE(visitor_.header_.get()); 922 ASSERT_TRUE(visitor_.header_.get());
945 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210), 923 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
946 visitor_.header_->public_header.connection_id); 924 visitor_.header_->public_header.connection_id);
947 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 925 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
948 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 926 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
949 EXPECT_FALSE(visitor_.header_->fec_flag); 927 EXPECT_FALSE(visitor_.header_->fec_flag);
950 EXPECT_FALSE(visitor_.header_->entropy_flag); 928 EXPECT_FALSE(visitor_.header_->entropy_flag);
951 EXPECT_EQ(0, visitor_.header_->entropy_hash); 929 EXPECT_EQ(0, visitor_.header_->entropy_hash);
952 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 930 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
953 visitor_.header_->packet_sequence_number); 931 visitor_.header_->packet_sequence_number);
954 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); 932 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
955 EXPECT_EQ(0x00u, visitor_.header_->fec_group); 933 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
956 934
957 // Now test framing boundaries 935 // Now test framing boundaries
958 for (size_t i = 0; 936 for (size_t i = 0; i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
959 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 937 !kIncludeVersion,
960 PACKET_4BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); 938 PACKET_4BYTE_SEQUENCE_NUMBER,
939 NOT_IN_FEC_GROUP);
961 ++i) { 940 ++i) {
962 string expected_error; 941 string expected_error;
963 if (i < kConnectionIdOffset) { 942 if (i < kConnectionIdOffset) {
964 expected_error = "Unable to read public flags."; 943 expected_error = "Unable to read public flags.";
965 } else if (i < GetSequenceNumberOffset(!kIncludeVersion)) { 944 } else if (i < GetSequenceNumberOffset(!kIncludeVersion)) {
966 expected_error = "Unable to read ConnectionId."; 945 expected_error = "Unable to read ConnectionId.";
967 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion, 946 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion,
968 PACKET_4BYTE_SEQUENCE_NUMBER)) { 947 PACKET_4BYTE_SEQUENCE_NUMBER)) {
969 expected_error = "Unable to read sequence number."; 948 expected_error = "Unable to read sequence number.";
970 } else if (i < GetFecGroupOffset(!kIncludeVersion, 949 } else if (i < GetFecGroupOffset(!kIncludeVersion,
971 PACKET_4BYTE_SEQUENCE_NUMBER)) { 950 PACKET_4BYTE_SEQUENCE_NUMBER)) {
972 expected_error = "Unable to read private flags."; 951 expected_error = "Unable to read private flags.";
973 } else { 952 } else {
974 expected_error = "Unable to read first fec protected packet offset."; 953 expected_error = "Unable to read first fec protected packet offset.";
975 } 954 }
976 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); 955 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
977 } 956 }
978 } 957 }
979 958
980 TEST_P(QuicFramerTest, PacketHeaderWith2ByteSequenceNumber) { 959 TEST_P(QuicFramerTest, PacketHeaderWith2ByteSequenceNumber) {
981 QuicFramerPeer::SetLastSequenceNumber(&framer_, 960 QuicFramerPeer::SetLastSequenceNumber(&framer_, GG_UINT64_C(0x123456789ABA));
982 GG_UINT64_C(0x123456789ABA));
983 961
984 unsigned char packet[] = { 962 unsigned char packet[] = {
985 // public flags (8 byte connection_id and 2 byte sequence number) 963 // public flags (8 byte connection_id and 2 byte sequence number)
986 0x1C, 964 0x1C,
987 // connection_id 965 // connection_id
988 0x10, 0x32, 0x54, 0x76, 966 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
989 0x98, 0xBA, 0xDC, 0xFE, 967 // packet sequence number
990 // packet sequence number 968 0xBC, 0x9A,
991 0xBC, 0x9A, 969 // private flags
992 // private flags 970 0x00,
993 0x00,
994 }; 971 };
995 972
996 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 973 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
997 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 974 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
998 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); 975 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
999 ASSERT_TRUE(visitor_.header_.get()); 976 ASSERT_TRUE(visitor_.header_.get());
1000 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210), 977 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
1001 visitor_.header_->public_header.connection_id); 978 visitor_.header_->public_header.connection_id);
1002 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 979 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
1003 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 980 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
1004 EXPECT_FALSE(visitor_.header_->fec_flag); 981 EXPECT_FALSE(visitor_.header_->fec_flag);
1005 EXPECT_FALSE(visitor_.header_->entropy_flag); 982 EXPECT_FALSE(visitor_.header_->entropy_flag);
1006 EXPECT_EQ(0, visitor_.header_->entropy_hash); 983 EXPECT_EQ(0, visitor_.header_->entropy_hash);
1007 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 984 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
1008 visitor_.header_->packet_sequence_number); 985 visitor_.header_->packet_sequence_number);
1009 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); 986 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
1010 EXPECT_EQ(0x00u, visitor_.header_->fec_group); 987 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
1011 988
1012 // Now test framing boundaries 989 // Now test framing boundaries
1013 for (size_t i = 0; 990 for (size_t i = 0; i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
1014 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 991 !kIncludeVersion,
1015 PACKET_2BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); 992 PACKET_2BYTE_SEQUENCE_NUMBER,
993 NOT_IN_FEC_GROUP);
1016 ++i) { 994 ++i) {
1017 string expected_error; 995 string expected_error;
1018 if (i < kConnectionIdOffset) { 996 if (i < kConnectionIdOffset) {
1019 expected_error = "Unable to read public flags."; 997 expected_error = "Unable to read public flags.";
1020 } else if (i < GetSequenceNumberOffset(!kIncludeVersion)) { 998 } else if (i < GetSequenceNumberOffset(!kIncludeVersion)) {
1021 expected_error = "Unable to read ConnectionId."; 999 expected_error = "Unable to read ConnectionId.";
1022 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion, 1000 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion,
1023 PACKET_2BYTE_SEQUENCE_NUMBER)) { 1001 PACKET_2BYTE_SEQUENCE_NUMBER)) {
1024 expected_error = "Unable to read sequence number."; 1002 expected_error = "Unable to read sequence number.";
1025 } else if (i < GetFecGroupOffset(!kIncludeVersion, 1003 } else if (i < GetFecGroupOffset(!kIncludeVersion,
1026 PACKET_2BYTE_SEQUENCE_NUMBER)) { 1004 PACKET_2BYTE_SEQUENCE_NUMBER)) {
1027 expected_error = "Unable to read private flags."; 1005 expected_error = "Unable to read private flags.";
1028 } else { 1006 } else {
1029 expected_error = "Unable to read first fec protected packet offset."; 1007 expected_error = "Unable to read first fec protected packet offset.";
1030 } 1008 }
1031 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); 1009 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
1032 } 1010 }
1033 } 1011 }
1034 1012
1035 TEST_P(QuicFramerTest, PacketHeaderWith1ByteSequenceNumber) { 1013 TEST_P(QuicFramerTest, PacketHeaderWith1ByteSequenceNumber) {
1036 QuicFramerPeer::SetLastSequenceNumber(&framer_, 1014 QuicFramerPeer::SetLastSequenceNumber(&framer_, GG_UINT64_C(0x123456789ABA));
1037 GG_UINT64_C(0x123456789ABA));
1038 1015
1039 unsigned char packet[] = { 1016 unsigned char packet[] = {
1040 // public flags (8 byte connection_id and 1 byte sequence number) 1017 // public flags (8 byte connection_id and 1 byte sequence number)
1041 0x0C, 1018 0x0C,
1042 // connection_id 1019 // connection_id
1043 0x10, 0x32, 0x54, 0x76, 1020 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1044 0x98, 0xBA, 0xDC, 0xFE, 1021 // packet sequence number
1045 // packet sequence number 1022 0xBC,
1046 0xBC, 1023 // private flags
1047 // private flags 1024 0x00,
1048 0x00,
1049 }; 1025 };
1050 1026
1051 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1027 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1052 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 1028 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
1053 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); 1029 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error());
1054 ASSERT_TRUE(visitor_.header_.get()); 1030 ASSERT_TRUE(visitor_.header_.get());
1055 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210), 1031 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
1056 visitor_.header_->public_header.connection_id); 1032 visitor_.header_->public_header.connection_id);
1057 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 1033 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
1058 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 1034 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
1059 EXPECT_FALSE(visitor_.header_->fec_flag); 1035 EXPECT_FALSE(visitor_.header_->fec_flag);
1060 EXPECT_FALSE(visitor_.header_->entropy_flag); 1036 EXPECT_FALSE(visitor_.header_->entropy_flag);
1061 EXPECT_EQ(0, visitor_.header_->entropy_hash); 1037 EXPECT_EQ(0, visitor_.header_->entropy_hash);
1062 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 1038 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
1063 visitor_.header_->packet_sequence_number); 1039 visitor_.header_->packet_sequence_number);
1064 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); 1040 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
1065 EXPECT_EQ(0x00u, visitor_.header_->fec_group); 1041 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
1066 1042
1067 // Now test framing boundaries 1043 // Now test framing boundaries
1068 for (size_t i = 0; 1044 for (size_t i = 0; i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
1069 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 1045 !kIncludeVersion,
1070 PACKET_1BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); 1046 PACKET_1BYTE_SEQUENCE_NUMBER,
1047 NOT_IN_FEC_GROUP);
1071 ++i) { 1048 ++i) {
1072 string expected_error; 1049 string expected_error;
1073 if (i < kConnectionIdOffset) { 1050 if (i < kConnectionIdOffset) {
1074 expected_error = "Unable to read public flags."; 1051 expected_error = "Unable to read public flags.";
1075 } else if (i < GetSequenceNumberOffset(!kIncludeVersion)) { 1052 } else if (i < GetSequenceNumberOffset(!kIncludeVersion)) {
1076 expected_error = "Unable to read ConnectionId."; 1053 expected_error = "Unable to read ConnectionId.";
1077 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion, 1054 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion,
1078 PACKET_1BYTE_SEQUENCE_NUMBER)) { 1055 PACKET_1BYTE_SEQUENCE_NUMBER)) {
1079 expected_error = "Unable to read sequence number."; 1056 expected_error = "Unable to read sequence number.";
1080 } else if (i < GetFecGroupOffset(!kIncludeVersion, 1057 } else if (i < GetFecGroupOffset(!kIncludeVersion,
1081 PACKET_1BYTE_SEQUENCE_NUMBER)) { 1058 PACKET_1BYTE_SEQUENCE_NUMBER)) {
1082 expected_error = "Unable to read private flags."; 1059 expected_error = "Unable to read private flags.";
1083 } else { 1060 } else {
1084 expected_error = "Unable to read first fec protected packet offset."; 1061 expected_error = "Unable to read first fec protected packet offset.";
1085 } 1062 }
1086 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); 1063 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
1087 } 1064 }
1088 } 1065 }
1089 1066
1090 TEST_P(QuicFramerTest, InvalidPublicFlag) { 1067 TEST_P(QuicFramerTest, InvalidPublicFlag) {
1091 unsigned char packet[] = { 1068 unsigned char packet[] = {
1092 // public flags: all flags set but the public reset flag and version flag. 1069 // public flags: all flags set but the public reset flag and version flag.
1093 0xFC, 1070 0xFC,
1094 // connection_id 1071 // connection_id
1095 0x10, 0x32, 0x54, 0x76, 1072 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1096 0x98, 0xBA, 0xDC, 0xFE, 1073 // packet sequence number
1097 // packet sequence number 1074 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
1098 0xBC, 0x9A, 0x78, 0x56, 1075 // private flags
1099 0x34, 0x12, 1076 0x00,
1100 // private flags
1101 0x00,
1102 1077
1103 // frame type (padding) 1078 // frame type (padding)
1104 0x00, 1079 0x00, 0x00, 0x00, 0x00, 0x00};
1105 0x00, 0x00, 0x00, 0x00
1106 };
1107 CheckProcessingFails(packet, 1080 CheckProcessingFails(packet,
1108 arraysize(packet), 1081 arraysize(packet),
1109 "Illegal public flags value.", 1082 "Illegal public flags value.",
1110 QUIC_INVALID_PACKET_HEADER); 1083 QUIC_INVALID_PACKET_HEADER);
1111 1084
1112 // Now turn off validation. 1085 // Now turn off validation.
1113 framer_.set_validate_flags(false); 1086 framer_.set_validate_flags(false);
1114 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1087 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1115 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1088 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1116 }; 1089 };
1117 1090
1118 TEST_P(QuicFramerTest, InvalidPublicFlagWithMatchingVersions) { 1091 TEST_P(QuicFramerTest, InvalidPublicFlagWithMatchingVersions) {
1119 unsigned char packet[] = { 1092 unsigned char packet[] = {
1120 // public flags (8 byte connection_id and version flag and an unknown flag) 1093 // public flags (8 byte connection_id and version flag and an unknown
1121 0x4D, 1094 // flag)
1122 // connection_id 1095 0x4D,
1123 0x10, 0x32, 0x54, 0x76, 1096 // connection_id
1124 0x98, 0xBA, 0xDC, 0xFE, 1097 0x10, 0x32, 0x54, 0x76, 0x98, 0x BA,
1125 // version tag 1098 0xDC, 0xFE,
1126 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), 1099 // version tag
1127 // packet sequence number 1100 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
1128 0xBC, 0x9A, 0x78, 0x56, 1101 // packet sequence number
1129 0x34, 0x12, 1102 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x 12,
1130 // private flags 1103 // private flags
1131 0x00, 1104 0x00,
1132 1105
1133 // frame type (padding) 1106 // frame type (padding)
1134 0x00, 1107 0x00, 0x00, 0x00, 0x00, 0x00};
1135 0x00, 0x00, 0x00, 0x00
1136 };
1137 CheckProcessingFails(packet, 1108 CheckProcessingFails(packet,
1138 arraysize(packet), 1109 arraysize(packet),
1139 "Illegal public flags value.", 1110 "Illegal public flags value.",
1140 QUIC_INVALID_PACKET_HEADER); 1111 QUIC_INVALID_PACKET_HEADER);
1141 }; 1112 };
1142 1113
1143 TEST_P(QuicFramerTest, LargePublicFlagWithMismatchedVersions) { 1114 TEST_P(QuicFramerTest, LargePublicFlagWithMismatchedVersions) {
1144 unsigned char packet[] = { 1115 unsigned char packet[] = {
1145 // public flags (8 byte connection_id, version flag and an unknown flag) 1116 // public flags (8 byte connection_id, version flag and an unknown flag)
1146 0x7D, 1117 0x7D,
1147 // connection_id 1118 // connection_id
1148 0x10, 0x32, 0x54, 0x76, 1119 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1149 0x98, 0xBA, 0xDC, 0xFE, 1120 // version tag
1150 // version tag 1121 'Q', '0', '0', '0',
1151 'Q', '0', '0', '0', 1122 // packet sequence number
1152 // packet sequence number 1123 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
1153 0xBC, 0x9A, 0x78, 0x56, 1124 // private flags
1154 0x34, 0x12, 1125 0x00,
1155 // private flags
1156 0x00,
1157 1126
1158 // frame type (padding frame) 1127 // frame type (padding frame)
1159 0x00, 1128 0x00, 0x00, 0x00, 0x00, 0x00};
1160 0x00, 0x00, 0x00, 0x00
1161 };
1162 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1129 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1163 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1130 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1164 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1131 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1165 ASSERT_TRUE(visitor_.header_.get()); 1132 ASSERT_TRUE(visitor_.header_.get());
1166 EXPECT_EQ(0, visitor_.frame_count_); 1133 EXPECT_EQ(0, visitor_.frame_count_);
1167 EXPECT_EQ(1, visitor_.version_mismatch_); 1134 EXPECT_EQ(1, visitor_.version_mismatch_);
1168 }; 1135 };
1169 1136
1170 TEST_P(QuicFramerTest, InvalidPrivateFlag) { 1137 TEST_P(QuicFramerTest, InvalidPrivateFlag) {
1171 unsigned char packet[] = { 1138 unsigned char packet[] = {// public flags (8 byte connection_id)
1172 // public flags (8 byte connection_id) 1139 0x3C,
1173 0x3C, 1140 // connection_id
1174 // connection_id 1141 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1175 0x10, 0x32, 0x54, 0x76, 1142 // packet sequence number
1176 0x98, 0xBA, 0xDC, 0xFE, 1143 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
1177 // packet sequence number 1144 // private flags
1178 0xBC, 0x9A, 0x78, 0x56, 1145 0x10,
1179 0x34, 0x12,
1180 // private flags
1181 0x10,
1182 1146
1183 // frame type (padding) 1147 // frame type (padding)
1184 0x00, 1148 0x00, 0x00, 0x00, 0x00, 0x00};
1185 0x00, 0x00, 0x00, 0x00
1186 };
1187 CheckProcessingFails(packet, 1149 CheckProcessingFails(packet,
1188 arraysize(packet), 1150 arraysize(packet),
1189 "Illegal private flags value.", 1151 "Illegal private flags value.",
1190 QUIC_INVALID_PACKET_HEADER); 1152 QUIC_INVALID_PACKET_HEADER);
1191 }; 1153 };
1192 1154
1193 TEST_P(QuicFramerTest, InvalidFECGroupOffset) { 1155 TEST_P(QuicFramerTest, InvalidFECGroupOffset) {
1194 unsigned char packet[] = { 1156 unsigned char packet[] = {// public flags (8 byte connection_id)
1195 // public flags (8 byte connection_id) 1157 0x3C,
1196 0x3C, 1158 // connection_id
1197 // connection_id 1159 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1198 0x10, 0x32, 0x54, 0x76, 1160 // packet sequence number
1199 0x98, 0xBA, 0xDC, 0xFE, 1161 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
1200 // packet sequence number 1162 // private flags (fec group)
1201 0x01, 0x00, 0x00, 0x00, 1163 0x02,
1202 0x00, 0x00, 1164 // first fec protected packet offset
1203 // private flags (fec group) 1165 0x10};
1204 0x02,
1205 // first fec protected packet offset
1206 0x10
1207 };
1208 CheckProcessingFails(packet, 1166 CheckProcessingFails(packet,
1209 arraysize(packet), 1167 arraysize(packet),
1210 "First fec protected packet offset must be less " 1168 "First fec protected packet offset must be less "
1211 "than the sequence number.", 1169 "than the sequence number.",
1212 QUIC_INVALID_PACKET_HEADER); 1170 QUIC_INVALID_PACKET_HEADER);
1213 }; 1171 };
1214 1172
1215 TEST_P(QuicFramerTest, PaddingFrame) { 1173 TEST_P(QuicFramerTest, PaddingFrame) {
1216 unsigned char packet[] = { 1174 unsigned char packet[] = {
1217 // public flags (8 byte connection_id) 1175 // public flags (8 byte connection_id)
1218 0x3C, 1176 0x3C,
1219 // connection_id 1177 // connection_id
1220 0x10, 0x32, 0x54, 0x76, 1178 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1221 0x98, 0xBA, 0xDC, 0xFE, 1179 // packet sequence number
1222 // packet sequence number 1180 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
1223 0xBC, 0x9A, 0x78, 0x56, 1181 // private flags
1224 0x34, 0x12, 1182 0x00,
1225 // private flags
1226 0x00,
1227 1183
1228 // frame type (padding frame) 1184 // frame type (padding frame)
1229 0x00, 1185 0x00,
1230 // Ignored data (which in this case is a stream frame) 1186 // Ignored data (which in this case is a stream frame)
1231 // frame type (stream frame with fin) 1187 // frame type (stream frame with fin)
1232 0xFF, 1188 0xFF,
1233 // stream id 1189 // stream id
1234 0x04, 0x03, 0x02, 0x01, 1190 0x04, 0x03, 0x02, 0x01,
1235 // offset 1191 // offset
1236 0x54, 0x76, 0x10, 0x32, 1192 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA,
1237 0xDC, 0xFE, 0x98, 0xBA, 1193 // data length
1238 // data length 1194 0x0c, 0x00,
1239 0x0c, 0x00, 1195 // data
1240 // data 1196 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!',
1241 'h', 'e', 'l', 'l',
1242 'o', ' ', 'w', 'o',
1243 'r', 'l', 'd', '!',
1244 }; 1197 };
1245 1198
1246 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1199 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1247 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1200 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1248 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1201 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1249 ASSERT_TRUE(visitor_.header_.get()); 1202 ASSERT_TRUE(visitor_.header_.get());
1250 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 1203 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1251 1204
1252 ASSERT_EQ(0u, visitor_.stream_frames_.size()); 1205 ASSERT_EQ(0u, visitor_.stream_frames_.size());
1253 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1206 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1254 // A packet with no frames is not acceptable. 1207 // A packet with no frames is not acceptable.
1255 CheckProcessingFails( 1208 CheckProcessingFails(packet,
1256 packet, 1209 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
1257 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 1210 !kIncludeVersion,
1258 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 1211 PACKET_6BYTE_SEQUENCE_NUMBER,
1259 "Packet has no frames.", QUIC_MISSING_PAYLOAD); 1212 NOT_IN_FEC_GROUP),
1213 "Packet has no frames.",
1214 QUIC_MISSING_PAYLOAD);
1260 } 1215 }
1261 1216
1262 TEST_P(QuicFramerTest, StreamFrame) { 1217 TEST_P(QuicFramerTest, StreamFrame) {
1263 unsigned char packet[] = { 1218 unsigned char packet[] = {// public flags (8 byte connection_id)
1264 // public flags (8 byte connection_id) 1219 0x3C,
1265 0x3C, 1220 // connection_id
1266 // connection_id 1221 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1267 0x10, 0x32, 0x54, 0x76, 1222 // packet sequence number
1268 0x98, 0xBA, 0xDC, 0xFE, 1223 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
1269 // packet sequence number 1224 // private flags
1270 0xBC, 0x9A, 0x78, 0x56, 1225 0x00,
1271 0x34, 0x12,
1272 // private flags
1273 0x00,
1274 1226
1275 // frame type (stream frame with fin) 1227 // frame type (stream frame with fin)
1276 0xFF, 1228 0xFF,
1277 // stream id 1229 // stream id
1278 0x04, 0x03, 0x02, 0x01, 1230 0x04, 0x03, 0x02, 0x01,
1279 // offset 1231 // offset
1280 0x54, 0x76, 0x10, 0x32, 1232 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA,
1281 0xDC, 0xFE, 0x98, 0xBA, 1233 // data length
1282 // data length 1234 0x0c, 0x00,
1283 0x0c, 0x00, 1235 // data
1284 // data 1236 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o',
1285 'h', 'e', 'l', 'l', 1237 'r', 'l', 'd', '!',
1286 'o', ' ', 'w', 'o',
1287 'r', 'l', 'd', '!',
1288 }; 1238 };
1289 1239
1290 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1240 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1291 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1241 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1292 1242
1293 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1243 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1294 ASSERT_TRUE(visitor_.header_.get()); 1244 ASSERT_TRUE(visitor_.header_.get());
1295 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 1245 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1296 1246
1297 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1247 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1298 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1248 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1299 EXPECT_EQ(static_cast<uint64>(0x01020304), 1249 EXPECT_EQ(static_cast<uint64>(0x01020304),
1300 visitor_.stream_frames_[0]->stream_id); 1250 visitor_.stream_frames_[0]->stream_id);
1301 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 1251 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1302 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), 1252 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1303 visitor_.stream_frames_[0]->offset); 1253 visitor_.stream_frames_[0]->offset);
1304 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); 1254 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1305 1255
1306 // Now test framing boundaries 1256 // Now test framing boundaries
1307 CheckStreamFrameBoundaries(packet, kQuicMaxStreamIdSize, !kIncludeVersion); 1257 CheckStreamFrameBoundaries(packet, kQuicMaxStreamIdSize, !kIncludeVersion);
1308 } 1258 }
1309 1259
1310 TEST_P(QuicFramerTest, StreamFrame3ByteStreamId) { 1260 TEST_P(QuicFramerTest, StreamFrame3ByteStreamId) {
1311 unsigned char packet[] = { 1261 unsigned char packet[] = {// public flags (8 byte connection_id)
1312 // public flags (8 byte connection_id) 1262 0x3C,
1313 0x3C, 1263 // connection_id
1314 // connection_id 1264 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1315 0x10, 0x32, 0x54, 0x76, 1265 // packet sequence number
1316 0x98, 0xBA, 0xDC, 0xFE, 1266 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
1317 // packet sequence number 1267 // private flags
1318 0xBC, 0x9A, 0x78, 0x56, 1268 0x00,
1319 0x34, 0x12,
1320 // private flags
1321 0x00,
1322 1269
1323 // frame type (stream frame with fin) 1270 // frame type (stream frame with fin)
1324 0xFE, 1271 0xFE,
1325 // stream id 1272 // stream id
1326 0x04, 0x03, 0x02, 1273 0x04, 0x03, 0x02,
1327 // offset 1274 // offset
1328 0x54, 0x76, 0x10, 0x32, 1275 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA,
1329 0xDC, 0xFE, 0x98, 0xBA, 1276 // data length
1330 // data length 1277 0x0c, 0x00,
1331 0x0c, 0x00, 1278 // data
1332 // data 1279 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o',
1333 'h', 'e', 'l', 'l', 1280 'r', 'l', 'd', '!',
1334 'o', ' ', 'w', 'o',
1335 'r', 'l', 'd', '!',
1336 }; 1281 };
1337 1282
1338 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1283 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1339 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1284 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1340 1285
1341 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1286 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1342 ASSERT_TRUE(visitor_.header_.get()); 1287 ASSERT_TRUE(visitor_.header_.get());
1343 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 1288 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1344 1289
1345 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1290 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1346 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1291 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1347 EXPECT_EQ(GG_UINT64_C(0x00020304), 1292 EXPECT_EQ(GG_UINT64_C(0x00020304), visitor_.stream_frames_[0]->stream_id);
1348 visitor_.stream_frames_[0]->stream_id);
1349 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 1293 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1350 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), 1294 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1351 visitor_.stream_frames_[0]->offset); 1295 visitor_.stream_frames_[0]->offset);
1352 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); 1296 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1353 1297
1354 // Now test framing boundaries 1298 // Now test framing boundaries
1355 const size_t stream_id_size = 3; 1299 const size_t stream_id_size = 3;
1356 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion); 1300 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion);
1357 } 1301 }
1358 1302
1359 TEST_P(QuicFramerTest, StreamFrame2ByteStreamId) { 1303 TEST_P(QuicFramerTest, StreamFrame2ByteStreamId) {
1360 unsigned char packet[] = { 1304 unsigned char packet[] = {// public flags (8 byte connection_id)
1361 // public flags (8 byte connection_id) 1305 0x3C,
1362 0x3C, 1306 // connection_id
1363 // connection_id 1307 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1364 0x10, 0x32, 0x54, 0x76, 1308 // packet sequence number
1365 0x98, 0xBA, 0xDC, 0xFE, 1309 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
1366 // packet sequence number 1310 // private flags
1367 0xBC, 0x9A, 0x78, 0x56, 1311 0x00,
1368 0x34, 0x12,
1369 // private flags
1370 0x00,
1371 1312
1372 // frame type (stream frame with fin) 1313 // frame type (stream frame with fin)
1373 0xFD, 1314 0xFD,
1374 // stream id 1315 // stream id
1375 0x04, 0x03, 1316 0x04, 0x03,
1376 // offset 1317 // offset
1377 0x54, 0x76, 0x10, 0x32, 1318 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA,
1378 0xDC, 0xFE, 0x98, 0xBA, 1319 // data length
1379 // data length 1320 0x0c, 0x00,
1380 0x0c, 0x00, 1321 // data
1381 // data 1322 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o',
1382 'h', 'e', 'l', 'l', 1323 'r', 'l', 'd', '!',
1383 'o', ' ', 'w', 'o',
1384 'r', 'l', 'd', '!',
1385 }; 1324 };
1386 1325
1387 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1326 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1388 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1327 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1389 1328
1390 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1329 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1391 ASSERT_TRUE(visitor_.header_.get()); 1330 ASSERT_TRUE(visitor_.header_.get());
1392 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 1331 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1393 1332
1394 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1333 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1395 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1334 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1396 EXPECT_EQ(static_cast<uint64>(0x00000304), 1335 EXPECT_EQ(static_cast<uint64>(0x00000304),
1397 visitor_.stream_frames_[0]->stream_id); 1336 visitor_.stream_frames_[0]->stream_id);
1398 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 1337 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1399 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), 1338 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1400 visitor_.stream_frames_[0]->offset); 1339 visitor_.stream_frames_[0]->offset);
1401 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); 1340 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1402 1341
1403 // Now test framing boundaries 1342 // Now test framing boundaries
1404 const size_t stream_id_size = 2; 1343 const size_t stream_id_size = 2;
1405 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion); 1344 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion);
1406 } 1345 }
1407 1346
1408 TEST_P(QuicFramerTest, StreamFrame1ByteStreamId) { 1347 TEST_P(QuicFramerTest, StreamFrame1ByteStreamId) {
1409 unsigned char packet[] = { 1348 unsigned char packet[] = {// public flags (8 byte connection_id)
1410 // public flags (8 byte connection_id) 1349 0x3C,
1411 0x3C, 1350 // connection_id
1412 // connection_id 1351 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1413 0x10, 0x32, 0x54, 0x76, 1352 // packet sequence number
1414 0x98, 0xBA, 0xDC, 0xFE, 1353 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
1415 // packet sequence number 1354 // private flags
1416 0xBC, 0x9A, 0x78, 0x56, 1355 0x00,
1417 0x34, 0x12,
1418 // private flags
1419 0x00,
1420 1356
1421 // frame type (stream frame with fin) 1357 // frame type (stream frame with fin)
1422 0xFC, 1358 0xFC,
1423 // stream id 1359 // stream id
1424 0x04, 1360 0x04,
1425 // offset 1361 // offset
1426 0x54, 0x76, 0x10, 0x32, 1362 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA,
1427 0xDC, 0xFE, 0x98, 0xBA, 1363 // data length
1428 // data length 1364 0x0c, 0x00,
1429 0x0c, 0x00, 1365 // data
1430 // data 1366 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o',
1431 'h', 'e', 'l', 'l', 1367 'r', 'l', 'd', '!',
1432 'o', ' ', 'w', 'o',
1433 'r', 'l', 'd', '!',
1434 }; 1368 };
1435 1369
1436 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1370 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1437 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1371 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1438 1372
1439 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1373 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1440 ASSERT_TRUE(visitor_.header_.get()); 1374 ASSERT_TRUE(visitor_.header_.get());
1441 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 1375 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1442 1376
1443 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1377 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1444 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1378 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1445 EXPECT_EQ(static_cast<uint64>(0x00000004), 1379 EXPECT_EQ(static_cast<uint64>(0x00000004),
1446 visitor_.stream_frames_[0]->stream_id); 1380 visitor_.stream_frames_[0]->stream_id);
1447 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 1381 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1448 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), 1382 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1449 visitor_.stream_frames_[0]->offset); 1383 visitor_.stream_frames_[0]->offset);
1450 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); 1384 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1451 1385
1452 // Now test framing boundaries 1386 // Now test framing boundaries
1453 const size_t stream_id_size = 1; 1387 const size_t stream_id_size = 1;
1454 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion); 1388 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion);
1455 } 1389 }
1456 1390
1457 TEST_P(QuicFramerTest, StreamFrameWithVersion) { 1391 TEST_P(QuicFramerTest, StreamFrameWithVersion) {
1458 unsigned char packet[] = { 1392 unsigned char packet[] = {
1459 // public flags (version, 8 byte connection_id) 1393 // public flags (version, 8 byte connection_id)
1460 0x3D, 1394 0x3D,
1461 // connection_id 1395 // connection_id
1462 0x10, 0x32, 0x54, 0x76, 1396 0x10, 0x32, 0x54, 0x76,
1463 0x98, 0xBA, 0xDC, 0xFE, 1397 0x98, 0xBA, 0xDC, 0xFE,
1464 // version tag 1398 // version tag
1465 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), 1399 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
1466 // packet sequence number 1400 // packet sequence number
1467 0xBC, 0x9A, 0x78, 0x56, 1401 0xBC, 0x9A, 0x78, 0x56,
1468 0x34, 0x12, 1402 0x34, 0x12,
1469 // private flags 1403 // private flags
1470 0x00, 1404 0x00,
1471 1405
1472 // frame type (stream frame with fin) 1406 // frame type (stream frame with fin)
1473 0xFF, 1407 0xFF,
1474 // stream id 1408 // stream id
1475 0x04, 0x03, 0x02, 0x01, 1409 0x04, 0x03, 0x02, 0x01,
1476 // offset 1410 // offset
1477 0x54, 0x76, 0x10, 0x32, 1411 0x54, 0x76, 0x10, 0x32,
1478 0xDC, 0xFE, 0x98, 0xBA, 1412 0xDC, 0xFE, 0x98, 0xBA,
1479 // data length 1413 // data length
1480 0x0c, 0x00, 1414 0x0c, 0x00,
1481 // data 1415 // data
1482 'h', 'e', 'l', 'l', 1416 'h', 'e', 'l', 'l',
1483 'o', ' ', 'w', 'o', 1417 'o', ' ', 'w', 'o',
1484 'r', 'l', 'd', '!', 1418 'r', 'l', 'd', '!',
1485 }; 1419 };
1486 1420
1487 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1421 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1488 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1422 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1489 1423
1490 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1424 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1491 ASSERT_TRUE(visitor_.header_.get()); 1425 ASSERT_TRUE(visitor_.header_.get());
1492 EXPECT_TRUE(visitor_.header_.get()->public_header.version_flag); 1426 EXPECT_TRUE(visitor_.header_.get()->public_header.version_flag);
1493 EXPECT_EQ(GetParam(), visitor_.header_.get()->public_header.versions[0]); 1427 EXPECT_EQ(GetParam(), visitor_.header_.get()->public_header.versions[0]);
1494 EXPECT_TRUE(CheckDecryption(encrypted, kIncludeVersion)); 1428 EXPECT_TRUE(CheckDecryption(encrypted, kIncludeVersion));
1495 1429
1496 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1430 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1497 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1431 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1498 EXPECT_EQ(static_cast<uint64>(0x01020304), 1432 EXPECT_EQ(static_cast<uint64>(0x01020304),
1499 visitor_.stream_frames_[0]->stream_id); 1433 visitor_.stream_frames_[0]->stream_id);
1500 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 1434 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1501 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), 1435 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1502 visitor_.stream_frames_[0]->offset); 1436 visitor_.stream_frames_[0]->offset);
1503 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); 1437 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1504 1438
1505 // Now test framing boundaries 1439 // Now test framing boundaries
1506 CheckStreamFrameBoundaries(packet, kQuicMaxStreamIdSize, kIncludeVersion); 1440 CheckStreamFrameBoundaries(packet, kQuicMaxStreamIdSize, kIncludeVersion);
1507 } 1441 }
1508 1442
1509 TEST_P(QuicFramerTest, RejectPacket) { 1443 TEST_P(QuicFramerTest, RejectPacket) {
1510 visitor_.accept_packet_ = false; 1444 visitor_.accept_packet_ = false;
1511 1445
1512 unsigned char packet[] = { 1446 unsigned char packet[] = {// public flags (8 byte connection_id)
1513 // public flags (8 byte connection_id) 1447 0x3C,
1514 0x3C, 1448 // connection_id
1515 // connection_id 1449 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1516 0x10, 0x32, 0x54, 0x76, 1450 // packet sequence number
1517 0x98, 0xBA, 0xDC, 0xFE, 1451 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
1518 // packet sequence number 1452 // private flags
1519 0xBC, 0x9A, 0x78, 0x56, 1453 0x00,
1520 0x34, 0x12,
1521 // private flags
1522 0x00,
1523 1454
1524 // frame type (stream frame with fin) 1455 // frame type (stream frame with fin)
1525 0xFF, 1456 0xFF,
1526 // stream id 1457 // stream id
1527 0x04, 0x03, 0x02, 0x01, 1458 0x04, 0x03, 0x02, 0x01,
1528 // offset 1459 // offset
1529 0x54, 0x76, 0x10, 0x32, 1460 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA,
1530 0xDC, 0xFE, 0x98, 0xBA, 1461 // data length
1531 // data length 1462 0x0c, 0x00,
1532 0x0c, 0x00, 1463 // data
1533 // data 1464 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o',
1534 'h', 'e', 'l', 'l', 1465 'r', 'l', 'd', '!',
1535 'o', ' ', 'w', 'o',
1536 'r', 'l', 'd', '!',
1537 }; 1466 };
1538 1467
1539 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1468 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1540 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1469 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1541 1470
1542 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1471 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1543 ASSERT_TRUE(visitor_.header_.get()); 1472 ASSERT_TRUE(visitor_.header_.get());
1544 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 1473 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1545 1474
1546 ASSERT_EQ(0u, visitor_.stream_frames_.size()); 1475 ASSERT_EQ(0u, visitor_.stream_frames_.size());
1547 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1476 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1548 } 1477 }
1549 1478
1550 TEST_P(QuicFramerTest, RejectPublicHeader) { 1479 TEST_P(QuicFramerTest, RejectPublicHeader) {
1551 visitor_.accept_public_header_ = false; 1480 visitor_.accept_public_header_ = false;
1552 1481
1553 unsigned char packet[] = { 1482 unsigned char packet[] = {// public flags (8 byte connection_id)
1554 // public flags (8 byte connection_id) 1483 0x3C,
1555 0x3C, 1484 // connection_id
1556 // connection_id 1485 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1557 0x10, 0x32, 0x54, 0x76,
1558 0x98, 0xBA, 0xDC, 0xFE,
1559 }; 1486 };
1560 1487
1561 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1488 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1562 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1489 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1563 1490
1564 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1491 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1565 ASSERT_TRUE(visitor_.public_header_.get()); 1492 ASSERT_TRUE(visitor_.public_header_.get());
1566 ASSERT_FALSE(visitor_.header_.get()); 1493 ASSERT_FALSE(visitor_.header_.get());
1567 } 1494 }
1568 1495
1569 TEST_P(QuicFramerTest, RevivedStreamFrame) { 1496 TEST_P(QuicFramerTest, RevivedStreamFrame) {
1570 unsigned char payload[] = { 1497 unsigned char payload[] = {// frame type (stream frame with fin)
1571 // frame type (stream frame with fin) 1498 0xFF,
1572 0xFF, 1499 // stream id
1573 // stream id 1500 0x04, 0x03, 0x02, 0x01,
1574 0x04, 0x03, 0x02, 0x01, 1501 // offset
1575 // offset 1502 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA,
1576 0x54, 0x76, 0x10, 0x32, 1503 // data length
1577 0xDC, 0xFE, 0x98, 0xBA, 1504 0x0c, 0x00,
1578 // data length 1505 // data
1579 0x0c, 0x00, 1506 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o',
1580 // data 1507 'r', 'l', 'd', '!',
1581 'h', 'e', 'l', 'l',
1582 'o', ' ', 'w', 'o',
1583 'r', 'l', 'd', '!',
1584 }; 1508 };
1585 1509
1586 QuicPacketHeader header; 1510 QuicPacketHeader header;
1587 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 1511 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
1588 header.public_header.reset_flag = false; 1512 header.public_header.reset_flag = false;
1589 header.public_header.version_flag = false; 1513 header.public_header.version_flag = false;
1590 header.fec_flag = true; 1514 header.fec_flag = true;
1591 header.entropy_flag = true; 1515 header.entropy_flag = true;
1592 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 1516 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
1593 header.fec_group = 0; 1517 header.fec_group = 0;
1594 1518
1595 // Do not encrypt the payload because the revived payload is post-encryption. 1519 // Do not encrypt the payload because the revived payload is post-encryption.
1596 EXPECT_TRUE(framer_.ProcessRevivedPacket(&header, 1520 EXPECT_TRUE(framer_.ProcessRevivedPacket(
1597 StringPiece(AsChars(payload), 1521 &header, StringPiece(AsChars(payload), arraysize(payload))));
1598 arraysize(payload))));
1599 1522
1600 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1523 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1601 ASSERT_EQ(1, visitor_.revived_packets_); 1524 ASSERT_EQ(1, visitor_.revived_packets_);
1602 ASSERT_TRUE(visitor_.header_.get()); 1525 ASSERT_TRUE(visitor_.header_.get());
1603 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210), 1526 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
1604 visitor_.header_->public_header.connection_id); 1527 visitor_.header_->public_header.connection_id);
1605 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); 1528 EXPECT_FALSE(visitor_.header_->public_header.reset_flag);
1606 EXPECT_FALSE(visitor_.header_->public_header.version_flag); 1529 EXPECT_FALSE(visitor_.header_->public_header.version_flag);
1607 EXPECT_TRUE(visitor_.header_->fec_flag); 1530 EXPECT_TRUE(visitor_.header_->fec_flag);
1608 EXPECT_TRUE(visitor_.header_->entropy_flag); 1531 EXPECT_TRUE(visitor_.header_->entropy_flag);
1609 EXPECT_EQ(1 << (header.packet_sequence_number % 8), 1532 EXPECT_EQ(1 << (header.packet_sequence_number % 8),
1610 visitor_.header_->entropy_hash); 1533 visitor_.header_->entropy_hash);
1611 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 1534 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
1612 visitor_.header_->packet_sequence_number); 1535 visitor_.header_->packet_sequence_number);
1613 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); 1536 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
1614 EXPECT_EQ(0x00u, visitor_.header_->fec_group); 1537 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
1615 1538
1616 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1539 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1617 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1540 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1618 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id); 1541 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id);
1619 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 1542 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1620 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), 1543 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1621 visitor_.stream_frames_[0]->offset); 1544 visitor_.stream_frames_[0]->offset);
1622 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); 1545 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1623 } 1546 }
1624 1547
1625 TEST_P(QuicFramerTest, StreamFrameInFecGroup) { 1548 TEST_P(QuicFramerTest, StreamFrameInFecGroup) {
1626 unsigned char packet[] = { 1549 unsigned char packet[] = {// public flags (8 byte connection_id)
1627 // public flags (8 byte connection_id) 1550 0x3C,
1628 0x3C, 1551 // connection_id
1629 // connection_id 1552 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1630 0x10, 0x32, 0x54, 0x76, 1553 // packet sequence number
1631 0x98, 0xBA, 0xDC, 0xFE, 1554 0xBC, 0x9A, 0x78, 0x56, 0x12, 0x34,
1632 // packet sequence number 1555 // private flags (fec group)
1633 0xBC, 0x9A, 0x78, 0x56, 1556 0x02,
1634 0x12, 0x34, 1557 // first fec protected packet offset
1635 // private flags (fec group) 1558 0x02,
1636 0x02,
1637 // first fec protected packet offset
1638 0x02,
1639 1559
1640 // frame type (stream frame with fin) 1560 // frame type (stream frame with fin)
1641 0xFF, 1561 0xFF,
1642 // stream id 1562 // stream id
1643 0x04, 0x03, 0x02, 0x01, 1563 0x04, 0x03, 0x02, 0x01,
1644 // offset 1564 // offset
1645 0x54, 0x76, 0x10, 0x32, 1565 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA,
1646 0xDC, 0xFE, 0x98, 0xBA, 1566 // data length
1647 // data length 1567 0x0c, 0x00,
1648 0x0c, 0x00, 1568 // data
1649 // data 1569 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o',
1650 'h', 'e', 'l', 'l', 1570 'r', 'l', 'd', '!',
1651 'o', ' ', 'w', 'o',
1652 'r', 'l', 'd', '!',
1653 }; 1571 };
1654 1572
1655 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1573 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1656 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1574 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1657 1575
1658 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1576 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1659 ASSERT_TRUE(visitor_.header_.get()); 1577 ASSERT_TRUE(visitor_.header_.get());
1660 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 1578 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1661 EXPECT_EQ(IN_FEC_GROUP, visitor_.header_->is_in_fec_group); 1579 EXPECT_EQ(IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
1662 EXPECT_EQ(GG_UINT64_C(0x341256789ABA), 1580 EXPECT_EQ(GG_UINT64_C(0x341256789ABA), visitor_.header_->fec_group);
1663 visitor_.header_->fec_group);
1664 const size_t fec_offset = 1581 const size_t fec_offset =
1665 GetStartOfFecProtectedData(PACKET_8BYTE_CONNECTION_ID, 1582 GetStartOfFecProtectedData(PACKET_8BYTE_CONNECTION_ID,
1666 !kIncludeVersion, 1583 !kIncludeVersion,
1667 PACKET_6BYTE_SEQUENCE_NUMBER); 1584 PACKET_6BYTE_SEQUENCE_NUMBER);
1668 EXPECT_EQ( 1585 EXPECT_EQ(
1669 string(AsChars(packet) + fec_offset, arraysize(packet) - fec_offset), 1586 string(AsChars(packet) + fec_offset, arraysize(packet) - fec_offset),
1670 visitor_.fec_protected_payload_); 1587 visitor_.fec_protected_payload_);
1671 1588
1672 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1589 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1673 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1590 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1674 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id); 1591 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id);
1675 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 1592 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1676 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), 1593 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1677 visitor_.stream_frames_[0]->offset); 1594 visitor_.stream_frames_[0]->offset);
1678 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); 1595 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]);
1679 } 1596 }
1680 1597
1681 TEST_P(QuicFramerTest, AckFrame15) { 1598 TEST_P(QuicFramerTest, AckFrame15) {
1682 if (framer_.version() != QUIC_VERSION_15) { 1599 if (framer_.version() != QUIC_VERSION_15) {
1683 return; 1600 return;
1684 } 1601 }
1685 1602
1686 unsigned char packet[] = { 1603 unsigned char packet[] = {
1687 // public flags (8 byte connection_id) 1604 // public flags (8 byte connection_id)
1688 0x3C, 1605 0x3C,
1689 // connection_id 1606 // connection_id
1690 0x10, 0x32, 0x54, 0x76, 1607 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1691 0x98, 0xBA, 0xDC, 0xFE, 1608 // packet sequence number
1692 // packet sequence number 1609 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
1693 0xA8, 0x9A, 0x78, 0x56, 1610 // private flags (entropy)
1694 0x34, 0x12, 1611 0x01,
1695 // private flags (entropy)
1696 0x01,
1697 1612
1698 // frame type (ack frame) 1613 // frame type (ack frame)
1699 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) 1614 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1700 0x6C, 1615 0x6C,
1701 // entropy hash of sent packets till least awaiting - 1. 1616 // entropy hash of sent packets till least awaiting - 1.
1702 0xAB, 1617 0xAB,
1703 // least packet sequence number awaiting an ack, delta from sequence number. 1618 // least packet sequence number awaiting an ack, delta from sequence
1704 0x08, 0x00, 0x00, 0x00, 1619 // number.
1705 0x00, 0x00, 1620 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
1706 // entropy hash of all received packets. 1621 // entropy hash of all received packets.
1707 0xBA, 1622 0xBA,
1708 // largest observed packet sequence number 1623 // largest observed packet sequence number
1709 0xBF, 0x9A, 0x78, 0x56, 1624 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
1710 0x34, 0x12, 1625 // Zero delta time.
1711 // Zero delta time. 1626 0x0, 0x0,
1712 0x0, 0x0, 1627 // num missing packets
1713 // num missing packets 1628 0x01,
1714 0x01, 1629 // missing packet delta
1715 // missing packet delta 1630 0x01,
1716 0x01, 1631 // 0 more missing packets in range.
1717 // 0 more missing packets in range. 1632 0x00,
1718 0x00, 1633 // Number of revived packets.
1719 // Number of revived packets. 1634 0x00,
1720 0x00,
1721 }; 1635 };
1722 1636
1723 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1637 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1724 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1638 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1725 1639
1726 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1640 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1727 ASSERT_TRUE(visitor_.header_.get()); 1641 ASSERT_TRUE(visitor_.header_.get());
1728 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 1642 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1729 1643
1730 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 1644 EXPECT_EQ(0u, visitor_.stream_frames_.size());
1731 ASSERT_EQ(1u, visitor_.ack_frames_.size()); 1645 ASSERT_EQ(1u, visitor_.ack_frames_.size());
1732 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; 1646 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
1733 EXPECT_EQ(0xAB, frame.sent_info.entropy_hash); 1647 EXPECT_EQ(0xAB, frame.sent_info.entropy_hash);
1734 EXPECT_EQ(0xBA, frame.received_info.entropy_hash); 1648 EXPECT_EQ(0xBA, frame.received_info.entropy_hash);
1735 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.received_info.largest_observed); 1649 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.received_info.largest_observed);
1736 ASSERT_EQ(1u, frame.received_info.missing_packets.size()); 1650 ASSERT_EQ(1u, frame.received_info.missing_packets.size());
1737 SequenceNumberSet::const_iterator missing_iter = 1651 SequenceNumberSet::const_iterator missing_iter =
1738 frame.received_info.missing_packets.begin(); 1652 frame.received_info.missing_packets.begin();
1739 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter); 1653 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter);
1740 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame.sent_info.least_unacked); 1654 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame.sent_info.least_unacked);
1741 1655
1742 const size_t kSentEntropyOffset = kQuicFrameTypeSize; 1656 const size_t kSentEntropyOffset = kQuicFrameTypeSize;
1743 const size_t kLeastUnackedOffset = kSentEntropyOffset + kQuicEntropyHashSize; 1657 const size_t kLeastUnackedOffset = kSentEntropyOffset + kQuicEntropyHashSize;
1744 const size_t kReceivedEntropyOffset = kLeastUnackedOffset + 1658 const size_t kReceivedEntropyOffset =
1745 PACKET_6BYTE_SEQUENCE_NUMBER; 1659 kLeastUnackedOffset + PACKET_6BYTE_SEQUENCE_NUMBER;
1746 const size_t kLargestObservedOffset = kReceivedEntropyOffset + 1660 const size_t kLargestObservedOffset =
1747 kQuicEntropyHashSize; 1661 kReceivedEntropyOffset + kQuicEntropyHashSize;
1748 const size_t kMissingDeltaTimeOffset = kLargestObservedOffset + 1662 const size_t kMissingDeltaTimeOffset =
1749 PACKET_6BYTE_SEQUENCE_NUMBER; 1663 kLargestObservedOffset + PACKET_6BYTE_SEQUENCE_NUMBER;
1750 const size_t kNumMissingPacketOffset = kMissingDeltaTimeOffset + 1664 const size_t kNumMissingPacketOffset =
1751 kQuicDeltaTimeLargestObservedSize; 1665 kMissingDeltaTimeOffset + kQuicDeltaTimeLargestObservedSize;
1752 const size_t kMissingPacketsOffset = kNumMissingPacketOffset + 1666 const size_t kMissingPacketsOffset =
1753 kNumberOfMissingPacketsSize; 1667 kNumMissingPacketOffset + kNumberOfMissingPacketsSize;
1754 const size_t kMissingPacketsRange = kMissingPacketsOffset + 1668 const size_t kMissingPacketsRange =
1755 PACKET_1BYTE_SEQUENCE_NUMBER; 1669 kMissingPacketsOffset + PACKET_1BYTE_SEQUENCE_NUMBER;
1756 const size_t kRevivedPacketsLength = kMissingPacketsRange + 1670 const size_t kRevivedPacketsLength =
1757 PACKET_1BYTE_SEQUENCE_NUMBER; 1671 kMissingPacketsRange + PACKET_1BYTE_SEQUENCE_NUMBER;
1758 // Now test framing boundaries 1672 // Now test framing boundaries
1759 const size_t ack_frame_size = kRevivedPacketsLength + 1673 const size_t ack_frame_size =
1760 PACKET_1BYTE_SEQUENCE_NUMBER; 1674 kRevivedPacketsLength + PACKET_1BYTE_SEQUENCE_NUMBER;
1761 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) { 1675 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) {
1762 string expected_error; 1676 string expected_error;
1763 if (i < kLeastUnackedOffset) { 1677 if (i < kLeastUnackedOffset) {
1764 expected_error = "Unable to read entropy hash for sent packets."; 1678 expected_error = "Unable to read entropy hash for sent packets.";
1765 } else if (i < kReceivedEntropyOffset) { 1679 } else if (i < kReceivedEntropyOffset) {
1766 expected_error = "Unable to read least unacked delta."; 1680 expected_error = "Unable to read least unacked delta.";
1767 } else if (i < kLargestObservedOffset) { 1681 } else if (i < kLargestObservedOffset) {
1768 expected_error = "Unable to read entropy hash for received packets."; 1682 expected_error = "Unable to read entropy hash for received packets.";
1769 } else if (i < kMissingDeltaTimeOffset) { 1683 } else if (i < kMissingDeltaTimeOffset) {
1770 expected_error = "Unable to read largest observed."; 1684 expected_error = "Unable to read largest observed.";
1771 } else if (i < kNumMissingPacketOffset) { 1685 } else if (i < kNumMissingPacketOffset) {
1772 expected_error = "Unable to read delta time largest observed."; 1686 expected_error = "Unable to read delta time largest observed.";
1773 } else if (i < kMissingPacketsOffset) { 1687 } else if (i < kMissingPacketsOffset) {
1774 expected_error = "Unable to read num missing packet ranges."; 1688 expected_error = "Unable to read num missing packet ranges.";
1775 } else if (i < kMissingPacketsRange) { 1689 } else if (i < kMissingPacketsRange) {
1776 expected_error = "Unable to read missing sequence number delta."; 1690 expected_error = "Unable to read missing sequence number delta.";
1777 } else if (i < kRevivedPacketsLength) { 1691 } else if (i < kRevivedPacketsLength) {
1778 expected_error = "Unable to read missing sequence number range."; 1692 expected_error = "Unable to read missing sequence number range.";
1779 } else { 1693 } else {
1780 expected_error = "Unable to read num revived packets."; 1694 expected_error = "Unable to read num revived packets.";
1781 } 1695 }
1782 CheckProcessingFails( 1696 CheckProcessingFails(packet,
1783 packet, 1697 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
1784 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 1698 !kIncludeVersion,
1785 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 1699 PACKET_6BYTE_SEQUENCE_NUMBER,
1786 expected_error, QUIC_INVALID_ACK_DATA); 1700 NOT_IN_FEC_GROUP),
1701 expected_error,
1702 QUIC_INVALID_ACK_DATA);
1787 } 1703 }
1788 } 1704 }
1789 1705
1790 TEST_P(QuicFramerTest, AckFrame) { 1706 TEST_P(QuicFramerTest, AckFrame) {
1791 if (framer_.version() <= QUIC_VERSION_15) { 1707 if (framer_.version() <= QUIC_VERSION_15) {
1792 return; 1708 return;
1793 } 1709 }
1794 1710
1795 unsigned char packet[] = { 1711 unsigned char packet[] = {
1796 // public flags (8 byte connection_id) 1712 // public flags (8 byte connection_id)
1797 0x3C, 1713 0x3C,
1798 // connection_id 1714 // connection_id
1799 0x10, 0x32, 0x54, 0x76, 1715 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1800 0x98, 0xBA, 0xDC, 0xFE, 1716 // packet sequence number
1801 // packet sequence number 1717 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
1802 0xA8, 0x9A, 0x78, 0x56, 1718 // private flags (entropy)
1803 0x34, 0x12, 1719 0x01,
1804 // private flags (entropy)
1805 0x01,
1806 1720
1807 // frame type (ack frame) 1721 // frame type (ack frame)
1808 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) 1722 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1809 0x6C, 1723 0x6C,
1810 // entropy hash of all received packets. 1724 // entropy hash of all received packets.
1811 0xBA, 1725 0xBA,
1812 // largest observed packet sequence number 1726 // largest observed packet sequence number
1813 0xBF, 0x9A, 0x78, 0x56, 1727 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
1814 0x34, 0x12, 1728 // Zero delta time.
1815 // Zero delta time. 1729 0x0, 0x0,
1816 0x0, 0x0, 1730 // num missing packets
1817 // num missing packets 1731 0x01,
1818 0x01, 1732 // missing packet delta
1819 // missing packet delta 1733 0x01,
1820 0x01, 1734 // 0 more missing packets in range.
1821 // 0 more missing packets in range. 1735 0x00,
1822 0x00, 1736 // Number of revived packets.
1823 // Number of revived packets. 1737 0x00,
1824 0x00,
1825 }; 1738 };
1826 1739
1827 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1740 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1828 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1741 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1829 1742
1830 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1743 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1831 ASSERT_TRUE(visitor_.header_.get()); 1744 ASSERT_TRUE(visitor_.header_.get());
1832 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 1745 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1833 1746
1834 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 1747 EXPECT_EQ(0u, visitor_.stream_frames_.size());
1835 ASSERT_EQ(1u, visitor_.ack_frames_.size()); 1748 ASSERT_EQ(1u, visitor_.ack_frames_.size());
1836 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; 1749 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
1837 EXPECT_EQ(0xBA, frame.received_info.entropy_hash); 1750 EXPECT_EQ(0xBA, frame.received_info.entropy_hash);
1838 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.received_info.largest_observed); 1751 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.received_info.largest_observed);
1839 ASSERT_EQ(1u, frame.received_info.missing_packets.size()); 1752 ASSERT_EQ(1u, frame.received_info.missing_packets.size());
1840 SequenceNumberSet::const_iterator missing_iter = 1753 SequenceNumberSet::const_iterator missing_iter =
1841 frame.received_info.missing_packets.begin(); 1754 frame.received_info.missing_packets.begin();
1842 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter); 1755 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter);
1843 1756
1844 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize; 1757 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize;
1845 const size_t kLargestObservedOffset = kReceivedEntropyOffset + 1758 const size_t kLargestObservedOffset =
1846 kQuicEntropyHashSize; 1759 kReceivedEntropyOffset + kQuicEntropyHashSize;
1847 const size_t kMissingDeltaTimeOffset = kLargestObservedOffset + 1760 const size_t kMissingDeltaTimeOffset =
1848 PACKET_6BYTE_SEQUENCE_NUMBER; 1761 kLargestObservedOffset + PACKET_6BYTE_SEQUENCE_NUMBER;
1849 const size_t kNumMissingPacketOffset = kMissingDeltaTimeOffset + 1762 const size_t kNumMissingPacketOffset =
1850 kQuicDeltaTimeLargestObservedSize; 1763 kMissingDeltaTimeOffset + kQuicDeltaTimeLargestObservedSize;
1851 const size_t kMissingPacketsOffset = kNumMissingPacketOffset + 1764 const size_t kMissingPacketsOffset =
1852 kNumberOfMissingPacketsSize; 1765 kNumMissingPacketOffset + kNumberOfMissingPacketsSize;
1853 const size_t kMissingPacketsRange = kMissingPacketsOffset + 1766 const size_t kMissingPacketsRange =
1854 PACKET_1BYTE_SEQUENCE_NUMBER; 1767 kMissingPacketsOffset + PACKET_1BYTE_SEQUENCE_NUMBER;
1855 const size_t kRevivedPacketsLength = kMissingPacketsRange + 1768 const size_t kRevivedPacketsLength =
1856 PACKET_1BYTE_SEQUENCE_NUMBER; 1769 kMissingPacketsRange + PACKET_1BYTE_SEQUENCE_NUMBER;
1857 // Now test framing boundaries 1770 // Now test framing boundaries
1858 const size_t ack_frame_size = kRevivedPacketsLength + 1771 const size_t ack_frame_size =
1859 PACKET_1BYTE_SEQUENCE_NUMBER; 1772 kRevivedPacketsLength + PACKET_1BYTE_SEQUENCE_NUMBER;
1860 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) { 1773 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) {
1861 string expected_error; 1774 string expected_error;
1862 if (i < kLargestObservedOffset) { 1775 if (i < kLargestObservedOffset) {
1863 expected_error = "Unable to read entropy hash for received packets."; 1776 expected_error = "Unable to read entropy hash for received packets.";
1864 } else if (i < kMissingDeltaTimeOffset) { 1777 } else if (i < kMissingDeltaTimeOffset) {
1865 expected_error = "Unable to read largest observed."; 1778 expected_error = "Unable to read largest observed.";
1866 } else if (i < kNumMissingPacketOffset) { 1779 } else if (i < kNumMissingPacketOffset) {
1867 expected_error = "Unable to read delta time largest observed."; 1780 expected_error = "Unable to read delta time largest observed.";
1868 } else if (i < kMissingPacketsOffset) { 1781 } else if (i < kMissingPacketsOffset) {
1869 expected_error = "Unable to read num missing packet ranges."; 1782 expected_error = "Unable to read num missing packet ranges.";
1870 } else if (i < kMissingPacketsRange) { 1783 } else if (i < kMissingPacketsRange) {
1871 expected_error = "Unable to read missing sequence number delta."; 1784 expected_error = "Unable to read missing sequence number delta.";
1872 } else if (i < kRevivedPacketsLength) { 1785 } else if (i < kRevivedPacketsLength) {
1873 expected_error = "Unable to read missing sequence number range."; 1786 expected_error = "Unable to read missing sequence number range.";
1874 } else { 1787 } else {
1875 expected_error = "Unable to read num revived packets."; 1788 expected_error = "Unable to read num revived packets.";
1876 } 1789 }
1877 CheckProcessingFails( 1790 CheckProcessingFails(packet,
1878 packet, 1791 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
1879 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 1792 !kIncludeVersion,
1880 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 1793 PACKET_6BYTE_SEQUENCE_NUMBER,
1881 expected_error, QUIC_INVALID_ACK_DATA); 1794 NOT_IN_FEC_GROUP),
1795 expected_error,
1796 QUIC_INVALID_ACK_DATA);
1882 } 1797 }
1883 } 1798 }
1884 1799
1885 TEST_P(QuicFramerTest, AckFrameRevivedPackets) { 1800 TEST_P(QuicFramerTest, AckFrameRevivedPackets) {
1886 if (framer_.version() <= QUIC_VERSION_15) { 1801 if (framer_.version() <= QUIC_VERSION_15) {
1887 return; 1802 return;
1888 } 1803 }
1889 1804
1890 unsigned char packet[] = { 1805 unsigned char packet[] = {
1891 // public flags (8 byte connection_id) 1806 // public flags (8 byte connection_id)
1892 0x3C, 1807 0x3C,
1893 // connection_id 1808 // connection_id
1894 0x10, 0x32, 0x54, 0x76, 1809 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1895 0x98, 0xBA, 0xDC, 0xFE, 1810 // packet sequence number
1896 // packet sequence number 1811 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
1897 0xA8, 0x9A, 0x78, 0x56, 1812 // private flags (entropy)
1898 0x34, 0x12, 1813 0x01,
1899 // private flags (entropy)
1900 0x01,
1901 1814
1902 // frame type (ack frame) 1815 // frame type (ack frame)
1903 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) 1816 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
1904 0x6C, 1817 0x6C,
1905 // entropy hash of all received packets. 1818 // entropy hash of all received packets.
1906 0xBA, 1819 0xBA,
1907 // largest observed packet sequence number 1820 // largest observed packet sequence number
1908 0xBF, 0x9A, 0x78, 0x56, 1821 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
1909 0x34, 0x12, 1822 // Zero delta time.
1910 // Zero delta time. 1823 0x0, 0x0,
1911 0x0, 0x0, 1824 // num missing packets
1912 // num missing packets 1825 0x01,
1913 0x01, 1826 // missing packet delta
1914 // missing packet delta 1827 0x01,
1915 0x01, 1828 // 0 more missing packets in range.
1916 // 0 more missing packets in range. 1829 0x00,
1917 0x00, 1830 // Number of revived packets.
1918 // Number of revived packets. 1831 0x01,
1919 0x01, 1832 // Revived packet sequence number.
1920 // Revived packet sequence number. 1833 0xBE, 0x9A, 0x78, 0x56, 0x34, 0x12,
1921 0xBE, 0x9A, 0x78, 0x56,
1922 0x34, 0x12,
1923 }; 1834 };
1924 1835
1925 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1836 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1926 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1837 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1927 1838
1928 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1839 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1929 ASSERT_TRUE(visitor_.header_.get()); 1840 ASSERT_TRUE(visitor_.header_.get());
1930 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 1841 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1931 1842
1932 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 1843 EXPECT_EQ(0u, visitor_.stream_frames_.size());
1933 ASSERT_EQ(1u, visitor_.ack_frames_.size()); 1844 ASSERT_EQ(1u, visitor_.ack_frames_.size());
1934 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; 1845 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
1935 EXPECT_EQ(0xBA, frame.received_info.entropy_hash); 1846 EXPECT_EQ(0xBA, frame.received_info.entropy_hash);
1936 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.received_info.largest_observed); 1847 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.received_info.largest_observed);
1937 ASSERT_EQ(1u, frame.received_info.missing_packets.size()); 1848 ASSERT_EQ(1u, frame.received_info.missing_packets.size());
1938 SequenceNumberSet::const_iterator missing_iter = 1849 SequenceNumberSet::const_iterator missing_iter =
1939 frame.received_info.missing_packets.begin(); 1850 frame.received_info.missing_packets.begin();
1940 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter); 1851 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter);
1941 1852
1942 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize; 1853 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize;
1943 const size_t kLargestObservedOffset = kReceivedEntropyOffset + 1854 const size_t kLargestObservedOffset =
1944 kQuicEntropyHashSize; 1855 kReceivedEntropyOffset + kQuicEntropyHashSize;
1945 const size_t kMissingDeltaTimeOffset = kLargestObservedOffset + 1856 const size_t kMissingDeltaTimeOffset =
1946 PACKET_6BYTE_SEQUENCE_NUMBER; 1857 kLargestObservedOffset + PACKET_6BYTE_SEQUENCE_NUMBER;
1947 const size_t kNumMissingPacketOffset = kMissingDeltaTimeOffset + 1858 const size_t kNumMissingPacketOffset =
1948 kQuicDeltaTimeLargestObservedSize; 1859 kMissingDeltaTimeOffset + kQuicDeltaTimeLargestObservedSize;
1949 const size_t kMissingPacketsOffset = kNumMissingPacketOffset + 1860 const size_t kMissingPacketsOffset =
1950 kNumberOfMissingPacketsSize; 1861 kNumMissingPacketOffset + kNumberOfMissingPacketsSize;
1951 const size_t kMissingPacketsRange = kMissingPacketsOffset + 1862 const size_t kMissingPacketsRange =
1952 PACKET_1BYTE_SEQUENCE_NUMBER; 1863 kMissingPacketsOffset + PACKET_1BYTE_SEQUENCE_NUMBER;
1953 const size_t kRevivedPacketsLength = kMissingPacketsRange + 1864 const size_t kRevivedPacketsLength =
1954 PACKET_1BYTE_SEQUENCE_NUMBER; 1865 kMissingPacketsRange + PACKET_1BYTE_SEQUENCE_NUMBER;
1955 const size_t kRevivedPacketSequenceNumberLength = kRevivedPacketsLength + 1866 const size_t kRevivedPacketSequenceNumberLength =
1956 PACKET_1BYTE_SEQUENCE_NUMBER; 1867 kRevivedPacketsLength + PACKET_1BYTE_SEQUENCE_NUMBER;
1957 // Now test framing boundaries 1868 // Now test framing boundaries
1958 const size_t ack_frame_size = kRevivedPacketSequenceNumberLength + 1869 const size_t ack_frame_size =
1959 PACKET_6BYTE_SEQUENCE_NUMBER; 1870 kRevivedPacketSequenceNumberLength + PACKET_6BYTE_SEQUENCE_NUMBER;
1960 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) { 1871 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) {
1961 string expected_error; 1872 string expected_error;
1962 if (i < kReceivedEntropyOffset) { 1873 if (i < kReceivedEntropyOffset) {
1963 expected_error = "Unable to read least unacked delta."; 1874 expected_error = "Unable to read least unacked delta.";
1964 } else if (i < kLargestObservedOffset) { 1875 } else if (i < kLargestObservedOffset) {
1965 expected_error = "Unable to read entropy hash for received packets."; 1876 expected_error = "Unable to read entropy hash for received packets.";
1966 } else if (i < kMissingDeltaTimeOffset) { 1877 } else if (i < kMissingDeltaTimeOffset) {
1967 expected_error = "Unable to read largest observed."; 1878 expected_error = "Unable to read largest observed.";
1968 } else if (i < kNumMissingPacketOffset) { 1879 } else if (i < kNumMissingPacketOffset) {
1969 expected_error = "Unable to read delta time largest observed."; 1880 expected_error = "Unable to read delta time largest observed.";
1970 } else if (i < kMissingPacketsOffset) { 1881 } else if (i < kMissingPacketsOffset) {
1971 expected_error = "Unable to read num missing packet ranges."; 1882 expected_error = "Unable to read num missing packet ranges.";
1972 } else if (i < kMissingPacketsRange) { 1883 } else if (i < kMissingPacketsRange) {
1973 expected_error = "Unable to read missing sequence number delta."; 1884 expected_error = "Unable to read missing sequence number delta.";
1974 } else if (i < kRevivedPacketsLength) { 1885 } else if (i < kRevivedPacketsLength) {
1975 expected_error = "Unable to read missing sequence number range."; 1886 expected_error = "Unable to read missing sequence number range.";
1976 } else if (i < kRevivedPacketSequenceNumberLength) { 1887 } else if (i < kRevivedPacketSequenceNumberLength) {
1977 expected_error = "Unable to read num revived packets."; 1888 expected_error = "Unable to read num revived packets.";
1978 } else { 1889 } else {
1979 expected_error = "Unable to read revived packet."; 1890 expected_error = "Unable to read revived packet.";
1980 } 1891 }
1981 CheckProcessingFails( 1892 CheckProcessingFails(packet,
1982 packet, 1893 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
1983 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 1894 !kIncludeVersion,
1984 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 1895 PACKET_6BYTE_SEQUENCE_NUMBER,
1985 expected_error, QUIC_INVALID_ACK_DATA); 1896 NOT_IN_FEC_GROUP),
1897 expected_error,
1898 QUIC_INVALID_ACK_DATA);
1986 } 1899 }
1987 } 1900 }
1988 1901
1989 TEST_P(QuicFramerTest, AckFrameRevivedPackets15) { 1902 TEST_P(QuicFramerTest, AckFrameRevivedPackets15) {
1990 if (framer_.version() != QUIC_VERSION_15) { 1903 if (framer_.version() != QUIC_VERSION_15) {
1991 return; 1904 return;
1992 } 1905 }
1993 1906
1994 unsigned char packet[] = { 1907 unsigned char packet[] = {
1995 // public flags (8 byte connection_id) 1908 // public flags (8 byte connection_id)
1996 0x3C, 1909 0x3C,
1997 // connection_id 1910 // connection_id
1998 0x10, 0x32, 0x54, 0x76, 1911 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1999 0x98, 0xBA, 0xDC, 0xFE, 1912 // packet sequence number
2000 // packet sequence number 1913 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
2001 0xA8, 0x9A, 0x78, 0x56, 1914 // private flags (entropy)
2002 0x34, 0x12, 1915 0x01,
2003 // private flags (entropy)
2004 0x01,
2005 1916
2006 // frame type (ack frame) 1917 // frame type (ack frame)
2007 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) 1918 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2008 0x6C, 1919 0x6C,
2009 // entropy hash of sent packets till least awaiting - 1. 1920 // entropy hash of sent packets till least awaiting - 1.
2010 0xAB, 1921 0xAB,
2011 // least packet sequence number awaiting an ack, delta from sequence number. 1922 // least packet sequence number awaiting an ack, delta from sequence
2012 0x08, 0x00, 0x00, 0x00, 1923 // number.
2013 0x00, 0x00, 1924 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
2014 // entropy hash of all received packets. 1925 // entropy hash of all received packets.
2015 0xBA, 1926 0xBA,
2016 // largest observed packet sequence number 1927 // largest observed packet sequence number
2017 0xBF, 0x9A, 0x78, 0x56, 1928 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
2018 0x34, 0x12, 1929 // Zero delta time.
2019 // Zero delta time. 1930 0x0, 0x0,
2020 0x0, 0x0, 1931 // num missing packets
2021 // num missing packets 1932 0x01,
2022 0x01, 1933 // missing packet delta
2023 // missing packet delta 1934 0x01,
2024 0x01, 1935 // 0 more missing packets in range.
2025 // 0 more missing packets in range. 1936 0x00,
2026 0x00, 1937 // Number of revived packets.
2027 // Number of revived packets. 1938 0x01,
2028 0x01, 1939 // Revived packet sequence number.
2029 // Revived packet sequence number. 1940 0xBE, 0x9A, 0x78, 0x56, 0x34, 0x12,
2030 0xBE, 0x9A, 0x78, 0x56,
2031 0x34, 0x12,
2032 }; 1941 };
2033 1942
2034 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1943 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2035 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1944 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2036 1945
2037 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1946 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2038 ASSERT_TRUE(visitor_.header_.get()); 1947 ASSERT_TRUE(visitor_.header_.get());
2039 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 1948 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2040 1949
2041 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 1950 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2042 ASSERT_EQ(1u, visitor_.ack_frames_.size()); 1951 ASSERT_EQ(1u, visitor_.ack_frames_.size());
2043 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; 1952 const QuicAckFrame& frame = *visitor_.ack_frames_[0];
2044 EXPECT_EQ(0xAB, frame.sent_info.entropy_hash); 1953 EXPECT_EQ(0xAB, frame.sent_info.entropy_hash);
2045 EXPECT_EQ(0xBA, frame.received_info.entropy_hash); 1954 EXPECT_EQ(0xBA, frame.received_info.entropy_hash);
2046 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.received_info.largest_observed); 1955 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.received_info.largest_observed);
2047 ASSERT_EQ(1u, frame.received_info.missing_packets.size()); 1956 ASSERT_EQ(1u, frame.received_info.missing_packets.size());
2048 SequenceNumberSet::const_iterator missing_iter = 1957 SequenceNumberSet::const_iterator missing_iter =
2049 frame.received_info.missing_packets.begin(); 1958 frame.received_info.missing_packets.begin();
2050 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter); 1959 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter);
2051 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame.sent_info.least_unacked); 1960 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame.sent_info.least_unacked);
2052 1961
2053 const size_t kSentEntropyOffset = kQuicFrameTypeSize; 1962 const size_t kSentEntropyOffset = kQuicFrameTypeSize;
2054 const size_t kLeastUnackedOffset = kSentEntropyOffset + kQuicEntropyHashSize; 1963 const size_t kLeastUnackedOffset = kSentEntropyOffset + kQuicEntropyHashSize;
2055 const size_t kReceivedEntropyOffset = kLeastUnackedOffset + 1964 const size_t kReceivedEntropyOffset =
2056 PACKET_6BYTE_SEQUENCE_NUMBER; 1965 kLeastUnackedOffset + PACKET_6BYTE_SEQUENCE_NUMBER;
2057 const size_t kLargestObservedOffset = kReceivedEntropyOffset + 1966 const size_t kLargestObservedOffset =
2058 kQuicEntropyHashSize; 1967 kReceivedEntropyOffset + kQuicEntropyHashSize;
2059 const size_t kMissingDeltaTimeOffset = kLargestObservedOffset + 1968 const size_t kMissingDeltaTimeOffset =
2060 PACKET_6BYTE_SEQUENCE_NUMBER; 1969 kLargestObservedOffset + PACKET_6BYTE_SEQUENCE_NUMBER;
2061 const size_t kNumMissingPacketOffset = kMissingDeltaTimeOffset + 1970 const size_t kNumMissingPacketOffset =
2062 kQuicDeltaTimeLargestObservedSize; 1971 kMissingDeltaTimeOffset + kQuicDeltaTimeLargestObservedSize;
2063 const size_t kMissingPacketsOffset = kNumMissingPacketOffset + 1972 const size_t kMissingPacketsOffset =
2064 kNumberOfMissingPacketsSize; 1973 kNumMissingPacketOffset + kNumberOfMissingPacketsSize;
2065 const size_t kMissingPacketsRange = kMissingPacketsOffset + 1974 const size_t kMissingPacketsRange =
2066 PACKET_1BYTE_SEQUENCE_NUMBER; 1975 kMissingPacketsOffset + PACKET_1BYTE_SEQUENCE_NUMBER;
2067 const size_t kRevivedPacketsLength = kMissingPacketsRange + 1976 const size_t kRevivedPacketsLength =
2068 PACKET_1BYTE_SEQUENCE_NUMBER; 1977 kMissingPacketsRange + PACKET_1BYTE_SEQUENCE_NUMBER;
2069 const size_t kRevivedPacketSequenceNumberLength = kRevivedPacketsLength + 1978 const size_t kRevivedPacketSequenceNumberLength =
2070 PACKET_1BYTE_SEQUENCE_NUMBER; 1979 kRevivedPacketsLength + PACKET_1BYTE_SEQUENCE_NUMBER;
2071 // Now test framing boundaries 1980 // Now test framing boundaries
2072 const size_t ack_frame_size = kRevivedPacketSequenceNumberLength + 1981 const size_t ack_frame_size =
2073 PACKET_6BYTE_SEQUENCE_NUMBER; 1982 kRevivedPacketSequenceNumberLength + PACKET_6BYTE_SEQUENCE_NUMBER;
2074 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) { 1983 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) {
2075 string expected_error; 1984 string expected_error;
2076 if (i < kLeastUnackedOffset) { 1985 if (i < kLeastUnackedOffset) {
2077 expected_error = "Unable to read entropy hash for sent packets."; 1986 expected_error = "Unable to read entropy hash for sent packets.";
2078 } else if (i < kReceivedEntropyOffset) { 1987 } else if (i < kReceivedEntropyOffset) {
2079 expected_error = "Unable to read least unacked delta."; 1988 expected_error = "Unable to read least unacked delta.";
2080 } else if (i < kLargestObservedOffset) { 1989 } else if (i < kLargestObservedOffset) {
2081 expected_error = "Unable to read entropy hash for received packets."; 1990 expected_error = "Unable to read entropy hash for received packets.";
2082 } else if (i < kMissingDeltaTimeOffset) { 1991 } else if (i < kMissingDeltaTimeOffset) {
2083 expected_error = "Unable to read largest observed."; 1992 expected_error = "Unable to read largest observed.";
2084 } else if (i < kNumMissingPacketOffset) { 1993 } else if (i < kNumMissingPacketOffset) {
2085 expected_error = "Unable to read delta time largest observed."; 1994 expected_error = "Unable to read delta time largest observed.";
2086 } else if (i < kMissingPacketsOffset) { 1995 } else if (i < kMissingPacketsOffset) {
2087 expected_error = "Unable to read num missing packet ranges."; 1996 expected_error = "Unable to read num missing packet ranges.";
2088 } else if (i < kMissingPacketsRange) { 1997 } else if (i < kMissingPacketsRange) {
2089 expected_error = "Unable to read missing sequence number delta."; 1998 expected_error = "Unable to read missing sequence number delta.";
2090 } else if (i < kRevivedPacketsLength) { 1999 } else if (i < kRevivedPacketsLength) {
2091 expected_error = "Unable to read missing sequence number range."; 2000 expected_error = "Unable to read missing sequence number range.";
2092 } else if (i < kRevivedPacketSequenceNumberLength) { 2001 } else if (i < kRevivedPacketSequenceNumberLength) {
2093 expected_error = "Unable to read num revived packets."; 2002 expected_error = "Unable to read num revived packets.";
2094 } else { 2003 } else {
2095 expected_error = "Unable to read revived packet."; 2004 expected_error = "Unable to read revived packet.";
2096 } 2005 }
2097 CheckProcessingFails( 2006 CheckProcessingFails(packet,
2098 packet, 2007 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
2099 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 2008 !kIncludeVersion,
2100 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 2009 PACKET_6BYTE_SEQUENCE_NUMBER,
2101 expected_error, QUIC_INVALID_ACK_DATA); 2010 NOT_IN_FEC_GROUP),
2011 expected_error,
2012 QUIC_INVALID_ACK_DATA);
2102 } 2013 }
2103 } 2014 }
2104 2015
2105 TEST_P(QuicFramerTest, AckFrameNoNacks) { 2016 TEST_P(QuicFramerTest, AckFrameNoNacks) {
2106 if (framer_.version() <= QUIC_VERSION_15) { 2017 if (framer_.version() <= QUIC_VERSION_15) {
2107 return; 2018 return;
2108 } 2019 }
2109 unsigned char packet[] = { 2020 unsigned char packet[] = {
2110 // public flags (8 byte connection_id) 2021 // public flags (8 byte connection_id)
2111 0x3C, 2022 0x3C,
2112 // connection_id 2023 // connection_id
2113 0x10, 0x32, 0x54, 0x76, 2024 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2114 0x98, 0xBA, 0xDC, 0xFE, 2025 // packet sequence number
2115 // packet sequence number 2026 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
2116 0xA8, 0x9A, 0x78, 0x56, 2027 // private flags (entropy)
2117 0x34, 0x12, 2028 0x01,
2118 // private flags (entropy)
2119 0x01,
2120 2029
2121 // frame type (ack frame) 2030 // frame type (ack frame)
2122 // (no nacks, not truncated, 6 byte largest observed, 1 byte delta) 2031 // (no nacks, not truncated, 6 byte largest observed, 1 byte delta)
2123 0x4C, 2032 0x4C,
2124 // entropy hash of all received packets. 2033 // entropy hash of all received packets.
2125 0xBA, 2034 0xBA,
2126 // largest observed packet sequence number 2035 // largest observed packet sequence number
2127 0xBF, 0x9A, 0x78, 0x56, 2036 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
2128 0x34, 0x12, 2037 // Zero delta time.
2129 // Zero delta time. 2038 0x0, 0x0,
2130 0x0, 0x0,
2131 }; 2039 };
2132 2040
2133 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2041 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2134 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2042 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2135 2043
2136 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2044 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2137 ASSERT_TRUE(visitor_.header_.get()); 2045 ASSERT_TRUE(visitor_.header_.get());
2138 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2046 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2139 2047
2140 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 2048 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2141 ASSERT_EQ(1u, visitor_.ack_frames_.size()); 2049 ASSERT_EQ(1u, visitor_.ack_frames_.size());
2142 QuicAckFrame* frame = visitor_.ack_frames_[0]; 2050 QuicAckFrame* frame = visitor_.ack_frames_[0];
2143 EXPECT_EQ(0xBA, frame->received_info.entropy_hash); 2051 EXPECT_EQ(0xBA, frame->received_info.entropy_hash);
2144 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), 2052 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF),
2145 frame->received_info.largest_observed); 2053 frame->received_info.largest_observed);
2146 ASSERT_EQ(0u, frame->received_info.missing_packets.size()); 2054 ASSERT_EQ(0u, frame->received_info.missing_packets.size());
2147 2055
2148 // Verify that the packet re-serializes identically. 2056 // Verify that the packet re-serializes identically.
2149 QuicFrames frames; 2057 QuicFrames frames;
2150 frames.push_back(QuicFrame(frame)); 2058 frames.push_back(QuicFrame(frame));
2151 scoped_ptr<QuicPacket> data( 2059 scoped_ptr<QuicPacket> data(
2152 framer_.BuildUnsizedDataPacket(*visitor_.header_, frames).packet); 2060 framer_.BuildUnsizedDataPacket(*visitor_.header_, frames).packet);
2153 ASSERT_TRUE(data != NULL); 2061 ASSERT_TRUE(data != NULL);
2154 2062
2155 test::CompareCharArraysWithHexError("constructed packet", 2063 test::CompareCharArraysWithHexError("constructed packet",
2156 data->data(), data->length(), 2064 data->data(),
2157 AsChars(packet), arraysize(packet)); 2065 data->length(),
2066 AsChars(packet),
2067 arraysize(packet));
2158 } 2068 }
2159 2069
2160 TEST_P(QuicFramerTest, AckFrameNoNacks15) { 2070 TEST_P(QuicFramerTest, AckFrameNoNacks15) {
2161 if (framer_.version() > QUIC_VERSION_15) { 2071 if (framer_.version() > QUIC_VERSION_15) {
2162 return; 2072 return;
2163 } 2073 }
2164 unsigned char packet[] = { 2074 unsigned char packet[] = {
2165 // public flags (8 byte connection_id) 2075 // public flags (8 byte connection_id)
2166 0x3C, 2076 0x3C,
2167 // connection_id 2077 // connection_id
2168 0x10, 0x32, 0x54, 0x76, 2078 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2169 0x98, 0xBA, 0xDC, 0xFE, 2079 // packet sequence number
2170 // packet sequence number 2080 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
2171 0xA8, 0x9A, 0x78, 0x56, 2081 // private flags (entropy)
2172 0x34, 0x12, 2082 0x01,
2173 // private flags (entropy)
2174 0x01,
2175 2083
2176 // frame type (ack frame) 2084 // frame type (ack frame)
2177 // (no nacks, not truncated, 6 byte largest observed, 1 byte delta) 2085 // (no nacks, not truncated, 6 byte largest observed, 1 byte delta)
2178 0x4C, 2086 0x4C,
2179 // entropy hash of sent packets till least awaiting - 1. 2087 // entropy hash of sent packets till least awaiting - 1.
2180 0xAB, 2088 0xAB,
2181 // least packet sequence number awaiting an ack, delta from sequence number. 2089 // least packet sequence number awaiting an ack, delta from sequence
2182 0x08, 0x00, 0x00, 0x00, 2090 // number.
2183 0x00, 0x00, 2091 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
2184 // entropy hash of all received packets. 2092 // entropy hash of all received packets.
2185 0xBA, 2093 0xBA,
2186 // largest observed packet sequence number 2094 // largest observed packet sequence number
2187 0xBF, 0x9A, 0x78, 0x56, 2095 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
2188 0x34, 0x12, 2096 // Zero delta time.
2189 // Zero delta time. 2097 0x0, 0x0,
2190 0x0, 0x0,
2191 }; 2098 };
2192 2099
2193 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2100 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2194 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2101 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2195 2102
2196 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2103 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2197 ASSERT_TRUE(visitor_.header_.get()); 2104 ASSERT_TRUE(visitor_.header_.get());
2198 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2105 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2199 2106
2200 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 2107 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2201 ASSERT_EQ(1u, visitor_.ack_frames_.size()); 2108 ASSERT_EQ(1u, visitor_.ack_frames_.size());
2202 QuicAckFrame* frame = visitor_.ack_frames_[0]; 2109 QuicAckFrame* frame = visitor_.ack_frames_[0];
2203 EXPECT_EQ(0xAB, frame->sent_info.entropy_hash); 2110 EXPECT_EQ(0xAB, frame->sent_info.entropy_hash);
2204 EXPECT_EQ(0xBA, frame->received_info.entropy_hash); 2111 EXPECT_EQ(0xBA, frame->received_info.entropy_hash);
2205 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), 2112 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF),
2206 frame->received_info.largest_observed); 2113 frame->received_info.largest_observed);
2207 ASSERT_EQ(0u, frame->received_info.missing_packets.size()); 2114 ASSERT_EQ(0u, frame->received_info.missing_packets.size());
2208 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame->sent_info.least_unacked); 2115 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame->sent_info.least_unacked);
2209 2116
2210 // Verify that the packet re-serializes identically. 2117 // Verify that the packet re-serializes identically.
2211 QuicFrames frames; 2118 QuicFrames frames;
2212 frames.push_back(QuicFrame(frame)); 2119 frames.push_back(QuicFrame(frame));
2213 scoped_ptr<QuicPacket> data( 2120 scoped_ptr<QuicPacket> data(
2214 framer_.BuildUnsizedDataPacket(*visitor_.header_, frames).packet); 2121 framer_.BuildUnsizedDataPacket(*visitor_.header_, frames).packet);
2215 ASSERT_TRUE(data != NULL); 2122 ASSERT_TRUE(data != NULL);
2216 2123
2217 test::CompareCharArraysWithHexError("constructed packet", 2124 test::CompareCharArraysWithHexError("constructed packet",
2218 data->data(), data->length(), 2125 data->data(),
2219 AsChars(packet), arraysize(packet)); 2126 data->length(),
2127 AsChars(packet),
2128 arraysize(packet));
2220 } 2129 }
2221 2130
2222 TEST_P(QuicFramerTest, AckFrame500Nacks) { 2131 TEST_P(QuicFramerTest, AckFrame500Nacks) {
2223 if (framer_.version() <= QUIC_VERSION_15) { 2132 if (framer_.version() <= QUIC_VERSION_15) {
2224 return; 2133 return;
2225 } 2134 }
2226 unsigned char packet[] = { 2135 unsigned char packet[] = {
2227 // public flags (8 byte connection_id) 2136 // public flags (8 byte connection_id)
2228 0x3C, 2137 0x3C,
2229 // connection_id 2138 // connection_id
2230 0x10, 0x32, 0x54, 0x76, 2139 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2231 0x98, 0xBA, 0xDC, 0xFE, 2140 // packet sequence number
2232 // packet sequence number 2141 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
2233 0xA8, 0x9A, 0x78, 0x56, 2142 // private flags (entropy)
2234 0x34, 0x12, 2143 0x01,
2235 // private flags (entropy)
2236 0x01,
2237 2144
2238 // frame type (ack frame) 2145 // frame type (ack frame)
2239 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) 2146 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2240 0x6C, 2147 0x6C,
2241 // entropy hash of all received packets. 2148 // entropy hash of all received packets.
2242 0xBA, 2149 0xBA,
2243 // largest observed packet sequence number 2150 // largest observed packet sequence number
2244 0xBF, 0x9A, 0x78, 0x56, 2151 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
2245 0x34, 0x12, 2152 // Zero delta time.
2246 // Zero delta time. 2153 0x0, 0x0,
2247 0x0, 0x0, 2154 // num missing packet ranges
2248 // num missing packet ranges 2155 0x02,
2249 0x02, 2156 // missing packet delta
2250 // missing packet delta 2157 0x01,
2251 0x01, 2158 // 243 more missing packets in range.
2252 // 243 more missing packets in range. 2159 // The ranges are listed in this order so the re-constructed packet
2253 // The ranges are listed in this order so the re-constructed packet matches. 2160 // matches.
2254 0xF3, 2161 0xF3,
2255 // No gap between ranges 2162 // No gap between ranges
2256 0x00, 2163 0x00,
2257 // 255 more missing packets in range. 2164 // 255 more missing packets in range.
2258 0xFF, 2165 0xFF,
2259 // No revived packets. 2166 // No revived packets.
2260 0x00, 2167 0x00,
2261 }; 2168 };
2262 2169
2263 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2170 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2264 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2171 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2265 2172
2266 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2173 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2267 ASSERT_TRUE(visitor_.header_.get()); 2174 ASSERT_TRUE(visitor_.header_.get());
2268 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2175 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2269 2176
2270 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 2177 EXPECT_EQ(0u, visitor_.stream_frames_.size());
(...skipping 12 matching lines...) Expand all
2283 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *last_missing_iter); 2190 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *last_missing_iter);
2284 2191
2285 // Verify that the packet re-serializes identically. 2192 // Verify that the packet re-serializes identically.
2286 QuicFrames frames; 2193 QuicFrames frames;
2287 frames.push_back(QuicFrame(frame)); 2194 frames.push_back(QuicFrame(frame));
2288 scoped_ptr<QuicPacket> data( 2195 scoped_ptr<QuicPacket> data(
2289 framer_.BuildUnsizedDataPacket(*visitor_.header_, frames).packet); 2196 framer_.BuildUnsizedDataPacket(*visitor_.header_, frames).packet);
2290 ASSERT_TRUE(data != NULL); 2197 ASSERT_TRUE(data != NULL);
2291 2198
2292 test::CompareCharArraysWithHexError("constructed packet", 2199 test::CompareCharArraysWithHexError("constructed packet",
2293 data->data(), data->length(), 2200 data->data(),
2294 AsChars(packet), arraysize(packet)); 2201 data->length(),
2202 AsChars(packet),
2203 arraysize(packet));
2295 } 2204 }
2296 2205
2297 TEST_P(QuicFramerTest, AckFrame500Nacks15) { 2206 TEST_P(QuicFramerTest, AckFrame500Nacks15) {
2298 if (framer_.version() != QUIC_VERSION_15) { 2207 if (framer_.version() != QUIC_VERSION_15) {
2299 return; 2208 return;
2300 } 2209 }
2301 unsigned char packet[] = { 2210 unsigned char packet[] = {
2302 // public flags (8 byte connection_id) 2211 // public flags (8 byte connection_id)
2303 0x3C, 2212 0x3C,
2304 // connection_id 2213 // connection_id
2305 0x10, 0x32, 0x54, 0x76, 2214 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2306 0x98, 0xBA, 0xDC, 0xFE, 2215 // packet sequence number
2307 // packet sequence number 2216 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
2308 0xA8, 0x9A, 0x78, 0x56, 2217 // private flags (entropy)
2309 0x34, 0x12, 2218 0x01,
2310 // private flags (entropy)
2311 0x01,
2312 2219
2313 // frame type (ack frame) 2220 // frame type (ack frame)
2314 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) 2221 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2315 0x6C, 2222 0x6C,
2316 // entropy hash of sent packets till least awaiting - 1. 2223 // entropy hash of sent packets till least awaiting - 1.
2317 0xAB, 2224 0xAB,
2318 // least packet sequence number awaiting an ack, delta from sequence number. 2225 // least packet sequence number awaiting an ack, delta from sequence
2319 0x08, 0x00, 0x00, 0x00, 2226 // number.
2320 0x00, 0x00, 2227 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
2321 // entropy hash of all received packets. 2228 // entropy hash of all received packets.
2322 0xBA, 2229 0xBA,
2323 // largest observed packet sequence number 2230 // largest observed packet sequence number
2324 0xBF, 0x9A, 0x78, 0x56, 2231 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
2325 0x34, 0x12, 2232 // Zero delta time.
2326 // Zero delta time. 2233 0x0, 0x0,
2327 0x0, 0x0, 2234 // num missing packet ranges
2328 // num missing packet ranges 2235 0x02,
2329 0x02, 2236 // missing packet delta
2330 // missing packet delta 2237 0x01,
2331 0x01, 2238 // 243 more missing packets in range.
2332 // 243 more missing packets in range. 2239 // The ranges are listed in this order so the re-constructed packet
2333 // The ranges are listed in this order so the re-constructed packet matches. 2240 // matches.
2334 0xF3, 2241 0xF3,
2335 // No gap between ranges 2242 // No gap between ranges
2336 0x00, 2243 0x00,
2337 // 255 more missing packets in range. 2244 // 255 more missing packets in range.
2338 0xFF, 2245 0xFF,
2339 // No revived packets. 2246 // No revived packets.
2340 0x00, 2247 0x00,
2341 }; 2248 };
2342 2249
2343 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2250 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2344 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2251 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2345 2252
2346 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2253 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2347 ASSERT_TRUE(visitor_.header_.get()); 2254 ASSERT_TRUE(visitor_.header_.get());
2348 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2255 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2349 2256
2350 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 2257 EXPECT_EQ(0u, visitor_.stream_frames_.size());
(...skipping 14 matching lines...) Expand all
2365 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame->sent_info.least_unacked); 2272 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame->sent_info.least_unacked);
2366 2273
2367 // Verify that the packet re-serializes identically. 2274 // Verify that the packet re-serializes identically.
2368 QuicFrames frames; 2275 QuicFrames frames;
2369 frames.push_back(QuicFrame(frame)); 2276 frames.push_back(QuicFrame(frame));
2370 scoped_ptr<QuicPacket> data( 2277 scoped_ptr<QuicPacket> data(
2371 framer_.BuildUnsizedDataPacket(*visitor_.header_, frames).packet); 2278 framer_.BuildUnsizedDataPacket(*visitor_.header_, frames).packet);
2372 ASSERT_TRUE(data != NULL); 2279 ASSERT_TRUE(data != NULL);
2373 2280
2374 test::CompareCharArraysWithHexError("constructed packet", 2281 test::CompareCharArraysWithHexError("constructed packet",
2375 data->data(), data->length(), 2282 data->data(),
2376 AsChars(packet), arraysize(packet)); 2283 data->length(),
2284 AsChars(packet),
2285 arraysize(packet));
2377 } 2286 }
2378 2287
2379 TEST_P(QuicFramerTest, CongestionFeedbackFrameTCP) { 2288 TEST_P(QuicFramerTest, CongestionFeedbackFrameTCP) {
2380 unsigned char packet[] = { 2289 unsigned char packet[] = {// public flags (8 byte connection_id)
2381 // public flags (8 byte connection_id) 2290 0x3C,
2382 0x3C, 2291 // connection_id
2383 // connection_id 2292 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2384 0x10, 0x32, 0x54, 0x76, 2293 // packet sequence number
2385 0x98, 0xBA, 0xDC, 0xFE, 2294 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
2386 // packet sequence number 2295 // private flags
2387 0xBC, 0x9A, 0x78, 0x56, 2296 0x00,
2388 0x34, 0x12,
2389 // private flags
2390 0x00,
2391 2297
2392 // frame type (congestion feedback frame) 2298 // frame type (congestion feedback frame)
2393 0x20, 2299 0x20,
2394 // congestion feedback type (tcp) 2300 // congestion feedback type (tcp)
2395 0x00, 2301 0x00,
2396 // ack_frame.feedback.tcp.receive_window 2302 // ack_frame.feedback.tcp.receive_window
2397 0x03, 0x04, 2303 0x03, 0x04,
2398 }; 2304 };
2399 2305
2400 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2306 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2401 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2307 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2402 2308
2403 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2309 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2404 ASSERT_TRUE(visitor_.header_.get()); 2310 ASSERT_TRUE(visitor_.header_.get());
2405 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2311 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2406 2312
2407 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 2313 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2408 ASSERT_EQ(1u, visitor_.congestion_feedback_frames_.size()); 2314 ASSERT_EQ(1u, visitor_.congestion_feedback_frames_.size());
2409 const QuicCongestionFeedbackFrame& frame = 2315 const QuicCongestionFeedbackFrame& frame =
2410 *visitor_.congestion_feedback_frames_[0]; 2316 *visitor_.congestion_feedback_frames_[0];
2411 ASSERT_EQ(kTCP, frame.type); 2317 ASSERT_EQ(kTCP, frame.type);
2412 EXPECT_EQ(0x4030u, frame.tcp.receive_window); 2318 EXPECT_EQ(0x4030u, frame.tcp.receive_window);
2413 2319
2414 // Now test framing boundaries 2320 // Now test framing boundaries
2415 for (size_t i = kQuicFrameTypeSize; i < 4; ++i) { 2321 for (size_t i = kQuicFrameTypeSize; i < 4; ++i) {
2416 string expected_error; 2322 string expected_error;
2417 if (i < 2) { 2323 if (i < 2) {
2418 expected_error = "Unable to read congestion feedback type."; 2324 expected_error = "Unable to read congestion feedback type.";
2419 } else if (i < 4) { 2325 } else if (i < 4) {
2420 expected_error = "Unable to read receive window."; 2326 expected_error = "Unable to read receive window.";
2421 } 2327 }
2422 CheckProcessingFails( 2328 CheckProcessingFails(packet,
2423 packet, 2329 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
2424 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 2330 !kIncludeVersion,
2425 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 2331 PACKET_6BYTE_SEQUENCE_NUMBER,
2426 expected_error, QUIC_INVALID_CONGESTION_FEEDBACK_DATA); 2332 NOT_IN_FEC_GROUP),
2333 expected_error,
2334 QUIC_INVALID_CONGESTION_FEEDBACK_DATA);
2427 } 2335 }
2428 } 2336 }
2429 2337
2430 TEST_P(QuicFramerTest, CongestionFeedbackFrameInterArrival) { 2338 TEST_P(QuicFramerTest, CongestionFeedbackFrameInterArrival) {
2431 unsigned char packet[] = { 2339 unsigned char packet[] = {// public flags (8 byte connection_id)
2432 // public flags (8 byte connection_id) 2340 0x3C,
2433 0x3C, 2341 // connection_id
2434 // connection_id 2342 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2435 0x10, 0x32, 0x54, 0x76, 2343 // packet sequence number
2436 0x98, 0xBA, 0xDC, 0xFE, 2344 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
2437 // packet sequence number 2345 // private flags
2438 0xBC, 0x9A, 0x78, 0x56, 2346 0x00,
2439 0x34, 0x12,
2440 // private flags
2441 0x00,
2442 2347
2443 // frame type (congestion feedback frame) 2348 // frame type (congestion feedback frame)
2444 0x20, 2349 0x20,
2445 // congestion feedback type (inter arrival) 2350 // congestion feedback type (inter arrival)
2446 0x01, 2351 0x01,
2447 // num received packets 2352 // num received packets
2448 0x03, 2353 0x03,
2449 // lowest sequence number 2354 // lowest sequence number
2450 0xBA, 0x9A, 0x78, 0x56, 2355 0xBA, 0x9A, 0x78, 0x56, 0x34, 0x12,
2451 0x34, 0x12, 2356 // receive time
2452 // receive time 2357 0x87, 0x96, 0xA5, 0xB4, 0xC3, 0xD2, 0xE1, 0x07,
2453 0x87, 0x96, 0xA5, 0xB4, 2358 // sequence delta
2454 0xC3, 0xD2, 0xE1, 0x07, 2359 0x01, 0x00,
2455 // sequence delta 2360 // time delta
2456 0x01, 0x00, 2361 0x01, 0x00, 0x00, 0x00,
2457 // time delta 2362 // sequence delta (skip one packet)
2458 0x01, 0x00, 0x00, 0x00, 2363 0x03, 0x00,
2459 // sequence delta (skip one packet) 2364 // time delta
2460 0x03, 0x00, 2365 0x02, 0x00, 0x00, 0x00,
2461 // time delta
2462 0x02, 0x00, 0x00, 0x00,
2463 }; 2366 };
2464 2367
2465 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2368 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2466 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2369 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2467 2370
2468 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2371 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2469 ASSERT_TRUE(visitor_.header_.get()); 2372 ASSERT_TRUE(visitor_.header_.get());
2470 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2373 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2471 2374
2472 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 2375 EXPECT_EQ(0u, visitor_.stream_frames_.size());
(...skipping 29 matching lines...) Expand all
2502 expected_error = "Unable to read time received."; 2405 expected_error = "Unable to read time received.";
2503 } else if (i < 19) { 2406 } else if (i < 19) {
2504 expected_error = "Unable to read sequence delta in received packets."; 2407 expected_error = "Unable to read sequence delta in received packets.";
2505 } else if (i < 23) { 2408 } else if (i < 23) {
2506 expected_error = "Unable to read time delta in received packets."; 2409 expected_error = "Unable to read time delta in received packets.";
2507 } else if (i < 25) { 2410 } else if (i < 25) {
2508 expected_error = "Unable to read sequence delta in received packets."; 2411 expected_error = "Unable to read sequence delta in received packets.";
2509 } else if (i < 29) { 2412 } else if (i < 29) {
2510 expected_error = "Unable to read time delta in received packets."; 2413 expected_error = "Unable to read time delta in received packets.";
2511 } 2414 }
2512 CheckProcessingFails( 2415 CheckProcessingFails(packet,
2513 packet, 2416 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
2514 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 2417 !kIncludeVersion,
2515 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 2418 PACKET_6BYTE_SEQUENCE_NUMBER,
2516 expected_error, QUIC_INVALID_CONGESTION_FEEDBACK_DATA); 2419 NOT_IN_FEC_GROUP),
2420 expected_error,
2421 QUIC_INVALID_CONGESTION_FEEDBACK_DATA);
2517 } 2422 }
2518 } 2423 }
2519 2424
2520 TEST_P(QuicFramerTest, CongestionFeedbackFrameFixRate) { 2425 TEST_P(QuicFramerTest, CongestionFeedbackFrameFixRate) {
2521 unsigned char packet[] = { 2426 unsigned char packet[] = {// public flags (8 byte connection_id)
2522 // public flags (8 byte connection_id) 2427 0x3C,
2523 0x3C, 2428 // connection_id
2524 // connection_id 2429 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2525 0x10, 0x32, 0x54, 0x76, 2430 // packet sequence number
2526 0x98, 0xBA, 0xDC, 0xFE, 2431 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
2527 // packet sequence number 2432 // private flags
2528 0xBC, 0x9A, 0x78, 0x56, 2433 0x00,
2529 0x34, 0x12,
2530 // private flags
2531 0x00,
2532 2434
2533 // frame type (congestion feedback frame) 2435 // frame type (congestion feedback frame)
2534 0x20, 2436 0x20,
2535 // congestion feedback type (fix rate) 2437 // congestion feedback type (fix rate)
2536 0x02, 2438 0x02,
2537 // bitrate_in_bytes_per_second; 2439 // bitrate_in_bytes_per_second;
2538 0x01, 0x02, 0x03, 0x04, 2440 0x01, 0x02, 0x03, 0x04,
2539 }; 2441 };
2540 2442
2541 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2443 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2542 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2444 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2543 2445
2544 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2446 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2545 ASSERT_TRUE(visitor_.header_.get()); 2447 ASSERT_TRUE(visitor_.header_.get());
2546 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2448 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2547 2449
2548 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 2450 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2549 ASSERT_EQ(1u, visitor_.congestion_feedback_frames_.size()); 2451 ASSERT_EQ(1u, visitor_.congestion_feedback_frames_.size());
2550 const QuicCongestionFeedbackFrame& frame = 2452 const QuicCongestionFeedbackFrame& frame =
2551 *visitor_.congestion_feedback_frames_[0]; 2453 *visitor_.congestion_feedback_frames_[0];
2552 ASSERT_EQ(kFixRate, frame.type); 2454 ASSERT_EQ(kFixRate, frame.type);
2553 EXPECT_EQ(static_cast<uint32>(0x04030201), 2455 EXPECT_EQ(static_cast<uint32>(0x04030201),
2554 frame.fix_rate.bitrate.ToBytesPerSecond()); 2456 frame.fix_rate.bitrate.ToBytesPerSecond());
2555 2457
2556 // Now test framing boundaries 2458 // Now test framing boundaries
2557 for (size_t i = kQuicFrameTypeSize; i < 6; ++i) { 2459 for (size_t i = kQuicFrameTypeSize; i < 6; ++i) {
2558 string expected_error; 2460 string expected_error;
2559 if (i < 2) { 2461 if (i < 2) {
2560 expected_error = "Unable to read congestion feedback type."; 2462 expected_error = "Unable to read congestion feedback type.";
2561 } else if (i < 6) { 2463 } else if (i < 6) {
2562 expected_error = "Unable to read bitrate."; 2464 expected_error = "Unable to read bitrate.";
2563 } 2465 }
2564 CheckProcessingFails( 2466 CheckProcessingFails(packet,
2565 packet, 2467 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
2566 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 2468 !kIncludeVersion,
2567 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 2469 PACKET_6BYTE_SEQUENCE_NUMBER,
2568 expected_error, QUIC_INVALID_CONGESTION_FEEDBACK_DATA); 2470 NOT_IN_FEC_GROUP),
2471 expected_error,
2472 QUIC_INVALID_CONGESTION_FEEDBACK_DATA);
2569 } 2473 }
2570 } 2474 }
2571 2475
2572 TEST_P(QuicFramerTest, CongestionFeedbackFrameInvalidFeedback) { 2476 TEST_P(QuicFramerTest, CongestionFeedbackFrameInvalidFeedback) {
2573 unsigned char packet[] = { 2477 unsigned char packet[] = {// public flags (8 byte connection_id)
2574 // public flags (8 byte connection_id) 2478 0x3C,
2575 0x3C, 2479 // connection_id
2576 // connection_id 2480 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2577 0x10, 0x32, 0x54, 0x76, 2481 // packet sequence number
2578 0x98, 0xBA, 0xDC, 0xFE, 2482 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
2579 // packet sequence number 2483 // private flags
2580 0xBC, 0x9A, 0x78, 0x56, 2484 0x00,
2581 0x34, 0x12,
2582 // private flags
2583 0x00,
2584 2485
2585 // frame type (congestion feedback frame) 2486 // frame type (congestion feedback frame)
2586 0x20, 2487 0x20,
2587 // congestion feedback type (invalid) 2488 // congestion feedback type (invalid)
2588 0x03, 2489 0x03,
2589 }; 2490 };
2590 2491
2591 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2492 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2592 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); 2493 EXPECT_FALSE(framer_.ProcessPacket(encrypted));
2593 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2494 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2594 EXPECT_EQ(QUIC_INVALID_CONGESTION_FEEDBACK_DATA, framer_.error()); 2495 EXPECT_EQ(QUIC_INVALID_CONGESTION_FEEDBACK_DATA, framer_.error());
2595 } 2496 }
2596 2497
2597 TEST_P(QuicFramerTest, StopWaitingFrame) { 2498 TEST_P(QuicFramerTest, StopWaitingFrame) {
2598 if (framer_.version() <= QUIC_VERSION_15) { 2499 if (framer_.version() <= QUIC_VERSION_15) {
2599 return; 2500 return;
2600 } 2501 }
2601 unsigned char packet[] = { 2502 unsigned char packet[] = {
2602 // public flags (8 byte connection_id) 2503 // public flags (8 byte connection_id)
2603 0x3C, 2504 0x3C,
2604 // connection_id 2505 // connection_id
2605 0x10, 0x32, 0x54, 0x76, 2506 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2606 0x98, 0xBA, 0xDC, 0xFE, 2507 // packet sequence number
2607 // packet sequence number 2508 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
2608 0xA8, 0x9A, 0x78, 0x56, 2509 // private flags (entropy)
2609 0x34, 0x12, 2510 0x01,
2610 // private flags (entropy)
2611 0x01,
2612 2511
2613 // frame type (ack frame) 2512 // frame type (ack frame)
2614 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) 2513 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
2615 0x06, 2514 0x06,
2616 // entropy hash of sent packets till least awaiting - 1. 2515 // entropy hash of sent packets till least awaiting - 1.
2617 0xAB, 2516 0xAB,
2618 // least packet sequence number awaiting an ack, delta from sequence number. 2517 // least packet sequence number awaiting an ack, delta from sequence
2619 0x08, 0x00, 0x00, 0x00, 2518 // number.
2620 0x00, 0x00, 2519 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
2621 }; 2520 };
2622 2521
2623 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2522 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2624 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2523 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2625 2524
2626 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2525 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2627 ASSERT_TRUE(visitor_.header_.get()); 2526 ASSERT_TRUE(visitor_.header_.get());
2628 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2527 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2629 2528
2630 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 2529 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2631 ASSERT_EQ(1u, visitor_.stop_waiting_frames_.size()); 2530 ASSERT_EQ(1u, visitor_.stop_waiting_frames_.size());
2632 const QuicStopWaitingFrame& frame = *visitor_.stop_waiting_frames_[0]; 2531 const QuicStopWaitingFrame& frame = *visitor_.stop_waiting_frames_[0];
2633 EXPECT_EQ(0xAB, frame.entropy_hash); 2532 EXPECT_EQ(0xAB, frame.entropy_hash);
2634 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame.least_unacked); 2533 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame.least_unacked);
2635 2534
2636 const size_t kSentEntropyOffset = kQuicFrameTypeSize; 2535 const size_t kSentEntropyOffset = kQuicFrameTypeSize;
2637 const size_t kLeastUnackedOffset = kSentEntropyOffset + kQuicEntropyHashSize; 2536 const size_t kLeastUnackedOffset = kSentEntropyOffset + kQuicEntropyHashSize;
2638 const size_t frame_size = 7; 2537 const size_t frame_size = 7;
2639 for (size_t i = kQuicFrameTypeSize; i < frame_size; ++i) { 2538 for (size_t i = kQuicFrameTypeSize; i < frame_size; ++i) {
2640 string expected_error; 2539 string expected_error;
2641 if (i < kLeastUnackedOffset) { 2540 if (i < kLeastUnackedOffset) {
2642 expected_error = "Unable to read entropy hash for sent packets."; 2541 expected_error = "Unable to read entropy hash for sent packets.";
2643 } else { 2542 } else {
2644 expected_error = "Unable to read least unacked delta."; 2543 expected_error = "Unable to read least unacked delta.";
2645 } 2544 }
2646 CheckProcessingFails( 2545 CheckProcessingFails(packet,
2647 packet, 2546 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
2648 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 2547 !kIncludeVersion,
2649 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 2548 PACKET_6BYTE_SEQUENCE_NUMBER,
2650 expected_error, QUIC_INVALID_STOP_WAITING_DATA); 2549 NOT_IN_FEC_GROUP),
2550 expected_error,
2551 QUIC_INVALID_STOP_WAITING_DATA);
2651 } 2552 }
2652 } 2553 }
2653 2554
2654 TEST_P(QuicFramerTest, RstStreamFrameQuic) { 2555 TEST_P(QuicFramerTest, RstStreamFrameQuic) {
2655 unsigned char packet[] = { 2556 unsigned char packet[] = {// public flags (8 byte connection_id)
2656 // public flags (8 byte connection_id) 2557 0x3C,
2657 0x3C, 2558 // connection_id
2658 // connection_id 2559 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2659 0x10, 0x32, 0x54, 0x76, 2560 // packet sequence number
2660 0x98, 0xBA, 0xDC, 0xFE, 2561 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
2661 // packet sequence number 2562 // private flags
2662 0xBC, 0x9A, 0x78, 0x56, 2563 0x00,
2663 0x34, 0x12,
2664 // private flags
2665 0x00,
2666 2564
2667 // frame type (rst stream frame) 2565 // frame type (rst stream frame)
2668 0x01, 2566 0x01,
2669 // stream id 2567 // stream id
2670 0x04, 0x03, 0x02, 0x01, 2568 0x04, 0x03, 0x02, 0x01,
2671 2569
2672 // sent byte offset 2570 // sent byte offset
2673 0x01, 0x02, 0x03, 0x04, 2571 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
2674 0x05, 0x06, 0x07, 0x08,
2675 2572
2676 // error code 2573 // error code
2677 0x01, 0x00, 0x00, 0x00, 2574 0x01, 0x00, 0x00, 0x00,
2678 2575
2679 // error details length 2576 // error details length
2680 0x0d, 0x00, 2577 0x0d, 0x00,
2681 // error details 2578 // error details
2682 'b', 'e', 'c', 'a', 2579 'b', 'e', 'c', 'a', 'u', 's', 'e', ' ',
2683 'u', 's', 'e', ' ', 2580 'I', ' ', 'c', 'a', 'n',
2684 'I', ' ', 'c', 'a',
2685 'n',
2686 }; 2581 };
2687 2582
2688 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2583 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2689 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2584 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2690 2585
2691 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2586 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2692 ASSERT_TRUE(visitor_.header_.get()); 2587 ASSERT_TRUE(visitor_.header_.get());
2693 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2588 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2694 2589
2695 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.rst_stream_frame_.stream_id); 2590 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.rst_stream_frame_.stream_id);
2696 EXPECT_EQ(0x01, visitor_.rst_stream_frame_.error_code); 2591 EXPECT_EQ(0x01, visitor_.rst_stream_frame_.error_code);
2697 EXPECT_EQ("because I can", visitor_.rst_stream_frame_.error_details); 2592 EXPECT_EQ("because I can", visitor_.rst_stream_frame_.error_details);
2698 EXPECT_EQ(GG_UINT64_C(0x0807060504030201), 2593 EXPECT_EQ(GG_UINT64_C(0x0807060504030201),
2699 visitor_.rst_stream_frame_.byte_offset); 2594 visitor_.rst_stream_frame_.byte_offset);
2700 2595
2701 // Now test framing boundaries 2596 // Now test framing boundaries
2702 for (size_t i = kQuicFrameTypeSize; 2597 for (size_t i = kQuicFrameTypeSize;
2703 i < QuicFramer::GetMinRstStreamFrameSize(version_); ++i) { 2598 i < QuicFramer::GetMinRstStreamFrameSize(version_);
2599 ++i) {
2704 string expected_error; 2600 string expected_error;
2705 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) { 2601 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) {
2706 expected_error = "Unable to read stream_id."; 2602 expected_error = "Unable to read stream_id.";
2707 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize + 2603 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize +
2708 + kQuicMaxStreamOffsetSize) { 2604 +kQuicMaxStreamOffsetSize) {
2709 expected_error = "Unable to read rst stream sent byte offset."; 2605 expected_error = "Unable to read rst stream sent byte offset.";
2710 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize + 2606 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize +
2711 + kQuicMaxStreamOffsetSize + kQuicErrorCodeSize) { 2607 +kQuicMaxStreamOffsetSize + kQuicErrorCodeSize) {
2712 expected_error = "Unable to read rst stream error code."; 2608 expected_error = "Unable to read rst stream error code.";
2713 } else { 2609 } else {
2714 expected_error = "Unable to read rst stream error details."; 2610 expected_error = "Unable to read rst stream error details.";
2715 } 2611 }
2716 CheckProcessingFails( 2612 CheckProcessingFails(packet,
2717 packet, 2613 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
2718 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 2614 !kIncludeVersion,
2719 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 2615 PACKET_6BYTE_SEQUENCE_NUMBER,
2720 expected_error, QUIC_INVALID_RST_STREAM_DATA); 2616 NOT_IN_FEC_GROUP),
2617 expected_error,
2618 QUIC_INVALID_RST_STREAM_DATA);
2721 } 2619 }
2722 } 2620 }
2723 2621
2724 TEST_P(QuicFramerTest, ConnectionCloseFrame) { 2622 TEST_P(QuicFramerTest, ConnectionCloseFrame) {
2725 unsigned char packet[] = { 2623 unsigned char packet[] = {// public flags (8 byte connection_id)
2726 // public flags (8 byte connection_id) 2624 0x3C,
2727 0x3C, 2625 // connection_id
2728 // connection_id 2626 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2729 0x10, 0x32, 0x54, 0x76, 2627 // packet sequence number
2730 0x98, 0xBA, 0xDC, 0xFE, 2628 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
2731 // packet sequence number 2629 // private flags
2732 0xBC, 0x9A, 0x78, 0x56, 2630 0x00,
2733 0x34, 0x12,
2734 // private flags
2735 0x00,
2736 2631
2737 // frame type (connection close frame) 2632 // frame type (connection close frame)
2738 0x02, 2633 0x02,
2739 // error code 2634 // error code
2740 0x11, 0x00, 0x00, 0x00, 2635 0x11, 0x00, 0x00, 0x00,
2741 2636
2742 // error details length 2637 // error details length
2743 0x0d, 0x00, 2638 0x0d, 0x00,
2744 // error details 2639 // error details
2745 'b', 'e', 'c', 'a', 2640 'b', 'e', 'c', 'a', 'u', 's', 'e', ' ',
2746 'u', 's', 'e', ' ', 2641 'I', ' ', 'c', 'a', 'n',
2747 'I', ' ', 'c', 'a',
2748 'n',
2749 }; 2642 };
2750 2643
2751 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2644 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2752 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2645 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2753 2646
2754 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2647 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2755 ASSERT_TRUE(visitor_.header_.get()); 2648 ASSERT_TRUE(visitor_.header_.get());
2756 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2649 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2757 2650
2758 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 2651 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2759 2652
2760 EXPECT_EQ(0x11, visitor_.connection_close_frame_.error_code); 2653 EXPECT_EQ(0x11, visitor_.connection_close_frame_.error_code);
2761 EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); 2654 EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details);
2762 2655
2763 ASSERT_EQ(0u, visitor_.ack_frames_.size()); 2656 ASSERT_EQ(0u, visitor_.ack_frames_.size());
2764 2657
2765 // Now test framing boundaries 2658 // Now test framing boundaries
2766 for (size_t i = kQuicFrameTypeSize; 2659 for (size_t i = kQuicFrameTypeSize;
2767 i < QuicFramer::GetMinConnectionCloseFrameSize(); ++i) { 2660 i < QuicFramer::GetMinConnectionCloseFrameSize();
2661 ++i) {
2768 string expected_error; 2662 string expected_error;
2769 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) { 2663 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) {
2770 expected_error = "Unable to read connection close error code."; 2664 expected_error = "Unable to read connection close error code.";
2771 } else { 2665 } else {
2772 expected_error = "Unable to read connection close error details."; 2666 expected_error = "Unable to read connection close error details.";
2773 } 2667 }
2774 CheckProcessingFails( 2668 CheckProcessingFails(packet,
2775 packet, 2669 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
2776 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 2670 !kIncludeVersion,
2777 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 2671 PACKET_6BYTE_SEQUENCE_NUMBER,
2778 expected_error, QUIC_INVALID_CONNECTION_CLOSE_DATA); 2672 NOT_IN_FEC_GROUP),
2673 expected_error,
2674 QUIC_INVALID_CONNECTION_CLOSE_DATA);
2779 } 2675 }
2780 } 2676 }
2781 2677
2782 TEST_P(QuicFramerTest, GoAwayFrame) { 2678 TEST_P(QuicFramerTest, GoAwayFrame) {
2783 unsigned char packet[] = { 2679 unsigned char packet[] = {// public flags (8 byte connection_id)
2784 // public flags (8 byte connection_id) 2680 0x3C,
2785 0x3C, 2681 // connection_id
2786 // connection_id 2682 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2787 0x10, 0x32, 0x54, 0x76, 2683 // packet sequence number
2788 0x98, 0xBA, 0xDC, 0xFE, 2684 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
2789 // packet sequence number 2685 // private flags
2790 0xBC, 0x9A, 0x78, 0x56, 2686 0x00,
2791 0x34, 0x12,
2792 // private flags
2793 0x00,
2794 2687
2795 // frame type (go away frame) 2688 // frame type (go away frame)
2796 0x03, 2689 0x03,
2797 // error code 2690 // error code
2798 0x09, 0x00, 0x00, 0x00, 2691 0x09, 0x00, 0x00, 0x00,
2799 // stream id 2692 // stream id
2800 0x04, 0x03, 0x02, 0x01, 2693 0x04, 0x03, 0x02, 0x01,
2801 // error details length 2694 // error details length
2802 0x0d, 0x00, 2695 0x0d, 0x00,
2803 // error details 2696 // error details
2804 'b', 'e', 'c', 'a', 2697 'b', 'e', 'c', 'a', 'u', 's', 'e', ' ',
2805 'u', 's', 'e', ' ', 2698 'I', ' ', 'c', 'a', 'n',
2806 'I', ' ', 'c', 'a',
2807 'n',
2808 }; 2699 };
2809 2700
2810 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2701 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2811 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2702 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2812 2703
2813 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2704 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2814 ASSERT_TRUE(visitor_.header_.get()); 2705 ASSERT_TRUE(visitor_.header_.get());
2815 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2706 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2816 2707
2817 EXPECT_EQ(GG_UINT64_C(0x01020304), 2708 EXPECT_EQ(GG_UINT64_C(0x01020304),
2818 visitor_.goaway_frame_.last_good_stream_id); 2709 visitor_.goaway_frame_.last_good_stream_id);
2819 EXPECT_EQ(0x9, visitor_.goaway_frame_.error_code); 2710 EXPECT_EQ(0x9, visitor_.goaway_frame_.error_code);
2820 EXPECT_EQ("because I can", visitor_.goaway_frame_.reason_phrase); 2711 EXPECT_EQ("because I can", visitor_.goaway_frame_.reason_phrase);
2821 2712
2822 const size_t reason_size = arraysize("because I can") - 1; 2713 const size_t reason_size = arraysize("because I can") - 1;
2823 // Now test framing boundaries 2714 // Now test framing boundaries
2824 for (size_t i = kQuicFrameTypeSize; 2715 for (size_t i = kQuicFrameTypeSize;
2825 i < QuicFramer::GetMinGoAwayFrameSize() + reason_size; ++i) { 2716 i < QuicFramer::GetMinGoAwayFrameSize() + reason_size;
2717 ++i) {
2826 string expected_error; 2718 string expected_error;
2827 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) { 2719 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) {
2828 expected_error = "Unable to read go away error code."; 2720 expected_error = "Unable to read go away error code.";
2829 } else if (i < kQuicFrameTypeSize + kQuicErrorCodeSize + 2721 } else if (i <
2830 kQuicMaxStreamIdSize) { 2722 kQuicFrameTypeSize + kQuicErrorCodeSize + kQuicMaxStreamIdSize) {
2831 expected_error = "Unable to read last good stream id."; 2723 expected_error = "Unable to read last good stream id.";
2832 } else { 2724 } else {
2833 expected_error = "Unable to read goaway reason."; 2725 expected_error = "Unable to read goaway reason.";
2834 } 2726 }
2835 CheckProcessingFails( 2727 CheckProcessingFails(packet,
2836 packet, 2728 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
2837 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 2729 !kIncludeVersion,
2838 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 2730 PACKET_6BYTE_SEQUENCE_NUMBER,
2839 expected_error, QUIC_INVALID_GOAWAY_DATA); 2731 NOT_IN_FEC_GROUP),
2732 expected_error,
2733 QUIC_INVALID_GOAWAY_DATA);
2840 } 2734 }
2841 } 2735 }
2842 2736
2843 TEST_P(QuicFramerTest, WindowUpdateFrame) { 2737 TEST_P(QuicFramerTest, WindowUpdateFrame) {
2844 unsigned char packet[] = { 2738 unsigned char packet[] = {// public flags (8 byte connection_id)
2845 // public flags (8 byte connection_id) 2739 0x3C,
2846 0x3C, 2740 // connection_id
2847 // connection_id 2741 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2848 0x10, 0x32, 0x54, 0x76, 2742 // packet sequence number
2849 0x98, 0xBA, 0xDC, 0xFE, 2743 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
2850 // packet sequence number 2744 // private flags
2851 0xBC, 0x9A, 0x78, 0x56, 2745 0x00,
2852 0x34, 0x12,
2853 // private flags
2854 0x00,
2855 2746
2856 // frame type (window update frame) 2747 // frame type (window update frame)
2857 0x04, 2748 0x04,
2858 // stream id 2749 // stream id
2859 0x04, 0x03, 0x02, 0x01, 2750 0x04, 0x03, 0x02, 0x01,
2860 // byte offset 2751 // byte offset
2861 0x05, 0x06, 0x07, 0x08, 2752 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c,
2862 0x09, 0x0a, 0x0b, 0x0c,
2863 }; 2753 };
2864 2754
2865 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2755 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2866 2756
2867 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2757 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2868 2758
2869 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2759 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2870 ASSERT_TRUE(visitor_.header_.get()); 2760 ASSERT_TRUE(visitor_.header_.get());
2871 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2761 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2872 2762
2873 EXPECT_EQ(GG_UINT64_C(0x01020304), 2763 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.window_update_frame_.stream_id);
2874 visitor_.window_update_frame_.stream_id);
2875 EXPECT_EQ(GG_UINT64_C(0x0c0b0a0908070605), 2764 EXPECT_EQ(GG_UINT64_C(0x0c0b0a0908070605),
2876 visitor_.window_update_frame_.byte_offset); 2765 visitor_.window_update_frame_.byte_offset);
2877 2766
2878 // Now test framing boundaries 2767 // Now test framing boundaries
2879 for (size_t i = kQuicFrameTypeSize; 2768 for (size_t i = kQuicFrameTypeSize;
2880 i < QuicFramer::GetWindowUpdateFrameSize(); ++i) { 2769 i < QuicFramer::GetWindowUpdateFrameSize();
2770 ++i) {
2881 string expected_error; 2771 string expected_error;
2882 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) { 2772 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) {
2883 expected_error = "Unable to read stream_id."; 2773 expected_error = "Unable to read stream_id.";
2884 } else { 2774 } else {
2885 expected_error = "Unable to read window byte_offset."; 2775 expected_error = "Unable to read window byte_offset.";
2886 } 2776 }
2887 CheckProcessingFails( 2777 CheckProcessingFails(packet,
2888 packet, 2778 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
2889 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 2779 !kIncludeVersion,
2890 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 2780 PACKET_6BYTE_SEQUENCE_NUMBER,
2891 expected_error, QUIC_INVALID_WINDOW_UPDATE_DATA); 2781 NOT_IN_FEC_GROUP),
2782 expected_error,
2783 QUIC_INVALID_WINDOW_UPDATE_DATA);
2892 } 2784 }
2893 } 2785 }
2894 2786
2895 TEST_P(QuicFramerTest, BlockedFrame) { 2787 TEST_P(QuicFramerTest, BlockedFrame) {
2896 unsigned char packet[] = { 2788 unsigned char packet[] = {// public flags (8 byte connection_id)
2897 // public flags (8 byte connection_id) 2789 0x3C,
2898 0x3C, 2790 // connection_id
2899 // connection_id 2791 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2900 0x10, 0x32, 0x54, 0x76, 2792 // packet sequence number
2901 0x98, 0xBA, 0xDC, 0xFE, 2793 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
2902 // packet sequence number 2794 // private flags
2903 0xBC, 0x9A, 0x78, 0x56, 2795 0x00,
2904 0x34, 0x12,
2905 // private flags
2906 0x00,
2907 2796
2908 // frame type (blocked frame) 2797 // frame type (blocked frame)
2909 0x05, 2798 0x05,
2910 // stream id 2799 // stream id
2911 0x04, 0x03, 0x02, 0x01, 2800 0x04, 0x03, 0x02, 0x01,
2912 }; 2801 };
2913 2802
2914 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2803 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2915 2804
2916 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2805 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2917 2806
2918 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2807 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2919 ASSERT_TRUE(visitor_.header_.get()); 2808 ASSERT_TRUE(visitor_.header_.get());
2920 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2809 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2921 2810
2922 EXPECT_EQ(GG_UINT64_C(0x01020304), 2811 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.blocked_frame_.stream_id);
2923 visitor_.blocked_frame_.stream_id);
2924 2812
2925 // Now test framing boundaries 2813 // Now test framing boundaries
2926 for (size_t i = kQuicFrameTypeSize; i < QuicFramer::GetBlockedFrameSize(); 2814 for (size_t i = kQuicFrameTypeSize; i < QuicFramer::GetBlockedFrameSize();
2927 ++i) { 2815 ++i) {
2928 string expected_error = "Unable to read stream_id."; 2816 string expected_error = "Unable to read stream_id.";
2929 CheckProcessingFails( 2817 CheckProcessingFails(packet,
2930 packet, 2818 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
2931 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 2819 !kIncludeVersion,
2932 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 2820 PACKET_6BYTE_SEQUENCE_NUMBER,
2933 expected_error, QUIC_INVALID_BLOCKED_DATA); 2821 NOT_IN_FEC_GROUP),
2822 expected_error,
2823 QUIC_INVALID_BLOCKED_DATA);
2934 } 2824 }
2935 } 2825 }
2936 2826
2937 TEST_P(QuicFramerTest, PingFrame) { 2827 TEST_P(QuicFramerTest, PingFrame) {
2938 if (version_ <= QUIC_VERSION_17) { 2828 if (version_ <= QUIC_VERSION_17) {
2939 return; 2829 return;
2940 } 2830 }
2941 2831
2942 unsigned char packet[] = { 2832 unsigned char packet[] = {// public flags (8 byte connection_id)
2943 // public flags (8 byte connection_id) 2833 0x3C,
2944 0x3C, 2834 // connection_id
2945 // connection_id 2835 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2946 0x10, 0x32, 0x54, 0x76, 2836 // packet sequence number
2947 0x98, 0xBA, 0xDC, 0xFE, 2837 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
2948 // packet sequence number 2838 // private flags
2949 0xBC, 0x9A, 0x78, 0x56, 2839 0x00,
2950 0x34, 0x12,
2951 // private flags
2952 0x00,
2953 2840
2954 // frame type (ping frame) 2841 // frame type (ping frame)
2955 0x07, 2842 0x07,
2956 }; 2843 };
2957 2844
2958 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2845 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2959 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2846 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2960 2847
2961 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2848 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2962 ASSERT_TRUE(visitor_.header_.get()); 2849 ASSERT_TRUE(visitor_.header_.get());
2963 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2850 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2964 2851
2965 EXPECT_EQ(1u, visitor_.ping_frames_.size()); 2852 EXPECT_EQ(1u, visitor_.ping_frames_.size());
2966 2853
2967 // No need to check the PING frame boundaries because it has no payload. 2854 // No need to check the PING frame boundaries because it has no payload.
2968 } 2855 }
2969 2856
2970 TEST_P(QuicFramerTest, PublicResetPacket) { 2857 TEST_P(QuicFramerTest, PublicResetPacket) {
2971 unsigned char packet[] = { 2858 unsigned char packet[] = {// public flags (public reset, 8 byte connection_id)
2972 // public flags (public reset, 8 byte connection_id) 2859 0x0E,
2973 0x0E, 2860 // connection_id
2974 // connection_id 2861 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
2975 0x10, 0x32, 0x54, 0x76, 2862 // message tag (kPRST)
2976 0x98, 0xBA, 0xDC, 0xFE, 2863 'P', 'R', 'S', 'T',
2977 // message tag (kPRST) 2864 // num_entries (2) + padding
2978 'P', 'R', 'S', 'T', 2865 0x02, 0x00, 0x00, 0x00,
2979 // num_entries (2) + padding 2866 // tag kRNON
2980 0x02, 0x00, 0x00, 0x00, 2867 'R', 'N', 'O', 'N',
2981 // tag kRNON 2868 // end offset 8
2982 'R', 'N', 'O', 'N', 2869 0x08, 0x00, 0x00, 0x00,
2983 // end offset 8 2870 // tag kRSEQ
2984 0x08, 0x00, 0x00, 0x00, 2871 'R', 'S', 'E', 'Q',
2985 // tag kRSEQ 2872 // end offset 16
2986 'R', 'S', 'E', 'Q', 2873 0x10, 0x00, 0x00, 0x00,
2987 // end offset 16 2874 // nonce proof
2988 0x10, 0x00, 0x00, 0x00, 2875 0x89, 0x67, 0x45, 0x23, 0x01, 0xEF, 0xCD, 0xAB,
2989 // nonce proof 2876 // rejected sequence number
2990 0x89, 0x67, 0x45, 0x23, 2877 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, 0x00, 0x00,
2991 0x01, 0xEF, 0xCD, 0xAB,
2992 // rejected sequence number
2993 0xBC, 0x9A, 0x78, 0x56,
2994 0x34, 0x12, 0x00, 0x00,
2995 }; 2878 };
2996 2879
2997 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2880 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
2998 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2881 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
2999 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); 2882 ASSERT_EQ(QUIC_NO_ERROR, framer_.error());
3000 ASSERT_TRUE(visitor_.public_reset_packet_.get()); 2883 ASSERT_TRUE(visitor_.public_reset_packet_.get());
3001 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210), 2884 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
3002 visitor_.public_reset_packet_->public_header.connection_id); 2885 visitor_.public_reset_packet_->public_header.connection_id);
3003 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag); 2886 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag);
3004 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag); 2887 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag);
3005 EXPECT_EQ(GG_UINT64_C(0xABCDEF0123456789), 2888 EXPECT_EQ(GG_UINT64_C(0xABCDEF0123456789),
3006 visitor_.public_reset_packet_->nonce_proof); 2889 visitor_.public_reset_packet_->nonce_proof);
3007 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 2890 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
3008 visitor_.public_reset_packet_->rejected_sequence_number); 2891 visitor_.public_reset_packet_->rejected_sequence_number);
3009 EXPECT_TRUE( 2892 EXPECT_TRUE(visitor_.public_reset_packet_->client_address.address().empty());
3010 visitor_.public_reset_packet_->client_address.address().empty());
3011 2893
3012 // Now test framing boundaries 2894 // Now test framing boundaries
3013 for (size_t i = 0; i < arraysize(packet); ++i) { 2895 for (size_t i = 0; i < arraysize(packet); ++i) {
3014 string expected_error; 2896 string expected_error;
3015 DVLOG(1) << "iteration: " << i; 2897 DVLOG(1) << "iteration: " << i;
3016 if (i < kConnectionIdOffset) { 2898 if (i < kConnectionIdOffset) {
3017 expected_error = "Unable to read public flags."; 2899 expected_error = "Unable to read public flags.";
3018 CheckProcessingFails(packet, i, expected_error, 2900 CheckProcessingFails(
3019 QUIC_INVALID_PACKET_HEADER); 2901 packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
3020 } else if (i < kPublicResetPacketMessageTagOffset) { 2902 } else if (i < kPublicResetPacketMessageTagOffset) {
3021 expected_error = "Unable to read ConnectionId."; 2903 expected_error = "Unable to read ConnectionId.";
3022 CheckProcessingFails(packet, i, expected_error, 2904 CheckProcessingFails(
3023 QUIC_INVALID_PACKET_HEADER); 2905 packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
3024 } else { 2906 } else {
3025 expected_error = "Unable to read reset message."; 2907 expected_error = "Unable to read reset message.";
3026 CheckProcessingFails(packet, i, expected_error, 2908 CheckProcessingFails(
3027 QUIC_INVALID_PUBLIC_RST_PACKET); 2909 packet, i, expected_error, QUIC_INVALID_PUBLIC_RST_PACKET);
3028 } 2910 }
3029 } 2911 }
3030 } 2912 }
3031 2913
3032 TEST_P(QuicFramerTest, PublicResetPacketWithTrailingJunk) { 2914 TEST_P(QuicFramerTest, PublicResetPacketWithTrailingJunk) {
3033 unsigned char packet[] = { 2915 unsigned char packet[] = {// public flags (public reset, 8 byte connection_id)
3034 // public flags (public reset, 8 byte connection_id) 2916 0x0E,
3035 0x0E, 2917 // connection_id
3036 // connection_id 2918 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3037 0x10, 0x32, 0x54, 0x76, 2919 // message tag (kPRST)
3038 0x98, 0xBA, 0xDC, 0xFE, 2920 'P', 'R', 'S', 'T',
3039 // message tag (kPRST) 2921 // num_entries (2) + padding
3040 'P', 'R', 'S', 'T', 2922 0x02, 0x00, 0x00, 0x00,
3041 // num_entries (2) + padding 2923 // tag kRNON
3042 0x02, 0x00, 0x00, 0x00, 2924 'R', 'N', 'O', 'N',
3043 // tag kRNON 2925 // end offset 8
3044 'R', 'N', 'O', 'N', 2926 0x08, 0x00, 0x00, 0x00,
3045 // end offset 8 2927 // tag kRSEQ
3046 0x08, 0x00, 0x00, 0x00, 2928 'R', 'S', 'E', 'Q',
3047 // tag kRSEQ 2929 // end offset 16
3048 'R', 'S', 'E', 'Q', 2930 0x10, 0x00, 0x00, 0x00,
3049 // end offset 16 2931 // nonce proof
3050 0x10, 0x00, 0x00, 0x00, 2932 0x89, 0x67, 0x45, 0x23, 0x01, 0xEF, 0xCD, 0xAB,
3051 // nonce proof 2933 // rejected sequence number
3052 0x89, 0x67, 0x45, 0x23, 2934 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, 0x00, 0x00,
3053 0x01, 0xEF, 0xCD, 0xAB, 2935 // trailing junk
3054 // rejected sequence number 2936 'j', 'u', 'n', 'k',
3055 0xBC, 0x9A, 0x78, 0x56,
3056 0x34, 0x12, 0x00, 0x00,
3057 // trailing junk
3058 'j', 'u', 'n', 'k',
3059 }; 2937 };
3060 2938
3061 string expected_error = "Unable to read reset message."; 2939 string expected_error = "Unable to read reset message.";
3062 CheckProcessingFails(packet, arraysize(packet), expected_error, 2940 CheckProcessingFails(packet,
2941 arraysize(packet),
2942 expected_error,
3063 QUIC_INVALID_PUBLIC_RST_PACKET); 2943 QUIC_INVALID_PUBLIC_RST_PACKET);
3064 } 2944 }
3065 2945
3066 TEST_P(QuicFramerTest, PublicResetPacketWithClientAddress) { 2946 TEST_P(QuicFramerTest, PublicResetPacketWithClientAddress) {
3067 unsigned char packet[] = { 2947 unsigned char packet[] = {// public flags (public reset, 8 byte connection_id)
3068 // public flags (public reset, 8 byte connection_id) 2948 0x0E,
3069 0x0E, 2949 // connection_id
3070 // connection_id 2950 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3071 0x10, 0x32, 0x54, 0x76, 2951 // message tag (kPRST)
3072 0x98, 0xBA, 0xDC, 0xFE, 2952 'P', 'R', 'S', 'T',
3073 // message tag (kPRST) 2953 // num_entries (3) + padding
3074 'P', 'R', 'S', 'T', 2954 0x03, 0x00, 0x00, 0x00,
3075 // num_entries (3) + padding 2955 // tag kRNON
3076 0x03, 0x00, 0x00, 0x00, 2956 'R', 'N', 'O', 'N',
3077 // tag kRNON 2957 // end offset 8
3078 'R', 'N', 'O', 'N', 2958 0x08, 0x00, 0x00, 0x00,
3079 // end offset 8 2959 // tag kRSEQ
3080 0x08, 0x00, 0x00, 0x00, 2960 'R', 'S', 'E', 'Q',
3081 // tag kRSEQ 2961 // end offset 16
3082 'R', 'S', 'E', 'Q', 2962 0x10, 0x00, 0x00, 0x00,
3083 // end offset 16 2963 // tag kCADR
3084 0x10, 0x00, 0x00, 0x00, 2964 'C', 'A', 'D', 'R',
3085 // tag kCADR 2965 // end offset 24
3086 'C', 'A', 'D', 'R', 2966 0x18, 0x00, 0x00, 0x00,
3087 // end offset 24 2967 // nonce proof
3088 0x18, 0x00, 0x00, 0x00, 2968 0x89, 0x67, 0x45, 0x23, 0x01, 0xEF, 0xCD, 0xAB,
3089 // nonce proof 2969 // rejected sequence number
3090 0x89, 0x67, 0x45, 0x23, 2970 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, 0x00, 0x00,
3091 0x01, 0xEF, 0xCD, 0xAB, 2971 // client address: 4.31.198.44:443
3092 // rejected sequence number 2972 0x02, 0x00, 0x04, 0x1F, 0xC6, 0x2C, 0xBB, 0x01,
3093 0xBC, 0x9A, 0x78, 0x56,
3094 0x34, 0x12, 0x00, 0x00,
3095 // client address: 4.31.198.44:443
3096 0x02, 0x00,
3097 0x04, 0x1F, 0xC6, 0x2C,
3098 0xBB, 0x01,
3099 }; 2973 };
3100 2974
3101 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 2975 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
3102 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 2976 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
3103 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); 2977 ASSERT_EQ(QUIC_NO_ERROR, framer_.error());
3104 ASSERT_TRUE(visitor_.public_reset_packet_.get()); 2978 ASSERT_TRUE(visitor_.public_reset_packet_.get());
3105 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210), 2979 EXPECT_EQ(GG_UINT64_C(0xFEDCBA9876543210),
3106 visitor_.public_reset_packet_->public_header.connection_id); 2980 visitor_.public_reset_packet_->public_header.connection_id);
3107 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag); 2981 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag);
3108 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag); 2982 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag);
3109 EXPECT_EQ(GG_UINT64_C(0xABCDEF0123456789), 2983 EXPECT_EQ(GG_UINT64_C(0xABCDEF0123456789),
3110 visitor_.public_reset_packet_->nonce_proof); 2984 visitor_.public_reset_packet_->nonce_proof);
3111 EXPECT_EQ(GG_UINT64_C(0x123456789ABC), 2985 EXPECT_EQ(GG_UINT64_C(0x123456789ABC),
3112 visitor_.public_reset_packet_->rejected_sequence_number); 2986 visitor_.public_reset_packet_->rejected_sequence_number);
3113 EXPECT_EQ("4.31.198.44", 2987 EXPECT_EQ("4.31.198.44",
3114 IPAddressToString(visitor_.public_reset_packet_-> 2988 IPAddressToString(
3115 client_address.address())); 2989 visitor_.public_reset_packet_->client_address.address()));
3116 EXPECT_EQ(443, visitor_.public_reset_packet_->client_address.port()); 2990 EXPECT_EQ(443, visitor_.public_reset_packet_->client_address.port());
3117 2991
3118 // Now test framing boundaries 2992 // Now test framing boundaries
3119 for (size_t i = 0; i < arraysize(packet); ++i) { 2993 for (size_t i = 0; i < arraysize(packet); ++i) {
3120 string expected_error; 2994 string expected_error;
3121 DVLOG(1) << "iteration: " << i; 2995 DVLOG(1) << "iteration: " << i;
3122 if (i < kConnectionIdOffset) { 2996 if (i < kConnectionIdOffset) {
3123 expected_error = "Unable to read public flags."; 2997 expected_error = "Unable to read public flags.";
3124 CheckProcessingFails(packet, i, expected_error, 2998 CheckProcessingFails(
3125 QUIC_INVALID_PACKET_HEADER); 2999 packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
3126 } else if (i < kPublicResetPacketMessageTagOffset) { 3000 } else if (i < kPublicResetPacketMessageTagOffset) {
3127 expected_error = "Unable to read ConnectionId."; 3001 expected_error = "Unable to read ConnectionId.";
3128 CheckProcessingFails(packet, i, expected_error, 3002 CheckProcessingFails(
3129 QUIC_INVALID_PACKET_HEADER); 3003 packet, i, expected_error, QUIC_INVALID_PACKET_HEADER);
3130 } else { 3004 } else {
3131 expected_error = "Unable to read reset message."; 3005 expected_error = "Unable to read reset message.";
3132 CheckProcessingFails(packet, i, expected_error, 3006 CheckProcessingFails(
3133 QUIC_INVALID_PUBLIC_RST_PACKET); 3007 packet, i, expected_error, QUIC_INVALID_PUBLIC_RST_PACKET);
3134 } 3008 }
3135 } 3009 }
3136 } 3010 }
3137 3011
3138 TEST_P(QuicFramerTest, VersionNegotiationPacket) { 3012 TEST_P(QuicFramerTest, VersionNegotiationPacket) {
3139 unsigned char packet[] = { 3013 unsigned char packet[] = {
3140 // public flags (version, 8 byte connection_id) 3014 // public flags (version, 8 byte connection_id)
3141 0x3D, 3015 0x3D,
3142 // connection_id 3016 // connection_id
3143 0x10, 0x32, 0x54, 0x76, 3017 0x10, 0x32, 0x54, 0x76,
3144 0x98, 0xBA, 0xDC, 0xFE, 3018 0x98, 0xBA, 0xDC, 0xFE,
3145 // version tag 3019 // version tag
3146 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), 3020 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
3147 'Q', '2', '.', '0', 3021 'Q', '2', '.', '0',
3148 }; 3022 };
3149 3023
3150 QuicFramerPeer::SetIsServer(&framer_, false); 3024 QuicFramerPeer::SetIsServer(&framer_, false);
3151 3025
3152 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 3026 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
3153 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 3027 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
3154 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); 3028 ASSERT_EQ(QUIC_NO_ERROR, framer_.error());
3155 ASSERT_TRUE(visitor_.version_negotiation_packet_.get()); 3029 ASSERT_TRUE(visitor_.version_negotiation_packet_.get());
3156 EXPECT_EQ(2u, visitor_.version_negotiation_packet_->versions.size()); 3030 EXPECT_EQ(2u, visitor_.version_negotiation_packet_->versions.size());
3157 EXPECT_EQ(GetParam(), visitor_.version_negotiation_packet_->versions[0]); 3031 EXPECT_EQ(GetParam(), visitor_.version_negotiation_packet_->versions[0]);
3158 3032
3159 for (size_t i = 0; i <= kPublicFlagsSize + PACKET_8BYTE_CONNECTION_ID; ++i) { 3033 for (size_t i = 0; i <= kPublicFlagsSize + PACKET_8BYTE_CONNECTION_ID; ++i) {
3160 string expected_error; 3034 string expected_error;
3161 QuicErrorCode error_code = QUIC_INVALID_PACKET_HEADER; 3035 QuicErrorCode error_code = QUIC_INVALID_PACKET_HEADER;
3162 if (i < kConnectionIdOffset) { 3036 if (i < kConnectionIdOffset) {
3163 expected_error = "Unable to read public flags."; 3037 expected_error = "Unable to read public flags.";
3164 } else if (i < kVersionOffset) { 3038 } else if (i < kVersionOffset) {
3165 expected_error = "Unable to read ConnectionId."; 3039 expected_error = "Unable to read ConnectionId.";
3166 } else { 3040 } else {
3167 expected_error = "Unable to read supported version in negotiation."; 3041 expected_error = "Unable to read supported version in negotiation.";
3168 error_code = QUIC_INVALID_VERSION_NEGOTIATION_PACKET; 3042 error_code = QUIC_INVALID_VERSION_NEGOTIATION_PACKET;
3169 } 3043 }
3170 CheckProcessingFails(packet, i, expected_error, error_code); 3044 CheckProcessingFails(packet, i, expected_error, error_code);
3171 } 3045 }
3172 } 3046 }
3173 3047
3174 TEST_P(QuicFramerTest, FecPacket) { 3048 TEST_P(QuicFramerTest, FecPacket) {
3175 unsigned char packet[] = { 3049 unsigned char packet[] = {// public flags (8 byte connection_id)
3176 // public flags (8 byte connection_id) 3050 0x3C,
3177 0x3C, 3051 // connection_id
3178 // connection_id 3052 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3179 0x10, 0x32, 0x54, 0x76, 3053 // packet sequence number
3180 0x98, 0xBA, 0xDC, 0xFE, 3054 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
3181 // packet sequence number 3055 // private flags (fec group & FEC)
3182 0xBC, 0x9A, 0x78, 0x56, 3056 0x06,
3183 0x34, 0x12, 3057 // first fec protected packet offset
3184 // private flags (fec group & FEC) 3058 0x01,
3185 0x06,
3186 // first fec protected packet offset
3187 0x01,
3188 3059
3189 // redundancy 3060 // redundancy
3190 'a', 'b', 'c', 'd', 3061 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
3191 'e', 'f', 'g', 'h', 3062 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
3192 'i', 'j', 'k', 'l',
3193 'm', 'n', 'o', 'p',
3194 }; 3063 };
3195 3064
3196 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 3065 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
3197 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 3066 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
3198 3067
3199 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 3068 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
3200 ASSERT_TRUE(visitor_.header_.get()); 3069 ASSERT_TRUE(visitor_.header_.get());
3201 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 3070 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
3202 3071
3203 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 3072 EXPECT_EQ(0u, visitor_.stream_frames_.size());
(...skipping 12 matching lines...) Expand all
3216 header.fec_flag = false; 3085 header.fec_flag = false;
3217 header.entropy_flag = false; 3086 header.entropy_flag = false;
3218 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 3087 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
3219 header.fec_group = 0; 3088 header.fec_group = 0;
3220 3089
3221 QuicPaddingFrame padding_frame; 3090 QuicPaddingFrame padding_frame;
3222 3091
3223 QuicFrames frames; 3092 QuicFrames frames;
3224 frames.push_back(QuicFrame(&padding_frame)); 3093 frames.push_back(QuicFrame(&padding_frame));
3225 3094
3226 unsigned char packet[kMaxPacketSize] = { 3095 unsigned char packet[kMaxPacketSize] = {// public flags (8 byte connection_id)
3227 // public flags (8 byte connection_id) 3096 0x3C,
3228 0x3C, 3097 // connection_id
3229 // connection_id 3098 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA,
3230 0x10, 0x32, 0x54, 0x76, 3099 0xDC, 0xFE,
3231 0x98, 0xBA, 0xDC, 0xFE, 3100 // packet sequence number
3232 // packet sequence number 3101 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
3233 0xBC, 0x9A, 0x78, 0x56, 3102 // private flags
3234 0x34, 0x12, 3103 0x00,
3235 // private flags
3236 0x00,
3237 3104
3238 // frame type (padding frame) 3105 // frame type (padding frame)
3239 0x00, 3106 0x00, 0x00, 0x00, 0x00, 0x00};
3240 0x00, 0x00, 0x00, 0x00
3241 };
3242 3107
3243 uint64 header_size = 3108 uint64 header_size = GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
3244 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 3109 !kIncludeVersion,
3245 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); 3110 PACKET_6BYTE_SEQUENCE_NUMBER,
3111 NOT_IN_FEC_GROUP);
3246 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1); 3112 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1);
3247 3113
3248 scoped_ptr<QuicPacket> data( 3114 scoped_ptr<QuicPacket> data(
3249 framer_.BuildUnsizedDataPacket(header, frames).packet); 3115 framer_.BuildUnsizedDataPacket(header, frames).packet);
3250 ASSERT_TRUE(data != NULL); 3116 ASSERT_TRUE(data != NULL);
3251 3117
3252 test::CompareCharArraysWithHexError("constructed packet", 3118 test::CompareCharArraysWithHexError("constructed packet",
3253 data->data(), data->length(), 3119 data->data(),
3120 data->length(),
3254 AsChars(packet), 3121 AsChars(packet),
3255 arraysize(packet)); 3122 arraysize(packet));
3256 } 3123 }
3257 3124
3258 TEST_P(QuicFramerTest, Build4ByteSequenceNumberPaddingFramePacket) { 3125 TEST_P(QuicFramerTest, Build4ByteSequenceNumberPaddingFramePacket) {
3259 QuicPacketHeader header; 3126 QuicPacketHeader header;
3260 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3127 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3261 header.public_header.reset_flag = false; 3128 header.public_header.reset_flag = false;
3262 header.public_header.version_flag = false; 3129 header.public_header.version_flag = false;
3263 header.fec_flag = false; 3130 header.fec_flag = false;
3264 header.entropy_flag = false; 3131 header.entropy_flag = false;
3265 header.public_header.sequence_number_length = PACKET_4BYTE_SEQUENCE_NUMBER; 3132 header.public_header.sequence_number_length = PACKET_4BYTE_SEQUENCE_NUMBER;
3266 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 3133 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
3267 header.fec_group = 0; 3134 header.fec_group = 0;
3268 3135
3269 QuicPaddingFrame padding_frame; 3136 QuicPaddingFrame padding_frame;
3270 3137
3271 QuicFrames frames; 3138 QuicFrames frames;
3272 frames.push_back(QuicFrame(&padding_frame)); 3139 frames.push_back(QuicFrame(&padding_frame));
3273 3140
3274 unsigned char packet[kMaxPacketSize] = { 3141 unsigned char packet[kMaxPacketSize] = {
3275 // public flags (8 byte connection_id and 4 byte sequence number) 3142 // public flags (8 byte connection_id and 4 byte sequence number)
3276 0x2C, 3143 0x2C,
3277 // connection_id 3144 // connection_id
3278 0x10, 0x32, 0x54, 0x76, 3145 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3279 0x98, 0xBA, 0xDC, 0xFE, 3146 // packet sequence number
3280 // packet sequence number 3147 0xBC, 0x9A, 0x78, 0x56,
3281 0xBC, 0x9A, 0x78, 0x56, 3148 // private flags
3282 // private flags 3149 0x00,
3283 0x00,
3284 3150
3285 // frame type (padding frame) 3151 // frame type (padding frame)
3286 0x00, 3152 0x00, 0x00, 0x00, 0x00, 0x00};
3287 0x00, 0x00, 0x00, 0x00
3288 };
3289 3153
3290 uint64 header_size = 3154 uint64 header_size = GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
3291 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 3155 !kIncludeVersion,
3292 PACKET_4BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); 3156 PACKET_4BYTE_SEQUENCE_NUMBER,
3157 NOT_IN_FEC_GROUP);
3293 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1); 3158 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1);
3294 3159
3295 scoped_ptr<QuicPacket> data( 3160 scoped_ptr<QuicPacket> data(
3296 framer_.BuildUnsizedDataPacket(header, frames).packet); 3161 framer_.BuildUnsizedDataPacket(header, frames).packet);
3297 ASSERT_TRUE(data != NULL); 3162 ASSERT_TRUE(data != NULL);
3298 3163
3299 test::CompareCharArraysWithHexError("constructed packet", 3164 test::CompareCharArraysWithHexError("constructed packet",
3300 data->data(), data->length(), 3165 data->data(),
3166 data->length(),
3301 AsChars(packet), 3167 AsChars(packet),
3302 arraysize(packet)); 3168 arraysize(packet));
3303 } 3169 }
3304 3170
3305 TEST_P(QuicFramerTest, Build2ByteSequenceNumberPaddingFramePacket) { 3171 TEST_P(QuicFramerTest, Build2ByteSequenceNumberPaddingFramePacket) {
3306 QuicPacketHeader header; 3172 QuicPacketHeader header;
3307 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3173 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3308 header.public_header.reset_flag = false; 3174 header.public_header.reset_flag = false;
3309 header.public_header.version_flag = false; 3175 header.public_header.version_flag = false;
3310 header.fec_flag = false; 3176 header.fec_flag = false;
3311 header.entropy_flag = false; 3177 header.entropy_flag = false;
3312 header.public_header.sequence_number_length = PACKET_2BYTE_SEQUENCE_NUMBER; 3178 header.public_header.sequence_number_length = PACKET_2BYTE_SEQUENCE_NUMBER;
3313 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 3179 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
3314 header.fec_group = 0; 3180 header.fec_group = 0;
3315 3181
3316 QuicPaddingFrame padding_frame; 3182 QuicPaddingFrame padding_frame;
3317 3183
3318 QuicFrames frames; 3184 QuicFrames frames;
3319 frames.push_back(QuicFrame(&padding_frame)); 3185 frames.push_back(QuicFrame(&padding_frame));
3320 3186
3321 unsigned char packet[kMaxPacketSize] = { 3187 unsigned char packet[kMaxPacketSize] = {
3322 // public flags (8 byte connection_id and 2 byte sequence number) 3188 // public flags (8 byte connection_id and 2 byte sequence number)
3323 0x1C, 3189 0x1C,
3324 // connection_id 3190 // connection_id
3325 0x10, 0x32, 0x54, 0x76, 3191 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3326 0x98, 0xBA, 0xDC, 0xFE, 3192 // packet sequence number
3327 // packet sequence number 3193 0xBC, 0x9A,
3328 0xBC, 0x9A, 3194 // private flags
3329 // private flags 3195 0x00,
3330 0x00,
3331 3196
3332 // frame type (padding frame) 3197 // frame type (padding frame)
3333 0x00, 3198 0x00, 0x00, 0x00, 0x00, 0x00};
3334 0x00, 0x00, 0x00, 0x00
3335 };
3336 3199
3337 uint64 header_size = 3200 uint64 header_size = GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
3338 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 3201 !kIncludeVersion,
3339 PACKET_2BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); 3202 PACKET_2BYTE_SEQUENCE_NUMBER,
3203 NOT_IN_FEC_GROUP);
3340 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1); 3204 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1);
3341 3205
3342 scoped_ptr<QuicPacket> data( 3206 scoped_ptr<QuicPacket> data(
3343 framer_.BuildUnsizedDataPacket(header, frames).packet); 3207 framer_.BuildUnsizedDataPacket(header, frames).packet);
3344 ASSERT_TRUE(data != NULL); 3208 ASSERT_TRUE(data != NULL);
3345 3209
3346 test::CompareCharArraysWithHexError("constructed packet", 3210 test::CompareCharArraysWithHexError("constructed packet",
3347 data->data(), data->length(), 3211 data->data(),
3212 data->length(),
3348 AsChars(packet), 3213 AsChars(packet),
3349 arraysize(packet)); 3214 arraysize(packet));
3350 } 3215 }
3351 3216
3352 TEST_P(QuicFramerTest, Build1ByteSequenceNumberPaddingFramePacket) { 3217 TEST_P(QuicFramerTest, Build1ByteSequenceNumberPaddingFramePacket) {
3353 QuicPacketHeader header; 3218 QuicPacketHeader header;
3354 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3219 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3355 header.public_header.reset_flag = false; 3220 header.public_header.reset_flag = false;
3356 header.public_header.version_flag = false; 3221 header.public_header.version_flag = false;
3357 header.fec_flag = false; 3222 header.fec_flag = false;
3358 header.entropy_flag = false; 3223 header.entropy_flag = false;
3359 header.public_header.sequence_number_length = PACKET_1BYTE_SEQUENCE_NUMBER; 3224 header.public_header.sequence_number_length = PACKET_1BYTE_SEQUENCE_NUMBER;
3360 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 3225 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
3361 header.fec_group = 0; 3226 header.fec_group = 0;
3362 3227
3363 QuicPaddingFrame padding_frame; 3228 QuicPaddingFrame padding_frame;
3364 3229
3365 QuicFrames frames; 3230 QuicFrames frames;
3366 frames.push_back(QuicFrame(&padding_frame)); 3231 frames.push_back(QuicFrame(&padding_frame));
3367 3232
3368 unsigned char packet[kMaxPacketSize] = { 3233 unsigned char packet[kMaxPacketSize] = {
3369 // public flags (8 byte connection_id and 1 byte sequence number) 3234 // public flags (8 byte connection_id and 1 byte sequence number)
3370 0x0C, 3235 0x0C,
3371 // connection_id 3236 // connection_id
3372 0x10, 0x32, 0x54, 0x76, 3237 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3373 0x98, 0xBA, 0xDC, 0xFE, 3238 // packet sequence number
3374 // packet sequence number 3239 0xBC,
3375 0xBC, 3240 // private flags
3376 // private flags 3241 0x00,
3377 0x00,
3378 3242
3379 // frame type (padding frame) 3243 // frame type (padding frame)
3380 0x00, 3244 0x00, 0x00, 0x00, 0x00, 0x00};
3381 0x00, 0x00, 0x00, 0x00
3382 };
3383 3245
3384 uint64 header_size = 3246 uint64 header_size = GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID,
3385 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 3247 !kIncludeVersion,
3386 PACKET_1BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); 3248 PACKET_1BYTE_SEQUENCE_NUMBER,
3249 NOT_IN_FEC_GROUP);
3387 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1); 3250 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1);
3388 3251
3389 scoped_ptr<QuicPacket> data( 3252 scoped_ptr<QuicPacket> data(
3390 framer_.BuildUnsizedDataPacket(header, frames).packet); 3253 framer_.BuildUnsizedDataPacket(header, frames).packet);
3391 ASSERT_TRUE(data != NULL); 3254 ASSERT_TRUE(data != NULL);
3392 3255
3393 test::CompareCharArraysWithHexError("constructed packet", 3256 test::CompareCharArraysWithHexError("constructed packet",
3394 data->data(), data->length(), 3257 data->data(),
3258 data->length(),
3395 AsChars(packet), 3259 AsChars(packet),
3396 arraysize(packet)); 3260 arraysize(packet));
3397 } 3261 }
3398 3262
3399 TEST_P(QuicFramerTest, BuildStreamFramePacket) { 3263 TEST_P(QuicFramerTest, BuildStreamFramePacket) {
3400 QuicPacketHeader header; 3264 QuicPacketHeader header;
3401 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3265 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3402 header.public_header.reset_flag = false; 3266 header.public_header.reset_flag = false;
3403 header.public_header.version_flag = false; 3267 header.public_header.version_flag = false;
3404 header.fec_flag = false; 3268 header.fec_flag = false;
3405 header.entropy_flag = true; 3269 header.entropy_flag = true;
3406 header.packet_sequence_number = GG_UINT64_C(0x77123456789ABC); 3270 header.packet_sequence_number = GG_UINT64_C(0x77123456789ABC);
3407 header.fec_group = 0; 3271 header.fec_group = 0;
3408 3272
3409 QuicStreamFrame stream_frame; 3273 QuicStreamFrame stream_frame;
3410 stream_frame.stream_id = 0x01020304; 3274 stream_frame.stream_id = 0x01020304;
3411 stream_frame.fin = true; 3275 stream_frame.fin = true;
3412 stream_frame.offset = GG_UINT64_C(0xBA98FEDC32107654); 3276 stream_frame.offset = GG_UINT64_C(0xBA98FEDC32107654);
3413 stream_frame.data = MakeIOVector("hello world!"); 3277 stream_frame.data = MakeIOVector("hello world!");
3414 3278
3415 QuicFrames frames; 3279 QuicFrames frames;
3416 frames.push_back(QuicFrame(&stream_frame)); 3280 frames.push_back(QuicFrame(&stream_frame));
3417 3281
3418 unsigned char packet[] = { 3282 unsigned char packet[] = {// public flags (8 byte connection_id)
3419 // public flags (8 byte connection_id) 3283 0x3C,
3420 0x3C, 3284 // connection_id
3421 // connection_id 3285 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3422 0x10, 0x32, 0x54, 0x76, 3286 // packet sequence number
3423 0x98, 0xBA, 0xDC, 0xFE, 3287 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
3424 // packet sequence number 3288 // private flags (entropy)
3425 0xBC, 0x9A, 0x78, 0x56, 3289 0x01,
3426 0x34, 0x12,
3427 // private flags (entropy)
3428 0x01,
3429 3290
3430 // frame type (stream frame with fin and no length) 3291 // frame type (stream frame with fin and no length)
3431 0xDF, 3292 0xDF,
3432 // stream id 3293 // stream id
3433 0x04, 0x03, 0x02, 0x01, 3294 0x04, 0x03, 0x02, 0x01,
3434 // offset 3295 // offset
3435 0x54, 0x76, 0x10, 0x32, 3296 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA,
3436 0xDC, 0xFE, 0x98, 0xBA, 3297 // data
3437 // data 3298 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o',
3438 'h', 'e', 'l', 'l', 3299 'r', 'l', 'd', '!',
3439 'o', ' ', 'w', 'o',
3440 'r', 'l', 'd', '!',
3441 }; 3300 };
3442 3301
3443 scoped_ptr<QuicPacket> data( 3302 scoped_ptr<QuicPacket> data(
3444 framer_.BuildUnsizedDataPacket(header, frames).packet); 3303 framer_.BuildUnsizedDataPacket(header, frames).packet);
3445 ASSERT_TRUE(data != NULL); 3304 ASSERT_TRUE(data != NULL);
3446 3305
3447 test::CompareCharArraysWithHexError("constructed packet", 3306 test::CompareCharArraysWithHexError("constructed packet",
3448 data->data(), data->length(), 3307 data->data(),
3449 AsChars(packet), arraysize(packet)); 3308 data->length(),
3309 AsChars(packet),
3310 arraysize(packet));
3450 } 3311 }
3451 3312
3452 TEST_P(QuicFramerTest, BuildStreamFramePacketInFecGroup) { 3313 TEST_P(QuicFramerTest, BuildStreamFramePacketInFecGroup) {
3453 QuicPacketHeader header; 3314 QuicPacketHeader header;
3454 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3315 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3455 header.public_header.reset_flag = false; 3316 header.public_header.reset_flag = false;
3456 header.public_header.version_flag = false; 3317 header.public_header.version_flag = false;
3457 header.fec_flag = false; 3318 header.fec_flag = false;
3458 header.entropy_flag = true; 3319 header.entropy_flag = true;
3459 header.packet_sequence_number = GG_UINT64_C(0x77123456789ABC); 3320 header.packet_sequence_number = GG_UINT64_C(0x77123456789ABC);
3460 header.is_in_fec_group = IN_FEC_GROUP; 3321 header.is_in_fec_group = IN_FEC_GROUP;
3461 header.fec_group = GG_UINT64_C(0x77123456789ABC); 3322 header.fec_group = GG_UINT64_C(0x77123456789ABC);
3462 3323
3463 QuicStreamFrame stream_frame; 3324 QuicStreamFrame stream_frame;
3464 stream_frame.stream_id = 0x01020304; 3325 stream_frame.stream_id = 0x01020304;
3465 stream_frame.fin = true; 3326 stream_frame.fin = true;
3466 stream_frame.offset = GG_UINT64_C(0xBA98FEDC32107654); 3327 stream_frame.offset = GG_UINT64_C(0xBA98FEDC32107654);
3467 stream_frame.data = MakeIOVector("hello world!"); 3328 stream_frame.data = MakeIOVector("hello world!");
3468 3329
3469 QuicFrames frames; 3330 QuicFrames frames;
3470 frames.push_back(QuicFrame(&stream_frame)); 3331 frames.push_back(QuicFrame(&stream_frame));
3471 unsigned char packet[] = { 3332 unsigned char packet[] = {
3472 // public flags (8 byte connection_id) 3333 // public flags (8 byte connection_id)
3473 0x3C, 3334 0x3C,
3474 // connection_id 3335 // connection_id
3475 0x10, 0x32, 0x54, 0x76, 3336 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3476 0x98, 0xBA, 0xDC, 0xFE, 3337 // packet sequence number
3477 // packet sequence number 3338 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
3478 0xBC, 0x9A, 0x78, 0x56, 3339 // private flags (entropy, is_in_fec_group)
3479 0x34, 0x12, 3340 0x03,
3480 // private flags (entropy, is_in_fec_group) 3341 // FEC group
3481 0x03, 3342 0x00,
3482 // FEC group 3343 // frame type (stream frame with fin and data length field)
3483 0x00, 3344 0xFF,
3484 // frame type (stream frame with fin and data length field) 3345 // stream id
3485 0xFF, 3346 0x04, 0x03, 0x02, 0x01,
3486 // stream id 3347 // offset
3487 0x04, 0x03, 0x02, 0x01, 3348 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA,
3488 // offset 3349 // data length (since packet is in an FEC group)
3489 0x54, 0x76, 0x10, 0x32, 3350 0x0C, 0x00,
3490 0xDC, 0xFE, 0x98, 0xBA, 3351 // data
3491 // data length (since packet is in an FEC group) 3352 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!',
3492 0x0C, 0x00,
3493 // data
3494 'h', 'e', 'l', 'l',
3495 'o', ' ', 'w', 'o',
3496 'r', 'l', 'd', '!',
3497 }; 3353 };
3498 3354
3499 scoped_ptr<QuicPacket> data( 3355 scoped_ptr<QuicPacket> data(
3500 framer_.BuildUnsizedDataPacket(header, frames).packet); 3356 framer_.BuildUnsizedDataPacket(header, frames).packet);
3501 ASSERT_TRUE(data != NULL); 3357 ASSERT_TRUE(data != NULL);
3502 3358
3503 test::CompareCharArraysWithHexError("constructed packet", 3359 test::CompareCharArraysWithHexError("constructed packet",
3504 data->data(), data->length(), 3360 data->data(),
3505 AsChars(packet), arraysize(packet)); 3361 data->length(),
3362 AsChars(packet),
3363 arraysize(packet));
3506 } 3364 }
3507 3365
3508 TEST_P(QuicFramerTest, BuildStreamFramePacketWithVersionFlag) { 3366 TEST_P(QuicFramerTest, BuildStreamFramePacketWithVersionFlag) {
3509 QuicPacketHeader header; 3367 QuicPacketHeader header;
3510 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3368 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3511 header.public_header.reset_flag = false; 3369 header.public_header.reset_flag = false;
3512 header.public_header.version_flag = true; 3370 header.public_header.version_flag = true;
3513 header.fec_flag = false; 3371 header.fec_flag = false;
3514 header.entropy_flag = true; 3372 header.entropy_flag = true;
3515 header.packet_sequence_number = GG_UINT64_C(0x77123456789ABC); 3373 header.packet_sequence_number = GG_UINT64_C(0x77123456789ABC);
3516 header.fec_group = 0; 3374 header.fec_group = 0;
3517 3375
3518 QuicStreamFrame stream_frame; 3376 QuicStreamFrame stream_frame;
3519 stream_frame.stream_id = 0x01020304; 3377 stream_frame.stream_id = 0x01020304;
3520 stream_frame.fin = true; 3378 stream_frame.fin = true;
3521 stream_frame.offset = GG_UINT64_C(0xBA98FEDC32107654); 3379 stream_frame.offset = GG_UINT64_C(0xBA98FEDC32107654);
3522 stream_frame.data = MakeIOVector("hello world!"); 3380 stream_frame.data = MakeIOVector("hello world!");
3523 3381
3524 QuicFrames frames; 3382 QuicFrames frames;
3525 frames.push_back(QuicFrame(&stream_frame)); 3383 frames.push_back(QuicFrame(&stream_frame));
3526 3384
3527 unsigned char packet[] = { 3385 unsigned char packet[] = {
3528 // public flags (version, 8 byte connection_id) 3386 // public flags (version, 8 byte connection_id)
3529 0x3D, 3387 0x3D,
3530 // connection_id 3388 // connection_id
3531 0x10, 0x32, 0x54, 0x76, 3389 0x10, 0x32, 0x54, 0x76,
3532 0x98, 0xBA, 0xDC, 0xFE, 3390 0x98, 0xBA, 0xDC, 0xFE,
3533 // version tag 3391 // version tag
3534 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), 3392 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
3535 // packet sequence number 3393 // packet sequence number
3536 0xBC, 0x9A, 0x78, 0x56, 3394 0xBC, 0x9A, 0x78, 0x56,
3537 0x34, 0x12, 3395 0x34, 0x12,
3538 // private flags (entropy) 3396 // private flags (entropy)
3539 0x01, 3397 0x01,
3540 3398
3541 // frame type (stream frame with fin and no length) 3399 // frame type (stream frame with fin and no length)
3542 0xDF, 3400 0xDF,
3543 // stream id 3401 // stream id
3544 0x04, 0x03, 0x02, 0x01, 3402 0x04, 0x03, 0x02, 0x01,
3545 // offset 3403 // offset
3546 0x54, 0x76, 0x10, 0x32, 3404 0x54, 0x76, 0x10, 0x32,
3547 0xDC, 0xFE, 0x98, 0xBA, 3405 0xDC, 0xFE, 0x98, 0xBA,
3548 // data 3406 // data
3549 'h', 'e', 'l', 'l', 3407 'h', 'e', 'l', 'l',
3550 'o', ' ', 'w', 'o', 3408 'o', ' ', 'w', 'o',
3551 'r', 'l', 'd', '!', 3409 'r', 'l', 'd', '!',
3552 }; 3410 };
3553 3411
3554 QuicFramerPeer::SetIsServer(&framer_, false); 3412 QuicFramerPeer::SetIsServer(&framer_, false);
3555 scoped_ptr<QuicPacket> data( 3413 scoped_ptr<QuicPacket> data(
3556 framer_.BuildUnsizedDataPacket(header, frames).packet); 3414 framer_.BuildUnsizedDataPacket(header, frames).packet);
3557 ASSERT_TRUE(data != NULL); 3415 ASSERT_TRUE(data != NULL);
3558 3416
3559 test::CompareCharArraysWithHexError("constructed packet", 3417 test::CompareCharArraysWithHexError("constructed packet",
3560 data->data(), data->length(), 3418 data->data(),
3561 AsChars(packet), arraysize(packet)); 3419 data->length(),
3420 AsChars(packet),
3421 arraysize(packet));
3562 } 3422 }
3563 3423
3564 TEST_P(QuicFramerTest, BuildVersionNegotiationPacket) { 3424 TEST_P(QuicFramerTest, BuildVersionNegotiationPacket) {
3565 QuicPacketPublicHeader header; 3425 QuicPacketPublicHeader header;
3566 header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3426 header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3567 header.reset_flag = false; 3427 header.reset_flag = false;
3568 header.version_flag = true; 3428 header.version_flag = true;
3569 3429
3570 unsigned char packet[] = { 3430 unsigned char packet[] = {
3571 // public flags (version, 8 byte connection_id) 3431 // public flags (version, 8 byte connection_id)
3572 0x0D, 3432 0x0D,
3573 // connection_id 3433 // connection_id
3574 0x10, 0x32, 0x54, 0x76, 3434 0x10, 0x32, 0x54, 0x76,
3575 0x98, 0xBA, 0xDC, 0xFE, 3435 0x98, 0xBA, 0xDC, 0xFE,
3576 // version tag 3436 // version tag
3577 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), 3437 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(),
3578 }; 3438 };
3579 3439
3580 QuicVersionVector versions; 3440 QuicVersionVector versions;
3581 versions.push_back(GetParam()); 3441 versions.push_back(GetParam());
3582 scoped_ptr<QuicEncryptedPacket> data( 3442 scoped_ptr<QuicEncryptedPacket> data(
3583 framer_.BuildVersionNegotiationPacket(header, versions)); 3443 framer_.BuildVersionNegotiationPacket(header, versions));
3584 3444
3585 test::CompareCharArraysWithHexError("constructed packet", 3445 test::CompareCharArraysWithHexError("constructed packet",
3586 data->data(), data->length(), 3446 data->data(),
3587 AsChars(packet), arraysize(packet)); 3447 data->length(),
3448 AsChars(packet),
3449 arraysize(packet));
3588 } 3450 }
3589 3451
3590 TEST_P(QuicFramerTest, BuildAckFramePacket) { 3452 TEST_P(QuicFramerTest, BuildAckFramePacket) {
3591 if (version_ <= QUIC_VERSION_15) { 3453 if (version_ <= QUIC_VERSION_15) {
3592 return; 3454 return;
3593 } 3455 }
3594 QuicPacketHeader header; 3456 QuicPacketHeader header;
3595 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3457 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3596 header.public_header.reset_flag = false; 3458 header.public_header.reset_flag = false;
3597 header.public_header.version_flag = false; 3459 header.public_header.version_flag = false;
3598 header.fec_flag = false; 3460 header.fec_flag = false;
3599 header.entropy_flag = true; 3461 header.entropy_flag = true;
3600 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8); 3462 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8);
3601 header.fec_group = 0; 3463 header.fec_group = 0;
3602 3464
3603 QuicAckFrame ack_frame; 3465 QuicAckFrame ack_frame;
3604 ack_frame.received_info.entropy_hash = 0x43; 3466 ack_frame.received_info.entropy_hash = 0x43;
3605 ack_frame.received_info.largest_observed = GG_UINT64_C(0x770123456789ABF); 3467 ack_frame.received_info.largest_observed = GG_UINT64_C(0x770123456789ABF);
3606 ack_frame.received_info.delta_time_largest_observed = QuicTime::Delta::Zero(); 3468 ack_frame.received_info.delta_time_largest_observed = QuicTime::Delta::Zero();
3607 ack_frame.received_info.missing_packets.insert( 3469 ack_frame.received_info.missing_packets.insert(
3608 GG_UINT64_C(0x770123456789ABE)); 3470 GG_UINT64_C(0x770123456789ABE));
3609 3471
3610 QuicFrames frames; 3472 QuicFrames frames;
3611 frames.push_back(QuicFrame(&ack_frame)); 3473 frames.push_back(QuicFrame(&ack_frame));
3612 3474
3613 unsigned char packet[] = { 3475 unsigned char packet[] = {
3614 // public flags (8 byte connection_id) 3476 // public flags (8 byte connection_id)
3615 0x3C, 3477 0x3C,
3616 // connection_id 3478 // connection_id
3617 0x10, 0x32, 0x54, 0x76, 3479 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3618 0x98, 0xBA, 0xDC, 0xFE, 3480 // packet sequence number
3619 // packet sequence number 3481 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
3620 0xA8, 0x9A, 0x78, 0x56, 3482 // private flags (entropy)
3621 0x34, 0x12, 3483 0x01,
3622 // private flags (entropy)
3623 0x01,
3624 3484
3625 // frame type (ack frame) 3485 // frame type (ack frame)
3626 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) 3486 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
3627 0x6C, 3487 0x6C,
3628 // entropy hash of all received packets. 3488 // entropy hash of all received packets.
3629 0x43, 3489 0x43,
3630 // largest observed packet sequence number 3490 // largest observed packet sequence number
3631 0xBF, 0x9A, 0x78, 0x56, 3491 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
3632 0x34, 0x12, 3492 // Zero delta time.
3633 // Zero delta time. 3493 0x0, 0x0,
3634 0x0, 0x0, 3494 // num missing packet ranges
3635 // num missing packet ranges 3495 0x01,
3636 0x01, 3496 // missing packet delta
3637 // missing packet delta 3497 0x01,
3638 0x01, 3498 // 0 more missing packets in range.
3639 // 0 more missing packets in range. 3499 0x00,
3640 0x00, 3500 // 0 revived packets.
3641 // 0 revived packets. 3501 0x00,
3642 0x00,
3643 }; 3502 };
3644 3503
3645 scoped_ptr<QuicPacket> data( 3504 scoped_ptr<QuicPacket> data(
3646 framer_.BuildUnsizedDataPacket(header, frames).packet); 3505 framer_.BuildUnsizedDataPacket(header, frames).packet);
3647 ASSERT_TRUE(data != NULL); 3506 ASSERT_TRUE(data != NULL);
3648 3507
3649 test::CompareCharArraysWithHexError("constructed packet", 3508 test::CompareCharArraysWithHexError("constructed packet",
3650 data->data(), data->length(), 3509 data->data(),
3651 AsChars(packet), arraysize(packet)); 3510 data->length(),
3511 AsChars(packet),
3512 arraysize(packet));
3652 } 3513 }
3653 3514
3654 TEST_P(QuicFramerTest, BuildAckFramePacket15) { 3515 TEST_P(QuicFramerTest, BuildAckFramePacket15) {
3655 if (version_ != QUIC_VERSION_15) { 3516 if (version_ != QUIC_VERSION_15) {
3656 return; 3517 return;
3657 } 3518 }
3658 QuicPacketHeader header; 3519 QuicPacketHeader header;
3659 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3520 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3660 header.public_header.reset_flag = false; 3521 header.public_header.reset_flag = false;
3661 header.public_header.version_flag = false; 3522 header.public_header.version_flag = false;
3662 header.fec_flag = false; 3523 header.fec_flag = false;
3663 header.entropy_flag = true; 3524 header.entropy_flag = true;
3664 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8); 3525 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8);
3665 header.fec_group = 0; 3526 header.fec_group = 0;
3666 3527
3667 QuicAckFrame ack_frame; 3528 QuicAckFrame ack_frame;
3668 ack_frame.received_info.entropy_hash = 0x43; 3529 ack_frame.received_info.entropy_hash = 0x43;
3669 ack_frame.received_info.largest_observed = GG_UINT64_C(0x770123456789ABF); 3530 ack_frame.received_info.largest_observed = GG_UINT64_C(0x770123456789ABF);
3670 ack_frame.received_info.delta_time_largest_observed = QuicTime::Delta::Zero(); 3531 ack_frame.received_info.delta_time_largest_observed = QuicTime::Delta::Zero();
3671 ack_frame.received_info.missing_packets.insert( 3532 ack_frame.received_info.missing_packets.insert(
3672 GG_UINT64_C(0x770123456789ABE)); 3533 GG_UINT64_C(0x770123456789ABE));
3673 ack_frame.sent_info.entropy_hash = 0x14; 3534 ack_frame.sent_info.entropy_hash = 0x14;
3674 ack_frame.sent_info.least_unacked = GG_UINT64_C(0x770123456789AA0); 3535 ack_frame.sent_info.least_unacked = GG_UINT64_C(0x770123456789AA0);
3675 3536
3676 QuicFrames frames; 3537 QuicFrames frames;
3677 frames.push_back(QuicFrame(&ack_frame)); 3538 frames.push_back(QuicFrame(&ack_frame));
3678 3539
3679 unsigned char packet[] = { 3540 unsigned char packet[] = {
3680 // public flags (8 byte connection_id) 3541 // public flags (8 byte connection_id)
3681 0x3C, 3542 0x3C,
3682 // connection_id 3543 // connection_id
3683 0x10, 0x32, 0x54, 0x76, 3544 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3684 0x98, 0xBA, 0xDC, 0xFE, 3545 // packet sequence number
3685 // packet sequence number 3546 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
3686 0xA8, 0x9A, 0x78, 0x56, 3547 // private flags (entropy)
3687 0x34, 0x12, 3548 0x01,
3688 // private flags (entropy)
3689 0x01,
3690 3549
3691 // frame type (ack frame) 3550 // frame type (ack frame)
3692 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) 3551 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta)
3693 0x6C, 3552 0x6C,
3694 // entropy hash of sent packets till least awaiting - 1. 3553 // entropy hash of sent packets till least awaiting - 1.
3695 0x14, 3554 0x14,
3696 // least packet sequence number awaiting an ack, delta from sequence number. 3555 // least packet sequence number awaiting an ack, delta from sequence
3697 0x08, 0x00, 0x00, 0x00, 3556 // number.
3698 0x00, 0x00, 3557 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
3699 // entropy hash of all received packets. 3558 // entropy hash of all received packets.
3700 0x43, 3559 0x43,
3701 // largest observed packet sequence number 3560 // largest observed packet sequence number
3702 0xBF, 0x9A, 0x78, 0x56, 3561 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
3703 0x34, 0x12, 3562 // Zero delta time.
3704 // Zero delta time. 3563 0x0, 0x0,
3705 0x0, 0x0, 3564 // num missing packet ranges
3706 // num missing packet ranges 3565 0x01,
3707 0x01, 3566 // missing packet delta
3708 // missing packet delta 3567 0x01,
3709 0x01, 3568 // 0 more missing packets in range.
3710 // 0 more missing packets in range. 3569 0x00,
3711 0x00, 3570 // 0 revived packets.
3712 // 0 revived packets. 3571 0x00,
3713 0x00,
3714 }; 3572 };
3715 3573
3716 scoped_ptr<QuicPacket> data( 3574 scoped_ptr<QuicPacket> data(
3717 framer_.BuildUnsizedDataPacket(header, frames).packet); 3575 framer_.BuildUnsizedDataPacket(header, frames).packet);
3718 ASSERT_TRUE(data != NULL); 3576 ASSERT_TRUE(data != NULL);
3719 3577
3720 test::CompareCharArraysWithHexError("constructed packet", 3578 test::CompareCharArraysWithHexError("constructed packet",
3721 data->data(), data->length(), 3579 data->data(),
3722 AsChars(packet), arraysize(packet)); 3580 data->length(),
3581 AsChars(packet),
3582 arraysize(packet));
3723 } 3583 }
3724 3584
3725 TEST_P(QuicFramerTest, BuildCongestionFeedbackFramePacketTCP) { 3585 TEST_P(QuicFramerTest, BuildCongestionFeedbackFramePacketTCP) {
3726 QuicPacketHeader header; 3586 QuicPacketHeader header;
3727 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3587 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3728 header.public_header.reset_flag = false; 3588 header.public_header.reset_flag = false;
3729 header.public_header.version_flag = false; 3589 header.public_header.version_flag = false;
3730 header.fec_flag = false; 3590 header.fec_flag = false;
3731 header.entropy_flag = false; 3591 header.entropy_flag = false;
3732 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 3592 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
3733 header.fec_group = 0; 3593 header.fec_group = 0;
3734 3594
3735 QuicCongestionFeedbackFrame congestion_feedback_frame; 3595 QuicCongestionFeedbackFrame congestion_feedback_frame;
3736 congestion_feedback_frame.type = kTCP; 3596 congestion_feedback_frame.type = kTCP;
3737 congestion_feedback_frame.tcp.receive_window = 0x4030; 3597 congestion_feedback_frame.tcp.receive_window = 0x4030;
3738 3598
3739 QuicFrames frames; 3599 QuicFrames frames;
3740 frames.push_back(QuicFrame(&congestion_feedback_frame)); 3600 frames.push_back(QuicFrame(&congestion_feedback_frame));
3741 3601
3742 unsigned char packet[] = { 3602 unsigned char packet[] = {// public flags (8 byte connection_id)
3743 // public flags (8 byte connection_id) 3603 0x3C,
3744 0x3C, 3604 // connection_id
3745 // connection_id 3605 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3746 0x10, 0x32, 0x54, 0x76, 3606 // packet sequence number
3747 0x98, 0xBA, 0xDC, 0xFE, 3607 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
3748 // packet sequence number 3608 // private flags
3749 0xBC, 0x9A, 0x78, 0x56, 3609 0x00,
3750 0x34, 0x12,
3751 // private flags
3752 0x00,
3753 3610
3754 // frame type (congestion feedback frame) 3611 // frame type (congestion feedback frame)
3755 0x20, 3612 0x20,
3756 // congestion feedback type (TCP) 3613 // congestion feedback type (TCP)
3757 0x00, 3614 0x00,
3758 // TCP receive window 3615 // TCP receive window
3759 0x03, 0x04, 3616 0x03, 0x04,
3760 }; 3617 };
3761 3618
3762 scoped_ptr<QuicPacket> data( 3619 scoped_ptr<QuicPacket> data(
3763 framer_.BuildUnsizedDataPacket(header, frames).packet); 3620 framer_.BuildUnsizedDataPacket(header, frames).packet);
3764 ASSERT_TRUE(data != NULL); 3621 ASSERT_TRUE(data != NULL);
3765 3622
3766 test::CompareCharArraysWithHexError("constructed packet", 3623 test::CompareCharArraysWithHexError("constructed packet",
3767 data->data(), data->length(), 3624 data->data(),
3768 AsChars(packet), arraysize(packet)); 3625 data->length(),
3626 AsChars(packet),
3627 arraysize(packet));
3769 } 3628 }
3770 3629
3771 TEST_P(QuicFramerTest, BuildCongestionFeedbackFramePacketInterArrival) { 3630 TEST_P(QuicFramerTest, BuildCongestionFeedbackFramePacketInterArrival) {
3772 QuicPacketHeader header; 3631 QuicPacketHeader header;
3773 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3632 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3774 header.public_header.reset_flag = false; 3633 header.public_header.reset_flag = false;
3775 header.public_header.version_flag = false; 3634 header.public_header.version_flag = false;
3776 header.fec_flag = false; 3635 header.fec_flag = false;
3777 header.entropy_flag = false; 3636 header.entropy_flag = false;
3778 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 3637 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
3779 header.fec_group = 0; 3638 header.fec_group = 0;
3780 3639
3781 QuicCongestionFeedbackFrame frame; 3640 QuicCongestionFeedbackFrame frame;
3782 frame.type = kInterArrival; 3641 frame.type = kInterArrival;
3783 frame.inter_arrival.received_packet_times.insert( 3642 frame.inter_arrival.received_packet_times.insert(make_pair(
3784 make_pair(GG_UINT64_C(0x0123456789ABA), 3643 GG_UINT64_C(0x0123456789ABA),
3785 start_.Add(QuicTime::Delta::FromMicroseconds( 3644 start_.Add(
3786 GG_UINT64_C(0x07E1D2C3B4A59687))))); 3645 QuicTime::Delta::FromMicroseconds(GG_UINT64_C(0x07E1D2C3B4A59687)))));
3787 frame.inter_arrival.received_packet_times.insert( 3646 frame.inter_arrival.received_packet_times.insert(make_pair(
3788 make_pair(GG_UINT64_C(0x0123456789ABB), 3647 GG_UINT64_C(0x0123456789ABB),
3789 start_.Add(QuicTime::Delta::FromMicroseconds( 3648 start_.Add(
3790 GG_UINT64_C(0x07E1D2C3B4A59688))))); 3649 QuicTime::Delta::FromMicroseconds(GG_UINT64_C(0x07E1D2C3B4A59688)))));
3791 frame.inter_arrival.received_packet_times.insert( 3650 frame.inter_arrival.received_packet_times.insert(make_pair(
3792 make_pair(GG_UINT64_C(0x0123456789ABD), 3651 GG_UINT64_C(0x0123456789ABD),
3793 start_.Add(QuicTime::Delta::FromMicroseconds( 3652 start_.Add(
3794 GG_UINT64_C(0x07E1D2C3B4A59689))))); 3653 QuicTime::Delta::FromMicroseconds(GG_UINT64_C(0x07E1D2C3B4A59689)))));
3795 QuicFrames frames; 3654 QuicFrames frames;
3796 frames.push_back(QuicFrame(&frame)); 3655 frames.push_back(QuicFrame(&frame));
3797 3656
3798 unsigned char packet[] = { 3657 unsigned char packet[] = {// public flags (8 byte connection_id)
3799 // public flags (8 byte connection_id) 3658 0x3C,
3800 0x3C, 3659 // connection_id
3801 // connection_id 3660 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3802 0x10, 0x32, 0x54, 0x76, 3661 // packet sequence number
3803 0x98, 0xBA, 0xDC, 0xFE, 3662 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
3804 // packet sequence number 3663 // private flags
3805 0xBC, 0x9A, 0x78, 0x56, 3664 0x00,
3806 0x34, 0x12,
3807 // private flags
3808 0x00,
3809 3665
3810 // frame type (congestion feedback frame) 3666 // frame type (congestion feedback frame)
3811 0x20, 3667 0x20,
3812 // congestion feedback type (inter arrival) 3668 // congestion feedback type (inter arrival)
3813 0x01, 3669 0x01,
3814 // num received packets 3670 // num received packets
3815 0x03, 3671 0x03,
3816 // lowest sequence number 3672 // lowest sequence number
3817 0xBA, 0x9A, 0x78, 0x56, 3673 0xBA, 0x9A, 0x78, 0x56, 0x34, 0x12,
3818 0x34, 0x12, 3674 // receive time
3819 // receive time 3675 0x87, 0x96, 0xA5, 0xB4, 0xC3, 0xD2, 0xE1, 0x07,
3820 0x87, 0x96, 0xA5, 0xB4, 3676 // sequence delta
3821 0xC3, 0xD2, 0xE1, 0x07, 3677 0x01, 0x00,
3822 // sequence delta 3678 // time delta
3823 0x01, 0x00, 3679 0x01, 0x00, 0x00, 0x00,
3824 // time delta 3680 // sequence delta (skip one packet)
3825 0x01, 0x00, 0x00, 0x00, 3681 0x03, 0x00,
3826 // sequence delta (skip one packet) 3682 // time delta
3827 0x03, 0x00, 3683 0x02, 0x00, 0x00, 0x00,
3828 // time delta
3829 0x02, 0x00, 0x00, 0x00,
3830 }; 3684 };
3831 3685
3832 scoped_ptr<QuicPacket> data( 3686 scoped_ptr<QuicPacket> data(
3833 framer_.BuildUnsizedDataPacket(header, frames).packet); 3687 framer_.BuildUnsizedDataPacket(header, frames).packet);
3834 ASSERT_TRUE(data != NULL); 3688 ASSERT_TRUE(data != NULL);
3835 3689
3836 test::CompareCharArraysWithHexError("constructed packet", 3690 test::CompareCharArraysWithHexError("constructed packet",
3837 data->data(), data->length(), 3691 data->data(),
3838 AsChars(packet), arraysize(packet)); 3692 data->length(),
3693 AsChars(packet),
3694 arraysize(packet));
3839 } 3695 }
3840 3696
3841 TEST_P(QuicFramerTest, BuildStopWaitingPacket) { 3697 TEST_P(QuicFramerTest, BuildStopWaitingPacket) {
3842 if (version_ <= QUIC_VERSION_15) { 3698 if (version_ <= QUIC_VERSION_15) {
3843 return; 3699 return;
3844 } 3700 }
3845 QuicPacketHeader header; 3701 QuicPacketHeader header;
3846 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3702 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3847 header.public_header.reset_flag = false; 3703 header.public_header.reset_flag = false;
3848 header.public_header.version_flag = false; 3704 header.public_header.version_flag = false;
3849 header.fec_flag = false; 3705 header.fec_flag = false;
3850 header.entropy_flag = true; 3706 header.entropy_flag = true;
3851 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8); 3707 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8);
3852 header.fec_group = 0; 3708 header.fec_group = 0;
3853 3709
3854 QuicStopWaitingFrame stop_waiting_frame; 3710 QuicStopWaitingFrame stop_waiting_frame;
3855 stop_waiting_frame.entropy_hash = 0x14; 3711 stop_waiting_frame.entropy_hash = 0x14;
3856 stop_waiting_frame.least_unacked = GG_UINT64_C(0x770123456789AA0); 3712 stop_waiting_frame.least_unacked = GG_UINT64_C(0x770123456789AA0);
3857 3713
3858 QuicFrames frames; 3714 QuicFrames frames;
3859 frames.push_back(QuicFrame(&stop_waiting_frame)); 3715 frames.push_back(QuicFrame(&stop_waiting_frame));
3860 3716
3861 unsigned char packet[] = { 3717 unsigned char packet[] = {
3862 // public flags (8 byte connection_id) 3718 // public flags (8 byte connection_id)
3863 0x3C, 3719 0x3C,
3864 // connection_id 3720 // connection_id
3865 0x10, 0x32, 0x54, 0x76, 3721 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3866 0x98, 0xBA, 0xDC, 0xFE, 3722 // packet sequence number
3867 // packet sequence number 3723 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12,
3868 0xA8, 0x9A, 0x78, 0x56, 3724 // private flags (entropy)
3869 0x34, 0x12, 3725 0x01,
3870 // private flags (entropy)
3871 0x01,
3872 3726
3873 // frame type (stop waiting frame) 3727 // frame type (stop waiting frame)
3874 0x06, 3728 0x06,
3875 // entropy hash of sent packets till least awaiting - 1. 3729 // entropy hash of sent packets till least awaiting - 1.
3876 0x14, 3730 0x14,
3877 // least packet sequence number awaiting an ack, delta from sequence number. 3731 // least packet sequence number awaiting an ack, delta from sequence
3878 0x08, 0x00, 0x00, 0x00, 3732 // number.
3879 0x00, 0x00, 3733 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
3880 }; 3734 };
3881 3735
3882 scoped_ptr<QuicPacket> data( 3736 scoped_ptr<QuicPacket> data(
3883 framer_.BuildUnsizedDataPacket(header, frames).packet); 3737 framer_.BuildUnsizedDataPacket(header, frames).packet);
3884 ASSERT_TRUE(data != NULL); 3738 ASSERT_TRUE(data != NULL);
3885 3739
3886 test::CompareCharArraysWithHexError("constructed packet", 3740 test::CompareCharArraysWithHexError("constructed packet",
3887 data->data(), data->length(), 3741 data->data(),
3888 AsChars(packet), arraysize(packet)); 3742 data->length(),
3743 AsChars(packet),
3744 arraysize(packet));
3889 } 3745 }
3890 3746
3891 TEST_P(QuicFramerTest, BuildCongestionFeedbackFramePacketFixRate) { 3747 TEST_P(QuicFramerTest, BuildCongestionFeedbackFramePacketFixRate) {
3892 QuicPacketHeader header; 3748 QuicPacketHeader header;
3893 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3749 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3894 header.public_header.reset_flag = false; 3750 header.public_header.reset_flag = false;
3895 header.public_header.version_flag = false; 3751 header.public_header.version_flag = false;
3896 header.fec_flag = false; 3752 header.fec_flag = false;
3897 header.entropy_flag = false; 3753 header.entropy_flag = false;
3898 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 3754 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
3899 header.fec_group = 0; 3755 header.fec_group = 0;
3900 3756
3901 QuicCongestionFeedbackFrame congestion_feedback_frame; 3757 QuicCongestionFeedbackFrame congestion_feedback_frame;
3902 congestion_feedback_frame.type = kFixRate; 3758 congestion_feedback_frame.type = kFixRate;
3903 congestion_feedback_frame.fix_rate.bitrate 3759 congestion_feedback_frame.fix_rate.bitrate =
3904 = QuicBandwidth::FromBytesPerSecond(0x04030201); 3760 QuicBandwidth::FromBytesPerSecond(0x04030201);
3905 3761
3906 QuicFrames frames; 3762 QuicFrames frames;
3907 frames.push_back(QuicFrame(&congestion_feedback_frame)); 3763 frames.push_back(QuicFrame(&congestion_feedback_frame));
3908 3764
3909 unsigned char packet[] = { 3765 unsigned char packet[] = {// public flags (8 byte connection_id)
3910 // public flags (8 byte connection_id) 3766 0x3C,
3911 0x3C, 3767 // connection_id
3912 // connection_id 3768 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3913 0x10, 0x32, 0x54, 0x76, 3769 // packet sequence number
3914 0x98, 0xBA, 0xDC, 0xFE, 3770 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
3915 // packet sequence number 3771 // private flags
3916 0xBC, 0x9A, 0x78, 0x56, 3772 0x00,
3917 0x34, 0x12,
3918 // private flags
3919 0x00,
3920 3773
3921 // frame type (congestion feedback frame) 3774 // frame type (congestion feedback frame)
3922 0x20, 3775 0x20,
3923 // congestion feedback type (fix rate) 3776 // congestion feedback type (fix rate)
3924 0x02, 3777 0x02,
3925 // bitrate_in_bytes_per_second; 3778 // bitrate_in_bytes_per_second;
3926 0x01, 0x02, 0x03, 0x04, 3779 0x01, 0x02, 0x03, 0x04,
3927 }; 3780 };
3928 3781
3929 scoped_ptr<QuicPacket> data( 3782 scoped_ptr<QuicPacket> data(
3930 framer_.BuildUnsizedDataPacket(header, frames).packet); 3783 framer_.BuildUnsizedDataPacket(header, frames).packet);
3931 ASSERT_TRUE(data != NULL); 3784 ASSERT_TRUE(data != NULL);
3932 3785
3933 test::CompareCharArraysWithHexError("constructed packet", 3786 test::CompareCharArraysWithHexError("constructed packet",
3934 data->data(), data->length(), 3787 data->data(),
3935 AsChars(packet), arraysize(packet)); 3788 data->length(),
3789 AsChars(packet),
3790 arraysize(packet));
3936 } 3791 }
3937 3792
3938 TEST_P(QuicFramerTest, BuildCongestionFeedbackFramePacketInvalidFeedback) { 3793 TEST_P(QuicFramerTest, BuildCongestionFeedbackFramePacketInvalidFeedback) {
3939 QuicPacketHeader header; 3794 QuicPacketHeader header;
3940 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3795 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
3941 header.public_header.reset_flag = false; 3796 header.public_header.reset_flag = false;
3942 header.public_header.version_flag = false; 3797 header.public_header.version_flag = false;
3943 header.fec_flag = false; 3798 header.fec_flag = false;
3944 header.entropy_flag = false; 3799 header.entropy_flag = false;
3945 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 3800 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
(...skipping 22 matching lines...) Expand all
3968 header.entropy_flag = false; 3823 header.entropy_flag = false;
3969 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 3824 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
3970 header.fec_group = 0; 3825 header.fec_group = 0;
3971 3826
3972 QuicRstStreamFrame rst_frame; 3827 QuicRstStreamFrame rst_frame;
3973 rst_frame.stream_id = 0x01020304; 3828 rst_frame.stream_id = 0x01020304;
3974 rst_frame.error_code = static_cast<QuicRstStreamErrorCode>(0x05060708); 3829 rst_frame.error_code = static_cast<QuicRstStreamErrorCode>(0x05060708);
3975 rst_frame.error_details = "because I can"; 3830 rst_frame.error_details = "because I can";
3976 rst_frame.byte_offset = 0x0807060504030201; 3831 rst_frame.byte_offset = 0x0807060504030201;
3977 3832
3978 unsigned char packet[] = { 3833 unsigned char packet[] = {// public flags (8 byte connection_id)
3979 // public flags (8 byte connection_id) 3834 0x3C,
3980 0x3C, 3835 // connection_id
3981 // connection_id 3836 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
3982 0x10, 0x32, 0x54, 0x76, 3837 // packet sequence number
3983 0x98, 0xBA, 0xDC, 0xFE, 3838 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
3984 // packet sequence number 3839 // private flags
3985 0xBC, 0x9A, 0x78, 0x56, 3840 0x00,
3986 0x34, 0x12,
3987 // private flags
3988 0x00,
3989 3841
3990 // frame type (rst stream frame) 3842 // frame type (rst stream frame)
3991 0x01, 3843 0x01,
3992 // stream id 3844 // stream id
3993 0x04, 0x03, 0x02, 0x01, 3845 0x04, 0x03, 0x02, 0x01,
3994 // sent byte offset 3846 // sent byte offset
3995 0x01, 0x02, 0x03, 0x04, 3847 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
3996 0x05, 0x06, 0x07, 0x08, 3848 // error code
3997 // error code 3849 0x08, 0x07, 0x06, 0x05,
3998 0x08, 0x07, 0x06, 0x05, 3850 // error details length
3999 // error details length 3851 0x0d, 0x00,
4000 0x0d, 0x00, 3852 // error details
4001 // error details 3853 'b', 'e', 'c', 'a', 'u', 's', 'e', ' ',
4002 'b', 'e', 'c', 'a', 3854 'I', ' ', 'c', 'a', 'n',
4003 'u', 's', 'e', ' ',
4004 'I', ' ', 'c', 'a',
4005 'n',
4006 }; 3855 };
4007 3856
4008 QuicFrames frames; 3857 QuicFrames frames;
4009 frames.push_back(QuicFrame(&rst_frame)); 3858 frames.push_back(QuicFrame(&rst_frame));
4010 3859
4011 scoped_ptr<QuicPacket> data( 3860 scoped_ptr<QuicPacket> data(
4012 framer_.BuildUnsizedDataPacket(header, frames).packet); 3861 framer_.BuildUnsizedDataPacket(header, frames).packet);
4013 ASSERT_TRUE(data != NULL); 3862 ASSERT_TRUE(data != NULL);
4014 3863
4015 test::CompareCharArraysWithHexError("constructed packet", 3864 test::CompareCharArraysWithHexError("constructed packet",
4016 data->data(), data->length(), 3865 data->data(),
4017 AsChars(packet), arraysize(packet)); 3866 data->length(),
3867 AsChars(packet),
3868 arraysize(packet));
4018 } 3869 }
4019 3870
4020 TEST_P(QuicFramerTest, BuildCloseFramePacket) { 3871 TEST_P(QuicFramerTest, BuildCloseFramePacket) {
4021 QuicPacketHeader header; 3872 QuicPacketHeader header;
4022 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3873 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4023 header.public_header.reset_flag = false; 3874 header.public_header.reset_flag = false;
4024 header.public_header.version_flag = false; 3875 header.public_header.version_flag = false;
4025 header.fec_flag = false; 3876 header.fec_flag = false;
4026 header.entropy_flag = true; 3877 header.entropy_flag = true;
4027 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 3878 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
4028 header.fec_group = 0; 3879 header.fec_group = 0;
4029 3880
4030 QuicConnectionCloseFrame close_frame; 3881 QuicConnectionCloseFrame close_frame;
4031 close_frame.error_code = static_cast<QuicErrorCode>(0x05060708); 3882 close_frame.error_code = static_cast<QuicErrorCode>(0x05060708);
4032 close_frame.error_details = "because I can"; 3883 close_frame.error_details = "because I can";
4033 3884
4034 QuicFrames frames; 3885 QuicFrames frames;
4035 frames.push_back(QuicFrame(&close_frame)); 3886 frames.push_back(QuicFrame(&close_frame));
4036 3887
4037 unsigned char packet[] = { 3888 unsigned char packet[] = {// public flags (8 byte connection_id)
4038 // public flags (8 byte connection_id) 3889 0x3C,
4039 0x3C, 3890 // connection_id
4040 // connection_id 3891 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
4041 0x10, 0x32, 0x54, 0x76, 3892 // packet sequence number
4042 0x98, 0xBA, 0xDC, 0xFE, 3893 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
4043 // packet sequence number 3894 // private flags (entropy)
4044 0xBC, 0x9A, 0x78, 0x56, 3895 0x01,
4045 0x34, 0x12,
4046 // private flags (entropy)
4047 0x01,
4048 3896
4049 // frame type (connection close frame) 3897 // frame type (connection close frame)
4050 0x02, 3898 0x02,
4051 // error code 3899 // error code
4052 0x08, 0x07, 0x06, 0x05, 3900 0x08, 0x07, 0x06, 0x05,
4053 // error details length 3901 // error details length
4054 0x0d, 0x00, 3902 0x0d, 0x00,
4055 // error details 3903 // error details
4056 'b', 'e', 'c', 'a', 3904 'b', 'e', 'c', 'a', 'u', 's', 'e', ' ',
4057 'u', 's', 'e', ' ', 3905 'I', ' ', 'c', 'a', 'n',
4058 'I', ' ', 'c', 'a',
4059 'n',
4060 }; 3906 };
4061 3907
4062 scoped_ptr<QuicPacket> data( 3908 scoped_ptr<QuicPacket> data(
4063 framer_.BuildUnsizedDataPacket(header, frames).packet); 3909 framer_.BuildUnsizedDataPacket(header, frames).packet);
4064 ASSERT_TRUE(data != NULL); 3910 ASSERT_TRUE(data != NULL);
4065 3911
4066 test::CompareCharArraysWithHexError("constructed packet", 3912 test::CompareCharArraysWithHexError("constructed packet",
4067 data->data(), data->length(), 3913 data->data(),
4068 AsChars(packet), arraysize(packet)); 3914 data->length(),
3915 AsChars(packet),
3916 arraysize(packet));
4069 } 3917 }
4070 3918
4071 TEST_P(QuicFramerTest, BuildGoAwayPacket) { 3919 TEST_P(QuicFramerTest, BuildGoAwayPacket) {
4072 QuicPacketHeader header; 3920 QuicPacketHeader header;
4073 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3921 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4074 header.public_header.reset_flag = false; 3922 header.public_header.reset_flag = false;
4075 header.public_header.version_flag = false; 3923 header.public_header.version_flag = false;
4076 header.fec_flag = false; 3924 header.fec_flag = false;
4077 header.entropy_flag = true; 3925 header.entropy_flag = true;
4078 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 3926 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
4079 header.fec_group = 0; 3927 header.fec_group = 0;
4080 3928
4081 QuicGoAwayFrame goaway_frame; 3929 QuicGoAwayFrame goaway_frame;
4082 goaway_frame.error_code = static_cast<QuicErrorCode>(0x05060708); 3930 goaway_frame.error_code = static_cast<QuicErrorCode>(0x05060708);
4083 goaway_frame.last_good_stream_id = 0x01020304; 3931 goaway_frame.last_good_stream_id = 0x01020304;
4084 goaway_frame.reason_phrase = "because I can"; 3932 goaway_frame.reason_phrase = "because I can";
4085 3933
4086 QuicFrames frames; 3934 QuicFrames frames;
4087 frames.push_back(QuicFrame(&goaway_frame)); 3935 frames.push_back(QuicFrame(&goaway_frame));
4088 3936
4089 unsigned char packet[] = { 3937 unsigned char packet[] = {// public flags (8 byte connection_id)
4090 // public flags (8 byte connection_id) 3938 0x3C,
4091 0x3C, 3939 // connection_id
4092 // connection_id 3940 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
4093 0x10, 0x32, 0x54, 0x76, 3941 // packet sequence number
4094 0x98, 0xBA, 0xDC, 0xFE, 3942 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
4095 // packet sequence number 3943 // private flags(entropy)
4096 0xBC, 0x9A, 0x78, 0x56, 3944 0x01,
4097 0x34, 0x12,
4098 // private flags(entropy)
4099 0x01,
4100 3945
4101 // frame type (go away frame) 3946 // frame type (go away frame)
4102 0x03, 3947 0x03,
4103 // error code 3948 // error code
4104 0x08, 0x07, 0x06, 0x05, 3949 0x08, 0x07, 0x06, 0x05,
4105 // stream id 3950 // stream id
4106 0x04, 0x03, 0x02, 0x01, 3951 0x04, 0x03, 0x02, 0x01,
4107 // error details length 3952 // error details length
4108 0x0d, 0x00, 3953 0x0d, 0x00,
4109 // error details 3954 // error details
4110 'b', 'e', 'c', 'a', 3955 'b', 'e', 'c', 'a', 'u', 's', 'e', ' ',
4111 'u', 's', 'e', ' ', 3956 'I', ' ', 'c', 'a', 'n',
4112 'I', ' ', 'c', 'a',
4113 'n',
4114 }; 3957 };
4115 3958
4116 scoped_ptr<QuicPacket> data( 3959 scoped_ptr<QuicPacket> data(
4117 framer_.BuildUnsizedDataPacket(header, frames).packet); 3960 framer_.BuildUnsizedDataPacket(header, frames).packet);
4118 ASSERT_TRUE(data != NULL); 3961 ASSERT_TRUE(data != NULL);
4119 3962
4120 test::CompareCharArraysWithHexError("constructed packet", 3963 test::CompareCharArraysWithHexError("constructed packet",
4121 data->data(), data->length(), 3964 data->data(),
4122 AsChars(packet), arraysize(packet)); 3965 data->length(),
3966 AsChars(packet),
3967 arraysize(packet));
4123 } 3968 }
4124 3969
4125 TEST_P(QuicFramerTest, BuildWindowUpdatePacket) { 3970 TEST_P(QuicFramerTest, BuildWindowUpdatePacket) {
4126 QuicPacketHeader header; 3971 QuicPacketHeader header;
4127 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 3972 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4128 header.public_header.reset_flag = false; 3973 header.public_header.reset_flag = false;
4129 header.public_header.version_flag = false; 3974 header.public_header.version_flag = false;
4130 header.fec_flag = false; 3975 header.fec_flag = false;
4131 header.entropy_flag = true; 3976 header.entropy_flag = true;
4132 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 3977 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
4133 header.fec_group = 0; 3978 header.fec_group = 0;
4134 3979
4135 QuicWindowUpdateFrame window_update_frame; 3980 QuicWindowUpdateFrame window_update_frame;
4136 window_update_frame.stream_id = 0x01020304; 3981 window_update_frame.stream_id = 0x01020304;
4137 window_update_frame.byte_offset = 0x1122334455667788; 3982 window_update_frame.byte_offset = 0x1122334455667788;
4138 3983
4139 QuicFrames frames; 3984 QuicFrames frames;
4140 frames.push_back(QuicFrame(&window_update_frame)); 3985 frames.push_back(QuicFrame(&window_update_frame));
4141 3986
4142 unsigned char packet[] = { 3987 unsigned char packet[] = {// public flags (8 byte connection_id)
4143 // public flags (8 byte connection_id) 3988 0x3C,
4144 0x3C, 3989 // connection_id
4145 // connection_id 3990 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
4146 0x10, 0x32, 0x54, 0x76, 3991 // packet sequence number
4147 0x98, 0xBA, 0xDC, 0xFE, 3992 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
4148 // packet sequence number 3993 // private flags(entropy)
4149 0xBC, 0x9A, 0x78, 0x56, 3994 0x01,
4150 0x34, 0x12,
4151 // private flags(entropy)
4152 0x01,
4153 3995
4154 // frame type (window update frame) 3996 // frame type (window update frame)
4155 0x04, 3997 0x04,
4156 // stream id 3998 // stream id
4157 0x04, 0x03, 0x02, 0x01, 3999 0x04, 0x03, 0x02, 0x01,
4158 // byte offset 4000 // byte offset
4159 0x88, 0x77, 0x66, 0x55, 4001 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11,
4160 0x44, 0x33, 0x22, 0x11,
4161 }; 4002 };
4162 4003
4163 scoped_ptr<QuicPacket> data( 4004 scoped_ptr<QuicPacket> data(
4164 framer_.BuildUnsizedDataPacket(header, frames).packet); 4005 framer_.BuildUnsizedDataPacket(header, frames).packet);
4165 ASSERT_TRUE(data != NULL); 4006 ASSERT_TRUE(data != NULL);
4166 4007
4167 test::CompareCharArraysWithHexError("constructed packet", data->data(), 4008 test::CompareCharArraysWithHexError("constructed packet",
4168 data->length(), AsChars(packet), 4009 data->data(),
4010 data->length(),
4011 AsChars(packet),
4169 arraysize(packet)); 4012 arraysize(packet));
4170 } 4013 }
4171 4014
4172 TEST_P(QuicFramerTest, BuildBlockedPacket) { 4015 TEST_P(QuicFramerTest, BuildBlockedPacket) {
4173 QuicPacketHeader header; 4016 QuicPacketHeader header;
4174 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 4017 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4175 header.public_header.reset_flag = false; 4018 header.public_header.reset_flag = false;
4176 header.public_header.version_flag = false; 4019 header.public_header.version_flag = false;
4177 header.fec_flag = false; 4020 header.fec_flag = false;
4178 header.entropy_flag = true; 4021 header.entropy_flag = true;
4179 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 4022 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
4180 header.fec_group = 0; 4023 header.fec_group = 0;
4181 4024
4182 QuicBlockedFrame blocked_frame; 4025 QuicBlockedFrame blocked_frame;
4183 blocked_frame.stream_id = 0x01020304; 4026 blocked_frame.stream_id = 0x01020304;
4184 4027
4185 QuicFrames frames; 4028 QuicFrames frames;
4186 frames.push_back(QuicFrame(&blocked_frame)); 4029 frames.push_back(QuicFrame(&blocked_frame));
4187 4030
4188 unsigned char packet[] = { 4031 unsigned char packet[] = {// public flags (8 byte connection_id)
4189 // public flags (8 byte connection_id) 4032 0x3C,
4190 0x3C, 4033 // connection_id
4191 // connection_id 4034 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
4192 0x10, 0x32, 0x54, 0x76, 4035 // packet sequence number
4193 0x98, 0xBA, 0xDC, 0xFE, 4036 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
4194 // packet sequence number 4037 // private flags(entropy)
4195 0xBC, 0x9A, 0x78, 0x56, 4038 0x01,
4196 0x34, 0x12,
4197 // private flags(entropy)
4198 0x01,
4199 4039
4200 // frame type (blocked frame) 4040 // frame type (blocked frame)
4201 0x05, 4041 0x05,
4202 // stream id 4042 // stream id
4203 0x04, 0x03, 0x02, 0x01, 4043 0x04, 0x03, 0x02, 0x01,
4204 }; 4044 };
4205 4045
4206 scoped_ptr<QuicPacket> data( 4046 scoped_ptr<QuicPacket> data(
4207 framer_.BuildUnsizedDataPacket(header, frames).packet); 4047 framer_.BuildUnsizedDataPacket(header, frames).packet);
4208 ASSERT_TRUE(data != NULL); 4048 ASSERT_TRUE(data != NULL);
4209 4049
4210 test::CompareCharArraysWithHexError("constructed packet", data->data(), 4050 test::CompareCharArraysWithHexError("constructed packet",
4211 data->length(), AsChars(packet), 4051 data->data(),
4052 data->length(),
4053 AsChars(packet),
4212 arraysize(packet)); 4054 arraysize(packet));
4213 } 4055 }
4214 4056
4215 TEST_P(QuicFramerTest, BuildPingPacket) { 4057 TEST_P(QuicFramerTest, BuildPingPacket) {
4216 QuicPacketHeader header; 4058 QuicPacketHeader header;
4217 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 4059 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4218 header.public_header.reset_flag = false; 4060 header.public_header.reset_flag = false;
4219 header.public_header.version_flag = false; 4061 header.public_header.version_flag = false;
4220 header.fec_flag = false; 4062 header.fec_flag = false;
4221 header.entropy_flag = true; 4063 header.entropy_flag = true;
4222 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); 4064 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC);
4223 header.fec_group = 0; 4065 header.fec_group = 0;
4224 4066
4225 QuicPingFrame ping_frame; 4067 QuicPingFrame ping_frame;
4226 4068
4227 QuicFrames frames; 4069 QuicFrames frames;
4228 frames.push_back(QuicFrame(&ping_frame)); 4070 frames.push_back(QuicFrame(&ping_frame));
4229 4071
4230 unsigned char packet[] = { 4072 unsigned char packet[] = {// public flags (8 byte connection_id)
4231 // public flags (8 byte connection_id) 4073 0x3C,
4232 0x3C, 4074 // connection_id
4233 // connection_id 4075 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
4234 0x10, 0x32, 0x54, 0x76, 4076 // packet sequence number
4235 0x98, 0xBA, 0xDC, 0xFE, 4077 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
4236 // packet sequence number 4078 // private flags(entropy)
4237 0xBC, 0x9A, 0x78, 0x56, 4079 0x01,
4238 0x34, 0x12,
4239 // private flags(entropy)
4240 0x01,
4241 4080
4242 // frame type (ping frame) 4081 // frame type (ping frame)
4243 0x07, 4082 0x07,
4244 }; 4083 };
4245 4084
4246 if (version_ > QUIC_VERSION_17) { 4085 if (version_ > QUIC_VERSION_17) {
4247 scoped_ptr<QuicPacket> data( 4086 scoped_ptr<QuicPacket> data(
4248 framer_.BuildUnsizedDataPacket(header, frames).packet); 4087 framer_.BuildUnsizedDataPacket(header, frames).packet);
4249 ASSERT_TRUE(data != NULL); 4088 ASSERT_TRUE(data != NULL);
4250 4089
4251 test::CompareCharArraysWithHexError("constructed packet", data->data(), 4090 test::CompareCharArraysWithHexError("constructed packet",
4252 data->length(), AsChars(packet), 4091 data->data(),
4092 data->length(),
4093 AsChars(packet),
4253 arraysize(packet)); 4094 arraysize(packet));
4254 } else { 4095 } else {
4255 string expected_error = 4096 string expected_error =
4256 "Attempt to add a PingFrame in " + QuicVersionToString(version_); 4097 "Attempt to add a PingFrame in " + QuicVersionToString(version_);
4257 EXPECT_DFATAL(framer_.BuildUnsizedDataPacket(header, frames), 4098 EXPECT_DFATAL(framer_.BuildUnsizedDataPacket(header, frames),
4258 expected_error); 4099 expected_error);
4259 return; 4100 return;
4260 } 4101 }
4261 } 4102 }
4262 4103
4263 TEST_P(QuicFramerTest, BuildPublicResetPacket) { 4104 TEST_P(QuicFramerTest, BuildPublicResetPacket) {
4264 QuicPublicResetPacket reset_packet; 4105 QuicPublicResetPacket reset_packet;
4265 reset_packet.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 4106 reset_packet.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4266 reset_packet.public_header.reset_flag = true; 4107 reset_packet.public_header.reset_flag = true;
4267 reset_packet.public_header.version_flag = false; 4108 reset_packet.public_header.version_flag = false;
4268 reset_packet.rejected_sequence_number = GG_UINT64_C(0x123456789ABC); 4109 reset_packet.rejected_sequence_number = GG_UINT64_C(0x123456789ABC);
4269 reset_packet.nonce_proof = GG_UINT64_C(0xABCDEF0123456789); 4110 reset_packet.nonce_proof = GG_UINT64_C(0xABCDEF0123456789);
4270 4111
4271 unsigned char packet[] = { 4112 unsigned char packet[] = {// public flags (public reset, 8 byte ConnectionId)
4272 // public flags (public reset, 8 byte ConnectionId) 4113 0x0E,
4273 0x0E, 4114 // connection_id
4274 // connection_id 4115 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
4275 0x10, 0x32, 0x54, 0x76, 4116 // message tag (kPRST)
4276 0x98, 0xBA, 0xDC, 0xFE, 4117 'P', 'R', 'S', 'T',
4277 // message tag (kPRST) 4118 // num_entries (2) + padding
4278 'P', 'R', 'S', 'T', 4119 0x02, 0x00, 0x00, 0x00,
4279 // num_entries (2) + padding 4120 // tag kRNON
4280 0x02, 0x00, 0x00, 0x00, 4121 'R', 'N', 'O', 'N',
4281 // tag kRNON 4122 // end offset 8
4282 'R', 'N', 'O', 'N', 4123 0x08, 0x00, 0x00, 0x00,
4283 // end offset 8 4124 // tag kRSEQ
4284 0x08, 0x00, 0x00, 0x00, 4125 'R', 'S', 'E', 'Q',
4285 // tag kRSEQ 4126 // end offset 16
4286 'R', 'S', 'E', 'Q', 4127 0x10, 0x00, 0x00, 0x00,
4287 // end offset 16 4128 // nonce proof
4288 0x10, 0x00, 0x00, 0x00, 4129 0x89, 0x67, 0x45, 0x23, 0x01, 0xEF, 0xCD, 0xAB,
4289 // nonce proof 4130 // rejected sequence number
4290 0x89, 0x67, 0x45, 0x23, 4131 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, 0x00, 0x00,
4291 0x01, 0xEF, 0xCD, 0xAB,
4292 // rejected sequence number
4293 0xBC, 0x9A, 0x78, 0x56,
4294 0x34, 0x12, 0x00, 0x00,
4295 }; 4132 };
4296 4133
4297 scoped_ptr<QuicEncryptedPacket> data( 4134 scoped_ptr<QuicEncryptedPacket> data(
4298 framer_.BuildPublicResetPacket(reset_packet)); 4135 framer_.BuildPublicResetPacket(reset_packet));
4299 ASSERT_TRUE(data != NULL); 4136 ASSERT_TRUE(data != NULL);
4300 4137
4301 test::CompareCharArraysWithHexError("constructed packet", 4138 test::CompareCharArraysWithHexError("constructed packet",
4302 data->data(), data->length(), 4139 data->data(),
4303 AsChars(packet), arraysize(packet)); 4140 data->length(),
4141 AsChars(packet),
4142 arraysize(packet));
4304 } 4143 }
4305 4144
4306 TEST_P(QuicFramerTest, BuildPublicResetPacketWithClientAddress) { 4145 TEST_P(QuicFramerTest, BuildPublicResetPacketWithClientAddress) {
4307 QuicPublicResetPacket reset_packet; 4146 QuicPublicResetPacket reset_packet;
4308 reset_packet.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 4147 reset_packet.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4309 reset_packet.public_header.reset_flag = true; 4148 reset_packet.public_header.reset_flag = true;
4310 reset_packet.public_header.version_flag = false; 4149 reset_packet.public_header.version_flag = false;
4311 reset_packet.rejected_sequence_number = GG_UINT64_C(0x123456789ABC); 4150 reset_packet.rejected_sequence_number = GG_UINT64_C(0x123456789ABC);
4312 reset_packet.nonce_proof = GG_UINT64_C(0xABCDEF0123456789); 4151 reset_packet.nonce_proof = GG_UINT64_C(0xABCDEF0123456789);
4313 reset_packet.client_address = IPEndPoint(Loopback4(), 0x1234); 4152 reset_packet.client_address = IPEndPoint(Loopback4(), 0x1234);
4314 4153
4315 unsigned char packet[] = { 4154 unsigned char packet[] = {// public flags (public reset, 8 byte ConnectionId)
4316 // public flags (public reset, 8 byte ConnectionId) 4155 0x0E,
4317 0x0E, 4156 // connection_id
4318 // connection_id 4157 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
4319 0x10, 0x32, 0x54, 0x76, 4158 // message tag (kPRST)
4320 0x98, 0xBA, 0xDC, 0xFE, 4159 'P', 'R', 'S', 'T',
4321 // message tag (kPRST) 4160 // num_entries (3) + padding
4322 'P', 'R', 'S', 'T', 4161 0x03, 0x00, 0x00, 0x00,
4323 // num_entries (3) + padding 4162 // tag kRNON
4324 0x03, 0x00, 0x00, 0x00, 4163 'R', 'N', 'O', 'N',
4325 // tag kRNON 4164 // end offset 8
4326 'R', 'N', 'O', 'N', 4165 0x08, 0x00, 0x00, 0x00,
4327 // end offset 8 4166 // tag kRSEQ
4328 0x08, 0x00, 0x00, 0x00, 4167 'R', 'S', 'E', 'Q',
4329 // tag kRSEQ 4168 // end offset 16
4330 'R', 'S', 'E', 'Q', 4169 0x10, 0x00, 0x00, 0x00,
4331 // end offset 16 4170 // tag kCADR
4332 0x10, 0x00, 0x00, 0x00, 4171 'C', 'A', 'D', 'R',
4333 // tag kCADR 4172 // end offset 24
4334 'C', 'A', 'D', 'R', 4173 0x18, 0x00, 0x00, 0x00,
4335 // end offset 24 4174 // nonce proof
4336 0x18, 0x00, 0x00, 0x00, 4175 0x89, 0x67, 0x45, 0x23, 0x01, 0xEF, 0xCD, 0xAB,
4337 // nonce proof 4176 // rejected sequence number
4338 0x89, 0x67, 0x45, 0x23, 4177 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, 0x00, 0x00,
4339 0x01, 0xEF, 0xCD, 0xAB, 4178 // client address
4340 // rejected sequence number 4179 0x02, 0x00, 0x7F, 0x00, 0x00, 0x01, 0x34, 0x12,
4341 0xBC, 0x9A, 0x78, 0x56,
4342 0x34, 0x12, 0x00, 0x00,
4343 // client address
4344 0x02, 0x00,
4345 0x7F, 0x00, 0x00, 0x01,
4346 0x34, 0x12,
4347 }; 4180 };
4348 4181
4349 scoped_ptr<QuicEncryptedPacket> data( 4182 scoped_ptr<QuicEncryptedPacket> data(
4350 framer_.BuildPublicResetPacket(reset_packet)); 4183 framer_.BuildPublicResetPacket(reset_packet));
4351 ASSERT_TRUE(data != NULL); 4184 ASSERT_TRUE(data != NULL);
4352 4185
4353 test::CompareCharArraysWithHexError("constructed packet", 4186 test::CompareCharArraysWithHexError("constructed packet",
4354 data->data(), data->length(), 4187 data->data(),
4355 AsChars(packet), arraysize(packet)); 4188 data->length(),
4189 AsChars(packet),
4190 arraysize(packet));
4356 } 4191 }
4357 4192
4358 TEST_P(QuicFramerTest, BuildFecPacket) { 4193 TEST_P(QuicFramerTest, BuildFecPacket) {
4359 QuicPacketHeader header; 4194 QuicPacketHeader header;
4360 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); 4195 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210);
4361 header.public_header.reset_flag = false; 4196 header.public_header.reset_flag = false;
4362 header.public_header.version_flag = false; 4197 header.public_header.version_flag = false;
4363 header.fec_flag = true; 4198 header.fec_flag = true;
4364 header.entropy_flag = true; 4199 header.entropy_flag = true;
4365 header.packet_sequence_number = (GG_UINT64_C(0x123456789ABC)); 4200 header.packet_sequence_number = (GG_UINT64_C(0x123456789ABC));
4366 header.is_in_fec_group = IN_FEC_GROUP; 4201 header.is_in_fec_group = IN_FEC_GROUP;
4367 header.fec_group = GG_UINT64_C(0x123456789ABB);; 4202 header.fec_group = GG_UINT64_C(0x123456789ABB);
4203 ;
4368 4204
4369 QuicFecData fec_data; 4205 QuicFecData fec_data;
4370 fec_data.fec_group = 1; 4206 fec_data.fec_group = 1;
4371 fec_data.redundancy = "abcdefghijklmnop"; 4207 fec_data.redundancy = "abcdefghijklmnop";
4372 4208
4373 unsigned char packet[] = { 4209 unsigned char packet[] = {// public flags (8 byte connection_id)
4374 // public flags (8 byte connection_id) 4210 0x3C,
4375 0x3C, 4211 // connection_id
4376 // connection_id 4212 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
4377 0x10, 0x32, 0x54, 0x76, 4213 // packet sequence number
4378 0x98, 0xBA, 0xDC, 0xFE, 4214 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
4379 // packet sequence number 4215 // private flags (entropy & fec group & fec packet)
4380 0xBC, 0x9A, 0x78, 0x56, 4216 0x07,
4381 0x34, 0x12, 4217 // first fec protected packet offset
4382 // private flags (entropy & fec group & fec packet) 4218 0x01,
4383 0x07,
4384 // first fec protected packet offset
4385 0x01,
4386 4219
4387 // redundancy 4220 // redundancy
4388 'a', 'b', 'c', 'd', 4221 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
4389 'e', 'f', 'g', 'h', 4222 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
4390 'i', 'j', 'k', 'l',
4391 'm', 'n', 'o', 'p',
4392 }; 4223 };
4393 4224
4394 scoped_ptr<QuicPacket> data( 4225 scoped_ptr<QuicPacket> data(framer_.BuildFecPacket(header, fec_data).packet);
4395 framer_.BuildFecPacket(header, fec_data).packet);
4396 ASSERT_TRUE(data != NULL); 4226 ASSERT_TRUE(data != NULL);
4397 4227
4398 test::CompareCharArraysWithHexError("constructed packet", 4228 test::CompareCharArraysWithHexError("constructed packet",
4399 data->data(), data->length(), 4229 data->data(),
4400 AsChars(packet), arraysize(packet)); 4230 data->length(),
4231 AsChars(packet),
4232 arraysize(packet));
4401 } 4233 }
4402 4234
4403 TEST_P(QuicFramerTest, EncryptPacket) { 4235 TEST_P(QuicFramerTest, EncryptPacket) {
4404 QuicPacketSequenceNumber sequence_number = GG_UINT64_C(0x123456789ABC); 4236 QuicPacketSequenceNumber sequence_number = GG_UINT64_C(0x123456789ABC);
4405 unsigned char packet[] = { 4237 unsigned char packet[] = {// public flags (8 byte connection_id)
4406 // public flags (8 byte connection_id) 4238 0x3C,
4407 0x3C, 4239 // connection_id
4408 // connection_id 4240 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
4409 0x10, 0x32, 0x54, 0x76, 4241 // packet sequence number
4410 0x98, 0xBA, 0xDC, 0xFE, 4242 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
4411 // packet sequence number 4243 // private flags (fec group & fec packet)
4412 0xBC, 0x9A, 0x78, 0x56, 4244 0x06,
4413 0x34, 0x12, 4245 // first fec protected packet offset
4414 // private flags (fec group & fec packet) 4246 0x01,
4415 0x06,
4416 // first fec protected packet offset
4417 0x01,
4418 4247
4419 // redundancy 4248 // redundancy
4420 'a', 'b', 'c', 'd', 4249 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
4421 'e', 'f', 'g', 'h', 4250 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
4422 'i', 'j', 'k', 'l',
4423 'm', 'n', 'o', 'p',
4424 }; 4251 };
4425 4252
4426 scoped_ptr<QuicPacket> raw( 4253 scoped_ptr<QuicPacket> raw(
4427 QuicPacket::NewDataPacket(AsChars(packet), arraysize(packet), false, 4254 QuicPacket::NewDataPacket(AsChars(packet),
4428 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, 4255 arraysize(packet),
4256 false,
4257 PACKET_8BYTE_CONNECTION_ID,
4258 !kIncludeVersion,
4429 PACKET_6BYTE_SEQUENCE_NUMBER)); 4259 PACKET_6BYTE_SEQUENCE_NUMBER));
4430 scoped_ptr<QuicEncryptedPacket> encrypted( 4260 scoped_ptr<QuicEncryptedPacket> encrypted(
4431 framer_.EncryptPacket(ENCRYPTION_NONE, sequence_number, *raw)); 4261 framer_.EncryptPacket(ENCRYPTION_NONE, sequence_number, *raw));
4432 4262
4433 ASSERT_TRUE(encrypted.get() != NULL); 4263 ASSERT_TRUE(encrypted.get() != NULL);
4434 EXPECT_TRUE(CheckEncryption(sequence_number, raw.get())); 4264 EXPECT_TRUE(CheckEncryption(sequence_number, raw.get()));
4435 } 4265 }
4436 4266
4437 TEST_P(QuicFramerTest, EncryptPacketWithVersionFlag) { 4267 TEST_P(QuicFramerTest, EncryptPacketWithVersionFlag) {
4438 QuicPacketSequenceNumber sequence_number = GG_UINT64_C(0x123456789ABC); 4268 QuicPacketSequenceNumber sequence_number = GG_UINT64_C(0x123456789ABC);
4439 unsigned char packet[] = { 4269 unsigned char packet[] = {// public flags (version, 8 byte connection_id)
4440 // public flags (version, 8 byte connection_id) 4270 0x3D,
4441 0x3D, 4271 // connection_id
4442 // connection_id 4272 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
4443 0x10, 0x32, 0x54, 0x76, 4273 // version tag
4444 0x98, 0xBA, 0xDC, 0xFE, 4274 'Q', '.', '1', '0',
4445 // version tag 4275 // packet sequence number
4446 'Q', '.', '1', '0', 4276 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
4447 // packet sequence number 4277 // private flags (fec group & fec flags)
4448 0xBC, 0x9A, 0x78, 0x56, 4278 0x06,
4449 0x34, 0x12, 4279 // first fec protected packet offset
4450 // private flags (fec group & fec flags) 4280 0x01,
4451 0x06,
4452 // first fec protected packet offset
4453 0x01,
4454 4281
4455 // redundancy 4282 // redundancy
4456 'a', 'b', 'c', 'd', 4283 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
4457 'e', 'f', 'g', 'h', 4284 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
4458 'i', 'j', 'k', 'l',
4459 'm', 'n', 'o', 'p',
4460 }; 4285 };
4461 4286
4462 scoped_ptr<QuicPacket> raw( 4287 scoped_ptr<QuicPacket> raw(
4463 QuicPacket::NewDataPacket(AsChars(packet), arraysize(packet), false, 4288 QuicPacket::NewDataPacket(AsChars(packet),
4464 PACKET_8BYTE_CONNECTION_ID, kIncludeVersion, 4289 arraysize(packet),
4290 false,
4291 PACKET_8BYTE_CONNECTION_ID,
4292 kIncludeVersion,
4465 PACKET_6BYTE_SEQUENCE_NUMBER)); 4293 PACKET_6BYTE_SEQUENCE_NUMBER));
4466 scoped_ptr<QuicEncryptedPacket> encrypted( 4294 scoped_ptr<QuicEncryptedPacket> encrypted(
4467 framer_.EncryptPacket(ENCRYPTION_NONE, sequence_number, *raw)); 4295 framer_.EncryptPacket(ENCRYPTION_NONE, sequence_number, *raw));
4468 4296
4469 ASSERT_TRUE(encrypted.get() != NULL); 4297 ASSERT_TRUE(encrypted.get() != NULL);
4470 EXPECT_TRUE(CheckEncryption(sequence_number, raw.get())); 4298 EXPECT_TRUE(CheckEncryption(sequence_number, raw.get()));
4471 } 4299 }
4472 4300
4473 TEST_P(QuicFramerTest, Truncation) { 4301 TEST_P(QuicFramerTest, Truncation) {
4474 if (framer_.version() <= QUIC_VERSION_15) { 4302 if (framer_.version() <= QUIC_VERSION_15) {
(...skipping 18 matching lines...) Expand all
4493 QuicFrame frame; 4321 QuicFrame frame;
4494 frame.type = ACK_FRAME; 4322 frame.type = ACK_FRAME;
4495 frame.ack_frame = &ack_frame; 4323 frame.ack_frame = &ack_frame;
4496 QuicFrames frames; 4324 QuicFrames frames;
4497 frames.push_back(frame); 4325 frames.push_back(frame);
4498 4326
4499 scoped_ptr<QuicPacket> raw_ack_packet( 4327 scoped_ptr<QuicPacket> raw_ack_packet(
4500 framer_.BuildUnsizedDataPacket(header, frames).packet); 4328 framer_.BuildUnsizedDataPacket(header, frames).packet);
4501 ASSERT_TRUE(raw_ack_packet != NULL); 4329 ASSERT_TRUE(raw_ack_packet != NULL);
4502 4330
4503 scoped_ptr<QuicEncryptedPacket> ack_packet( 4331 scoped_ptr<QuicEncryptedPacket> ack_packet(framer_.EncryptPacket(
4504 framer_.EncryptPacket(ENCRYPTION_NONE, header.packet_sequence_number, 4332 ENCRYPTION_NONE, header.packet_sequence_number, *raw_ack_packet));
4505 *raw_ack_packet));
4506 4333
4507 // Now make sure we can turn our ack packet back into an ack frame 4334 // Now make sure we can turn our ack packet back into an ack frame
4508 ASSERT_TRUE(framer_.ProcessPacket(*ack_packet)); 4335 ASSERT_TRUE(framer_.ProcessPacket(*ack_packet));
4509 ASSERT_EQ(1u, visitor_.ack_frames_.size()); 4336 ASSERT_EQ(1u, visitor_.ack_frames_.size());
4510 const QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0]; 4337 const QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0];
4511 EXPECT_TRUE(processed_ack_frame.received_info.is_truncated); 4338 EXPECT_TRUE(processed_ack_frame.received_info.is_truncated);
4512 EXPECT_EQ(510u, processed_ack_frame.received_info.largest_observed); 4339 EXPECT_EQ(510u, processed_ack_frame.received_info.largest_observed);
4513 ASSERT_EQ(255u, processed_ack_frame.received_info.missing_packets.size()); 4340 ASSERT_EQ(255u, processed_ack_frame.received_info.missing_packets.size());
4514 SequenceNumberSet::const_iterator missing_iter = 4341 SequenceNumberSet::const_iterator missing_iter =
4515 processed_ack_frame.received_info.missing_packets.begin(); 4342 processed_ack_frame.received_info.missing_packets.begin();
(...skipping 27 matching lines...) Expand all
4543 QuicFrame frame; 4370 QuicFrame frame;
4544 frame.type = ACK_FRAME; 4371 frame.type = ACK_FRAME;
4545 frame.ack_frame = &ack_frame; 4372 frame.ack_frame = &ack_frame;
4546 QuicFrames frames; 4373 QuicFrames frames;
4547 frames.push_back(frame); 4374 frames.push_back(frame);
4548 4375
4549 scoped_ptr<QuicPacket> raw_ack_packet( 4376 scoped_ptr<QuicPacket> raw_ack_packet(
4550 framer_.BuildUnsizedDataPacket(header, frames).packet); 4377 framer_.BuildUnsizedDataPacket(header, frames).packet);
4551 ASSERT_TRUE(raw_ack_packet != NULL); 4378 ASSERT_TRUE(raw_ack_packet != NULL);
4552 4379
4553 scoped_ptr<QuicEncryptedPacket> ack_packet( 4380 scoped_ptr<QuicEncryptedPacket> ack_packet(framer_.EncryptPacket(
4554 framer_.EncryptPacket(ENCRYPTION_NONE, header.packet_sequence_number, 4381 ENCRYPTION_NONE, header.packet_sequence_number, *raw_ack_packet));
4555 *raw_ack_packet));
4556 4382
4557 // Now make sure we can turn our ack packet back into an ack frame 4383 // Now make sure we can turn our ack packet back into an ack frame
4558 ASSERT_TRUE(framer_.ProcessPacket(*ack_packet)); 4384 ASSERT_TRUE(framer_.ProcessPacket(*ack_packet));
4559 ASSERT_EQ(1u, visitor_.ack_frames_.size()); 4385 ASSERT_EQ(1u, visitor_.ack_frames_.size());
4560 const QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0]; 4386 const QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0];
4561 EXPECT_EQ(header.packet_sequence_number - 1, 4387 EXPECT_EQ(header.packet_sequence_number - 1,
4562 processed_ack_frame.sent_info.least_unacked); 4388 processed_ack_frame.sent_info.least_unacked);
4563 EXPECT_TRUE(processed_ack_frame.received_info.is_truncated); 4389 EXPECT_TRUE(processed_ack_frame.received_info.is_truncated);
4564 EXPECT_EQ(510u, processed_ack_frame.received_info.largest_observed); 4390 EXPECT_EQ(510u, processed_ack_frame.received_info.largest_observed);
4565 ASSERT_EQ(255u, processed_ack_frame.received_info.missing_packets.size()); 4391 ASSERT_EQ(255u, processed_ack_frame.received_info.missing_packets.size());
(...skipping 26 matching lines...) Expand all
4592 QuicFrame frame; 4418 QuicFrame frame;
4593 frame.type = ACK_FRAME; 4419 frame.type = ACK_FRAME;
4594 frame.ack_frame = &ack_frame; 4420 frame.ack_frame = &ack_frame;
4595 QuicFrames frames; 4421 QuicFrames frames;
4596 frames.push_back(frame); 4422 frames.push_back(frame);
4597 4423
4598 scoped_ptr<QuicPacket> raw_ack_packet( 4424 scoped_ptr<QuicPacket> raw_ack_packet(
4599 framer_.BuildUnsizedDataPacket(header, frames).packet); 4425 framer_.BuildUnsizedDataPacket(header, frames).packet);
4600 ASSERT_TRUE(raw_ack_packet != NULL); 4426 ASSERT_TRUE(raw_ack_packet != NULL);
4601 4427
4602 scoped_ptr<QuicEncryptedPacket> ack_packet( 4428 scoped_ptr<QuicEncryptedPacket> ack_packet(framer_.EncryptPacket(
4603 framer_.EncryptPacket(ENCRYPTION_NONE, header.packet_sequence_number, 4429 ENCRYPTION_NONE, header.packet_sequence_number, *raw_ack_packet));
4604 *raw_ack_packet));
4605 4430
4606 // Now make sure we can turn our ack packet back into an ack frame 4431 // Now make sure we can turn our ack packet back into an ack frame
4607 ASSERT_TRUE(framer_.ProcessPacket(*ack_packet)); 4432 ASSERT_TRUE(framer_.ProcessPacket(*ack_packet));
4608 4433
4609 // Test for clean truncation of the ack by comparing the length of the 4434 // Test for clean truncation of the ack by comparing the length of the
4610 // original packets to the re-serialized packets. 4435 // original packets to the re-serialized packets.
4611 frames.clear(); 4436 frames.clear();
4612 frame.type = ACK_FRAME; 4437 frame.type = ACK_FRAME;
4613 frame.ack_frame = visitor_.ack_frames_[0]; 4438 frame.ack_frame = visitor_.ack_frames_[0];
4614 frames.push_back(frame); 4439 frames.push_back(frame);
4615 4440
4616 size_t original_raw_length = raw_ack_packet->length(); 4441 size_t original_raw_length = raw_ack_packet->length();
4617 raw_ack_packet.reset( 4442 raw_ack_packet.reset(framer_.BuildUnsizedDataPacket(header, frames).packet);
4618 framer_.BuildUnsizedDataPacket(header, frames).packet);
4619 ASSERT_TRUE(raw_ack_packet != NULL); 4443 ASSERT_TRUE(raw_ack_packet != NULL);
4620 EXPECT_EQ(original_raw_length, raw_ack_packet->length()); 4444 EXPECT_EQ(original_raw_length, raw_ack_packet->length());
4621 ASSERT_TRUE(raw_ack_packet != NULL); 4445 ASSERT_TRUE(raw_ack_packet != NULL);
4622 } 4446 }
4623 4447
4624 TEST_P(QuicFramerTest, EntropyFlagTest) { 4448 TEST_P(QuicFramerTest, EntropyFlagTest) {
4625 unsigned char packet[] = { 4449 unsigned char packet[] = {// public flags (8 byte connection_id)
4626 // public flags (8 byte connection_id) 4450 0x3C,
4627 0x3C, 4451 // connection_id
4628 // connection_id 4452 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
4629 0x10, 0x32, 0x54, 0x76, 4453 // packet sequence number
4630 0x98, 0xBA, 0xDC, 0xFE, 4454 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
4631 // packet sequence number 4455 // private flags (Entropy)
4632 0xBC, 0x9A, 0x78, 0x56, 4456 0x01,
4633 0x34, 0x12,
4634 // private flags (Entropy)
4635 0x01,
4636 4457
4637 // frame type (stream frame with fin and no length) 4458 // frame type (stream frame with fin and no length)
4638 0xDF, 4459 0xDF,
4639 // stream id 4460 // stream id
4640 0x04, 0x03, 0x02, 0x01, 4461 0x04, 0x03, 0x02, 0x01,
4641 // offset 4462 // offset
4642 0x54, 0x76, 0x10, 0x32, 4463 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA,
4643 0xDC, 0xFE, 0x98, 0xBA, 4464 // data
4644 // data 4465 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o',
4645 'h', 'e', 'l', 'l', 4466 'r', 'l', 'd', '!',
4646 'o', ' ', 'w', 'o',
4647 'r', 'l', 'd', '!',
4648 }; 4467 };
4649 4468
4650 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 4469 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
4651 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 4470 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
4652 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 4471 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
4653 ASSERT_TRUE(visitor_.header_.get()); 4472 ASSERT_TRUE(visitor_.header_.get());
4654 EXPECT_TRUE(visitor_.header_->entropy_flag); 4473 EXPECT_TRUE(visitor_.header_->entropy_flag);
4655 EXPECT_EQ(1 << 4, visitor_.header_->entropy_hash); 4474 EXPECT_EQ(1 << 4, visitor_.header_->entropy_hash);
4656 EXPECT_FALSE(visitor_.header_->fec_flag); 4475 EXPECT_FALSE(visitor_.header_->fec_flag);
4657 }; 4476 };
4658 4477
4659 TEST_P(QuicFramerTest, FecEntropyTest) { 4478 TEST_P(QuicFramerTest, FecEntropyTest) {
4660 unsigned char packet[] = { 4479 unsigned char packet[] = {// public flags (8 byte connection_id)
4661 // public flags (8 byte connection_id) 4480 0x3C,
4662 0x3C, 4481 // connection_id
4663 // connection_id 4482 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
4664 0x10, 0x32, 0x54, 0x76, 4483 // packet sequence number
4665 0x98, 0xBA, 0xDC, 0xFE, 4484 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
4666 // packet sequence number 4485 // private flags (Entropy & fec group & FEC)
4667 0xBC, 0x9A, 0x78, 0x56, 4486 0x07,
4668 0x34, 0x12, 4487 // first fec protected packet offset
4669 // private flags (Entropy & fec group & FEC) 4488 0xFF,
4670 0x07,
4671 // first fec protected packet offset
4672 0xFF,
4673 4489
4674 // frame type (stream frame with fin and no length) 4490 // frame type (stream frame with fin and no length)
4675 0xDF, 4491 0xDF,
4676 // stream id 4492 // stream id
4677 0x04, 0x03, 0x02, 0x01, 4493 0x04, 0x03, 0x02, 0x01,
4678 // offset 4494 // offset
4679 0x54, 0x76, 0x10, 0x32, 4495 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA,
4680 0xDC, 0xFE, 0x98, 0xBA, 4496 // data
4681 // data 4497 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o',
4682 'h', 'e', 'l', 'l', 4498 'r', 'l', 'd', '!',
4683 'o', ' ', 'w', 'o',
4684 'r', 'l', 'd', '!',
4685 }; 4499 };
4686 4500
4687 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 4501 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
4688 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 4502 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
4689 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 4503 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
4690 ASSERT_TRUE(visitor_.header_.get()); 4504 ASSERT_TRUE(visitor_.header_.get());
4691 EXPECT_TRUE(visitor_.header_->fec_flag); 4505 EXPECT_TRUE(visitor_.header_->fec_flag);
4692 EXPECT_TRUE(visitor_.header_->entropy_flag); 4506 EXPECT_TRUE(visitor_.header_->entropy_flag);
4693 EXPECT_EQ(1 << 4, visitor_.header_->entropy_hash); 4507 EXPECT_EQ(1 << 4, visitor_.header_->entropy_hash);
4694 }; 4508 };
4695 4509
4696 TEST_P(QuicFramerTest, StopPacketProcessing) { 4510 TEST_P(QuicFramerTest, StopPacketProcessing) {
4697 unsigned char packet[] = { 4511 unsigned char packet[] = {
4698 // public flags (8 byte connection_id) 4512 // public flags (8 byte connection_id)
4699 0x3C, 4513 0x3C,
4700 // connection_id 4514 // connection_id
4701 0x10, 0x32, 0x54, 0x76, 4515 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
4702 0x98, 0xBA, 0xDC, 0xFE, 4516 // packet sequence number
4703 // packet sequence number 4517 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
4704 0xBC, 0x9A, 0x78, 0x56, 4518 // Entropy
4705 0x34, 0x12, 4519 0x01,
4706 // Entropy
4707 0x01,
4708 4520
4709 // frame type (stream frame with fin) 4521 // frame type (stream frame with fin)
4710 0xFF, 4522 0xFF,
4711 // stream id 4523 // stream id
4712 0x04, 0x03, 0x02, 0x01, 4524 0x04, 0x03, 0x02, 0x01,
4713 // offset 4525 // offset
4714 0x54, 0x76, 0x10, 0x32, 4526 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA,
4715 0xDC, 0xFE, 0x98, 0xBA, 4527 // data length
4716 // data length 4528 0x0c, 0x00,
4717 0x0c, 0x00, 4529 // data
4718 // data 4530 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!',
4719 'h', 'e', 'l', 'l',
4720 'o', ' ', 'w', 'o',
4721 'r', 'l', 'd', '!',
4722 4531
4723 // frame type (ack frame) 4532 // frame type (ack frame)
4724 0x40, 4533 0x40,
4725 // entropy hash of sent packets till least awaiting - 1. 4534 // entropy hash of sent packets till least awaiting - 1.
4726 0x14, 4535 0x14,
4727 // least packet sequence number awaiting an ack 4536 // least packet sequence number awaiting an ack
4728 0xA0, 0x9A, 0x78, 0x56, 4537 0xA0, 0x9A, 0x78, 0x56, 0x34, 0x12,
4729 0x34, 0x12, 4538 // entropy hash of all received packets.
4730 // entropy hash of all received packets. 4539 0x43,
4731 0x43, 4540 // largest observed packet sequence number
4732 // largest observed packet sequence number 4541 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12,
4733 0xBF, 0x9A, 0x78, 0x56, 4542 // num missing packets
4734 0x34, 0x12, 4543 0x01,
4735 // num missing packets 4544 // missing packet
4736 0x01, 4545 0xBE, 0x9A, 0x78, 0x56, 0x34, 0x12,
4737 // missing packet
4738 0xBE, 0x9A, 0x78, 0x56,
4739 0x34, 0x12,
4740 }; 4546 };
4741 4547
4742 MockFramerVisitor visitor; 4548 MockFramerVisitor visitor;
4743 framer_.set_visitor(&visitor); 4549 framer_.set_visitor(&visitor);
4744 EXPECT_CALL(visitor, OnPacket()); 4550 EXPECT_CALL(visitor, OnPacket());
4745 EXPECT_CALL(visitor, OnPacketHeader(_)); 4551 EXPECT_CALL(visitor, OnPacketHeader(_));
4746 EXPECT_CALL(visitor, OnStreamFrame(_)).WillOnce(Return(false)); 4552 EXPECT_CALL(visitor, OnStreamFrame(_)).WillOnce(Return(false));
4747 EXPECT_CALL(visitor, OnAckFrame(_)).Times(0); 4553 EXPECT_CALL(visitor, OnAckFrame(_)).Times(0);
4748 EXPECT_CALL(visitor, OnPacketComplete()); 4554 EXPECT_CALL(visitor, OnPacketComplete());
4749 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); 4555 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true));
4750 4556
4751 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 4557 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
4752 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 4558 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
4753 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 4559 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
4754 } 4560 }
4755 4561
4756 } // namespace test 4562 } // namespace test
4757 } // namespace net 4563 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698