blob: 5e4d7f5b3d3ed17d67c6d0d255ab59b5a4815c48 [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]8b37a092012-10-18 21:53:4955MockFramerVisitor::MockFramerVisitor() {
56 // By default, we want to accept packets.
[email protected]14e8106c2013-03-14 16:25:3357 ON_CALL(*this, OnProtocolVersionMismatch(_))
58 .WillByDefault(testing::Return(false));
59
60 // By default, we want to accept packets.
[email protected]ec86d5462013-11-17 16:04:4961 ON_CALL(*this, OnUnauthenticatedHeader(_))
62 .WillByDefault(testing::Return(true));
63
[email protected]066d8182014-01-04 02:02:4564 ON_CALL(*this, OnUnauthenticatedPublicHeader(_))
65 .WillByDefault(testing::Return(true));
66
[email protected]cff7b7b2013-01-11 08:49:0767 ON_CALL(*this, OnPacketHeader(_))
[email protected]8b37a092012-10-18 21:53:4968 .WillByDefault(testing::Return(true));
[email protected]a57e0272013-04-26 07:31:4769
70 ON_CALL(*this, OnStreamFrame(_))
71 .WillByDefault(testing::Return(true));
72
73 ON_CALL(*this, OnAckFrame(_))
74 .WillByDefault(testing::Return(true));
75
76 ON_CALL(*this, OnCongestionFeedbackFrame(_))
77 .WillByDefault(testing::Return(true));
78
[email protected]93dd91f2014-02-27 00:09:0379 ON_CALL(*this, OnStopWaitingFrame(_))
80 .WillByDefault(testing::Return(true));
81
[email protected]d8c522112014-04-23 09:23:2582 ON_CALL(*this, OnPingFrame(_))
83 .WillByDefault(testing::Return(true));
84
[email protected]a57e0272013-04-26 07:31:4785 ON_CALL(*this, OnRstStreamFrame(_))
86 .WillByDefault(testing::Return(true));
87
88 ON_CALL(*this, OnConnectionCloseFrame(_))
89 .WillByDefault(testing::Return(true));
90
91 ON_CALL(*this, OnGoAwayFrame(_))
92 .WillByDefault(testing::Return(true));
[email protected]8b37a092012-10-18 21:53:4993}
94
[email protected]044ac2b2012-11-13 21:41:0695MockFramerVisitor::~MockFramerVisitor() {
96}
[email protected]8b37a092012-10-18 21:53:4997
[email protected]48878092013-07-26 14:51:5698bool NoOpFramerVisitor::OnProtocolVersionMismatch(QuicVersion version) {
[email protected]14e8106c2013-03-14 16:25:3399 return false;
100}
101
[email protected]066d8182014-01-04 02:02:45102bool NoOpFramerVisitor::OnUnauthenticatedPublicHeader(
103 const QuicPacketPublicHeader& header) {
104 return true;
105}
106
[email protected]ec86d5462013-11-17 16:04:49107bool NoOpFramerVisitor::OnUnauthenticatedHeader(
108 const QuicPacketHeader& header) {
109 return true;
110}
111
[email protected]8b37a092012-10-18 21:53:49112bool NoOpFramerVisitor::OnPacketHeader(const QuicPacketHeader& header) {
113 return true;
114}
115
[email protected]a57e0272013-04-26 07:31:47116bool NoOpFramerVisitor::OnStreamFrame(const QuicStreamFrame& frame) {
117 return true;
118}
119
120bool NoOpFramerVisitor::OnAckFrame(const QuicAckFrame& frame) {
121 return true;
122}
123
124bool NoOpFramerVisitor::OnCongestionFeedbackFrame(
125 const QuicCongestionFeedbackFrame& frame) {
126 return true;
127}
128
[email protected]93dd91f2014-02-27 00:09:03129bool NoOpFramerVisitor::OnStopWaitingFrame(
130 const QuicStopWaitingFrame& frame) {
131 return true;
132}
133
[email protected]d8c522112014-04-23 09:23:25134bool NoOpFramerVisitor::OnPingFrame(const QuicPingFrame& frame) {
135 return true;
136}
137
[email protected]a57e0272013-04-26 07:31:47138bool NoOpFramerVisitor::OnRstStreamFrame(
139 const QuicRstStreamFrame& frame) {
140 return true;
141}
142
143bool NoOpFramerVisitor::OnConnectionCloseFrame(
144 const QuicConnectionCloseFrame& frame) {
145 return true;
146}
147
148bool NoOpFramerVisitor::OnGoAwayFrame(const QuicGoAwayFrame& frame) {
149 return true;
150}
151
[email protected]cb23a922014-02-20 17:42:38152bool NoOpFramerVisitor::OnWindowUpdateFrame(
153 const QuicWindowUpdateFrame& frame) {
154 return true;
155}
156
157bool NoOpFramerVisitor::OnBlockedFrame(const QuicBlockedFrame& frame) {
158 return true;
159}
160
[email protected]8d659e22013-01-19 04:26:10161MockConnectionVisitor::MockConnectionVisitor() {
162}
163
164MockConnectionVisitor::~MockConnectionVisitor() {
165}
166
[email protected]9c0b1352012-11-04 00:03:27167MockHelper::MockHelper() {
168}
169
170MockHelper::~MockHelper() {
171}
172
[email protected]97693d12012-11-16 16:05:00173const QuicClock* MockHelper::GetClock() const {
[email protected]9c0b1352012-11-04 00:03:27174 return &clock_;
175}
176
[email protected]9558c5d32012-12-22 00:08:14177QuicRandom* MockHelper::GetRandomGenerator() {
178 return &random_generator_;
179}
180
[email protected]965dbe62013-08-09 21:34:31181QuicAlarm* MockHelper::CreateAlarm(QuicAlarm::Delegate* delegate) {
182 return new TestAlarm(delegate);
183}
184
[email protected]fe053f92013-04-23 20:18:55185void MockHelper::AdvanceTime(QuicTime::Delta delta) {
186 clock_.AdvanceTime(delta);
187}
188
[email protected]c05a6d222013-12-16 19:42:03189MockConnection::MockConnection(bool is_server)
[email protected]3aa9ca72014-02-27 19:39:43190 : QuicConnection(kTestConnectionId,
[email protected]300ccd52014-01-25 08:00:19191 IPEndPoint(TestPeerIPAddress(), kTestPort),
[email protected]c05a6d222013-12-16 19:42:03192 new testing::NiceMock<MockHelper>(),
[email protected]cbd731e2013-10-24 00:20:39193 new testing::NiceMock<MockPacketWriter>(),
[email protected]9bb57c72014-03-31 20:36:04194 is_server, QuicSupportedVersions(),
195 kInitialFlowControlWindowForTest),
[email protected]c05a6d222013-12-16 19:42:03196 writer_(QuicConnectionPeer::GetWriter(this)),
197 helper_(helper()) {
198}
199
200MockConnection::MockConnection(IPEndPoint address,
201 bool is_server)
[email protected]3aa9ca72014-02-27 19:39:43202 : QuicConnection(kTestConnectionId, address,
[email protected]c05a6d222013-12-16 19:42:03203 new testing::NiceMock<MockHelper>(),
204 new testing::NiceMock<MockPacketWriter>(),
[email protected]9bb57c72014-03-31 20:36:04205 is_server, QuicSupportedVersions(),
206 kInitialFlowControlWindowForTest),
[email protected]2cfc6bb82013-10-27 03:40:44207 writer_(QuicConnectionPeer::GetWriter(this)),
208 helper_(helper()) {
[email protected]044ac2b2012-11-13 21:41:06209}
210
[email protected]3aa9ca72014-02-27 19:39:43211MockConnection::MockConnection(QuicConnectionId connection_id,
[email protected]14e8106c2013-03-14 16:25:33212 bool is_server)
[email protected]3aa9ca72014-02-27 19:39:43213 : QuicConnection(connection_id,
214 IPEndPoint(TestPeerIPAddress(), kTestPort),
[email protected]c05a6d222013-12-16 19:42:03215 new testing::NiceMock<MockHelper>(),
216 new testing::NiceMock<MockPacketWriter>(),
[email protected]9bb57c72014-03-31 20:36:04217 is_server, QuicSupportedVersions(),
218 kInitialFlowControlWindowForTest),
[email protected]c05a6d222013-12-16 19:42:03219 writer_(QuicConnectionPeer::GetWriter(this)),
220 helper_(helper()) {
[email protected]872edd9e2013-01-16 08:51:15221}
222
[email protected]4d640792013-12-18 22:21:08223MockConnection::MockConnection(bool is_server,
224 const QuicVersionVector& supported_versions)
[email protected]3aa9ca72014-02-27 19:39:43225 : QuicConnection(kTestConnectionId,
[email protected]300ccd52014-01-25 08:00:19226 IPEndPoint(TestPeerIPAddress(), kTestPort),
[email protected]4d640792013-12-18 22:21:08227 new testing::NiceMock<MockHelper>(),
228 new testing::NiceMock<MockPacketWriter>(),
[email protected]9bb57c72014-03-31 20:36:04229 is_server, supported_versions,
230 kInitialFlowControlWindowForTest),
[email protected]4d640792013-12-18 22:21:08231 writer_(QuicConnectionPeer::GetWriter(this)),
232 helper_(helper()) {
233}
234
[email protected]044ac2b2012-11-13 21:41:06235MockConnection::~MockConnection() {
236}
237
[email protected]fe053f92013-04-23 20:18:55238void MockConnection::AdvanceTime(QuicTime::Delta delta) {
[email protected]fe053f92013-04-23 20:18:55239 static_cast<MockHelper*>(helper())->AdvanceTime(delta);
240}
241
[email protected]c05a6d222013-12-16 19:42:03242PacketSavingConnection::PacketSavingConnection(bool is_server)
243 : MockConnection(is_server) {
[email protected]044ac2b2012-11-13 21:41:06244}
245
[email protected]4d640792013-12-18 22:21:08246PacketSavingConnection::PacketSavingConnection(
247 bool is_server,
248 const QuicVersionVector& supported_versions)
249 : MockConnection(is_server, supported_versions) {
250}
251
[email protected]044ac2b2012-11-13 21:41:06252PacketSavingConnection::~PacketSavingConnection() {
[email protected]701bc892013-01-17 04:51:54253 STLDeleteElements(&packets_);
[email protected]2532de12013-05-09 12:29:33254 STLDeleteElements(&encrypted_packets_);
[email protected]044ac2b2012-11-13 21:41:06255}
256
[email protected]fee17f72013-02-03 07:47:41257bool PacketSavingConnection::SendOrQueuePacket(
[email protected]8ba81212013-05-03 13:11:48258 EncryptionLevel level,
[email protected]ec86d5462013-11-17 16:04:49259 const SerializedPacket& packet,
260 TransmissionType transmission_type) {
261 packets_.push_back(packet.packet);
[email protected]c5e1aca2014-01-30 04:03:04262 QuicEncryptedPacket* encrypted = QuicConnectionPeer::GetFramer(this)->
263 EncryptPacket(level, packet.sequence_number, *packet.packet);
[email protected]2532de12013-05-09 12:29:33264 encrypted_packets_.push_back(encrypted);
[email protected]044ac2b2012-11-13 21:41:06265 return true;
266}
267
[email protected]c05a6d222013-12-16 19:42:03268MockSession::MockSession(QuicConnection* connection)
269 : QuicSession(connection, DefaultQuicConfig()) {
[email protected]93dd91f2014-02-27 00:09:03270 ON_CALL(*this, WritevData(_, _, _, _, _))
[email protected]cff7b7b2013-01-11 08:49:07271 .WillByDefault(testing::Return(QuicConsumedData(0, false)));
[email protected]044ac2b2012-11-13 21:41:06272}
273
274MockSession::~MockSession() {
275}
276
[email protected]899951652013-05-16 12:52:39277TestSession::TestSession(QuicConnection* connection,
[email protected]c05a6d222013-12-16 19:42:03278 const QuicConfig& config)
279 : QuicSession(connection, config),
[email protected]2532de12013-05-09 12:29:33280 crypto_stream_(NULL) {
281}
282
[email protected]b064310782013-05-30 21:12:17283TestSession::~TestSession() {}
[email protected]2532de12013-05-09 12:29:33284
285void TestSession::SetCryptoStream(QuicCryptoStream* stream) {
286 crypto_stream_ = stream;
287}
288
289QuicCryptoStream* TestSession::GetCryptoStream() {
290 return crypto_stream_;
291}
292
[email protected]90f62f092014-03-24 02:41:23293TestClientSession::TestClientSession(QuicConnection* connection,
294 const QuicConfig& config)
295 : QuicClientSessionBase(connection, config),
296 crypto_stream_(NULL) {
[email protected]64c12232014-03-26 05:43:59297 EXPECT_CALL(*this, OnProofValid(_)).Times(AnyNumber());
[email protected]90f62f092014-03-24 02:41:23298}
299
300TestClientSession::~TestClientSession() {}
301
302void TestClientSession::SetCryptoStream(QuicCryptoStream* stream) {
303 crypto_stream_ = stream;
304}
305
306QuicCryptoStream* TestClientSession::GetCryptoStream() {
307 return crypto_stream_;
308}
309
[email protected]cbd731e2013-10-24 00:20:39310MockPacketWriter::MockPacketWriter() {
311}
312
313MockPacketWriter::~MockPacketWriter() {
314}
315
[email protected]fee17f72013-02-03 07:47:41316MockSendAlgorithm::MockSendAlgorithm() {
[email protected]8d659e22013-01-19 04:26:10317}
318
[email protected]fee17f72013-02-03 07:47:41319MockSendAlgorithm::~MockSendAlgorithm() {
[email protected]8d659e22013-01-19 04:26:10320}
321
[email protected]3aa9ca72014-02-27 19:39:43322MockLossAlgorithm::MockLossAlgorithm() {
323}
324
325MockLossAlgorithm::~MockLossAlgorithm() {
326}
327
[email protected]97cf3022013-09-05 14:30:16328MockAckNotifierDelegate::MockAckNotifierDelegate() {
329}
330
331MockAckNotifierDelegate::~MockAckNotifierDelegate() {
332}
333
[email protected]8b37a092012-10-18 21:53:49334namespace {
335
336string HexDumpWithMarks(const char* data, int length,
337 const bool* marks, int mark_length) {
338 static const char kHexChars[] = "0123456789abcdef";
339 static const int kColumns = 4;
340
341 const int kSizeLimit = 1024;
342 if (length > kSizeLimit || mark_length > kSizeLimit) {
343 LOG(ERROR) << "Only dumping first " << kSizeLimit << " bytes.";
344 length = min(length, kSizeLimit);
345 mark_length = min(mark_length, kSizeLimit);
346 }
347
348 string hex;
349 for (const char* row = data; length > 0;
350 row += kColumns, length -= kColumns) {
351 for (const char *p = row; p < row + 4; ++p) {
352 if (p < row + length) {
353 const bool mark =
354 (marks && (p - data) < mark_length && marks[p - data]);
355 hex += mark ? '*' : ' ';
356 hex += kHexChars[(*p & 0xf0) >> 4];
357 hex += kHexChars[*p & 0x0f];
358 hex += mark ? '*' : ' ';
359 } else {
360 hex += " ";
361 }
362 }
363 hex = hex + " ";
364
365 for (const char *p = row; p < row + 4 && p < row + length; ++p)
366 hex += (*p >= 0x20 && *p <= 0x7f) ? (*p) : '.';
367
368 hex = hex + '\n';
369 }
370 return hex;
371}
372
373} // namespace
374
[email protected]300ccd52014-01-25 08:00:19375IPAddressNumber TestPeerIPAddress() { return Loopback4(); }
376
[email protected]b007e632013-10-28 08:39:25377QuicVersion QuicVersionMax() { return QuicSupportedVersions().front(); }
378
379QuicVersion QuicVersionMin() { return QuicSupportedVersions().back(); }
380
[email protected]c05a6d222013-12-16 19:42:03381IPAddressNumber Loopback4() {
[email protected]300ccd52014-01-25 08:00:19382 IPAddressNumber addr;
383 CHECK(ParseIPLiteralToNumber("127.0.0.1", &addr));
[email protected]c05a6d222013-12-16 19:42:03384 return addr;
385}
386
[email protected]9bb57c72014-03-31 20:36:04387void GenerateBody(string* body, int length) {
388 body->clear();
389 body->reserve(length);
390 for (int i = 0; i < length; ++i) {
391 body->append(1, static_cast<char>(32 + i % (126 - 32)));
392 }
393}
394
[email protected]ffc34bf2014-03-07 02:42:02395QuicEncryptedPacket* ConstructEncryptedPacket(
396 QuicConnectionId connection_id,
397 bool version_flag,
398 bool reset_flag,
399 QuicPacketSequenceNumber sequence_number,
400 const string& data) {
401 QuicPacketHeader header;
402 header.public_header.connection_id = connection_id;
403 header.public_header.connection_id_length = PACKET_8BYTE_CONNECTION_ID;
404 header.public_header.version_flag = version_flag;
405 header.public_header.reset_flag = reset_flag;
406 header.public_header.sequence_number_length = PACKET_6BYTE_SEQUENCE_NUMBER;
407 header.packet_sequence_number = sequence_number;
408 header.entropy_flag = false;
409 header.entropy_hash = 0;
410 header.fec_flag = false;
411 header.is_in_fec_group = NOT_IN_FEC_GROUP;
412 header.fec_group = 0;
413 QuicStreamFrame stream_frame(1, false, 0, MakeIOVector(data));
414 QuicFrame frame(&stream_frame);
415 QuicFrames frames;
416 frames.push_back(frame);
417 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), false);
418 scoped_ptr<QuicPacket> packet(
419 framer.BuildUnsizedDataPacket(header, frames).packet);
420 EXPECT_TRUE(packet != NULL);
421 QuicEncryptedPacket* encrypted = framer.EncryptPacket(ENCRYPTION_NONE,
422 sequence_number,
423 *packet);
424 EXPECT_TRUE(encrypted != NULL);
425 return encrypted;
426}
427
[email protected]8b37a092012-10-18 21:53:49428void CompareCharArraysWithHexError(
429 const string& description,
430 const char* actual,
431 const int actual_len,
432 const char* expected,
433 const int expected_len) {
[email protected]b007e632013-10-28 08:39:25434 EXPECT_EQ(actual_len, expected_len);
[email protected]8b37a092012-10-18 21:53:49435 const int min_len = min(actual_len, expected_len);
436 const int max_len = max(actual_len, expected_len);
[email protected]4356f0f2013-04-07 00:58:17437 scoped_ptr<bool[]> marks(new bool[max_len]);
[email protected]8b37a092012-10-18 21:53:49438 bool identical = (actual_len == expected_len);
439 for (int i = 0; i < min_len; ++i) {
440 if (actual[i] != expected[i]) {
441 marks[i] = true;
442 identical = false;
443 } else {
444 marks[i] = false;
445 }
446 }
447 for (int i = min_len; i < max_len; ++i) {
448 marks[i] = true;
449 }
450 if (identical) return;
451 ADD_FAILURE()
452 << "Description:\n"
453 << description
454 << "\n\nExpected:\n"
455 << HexDumpWithMarks(expected, expected_len, marks.get(), max_len)
456 << "\nActual:\n"
457 << HexDumpWithMarks(actual, actual_len, marks.get(), max_len);
458}
459
[email protected]b12764d2013-12-02 22:28:30460bool DecodeHexString(const base::StringPiece& hex, std::string* bytes) {
461 bytes->clear();
462 if (hex.empty())
463 return true;
464 std::vector<uint8> v;
465 if (!base::HexStringToBytes(hex.as_string(), &v))
466 return false;
467 if (!v.empty())
468 bytes->assign(reinterpret_cast<const char*>(&v[0]), v.size());
469 return true;
470}
471
[email protected]d3d15bf2013-01-30 02:51:54472static QuicPacket* ConstructPacketFromHandshakeMessage(
[email protected]3aa9ca72014-02-27 19:39:43473 QuicConnectionId connection_id,
[email protected]14e8106c2013-03-14 16:25:33474 const CryptoHandshakeMessage& message,
475 bool should_include_version) {
[email protected]8b37a092012-10-18 21:53:49476 CryptoFramer crypto_framer;
[email protected]dc2cc742012-10-21 13:56:13477 scoped_ptr<QuicData> data(crypto_framer.ConstructHandshakeMessage(message));
[email protected]b007e632013-10-28 08:39:25478 QuicFramer quic_framer(QuicSupportedVersions(), QuicTime::Zero(), false);
[email protected]8b37a092012-10-18 21:53:49479
480 QuicPacketHeader header;
[email protected]3aa9ca72014-02-27 19:39:43481 header.public_header.connection_id = connection_id;
[email protected]9db443912013-02-25 05:27:03482 header.public_header.reset_flag = false;
[email protected]14e8106c2013-03-14 16:25:33483 header.public_header.version_flag = should_include_version;
[email protected]8b37a092012-10-18 21:53:49484 header.packet_sequence_number = 1;
[email protected]9db443912013-02-25 05:27:03485 header.entropy_flag = false;
486 header.entropy_hash = 0;
487 header.fec_flag = false;
[email protected]8b37a092012-10-18 21:53:49488 header.fec_group = 0;
489
[email protected]be24ab22012-10-22 03:01:52490 QuicStreamFrame stream_frame(kCryptoStreamId, false, 0,
[email protected]5dafdb62013-11-14 01:24:26491 MakeIOVector(data->AsStringPiece()));
[email protected]8b37a092012-10-18 21:53:49492
[email protected]be24ab22012-10-22 03:01:52493 QuicFrame frame(&stream_frame);
494 QuicFrames frames;
495 frames.push_back(frame);
[email protected]3e60db82013-08-05 19:43:06496 return quic_framer.BuildUnsizedDataPacket(header, frames).packet;
[email protected]8b37a092012-10-18 21:53:49497}
498
[email protected]3aa9ca72014-02-27 19:39:43499QuicPacket* ConstructHandshakePacket(QuicConnectionId connection_id,
500 QuicTag tag) {
[email protected]d3d15bf2013-01-30 02:51:54501 CryptoHandshakeMessage message;
[email protected]ccc66e8a2013-03-26 08:26:14502 message.set_tag(tag);
[email protected]3aa9ca72014-02-27 19:39:43503 return ConstructPacketFromHandshakeMessage(connection_id, message, false);
[email protected]d3d15bf2013-01-30 02:51:54504}
505
[email protected]ea825e02013-08-21 18:12:45506size_t GetPacketLengthForOneStream(
507 QuicVersion version,
508 bool include_version,
509 QuicSequenceNumberLength sequence_number_length,
510 InFecGroup is_in_fec_group,
511 size_t* payload_length) {
[email protected]f62262b2013-07-05 20:57:30512 *payload_length = 1;
513 const size_t stream_length =
[email protected]5dafdb62013-11-14 01:24:26514 NullEncrypter().GetCiphertextSize(*payload_length) +
[email protected]b064310782013-05-30 21:12:17515 QuicPacketCreator::StreamFramePacketOverhead(
[email protected]3aa9ca72014-02-27 19:39:43516 version, PACKET_8BYTE_CONNECTION_ID, include_version,
[email protected]ea825e02013-08-21 18:12:45517 sequence_number_length, is_in_fec_group);
[email protected]5dafdb62013-11-14 01:24:26518 const size_t ack_length = NullEncrypter().GetCiphertextSize(
[email protected]8e01c062013-10-31 07:35:31519 QuicFramer::GetMinAckFrameSize(
520 version, sequence_number_length, PACKET_1BYTE_SEQUENCE_NUMBER)) +
[email protected]3aa9ca72014-02-27 19:39:43521 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, include_version,
[email protected]ea825e02013-08-21 18:12:45522 sequence_number_length, is_in_fec_group);
[email protected]f62262b2013-07-05 20:57:30523 if (stream_length < ack_length) {
524 *payload_length = 1 + ack_length - stream_length;
525 }
526
[email protected]5dafdb62013-11-14 01:24:26527 return NullEncrypter().GetCiphertextSize(*payload_length) +
[email protected]f62262b2013-07-05 20:57:30528 QuicPacketCreator::StreamFramePacketOverhead(
[email protected]3aa9ca72014-02-27 19:39:43529 version, PACKET_8BYTE_CONNECTION_ID, include_version,
[email protected]ea825e02013-08-21 18:12:45530 sequence_number_length, is_in_fec_group);
[email protected]5351cc4b2013-03-03 07:22:41531}
532
[email protected]8e01c062013-10-31 07:35:31533TestEntropyCalculator::TestEntropyCalculator() { }
534
535TestEntropyCalculator::~TestEntropyCalculator() { }
536
[email protected]48878092013-07-26 14:51:56537QuicPacketEntropyHash TestEntropyCalculator::EntropyHash(
[email protected]9db443912013-02-25 05:27:03538 QuicPacketSequenceNumber sequence_number) const {
539 return 1u;
540}
541
[email protected]8e01c062013-10-31 07:35:31542MockEntropyCalculator::MockEntropyCalculator() { }
543
544MockEntropyCalculator::~MockEntropyCalculator() { }
545
[email protected]b064310782013-05-30 21:12:17546QuicConfig DefaultQuicConfig() {
547 QuicConfig config;
548 config.SetDefaults();
549 return config;
550}
551
[email protected]4d640792013-12-18 22:21:08552QuicVersionVector SupportedVersions(QuicVersion version) {
553 QuicVersionVector versions;
554 versions.push_back(version);
555 return versions;
556}
557
[email protected]8b37a092012-10-18 21:53:49558} // namespace test
[email protected]8b37a092012-10-18 21:53:49559} // namespace net