blob: 4f04266842bb634ff0b26c54a49dc855f1ca3651 [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]cbd731e2013-10-24 00:20:3917#include "net/quic/test_tools/quic_connection_peer.h"
[email protected]c244c5a12013-05-07 20:55:0418#include "net/spdy/spdy_frame_builder.h"
[email protected]8b37a092012-10-18 21:53:4919
[email protected]c244c5a12013-05-07 20:55:0420using base::StringPiece;
[email protected]8b37a092012-10-18 21:53:4921using std::max;
22using std::min;
23using std::string;
[email protected]cff7b7b2013-01-11 08:49:0724using testing::_;
[email protected]8b37a092012-10-18 21:53:4925
26namespace net {
27namespace test {
[email protected]965dbe62013-08-09 21:34:3128namespace {
29
30// No-op alarm implementation used by MockHelper.
31class TestAlarm : public QuicAlarm {
32 public:
33 explicit TestAlarm(QuicAlarm::Delegate* delegate)
34 : QuicAlarm(delegate) {
35 }
36
37 virtual void SetImpl() OVERRIDE {}
38 virtual void CancelImpl() OVERRIDE {}
39};
40
41} // namespace
[email protected]8b37a092012-10-18 21:53:4942
43MockFramerVisitor::MockFramerVisitor() {
44 // By default, we want to accept packets.
[email protected]14e8106c2013-03-14 16:25:3345 ON_CALL(*this, OnProtocolVersionMismatch(_))
46 .WillByDefault(testing::Return(false));
47
48 // By default, we want to accept packets.
[email protected]ec86d5462013-11-17 16:04:4949 ON_CALL(*this, OnUnauthenticatedHeader(_))
50 .WillByDefault(testing::Return(true));
51
[email protected]066d8182014-01-04 02:02:4552 ON_CALL(*this, OnUnauthenticatedPublicHeader(_))
53 .WillByDefault(testing::Return(true));
54
[email protected]cff7b7b2013-01-11 08:49:0755 ON_CALL(*this, OnPacketHeader(_))
[email protected]8b37a092012-10-18 21:53:4956 .WillByDefault(testing::Return(true));
[email protected]a57e0272013-04-26 07:31:4757
58 ON_CALL(*this, OnStreamFrame(_))
59 .WillByDefault(testing::Return(true));
60
61 ON_CALL(*this, OnAckFrame(_))
62 .WillByDefault(testing::Return(true));
63
64 ON_CALL(*this, OnCongestionFeedbackFrame(_))
65 .WillByDefault(testing::Return(true));
66
67 ON_CALL(*this, OnRstStreamFrame(_))
68 .WillByDefault(testing::Return(true));
69
70 ON_CALL(*this, OnConnectionCloseFrame(_))
71 .WillByDefault(testing::Return(true));
72
73 ON_CALL(*this, OnGoAwayFrame(_))
74 .WillByDefault(testing::Return(true));
[email protected]8b37a092012-10-18 21:53:4975}
76
[email protected]044ac2b2012-11-13 21:41:0677MockFramerVisitor::~MockFramerVisitor() {
78}
[email protected]8b37a092012-10-18 21:53:4979
[email protected]48878092013-07-26 14:51:5680bool NoOpFramerVisitor::OnProtocolVersionMismatch(QuicVersion version) {
[email protected]14e8106c2013-03-14 16:25:3381 return false;
82}
83
[email protected]066d8182014-01-04 02:02:4584bool NoOpFramerVisitor::OnUnauthenticatedPublicHeader(
85 const QuicPacketPublicHeader& header) {
86 return true;
87}
88
[email protected]ec86d5462013-11-17 16:04:4989bool NoOpFramerVisitor::OnUnauthenticatedHeader(
90 const QuicPacketHeader& header) {
91 return true;
92}
93
[email protected]8b37a092012-10-18 21:53:4994bool NoOpFramerVisitor::OnPacketHeader(const QuicPacketHeader& header) {
95 return true;
96}
97
[email protected]a57e0272013-04-26 07:31:4798bool NoOpFramerVisitor::OnStreamFrame(const QuicStreamFrame& frame) {
99 return true;
100}
101
102bool NoOpFramerVisitor::OnAckFrame(const QuicAckFrame& frame) {
103 return true;
104}
105
106bool NoOpFramerVisitor::OnCongestionFeedbackFrame(
107 const QuicCongestionFeedbackFrame& frame) {
108 return true;
109}
110
111bool NoOpFramerVisitor::OnRstStreamFrame(
112 const QuicRstStreamFrame& frame) {
113 return true;
114}
115
116bool NoOpFramerVisitor::OnConnectionCloseFrame(
117 const QuicConnectionCloseFrame& frame) {
118 return true;
119}
120
121bool NoOpFramerVisitor::OnGoAwayFrame(const QuicGoAwayFrame& frame) {
122 return true;
123}
124
[email protected]9db443912013-02-25 05:27:03125FramerVisitorCapturingFrames::FramerVisitorCapturingFrames() : frame_count_(0) {
[email protected]134e5c32012-12-12 19:20:36126}
127
[email protected]9db443912013-02-25 05:27:03128FramerVisitorCapturingFrames::~FramerVisitorCapturingFrames() {
[email protected]0ac0c5b2013-11-20 05:55:58129 Reset();
130}
131
132void FramerVisitorCapturingFrames::Reset() {
[email protected]583bcbcf2013-10-28 01:51:15133 STLDeleteElements(&stream_data_);
[email protected]0ac0c5b2013-11-20 05:55:58134 stream_frames_.clear();
135 frame_count_ = 0;
136 ack_.reset();
137 feedback_.reset();
138 rst_.reset();
139 close_.reset();
140 goaway_.reset();
141 version_negotiation_packet_.reset();
[email protected]26f3f8e2012-12-13 21:07:19142}
143
[email protected]9db443912013-02-25 05:27:03144bool FramerVisitorCapturingFrames::OnPacketHeader(
[email protected]4e6f0ed2012-11-02 22:15:38145 const QuicPacketHeader& header) {
146 header_ = header;
[email protected]9db443912013-02-25 05:27:03147 frame_count_ = 0;
[email protected]4e6f0ed2012-11-02 22:15:38148 return true;
149}
150
[email protected]a57e0272013-04-26 07:31:47151bool FramerVisitorCapturingFrames::OnStreamFrame(const QuicStreamFrame& frame) {
[email protected]583bcbcf2013-10-28 01:51:15152 // Make a copy of the frame and store a copy of underlying string, since
153 // frame.data may not exist outside this callback.
[email protected]5dafdb62013-11-14 01:24:26154 stream_data_.push_back(frame.GetDataAsString());
[email protected]583bcbcf2013-10-28 01:51:15155 QuicStreamFrame frame_copy = frame;
[email protected]5dafdb62013-11-14 01:24:26156 frame_copy.data.Clear();
157 frame_copy.data.Append(const_cast<char*>(stream_data_.back()->data()),
158 stream_data_.back()->size());
[email protected]583bcbcf2013-10-28 01:51:15159 stream_frames_.push_back(frame_copy);
[email protected]9db443912013-02-25 05:27:03160 ++frame_count_;
[email protected]a57e0272013-04-26 07:31:47161 return true;
[email protected]26f3f8e2012-12-13 21:07:19162}
163
[email protected]a57e0272013-04-26 07:31:47164bool FramerVisitorCapturingFrames::OnAckFrame(const QuicAckFrame& frame) {
[email protected]9db443912013-02-25 05:27:03165 ack_.reset(new QuicAckFrame(frame));
166 ++frame_count_;
[email protected]a57e0272013-04-26 07:31:47167 return true;
[email protected]9db443912013-02-25 05:27:03168}
169
[email protected]a57e0272013-04-26 07:31:47170bool FramerVisitorCapturingFrames::OnCongestionFeedbackFrame(
[email protected]26f3f8e2012-12-13 21:07:19171 const QuicCongestionFeedbackFrame& frame) {
172 feedback_.reset(new QuicCongestionFeedbackFrame(frame));
[email protected]9db443912013-02-25 05:27:03173 ++frame_count_;
[email protected]a57e0272013-04-26 07:31:47174 return true;
[email protected]9db443912013-02-25 05:27:03175}
176
[email protected]a57e0272013-04-26 07:31:47177bool FramerVisitorCapturingFrames::OnRstStreamFrame(
[email protected]9db443912013-02-25 05:27:03178 const QuicRstStreamFrame& frame) {
179 rst_.reset(new QuicRstStreamFrame(frame));
180 ++frame_count_;
[email protected]a57e0272013-04-26 07:31:47181 return true;
[email protected]9db443912013-02-25 05:27:03182}
183
[email protected]a57e0272013-04-26 07:31:47184bool FramerVisitorCapturingFrames::OnConnectionCloseFrame(
[email protected]9db443912013-02-25 05:27:03185 const QuicConnectionCloseFrame& frame) {
186 close_.reset(new QuicConnectionCloseFrame(frame));
187 ++frame_count_;
[email protected]a57e0272013-04-26 07:31:47188 return true;
[email protected]9db443912013-02-25 05:27:03189}
190
[email protected]a57e0272013-04-26 07:31:47191bool FramerVisitorCapturingFrames::OnGoAwayFrame(const QuicGoAwayFrame& frame) {
[email protected]9db443912013-02-25 05:27:03192 goaway_.reset(new QuicGoAwayFrame(frame));
193 ++frame_count_;
[email protected]a57e0272013-04-26 07:31:47194 return true;
[email protected]4e6f0ed2012-11-02 22:15:38195}
196
[email protected]14e8106c2013-03-14 16:25:33197void FramerVisitorCapturingFrames::OnVersionNegotiationPacket(
198 const QuicVersionNegotiationPacket& packet) {
199 version_negotiation_packet_.reset(new QuicVersionNegotiationPacket(packet));
200 frame_count_ = 0;
201}
202
[email protected]fee17f72013-02-03 07:47:41203FramerVisitorCapturingPublicReset::FramerVisitorCapturingPublicReset() {
204}
205
206FramerVisitorCapturingPublicReset::~FramerVisitorCapturingPublicReset() {
207}
208
209void FramerVisitorCapturingPublicReset::OnPublicResetPacket(
210 const QuicPublicResetPacket& public_reset) {
211 public_reset_packet_ = public_reset;
212}
213
[email protected]8d659e22013-01-19 04:26:10214MockConnectionVisitor::MockConnectionVisitor() {
215}
216
217MockConnectionVisitor::~MockConnectionVisitor() {
218}
219
[email protected]9c0b1352012-11-04 00:03:27220MockHelper::MockHelper() {
221}
222
223MockHelper::~MockHelper() {
224}
225
[email protected]97693d12012-11-16 16:05:00226const QuicClock* MockHelper::GetClock() const {
[email protected]9c0b1352012-11-04 00:03:27227 return &clock_;
228}
229
[email protected]9558c5d32012-12-22 00:08:14230QuicRandom* MockHelper::GetRandomGenerator() {
231 return &random_generator_;
232}
233
[email protected]965dbe62013-08-09 21:34:31234QuicAlarm* MockHelper::CreateAlarm(QuicAlarm::Delegate* delegate) {
235 return new TestAlarm(delegate);
236}
237
[email protected]fe053f92013-04-23 20:18:55238void MockHelper::AdvanceTime(QuicTime::Delta delta) {
239 clock_.AdvanceTime(delta);
240}
241
[email protected]c05a6d222013-12-16 19:42:03242MockConnection::MockConnection(bool is_server)
243 : QuicConnection(kTestGuid,
244 IPEndPoint(Loopback4(), kTestPort),
245 new testing::NiceMock<MockHelper>(),
[email protected]cbd731e2013-10-24 00:20:39246 new testing::NiceMock<MockPacketWriter>(),
[email protected]b007e632013-10-28 08:39:25247 is_server, QuicSupportedVersions()),
[email protected]c05a6d222013-12-16 19:42:03248 writer_(QuicConnectionPeer::GetWriter(this)),
249 helper_(helper()) {
250}
251
252MockConnection::MockConnection(IPEndPoint address,
253 bool is_server)
254 : QuicConnection(kTestGuid, address,
255 new testing::NiceMock<MockHelper>(),
256 new testing::NiceMock<MockPacketWriter>(),
257 is_server, QuicSupportedVersions()),
[email protected]2cfc6bb82013-10-27 03:40:44258 writer_(QuicConnectionPeer::GetWriter(this)),
259 helper_(helper()) {
[email protected]044ac2b2012-11-13 21:41:06260}
261
[email protected]872edd9e2013-01-16 08:51:15262MockConnection::MockConnection(QuicGuid guid,
[email protected]14e8106c2013-03-14 16:25:33263 bool is_server)
[email protected]5d45daa2014-01-02 21:07:46264 : QuicConnection(guid, IPEndPoint(Loopback4(), kTestPort),
[email protected]c05a6d222013-12-16 19:42:03265 new testing::NiceMock<MockHelper>(),
266 new testing::NiceMock<MockPacketWriter>(),
267 is_server, QuicSupportedVersions()),
268 writer_(QuicConnectionPeer::GetWriter(this)),
269 helper_(helper()) {
[email protected]872edd9e2013-01-16 08:51:15270}
271
[email protected]4d640792013-12-18 22:21:08272MockConnection::MockConnection(bool is_server,
273 const QuicVersionVector& supported_versions)
274 : QuicConnection(kTestGuid,
275 IPEndPoint(Loopback4(), kTestPort),
276 new testing::NiceMock<MockHelper>(),
277 new testing::NiceMock<MockPacketWriter>(),
278 is_server, supported_versions),
279 writer_(QuicConnectionPeer::GetWriter(this)),
280 helper_(helper()) {
281}
282
[email protected]044ac2b2012-11-13 21:41:06283MockConnection::~MockConnection() {
284}
285
[email protected]fe053f92013-04-23 20:18:55286void MockConnection::AdvanceTime(QuicTime::Delta delta) {
[email protected]fe053f92013-04-23 20:18:55287 static_cast<MockHelper*>(helper())->AdvanceTime(delta);
288}
289
[email protected]c05a6d222013-12-16 19:42:03290PacketSavingConnection::PacketSavingConnection(bool is_server)
291 : MockConnection(is_server) {
[email protected]044ac2b2012-11-13 21:41:06292}
293
[email protected]4d640792013-12-18 22:21:08294PacketSavingConnection::PacketSavingConnection(
295 bool is_server,
296 const QuicVersionVector& supported_versions)
297 : MockConnection(is_server, supported_versions) {
298}
299
[email protected]044ac2b2012-11-13 21:41:06300PacketSavingConnection::~PacketSavingConnection() {
[email protected]701bc892013-01-17 04:51:54301 STLDeleteElements(&packets_);
[email protected]2532de12013-05-09 12:29:33302 STLDeleteElements(&encrypted_packets_);
[email protected]044ac2b2012-11-13 21:41:06303}
304
[email protected]fee17f72013-02-03 07:47:41305bool PacketSavingConnection::SendOrQueuePacket(
[email protected]8ba81212013-05-03 13:11:48306 EncryptionLevel level,
[email protected]ec86d5462013-11-17 16:04:49307 const SerializedPacket& packet,
308 TransmissionType transmission_type) {
309 packets_.push_back(packet.packet);
[email protected]2532de12013-05-09 12:29:33310 QuicEncryptedPacket* encrypted =
[email protected]ec86d5462013-11-17 16:04:49311 framer_.EncryptPacket(level, packet.sequence_number, *packet.packet);
[email protected]2532de12013-05-09 12:29:33312 encrypted_packets_.push_back(encrypted);
[email protected]044ac2b2012-11-13 21:41:06313 return true;
314}
315
[email protected]c05a6d222013-12-16 19:42:03316MockSession::MockSession(QuicConnection* connection)
317 : QuicSession(connection, DefaultQuicConfig()) {
[email protected]0ac0c5b2013-11-20 05:55:58318 ON_CALL(*this, WritevData(_, _, _, _, _, _))
[email protected]cff7b7b2013-01-11 08:49:07319 .WillByDefault(testing::Return(QuicConsumedData(0, false)));
[email protected]044ac2b2012-11-13 21:41:06320}
321
322MockSession::~MockSession() {
323}
324
[email protected]899951652013-05-16 12:52:39325TestSession::TestSession(QuicConnection* connection,
[email protected]c05a6d222013-12-16 19:42:03326 const QuicConfig& config)
327 : QuicSession(connection, config),
[email protected]2532de12013-05-09 12:29:33328 crypto_stream_(NULL) {
329}
330
[email protected]b064310782013-05-30 21:12:17331TestSession::~TestSession() {}
[email protected]2532de12013-05-09 12:29:33332
333void TestSession::SetCryptoStream(QuicCryptoStream* stream) {
334 crypto_stream_ = stream;
335}
336
337QuicCryptoStream* TestSession::GetCryptoStream() {
338 return crypto_stream_;
339}
340
[email protected]cbd731e2013-10-24 00:20:39341MockPacketWriter::MockPacketWriter() {
342}
343
344MockPacketWriter::~MockPacketWriter() {
345}
346
[email protected]fee17f72013-02-03 07:47:41347MockSendAlgorithm::MockSendAlgorithm() {
[email protected]8d659e22013-01-19 04:26:10348}
349
[email protected]fee17f72013-02-03 07:47:41350MockSendAlgorithm::~MockSendAlgorithm() {
[email protected]8d659e22013-01-19 04:26:10351}
352
[email protected]97cf3022013-09-05 14:30:16353MockAckNotifierDelegate::MockAckNotifierDelegate() {
354}
355
356MockAckNotifierDelegate::~MockAckNotifierDelegate() {
357}
358
[email protected]8b37a092012-10-18 21:53:49359namespace {
360
361string HexDumpWithMarks(const char* data, int length,
362 const bool* marks, int mark_length) {
363 static const char kHexChars[] = "0123456789abcdef";
364 static const int kColumns = 4;
365
366 const int kSizeLimit = 1024;
367 if (length > kSizeLimit || mark_length > kSizeLimit) {
368 LOG(ERROR) << "Only dumping first " << kSizeLimit << " bytes.";
369 length = min(length, kSizeLimit);
370 mark_length = min(mark_length, kSizeLimit);
371 }
372
373 string hex;
374 for (const char* row = data; length > 0;
375 row += kColumns, length -= kColumns) {
376 for (const char *p = row; p < row + 4; ++p) {
377 if (p < row + length) {
378 const bool mark =
379 (marks && (p - data) < mark_length && marks[p - data]);
380 hex += mark ? '*' : ' ';
381 hex += kHexChars[(*p & 0xf0) >> 4];
382 hex += kHexChars[*p & 0x0f];
383 hex += mark ? '*' : ' ';
384 } else {
385 hex += " ";
386 }
387 }
388 hex = hex + " ";
389
390 for (const char *p = row; p < row + 4 && p < row + length; ++p)
391 hex += (*p >= 0x20 && *p <= 0x7f) ? (*p) : '.';
392
393 hex = hex + '\n';
394 }
395 return hex;
396}
397
398} // namespace
399
[email protected]b007e632013-10-28 08:39:25400QuicVersion QuicVersionMax() { return QuicSupportedVersions().front(); }
401
402QuicVersion QuicVersionMin() { return QuicSupportedVersions().back(); }
403
[email protected]c05a6d222013-12-16 19:42:03404IPAddressNumber Loopback4() {
405 net::IPAddressNumber addr;
406 CHECK(net::ParseIPLiteralToNumber("127.0.0.1", &addr));
407 return addr;
408}
409
[email protected]8b37a092012-10-18 21:53:49410void CompareCharArraysWithHexError(
411 const string& description,
412 const char* actual,
413 const int actual_len,
414 const char* expected,
415 const int expected_len) {
[email protected]b007e632013-10-28 08:39:25416 EXPECT_EQ(actual_len, expected_len);
[email protected]8b37a092012-10-18 21:53:49417 const int min_len = min(actual_len, expected_len);
418 const int max_len = max(actual_len, expected_len);
[email protected]4356f0f2013-04-07 00:58:17419 scoped_ptr<bool[]> marks(new bool[max_len]);
[email protected]8b37a092012-10-18 21:53:49420 bool identical = (actual_len == expected_len);
421 for (int i = 0; i < min_len; ++i) {
422 if (actual[i] != expected[i]) {
423 marks[i] = true;
424 identical = false;
425 } else {
426 marks[i] = false;
427 }
428 }
429 for (int i = min_len; i < max_len; ++i) {
430 marks[i] = true;
431 }
432 if (identical) return;
433 ADD_FAILURE()
434 << "Description:\n"
435 << description
436 << "\n\nExpected:\n"
437 << HexDumpWithMarks(expected, expected_len, marks.get(), max_len)
438 << "\nActual:\n"
439 << HexDumpWithMarks(actual, actual_len, marks.get(), max_len);
440}
441
[email protected]b12764d2013-12-02 22:28:30442bool DecodeHexString(const base::StringPiece& hex, std::string* bytes) {
443 bytes->clear();
444 if (hex.empty())
445 return true;
446 std::vector<uint8> v;
447 if (!base::HexStringToBytes(hex.as_string(), &v))
448 return false;
449 if (!v.empty())
450 bytes->assign(reinterpret_cast<const char*>(&v[0]), v.size());
451 return true;
452}
453
[email protected]d3d15bf2013-01-30 02:51:54454static QuicPacket* ConstructPacketFromHandshakeMessage(
455 QuicGuid guid,
[email protected]14e8106c2013-03-14 16:25:33456 const CryptoHandshakeMessage& message,
457 bool should_include_version) {
[email protected]8b37a092012-10-18 21:53:49458 CryptoFramer crypto_framer;
[email protected]dc2cc742012-10-21 13:56:13459 scoped_ptr<QuicData> data(crypto_framer.ConstructHandshakeMessage(message));
[email protected]b007e632013-10-28 08:39:25460 QuicFramer quic_framer(QuicSupportedVersions(), QuicTime::Zero(), false);
[email protected]8b37a092012-10-18 21:53:49461
462 QuicPacketHeader header;
[email protected]c995c572013-01-18 05:43:20463 header.public_header.guid = guid;
[email protected]9db443912013-02-25 05:27:03464 header.public_header.reset_flag = false;
[email protected]14e8106c2013-03-14 16:25:33465 header.public_header.version_flag = should_include_version;
[email protected]8b37a092012-10-18 21:53:49466 header.packet_sequence_number = 1;
[email protected]9db443912013-02-25 05:27:03467 header.entropy_flag = false;
468 header.entropy_hash = 0;
469 header.fec_flag = false;
[email protected]8b37a092012-10-18 21:53:49470 header.fec_group = 0;
471
[email protected]be24ab22012-10-22 03:01:52472 QuicStreamFrame stream_frame(kCryptoStreamId, false, 0,
[email protected]5dafdb62013-11-14 01:24:26473 MakeIOVector(data->AsStringPiece()));
[email protected]8b37a092012-10-18 21:53:49474
[email protected]be24ab22012-10-22 03:01:52475 QuicFrame frame(&stream_frame);
476 QuicFrames frames;
477 frames.push_back(frame);
[email protected]3e60db82013-08-05 19:43:06478 return quic_framer.BuildUnsizedDataPacket(header, frames).packet;
[email protected]8b37a092012-10-18 21:53:49479}
480
[email protected]2532de12013-05-09 12:29:33481QuicPacket* ConstructHandshakePacket(QuicGuid guid, QuicTag tag) {
[email protected]d3d15bf2013-01-30 02:51:54482 CryptoHandshakeMessage message;
[email protected]ccc66e8a2013-03-26 08:26:14483 message.set_tag(tag);
[email protected]14e8106c2013-03-14 16:25:33484 return ConstructPacketFromHandshakeMessage(guid, message, false);
[email protected]d3d15bf2013-01-30 02:51:54485}
486
[email protected]ea825e02013-08-21 18:12:45487size_t GetPacketLengthForOneStream(
488 QuicVersion version,
489 bool include_version,
490 QuicSequenceNumberLength sequence_number_length,
491 InFecGroup is_in_fec_group,
492 size_t* payload_length) {
[email protected]f62262b2013-07-05 20:57:30493 *payload_length = 1;
494 const size_t stream_length =
[email protected]5dafdb62013-11-14 01:24:26495 NullEncrypter().GetCiphertextSize(*payload_length) +
[email protected]b064310782013-05-30 21:12:17496 QuicPacketCreator::StreamFramePacketOverhead(
[email protected]3e60db82013-08-05 19:43:06497 version, PACKET_8BYTE_GUID, include_version,
[email protected]ea825e02013-08-21 18:12:45498 sequence_number_length, is_in_fec_group);
[email protected]5dafdb62013-11-14 01:24:26499 const size_t ack_length = NullEncrypter().GetCiphertextSize(
[email protected]8e01c062013-10-31 07:35:31500 QuicFramer::GetMinAckFrameSize(
501 version, sequence_number_length, PACKET_1BYTE_SEQUENCE_NUMBER)) +
[email protected]25c31dc2013-06-05 17:56:04502 GetPacketHeaderSize(PACKET_8BYTE_GUID, include_version,
[email protected]ea825e02013-08-21 18:12:45503 sequence_number_length, is_in_fec_group);
[email protected]f62262b2013-07-05 20:57:30504 if (stream_length < ack_length) {
505 *payload_length = 1 + ack_length - stream_length;
506 }
507
[email protected]5dafdb62013-11-14 01:24:26508 return NullEncrypter().GetCiphertextSize(*payload_length) +
[email protected]f62262b2013-07-05 20:57:30509 QuicPacketCreator::StreamFramePacketOverhead(
[email protected]3e60db82013-08-05 19:43:06510 version, PACKET_8BYTE_GUID, include_version,
[email protected]ea825e02013-08-21 18:12:45511 sequence_number_length, is_in_fec_group);
[email protected]5351cc4b2013-03-03 07:22:41512}
513
[email protected]ea2ab47b2013-08-13 00:44:11514// Size in bytes of the stream frame fields for an arbitrary StreamID and
515// offset and the last frame in a packet.
[email protected]3e60db82013-08-05 19:43:06516size_t GetMinStreamFrameSize(QuicVersion version) {
[email protected]ea2ab47b2013-08-13 00:44:11517 return kQuicFrameTypeSize + kQuicMaxStreamIdSize + kQuicMaxStreamOffsetSize;
[email protected]3e60db82013-08-05 19:43:06518}
519
[email protected]8e01c062013-10-31 07:35:31520TestEntropyCalculator::TestEntropyCalculator() { }
521
522TestEntropyCalculator::~TestEntropyCalculator() { }
523
[email protected]48878092013-07-26 14:51:56524QuicPacketEntropyHash TestEntropyCalculator::EntropyHash(
[email protected]9db443912013-02-25 05:27:03525 QuicPacketSequenceNumber sequence_number) const {
526 return 1u;
527}
528
[email protected]8e01c062013-10-31 07:35:31529MockEntropyCalculator::MockEntropyCalculator() { }
530
531MockEntropyCalculator::~MockEntropyCalculator() { }
532
[email protected]b064310782013-05-30 21:12:17533QuicConfig DefaultQuicConfig() {
534 QuicConfig config;
535 config.SetDefaults();
536 return config;
537}
538
[email protected]4d640792013-12-18 22:21:08539QuicVersionVector SupportedVersions(QuicVersion version) {
540 QuicVersionVector versions;
541 versions.push_back(version);
542 return versions;
543}
544
[email protected]c244c5a12013-05-07 20:55:04545bool TestDecompressorVisitor::OnDecompressedData(StringPiece data) {
546 data.AppendToString(&data_);
547 return true;
548}
549
[email protected]899951652013-05-16 12:52:39550void TestDecompressorVisitor::OnDecompressionError() {
551 error_ = true;
552}
553
[email protected]8b37a092012-10-18 21:53:49554} // namespace test
[email protected]8b37a092012-10-18 21:53:49555} // namespace net