blob: f14dd7391c0b8ab4bb2503ea96e1b9c8b2b369e5 [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]ce7bb1412014-05-17 15:51:33194 is_server, QuicSupportedVersions()),
[email protected]c05a6d222013-12-16 19:42:03195 writer_(QuicConnectionPeer::GetWriter(this)),
196 helper_(helper()) {
197}
198
199MockConnection::MockConnection(IPEndPoint address,
200 bool is_server)
[email protected]3aa9ca72014-02-27 19:39:43201 : QuicConnection(kTestConnectionId, address,
[email protected]c05a6d222013-12-16 19:42:03202 new testing::NiceMock<MockHelper>(),
203 new testing::NiceMock<MockPacketWriter>(),
[email protected]ce7bb1412014-05-17 15:51:33204 is_server, QuicSupportedVersions()),
[email protected]2cfc6bb82013-10-27 03:40:44205 writer_(QuicConnectionPeer::GetWriter(this)),
206 helper_(helper()) {
[email protected]044ac2b2012-11-13 21:41:06207}
208
[email protected]3aa9ca72014-02-27 19:39:43209MockConnection::MockConnection(QuicConnectionId connection_id,
[email protected]14e8106c2013-03-14 16:25:33210 bool is_server)
[email protected]3aa9ca72014-02-27 19:39:43211 : QuicConnection(connection_id,
212 IPEndPoint(TestPeerIPAddress(), kTestPort),
[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]c05a6d222013-12-16 19:42:03216 writer_(QuicConnectionPeer::GetWriter(this)),
217 helper_(helper()) {
[email protected]872edd9e2013-01-16 08:51:15218}
219
[email protected]4d640792013-12-18 22:21:08220MockConnection::MockConnection(bool is_server,
221 const QuicVersionVector& supported_versions)
[email protected]3aa9ca72014-02-27 19:39:43222 : QuicConnection(kTestConnectionId,
[email protected]300ccd52014-01-25 08:00:19223 IPEndPoint(TestPeerIPAddress(), kTestPort),
[email protected]4d640792013-12-18 22:21:08224 new testing::NiceMock<MockHelper>(),
225 new testing::NiceMock<MockPacketWriter>(),
[email protected]ce7bb1412014-05-17 15:51:33226 is_server, supported_versions),
[email protected]4d640792013-12-18 22:21:08227 writer_(QuicConnectionPeer::GetWriter(this)),
228 helper_(helper()) {
229}
230
[email protected]044ac2b2012-11-13 21:41:06231MockConnection::~MockConnection() {
232}
233
[email protected]fe053f92013-04-23 20:18:55234void MockConnection::AdvanceTime(QuicTime::Delta delta) {
[email protected]fe053f92013-04-23 20:18:55235 static_cast<MockHelper*>(helper())->AdvanceTime(delta);
236}
237
[email protected]c05a6d222013-12-16 19:42:03238PacketSavingConnection::PacketSavingConnection(bool is_server)
239 : MockConnection(is_server) {
[email protected]044ac2b2012-11-13 21:41:06240}
241
[email protected]4d640792013-12-18 22:21:08242PacketSavingConnection::PacketSavingConnection(
243 bool is_server,
244 const QuicVersionVector& supported_versions)
245 : MockConnection(is_server, supported_versions) {
246}
247
[email protected]044ac2b2012-11-13 21:41:06248PacketSavingConnection::~PacketSavingConnection() {
[email protected]701bc892013-01-17 04:51:54249 STLDeleteElements(&packets_);
[email protected]2532de12013-05-09 12:29:33250 STLDeleteElements(&encrypted_packets_);
[email protected]044ac2b2012-11-13 21:41:06251}
252
[email protected]fee17f72013-02-03 07:47:41253bool PacketSavingConnection::SendOrQueuePacket(
[email protected]8ba81212013-05-03 13:11:48254 EncryptionLevel level,
[email protected]ec86d5462013-11-17 16:04:49255 const SerializedPacket& packet,
256 TransmissionType transmission_type) {
257 packets_.push_back(packet.packet);
[email protected]c5e1aca2014-01-30 04:03:04258 QuicEncryptedPacket* encrypted = QuicConnectionPeer::GetFramer(this)->
259 EncryptPacket(level, packet.sequence_number, *packet.packet);
[email protected]2532de12013-05-09 12:29:33260 encrypted_packets_.push_back(encrypted);
[email protected]044ac2b2012-11-13 21:41:06261 return true;
262}
263
[email protected]c05a6d222013-12-16 19:42:03264MockSession::MockSession(QuicConnection* connection)
[email protected]ce7bb1412014-05-17 15:51:33265 : QuicSession(connection, kInitialFlowControlWindowForTest,
266 DefaultQuicConfig()) {
[email protected]93dd91f2014-02-27 00:09:03267 ON_CALL(*this, WritevData(_, _, _, _, _))
[email protected]cff7b7b2013-01-11 08:49:07268 .WillByDefault(testing::Return(QuicConsumedData(0, false)));
[email protected]044ac2b2012-11-13 21:41:06269}
270
271MockSession::~MockSession() {
272}
273
[email protected]ce7bb1412014-05-17 15:51:33274TestSession::TestSession(QuicConnection* connection, const QuicConfig& config)
275 : QuicSession(connection, kInitialFlowControlWindowForTest, config),
276 crypto_stream_(NULL) {}
[email protected]2532de12013-05-09 12:29:33277
[email protected]b064310782013-05-30 21:12:17278TestSession::~TestSession() {}
[email protected]2532de12013-05-09 12:29:33279
280void TestSession::SetCryptoStream(QuicCryptoStream* stream) {
281 crypto_stream_ = stream;
282}
283
284QuicCryptoStream* TestSession::GetCryptoStream() {
285 return crypto_stream_;
286}
287
[email protected]90f62f092014-03-24 02:41:23288TestClientSession::TestClientSession(QuicConnection* connection,
289 const QuicConfig& config)
[email protected]ce7bb1412014-05-17 15:51:33290 : QuicClientSessionBase(connection, kInitialFlowControlWindowForTest,
291 config),
[email protected]90f62f092014-03-24 02:41:23292 crypto_stream_(NULL) {
[email protected]64c12232014-03-26 05:43:59293 EXPECT_CALL(*this, OnProofValid(_)).Times(AnyNumber());
[email protected]90f62f092014-03-24 02:41:23294}
295
296TestClientSession::~TestClientSession() {}
297
298void TestClientSession::SetCryptoStream(QuicCryptoStream* stream) {
299 crypto_stream_ = stream;
300}
301
302QuicCryptoStream* TestClientSession::GetCryptoStream() {
303 return crypto_stream_;
304}
305
[email protected]cbd731e2013-10-24 00:20:39306MockPacketWriter::MockPacketWriter() {
307}
308
309MockPacketWriter::~MockPacketWriter() {
310}
311
[email protected]fee17f72013-02-03 07:47:41312MockSendAlgorithm::MockSendAlgorithm() {
[email protected]8d659e22013-01-19 04:26:10313}
314
[email protected]fee17f72013-02-03 07:47:41315MockSendAlgorithm::~MockSendAlgorithm() {
[email protected]8d659e22013-01-19 04:26:10316}
317
[email protected]3aa9ca72014-02-27 19:39:43318MockLossAlgorithm::MockLossAlgorithm() {
319}
320
321MockLossAlgorithm::~MockLossAlgorithm() {
322}
323
[email protected]97cf3022013-09-05 14:30:16324MockAckNotifierDelegate::MockAckNotifierDelegate() {
325}
326
327MockAckNotifierDelegate::~MockAckNotifierDelegate() {
328}
329
[email protected]8b37a092012-10-18 21:53:49330namespace {
331
332string HexDumpWithMarks(const char* data, int length,
333 const bool* marks, int mark_length) {
334 static const char kHexChars[] = "0123456789abcdef";
335 static const int kColumns = 4;
336
337 const int kSizeLimit = 1024;
338 if (length > kSizeLimit || mark_length > kSizeLimit) {
339 LOG(ERROR) << "Only dumping first " << kSizeLimit << " bytes.";
340 length = min(length, kSizeLimit);
341 mark_length = min(mark_length, kSizeLimit);
342 }
343
344 string hex;
345 for (const char* row = data; length > 0;
346 row += kColumns, length -= kColumns) {
347 for (const char *p = row; p < row + 4; ++p) {
348 if (p < row + length) {
349 const bool mark =
350 (marks && (p - data) < mark_length && marks[p - data]);
351 hex += mark ? '*' : ' ';
352 hex += kHexChars[(*p & 0xf0) >> 4];
353 hex += kHexChars[*p & 0x0f];
354 hex += mark ? '*' : ' ';
355 } else {
356 hex += " ";
357 }
358 }
359 hex = hex + " ";
360
361 for (const char *p = row; p < row + 4 && p < row + length; ++p)
362 hex += (*p >= 0x20 && *p <= 0x7f) ? (*p) : '.';
363
364 hex = hex + '\n';
365 }
366 return hex;
367}
368
369} // namespace
370
[email protected]300ccd52014-01-25 08:00:19371IPAddressNumber TestPeerIPAddress() { return Loopback4(); }
372
[email protected]b007e632013-10-28 08:39:25373QuicVersion QuicVersionMax() { return QuicSupportedVersions().front(); }
374
375QuicVersion QuicVersionMin() { return QuicSupportedVersions().back(); }
376
[email protected]c05a6d222013-12-16 19:42:03377IPAddressNumber Loopback4() {
[email protected]300ccd52014-01-25 08:00:19378 IPAddressNumber addr;
379 CHECK(ParseIPLiteralToNumber("127.0.0.1", &addr));
[email protected]c05a6d222013-12-16 19:42:03380 return addr;
381}
382
[email protected]9bb57c72014-03-31 20:36:04383void GenerateBody(string* body, int length) {
384 body->clear();
385 body->reserve(length);
386 for (int i = 0; i < length; ++i) {
387 body->append(1, static_cast<char>(32 + i % (126 - 32)));
388 }
389}
390
[email protected]ffc34bf2014-03-07 02:42:02391QuicEncryptedPacket* ConstructEncryptedPacket(
392 QuicConnectionId connection_id,
393 bool version_flag,
394 bool reset_flag,
395 QuicPacketSequenceNumber sequence_number,
396 const string& data) {
397 QuicPacketHeader header;
398 header.public_header.connection_id = connection_id;
399 header.public_header.connection_id_length = PACKET_8BYTE_CONNECTION_ID;
400 header.public_header.version_flag = version_flag;
401 header.public_header.reset_flag = reset_flag;
402 header.public_header.sequence_number_length = PACKET_6BYTE_SEQUENCE_NUMBER;
403 header.packet_sequence_number = sequence_number;
404 header.entropy_flag = false;
405 header.entropy_hash = 0;
406 header.fec_flag = false;
407 header.is_in_fec_group = NOT_IN_FEC_GROUP;
408 header.fec_group = 0;
409 QuicStreamFrame stream_frame(1, false, 0, MakeIOVector(data));
410 QuicFrame frame(&stream_frame);
411 QuicFrames frames;
412 frames.push_back(frame);
413 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), false);
414 scoped_ptr<QuicPacket> packet(
415 framer.BuildUnsizedDataPacket(header, frames).packet);
416 EXPECT_TRUE(packet != NULL);
417 QuicEncryptedPacket* encrypted = framer.EncryptPacket(ENCRYPTION_NONE,
418 sequence_number,
419 *packet);
420 EXPECT_TRUE(encrypted != NULL);
421 return encrypted;
422}
423
[email protected]8b37a092012-10-18 21:53:49424void CompareCharArraysWithHexError(
425 const string& description,
426 const char* actual,
427 const int actual_len,
428 const char* expected,
429 const int expected_len) {
[email protected]b007e632013-10-28 08:39:25430 EXPECT_EQ(actual_len, expected_len);
[email protected]8b37a092012-10-18 21:53:49431 const int min_len = min(actual_len, expected_len);
432 const int max_len = max(actual_len, expected_len);
[email protected]4356f0f2013-04-07 00:58:17433 scoped_ptr<bool[]> marks(new bool[max_len]);
[email protected]8b37a092012-10-18 21:53:49434 bool identical = (actual_len == expected_len);
435 for (int i = 0; i < min_len; ++i) {
436 if (actual[i] != expected[i]) {
437 marks[i] = true;
438 identical = false;
439 } else {
440 marks[i] = false;
441 }
442 }
443 for (int i = min_len; i < max_len; ++i) {
444 marks[i] = true;
445 }
446 if (identical) return;
447 ADD_FAILURE()
448 << "Description:\n"
449 << description
450 << "\n\nExpected:\n"
451 << HexDumpWithMarks(expected, expected_len, marks.get(), max_len)
452 << "\nActual:\n"
453 << HexDumpWithMarks(actual, actual_len, marks.get(), max_len);
454}
455
[email protected]b12764d2013-12-02 22:28:30456bool DecodeHexString(const base::StringPiece& hex, std::string* bytes) {
457 bytes->clear();
458 if (hex.empty())
459 return true;
460 std::vector<uint8> v;
461 if (!base::HexStringToBytes(hex.as_string(), &v))
462 return false;
463 if (!v.empty())
464 bytes->assign(reinterpret_cast<const char*>(&v[0]), v.size());
465 return true;
466}
467
[email protected]d3d15bf2013-01-30 02:51:54468static QuicPacket* ConstructPacketFromHandshakeMessage(
[email protected]3aa9ca72014-02-27 19:39:43469 QuicConnectionId connection_id,
[email protected]14e8106c2013-03-14 16:25:33470 const CryptoHandshakeMessage& message,
471 bool should_include_version) {
[email protected]8b37a092012-10-18 21:53:49472 CryptoFramer crypto_framer;
[email protected]dc2cc742012-10-21 13:56:13473 scoped_ptr<QuicData> data(crypto_framer.ConstructHandshakeMessage(message));
[email protected]b007e632013-10-28 08:39:25474 QuicFramer quic_framer(QuicSupportedVersions(), QuicTime::Zero(), false);
[email protected]8b37a092012-10-18 21:53:49475
476 QuicPacketHeader header;
[email protected]3aa9ca72014-02-27 19:39:43477 header.public_header.connection_id = connection_id;
[email protected]9db443912013-02-25 05:27:03478 header.public_header.reset_flag = false;
[email protected]14e8106c2013-03-14 16:25:33479 header.public_header.version_flag = should_include_version;
[email protected]8b37a092012-10-18 21:53:49480 header.packet_sequence_number = 1;
[email protected]9db443912013-02-25 05:27:03481 header.entropy_flag = false;
482 header.entropy_hash = 0;
483 header.fec_flag = false;
[email protected]8b37a092012-10-18 21:53:49484 header.fec_group = 0;
485
[email protected]be24ab22012-10-22 03:01:52486 QuicStreamFrame stream_frame(kCryptoStreamId, false, 0,
[email protected]5dafdb62013-11-14 01:24:26487 MakeIOVector(data->AsStringPiece()));
[email protected]8b37a092012-10-18 21:53:49488
[email protected]be24ab22012-10-22 03:01:52489 QuicFrame frame(&stream_frame);
490 QuicFrames frames;
491 frames.push_back(frame);
[email protected]3e60db82013-08-05 19:43:06492 return quic_framer.BuildUnsizedDataPacket(header, frames).packet;
[email protected]8b37a092012-10-18 21:53:49493}
494
[email protected]3aa9ca72014-02-27 19:39:43495QuicPacket* ConstructHandshakePacket(QuicConnectionId connection_id,
496 QuicTag tag) {
[email protected]d3d15bf2013-01-30 02:51:54497 CryptoHandshakeMessage message;
[email protected]ccc66e8a2013-03-26 08:26:14498 message.set_tag(tag);
[email protected]3aa9ca72014-02-27 19:39:43499 return ConstructPacketFromHandshakeMessage(connection_id, message, false);
[email protected]d3d15bf2013-01-30 02:51:54500}
501
[email protected]ea825e02013-08-21 18:12:45502size_t GetPacketLengthForOneStream(
503 QuicVersion version,
504 bool include_version,
505 QuicSequenceNumberLength sequence_number_length,
506 InFecGroup is_in_fec_group,
507 size_t* payload_length) {
[email protected]f62262b2013-07-05 20:57:30508 *payload_length = 1;
509 const size_t stream_length =
[email protected]5dafdb62013-11-14 01:24:26510 NullEncrypter().GetCiphertextSize(*payload_length) +
[email protected]b064310782013-05-30 21:12:17511 QuicPacketCreator::StreamFramePacketOverhead(
[email protected]3aa9ca72014-02-27 19:39:43512 version, PACKET_8BYTE_CONNECTION_ID, include_version,
[email protected]ea825e02013-08-21 18:12:45513 sequence_number_length, is_in_fec_group);
[email protected]5dafdb62013-11-14 01:24:26514 const size_t ack_length = NullEncrypter().GetCiphertextSize(
[email protected]8e01c062013-10-31 07:35:31515 QuicFramer::GetMinAckFrameSize(
516 version, sequence_number_length, PACKET_1BYTE_SEQUENCE_NUMBER)) +
[email protected]3aa9ca72014-02-27 19:39:43517 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, include_version,
[email protected]ea825e02013-08-21 18:12:45518 sequence_number_length, is_in_fec_group);
[email protected]f62262b2013-07-05 20:57:30519 if (stream_length < ack_length) {
520 *payload_length = 1 + ack_length - stream_length;
521 }
522
[email protected]5dafdb62013-11-14 01:24:26523 return NullEncrypter().GetCiphertextSize(*payload_length) +
[email protected]f62262b2013-07-05 20:57:30524 QuicPacketCreator::StreamFramePacketOverhead(
[email protected]3aa9ca72014-02-27 19:39:43525 version, PACKET_8BYTE_CONNECTION_ID, include_version,
[email protected]ea825e02013-08-21 18:12:45526 sequence_number_length, is_in_fec_group);
[email protected]5351cc4b2013-03-03 07:22:41527}
528
[email protected]8e01c062013-10-31 07:35:31529TestEntropyCalculator::TestEntropyCalculator() { }
530
531TestEntropyCalculator::~TestEntropyCalculator() { }
532
[email protected]48878092013-07-26 14:51:56533QuicPacketEntropyHash TestEntropyCalculator::EntropyHash(
[email protected]9db443912013-02-25 05:27:03534 QuicPacketSequenceNumber sequence_number) const {
535 return 1u;
536}
537
[email protected]8e01c062013-10-31 07:35:31538MockEntropyCalculator::MockEntropyCalculator() { }
539
540MockEntropyCalculator::~MockEntropyCalculator() { }
541
[email protected]b064310782013-05-30 21:12:17542QuicConfig DefaultQuicConfig() {
543 QuicConfig config;
544 config.SetDefaults();
545 return config;
546}
547
[email protected]4d640792013-12-18 22:21:08548QuicVersionVector SupportedVersions(QuicVersion version) {
549 QuicVersionVector versions;
550 versions.push_back(version);
551 return versions;
552}
553
[email protected]8b37a092012-10-18 21:53:49554} // namespace test
[email protected]8b37a092012-10-18 21:53:49555} // namespace net