blob: f30fc99cb55d8d25965cba001952b970d5323aad [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// Copyright (c) 2018 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// gunit tests for the IETF-format framer --- generally does a simple test
6// for each framer; we generate the template object (eg
7// QuicIetfStreamFrame) with the correct stuff in it, ask that a frame
8// be serialized (call AppendIetf<mumble>) then deserialized (call
9// ProcessIetf<mumble>) and then check that the gazintas and gazoutas
10// are the same.
11//
12// We do minimal checking of the serialized frame
13//
14// We do look at various different values (resulting in different
15// length varints, etc)
16
17#include "net/third_party/quiche/src/quic/core/quic_framer.h"
18
19#include <algorithm>
20#include <cstdint>
21#include <map>
22#include <memory>
vasilvv872e7a32019-03-12 16:42:44 -070023#include <string>
QUICHE teama6ef0a62019-03-07 20:34:33 -050024#include <vector>
25
26#include "net/third_party/quiche/src/quic/core/crypto/null_decrypter.h"
27#include "net/third_party/quiche/src/quic/core/crypto/null_encrypter.h"
28#include "net/third_party/quiche/src/quic/core/crypto/quic_decrypter.h"
29#include "net/third_party/quiche/src/quic/core/crypto/quic_encrypter.h"
30#include "net/third_party/quiche/src/quic/core/quic_data_reader.h"
31#include "net/third_party/quiche/src/quic/core/quic_data_writer.h"
32#include "net/third_party/quiche/src/quic/core/quic_packets.h"
33#include "net/third_party/quiche/src/quic/core/quic_utils.h"
34#include "net/third_party/quiche/src/quic/platform/api/quic_arraysize.h"
35#include "net/third_party/quiche/src/quic/platform/api/quic_flags.h"
36#include "net/third_party/quiche/src/quic/platform/api/quic_logging.h"
37#include "net/third_party/quiche/src/quic/platform/api/quic_ptr_util.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050038#include "net/third_party/quiche/src/quic/platform/api/quic_test.h"
39#include "net/third_party/quiche/src/quic/test_tools/quic_framer_peer.h"
40#include "net/third_party/quiche/src/quic/test_tools/quic_test_utils.h"
41#include "net/third_party/quiche/src/quic/test_tools/simple_data_producer.h"
42
43namespace quic {
44namespace test {
45namespace {
46
47const size_t kNormalPacketBufferSize = 1400;
48// Several different stream ids, should be encoded
49// in 8, 4, 2, and 1 byte, respectively. Last one
50// checks that value==0 works.
51// All stream IDs end in 0x0, so the client/server- initiated
52// and Uni/Bi-directional bits are available to alter, as any
53// given test may wish.
54const QuicIetfStreamId kStreamId8 = UINT64_C(0x3EDCBA9876543210);
55const QuicIetfStreamId kStreamId4 = UINT64_C(0x36543210);
56const QuicIetfStreamId kStreamId2 = UINT64_C(0x3210);
57const QuicIetfStreamId kStreamId1 = UINT64_C(0x10);
58const QuicIetfStreamId kStreamId0 = UINT64_C(0x00);
59
60// Ditto for the offsets.
61const QuicIetfStreamOffset kOffset8 = UINT64_C(0x3210BA9876543210);
62const QuicIetfStreamOffset kOffset4 = UINT64_C(0x32109876);
63const QuicIetfStreamOffset kOffset2 = UINT64_C(0x3456);
64const QuicIetfStreamOffset kOffset1 = UINT64_C(0x3f);
65const QuicIetfStreamOffset kOffset0 = UINT64_C(0x00);
66
67// Structures used to create various ack frames.
68
69// Defines an ack frame to feed through the framer/deframer.
70struct ack_frame {
71 uint64_t delay_time;
72 bool is_ack_ecn;
73 QuicPacketCount ect_0_count;
74 QuicPacketCount ect_1_count;
75 QuicPacketCount ecn_ce_count;
76 const std::vector<QuicAckBlock>& ranges;
77 uint64_t expected_frame_type;
78};
79
80class TestQuicVisitor : public QuicFramerVisitorInterface {
81 public:
82 TestQuicVisitor() {}
83
84 ~TestQuicVisitor() override {}
85
86 void OnError(QuicFramer* f) override {
87 QUIC_DLOG(INFO) << "QuicIetfFramer Error: "
88 << QuicErrorCodeToString(f->error()) << " (" << f->error()
89 << ")";
90 }
91
92 void OnPacket() override {}
93
94 void OnPublicResetPacket(const QuicPublicResetPacket& packet) override {}
95
96 void OnVersionNegotiationPacket(
97 const QuicVersionNegotiationPacket& packet) override {}
98
dschinazi244f6dc2019-05-06 15:45:16 -070099 void OnRetryPacket(QuicConnectionId original_connection_id,
100 QuicConnectionId new_connection_id,
101 QuicStringPiece retry_token) override {}
102
QUICHE teama6ef0a62019-03-07 20:34:33 -0500103 bool OnProtocolVersionMismatch(ParsedQuicVersion received_version,
104 PacketHeaderFormat form) override {
105 return true;
106 }
107
108 bool OnUnauthenticatedPublicHeader(const QuicPacketHeader& header) override {
109 return true;
110 }
111
112 bool OnUnauthenticatedHeader(const QuicPacketHeader& header) override {
113 return true;
114 }
115
116 void OnDecryptedPacket(EncryptionLevel level) override {}
117
118 bool OnPacketHeader(const QuicPacketHeader& header) override { return true; }
119
120 void OnCoalescedPacket(const QuicEncryptedPacket& packet) override {}
121
122 bool OnStreamFrame(const QuicStreamFrame& frame) override { return true; }
123
124 bool OnCryptoFrame(const QuicCryptoFrame& frame) override { return true; }
125
126 bool OnAckFrameStart(QuicPacketNumber largest_acked,
127 QuicTime::Delta ack_delay_time) override {
128 return true;
129 }
130
131 bool OnAckRange(QuicPacketNumber start, QuicPacketNumber end) override {
132 return true;
133 }
134
135 bool OnAckTimestamp(QuicPacketNumber packet_number,
136 QuicTime timestamp) override {
137 return true;
138 }
139
140 bool OnAckFrameEnd(QuicPacketNumber start) override { return true; }
141
142 bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) override {
143 return true;
144 }
145
146 bool OnPaddingFrame(const QuicPaddingFrame& frame) override { return true; }
147
148 bool OnPingFrame(const QuicPingFrame& frame) override { return true; }
149
150 bool OnMessageFrame(const QuicMessageFrame& frame) override { return true; }
151
152 void OnPacketComplete() override {}
153
154 bool OnRstStreamFrame(const QuicRstStreamFrame& frame) override {
155 return true;
156 }
157
158 bool OnConnectionCloseFrame(const QuicConnectionCloseFrame& frame) override {
159 return true;
160 }
161
QUICHE teama6ef0a62019-03-07 20:34:33 -0500162 bool OnStopSendingFrame(const QuicStopSendingFrame& frame) override {
163 return true;
164 }
165
166 bool OnPathChallengeFrame(const QuicPathChallengeFrame& frame) override {
167 return true;
168 }
169 bool OnPathResponseFrame(const QuicPathResponseFrame& frame) override {
170 return true;
171 }
172
173 bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override { return true; }
174
175 bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override {
176 return true;
177 }
178
179 bool OnBlockedFrame(const QuicBlockedFrame& frame) override { return true; }
180
181 bool OnNewConnectionIdFrame(const QuicNewConnectionIdFrame& frame) override {
182 return true;
183 }
184
185 bool OnRetireConnectionIdFrame(
186 const QuicRetireConnectionIdFrame& frame) override {
187 return true;
188 }
189
190 bool OnNewTokenFrame(const QuicNewTokenFrame& frame) override { return true; }
191
192 bool IsValidStatelessResetToken(QuicUint128 token) const override {
193 return true;
194 }
195
196 void OnAuthenticatedIetfStatelessResetPacket(
197 const QuicIetfStatelessResetPacket& packet) override {}
198
fkastenholz3c4eabf2019-04-22 07:49:59 -0700199 bool OnMaxStreamsFrame(const QuicMaxStreamsFrame& frame) override {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500200 return true;
201 }
202
fkastenholz3c4eabf2019-04-22 07:49:59 -0700203 bool OnStreamsBlockedFrame(const QuicStreamsBlockedFrame& frame) override {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500204 return true;
205 }
206};
207
208class QuicIetfFramerTest : public QuicTestWithParam<ParsedQuicVersion> {
209 public:
210 QuicIetfFramerTest()
211 : start_(QuicTime::Zero() + QuicTime::Delta::FromMicroseconds(0x10)),
212 framer_(AllSupportedVersions(),
213 start_,
214 Perspective::IS_SERVER,
215 kQuicDefaultConnectionIdLength) {
216 framer_.set_visitor(&visitor_);
217 }
218
219 // Utility functions to do actual framing/deframing.
220 void TryStreamFrame(char* packet_buffer,
221 size_t packet_buffer_size,
222 const char* xmit_packet_data,
223 size_t xmit_packet_data_size,
224 QuicIetfStreamId stream_id,
225 QuicIetfStreamOffset offset,
226 bool fin_bit,
227 bool last_frame_bit,
228 QuicIetfFrameType frame_type) {
229 // initialize a writer so that the serialized packet is placed in
230 // packet_buffer.
231 QuicDataWriter writer(packet_buffer_size, packet_buffer,
232 NETWORK_BYTE_ORDER); // do not really care
233 // about endianness.
234 // set up to define the source frame we wish to send.
235 QuicStreamFrame source_stream_frame(
236 stream_id, fin_bit, offset, xmit_packet_data, xmit_packet_data_size);
237
238 // Write the frame to the packet buffer.
239 EXPECT_TRUE(QuicFramerPeer::AppendIetfStreamFrame(
240 &framer_, source_stream_frame, last_frame_bit, &writer));
241 // Better have something in the packet buffer.
242 EXPECT_NE(0u, writer.length());
243 // Now set up a reader to read in the frame.
244 QuicDataReader reader(packet_buffer, writer.length(), NETWORK_BYTE_ORDER);
245
246 // A StreamFrame to hold the results... we know the frame type,
247 // put it into the QuicIetfStreamFrame
248 QuicStreamFrame sink_stream_frame;
249 if (xmit_packet_data_size) {
250 EXPECT_EQ(sink_stream_frame.data_buffer, nullptr);
251 EXPECT_EQ(sink_stream_frame.data_length, 0u);
252 }
253
254 EXPECT_TRUE(QuicFramerPeer::ProcessIetfStreamFrame(
255 &framer_, &reader, frame_type, &sink_stream_frame));
256
257 // Now check that the streamid, fin-bit, offset, and
258 // data len all match the input.
259 EXPECT_EQ(sink_stream_frame.stream_id, source_stream_frame.stream_id);
260 EXPECT_EQ(sink_stream_frame.fin, source_stream_frame.fin);
261 EXPECT_EQ(sink_stream_frame.data_length, source_stream_frame.data_length);
262 if (frame_type & IETF_STREAM_FRAME_OFF_BIT) {
263 // There was an offset in the frame, see if xmit and rcv vales equal.
264 EXPECT_EQ(sink_stream_frame.offset, source_stream_frame.offset);
265 } else {
266 // Offset not in frame, so it better come out 0.
267 EXPECT_EQ(sink_stream_frame.offset, 0u);
268 }
269 if (xmit_packet_data_size) {
270 ASSERT_NE(sink_stream_frame.data_buffer, nullptr);
271 ASSERT_NE(source_stream_frame.data_buffer, nullptr);
272 EXPECT_EQ(strcmp(sink_stream_frame.data_buffer,
273 source_stream_frame.data_buffer),
274 0);
275 } else {
276 // No data in the frame.
277 EXPECT_EQ(source_stream_frame.data_length, 0u);
278 EXPECT_EQ(sink_stream_frame.data_length, 0u);
279 }
280 }
281
282 // Overall ack frame encode/decode/compare function
283 // Encodes an ack frame as specified at |*frame|
284 // Then decodes the frame,
285 // Then compares the two
286 // Does some basic checking:
287 // - did the writer write something?
288 // - did the reader read the entire packet?
289 // - did the things the reader read match what the writer wrote?
290 // Returns true if it all worked false if not.
291 bool TryAckFrame(char* packet_buffer,
292 size_t packet_buffer_size,
293 struct ack_frame* frame) {
294 QuicAckFrame transmit_frame = InitAckFrame(frame->ranges);
295 if (frame->is_ack_ecn) {
296 transmit_frame.ecn_counters_populated = true;
297 transmit_frame.ect_0_count = frame->ect_0_count;
298 transmit_frame.ect_1_count = frame->ect_1_count;
299 transmit_frame.ecn_ce_count = frame->ecn_ce_count;
300 }
301 transmit_frame.ack_delay_time =
302 QuicTime::Delta::FromMicroseconds(frame->delay_time);
303 size_t expected_size =
304 QuicFramerPeer::GetIetfAckFrameSize(&framer_, transmit_frame);
305
306 // Make a writer so that the serialized packet is placed in
307 // packet_buffer.
308 QuicDataWriter writer(expected_size, packet_buffer, NETWORK_BYTE_ORDER);
309
310 // Write the frame to the packet buffer.
311 EXPECT_TRUE(QuicFramerPeer::AppendIetfAckFrameAndTypeByte(
312 &framer_, transmit_frame, &writer));
313
314 size_t expected_frame_length = QuicFramerPeer::ComputeFrameLength(
315 &framer_, QuicFrame(&transmit_frame), false,
316 static_cast<QuicPacketNumberLength>(123456u));
317
318 // Encoded length should match what ComputeFrameLength returns
319 EXPECT_EQ(expected_frame_length, writer.length());
320 // and what is in the buffer should be the expected size.
321 EXPECT_EQ(expected_size, writer.length()) << "Frame is " << transmit_frame;
322 // Now set up a reader to read in the frame.
323 QuicDataReader reader(packet_buffer, writer.length(), NETWORK_BYTE_ORDER);
324
325 // read in the frame type
326 uint8_t received_frame_type;
327 EXPECT_TRUE(reader.ReadUInt8(&received_frame_type));
328 EXPECT_EQ(frame->expected_frame_type, received_frame_type);
329
330 // an AckFrame to hold the results
331 QuicAckFrame receive_frame;
332
333 EXPECT_TRUE(QuicFramerPeer::ProcessIetfAckFrame(
334 &framer_, &reader, received_frame_type, &receive_frame));
335
336 if (frame->is_ack_ecn &&
337 (frame->ect_0_count || frame->ect_1_count || frame->ecn_ce_count)) {
338 EXPECT_TRUE(receive_frame.ecn_counters_populated);
339 EXPECT_EQ(receive_frame.ect_0_count, frame->ect_0_count);
340 EXPECT_EQ(receive_frame.ect_1_count, frame->ect_1_count);
341 EXPECT_EQ(receive_frame.ecn_ce_count, frame->ecn_ce_count);
342 } else {
343 EXPECT_FALSE(receive_frame.ecn_counters_populated);
344 EXPECT_EQ(receive_frame.ect_0_count, 0u);
345 EXPECT_EQ(receive_frame.ect_1_count, 0u);
346 EXPECT_EQ(receive_frame.ecn_ce_count, 0u);
347 }
348
349 // Now check that the received frame matches the sent frame.
350 EXPECT_EQ(transmit_frame.largest_acked, receive_frame.largest_acked);
351 // The ~0x7 needs some explaining. The ack frame format down shifts the
352 // delay time by 3 (divide by 8) to allow for greater ranges in delay time.
353 // Therefore, if we give the framer a delay time that is not an
354 // even multiple of 8, the value that the deframer produces will
355 // not be the same as what the framer got. The downshift on
356 // framing and upshift on deframing results in clearing the 3
357 // low-order bits ... The masking basically does the same thing,
358 // so the compare works properly.
359 return true;
360 }
361
362 // encode, decode, and check a Path Challenge frame.
363 bool TryPathChallengeFrame(char* packet_buffer,
364 size_t packet_buffer_size,
365 const QuicPathFrameBuffer& data) {
366 // Make a writer so that the serialized packet is placed in
367 // packet_buffer.
368 QuicDataWriter writer(packet_buffer_size, packet_buffer,
369 NETWORK_BYTE_ORDER);
370
371 QuicPathChallengeFrame transmit_frame(0, data);
372
373 // write the frame to the packet buffer.
374 EXPECT_TRUE(QuicFramerPeer::AppendPathChallengeFrame(
375 &framer_, transmit_frame, &writer));
376
377 // Check for correct length in the packet buffer.
378 EXPECT_EQ(kQuicPathChallengeFrameSize, writer.length());
379
380 // now set up a reader to read in the frame.
381 QuicDataReader reader(packet_buffer, writer.length(), NETWORK_BYTE_ORDER);
382
383 QuicPathChallengeFrame receive_frame;
384
385 EXPECT_TRUE(QuicFramerPeer::ProcessPathChallengeFrame(&framer_, &reader,
386 &receive_frame));
387
388 // Now check that the received frame matches the sent frame.
389 EXPECT_EQ(
390 0, memcmp(transmit_frame.data_buffer.data(),
391 receive_frame.data_buffer.data(), kQuicPathFrameBufferSize));
392 return true;
393 }
394
395 // encode, decode, and check a Path Response frame.
396 bool TryPathResponseFrame(char* packet_buffer,
397 size_t packet_buffer_size,
398 const QuicPathFrameBuffer& data) {
399 // Make a writer so that the serialized packet is placed in
400 // packet_buffer.
401 QuicDataWriter writer(packet_buffer_size, packet_buffer,
402 NETWORK_BYTE_ORDER);
403
404 QuicPathResponseFrame transmit_frame(0, data);
405
406 // Write the frame to the packet buffer.
407 EXPECT_TRUE(QuicFramerPeer::AppendPathResponseFrame(
408 &framer_, transmit_frame, &writer));
409
410 // Check for correct length in the packet buffer.
411 EXPECT_EQ(kQuicPathResponseFrameSize, writer.length());
412
413 // Set up a reader to read in the frame.
414 QuicDataReader reader(packet_buffer, writer.length(), NETWORK_BYTE_ORDER);
415
416 QuicPathResponseFrame receive_frame;
417
418 EXPECT_TRUE(QuicFramerPeer::ProcessPathResponseFrame(&framer_, &reader,
419 &receive_frame));
420
421 // Now check that the received frame matches the sent frame.
422 EXPECT_EQ(
423 0, memcmp(transmit_frame.data_buffer.data(),
424 receive_frame.data_buffer.data(), kQuicPathFrameBufferSize));
425 return true;
426 }
427
428 // Test the Serialization/deserialization of a Reset Stream Frame.
429 void TryResetFrame(char* packet_buffer,
430 size_t packet_buffer_size,
431 QuicStreamId stream_id,
432 uint16_t error_code,
433 QuicStreamOffset final_offset) {
434 // Initialize a writer so that the serialized packet is placed in
435 // packet_buffer.
436 QuicDataWriter writer(packet_buffer_size, packet_buffer,
437 NETWORK_BYTE_ORDER);
438
439 QuicRstStreamFrame transmit_frame(static_cast<QuicControlFrameId>(1),
440 stream_id, error_code, final_offset);
441
442 // Write the frame to the packet buffer.
443 EXPECT_TRUE(QuicFramerPeer::AppendIetfResetStreamFrame(
444 &framer_, transmit_frame, &writer));
445 // Check that the size of the serialzed frame is in the allowed range.
446 EXPECT_LT(3u, writer.length());
447 EXPECT_GT(19u, writer.length());
448 // Now set up a reader to read in the thing in.
449 QuicDataReader reader(packet_buffer, writer.length(), NETWORK_BYTE_ORDER);
450
451 // A QuicRstStreamFrame to hold the results
452 QuicRstStreamFrame receive_frame;
453 EXPECT_TRUE(QuicFramerPeer::ProcessIetfResetStreamFrame(&framer_, &reader,
454 &receive_frame));
455
456 // Now check that the received values match the input.
457 EXPECT_EQ(receive_frame.stream_id, transmit_frame.stream_id);
458 EXPECT_EQ(receive_frame.ietf_error_code, transmit_frame.ietf_error_code);
459 EXPECT_EQ(receive_frame.byte_offset, transmit_frame.byte_offset);
460 }
461
fkastenholz3c4eabf2019-04-22 07:49:59 -0700462 void TryMaxStreamsFrame(QuicStreamCount stream_count,
QUICHE teama6ef0a62019-03-07 20:34:33 -0500463 bool unidirectional,
464 bool stream_id_server_initiated) {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500465 char packet_buffer[kNormalPacketBufferSize];
466 memset(packet_buffer, 0, sizeof(packet_buffer));
467
468 Perspective old_perspective = framer_.perspective();
fkastenholz3c4eabf2019-04-22 07:49:59 -0700469 // Set up the writer and transmit QuicMaxStreamsFrame
QUICHE teama6ef0a62019-03-07 20:34:33 -0500470 QuicDataWriter writer(sizeof(packet_buffer), packet_buffer,
471 NETWORK_BYTE_ORDER);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500472
473 // Set the perspective of the sender. If the stream id is supposed to
474 // be server-initiated, then the sender of the MAX_STREAMS should be
475 // a client, and vice versa. Do this prior to constructing the frame or
476 // generating the packet, so that any internal dependencies are satisfied.
477 QuicFramerPeer::SetPerspective(&framer_, (stream_id_server_initiated)
478 ? Perspective::IS_CLIENT
479 : Perspective::IS_SERVER);
fkastenholz3c4eabf2019-04-22 07:49:59 -0700480 QuicMaxStreamsFrame transmit_frame(0, stream_count, unidirectional);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500481
482 // Add the frame.
483 EXPECT_TRUE(QuicFramerPeer::AppendMaxStreamsFrame(&framer_, transmit_frame,
484 &writer));
485
486 // Check that buffer length is in the expected range
487 EXPECT_LE(1u, writer.length());
488 EXPECT_GE(8u, writer.length());
489
490 // Set the perspective for the receiver.
491 QuicFramerPeer::SetPerspective(&framer_, (stream_id_server_initiated)
492 ? Perspective::IS_SERVER
493 : Perspective::IS_CLIENT);
494
495 // Set up reader and empty receive QuicPaddingFrame.
496 QuicDataReader reader(packet_buffer, writer.length(), NETWORK_BYTE_ORDER);
fkastenholz3c4eabf2019-04-22 07:49:59 -0700497 QuicMaxStreamsFrame receive_frame;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500498
499 // Deframe it
500 EXPECT_TRUE(QuicFramerPeer::ProcessMaxStreamsFrame(
501 &framer_, &reader, &receive_frame,
502 (unidirectional) ? IETF_MAX_STREAMS_UNIDIRECTIONAL
503 : IETF_MAX_STREAMS_BIDIRECTIONAL))
504 << " Error: " << framer_.detailed_error();
505
506 // Now check that received and sent data are equivalent
fkastenholz3c4eabf2019-04-22 07:49:59 -0700507 EXPECT_EQ(stream_count, receive_frame.stream_count);
508 EXPECT_EQ(transmit_frame.stream_count, receive_frame.stream_count);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500509 QuicFramerPeer::SetPerspective(&framer_, old_perspective);
510 }
511
fkastenholz3c4eabf2019-04-22 07:49:59 -0700512 void TryStreamsBlockedFrame(QuicStreamCount stream_count,
QUICHE teama6ef0a62019-03-07 20:34:33 -0500513 bool unidirectional,
514 bool stream_id_server_initiated) {
QUICHE teama6ef0a62019-03-07 20:34:33 -0500515 char packet_buffer[kNormalPacketBufferSize];
516 memset(packet_buffer, 0, sizeof(packet_buffer));
517
518 Perspective old_perspective = framer_.perspective();
fkastenholz3c4eabf2019-04-22 07:49:59 -0700519 // Set up the writer and transmit QuicStreamsBlockedFrame
QUICHE teama6ef0a62019-03-07 20:34:33 -0500520 QuicDataWriter writer(sizeof(packet_buffer), packet_buffer,
521 NETWORK_BYTE_ORDER);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500522
523 // Set the perspective of the sender. If the stream id is supposed to
fkastenholz3c4eabf2019-04-22 07:49:59 -0700524 // be server-initiated, then the sender of the STREAMS_BLOCKED should be
QUICHE teama6ef0a62019-03-07 20:34:33 -0500525 // a client, and vice versa. Do this prior to constructing the frame or
526 // generating the packet, so that any internal dependencies are satisfied.
527 QuicFramerPeer::SetPerspective(&framer_, (stream_id_server_initiated)
528 ? Perspective::IS_SERVER
529 : Perspective::IS_CLIENT);
fkastenholz3c4eabf2019-04-22 07:49:59 -0700530 QuicStreamsBlockedFrame transmit_frame(0, stream_count, unidirectional);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500531
532 // Add the frame.
533 EXPECT_TRUE(QuicFramerPeer::AppendStreamsBlockedFrame(
534 &framer_, transmit_frame, &writer));
535
536 // Check that buffer length is in the expected range
537 EXPECT_LE(1u, writer.length());
538 EXPECT_GE(8u, writer.length());
539
540 // Set the perspective for the receiver.
541 QuicFramerPeer::SetPerspective(&framer_, (stream_id_server_initiated)
542 ? Perspective::IS_CLIENT
543 : Perspective::IS_SERVER);
544
545 // Set up reader and empty receive QuicPaddingFrame.
546 QuicDataReader reader(packet_buffer, writer.length(), NETWORK_BYTE_ORDER);
fkastenholz3c4eabf2019-04-22 07:49:59 -0700547 QuicStreamsBlockedFrame receive_frame;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500548
549 // Deframe it
550 EXPECT_TRUE(QuicFramerPeer::ProcessStreamsBlockedFrame(
551 &framer_, &reader, &receive_frame,
552 (unidirectional) ? IETF_STREAMS_BLOCKED_UNIDIRECTIONAL
553 : IETF_STREAMS_BLOCKED_BIDIRECTIONAL));
554
555 // Now check that received and sent data are equivalent
fkastenholz3c4eabf2019-04-22 07:49:59 -0700556 EXPECT_EQ(stream_count, receive_frame.stream_count);
557 EXPECT_EQ(transmit_frame.stream_count, receive_frame.stream_count);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500558 QuicFramerPeer::SetPerspective(&framer_, old_perspective);
559 }
560
561 QuicTime start_;
562 QuicFramer framer_;
563 test::TestQuicVisitor visitor_;
564};
565
566struct stream_frame_variant {
567 QuicIetfStreamId stream_id;
568 QuicIetfStreamOffset offset;
569 bool fin_bit;
570 bool last_frame_bit;
571 uint8_t frame_type;
572} stream_frame_to_test[] = {
573#define IETF_STREAM0 (((uint8_t)IETF_STREAM))
574
575#define IETF_STREAM1 (((uint8_t)IETF_STREAM) | IETF_STREAM_FRAME_FIN_BIT)
576
577#define IETF_STREAM2 (((uint8_t)IETF_STREAM) | IETF_STREAM_FRAME_LEN_BIT)
578
579#define IETF_STREAM3 \
580 (((uint8_t)IETF_STREAM) | IETF_STREAM_FRAME_LEN_BIT | \
581 IETF_STREAM_FRAME_FIN_BIT)
582
583#define IETF_STREAM4 (((uint8_t)IETF_STREAM) | IETF_STREAM_FRAME_OFF_BIT)
584
585#define IETF_STREAM5 \
586 (((uint8_t)IETF_STREAM) | IETF_STREAM_FRAME_OFF_BIT | \
587 IETF_STREAM_FRAME_FIN_BIT)
588
589#define IETF_STREAM6 \
590 (((uint8_t)IETF_STREAM) | IETF_STREAM_FRAME_OFF_BIT | \
591 IETF_STREAM_FRAME_LEN_BIT)
592
593#define IETF_STREAM7 \
594 (((uint8_t)IETF_STREAM) | IETF_STREAM_FRAME_OFF_BIT | \
595 IETF_STREAM_FRAME_LEN_BIT | IETF_STREAM_FRAME_FIN_BIT)
596
597 {kStreamId8, kOffset8, true, false, IETF_STREAM7},
598 {kStreamId8, kOffset8, false, false, IETF_STREAM6},
599 {kStreamId8, kOffset4, true, false, IETF_STREAM7},
600 {kStreamId8, kOffset4, false, false, IETF_STREAM6},
601 {kStreamId8, kOffset2, true, false, IETF_STREAM7},
602 {kStreamId8, kOffset2, false, false, IETF_STREAM6},
603 {kStreamId8, kOffset1, true, false, IETF_STREAM7},
604 {kStreamId8, kOffset1, false, false, IETF_STREAM6},
605 {kStreamId8, kOffset0, true, false, IETF_STREAM3},
606 {kStreamId8, kOffset0, false, false, IETF_STREAM2},
607 {kStreamId4, kOffset8, true, false, IETF_STREAM7},
608 {kStreamId4, kOffset8, false, false, IETF_STREAM6},
609 {kStreamId4, kOffset4, true, false, IETF_STREAM7},
610 {kStreamId4, kOffset4, false, false, IETF_STREAM6},
611 {kStreamId4, kOffset2, true, false, IETF_STREAM7},
612 {kStreamId4, kOffset2, false, false, IETF_STREAM6},
613 {kStreamId4, kOffset1, true, false, IETF_STREAM7},
614 {kStreamId4, kOffset1, false, false, IETF_STREAM6},
615 {kStreamId4, kOffset0, true, false, IETF_STREAM3},
616 {kStreamId4, kOffset0, false, false, IETF_STREAM2},
617 {kStreamId2, kOffset8, true, false, IETF_STREAM7},
618 {kStreamId2, kOffset8, false, false, IETF_STREAM6},
619 {kStreamId2, kOffset4, true, false, IETF_STREAM7},
620 {kStreamId2, kOffset4, false, false, IETF_STREAM6},
621 {kStreamId2, kOffset2, true, false, IETF_STREAM7},
622 {kStreamId2, kOffset2, false, false, IETF_STREAM6},
623 {kStreamId2, kOffset1, true, false, IETF_STREAM7},
624 {kStreamId2, kOffset1, false, false, IETF_STREAM6},
625 {kStreamId2, kOffset0, true, false, IETF_STREAM3},
626 {kStreamId2, kOffset0, false, false, IETF_STREAM2},
627 {kStreamId1, kOffset8, true, false, IETF_STREAM7},
628 {kStreamId1, kOffset8, false, false, IETF_STREAM6},
629 {kStreamId1, kOffset4, true, false, IETF_STREAM7},
630 {kStreamId1, kOffset4, false, false, IETF_STREAM6},
631 {kStreamId1, kOffset2, true, false, IETF_STREAM7},
632 {kStreamId1, kOffset2, false, false, IETF_STREAM6},
633 {kStreamId1, kOffset1, true, false, IETF_STREAM7},
634 {kStreamId1, kOffset1, false, false, IETF_STREAM6},
635 {kStreamId1, kOffset0, true, false, IETF_STREAM3},
636 {kStreamId1, kOffset0, false, false, IETF_STREAM2},
637 {kStreamId0, kOffset8, true, false, IETF_STREAM7},
638 {kStreamId0, kOffset8, false, false, IETF_STREAM6},
639 {kStreamId0, kOffset4, true, false, IETF_STREAM7},
640 {kStreamId0, kOffset4, false, false, IETF_STREAM6},
641 {kStreamId0, kOffset2, true, false, IETF_STREAM7},
642 {kStreamId0, kOffset2, false, false, IETF_STREAM6},
643 {kStreamId0, kOffset1, true, false, IETF_STREAM7},
644 {kStreamId0, kOffset1, false, false, IETF_STREAM6},
645 {kStreamId0, kOffset0, true, false, IETF_STREAM3},
646 {kStreamId0, kOffset0, false, false, IETF_STREAM2},
647
648 {kStreamId8, kOffset8, true, true, IETF_STREAM5},
649 {kStreamId8, kOffset8, false, true, IETF_STREAM4},
650 {kStreamId8, kOffset4, true, true, IETF_STREAM5},
651 {kStreamId8, kOffset4, false, true, IETF_STREAM4},
652 {kStreamId8, kOffset2, true, true, IETF_STREAM5},
653 {kStreamId8, kOffset2, false, true, IETF_STREAM4},
654 {kStreamId8, kOffset1, true, true, IETF_STREAM5},
655 {kStreamId8, kOffset1, false, true, IETF_STREAM4},
656 {kStreamId8, kOffset0, true, true, IETF_STREAM1},
657 {kStreamId8, kOffset0, false, true, IETF_STREAM0},
658 {kStreamId4, kOffset8, true, true, IETF_STREAM5},
659 {kStreamId4, kOffset8, false, true, IETF_STREAM4},
660 {kStreamId4, kOffset4, true, true, IETF_STREAM5},
661 {kStreamId4, kOffset4, false, true, IETF_STREAM4},
662 {kStreamId4, kOffset2, true, true, IETF_STREAM5},
663 {kStreamId4, kOffset2, false, true, IETF_STREAM4},
664 {kStreamId4, kOffset1, true, true, IETF_STREAM5},
665 {kStreamId4, kOffset1, false, true, IETF_STREAM4},
666 {kStreamId4, kOffset0, true, true, IETF_STREAM1},
667 {kStreamId4, kOffset0, false, true, IETF_STREAM0},
668 {kStreamId2, kOffset8, true, true, IETF_STREAM5},
669 {kStreamId2, kOffset8, false, true, IETF_STREAM4},
670 {kStreamId2, kOffset4, true, true, IETF_STREAM5},
671 {kStreamId2, kOffset4, false, true, IETF_STREAM4},
672 {kStreamId2, kOffset2, true, true, IETF_STREAM5},
673 {kStreamId2, kOffset2, false, true, IETF_STREAM4},
674 {kStreamId2, kOffset1, true, true, IETF_STREAM5},
675 {kStreamId2, kOffset1, false, true, IETF_STREAM4},
676 {kStreamId2, kOffset0, true, true, IETF_STREAM1},
677 {kStreamId2, kOffset0, false, true, IETF_STREAM0},
678 {kStreamId1, kOffset8, true, true, IETF_STREAM5},
679 {kStreamId1, kOffset8, false, true, IETF_STREAM4},
680 {kStreamId1, kOffset4, true, true, IETF_STREAM5},
681 {kStreamId1, kOffset4, false, true, IETF_STREAM4},
682 {kStreamId1, kOffset2, true, true, IETF_STREAM5},
683 {kStreamId1, kOffset2, false, true, IETF_STREAM4},
684 {kStreamId1, kOffset1, true, true, IETF_STREAM5},
685 {kStreamId1, kOffset1, false, true, IETF_STREAM4},
686 {kStreamId1, kOffset0, true, true, IETF_STREAM1},
687 {kStreamId1, kOffset0, false, true, IETF_STREAM0},
688 {kStreamId0, kOffset8, true, true, IETF_STREAM5},
689 {kStreamId0, kOffset8, false, true, IETF_STREAM4},
690 {kStreamId0, kOffset4, true, true, IETF_STREAM5},
691 {kStreamId0, kOffset4, false, true, IETF_STREAM4},
692 {kStreamId0, kOffset2, true, true, IETF_STREAM5},
693 {kStreamId0, kOffset2, false, true, IETF_STREAM4},
694 {kStreamId0, kOffset1, true, true, IETF_STREAM5},
695 {kStreamId0, kOffset1, false, true, IETF_STREAM4},
696 {kStreamId0, kOffset0, true, true, IETF_STREAM1},
697 {kStreamId0, kOffset0, false, true, IETF_STREAM0},
698};
699
700TEST_F(QuicIetfFramerTest, StreamFrame) {
701 char packet_buffer[kNormalPacketBufferSize];
702 const char* transmit_packet_data =
703 "this is a test of some packet data, "
704 "can do a simple strcmp to see if the "
705 "input and output are the same!";
706
707 size_t transmit_packet_data_len = strlen(transmit_packet_data) + 1;
708 for (size_t i = 0; i < QUIC_ARRAYSIZE(stream_frame_to_test); ++i) {
709 SCOPED_TRACE(i);
710 struct stream_frame_variant* variant = &stream_frame_to_test[i];
711 TryStreamFrame(packet_buffer, sizeof(packet_buffer), transmit_packet_data,
712 transmit_packet_data_len, variant->stream_id,
713 variant->offset, variant->fin_bit, variant->last_frame_bit,
714 static_cast<QuicIetfFrameType>(variant->frame_type));
715 }
716}
717// As the previous test, but with no data.
718TEST_F(QuicIetfFramerTest, ZeroLengthStreamFrame) {
719 char packet_buffer[kNormalPacketBufferSize];
720
721 for (size_t i = 0; i < QUIC_ARRAYSIZE(stream_frame_to_test); ++i) {
722 SCOPED_TRACE(i);
723 struct stream_frame_variant* variant = &stream_frame_to_test[i];
724 TryStreamFrame(packet_buffer, sizeof(packet_buffer),
725 /* xmit_packet_data = */ NULL,
726 /* xmit_packet_data_size = */ 0, variant->stream_id,
727 variant->offset, variant->fin_bit, variant->last_frame_bit,
728 static_cast<QuicIetfFrameType>(variant->frame_type));
729 }
730}
731
732TEST_F(QuicIetfFramerTest, CryptoFrame) {
733 SimpleDataProducer data_producer;
734 framer_.set_data_producer(&data_producer);
735 char packet_buffer[kNormalPacketBufferSize];
736
737 QuicStringPiece frame_data("This is a CRYPTO frame.");
738
739 QuicStreamOffset offsets[] = {kOffset8, kOffset4, kOffset2, kOffset1,
740 kOffset0};
741 for (QuicStreamOffset offset : offsets) {
QUICHE team6987b4a2019-03-15 16:23:04 -0700742 QuicCryptoFrame frame(ENCRYPTION_INITIAL, offset, frame_data.length());
743 data_producer.SaveCryptoData(ENCRYPTION_INITIAL, offset, frame_data);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500744
745 QuicDataWriter writer(QUIC_ARRAYSIZE(packet_buffer), packet_buffer,
746 NETWORK_BYTE_ORDER);
747
748 // Write the frame.
749 EXPECT_TRUE(QuicFramerPeer::AppendCryptoFrame(&framer_, frame, &writer));
750 EXPECT_NE(0u, writer.length());
751 // Read it back.
752 QuicDataReader reader(packet_buffer, writer.length(), NETWORK_BYTE_ORDER);
753 QuicCryptoFrame read_frame;
754 EXPECT_TRUE(
755 QuicFramerPeer::ProcessCryptoFrame(&framer_, &reader, &read_frame));
756
757 // Check that the frames match:
758 QuicStringPiece read_data(read_frame.data_buffer, read_frame.data_length);
759 EXPECT_EQ(read_frame.data_length, frame.data_length);
760 EXPECT_EQ(read_frame.offset, frame.offset);
761 EXPECT_EQ(read_data, frame_data);
762 }
763}
764
765TEST_F(QuicIetfFramerTest, ConnectionCloseEmptyString) {
766 char packet_buffer[kNormalPacketBufferSize];
767
768 // initialize a writer so that the serialized packet is placed in
769 // packet_buffer.
770 QuicDataWriter writer(sizeof(packet_buffer), packet_buffer,
771 NETWORK_BYTE_ORDER);
772
773 // empty string,
vasilvvc48c8712019-03-11 13:38:16 -0700774 std::string test_string = "Ich Bin Ein Jelly Donut?";
QUICHE teama6ef0a62019-03-07 20:34:33 -0500775 QuicConnectionCloseFrame sent_frame;
fkastenholze9d71a82019-04-09 05:12:13 -0700776 sent_frame.quic_error_code = static_cast<QuicErrorCode>(0);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500777 sent_frame.error_details = test_string;
fkastenholze9d71a82019-04-09 05:12:13 -0700778 sent_frame.transport_close_frame_type = 123;
fkastenholz72f509b2019-04-10 09:17:49 -0700779 sent_frame.close_type = IETF_QUIC_TRANSPORT_CONNECTION_CLOSE;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500780 // write the frame to the packet buffer.
781 EXPECT_TRUE(QuicFramerPeer::AppendIetfConnectionCloseFrame(
782 &framer_, sent_frame, &writer));
783
784 // better have something in the packet buffer.
785 EXPECT_NE(0u, writer.length());
786
787 // now set up a reader to read in the frame.
788 QuicDataReader reader(packet_buffer, writer.length(), NETWORK_BYTE_ORDER);
789
790 // a QuicConnectionCloseFrame to hold the results.
791 QuicConnectionCloseFrame sink_frame;
792
fkastenholze9d71a82019-04-09 05:12:13 -0700793 EXPECT_TRUE(QuicFramerPeer::ProcessIetfConnectionCloseFrame(
794 &framer_, &reader, IETF_QUIC_TRANSPORT_CONNECTION_CLOSE, &sink_frame));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500795
796 // Now check that received == sent
fkastenholz72f509b2019-04-10 09:17:49 -0700797 EXPECT_EQ(sent_frame.quic_error_code, sink_frame.quic_error_code);
fkastenholze9d71a82019-04-09 05:12:13 -0700798 EXPECT_EQ(sink_frame.quic_error_code, static_cast<QuicErrorCode>(0));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500799 EXPECT_EQ(sink_frame.error_details, test_string);
fkastenholz72f509b2019-04-10 09:17:49 -0700800 EXPECT_EQ(sink_frame.close_type, sent_frame.close_type);
801 EXPECT_EQ(sent_frame.close_type, IETF_QUIC_TRANSPORT_CONNECTION_CLOSE);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500802}
803
804TEST_F(QuicIetfFramerTest, ApplicationCloseEmptyString) {
805 char packet_buffer[kNormalPacketBufferSize];
806
807 // initialize a writer so that the serialized packet is placed in
808 // packet_buffer.
809 QuicDataWriter writer(sizeof(packet_buffer), packet_buffer,
810 NETWORK_BYTE_ORDER);
811
812 // empty string,
vasilvvc48c8712019-03-11 13:38:16 -0700813 std::string test_string = "Ich Bin Ein Jelly Donut?";
fkastenholz72f509b2019-04-10 09:17:49 -0700814 QuicConnectionCloseFrame sent_frame;
815 sent_frame.quic_error_code = static_cast<QuicErrorCode>(0);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500816 sent_frame.error_details = test_string;
fkastenholz72f509b2019-04-10 09:17:49 -0700817 sent_frame.close_type = IETF_QUIC_APPLICATION_CONNECTION_CLOSE;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500818 // write the frame to the packet buffer.
fkastenholz72f509b2019-04-10 09:17:49 -0700819 EXPECT_TRUE(QuicFramerPeer::AppendIetfConnectionCloseFrame(
820 &framer_, sent_frame, &writer));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500821
822 // better have something in the packet buffer.
823 EXPECT_NE(0u, writer.length());
824
825 // now set up a reader to read in the frame.
826 QuicDataReader reader(packet_buffer, writer.length(), NETWORK_BYTE_ORDER);
827
828 // a QuicConnectionCloseFrame to hold the results.
fkastenholz72f509b2019-04-10 09:17:49 -0700829 QuicConnectionCloseFrame sink_frame;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500830
fkastenholz72f509b2019-04-10 09:17:49 -0700831 EXPECT_TRUE(QuicFramerPeer::ProcessIetfConnectionCloseFrame(
832 &framer_, &reader, IETF_QUIC_APPLICATION_CONNECTION_CLOSE, &sink_frame));
QUICHE teama6ef0a62019-03-07 20:34:33 -0500833
834 // Now check that received == sent
fkastenholz72f509b2019-04-10 09:17:49 -0700835 EXPECT_EQ(sink_frame.quic_error_code, static_cast<QuicErrorCode>(0));
836 EXPECT_EQ(sent_frame.quic_error_code, sink_frame.quic_error_code);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500837 EXPECT_EQ(sink_frame.error_details, test_string);
fkastenholz72f509b2019-04-10 09:17:49 -0700838 EXPECT_EQ(sent_frame.close_type, IETF_QUIC_APPLICATION_CONNECTION_CLOSE);
839 EXPECT_EQ(sent_frame.close_type, sink_frame.close_type);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500840}
841
842// Testing for the IETF ACK framer.
843// clang-format off
844struct ack_frame ack_frame_variants[] = {
845 {90000,
846 false,
847 0,
848 0,
849 0,
850 {{QuicPacketNumber(1000), QuicPacketNumber(2001)}},
851 IETF_ACK},
852 {0,
853 false,
854 0,
855 0,
856 0,
857 {{QuicPacketNumber(1000), QuicPacketNumber(2001)}},
858 IETF_ACK},
859 {1,
860 false,
861 0,
862 0,
863 0,
864 {{QuicPacketNumber(1), QuicPacketNumber(2)},
865 {QuicPacketNumber(5), QuicPacketNumber(6)}},
866 IETF_ACK},
867 {63,
868 false,
869 0,
870 0,
871 0,
872 {{QuicPacketNumber(1), QuicPacketNumber(2)},
873 {QuicPacketNumber(5), QuicPacketNumber(6)}},
874 IETF_ACK},
875 {64,
876 false,
877 0,
878 0,
879 0,
880 {{QuicPacketNumber(1), QuicPacketNumber(2)},
881 {QuicPacketNumber(3), QuicPacketNumber(4)},
882 {QuicPacketNumber(5), QuicPacketNumber(6)},
883 {QuicPacketNumber(7), QuicPacketNumber(8)},
884 {QuicPacketNumber(9), QuicPacketNumber(10)},
885 {QuicPacketNumber(11), QuicPacketNumber(12)}},
886 IETF_ACK},
887 {10000,
888 false,
889 0,
890 0,
891 0,
892 {{QuicPacketNumber(1), QuicPacketNumber(2)},
893 {QuicPacketNumber(3), QuicPacketNumber(4)},
894 {QuicPacketNumber(5), QuicPacketNumber(6)},
895 {QuicPacketNumber(7), QuicPacketNumber(8)},
896 {QuicPacketNumber(9), QuicPacketNumber(10)},
897 {QuicPacketNumber(11), QuicPacketNumber(12)}},
898 IETF_ACK},
899 {100000000,
900 false,
901 0,
902 0,
903 0,
904 {{QuicPacketNumber(1), QuicPacketNumber(2)},
905 {QuicPacketNumber(3), QuicPacketNumber(4)},
906 {QuicPacketNumber(5), QuicPacketNumber(6)},
907 {QuicPacketNumber(7), QuicPacketNumber(8)},
908 {QuicPacketNumber(9), QuicPacketNumber(10)},
909 {QuicPacketNumber(11), QuicPacketNumber(12)}},
910 IETF_ACK},
911 {0,
912 false,
913 0,
914 0,
915 0,
916 {{QuicPacketNumber(1), QuicPacketNumber(65)}},
917 IETF_ACK},
918 {9223372036854775807,
919 false,
920 0,
921 0,
922 0,
923 {{QuicPacketNumber(1), QuicPacketNumber(11)},
924 {QuicPacketNumber(74), QuicPacketNumber(138)}},
925 IETF_ACK},
926 // This ack is for packets 60 & 125. There are 64 packets in the gap.
927 // The encoded value is gap_size - 1, or 63. Crosses a VarInt62 encoding
928 // boundary...
929 {1,
930 false,
931 0,
932 0,
933 0,
934 {{QuicPacketNumber(60), QuicPacketNumber(61)},
935 {QuicPacketNumber(125), QuicPacketNumber(126)}},
936 IETF_ACK},
937 {2,
938 false,
939 0,
940 0,
941 0,
942 {{QuicPacketNumber(1), QuicPacketNumber(65)},
943 {QuicPacketNumber(129), QuicPacketNumber(130)}},
944 IETF_ACK},
945 {3,
946 false,
947 0,
948 0,
949 0,
950 {{QuicPacketNumber(1), QuicPacketNumber(65)},
951 {QuicPacketNumber(129), QuicPacketNumber(195)}},
952 IETF_ACK},
953 {4,
954 false,
955 0,
956 0,
957 0,
958 {{QuicPacketNumber(1), QuicPacketNumber(65)},
959 {QuicPacketNumber(129), QuicPacketNumber(194)}},
960 IETF_ACK},
961 {5,
962 false,
963 0,
964 0,
965 0,
966 {{QuicPacketNumber(1), QuicPacketNumber(65)},
967 {QuicPacketNumber(129), QuicPacketNumber(193)}},
968 IETF_ACK},
969 {6,
970 false,
971 0,
972 0,
973 0,
974 {{QuicPacketNumber(1), QuicPacketNumber(65)},
975 {QuicPacketNumber(129), QuicPacketNumber(192)}},
976 IETF_ACK},
977 // declare some ack_ecn frames to try.
978 {6,
979 false,
980 100,
981 200,
982 300,
983 {{QuicPacketNumber(1), QuicPacketNumber(65)},
984 {QuicPacketNumber(129), QuicPacketNumber(192)}},
985 IETF_ACK},
986 {6,
987 true,
988 100,
989 200,
990 300,
991 {{QuicPacketNumber(1), QuicPacketNumber(65)},
992 {QuicPacketNumber(129), QuicPacketNumber(192)}},
993 IETF_ACK_ECN},
994 {6,
995 true,
996 100,
997 0,
998 0,
999 {{QuicPacketNumber(1), QuicPacketNumber(65)},
1000 {QuicPacketNumber(129), QuicPacketNumber(192)}},
1001 IETF_ACK_ECN},
1002 {6,
1003 true,
1004 0,
1005 200,
1006 0,
1007 {{QuicPacketNumber(1), QuicPacketNumber(65)},
1008 {QuicPacketNumber(129), QuicPacketNumber(192)}},
1009 IETF_ACK_ECN},
1010 {6,
1011 true,
1012 0,
1013 0,
1014 300,
1015 {{QuicPacketNumber(1), QuicPacketNumber(65)},
1016 {QuicPacketNumber(129), QuicPacketNumber(192)}},
1017 IETF_ACK_ECN},
1018 {6,
1019 true,
1020 0,
1021 0,
1022 0,
1023 {{QuicPacketNumber(1), QuicPacketNumber(65)},
1024 {QuicPacketNumber(129), QuicPacketNumber(192)}},
1025 IETF_ACK},
1026};
1027// clang-format on
1028
1029TEST_F(QuicIetfFramerTest, AckFrame) {
1030 char packet_buffer[kNormalPacketBufferSize];
1031 for (auto ack_frame_variant : ack_frame_variants) {
1032 EXPECT_TRUE(
1033 TryAckFrame(packet_buffer, sizeof(packet_buffer), &ack_frame_variant));
1034 }
1035}
1036
1037// Test the case of having a QuicAckFrame with no ranges in it. By
1038// examination of the Google Quic Ack code and tests, this case should
1039// be handled as an ack with no "ranges after the first"; the
1040// AckBlockCount should be 0 and the FirstAckBlock should be
1041// |LargestAcked| - 1 (number of packets preceding the LargestAcked.
1042TEST_F(QuicIetfFramerTest, AckFrameNoRanges) {
1043 char packet_buffer[kNormalPacketBufferSize];
1044
1045 // Make a writer so that the serialized packet is placed in
1046 // packet_buffer.
1047 QuicDataWriter writer(sizeof(packet_buffer), packet_buffer,
1048 NETWORK_BYTE_ORDER);
1049
1050 QuicAckFrame transmit_frame;
1051 transmit_frame.largest_acked = QuicPacketNumber(1);
1052 transmit_frame.ack_delay_time = QuicTime::Delta::FromMicroseconds(0);
1053
1054 size_t expected_size =
1055 QuicFramerPeer::GetIetfAckFrameSize(&framer_, transmit_frame);
1056 // Write the frame to the packet buffer.
1057 EXPECT_TRUE(QuicFramerPeer::AppendIetfAckFrameAndTypeByte(
1058 &framer_, transmit_frame, &writer));
1059
1060 uint8_t packet[] = {
1061 0x02, // type, IETF_ACK
1062 0x01, // largest_acked,
1063 0x00, // delay
1064 0x00, // count of additional ack blocks
1065 0x00, // size of first ack block (packets preceding largest_acked)
1066 };
1067 EXPECT_EQ(expected_size, sizeof(packet));
1068 EXPECT_EQ(sizeof(packet), writer.length());
1069 EXPECT_EQ(0, memcmp(packet, packet_buffer, writer.length()));
1070
1071 // Now set up a reader to read in the frame.
1072 QuicDataReader reader(packet_buffer, writer.length(), NETWORK_BYTE_ORDER);
1073
1074 // an AckFrame to hold the results
1075 QuicAckFrame receive_frame;
1076
1077 // read in the frame type
1078 uint8_t received_frame_type;
1079 EXPECT_TRUE(reader.ReadUInt8(&received_frame_type));
1080 EXPECT_EQ(received_frame_type, IETF_ACK);
1081
1082 EXPECT_TRUE(QuicFramerPeer::ProcessIetfAckFrame(&framer_, &reader, IETF_ACK,
1083 &receive_frame));
1084
1085 // Now check that the received frame matches the sent frame.
1086 EXPECT_EQ(transmit_frame.largest_acked, receive_frame.largest_acked);
1087}
1088
1089TEST_F(QuicIetfFramerTest, PathChallengeFrame) {
1090 // Double-braces needed on some platforms due to
1091 // https://bugs.llvm.org/show_bug.cgi?id=21629
1092 QuicPathFrameBuffer buffer0 = {{0, 0, 0, 0, 0, 0, 0, 0}};
1093 QuicPathFrameBuffer buffer1 = {
1094 {0x80, 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe5, 0xf7}};
1095 char packet_buffer[kNormalPacketBufferSize];
1096 EXPECT_TRUE(
1097 TryPathChallengeFrame(packet_buffer, sizeof(packet_buffer), buffer0));
1098 EXPECT_TRUE(
1099 TryPathChallengeFrame(packet_buffer, sizeof(packet_buffer), buffer1));
1100}
1101
1102TEST_F(QuicIetfFramerTest, PathResponseFrame) {
1103 // Double-braces needed on some platforms due to
1104 // https://bugs.llvm.org/show_bug.cgi?id=21629
1105 QuicPathFrameBuffer buffer0 = {{0, 0, 0, 0, 0, 0, 0, 0}};
1106 QuicPathFrameBuffer buffer1 = {
1107 {0x80, 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe5, 0xf7}};
1108 char packet_buffer[kNormalPacketBufferSize];
1109 EXPECT_TRUE(
1110 TryPathResponseFrame(packet_buffer, sizeof(packet_buffer), buffer0));
1111 EXPECT_TRUE(
1112 TryPathResponseFrame(packet_buffer, sizeof(packet_buffer), buffer1));
1113}
1114
1115TEST_F(QuicIetfFramerTest, ResetStreamFrame) {
1116 char packet_buffer[kNormalPacketBufferSize];
1117 struct resets {
1118 QuicStreamId stream_id;
1119 uint16_t error_code;
1120 QuicStreamOffset final_offset;
1121 } reset_frames[] = {
1122 {0, 55, 0},
1123 {0x10, 73, 0x300},
1124 };
1125 for (auto reset : reset_frames) {
1126 TryResetFrame(packet_buffer, sizeof(packet_buffer), reset.stream_id,
1127 reset.error_code, reset.final_offset);
1128 }
1129}
1130
1131TEST_F(QuicIetfFramerTest, StopSendingFrame) {
1132 char packet_buffer[kNormalPacketBufferSize];
1133
1134 // Make a writer so that the serialized packet is placed in
1135 // packet_buffer.
1136 QuicDataWriter writer(sizeof(packet_buffer), packet_buffer,
1137 NETWORK_BYTE_ORDER);
1138
1139 QuicStopSendingFrame transmit_frame;
1140 transmit_frame.stream_id = 12345;
1141 transmit_frame.application_error_code = 543;
1142
1143 // Write the frame to the packet buffer.
1144 EXPECT_TRUE(QuicFramerPeer::AppendStopSendingFrame(&framer_, transmit_frame,
1145 &writer));
1146 // Check that the number of bytes in the buffer is in the
1147 // allowed range.
1148 EXPECT_LE(3u, writer.length());
1149 EXPECT_GE(10u, writer.length());
1150
1151 QuicDataReader reader(packet_buffer, writer.length(), NETWORK_BYTE_ORDER);
1152
1153 // A frame to hold the results
1154 QuicStopSendingFrame receive_frame;
1155
1156 EXPECT_TRUE(QuicFramerPeer::ProcessStopSendingFrame(&framer_, &reader,
1157 &receive_frame));
1158
1159 // Verify that the transmitted and received values are the same.
1160 EXPECT_EQ(receive_frame.stream_id, 12345u);
1161 EXPECT_EQ(receive_frame.application_error_code, 543u);
1162 EXPECT_EQ(receive_frame.stream_id, transmit_frame.stream_id);
1163 EXPECT_EQ(receive_frame.application_error_code,
1164 transmit_frame.application_error_code);
1165}
1166
1167TEST_F(QuicIetfFramerTest, MaxDataFrame) {
1168 char packet_buffer[kNormalPacketBufferSize];
1169 QuicStreamOffset window_sizes[] = {0, 1, 2, 5, 10,
1170 20, 50, 100, 200, 500,
1171 1000000, kOffset8, kOffset4, kOffset2};
1172 for (QuicStreamOffset window_size : window_sizes) {
1173 memset(packet_buffer, 0, sizeof(packet_buffer));
1174
1175 // Set up the writer and transmit QuicWindowUpdateFrame
1176 QuicDataWriter writer(sizeof(packet_buffer), packet_buffer,
1177 NETWORK_BYTE_ORDER);
1178 QuicWindowUpdateFrame transmit_frame(0, 99, window_size);
1179
1180 // Add the frame.
1181 EXPECT_TRUE(
1182 QuicFramerPeer::AppendMaxDataFrame(&framer_, transmit_frame, &writer));
1183
1184 // Check that the number of bytes in the buffer is in the expected range.
1185 EXPECT_LE(1u, writer.length());
1186 EXPECT_GE(8u, writer.length());
1187
1188 // Set up reader and an empty QuicWindowUpdateFrame
1189 QuicDataReader reader(packet_buffer, writer.length(), NETWORK_BYTE_ORDER);
1190 QuicWindowUpdateFrame receive_frame;
1191
1192 // Deframe it
1193 EXPECT_TRUE(
1194 QuicFramerPeer::ProcessMaxDataFrame(&framer_, &reader, &receive_frame));
1195
1196 // Now check that the received data equals the sent data.
1197 EXPECT_EQ(transmit_frame.byte_offset, window_size);
1198 EXPECT_EQ(transmit_frame.byte_offset, receive_frame.byte_offset);
1199 EXPECT_EQ(QuicUtils::GetInvalidStreamId(framer_.transport_version()),
1200 receive_frame.stream_id);
1201 }
1202}
1203
1204TEST_F(QuicIetfFramerTest, MaxStreamDataFrame) {
1205 char packet_buffer[kNormalPacketBufferSize];
1206 QuicStreamOffset window_sizes[] = {0, 1, 2, 5, 10,
1207 20, 50, 100, 200, 500,
1208 1000000, kOffset8, kOffset4, kOffset2};
1209 QuicIetfStreamId stream_ids[] = {kStreamId4, kStreamId2, kStreamId1,
1210 kStreamId0};
1211
1212 for (QuicIetfStreamId stream_id : stream_ids) {
1213 for (QuicStreamOffset window_size : window_sizes) {
1214 memset(packet_buffer, 0, sizeof(packet_buffer));
1215
1216 // Set up the writer and transmit QuicWindowUpdateFrame
1217 QuicDataWriter writer(sizeof(packet_buffer), packet_buffer,
1218 NETWORK_BYTE_ORDER);
1219 QuicWindowUpdateFrame transmit_frame(0, stream_id, window_size);
1220
1221 // Add the frame.
1222 EXPECT_TRUE(QuicFramerPeer::AppendMaxStreamDataFrame(
1223 &framer_, transmit_frame, &writer));
1224
1225 // Check that number of bytes in the buffer is in the expected range.
1226 EXPECT_LE(2u, writer.length());
1227 EXPECT_GE(16u, writer.length());
1228
1229 // Set up reader and empty receive QuicPaddingFrame.
1230 QuicDataReader reader(packet_buffer, writer.length(), NETWORK_BYTE_ORDER);
1231 QuicWindowUpdateFrame receive_frame;
1232
1233 // Deframe it
1234 EXPECT_TRUE(QuicFramerPeer::ProcessMaxStreamDataFrame(&framer_, &reader,
1235 &receive_frame));
1236
1237 // Now check that received data and sent data are equal.
1238 EXPECT_EQ(transmit_frame.byte_offset, window_size);
1239 EXPECT_EQ(transmit_frame.byte_offset, receive_frame.byte_offset);
1240 EXPECT_EQ(stream_id, receive_frame.stream_id);
1241 EXPECT_EQ(transmit_frame.stream_id, receive_frame.stream_id);
1242 }
1243 }
1244}
1245
1246TEST_F(QuicIetfFramerTest, MaxStreamsFrame) {
fkastenholz3c4eabf2019-04-22 07:49:59 -07001247 QuicStreamCount stream_counts[] = {0x3fffffff, 0x3fff, 0x3f, 0x1};
QUICHE teama6ef0a62019-03-07 20:34:33 -05001248
fkastenholz3c4eabf2019-04-22 07:49:59 -07001249 for (QuicStreamCount stream_count : stream_counts) {
QUICHE teama6ef0a62019-03-07 20:34:33 -05001250 // Cover all four combinations of uni/bi-directional and
1251 // server-/client- initiation.
fkastenholz3c4eabf2019-04-22 07:49:59 -07001252 TryMaxStreamsFrame(stream_count, /*unidirectional=*/true,
QUICHE teama6ef0a62019-03-07 20:34:33 -05001253 /*stream_id_server_initiated=*/true);
fkastenholz3c4eabf2019-04-22 07:49:59 -07001254 TryMaxStreamsFrame(stream_count, /*unidirectional=*/true,
QUICHE teama6ef0a62019-03-07 20:34:33 -05001255 /*stream_id_server_initiated=*/false);
fkastenholz3c4eabf2019-04-22 07:49:59 -07001256 TryMaxStreamsFrame(stream_count, /*unidirectional=*/false,
QUICHE teama6ef0a62019-03-07 20:34:33 -05001257 /*stream_id_server_initiated=*/true);
fkastenholz3c4eabf2019-04-22 07:49:59 -07001258 TryMaxStreamsFrame(stream_count, /*unidirectional=*/false,
QUICHE teama6ef0a62019-03-07 20:34:33 -05001259 /*stream_id_server_initiated=*/false);
1260 }
1261}
1262
1263TEST_F(QuicIetfFramerTest, BlockedFrame) {
1264 char packet_buffer[kNormalPacketBufferSize];
1265 QuicStreamOffset offsets[] = {kOffset8, kOffset4, kOffset2, kOffset1,
1266 kOffset0};
1267
1268 for (QuicStreamOffset offset : offsets) {
1269 memset(packet_buffer, 0, sizeof(packet_buffer));
1270
1271 // Set up the writer and transmit QuicBlockedFrame
1272 QuicDataWriter writer(sizeof(packet_buffer), packet_buffer,
1273 NETWORK_BYTE_ORDER);
1274 QuicBlockedFrame transmit_frame(
1275 0, QuicUtils::GetInvalidStreamId(framer_.transport_version()), offset);
1276
1277 // Add the frame.
1278 EXPECT_TRUE(QuicFramerPeer::AppendIetfBlockedFrame(&framer_, transmit_frame,
1279 &writer));
1280
1281 // Check that buffer length is in the expected range
1282 EXPECT_LE(1u, writer.length());
1283 EXPECT_GE(8u, writer.length());
1284
1285 // Set up reader and empty receive QuicFrame.
1286 QuicDataReader reader(packet_buffer, writer.length(), NETWORK_BYTE_ORDER);
1287 QuicBlockedFrame receive_frame;
1288
1289 // Deframe it
1290 EXPECT_TRUE(QuicFramerPeer::ProcessIetfBlockedFrame(&framer_, &reader,
1291 &receive_frame));
1292
1293 // Check that received and sent data are equivalent
1294 EXPECT_EQ(QuicUtils::GetInvalidStreamId(framer_.transport_version()),
1295 receive_frame.stream_id);
1296 EXPECT_EQ(offset, receive_frame.offset);
1297 EXPECT_EQ(transmit_frame.offset, receive_frame.offset);
1298 }
1299}
1300
1301TEST_F(QuicIetfFramerTest, StreamBlockedFrame) {
1302 char packet_buffer[kNormalPacketBufferSize];
1303 QuicStreamOffset offsets[] = {0, 1, 2, 5, 10,
1304 20, 50, 100, 200, 500,
1305 1000000, kOffset8, kOffset4, kOffset2};
1306 QuicIetfStreamId stream_ids[] = {kStreamId4, kStreamId2, kStreamId1,
1307 kStreamId0};
1308
1309 for (QuicIetfStreamId stream_id : stream_ids) {
1310 for (QuicStreamOffset offset : offsets) {
1311 memset(packet_buffer, 0, sizeof(packet_buffer));
1312
1313 // Set up the writer and transmit QuicWindowUpdateFrame
1314 QuicDataWriter writer(sizeof(packet_buffer), packet_buffer,
1315 NETWORK_BYTE_ORDER);
1316 QuicBlockedFrame transmit_frame(0, stream_id, offset);
1317
1318 // Add the frame.
1319 EXPECT_TRUE(QuicFramerPeer::AppendStreamBlockedFrame(
1320 &framer_, transmit_frame, &writer));
1321
1322 // Check that number of bytes in the buffer is in the expected range.
1323 EXPECT_LE(2u, writer.length());
1324 EXPECT_GE(16u, writer.length());
1325
1326 // Set up reader and empty receive QuicPaddingFrame.
1327 QuicDataReader reader(packet_buffer, writer.length(), NETWORK_BYTE_ORDER);
1328 QuicBlockedFrame receive_frame;
1329
1330 // Deframe it
1331 EXPECT_TRUE(QuicFramerPeer::ProcessStreamBlockedFrame(&framer_, &reader,
1332 &receive_frame));
1333
1334 // Now check that received == sent
1335 EXPECT_EQ(transmit_frame.offset, offset);
1336 EXPECT_EQ(transmit_frame.offset, receive_frame.offset);
1337 EXPECT_EQ(stream_id, receive_frame.stream_id);
1338 EXPECT_EQ(transmit_frame.stream_id, receive_frame.stream_id);
1339 }
1340 }
1341}
1342
1343TEST_F(QuicIetfFramerTest, StreamsBlockedFrame) {
fkastenholz3c4eabf2019-04-22 07:49:59 -07001344 QuicStreamCount stream_counts[] = {0x3fffffff, 0x3fff, 0x3f, 0x1};
QUICHE teama6ef0a62019-03-07 20:34:33 -05001345
fkastenholz3c4eabf2019-04-22 07:49:59 -07001346 for (QuicStreamCount stream_count : stream_counts) {
1347 TryStreamsBlockedFrame(stream_count,
QUICHE teama6ef0a62019-03-07 20:34:33 -05001348 /*unidirectional=*/false,
1349 /*stream_id_server_initiated=*/false);
fkastenholz3c4eabf2019-04-22 07:49:59 -07001350 TryStreamsBlockedFrame(stream_count,
QUICHE teama6ef0a62019-03-07 20:34:33 -05001351 /*unidirectional=*/false,
1352 /*stream_id_server_initiated=*/true);
fkastenholz3c4eabf2019-04-22 07:49:59 -07001353 TryStreamsBlockedFrame(stream_count,
QUICHE teama6ef0a62019-03-07 20:34:33 -05001354 /*unidirectional=*/true,
1355 /*stream_id_server_initiated=*/false);
fkastenholz3c4eabf2019-04-22 07:49:59 -07001356 TryStreamsBlockedFrame(stream_count,
QUICHE teama6ef0a62019-03-07 20:34:33 -05001357 /*unidirectional=*/true,
1358 /*stream_id_server_initiated=*/true);
1359 }
1360}
1361
1362TEST_F(QuicIetfFramerTest, NewConnectionIdFrame) {
1363 char packet_buffer[kNormalPacketBufferSize];
1364
1365 QuicNewConnectionIdFrame transmit_frame;
1366 transmit_frame.connection_id = TestConnectionId(UINT64_C(0x0edcba9876543201));
1367 transmit_frame.sequence_number = 0x01020304;
1368 // The token is defined as a uint128 -- a 16-byte integer.
1369 // The value is set in this manner because we want each
1370 // byte to have a specific value so that the binary
1371 // packet check (below) is good. If we used integer
1372 // operations (eg. "token = 0x12345...") then the bytes
1373 // would be set in host order.
1374 unsigned char token_bytes[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
1375 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
1376 0x0c, 0x0d, 0x0e, 0x0f};
1377 memcpy(&transmit_frame.stateless_reset_token, token_bytes,
1378 sizeof(transmit_frame.stateless_reset_token));
1379
1380 memset(packet_buffer, 0, sizeof(packet_buffer));
1381
fkastenholz3c4eabf2019-04-22 07:49:59 -07001382 // Set up the writer and transmit a QuicNewConnectionIdFrame
QUICHE teama6ef0a62019-03-07 20:34:33 -05001383 QuicDataWriter writer(sizeof(packet_buffer), packet_buffer,
1384 NETWORK_BYTE_ORDER);
1385
1386 // Add the frame.
1387 EXPECT_TRUE(QuicFramerPeer::AppendNewConnectionIdFrame(
1388 &framer_, transmit_frame, &writer));
1389 // Check that buffer length is correct
1390 EXPECT_EQ(29u, writer.length());
1391 // clang-format off
1392 uint8_t packet[] = {
1393 // sequence number, 0x80 for varint62 encoding
1394 0x80 + 0x01, 0x02, 0x03, 0x04,
1395 // new connection id length, is not varint62 encoded.
1396 0x08,
1397 // new connection id, is not varint62 encoded.
1398 0x0E, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x01,
1399 // the reset token:
1400 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1401 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
1402 };
1403
1404 // clang-format on
1405 EXPECT_EQ(0, memcmp(packet_buffer, packet, sizeof(packet)));
1406
1407 // Set up reader and empty receive QuicPaddingFrame.
1408 QuicDataReader reader(packet_buffer, writer.length(), NETWORK_BYTE_ORDER);
1409 QuicNewConnectionIdFrame receive_frame;
1410
1411 // Deframe it
1412 EXPECT_TRUE(QuicFramerPeer::ProcessNewConnectionIdFrame(&framer_, &reader,
1413 &receive_frame));
1414
1415 // Now check that received == sent
1416 EXPECT_EQ(transmit_frame.connection_id, receive_frame.connection_id);
1417 EXPECT_EQ(transmit_frame.sequence_number, receive_frame.sequence_number);
1418 EXPECT_EQ(transmit_frame.stateless_reset_token,
1419 receive_frame.stateless_reset_token);
1420}
1421
1422TEST_F(QuicIetfFramerTest, RetireConnectionIdFrame) {
1423 char packet_buffer[kNormalPacketBufferSize];
1424
1425 QuicRetireConnectionIdFrame transmit_frame;
1426 transmit_frame.sequence_number = 0x01020304;
1427
1428 memset(packet_buffer, 0, sizeof(packet_buffer));
1429
fkastenholz3c4eabf2019-04-22 07:49:59 -07001430 // Set up the writer and transmit QuicRetireConnectionIdFrame
QUICHE teama6ef0a62019-03-07 20:34:33 -05001431 QuicDataWriter writer(sizeof(packet_buffer), packet_buffer,
1432 NETWORK_BYTE_ORDER);
1433
1434 // Add the frame.
1435 EXPECT_TRUE(QuicFramerPeer::AppendRetireConnectionIdFrame(
1436 &framer_, transmit_frame, &writer));
1437 // Check that buffer length is correct
1438 EXPECT_EQ(4u, writer.length());
1439 // clang-format off
1440 uint8_t packet[] = {
1441 // sequence number, 0x80 for varint62 encoding
1442 0x80 + 0x01, 0x02, 0x03, 0x04,
1443 };
1444
1445 // clang-format on
1446 EXPECT_EQ(0, memcmp(packet_buffer, packet, sizeof(packet)));
1447
1448 // Set up reader and empty receive QuicPaddingFrame.
1449 QuicDataReader reader(packet_buffer, writer.length(), NETWORK_BYTE_ORDER);
1450 QuicRetireConnectionIdFrame receive_frame;
1451
1452 // Deframe it
1453 EXPECT_TRUE(QuicFramerPeer::ProcessRetireConnectionIdFrame(&framer_, &reader,
1454 &receive_frame));
1455
1456 // Now check that received == sent
1457 EXPECT_EQ(transmit_frame.sequence_number, receive_frame.sequence_number);
1458}
1459
1460} // namespace
1461} // namespace test
1462} // namespace quic