blob: 1f7759db7a1adb8982f139f9735afab62651bae8 [file] [log] [blame]
[email protected]8b37a092012-10-18 21:53:491// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "net/quic/test_tools/quic_test_utils.h"
[email protected]9c0b1352012-11-04 00:03:276
[email protected]701bc892013-01-17 04:51:547#include "base/stl_util.h"
[email protected]b12764d2013-12-02 22:28:308#include "base/strings/string_number_conversions.h"
[email protected]8b37a092012-10-18 21:53:499#include "net/quic/crypto/crypto_framer.h"
[email protected]6f54ab32013-03-02 17:43:3510#include "net/quic/crypto/crypto_handshake.h"
[email protected]872edd9e2013-01-16 08:51:1511#include "net/quic/crypto/crypto_utils.h"
[email protected]5351cc4b2013-03-03 07:22:4112#include "net/quic/crypto/null_encrypter.h"
[email protected]4df69842013-02-27 06:32:1613#include "net/quic/crypto/quic_decrypter.h"
14#include "net/quic/crypto/quic_encrypter.h"
[email protected]a57e0272013-04-26 07:31:4715#include "net/quic/quic_framer.h"
[email protected]5351cc4b2013-03-03 07:22:4116#include "net/quic/quic_packet_creator.h"
[email protected]79d13dcb2014-02-05 07:23:1317#include "net/quic/quic_utils.h"
[email protected]cbd731e2013-10-24 00:20:3918#include "net/quic/test_tools/quic_connection_peer.h"
[email protected]c244c5a12013-05-07 20:55:0419#include "net/spdy/spdy_frame_builder.h"
[email protected]8b37a092012-10-18 21:53:4920
[email protected]c244c5a12013-05-07 20:55:0421using base::StringPiece;
[email protected]8b37a092012-10-18 21:53:4922using std::max;
23using std::min;
24using std::string;
[email protected]cff7b7b2013-01-11 08:49:0725using testing::_;
[email protected]64c12232014-03-26 05:43:5926using testing::AnyNumber;
[email protected]8b37a092012-10-18 21:53:4927
28namespace net {
29namespace test {
[email protected]965dbe62013-08-09 21:34:3130namespace {
31
32// No-op alarm implementation used by MockHelper.
33class TestAlarm : public QuicAlarm {
34 public:
35 explicit TestAlarm(QuicAlarm::Delegate* delegate)
36 : QuicAlarm(delegate) {
37 }
38
39 virtual void SetImpl() OVERRIDE {}
40 virtual void CancelImpl() OVERRIDE {}
41};
42
43} // namespace
[email protected]8b37a092012-10-18 21:53:4944
[email protected]fb35b0a2014-04-15 21:06:4945QuicAckFrame MakeAckFrame(QuicPacketSequenceNumber largest_observed,
46 QuicPacketSequenceNumber least_unacked) {
47 QuicAckFrame ack;
48 ack.received_info.largest_observed = largest_observed;
49 ack.received_info.entropy_hash = 0;
50 ack.sent_info.least_unacked = least_unacked;
51 ack.sent_info.entropy_hash = 0;
52 return ack;
53}
54
[email protected]aa7e4ef2014-05-28 03:53:1555QuicAckFrame MakeAckFrameWithNackRanges(
56 size_t num_nack_ranges, QuicPacketSequenceNumber least_unacked) {
57 QuicAckFrame ack = MakeAckFrame(2 * num_nack_ranges + least_unacked,
58 least_unacked);
59 // Add enough missing packets to get num_nack_ranges nack ranges.
60 for (QuicPacketSequenceNumber i = 1; i < 2 * num_nack_ranges; i += 2) {
61 ack.received_info.missing_packets.insert(least_unacked + i);
62 }
63 return ack;
64}
65
[email protected]8b37a092012-10-18 21:53:4966MockFramerVisitor::MockFramerVisitor() {
67 // By default, we want to accept packets.
[email protected]14e8106c2013-03-14 16:25:3368 ON_CALL(*this, OnProtocolVersionMismatch(_))
69 .WillByDefault(testing::Return(false));
70
71 // By default, we want to accept packets.
[email protected]ec86d5462013-11-17 16:04:4972 ON_CALL(*this, OnUnauthenticatedHeader(_))
73 .WillByDefault(testing::Return(true));
74
[email protected]066d8182014-01-04 02:02:4575 ON_CALL(*this, OnUnauthenticatedPublicHeader(_))
76 .WillByDefault(testing::Return(true));
77
[email protected]cff7b7b2013-01-11 08:49:0778 ON_CALL(*this, OnPacketHeader(_))
[email protected]8b37a092012-10-18 21:53:4979 .WillByDefault(testing::Return(true));
[email protected]a57e0272013-04-26 07:31:4780
81 ON_CALL(*this, OnStreamFrame(_))
82 .WillByDefault(testing::Return(true));
83
84 ON_CALL(*this, OnAckFrame(_))
85 .WillByDefault(testing::Return(true));
86
87 ON_CALL(*this, OnCongestionFeedbackFrame(_))
88 .WillByDefault(testing::Return(true));
89
[email protected]93dd91f2014-02-27 00:09:0390 ON_CALL(*this, OnStopWaitingFrame(_))
91 .WillByDefault(testing::Return(true));
92
[email protected]d8c522112014-04-23 09:23:2593 ON_CALL(*this, OnPingFrame(_))
94 .WillByDefault(testing::Return(true));
95
[email protected]a57e0272013-04-26 07:31:4796 ON_CALL(*this, OnRstStreamFrame(_))
97 .WillByDefault(testing::Return(true));
98
99 ON_CALL(*this, OnConnectionCloseFrame(_))
100 .WillByDefault(testing::Return(true));
101
102 ON_CALL(*this, OnGoAwayFrame(_))
103 .WillByDefault(testing::Return(true));
[email protected]8b37a092012-10-18 21:53:49104}
105
[email protected]044ac2b2012-11-13 21:41:06106MockFramerVisitor::~MockFramerVisitor() {
107}
[email protected]8b37a092012-10-18 21:53:49108
[email protected]48878092013-07-26 14:51:56109bool NoOpFramerVisitor::OnProtocolVersionMismatch(QuicVersion version) {
[email protected]14e8106c2013-03-14 16:25:33110 return false;
111}
112
[email protected]066d8182014-01-04 02:02:45113bool NoOpFramerVisitor::OnUnauthenticatedPublicHeader(
114 const QuicPacketPublicHeader& header) {
115 return true;
116}
117
[email protected]ec86d5462013-11-17 16:04:49118bool NoOpFramerVisitor::OnUnauthenticatedHeader(
119 const QuicPacketHeader& header) {
120 return true;
121}
122
[email protected]8b37a092012-10-18 21:53:49123bool NoOpFramerVisitor::OnPacketHeader(const QuicPacketHeader& header) {
124 return true;
125}
126
[email protected]a57e0272013-04-26 07:31:47127bool NoOpFramerVisitor::OnStreamFrame(const QuicStreamFrame& frame) {
128 return true;
129}
130
131bool NoOpFramerVisitor::OnAckFrame(const QuicAckFrame& frame) {
132 return true;
133}
134
135bool NoOpFramerVisitor::OnCongestionFeedbackFrame(
136 const QuicCongestionFeedbackFrame& frame) {
137 return true;
138}
139
[email protected]93dd91f2014-02-27 00:09:03140bool NoOpFramerVisitor::OnStopWaitingFrame(
141 const QuicStopWaitingFrame& frame) {
142 return true;
143}
144
[email protected]d8c522112014-04-23 09:23:25145bool NoOpFramerVisitor::OnPingFrame(const QuicPingFrame& frame) {
146 return true;
147}
148
[email protected]a57e0272013-04-26 07:31:47149bool NoOpFramerVisitor::OnRstStreamFrame(
150 const QuicRstStreamFrame& frame) {
151 return true;
152}
153
154bool NoOpFramerVisitor::OnConnectionCloseFrame(
155 const QuicConnectionCloseFrame& frame) {
156 return true;
157}
158
159bool NoOpFramerVisitor::OnGoAwayFrame(const QuicGoAwayFrame& frame) {
160 return true;
161}
162
[email protected]cb23a922014-02-20 17:42:38163bool NoOpFramerVisitor::OnWindowUpdateFrame(
164 const QuicWindowUpdateFrame& frame) {
165 return true;
166}
167
168bool NoOpFramerVisitor::OnBlockedFrame(const QuicBlockedFrame& frame) {
169 return true;
170}
171
[email protected]8d659e22013-01-19 04:26:10172MockConnectionVisitor::MockConnectionVisitor() {
173}
174
175MockConnectionVisitor::~MockConnectionVisitor() {
176}
177
[email protected]9c0b1352012-11-04 00:03:27178MockHelper::MockHelper() {
179}
180
181MockHelper::~MockHelper() {
182}
183
[email protected]97693d12012-11-16 16:05:00184const QuicClock* MockHelper::GetClock() const {
[email protected]9c0b1352012-11-04 00:03:27185 return &clock_;
186}
187
[email protected]9558c5d32012-12-22 00:08:14188QuicRandom* MockHelper::GetRandomGenerator() {
189 return &random_generator_;
190}
191
[email protected]965dbe62013-08-09 21:34:31192QuicAlarm* MockHelper::CreateAlarm(QuicAlarm::Delegate* delegate) {
193 return new TestAlarm(delegate);
194}
195
[email protected]fe053f92013-04-23 20:18:55196void MockHelper::AdvanceTime(QuicTime::Delta delta) {
197 clock_.AdvanceTime(delta);
198}
199
[email protected]c05a6d222013-12-16 19:42:03200MockConnection::MockConnection(bool is_server)
[email protected]3aa9ca72014-02-27 19:39:43201 : QuicConnection(kTestConnectionId,
[email protected]300ccd52014-01-25 08:00:19202 IPEndPoint(TestPeerIPAddress(), kTestPort),
[email protected]c05a6d222013-12-16 19:42:03203 new testing::NiceMock<MockHelper>(),
[email protected]cbd731e2013-10-24 00:20:39204 new testing::NiceMock<MockPacketWriter>(),
[email protected]ce7bb1412014-05-17 15:51:33205 is_server, QuicSupportedVersions()),
[email protected]c05a6d222013-12-16 19:42:03206 writer_(QuicConnectionPeer::GetWriter(this)),
207 helper_(helper()) {
208}
209
210MockConnection::MockConnection(IPEndPoint address,
211 bool is_server)
[email protected]3aa9ca72014-02-27 19:39:43212 : QuicConnection(kTestConnectionId, address,
[email protected]c05a6d222013-12-16 19:42:03213 new testing::NiceMock<MockHelper>(),
214 new testing::NiceMock<MockPacketWriter>(),
[email protected]ce7bb1412014-05-17 15:51:33215 is_server, QuicSupportedVersions()),
[email protected]2cfc6bb82013-10-27 03:40:44216 writer_(QuicConnectionPeer::GetWriter(this)),
217 helper_(helper()) {
[email protected]044ac2b2012-11-13 21:41:06218}
219
[email protected]3aa9ca72014-02-27 19:39:43220MockConnection::MockConnection(QuicConnectionId connection_id,
[email protected]14e8106c2013-03-14 16:25:33221 bool is_server)
[email protected]3aa9ca72014-02-27 19:39:43222 : QuicConnection(connection_id,
223 IPEndPoint(TestPeerIPAddress(), kTestPort),
[email protected]c05a6d222013-12-16 19:42:03224 new testing::NiceMock<MockHelper>(),
225 new testing::NiceMock<MockPacketWriter>(),
[email protected]ce7bb1412014-05-17 15:51:33226 is_server, QuicSupportedVersions()),
[email protected]c05a6d222013-12-16 19:42:03227 writer_(QuicConnectionPeer::GetWriter(this)),
228 helper_(helper()) {
[email protected]872edd9e2013-01-16 08:51:15229}
230
[email protected]4d640792013-12-18 22:21:08231MockConnection::MockConnection(bool is_server,
232 const QuicVersionVector& supported_versions)
[email protected]3aa9ca72014-02-27 19:39:43233 : QuicConnection(kTestConnectionId,
[email protected]300ccd52014-01-25 08:00:19234 IPEndPoint(TestPeerIPAddress(), kTestPort),
[email protected]4d640792013-12-18 22:21:08235 new testing::NiceMock<MockHelper>(),
236 new testing::NiceMock<MockPacketWriter>(),
[email protected]ce7bb1412014-05-17 15:51:33237 is_server, supported_versions),
[email protected]4d640792013-12-18 22:21:08238 writer_(QuicConnectionPeer::GetWriter(this)),
239 helper_(helper()) {
240}
241
[email protected]044ac2b2012-11-13 21:41:06242MockConnection::~MockConnection() {
243}
244
[email protected]fe053f92013-04-23 20:18:55245void MockConnection::AdvanceTime(QuicTime::Delta delta) {
[email protected]fe053f92013-04-23 20:18:55246 static_cast<MockHelper*>(helper())->AdvanceTime(delta);
247}
248
[email protected]c05a6d222013-12-16 19:42:03249PacketSavingConnection::PacketSavingConnection(bool is_server)
250 : MockConnection(is_server) {
[email protected]044ac2b2012-11-13 21:41:06251}
252
[email protected]4d640792013-12-18 22:21:08253PacketSavingConnection::PacketSavingConnection(
254 bool is_server,
255 const QuicVersionVector& supported_versions)
256 : MockConnection(is_server, supported_versions) {
257}
258
[email protected]044ac2b2012-11-13 21:41:06259PacketSavingConnection::~PacketSavingConnection() {
[email protected]701bc892013-01-17 04:51:54260 STLDeleteElements(&packets_);
[email protected]2532de12013-05-09 12:29:33261 STLDeleteElements(&encrypted_packets_);
[email protected]044ac2b2012-11-13 21:41:06262}
263
[email protected]fee17f72013-02-03 07:47:41264bool PacketSavingConnection::SendOrQueuePacket(
[email protected]8ba81212013-05-03 13:11:48265 EncryptionLevel level,
[email protected]ec86d5462013-11-17 16:04:49266 const SerializedPacket& packet,
267 TransmissionType transmission_type) {
268 packets_.push_back(packet.packet);
[email protected]c5e1aca2014-01-30 04:03:04269 QuicEncryptedPacket* encrypted = QuicConnectionPeer::GetFramer(this)->
270 EncryptPacket(level, packet.sequence_number, *packet.packet);
[email protected]2532de12013-05-09 12:29:33271 encrypted_packets_.push_back(encrypted);
[email protected]044ac2b2012-11-13 21:41:06272 return true;
273}
274
[email protected]c05a6d222013-12-16 19:42:03275MockSession::MockSession(QuicConnection* connection)
[email protected]ce7bb1412014-05-17 15:51:33276 : QuicSession(connection, kInitialFlowControlWindowForTest,
277 DefaultQuicConfig()) {
[email protected]93dd91f2014-02-27 00:09:03278 ON_CALL(*this, WritevData(_, _, _, _, _))
[email protected]cff7b7b2013-01-11 08:49:07279 .WillByDefault(testing::Return(QuicConsumedData(0, false)));
[email protected]044ac2b2012-11-13 21:41:06280}
281
282MockSession::~MockSession() {
283}
284
[email protected]ce7bb1412014-05-17 15:51:33285TestSession::TestSession(QuicConnection* connection, const QuicConfig& config)
286 : QuicSession(connection, kInitialFlowControlWindowForTest, config),
287 crypto_stream_(NULL) {}
[email protected]2532de12013-05-09 12:29:33288
[email protected]b064310782013-05-30 21:12:17289TestSession::~TestSession() {}
[email protected]2532de12013-05-09 12:29:33290
291void TestSession::SetCryptoStream(QuicCryptoStream* stream) {
292 crypto_stream_ = stream;
293}
294
295QuicCryptoStream* TestSession::GetCryptoStream() {
296 return crypto_stream_;
297}
298
[email protected]90f62f092014-03-24 02:41:23299TestClientSession::TestClientSession(QuicConnection* connection,
300 const QuicConfig& config)
[email protected]ce7bb1412014-05-17 15:51:33301 : QuicClientSessionBase(connection, kInitialFlowControlWindowForTest,
302 config),
[email protected]90f62f092014-03-24 02:41:23303 crypto_stream_(NULL) {
[email protected]64c12232014-03-26 05:43:59304 EXPECT_CALL(*this, OnProofValid(_)).Times(AnyNumber());
[email protected]90f62f092014-03-24 02:41:23305}
306
307TestClientSession::~TestClientSession() {}
308
309void TestClientSession::SetCryptoStream(QuicCryptoStream* stream) {
310 crypto_stream_ = stream;
311}
312
313QuicCryptoStream* TestClientSession::GetCryptoStream() {
314 return crypto_stream_;
315}
316
[email protected]cbd731e2013-10-24 00:20:39317MockPacketWriter::MockPacketWriter() {
318}
319
320MockPacketWriter::~MockPacketWriter() {
321}
322
[email protected]fee17f72013-02-03 07:47:41323MockSendAlgorithm::MockSendAlgorithm() {
[email protected]8d659e22013-01-19 04:26:10324}
325
[email protected]fee17f72013-02-03 07:47:41326MockSendAlgorithm::~MockSendAlgorithm() {
[email protected]8d659e22013-01-19 04:26:10327}
328
[email protected]3aa9ca72014-02-27 19:39:43329MockLossAlgorithm::MockLossAlgorithm() {
330}
331
332MockLossAlgorithm::~MockLossAlgorithm() {
333}
334
[email protected]97cf3022013-09-05 14:30:16335MockAckNotifierDelegate::MockAckNotifierDelegate() {
336}
337
338MockAckNotifierDelegate::~MockAckNotifierDelegate() {
339}
340
[email protected]8b37a092012-10-18 21:53:49341namespace {
342
343string HexDumpWithMarks(const char* data, int length,
344 const bool* marks, int mark_length) {
345 static const char kHexChars[] = "0123456789abcdef";
346 static const int kColumns = 4;
347
348 const int kSizeLimit = 1024;
349 if (length > kSizeLimit || mark_length > kSizeLimit) {
350 LOG(ERROR) << "Only dumping first " << kSizeLimit << " bytes.";
351 length = min(length, kSizeLimit);
352 mark_length = min(mark_length, kSizeLimit);
353 }
354
355 string hex;
356 for (const char* row = data; length > 0;
357 row += kColumns, length -= kColumns) {
358 for (const char *p = row; p < row + 4; ++p) {
359 if (p < row + length) {
360 const bool mark =
361 (marks && (p - data) < mark_length && marks[p - data]);
362 hex += mark ? '*' : ' ';
363 hex += kHexChars[(*p & 0xf0) >> 4];
364 hex += kHexChars[*p & 0x0f];
365 hex += mark ? '*' : ' ';
366 } else {
367 hex += " ";
368 }
369 }
370 hex = hex + " ";
371
372 for (const char *p = row; p < row + 4 && p < row + length; ++p)
373 hex += (*p >= 0x20 && *p <= 0x7f) ? (*p) : '.';
374
375 hex = hex + '\n';
376 }
377 return hex;
378}
379
380} // namespace
381
[email protected]300ccd52014-01-25 08:00:19382IPAddressNumber TestPeerIPAddress() { return Loopback4(); }
383
[email protected]b007e632013-10-28 08:39:25384QuicVersion QuicVersionMax() { return QuicSupportedVersions().front(); }
385
386QuicVersion QuicVersionMin() { return QuicSupportedVersions().back(); }
387
[email protected]c05a6d222013-12-16 19:42:03388IPAddressNumber Loopback4() {
[email protected]300ccd52014-01-25 08:00:19389 IPAddressNumber addr;
390 CHECK(ParseIPLiteralToNumber("127.0.0.1", &addr));
[email protected]c05a6d222013-12-16 19:42:03391 return addr;
392}
393
[email protected]9bb57c72014-03-31 20:36:04394void GenerateBody(string* body, int length) {
395 body->clear();
396 body->reserve(length);
397 for (int i = 0; i < length; ++i) {
398 body->append(1, static_cast<char>(32 + i % (126 - 32)));
399 }
400}
401
[email protected]ffc34bf2014-03-07 02:42:02402QuicEncryptedPacket* ConstructEncryptedPacket(
403 QuicConnectionId connection_id,
404 bool version_flag,
405 bool reset_flag,
406 QuicPacketSequenceNumber sequence_number,
407 const string& data) {
408 QuicPacketHeader header;
409 header.public_header.connection_id = connection_id;
410 header.public_header.connection_id_length = PACKET_8BYTE_CONNECTION_ID;
411 header.public_header.version_flag = version_flag;
412 header.public_header.reset_flag = reset_flag;
413 header.public_header.sequence_number_length = PACKET_6BYTE_SEQUENCE_NUMBER;
414 header.packet_sequence_number = sequence_number;
415 header.entropy_flag = false;
416 header.entropy_hash = 0;
417 header.fec_flag = false;
418 header.is_in_fec_group = NOT_IN_FEC_GROUP;
419 header.fec_group = 0;
420 QuicStreamFrame stream_frame(1, false, 0, MakeIOVector(data));
421 QuicFrame frame(&stream_frame);
422 QuicFrames frames;
423 frames.push_back(frame);
424 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), false);
425 scoped_ptr<QuicPacket> packet(
426 framer.BuildUnsizedDataPacket(header, frames).packet);
427 EXPECT_TRUE(packet != NULL);
428 QuicEncryptedPacket* encrypted = framer.EncryptPacket(ENCRYPTION_NONE,
429 sequence_number,
430 *packet);
431 EXPECT_TRUE(encrypted != NULL);
432 return encrypted;
433}
434
[email protected]8b37a092012-10-18 21:53:49435void CompareCharArraysWithHexError(
436 const string& description,
437 const char* actual,
438 const int actual_len,
439 const char* expected,
440 const int expected_len) {
[email protected]b007e632013-10-28 08:39:25441 EXPECT_EQ(actual_len, expected_len);
[email protected]8b37a092012-10-18 21:53:49442 const int min_len = min(actual_len, expected_len);
443 const int max_len = max(actual_len, expected_len);
[email protected]4356f0f2013-04-07 00:58:17444 scoped_ptr<bool[]> marks(new bool[max_len]);
[email protected]8b37a092012-10-18 21:53:49445 bool identical = (actual_len == expected_len);
446 for (int i = 0; i < min_len; ++i) {
447 if (actual[i] != expected[i]) {
448 marks[i] = true;
449 identical = false;
450 } else {
451 marks[i] = false;
452 }
453 }
454 for (int i = min_len; i < max_len; ++i) {
455 marks[i] = true;
456 }
457 if (identical) return;
458 ADD_FAILURE()
459 << "Description:\n"
460 << description
461 << "\n\nExpected:\n"
462 << HexDumpWithMarks(expected, expected_len, marks.get(), max_len)
463 << "\nActual:\n"
464 << HexDumpWithMarks(actual, actual_len, marks.get(), max_len);
465}
466
[email protected]b12764d2013-12-02 22:28:30467bool DecodeHexString(const base::StringPiece& hex, std::string* bytes) {
468 bytes->clear();
469 if (hex.empty())
470 return true;
471 std::vector<uint8> v;
472 if (!base::HexStringToBytes(hex.as_string(), &v))
473 return false;
474 if (!v.empty())
475 bytes->assign(reinterpret_cast<const char*>(&v[0]), v.size());
476 return true;
477}
478
[email protected]d3d15bf2013-01-30 02:51:54479static QuicPacket* ConstructPacketFromHandshakeMessage(
[email protected]3aa9ca72014-02-27 19:39:43480 QuicConnectionId connection_id,
[email protected]14e8106c2013-03-14 16:25:33481 const CryptoHandshakeMessage& message,
482 bool should_include_version) {
[email protected]8b37a092012-10-18 21:53:49483 CryptoFramer crypto_framer;
[email protected]dc2cc742012-10-21 13:56:13484 scoped_ptr<QuicData> data(crypto_framer.ConstructHandshakeMessage(message));
[email protected]b007e632013-10-28 08:39:25485 QuicFramer quic_framer(QuicSupportedVersions(), QuicTime::Zero(), false);
[email protected]8b37a092012-10-18 21:53:49486
487 QuicPacketHeader header;
[email protected]3aa9ca72014-02-27 19:39:43488 header.public_header.connection_id = connection_id;
[email protected]9db443912013-02-25 05:27:03489 header.public_header.reset_flag = false;
[email protected]14e8106c2013-03-14 16:25:33490 header.public_header.version_flag = should_include_version;
[email protected]8b37a092012-10-18 21:53:49491 header.packet_sequence_number = 1;
[email protected]9db443912013-02-25 05:27:03492 header.entropy_flag = false;
493 header.entropy_hash = 0;
494 header.fec_flag = false;
[email protected]8b37a092012-10-18 21:53:49495 header.fec_group = 0;
496
[email protected]be24ab22012-10-22 03:01:52497 QuicStreamFrame stream_frame(kCryptoStreamId, false, 0,
[email protected]5dafdb62013-11-14 01:24:26498 MakeIOVector(data->AsStringPiece()));
[email protected]8b37a092012-10-18 21:53:49499
[email protected]be24ab22012-10-22 03:01:52500 QuicFrame frame(&stream_frame);
501 QuicFrames frames;
502 frames.push_back(frame);
[email protected]3e60db82013-08-05 19:43:06503 return quic_framer.BuildUnsizedDataPacket(header, frames).packet;
[email protected]8b37a092012-10-18 21:53:49504}
505
[email protected]3aa9ca72014-02-27 19:39:43506QuicPacket* ConstructHandshakePacket(QuicConnectionId connection_id,
507 QuicTag tag) {
[email protected]d3d15bf2013-01-30 02:51:54508 CryptoHandshakeMessage message;
[email protected]ccc66e8a2013-03-26 08:26:14509 message.set_tag(tag);
[email protected]3aa9ca72014-02-27 19:39:43510 return ConstructPacketFromHandshakeMessage(connection_id, message, false);
[email protected]d3d15bf2013-01-30 02:51:54511}
512
[email protected]ea825e02013-08-21 18:12:45513size_t GetPacketLengthForOneStream(
514 QuicVersion version,
515 bool include_version,
516 QuicSequenceNumberLength sequence_number_length,
517 InFecGroup is_in_fec_group,
518 size_t* payload_length) {
[email protected]f62262b2013-07-05 20:57:30519 *payload_length = 1;
520 const size_t stream_length =
[email protected]5dafdb62013-11-14 01:24:26521 NullEncrypter().GetCiphertextSize(*payload_length) +
[email protected]b064310782013-05-30 21:12:17522 QuicPacketCreator::StreamFramePacketOverhead(
[email protected]3aa9ca72014-02-27 19:39:43523 version, PACKET_8BYTE_CONNECTION_ID, include_version,
[email protected]aa7e4ef2014-05-28 03:53:15524 sequence_number_length, 0u, is_in_fec_group);
[email protected]5dafdb62013-11-14 01:24:26525 const size_t ack_length = NullEncrypter().GetCiphertextSize(
[email protected]8e01c062013-10-31 07:35:31526 QuicFramer::GetMinAckFrameSize(
527 version, sequence_number_length, PACKET_1BYTE_SEQUENCE_NUMBER)) +
[email protected]3aa9ca72014-02-27 19:39:43528 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, include_version,
[email protected]ea825e02013-08-21 18:12:45529 sequence_number_length, is_in_fec_group);
[email protected]f62262b2013-07-05 20:57:30530 if (stream_length < ack_length) {
531 *payload_length = 1 + ack_length - stream_length;
532 }
533
[email protected]5dafdb62013-11-14 01:24:26534 return NullEncrypter().GetCiphertextSize(*payload_length) +
[email protected]f62262b2013-07-05 20:57:30535 QuicPacketCreator::StreamFramePacketOverhead(
[email protected]3aa9ca72014-02-27 19:39:43536 version, PACKET_8BYTE_CONNECTION_ID, include_version,
[email protected]aa7e4ef2014-05-28 03:53:15537 sequence_number_length, 0u, is_in_fec_group);
[email protected]5351cc4b2013-03-03 07:22:41538}
539
[email protected]8e01c062013-10-31 07:35:31540TestEntropyCalculator::TestEntropyCalculator() { }
541
542TestEntropyCalculator::~TestEntropyCalculator() { }
543
[email protected]48878092013-07-26 14:51:56544QuicPacketEntropyHash TestEntropyCalculator::EntropyHash(
[email protected]9db443912013-02-25 05:27:03545 QuicPacketSequenceNumber sequence_number) const {
546 return 1u;
547}
548
[email protected]8e01c062013-10-31 07:35:31549MockEntropyCalculator::MockEntropyCalculator() { }
550
551MockEntropyCalculator::~MockEntropyCalculator() { }
552
[email protected]b064310782013-05-30 21:12:17553QuicConfig DefaultQuicConfig() {
554 QuicConfig config;
555 config.SetDefaults();
556 return config;
557}
558
[email protected]4d640792013-12-18 22:21:08559QuicVersionVector SupportedVersions(QuicVersion version) {
560 QuicVersionVector versions;
561 versions.push_back(version);
562 return versions;
563}
564
[email protected]8b37a092012-10-18 21:53:49565} // namespace test
[email protected]8b37a092012-10-18 21:53:49566} // namespace net