Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(461)

Side by Side Diff: net/quic/quic_framer_test.cc

Issue 22311013: Removing QUIC's VERSION_6, now that QUIC no longer needs to support the (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Sync with trunk Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_framer.cc ('k') | net/quic/quic_protocol.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <map> 6 #include <map>
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
(...skipping 25 matching lines...) Expand all
36 const QuicPacketSequenceNumber kEpoch = GG_UINT64_C(1) << 48; 36 const QuicPacketSequenceNumber kEpoch = GG_UINT64_C(1) << 48;
37 const QuicPacketSequenceNumber kMask = kEpoch - 1; 37 const QuicPacketSequenceNumber kMask = kEpoch - 1;
38 38
39 // Index into the flags offset in the header. 39 // Index into the flags offset in the header.
40 const size_t kPublicFlagsOffset = 0; 40 const size_t kPublicFlagsOffset = 0;
41 // Index into the guid offset in the header. 41 // Index into the guid offset in the header.
42 const size_t kGuidOffset = kPublicFlagsSize; 42 const size_t kGuidOffset = kPublicFlagsSize;
43 // Index into the version string in the header. (if present). 43 // Index into the version string in the header. (if present).
44 const size_t kVersionOffset = kGuidOffset + PACKET_8BYTE_GUID; 44 const size_t kVersionOffset = kGuidOffset + PACKET_8BYTE_GUID;
45 45
46 // Size in bytes of the stream frame fields for an arbitrary StreamID and
47 // offset and the last frame in a packet.
48 // Index into the sequence number offset in the header. 46 // Index into the sequence number offset in the header.
49 size_t GetSequenceNumberOffset(QuicGuidLength guid_length, 47 size_t GetSequenceNumberOffset(QuicGuidLength guid_length,
50 bool include_version) { 48 bool include_version) {
51 return kGuidOffset + guid_length + 49 return kGuidOffset + guid_length +
52 (include_version ? kQuicVersionSize : 0); 50 (include_version ? kQuicVersionSize : 0);
53 } 51 }
54 52
55 size_t GetSequenceNumberOffset(bool include_version) { 53 size_t GetSequenceNumberOffset(bool include_version) {
56 return GetSequenceNumberOffset(PACKET_8BYTE_GUID, include_version); 54 return GetSequenceNumberOffset(PACKET_8BYTE_GUID, include_version);
57 } 55 }
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 412
415 test::TestEncrypter* encrypter_; 413 test::TestEncrypter* encrypter_;
416 test::TestDecrypter* decrypter_; 414 test::TestDecrypter* decrypter_;
417 QuicVersion version_; 415 QuicVersion version_;
418 QuicTime start_; 416 QuicTime start_;
419 QuicFramer framer_; 417 QuicFramer framer_;
420 test::TestQuicVisitor visitor_; 418 test::TestQuicVisitor visitor_;
421 test::TestEntropyCalculator entropy_calculator_; 419 test::TestEntropyCalculator entropy_calculator_;
422 }; 420 };
423 421
424 // Run all framer tests with QUIC version 6 and 7. 422 // Run all framer tests with all supported versions of QUIC.
425 INSTANTIATE_TEST_CASE_P(QuicFramerTests, 423 INSTANTIATE_TEST_CASE_P(QuicFramerTests,
426 QuicFramerTest, 424 QuicFramerTest,
427 ::testing::Values(QUIC_VERSION_6, QUIC_VERSION_7)); 425 ::testing::ValuesIn(kSupportedQuicVersions));
428 426
429 TEST_P(QuicFramerTest, CalculatePacketSequenceNumberFromWireNearEpochStart) { 427 TEST_P(QuicFramerTest, CalculatePacketSequenceNumberFromWireNearEpochStart) {
430 // A few quick manual sanity checks 428 // A few quick manual sanity checks
431 CheckCalculatePacketSequenceNumber(GG_UINT64_C(1), GG_UINT64_C(0)); 429 CheckCalculatePacketSequenceNumber(GG_UINT64_C(1), GG_UINT64_C(0));
432 CheckCalculatePacketSequenceNumber(kEpoch + 1, kMask); 430 CheckCalculatePacketSequenceNumber(kEpoch + 1, kMask);
433 CheckCalculatePacketSequenceNumber(kEpoch, kMask); 431 CheckCalculatePacketSequenceNumber(kEpoch, kMask);
434 432
435 // Cases where the last number was close to the start of the range 433 // Cases where the last number was close to the start of the range
436 for (uint64 last = 0; last < 10; last++) { 434 for (uint64 last = 0; last < 10; last++) {
437 // Small numbers should not wrap (even if they're out of order). 435 // Small numbers should not wrap (even if they're out of order).
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 0x98, 0xBA, 0xDC, 0xFE, 1089 0x98, 0xBA, 0xDC, 0xFE,
1092 // version tag 1090 // version tag
1093 'Q', '0', '0', '0', 1091 'Q', '0', '0', '0',
1094 // packet sequence number 1092 // packet sequence number
1095 0xBC, 0x9A, 0x78, 0x56, 1093 0xBC, 0x9A, 0x78, 0x56,
1096 0x34, 0x12, 1094 0x34, 0x12,
1097 // private flags 1095 // private flags
1098 0x00, 1096 0x00,
1099 1097
1100 // frame type (padding frame) 1098 // frame type (padding frame)
1101 static_cast<unsigned char>((version_ == QUIC_VERSION_6) ? 0x00 : 0x07), 1099 0x07,
1102 }; 1100 };
1103 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1101 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1104 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1102 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1105 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1103 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1106 ASSERT_TRUE(visitor_.header_.get()); 1104 ASSERT_TRUE(visitor_.header_.get());
1107 EXPECT_EQ(0, visitor_.frame_count_); 1105 EXPECT_EQ(0, visitor_.frame_count_);
1108 EXPECT_EQ(1, visitor_.version_mismatch_); 1106 EXPECT_EQ(1, visitor_.version_mismatch_);
1109 }; 1107 };
1110 1108
1111 TEST_P(QuicFramerTest, InvalidPrivateFlag) { 1109 TEST_P(QuicFramerTest, InvalidPrivateFlag) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 // guid 1172 // guid
1175 0x10, 0x32, 0x54, 0x76, 1173 0x10, 0x32, 0x54, 0x76,
1176 0x98, 0xBA, 0xDC, 0xFE, 1174 0x98, 0xBA, 0xDC, 0xFE,
1177 // packet sequence number 1175 // packet sequence number
1178 0xBC, 0x9A, 0x78, 0x56, 1176 0xBC, 0x9A, 0x78, 0x56,
1179 0x34, 0x12, 1177 0x34, 0x12,
1180 // private flags 1178 // private flags
1181 0x00, 1179 0x00,
1182 1180
1183 // frame type (padding frame) 1181 // frame type (padding frame)
1184 static_cast<unsigned char>((version_ == QUIC_VERSION_6) ? 0x00 : 0x07), 1182 0x07,
1185 // Ignored data (which in this case is a stream frame) 1183 // Ignored data (which in this case is a stream frame)
1186 0x01, 1184 0x01,
1187 0x04, 0x03, 0x02, 0x01, 1185 0x04, 0x03, 0x02, 0x01,
1188 0x01, 1186 0x01,
1189 0x54, 0x76, 0x10, 0x32, 1187 0x54, 0x76, 0x10, 0x32,
1190 0xDC, 0xFE, 0x98, 0xBA, 1188 0xDC, 0xFE, 0x98, 0xBA,
1191 0x0c, 0x00, 1189 0x0c, 0x00,
1192 'h', 'e', 'l', 'l', 1190 'h', 'e', 'l', 'l',
1193 'o', ' ', 'w', 'o', 1191 'o', ' ', 'w', 'o',
1194 'r', 'l', 'd', '!', 1192 'r', 'l', 'd', '!',
1195 }; 1193 };
1196 1194
1197 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 1195 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1198 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 1196 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1199 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1197 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1200 ASSERT_TRUE(visitor_.header_.get()); 1198 ASSERT_TRUE(visitor_.header_.get());
1201 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 1199 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1202 1200
1203 ASSERT_EQ(0u, visitor_.stream_frames_.size()); 1201 ASSERT_EQ(0u, visitor_.stream_frames_.size());
1204 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1202 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1205 // A packet with no frames is not acceptable. 1203 // A packet with no frames is not acceptable.
1206 CheckProcessingFails( 1204 CheckProcessingFails(
1207 packet, 1205 packet,
1208 GetPacketHeaderSize(PACKET_8BYTE_GUID, !kIncludeVersion, 1206 GetPacketHeaderSize(PACKET_8BYTE_GUID, !kIncludeVersion,
1209 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 1207 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
1210 "Unable to read frame type.", QUIC_INVALID_FRAME_DATA); 1208 "Unable to read frame type.", QUIC_INVALID_FRAME_DATA);
1211 } 1209 }
1212 1210
1213 TEST_P(QuicFramerTest, StreamFrameVersion6) { 1211 TEST_P(QuicFramerTest, StreamFrame) {
1214 // Set a specific version.
1215 framer_.set_version(QUIC_VERSION_6);
1216
1217 unsigned char packet[] = { 1212 unsigned char packet[] = {
1218 // public flags (8 byte guid) 1213 // public flags (8 byte guid)
1219 0x3C, 1214 0x3C,
1220 // guid
1221 0x10, 0x32, 0x54, 0x76,
1222 0x98, 0xBA, 0xDC, 0xFE,
1223 // packet sequence number
1224 0xBC, 0x9A, 0x78, 0x56,
1225 0x34, 0x12,
1226 // private flags
1227 0x00,
1228
1229 // frame type (stream frame)
1230 0x01,
1231 // stream id
1232 0x04, 0x03, 0x02, 0x01,
1233 // fin
1234 0x01,
1235 // offset
1236 0x54, 0x76, 0x10, 0x32,
1237 0xDC, 0xFE, 0x98, 0xBA,
1238 // data length
1239 0x0c, 0x00,
1240 // data
1241 'h', 'e', 'l', 'l',
1242 'o', ' ', 'w', 'o',
1243 'r', 'l', 'd', '!',
1244 };
1245
1246 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1247 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1248
1249 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1250 ASSERT_TRUE(visitor_.header_.get());
1251 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1252
1253 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1254 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1255 EXPECT_EQ(static_cast<uint64>(0x01020304),
1256 visitor_.stream_frames_[0]->stream_id);
1257 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1258 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1259 visitor_.stream_frames_[0]->offset);
1260 EXPECT_EQ("hello world!", visitor_.stream_frames_[0]->data);
1261
1262 // Now test framing boundaries
1263 for (size_t i = 0; i < GetMinStreamFrameSize(framer_.version()); ++i) {
1264 string expected_error;
1265 if (i < kQuicFrameTypeSize) {
1266 expected_error = "Unable to read frame type.";
1267 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) {
1268 expected_error = "Unable to read stream_id.";
1269 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize +
1270 kQuicStreamFinSize) {
1271 expected_error = "Unable to read fin.";
1272 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize +
1273 kQuicStreamFinSize + kQuicMaxStreamOffsetSize) {
1274 expected_error = "Unable to read offset.";
1275 } else {
1276 expected_error = "Unable to read frame data.";
1277 }
1278 CheckProcessingFails(
1279 packet,
1280 i + GetPacketHeaderSize(PACKET_8BYTE_GUID, !kIncludeVersion,
1281 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
1282 expected_error, QUIC_INVALID_FRAME_DATA);
1283 }
1284 }
1285
1286 TEST_P(QuicFramerTest, StreamFrame) {
1287 // Set a specific version.
1288 framer_.set_version(QUIC_VERSION_7);
1289
1290 unsigned char packet[] = {
1291 // public flags (8 byte guid)
1292 0x3C,
1293 // guid 1215 // guid
1294 0x10, 0x32, 0x54, 0x76, 1216 0x10, 0x32, 0x54, 0x76,
1295 0x98, 0xBA, 0xDC, 0xFE, 1217 0x98, 0xBA, 0xDC, 0xFE,
1296 // packet sequence number 1218 // packet sequence number
1297 0xBC, 0x9A, 0x78, 0x56, 1219 0xBC, 0x9A, 0x78, 0x56,
1298 0x34, 0x12, 1220 0x34, 0x12,
1299 // private flags 1221 // private flags
1300 0x00, 1222 0x00,
1301 1223
1302 // frame type (stream frame with fin) 1224 // frame type (stream frame with fin)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 } 1269 }
1348 CheckProcessingFails( 1270 CheckProcessingFails(
1349 packet, 1271 packet,
1350 i + GetPacketHeaderSize(PACKET_8BYTE_GUID, !kIncludeVersion, 1272 i + GetPacketHeaderSize(PACKET_8BYTE_GUID, !kIncludeVersion,
1351 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 1273 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
1352 expected_error, QUIC_INVALID_FRAME_DATA); 1274 expected_error, QUIC_INVALID_FRAME_DATA);
1353 } 1275 }
1354 } 1276 }
1355 1277
1356 TEST_P(QuicFramerTest, StreamFrame3ByteStreamId) { 1278 TEST_P(QuicFramerTest, StreamFrame3ByteStreamId) {
1357 // Set a specific version.
1358 framer_.set_version(QUIC_VERSION_7);
1359
1360 unsigned char packet[] = { 1279 unsigned char packet[] = {
1361 // public flags (8 byte guid) 1280 // public flags (8 byte guid)
1362 0x3C, 1281 0x3C,
1363 // guid 1282 // guid
1364 0x10, 0x32, 0x54, 0x76, 1283 0x10, 0x32, 0x54, 0x76,
1365 0x98, 0xBA, 0xDC, 0xFE, 1284 0x98, 0xBA, 0xDC, 0xFE,
1366 // packet sequence number 1285 // packet sequence number
1367 0xBC, 0x9A, 0x78, 0x56, 1286 0xBC, 0x9A, 0x78, 0x56,
1368 0x34, 0x12, 1287 0x34, 0x12,
1369 // private flags 1288 // private flags
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 } 1337 }
1419 CheckProcessingFails( 1338 CheckProcessingFails(
1420 packet, 1339 packet,
1421 i + GetPacketHeaderSize(PACKET_8BYTE_GUID, !kIncludeVersion, 1340 i + GetPacketHeaderSize(PACKET_8BYTE_GUID, !kIncludeVersion,
1422 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 1341 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
1423 expected_error, QUIC_INVALID_FRAME_DATA); 1342 expected_error, QUIC_INVALID_FRAME_DATA);
1424 } 1343 }
1425 } 1344 }
1426 1345
1427 TEST_P(QuicFramerTest, StreamFrame2ByteStreamId) { 1346 TEST_P(QuicFramerTest, StreamFrame2ByteStreamId) {
1428 // Set a specific version.
1429 framer_.set_version(QUIC_VERSION_7);
1430
1431 unsigned char packet[] = { 1347 unsigned char packet[] = {
1432 // public flags (8 byte guid) 1348 // public flags (8 byte guid)
1433 0x3C, 1349 0x3C,
1434 // guid 1350 // guid
1435 0x10, 0x32, 0x54, 0x76, 1351 0x10, 0x32, 0x54, 0x76,
1436 0x98, 0xBA, 0xDC, 0xFE, 1352 0x98, 0xBA, 0xDC, 0xFE,
1437 // packet sequence number 1353 // packet sequence number
1438 0xBC, 0x9A, 0x78, 0x56, 1354 0xBC, 0x9A, 0x78, 0x56,
1439 0x34, 0x12, 1355 0x34, 0x12,
1440 // private flags 1356 // private flags
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1489 } 1405 }
1490 CheckProcessingFails( 1406 CheckProcessingFails(
1491 packet, 1407 packet,
1492 i + GetPacketHeaderSize(PACKET_8BYTE_GUID, !kIncludeVersion, 1408 i + GetPacketHeaderSize(PACKET_8BYTE_GUID, !kIncludeVersion,
1493 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 1409 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
1494 expected_error, QUIC_INVALID_FRAME_DATA); 1410 expected_error, QUIC_INVALID_FRAME_DATA);
1495 } 1411 }
1496 } 1412 }
1497 1413
1498 TEST_P(QuicFramerTest, StreamFrame1ByteStreamId) { 1414 TEST_P(QuicFramerTest, StreamFrame1ByteStreamId) {
1499 // Set a specific version.
1500 framer_.set_version(QUIC_VERSION_7);
1501
1502 unsigned char packet[] = { 1415 unsigned char packet[] = {
1503 // public flags (8 byte guid) 1416 // public flags (8 byte guid)
1504 0x3C, 1417 0x3C,
1505 // guid 1418 // guid
1506 0x10, 0x32, 0x54, 0x76, 1419 0x10, 0x32, 0x54, 0x76,
1507 0x98, 0xBA, 0xDC, 0xFE, 1420 0x98, 0xBA, 0xDC, 0xFE,
1508 // packet sequence number 1421 // packet sequence number
1509 0xBC, 0x9A, 0x78, 0x56, 1422 0xBC, 0x9A, 0x78, 0x56,
1510 0x34, 0x12, 1423 0x34, 0x12,
1511 // private flags 1424 // private flags
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1559 expected_error = "Unable to read frame data."; 1472 expected_error = "Unable to read frame data.";
1560 } 1473 }
1561 CheckProcessingFails( 1474 CheckProcessingFails(
1562 packet, 1475 packet,
1563 i + GetPacketHeaderSize(PACKET_8BYTE_GUID, !kIncludeVersion, 1476 i + GetPacketHeaderSize(PACKET_8BYTE_GUID, !kIncludeVersion,
1564 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 1477 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
1565 expected_error, QUIC_INVALID_FRAME_DATA); 1478 expected_error, QUIC_INVALID_FRAME_DATA);
1566 } 1479 }
1567 } 1480 }
1568 1481
1569 TEST_P(QuicFramerTest, StreamFrameWithVersion6) {
1570 // Set a specific version.
1571 framer_.set_version(QUIC_VERSION_6);
1572
1573 unsigned char packet[] = {
1574 // public flags (version, 8 byte guid)
1575 0x3D,
1576 // guid
1577 0x10, 0x32, 0x54, 0x76,
1578 0x98, 0xBA, 0xDC, 0xFE,
1579 // version tag
1580 'Q', '0', '0', '6',
1581 // packet sequence number
1582 0xBC, 0x9A, 0x78, 0x56,
1583 0x34, 0x12,
1584 // private flags
1585 0x00,
1586
1587 // frame type (stream frame)
1588 0x01,
1589 // stream id
1590 0x04, 0x03, 0x02, 0x01,
1591 // fin
1592 0x01,
1593 // offset
1594 0x54, 0x76, 0x10, 0x32,
1595 0xDC, 0xFE, 0x98, 0xBA,
1596 // data length
1597 0x0c, 0x00,
1598 // data
1599 'h', 'e', 'l', 'l',
1600 'o', ' ', 'w', 'o',
1601 'r', 'l', 'd', '!',
1602 };
1603
1604 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1605 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1606
1607 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1608 ASSERT_TRUE(visitor_.header_.get());
1609 EXPECT_TRUE(visitor_.header_.get()->public_header.version_flag);
1610 EXPECT_EQ(QUIC_VERSION_6, visitor_.header_.get()->public_header.versions[0]);
1611 EXPECT_TRUE(CheckDecryption(encrypted, kIncludeVersion));
1612
1613 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1614 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1615 EXPECT_EQ(static_cast<uint64>(0x01020304),
1616 visitor_.stream_frames_[0]->stream_id);
1617 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1618 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1619 visitor_.stream_frames_[0]->offset);
1620 EXPECT_EQ("hello world!", visitor_.stream_frames_[0]->data);
1621
1622 // Now test framing boundaries
1623 for (size_t i = 0; i < GetMinStreamFrameSize(framer_.version()); ++i) {
1624 string expected_error;
1625 if (i < kQuicFrameTypeSize) {
1626 expected_error = "Unable to read frame type.";
1627 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) {
1628 expected_error = "Unable to read stream_id.";
1629 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize +
1630 kQuicStreamFinSize) {
1631 expected_error = "Unable to read fin.";
1632 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize +
1633 kQuicStreamFinSize + kQuicMaxStreamOffsetSize) {
1634 expected_error = "Unable to read offset.";
1635 } else {
1636 expected_error = "Unable to read frame data.";
1637 }
1638 CheckProcessingFails(
1639 packet,
1640 i + GetPacketHeaderSize(PACKET_8BYTE_GUID, kIncludeVersion,
1641 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
1642 expected_error, QUIC_INVALID_FRAME_DATA);
1643 }
1644 }
1645
1646 TEST_P(QuicFramerTest, StreamFrameWithVersion) { 1482 TEST_P(QuicFramerTest, StreamFrameWithVersion) {
1647 // Set a specific version. 1483 // Set a specific version.
1648 framer_.set_version(QUIC_VERSION_7); 1484 framer_.set_version(QUIC_VERSION_7);
1649 1485
1650 unsigned char packet[] = { 1486 unsigned char packet[] = {
1651 // public flags (version, 8 byte guid) 1487 // public flags (version, 8 byte guid)
1652 0x3D, 1488 0x3D,
1653 // guid 1489 // guid
1654 0x10, 0x32, 0x54, 0x76, 1490 0x10, 0x32, 0x54, 0x76,
1655 0x98, 0xBA, 0xDC, 0xFE, 1491 0x98, 0xBA, 0xDC, 0xFE,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1750 1586
1751 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 1587 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1752 ASSERT_TRUE(visitor_.header_.get()); 1588 ASSERT_TRUE(visitor_.header_.get());
1753 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 1589 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1754 1590
1755 ASSERT_EQ(0u, visitor_.stream_frames_.size()); 1591 ASSERT_EQ(0u, visitor_.stream_frames_.size());
1756 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1592 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1757 } 1593 }
1758 1594
1759 TEST_P(QuicFramerTest, RevivedStreamFrame) { 1595 TEST_P(QuicFramerTest, RevivedStreamFrame) {
1760 // Set a specific version.
1761 framer_.set_version(QUIC_VERSION_7);
1762
1763 unsigned char payload[] = { 1596 unsigned char payload[] = {
1764 // frame type (stream frame with fin) 1597 // frame type (stream frame with fin)
1765 0xFE, 1598 0xFE,
1766 // stream id 1599 // stream id
1767 0x04, 0x03, 0x02, 0x01, 1600 0x04, 0x03, 0x02, 0x01,
1768 // offset 1601 // offset
1769 0x54, 0x76, 0x10, 0x32, 1602 0x54, 0x76, 0x10, 0x32,
1770 0xDC, 0xFE, 0x98, 0xBA, 1603 0xDC, 0xFE, 0x98, 0xBA,
1771 // data length 1604 // data length
1772 0x0c, 0x00, 1605 0x0c, 0x00,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1807 EXPECT_EQ(0x00u, visitor_.header_->fec_group); 1640 EXPECT_EQ(0x00u, visitor_.header_->fec_group);
1808 1641
1809 ASSERT_EQ(1u, visitor_.stream_frames_.size()); 1642 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1810 EXPECT_EQ(0u, visitor_.ack_frames_.size()); 1643 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1811 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id); 1644 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id);
1812 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); 1645 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1813 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654), 1646 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1814 visitor_.stream_frames_[0]->offset); 1647 visitor_.stream_frames_[0]->offset);
1815 EXPECT_EQ("hello world!", visitor_.stream_frames_[0]->data); 1648 EXPECT_EQ("hello world!", visitor_.stream_frames_[0]->data);
1816 } 1649 }
1817 TEST_P(QuicFramerTest, StreamFrameInFecGroupVersion6) {
1818 // Set a specific version.
1819 framer_.set_version(QUIC_VERSION_6);
1820
1821 unsigned char packet[] = {
1822 // public flags (8 byte guid)
1823 0x3C,
1824 // guid
1825 0x10, 0x32, 0x54, 0x76,
1826 0x98, 0xBA, 0xDC, 0xFE,
1827 // packet sequence number
1828 0xBC, 0x9A, 0x78, 0x56,
1829 0x12, 0x34,
1830 // private flags (fec group)
1831 0x02,
1832 // first fec protected packet offset
1833 0x02,
1834
1835 // frame type (stream frame)
1836 0x01,
1837 // stream id
1838 0x04, 0x03, 0x02, 0x01,
1839 // fin
1840 0x01,
1841 // offset
1842 0x54, 0x76, 0x10, 0x32,
1843 0xDC, 0xFE, 0x98, 0xBA,
1844 // data length
1845 0x0c, 0x00,
1846 // data
1847 'h', 'e', 'l', 'l',
1848 'o', ' ', 'w', 'o',
1849 'r', 'l', 'd', '!',
1850 };
1851
1852 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
1853 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
1854
1855 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
1856 ASSERT_TRUE(visitor_.header_.get());
1857 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
1858 EXPECT_EQ(IN_FEC_GROUP, visitor_.header_->is_in_fec_group);
1859 EXPECT_EQ(GG_UINT64_C(0x341256789ABA),
1860 visitor_.header_->fec_group);
1861 const size_t fec_offset = GetStartOfFecProtectedData(
1862 PACKET_8BYTE_GUID, !kIncludeVersion, PACKET_6BYTE_SEQUENCE_NUMBER);
1863 EXPECT_EQ(
1864 string(AsChars(packet) + fec_offset, arraysize(packet) - fec_offset),
1865 visitor_.fec_protected_payload_);
1866
1867 ASSERT_EQ(1u, visitor_.stream_frames_.size());
1868 EXPECT_EQ(0u, visitor_.ack_frames_.size());
1869 EXPECT_EQ(GG_UINT64_C(0x01020304), visitor_.stream_frames_[0]->stream_id);
1870 EXPECT_TRUE(visitor_.stream_frames_[0]->fin);
1871 EXPECT_EQ(GG_UINT64_C(0xBA98FEDC32107654),
1872 visitor_.stream_frames_[0]->offset);
1873 EXPECT_EQ("hello world!", visitor_.stream_frames_[0]->data);
1874 }
1875 1650
1876 TEST_P(QuicFramerTest, StreamFrameInFecGroup) { 1651 TEST_P(QuicFramerTest, StreamFrameInFecGroup) {
1877 // Set a specific version. 1652 // Set a specific version.
1878 framer_.set_version(QUIC_VERSION_7); 1653 framer_.set_version(QUIC_VERSION_7);
1879 1654
1880 unsigned char packet[] = { 1655 unsigned char packet[] = {
1881 // public flags (8 byte guid) 1656 // public flags (8 byte guid)
1882 0x3C, 1657 0x3C,
1883 // guid 1658 // guid
1884 0x10, 0x32, 0x54, 0x76, 1659 0x10, 0x32, 0x54, 0x76,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1937 // guid 1712 // guid
1938 0x10, 0x32, 0x54, 0x76, 1713 0x10, 0x32, 0x54, 0x76,
1939 0x98, 0xBA, 0xDC, 0xFE, 1714 0x98, 0xBA, 0xDC, 0xFE,
1940 // packet sequence number 1715 // packet sequence number
1941 0xBC, 0x9A, 0x78, 0x56, 1716 0xBC, 0x9A, 0x78, 0x56,
1942 0x34, 0x12, 1717 0x34, 0x12,
1943 // private flags 1718 // private flags
1944 0x00, 1719 0x00,
1945 1720
1946 // frame type (ack frame) 1721 // frame type (ack frame)
1947 static_cast<unsigned char>((version_ == QUIC_VERSION_6) ? 0x02 : 0x01), 1722 static_cast<unsigned char>(0x01),
1948 // entropy hash of sent packets till least awaiting - 1. 1723 // entropy hash of sent packets till least awaiting - 1.
1949 0xAB, 1724 0xAB,
1950 // least packet sequence number awaiting an ack 1725 // least packet sequence number awaiting an ack
1951 0xA0, 0x9A, 0x78, 0x56, 1726 0xA0, 0x9A, 0x78, 0x56,
1952 0x34, 0x12, 1727 0x34, 0x12,
1953 // entropy hash of all received packets. 1728 // entropy hash of all received packets.
1954 0xBA, 1729 0xBA,
1955 // largest observed packet sequence number 1730 // largest observed packet sequence number
1956 0xBF, 0x9A, 0x78, 0x56, 1731 0xBF, 0x9A, 0x78, 0x56,
1957 0x34, 0x12, 1732 0x34, 0x12,
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
2269 // guid 2044 // guid
2270 0x10, 0x32, 0x54, 0x76, 2045 0x10, 0x32, 0x54, 0x76,
2271 0x98, 0xBA, 0xDC, 0xFE, 2046 0x98, 0xBA, 0xDC, 0xFE,
2272 // packet sequence number 2047 // packet sequence number
2273 0xBC, 0x9A, 0x78, 0x56, 2048 0xBC, 0x9A, 0x78, 0x56,
2274 0x34, 0x12, 2049 0x34, 0x12,
2275 // private flags 2050 // private flags
2276 0x00, 2051 0x00,
2277 2052
2278 // frame type (rst stream frame) 2053 // frame type (rst stream frame)
2279 static_cast<unsigned char>((version_ == QUIC_VERSION_6) ? 0x04 : 0x27), 2054 static_cast<unsigned char>(0x27),
2280 // stream id 2055 // stream id
2281 0x04, 0x03, 0x02, 0x01, 2056 0x04, 0x03, 0x02, 0x01,
2282 // error code 2057 // error code
2283 0x01, 0x00, 0x00, 0x00, 2058 0x01, 0x00, 0x00, 0x00,
2284 2059
2285 // error details length 2060 // error details length
2286 0x0d, 0x00, 2061 0x0d, 0x00,
2287 // error details 2062 // error details
2288 'b', 'e', 'c', 'a', 2063 'b', 'e', 'c', 'a',
2289 'u', 's', 'e', ' ', 2064 'u', 's', 'e', ' ',
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2328 // guid 2103 // guid
2329 0x10, 0x32, 0x54, 0x76, 2104 0x10, 0x32, 0x54, 0x76,
2330 0x98, 0xBA, 0xDC, 0xFE, 2105 0x98, 0xBA, 0xDC, 0xFE,
2331 // packet sequence number 2106 // packet sequence number
2332 0xBC, 0x9A, 0x78, 0x56, 2107 0xBC, 0x9A, 0x78, 0x56,
2333 0x34, 0x12, 2108 0x34, 0x12,
2334 // private flags 2109 // private flags
2335 0x00, 2110 0x00,
2336 2111
2337 // frame type (connection close frame) 2112 // frame type (connection close frame)
2338 static_cast<unsigned char>((version_ == QUIC_VERSION_6) ? 0x05 : 0x2F), 2113 static_cast<unsigned char>(0x2F),
2339 // error code 2114 // error code
2340 0x11, 0x00, 0x00, 0x00, 2115 0x11, 0x00, 0x00, 0x00,
2341 2116
2342 // error details length 2117 // error details length
2343 0x0d, 0x00, 2118 0x0d, 0x00,
2344 // error details 2119 // error details
2345 'b', 'e', 'c', 'a', 2120 'b', 'e', 'c', 'a',
2346 'u', 's', 'e', ' ', 2121 'u', 's', 'e', ' ',
2347 'I', ' ', 'c', 'a', 2122 'I', ' ', 'c', 'a',
2348 'n', 2123 'n',
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
2415 // guid 2190 // guid
2416 0x10, 0x32, 0x54, 0x76, 2191 0x10, 0x32, 0x54, 0x76,
2417 0x98, 0xBA, 0xDC, 0xFE, 2192 0x98, 0xBA, 0xDC, 0xFE,
2418 // packet sequence number 2193 // packet sequence number
2419 0xBC, 0x9A, 0x78, 0x56, 2194 0xBC, 0x9A, 0x78, 0x56,
2420 0x34, 0x12, 2195 0x34, 0x12,
2421 // private flags 2196 // private flags
2422 0x00, 2197 0x00,
2423 2198
2424 // frame type (go away frame) 2199 // frame type (go away frame)
2425 static_cast<unsigned char>((version_ == QUIC_VERSION_6) ? 0x06 : 0x37), 2200 static_cast<unsigned char>(0x37),
2426 // error code 2201 // error code
2427 0x09, 0x00, 0x00, 0x00, 2202 0x09, 0x00, 0x00, 0x00,
2428 // stream id 2203 // stream id
2429 0x04, 0x03, 0x02, 0x01, 2204 0x04, 0x03, 0x02, 0x01,
2430 // error details length 2205 // error details length
2431 0x0d, 0x00, 2206 0x0d, 0x00,
2432 // error details 2207 // error details
2433 'b', 'e', 'c', 'a', 2208 'b', 'e', 'c', 'a',
2434 'u', 's', 'e', ' ', 2209 'u', 's', 'e', ' ',
2435 'I', ' ', 'c', 'a', 2210 'I', ' ', 'c', 'a',
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
2619 // guid 2394 // guid
2620 0x10, 0x32, 0x54, 0x76, 2395 0x10, 0x32, 0x54, 0x76,
2621 0x98, 0xBA, 0xDC, 0xFE, 2396 0x98, 0xBA, 0xDC, 0xFE,
2622 // packet sequence number 2397 // packet sequence number
2623 0xBC, 0x9A, 0x78, 0x56, 2398 0xBC, 0x9A, 0x78, 0x56,
2624 0x34, 0x12, 2399 0x34, 0x12,
2625 // private flags 2400 // private flags
2626 0x00, 2401 0x00,
2627 2402
2628 // frame type (padding frame) 2403 // frame type (padding frame)
2629 static_cast<unsigned char>((version_ == QUIC_VERSION_6) ? 0x00 : 0x07), 2404 static_cast<unsigned char>(0x07),
2630 }; 2405 };
2631 2406
2632 uint64 header_size = 2407 uint64 header_size =
2633 GetPacketHeaderSize(PACKET_8BYTE_GUID, !kIncludeVersion, 2408 GetPacketHeaderSize(PACKET_8BYTE_GUID, !kIncludeVersion,
2634 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); 2409 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP);
2635 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1); 2410 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1);
2636 2411
2637 scoped_ptr<QuicPacket> data( 2412 scoped_ptr<QuicPacket> data(
2638 framer_.BuildUnsizedDataPacket(header, frames).packet); 2413 framer_.BuildUnsizedDataPacket(header, frames).packet);
2639 ASSERT_TRUE(data != NULL); 2414 ASSERT_TRUE(data != NULL);
(...skipping 24 matching lines...) Expand all
2664 0x2C, 2439 0x2C,
2665 // guid 2440 // guid
2666 0x10, 0x32, 0x54, 0x76, 2441 0x10, 0x32, 0x54, 0x76,
2667 0x98, 0xBA, 0xDC, 0xFE, 2442 0x98, 0xBA, 0xDC, 0xFE,
2668 // packet sequence number 2443 // packet sequence number
2669 0xBC, 0x9A, 0x78, 0x56, 2444 0xBC, 0x9A, 0x78, 0x56,
2670 // private flags 2445 // private flags
2671 0x00, 2446 0x00,
2672 2447
2673 // frame type (padding frame) 2448 // frame type (padding frame)
2674 static_cast<unsigned char>((version_ == QUIC_VERSION_6) ? 0x00 : 0x07), 2449 static_cast<unsigned char>(0x07),
2675 }; 2450 };
2676 2451
2677 uint64 header_size = 2452 uint64 header_size =
2678 GetPacketHeaderSize(PACKET_8BYTE_GUID, !kIncludeVersion, 2453 GetPacketHeaderSize(PACKET_8BYTE_GUID, !kIncludeVersion,
2679 PACKET_4BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); 2454 PACKET_4BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP);
2680 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1); 2455 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1);
2681 2456
2682 scoped_ptr<QuicPacket> data( 2457 scoped_ptr<QuicPacket> data(
2683 framer_.BuildUnsizedDataPacket(header, frames).packet); 2458 framer_.BuildUnsizedDataPacket(header, frames).packet);
2684 ASSERT_TRUE(data != NULL); 2459 ASSERT_TRUE(data != NULL);
(...skipping 24 matching lines...) Expand all
2709 0x1C, 2484 0x1C,
2710 // guid 2485 // guid
2711 0x10, 0x32, 0x54, 0x76, 2486 0x10, 0x32, 0x54, 0x76,
2712 0x98, 0xBA, 0xDC, 0xFE, 2487 0x98, 0xBA, 0xDC, 0xFE,
2713 // packet sequence number 2488 // packet sequence number
2714 0xBC, 0x9A, 2489 0xBC, 0x9A,
2715 // private flags 2490 // private flags
2716 0x00, 2491 0x00,
2717 2492
2718 // frame type (padding frame) 2493 // frame type (padding frame)
2719 static_cast<unsigned char>((version_ == QUIC_VERSION_6) ? 0x00 : 0x07), 2494 static_cast<unsigned char>(0x07),
2720 }; 2495 };
2721 2496
2722 uint64 header_size = 2497 uint64 header_size =
2723 GetPacketHeaderSize(PACKET_8BYTE_GUID, !kIncludeVersion, 2498 GetPacketHeaderSize(PACKET_8BYTE_GUID, !kIncludeVersion,
2724 PACKET_2BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); 2499 PACKET_2BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP);
2725 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1); 2500 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1);
2726 2501
2727 scoped_ptr<QuicPacket> data( 2502 scoped_ptr<QuicPacket> data(
2728 framer_.BuildUnsizedDataPacket(header, frames).packet); 2503 framer_.BuildUnsizedDataPacket(header, frames).packet);
2729 ASSERT_TRUE(data != NULL); 2504 ASSERT_TRUE(data != NULL);
(...skipping 24 matching lines...) Expand all
2754 0x0C, 2529 0x0C,
2755 // guid 2530 // guid
2756 0x10, 0x32, 0x54, 0x76, 2531 0x10, 0x32, 0x54, 0x76,
2757 0x98, 0xBA, 0xDC, 0xFE, 2532 0x98, 0xBA, 0xDC, 0xFE,
2758 // packet sequence number 2533 // packet sequence number
2759 0xBC, 2534 0xBC,
2760 // private flags 2535 // private flags
2761 0x00, 2536 0x00,
2762 2537
2763 // frame type (padding frame) 2538 // frame type (padding frame)
2764 static_cast<unsigned char>((version_ == QUIC_VERSION_6) ? 0x00 : 0x07), 2539 static_cast<unsigned char>(0x07),
2765 }; 2540 };
2766 2541
2767 uint64 header_size = 2542 uint64 header_size =
2768 GetPacketHeaderSize(PACKET_8BYTE_GUID, !kIncludeVersion, 2543 GetPacketHeaderSize(PACKET_8BYTE_GUID, !kIncludeVersion,
2769 PACKET_1BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP); 2544 PACKET_1BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP);
2770 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1); 2545 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1);
2771 2546
2772 scoped_ptr<QuicPacket> data( 2547 scoped_ptr<QuicPacket> data(
2773 framer_.BuildUnsizedDataPacket(header, frames).packet); 2548 framer_.BuildUnsizedDataPacket(header, frames).packet);
2774 ASSERT_TRUE(data != NULL); 2549 ASSERT_TRUE(data != NULL);
2775 2550
2776 test::CompareCharArraysWithHexError("constructed packet", 2551 test::CompareCharArraysWithHexError("constructed packet",
2777 data->data(), data->length(), 2552 data->data(), data->length(),
2778 AsChars(packet), arraysize(packet)); 2553 AsChars(packet), arraysize(packet));
2779 } 2554 }
2780 2555
2781 TEST_P(QuicFramerTest, BuildStreamFramePacketVersion6) {
2782 // Set a specific version.
2783 framer_.set_version(QUIC_VERSION_6);
2784
2785 QuicPacketHeader header;
2786 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210);
2787 header.public_header.reset_flag = false;
2788 header.public_header.version_flag = false;
2789 header.fec_flag = false;
2790 header.entropy_flag = true;
2791 header.packet_sequence_number = GG_UINT64_C(0x77123456789ABC);
2792 header.fec_group = 0;
2793
2794 QuicStreamFrame stream_frame;
2795 stream_frame.stream_id = 0x01020304;
2796 stream_frame.fin = true;
2797 stream_frame.offset = GG_UINT64_C(0xBA98FEDC32107654);
2798 stream_frame.data = "hello world!";
2799
2800 QuicFrames frames;
2801 frames.push_back(QuicFrame(&stream_frame));
2802
2803 unsigned char packet[] = {
2804 // public flags (8 byte guid)
2805 0x3C,
2806 // guid
2807 0x10, 0x32, 0x54, 0x76,
2808 0x98, 0xBA, 0xDC, 0xFE,
2809 // packet sequence number
2810 0xBC, 0x9A, 0x78, 0x56,
2811 0x34, 0x12,
2812 // private flags (entropy)
2813 0x01,
2814
2815 // frame type (stream frame)
2816 0x01,
2817 // stream id
2818 0x04, 0x03, 0x02, 0x01,
2819 // fin
2820 0x01,
2821 // offset
2822 0x54, 0x76, 0x10, 0x32,
2823 0xDC, 0xFE, 0x98, 0xBA,
2824 // data length
2825 0x0c, 0x00,
2826 // data
2827 'h', 'e', 'l', 'l',
2828 'o', ' ', 'w', 'o',
2829 'r', 'l', 'd', '!',
2830 };
2831
2832 scoped_ptr<QuicPacket> data(
2833 framer_.BuildUnsizedDataPacket(header, frames).packet);
2834 ASSERT_TRUE(data != NULL);
2835
2836 test::CompareCharArraysWithHexError("constructed packet",
2837 data->data(), data->length(),
2838 AsChars(packet), arraysize(packet));
2839 }
2840
2841 TEST_P(QuicFramerTest, BuildStreamFramePacket) { 2556 TEST_P(QuicFramerTest, BuildStreamFramePacket) {
2842 // Set a specific version. 2557 // Set a specific version.
2843 framer_.set_version(QUIC_VERSION_7); 2558 framer_.set_version(QUIC_VERSION_7);
2844 2559
2845 QuicPacketHeader header; 2560 QuicPacketHeader header;
2846 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210); 2561 header.public_header.guid = GG_UINT64_C(0xFEDCBA9876543210);
2847 header.public_header.reset_flag = false; 2562 header.public_header.reset_flag = false;
2848 header.public_header.version_flag = false; 2563 header.public_header.version_flag = false;
2849 header.fec_flag = false; 2564 header.fec_flag = false;
2850 header.entropy_flag = true; 2565 header.entropy_flag = true;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
2958 header.reset_flag = false; 2673 header.reset_flag = false;
2959 header.version_flag = true; 2674 header.version_flag = true;
2960 2675
2961 unsigned char packet[] = { 2676 unsigned char packet[] = {
2962 // public flags (version, 8 byte guid) 2677 // public flags (version, 8 byte guid)
2963 0x3D, 2678 0x3D,
2964 // guid 2679 // guid
2965 0x10, 0x32, 0x54, 0x76, 2680 0x10, 0x32, 0x54, 0x76,
2966 0x98, 0xBA, 0xDC, 0xFE, 2681 0x98, 0xBA, 0xDC, 0xFE,
2967 // version tag 2682 // version tag
2968 'Q', '0', '0', '6',
2969 'Q', '0', '0', '7', 2683 'Q', '0', '0', '7',
2970 }; 2684 };
2971 2685
2972 QuicVersionVector versions; 2686 QuicVersionVector versions;
2973 versions.push_back(QUIC_VERSION_6);
2974 versions.push_back(QUIC_VERSION_7); 2687 versions.push_back(QUIC_VERSION_7);
2975 scoped_ptr<QuicEncryptedPacket> data( 2688 scoped_ptr<QuicEncryptedPacket> data(
2976 framer_.BuildVersionNegotiationPacket(header, versions)); 2689 framer_.BuildVersionNegotiationPacket(header, versions));
2977 2690
2978 test::CompareCharArraysWithHexError("constructed packet", 2691 test::CompareCharArraysWithHexError("constructed packet",
2979 data->data(), data->length(), 2692 data->data(), data->length(),
2980 AsChars(packet), arraysize(packet)); 2693 AsChars(packet), arraysize(packet));
2981 } 2694 }
2982 2695
2983 TEST_P(QuicFramerTest, BuildAckFramePacket) { 2696 TEST_P(QuicFramerTest, BuildAckFramePacket) {
(...skipping 24 matching lines...) Expand all
3008 // guid 2721 // guid
3009 0x10, 0x32, 0x54, 0x76, 2722 0x10, 0x32, 0x54, 0x76,
3010 0x98, 0xBA, 0xDC, 0xFE, 2723 0x98, 0xBA, 0xDC, 0xFE,
3011 // packet sequence number 2724 // packet sequence number
3012 0xBC, 0x9A, 0x78, 0x56, 2725 0xBC, 0x9A, 0x78, 0x56,
3013 0x34, 0x12, 2726 0x34, 0x12,
3014 // private flags (entropy) 2727 // private flags (entropy)
3015 0x01, 2728 0x01,
3016 2729
3017 // frame type (ack frame) 2730 // frame type (ack frame)
3018 static_cast<unsigned char>((version_ == QUIC_VERSION_6) ? 0x02 : 0x01), 2731 static_cast<unsigned char>(0x01),
3019 // entropy hash of sent packets till least awaiting - 1. 2732 // entropy hash of sent packets till least awaiting - 1.
3020 0x14, 2733 0x14,
3021 // least packet sequence number awaiting an ack 2734 // least packet sequence number awaiting an ack
3022 0xA0, 0x9A, 0x78, 0x56, 2735 0xA0, 0x9A, 0x78, 0x56,
3023 0x34, 0x12, 2736 0x34, 0x12,
3024 // entropy hash of all received packets. 2737 // entropy hash of all received packets.
3025 0x43, 2738 0x43,
3026 // largest observed packet sequence number 2739 // largest observed packet sequence number
3027 0xBF, 0x9A, 0x78, 0x56, 2740 0xBF, 0x9A, 0x78, 0x56,
3028 0x34, 0x12, 2741 0x34, 0x12,
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
3256 // guid 2969 // guid
3257 0x10, 0x32, 0x54, 0x76, 2970 0x10, 0x32, 0x54, 0x76,
3258 0x98, 0xBA, 0xDC, 0xFE, 2971 0x98, 0xBA, 0xDC, 0xFE,
3259 // packet sequence number 2972 // packet sequence number
3260 0xBC, 0x9A, 0x78, 0x56, 2973 0xBC, 0x9A, 0x78, 0x56,
3261 0x34, 0x12, 2974 0x34, 0x12,
3262 // private flags 2975 // private flags
3263 0x00, 2976 0x00,
3264 2977
3265 // frame type (rst stream frame) 2978 // frame type (rst stream frame)
3266 static_cast<unsigned char>((version_ == QUIC_VERSION_6) ? 0x04 : 0x27), 2979 static_cast<unsigned char>(0x27),
3267 // stream id 2980 // stream id
3268 0x04, 0x03, 0x02, 0x01, 2981 0x04, 0x03, 0x02, 0x01,
3269 // error code 2982 // error code
3270 0x08, 0x07, 0x06, 0x05, 2983 0x08, 0x07, 0x06, 0x05,
3271 // error details length 2984 // error details length
3272 0x0d, 0x00, 2985 0x0d, 0x00,
3273 // error details 2986 // error details
3274 'b', 'e', 'c', 'a', 2987 'b', 'e', 'c', 'a',
3275 'u', 's', 'e', ' ', 2988 'u', 's', 'e', ' ',
3276 'I', ' ', 'c', 'a', 2989 'I', ' ', 'c', 'a',
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
3319 // guid 3032 // guid
3320 0x10, 0x32, 0x54, 0x76, 3033 0x10, 0x32, 0x54, 0x76,
3321 0x98, 0xBA, 0xDC, 0xFE, 3034 0x98, 0xBA, 0xDC, 0xFE,
3322 // packet sequence number 3035 // packet sequence number
3323 0xBC, 0x9A, 0x78, 0x56, 3036 0xBC, 0x9A, 0x78, 0x56,
3324 0x34, 0x12, 3037 0x34, 0x12,
3325 // private flags (entropy) 3038 // private flags (entropy)
3326 0x01, 3039 0x01,
3327 3040
3328 // frame type (connection close frame) 3041 // frame type (connection close frame)
3329 static_cast<unsigned char>((version_ == QUIC_VERSION_6) ? 0x05 : 0x2F), 3042 static_cast<unsigned char>(0x2F),
3330 // error code 3043 // error code
3331 0x08, 0x07, 0x06, 0x05, 3044 0x08, 0x07, 0x06, 0x05,
3332 // error details length 3045 // error details length
3333 0x0d, 0x00, 3046 0x0d, 0x00,
3334 // error details 3047 // error details
3335 'b', 'e', 'c', 'a', 3048 'b', 'e', 'c', 'a',
3336 'u', 's', 'e', ' ', 3049 'u', 's', 'e', ' ',
3337 'I', ' ', 'c', 'a', 3050 'I', ' ', 'c', 'a',
3338 'n', 3051 'n',
3339 3052
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
3390 // guid 3103 // guid
3391 0x10, 0x32, 0x54, 0x76, 3104 0x10, 0x32, 0x54, 0x76,
3392 0x98, 0xBA, 0xDC, 0xFE, 3105 0x98, 0xBA, 0xDC, 0xFE,
3393 // packet sequence number 3106 // packet sequence number
3394 0xBC, 0x9A, 0x78, 0x56, 3107 0xBC, 0x9A, 0x78, 0x56,
3395 0x34, 0x12, 3108 0x34, 0x12,
3396 // private flags(entropy) 3109 // private flags(entropy)
3397 0x01, 3110 0x01,
3398 3111
3399 // frame type (go away frame) 3112 // frame type (go away frame)
3400 static_cast<unsigned char>((version_ == QUIC_VERSION_6) ? 0x06 : 0x37), 3113 static_cast<unsigned char>(0x37),
3401 // error code 3114 // error code
3402 0x08, 0x07, 0x06, 0x05, 3115 0x08, 0x07, 0x06, 0x05,
3403 // stream id 3116 // stream id
3404 0x04, 0x03, 0x02, 0x01, 3117 0x04, 0x03, 0x02, 0x01,
3405 // error details length 3118 // error details length
3406 0x0d, 0x00, 3119 0x0d, 0x00,
3407 // error details 3120 // error details
3408 'b', 'e', 'c', 'a', 3121 'b', 'e', 'c', 'a',
3409 'u', 's', 'e', ' ', 3122 'u', 's', 'e', ' ',
3410 'I', ' ', 'c', 'a', 3123 'I', ' ', 'c', 'a',
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
3717 frame.connection_close_frame = &visitor_.connection_close_frame_; 3430 frame.connection_close_frame = &visitor_.connection_close_frame_;
3718 frames.push_back(frame); 3431 frames.push_back(frame);
3719 3432
3720 original_raw_length = raw_close_packet->length(); 3433 original_raw_length = raw_close_packet->length();
3721 raw_close_packet.reset( 3434 raw_close_packet.reset(
3722 framer_.BuildUnsizedDataPacket(header, frames).packet); 3435 framer_.BuildUnsizedDataPacket(header, frames).packet);
3723 ASSERT_TRUE(raw_ack_packet != NULL); 3436 ASSERT_TRUE(raw_ack_packet != NULL);
3724 EXPECT_EQ(original_raw_length, raw_close_packet->length()); 3437 EXPECT_EQ(original_raw_length, raw_close_packet->length());
3725 } 3438 }
3726 3439
3727 TEST_P(QuicFramerTest, EntropyFlagTestVersion6) {
3728 // Set a specific version.
3729 framer_.set_version(QUIC_VERSION_6);
3730
3731 unsigned char packet[] = {
3732 // public flags (8 byte guid)
3733 0x3C,
3734 // guid
3735 0x10, 0x32, 0x54, 0x76,
3736 0x98, 0xBA, 0xDC, 0xFE,
3737 // packet sequence number
3738 0xBC, 0x9A, 0x78, 0x56,
3739 0x34, 0x12,
3740 // private flags (Entropy)
3741 0x01,
3742
3743 // frame type (stream frame)
3744 0x01,
3745 // stream id
3746 0x04, 0x03, 0x02, 0x01,
3747 // fin
3748 0x01,
3749 // offset
3750 0x54, 0x76, 0x10, 0x32,
3751 0xDC, 0xFE, 0x98, 0xBA,
3752 // data length
3753 0x0c, 0x00,
3754 // data
3755 'h', 'e', 'l', 'l',
3756 'o', ' ', 'w', 'o',
3757 'r', 'l', 'd', '!',
3758 };
3759
3760 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
3761 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
3762 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
3763 ASSERT_TRUE(visitor_.header_.get());
3764 EXPECT_TRUE(visitor_.header_->entropy_flag);
3765 EXPECT_EQ(1 << 4, visitor_.header_->entropy_hash);
3766 EXPECT_FALSE(visitor_.header_->fec_flag);
3767 };
3768
3769 TEST_P(QuicFramerTest, EntropyFlagTest) { 3440 TEST_P(QuicFramerTest, EntropyFlagTest) {
3770 // Set a specific version. 3441 // Set a specific version.
3771 framer_.set_version(QUIC_VERSION_7); 3442 framer_.set_version(QUIC_VERSION_7);
3772 3443
3773 unsigned char packet[] = { 3444 unsigned char packet[] = {
3774 // public flags (8 byte guid) 3445 // public flags (8 byte guid)
3775 0x3C, 3446 0x3C,
3776 // guid 3447 // guid
3777 0x10, 0x32, 0x54, 0x76, 3448 0x10, 0x32, 0x54, 0x76,
3778 0x98, 0xBA, 0xDC, 0xFE, 3449 0x98, 0xBA, 0xDC, 0xFE,
(...skipping 18 matching lines...) Expand all
3797 3468
3798 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 3469 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
3799 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 3470 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
3800 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 3471 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
3801 ASSERT_TRUE(visitor_.header_.get()); 3472 ASSERT_TRUE(visitor_.header_.get());
3802 EXPECT_TRUE(visitor_.header_->entropy_flag); 3473 EXPECT_TRUE(visitor_.header_->entropy_flag);
3803 EXPECT_EQ(1 << 4, visitor_.header_->entropy_hash); 3474 EXPECT_EQ(1 << 4, visitor_.header_->entropy_hash);
3804 EXPECT_FALSE(visitor_.header_->fec_flag); 3475 EXPECT_FALSE(visitor_.header_->fec_flag);
3805 }; 3476 };
3806 3477
3807 TEST_P(QuicFramerTest, FecEntropyTestVersion6) {
3808 // Set a specific version.
3809 framer_.set_version(QUIC_VERSION_6);
3810
3811 unsigned char packet[] = {
3812 // public flags (8 byte guid)
3813 0x3C,
3814 // guid
3815 0x10, 0x32, 0x54, 0x76,
3816 0x98, 0xBA, 0xDC, 0xFE,
3817 // packet sequence number
3818 0xBC, 0x9A, 0x78, 0x56,
3819 0x34, 0x12,
3820 // private flags (Entropy & fec group & FEC)
3821 0x07,
3822 // first fec protected packet offset
3823 0xFF,
3824
3825 // frame type (stream frame)
3826 0x01,
3827 // stream id
3828 0x04, 0x03, 0x02, 0x01,
3829 // fin
3830 0x01,
3831 // offset
3832 0x54, 0x76, 0x10, 0x32,
3833 0xDC, 0xFE, 0x98, 0xBA,
3834 // data length
3835 0x0c, 0x00,
3836 // data
3837 'h', 'e', 'l', 'l',
3838 'o', ' ', 'w', 'o',
3839 'r', 'l', 'd', '!',
3840 };
3841
3842 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
3843 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
3844 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
3845 ASSERT_TRUE(visitor_.header_.get());
3846 EXPECT_TRUE(visitor_.header_->fec_flag);
3847 EXPECT_TRUE(visitor_.header_->entropy_flag);
3848 EXPECT_EQ(1 << 4, visitor_.header_->entropy_hash);
3849 };
3850
3851 TEST_P(QuicFramerTest, FecEntropyTest) { 3478 TEST_P(QuicFramerTest, FecEntropyTest) {
3852 // Set a specific version. 3479 // Set a specific version.
3853 framer_.set_version(QUIC_VERSION_7); 3480 framer_.set_version(QUIC_VERSION_7);
3854 3481
3855 unsigned char packet[] = { 3482 unsigned char packet[] = {
3856 // public flags (8 byte guid) 3483 // public flags (8 byte guid)
3857 0x3C, 3484 0x3C,
3858 // guid 3485 // guid
3859 0x10, 0x32, 0x54, 0x76, 3486 0x10, 0x32, 0x54, 0x76,
3860 0x98, 0xBA, 0xDC, 0xFE, 3487 0x98, 0xBA, 0xDC, 0xFE,
(...skipping 20 matching lines...) Expand all
3881 3508
3882 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 3509 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
3883 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 3510 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
3884 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 3511 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
3885 ASSERT_TRUE(visitor_.header_.get()); 3512 ASSERT_TRUE(visitor_.header_.get());
3886 EXPECT_TRUE(visitor_.header_->fec_flag); 3513 EXPECT_TRUE(visitor_.header_->fec_flag);
3887 EXPECT_TRUE(visitor_.header_->entropy_flag); 3514 EXPECT_TRUE(visitor_.header_->entropy_flag);
3888 EXPECT_EQ(1 << 4, visitor_.header_->entropy_hash); 3515 EXPECT_EQ(1 << 4, visitor_.header_->entropy_hash);
3889 }; 3516 };
3890 3517
3891 TEST_P(QuicFramerTest, StopPacketProcessingVersion6) {
3892 // Set a specific version.
3893 framer_.set_version(QUIC_VERSION_6);
3894
3895 unsigned char packet[] = {
3896 // public flags (8 byte guid)
3897 0x3C,
3898 // guid
3899 0x10, 0x32, 0x54, 0x76,
3900 0x98, 0xBA, 0xDC, 0xFE,
3901 // packet sequence number
3902 0xBC, 0x9A, 0x78, 0x56,
3903 0x34, 0x12,
3904 // Entropy
3905 0x01,
3906
3907 // frame type (stream frame)
3908 0x01,
3909 // stream id
3910 0x04, 0x03, 0x02, 0x01,
3911 // fin
3912 0x01,
3913 // offset
3914 0x54, 0x76, 0x10, 0x32,
3915 0xDC, 0xFE, 0x98, 0xBA,
3916 // data length
3917 0x0c, 0x00,
3918 // data
3919 'h', 'e', 'l', 'l',
3920 'o', ' ', 'w', 'o',
3921 'r', 'l', 'd', '!',
3922
3923 // frame type (ack frame)
3924 0x02,
3925 // entropy hash of sent packets till least awaiting - 1.
3926 0x14,
3927 // least packet sequence number awaiting an ack
3928 0xA0, 0x9A, 0x78, 0x56,
3929 0x34, 0x12,
3930 // entropy hash of all received packets.
3931 0x43,
3932 // largest observed packet sequence number
3933 0xBF, 0x9A, 0x78, 0x56,
3934 0x34, 0x12,
3935 // num missing packets
3936 0x01,
3937 // missing packet
3938 0xBE, 0x9A, 0x78, 0x56,
3939 0x34, 0x12,
3940 };
3941
3942 MockFramerVisitor visitor;
3943 framer_.set_visitor(&visitor);
3944 EXPECT_CALL(visitor, OnPacket());
3945 EXPECT_CALL(visitor, OnPacketHeader(_));
3946 EXPECT_CALL(visitor, OnStreamFrame(_)).WillOnce(Return(false));
3947 EXPECT_CALL(visitor, OnAckFrame(_)).Times(0);
3948 EXPECT_CALL(visitor, OnPacketComplete());
3949
3950 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
3951 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
3952 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
3953 }
3954
3955 TEST_P(QuicFramerTest, StopPacketProcessing) { 3518 TEST_P(QuicFramerTest, StopPacketProcessing) {
3956 // Set a specific version. 3519 // Set a specific version.
3957 framer_.set_version(QUIC_VERSION_7); 3520 framer_.set_version(QUIC_VERSION_7);
3958 3521
3959 unsigned char packet[] = { 3522 unsigned char packet[] = {
3960 // public flags (8 byte guid) 3523 // public flags (8 byte guid)
3961 0x3C, 3524 0x3C,
3962 // guid 3525 // guid
3963 0x10, 0x32, 0x54, 0x76, 3526 0x10, 0x32, 0x54, 0x76,
3964 0x98, 0xBA, 0xDC, 0xFE, 3527 0x98, 0xBA, 0xDC, 0xFE,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
4021 // guid 3584 // guid
4022 0x10, 0x32, 0x54, 0x76, 3585 0x10, 0x32, 0x54, 0x76,
4023 0x98, 0xBA, 0xDC, 0xFE, 3586 0x98, 0xBA, 0xDC, 0xFE,
4024 // packet sequence number 3587 // packet sequence number
4025 0xBC, 0x9A, 0x78, 0x56, 3588 0xBC, 0x9A, 0x78, 0x56,
4026 0x34, 0x12, 3589 0x34, 0x12,
4027 // private flags 3590 // private flags
4028 0x00, 3591 0x00,
4029 3592
4030 // frame type (connection close frame) 3593 // frame type (connection close frame)
4031 static_cast<unsigned char>((version_ == QUIC_VERSION_6) ? 0x05 : 0x2F), 3594 static_cast<unsigned char>(0x2F),
4032 // error code 3595 // error code
4033 0x11, 0x00, 0x00, 0x00, 3596 0x11, 0x00, 0x00, 0x00,
4034 // error details length 3597 // error details length
4035 0x0d, 0x00, 3598 0x0d, 0x00,
4036 // error details 3599 // error details
4037 'b', 'e', 'c', 'a', 3600 'b', 'e', 'c', 'a',
4038 'u', 's', 'e', ' ', 3601 'u', 's', 'e', ' ',
4039 'I', ' ', 'c', 'a', 3602 'I', ' ', 'c', 'a',
4040 'n', 3603 'n',
4041 3604
(...skipping 25 matching lines...) Expand all
4067 EXPECT_CALL(visitor, OnConnectionCloseFrame(_)).Times(0); 3630 EXPECT_CALL(visitor, OnConnectionCloseFrame(_)).Times(0);
4068 EXPECT_CALL(visitor, OnPacketComplete()); 3631 EXPECT_CALL(visitor, OnPacketComplete());
4069 3632
4070 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 3633 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
4071 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 3634 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
4072 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 3635 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
4073 } 3636 }
4074 3637
4075 } // namespace test 3638 } // namespace test
4076 } // namespace net 3639 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_framer.cc ('k') | net/quic/quic_protocol.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698