| OLD | NEW |
| 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/hash_tables.h" | 10 #include "base/hash_tables.h" |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 size_t len, | 218 size_t len, |
| 219 string expected_error, | 219 string expected_error, |
| 220 QuicErrorCode error_code) { | 220 QuicErrorCode error_code) { |
| 221 QuicEncryptedPacket encrypted(AsChars(packet), len, false); | 221 QuicEncryptedPacket encrypted(AsChars(packet), len, false); |
| 222 EXPECT_FALSE(framer_.ProcessPacket(self_address_, peer_address_, | 222 EXPECT_FALSE(framer_.ProcessPacket(self_address_, peer_address_, |
| 223 encrypted)) << "len: " << len; | 223 encrypted)) << "len: " << len; |
| 224 EXPECT_EQ(expected_error, framer_.detailed_error()) << "len: " << len; | 224 EXPECT_EQ(expected_error, framer_.detailed_error()) << "len: " << len; |
| 225 EXPECT_EQ(error_code, framer_.error()) << "len: " << len; | 225 EXPECT_EQ(error_code, framer_.error()) << "len: " << len; |
| 226 } | 226 } |
| 227 | 227 |
| 228 void ValidateTruncatedAck(const QuicAckFrame* ack, int keys) { | 228 void ValidateTruncatedAck(const QuicAckFrame* ack, size_t keys) { |
| 229 for (int i = 1; i < keys; ++i) { | 229 for (size_t i = 1; i < keys; ++i) { |
| 230 EXPECT_TRUE(ContainsKey(ack->received_info.missing_packets, i)) << i; | 230 EXPECT_TRUE(ContainsKey(ack->received_info.missing_packets, i)) << i; |
| 231 } | 231 } |
| 232 // With no gaps in the missing packets, we can't admit to having received | 232 EXPECT_EQ(keys, ack->received_info.largest_observed); |
| 233 // anything. | |
| 234 EXPECT_EQ(0u, ack->received_info.largest_received); | |
| 235 } | 233 } |
| 236 | 234 |
| 237 test::TestEncrypter* encrypter_; | 235 test::TestEncrypter* encrypter_; |
| 238 test::TestDecrypter* decrypter_; | 236 test::TestDecrypter* decrypter_; |
| 239 QuicFramer framer_; | 237 QuicFramer framer_; |
| 240 test::TestQuicVisitor visitor_; | 238 test::TestQuicVisitor visitor_; |
| 241 IPEndPoint self_address_; | 239 IPEndPoint self_address_; |
| 242 IPEndPoint peer_address_; | 240 IPEndPoint peer_address_; |
| 243 }; | 241 }; |
| 244 | 242 |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 // fec group | 550 // fec group |
| 553 0x00, | 551 0x00, |
| 554 | 552 |
| 555 // frame count | 553 // frame count |
| 556 0x01, | 554 0x01, |
| 557 // frame type (ack frame) | 555 // frame type (ack frame) |
| 558 0x02, | 556 0x02, |
| 559 // least packet sequence number awaiting an ack | 557 // least packet sequence number awaiting an ack |
| 560 0xA0, 0x9A, 0x78, 0x56, | 558 0xA0, 0x9A, 0x78, 0x56, |
| 561 0x34, 0x12, | 559 0x34, 0x12, |
| 562 // largest received packet sequence number | 560 // largest observed packet sequence number |
| 563 0xBF, 0x9A, 0x78, 0x56, | 561 0xBF, 0x9A, 0x78, 0x56, |
| 564 0x34, 0x12, | 562 0x34, 0x12, |
| 565 // num missing packets | 563 // num missing packets |
| 566 0x01, | 564 0x01, |
| 567 // missing packet | 565 // missing packet |
| 568 0xBE, 0x9A, 0x78, 0x56, | 566 0xBE, 0x9A, 0x78, 0x56, |
| 569 0x34, 0x12, | 567 0x34, 0x12, |
| 570 }; | 568 }; |
| 571 | 569 |
| 572 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 570 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 573 EXPECT_TRUE(framer_.ProcessPacket(self_address_, peer_address_, encrypted)); | 571 EXPECT_TRUE(framer_.ProcessPacket(self_address_, peer_address_, encrypted)); |
| 574 | 572 |
| 575 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); | 573 EXPECT_TRUE(CheckDecryption(StringPiece(AsChars(packet), arraysize(packet)))); |
| 576 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 574 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 577 ASSERT_TRUE(visitor_.header_.get()); | 575 ASSERT_TRUE(visitor_.header_.get()); |
| 578 | 576 |
| 579 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | 577 EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 580 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | 578 ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 581 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; | 579 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 582 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.received_info.largest_received); | 580 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.received_info.largest_observed); |
| 583 ASSERT_EQ(1u, frame.received_info.missing_packets.size()); | 581 ASSERT_EQ(1u, frame.received_info.missing_packets.size()); |
| 584 SequenceSet::const_iterator missing_iter = | 582 SequenceSet::const_iterator missing_iter = |
| 585 frame.received_info.missing_packets.begin(); | 583 frame.received_info.missing_packets.begin(); |
| 586 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter); | 584 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter); |
| 587 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame.sent_info.least_unacked); | 585 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame.sent_info.least_unacked); |
| 588 | 586 |
| 589 // Now test framing boundaries | 587 // Now test framing boundaries |
| 590 for (size_t i = 0; i < 21; ++i) { | 588 for (size_t i = 0; i < 21; ++i) { |
| 591 string expected_error; | 589 string expected_error; |
| 592 if (i < 1) { | 590 if (i < 1) { |
| 593 expected_error = "Unable to read frame count."; | 591 expected_error = "Unable to read frame count."; |
| 594 } else if (i < 2) { | 592 } else if (i < 2) { |
| 595 expected_error = "Unable to read frame type."; | 593 expected_error = "Unable to read frame type."; |
| 596 } else if (i < 8) { | 594 } else if (i < 8) { |
| 597 expected_error = "Unable to read least unacked."; | 595 expected_error = "Unable to read least unacked."; |
| 598 } else if (i < 14) { | 596 } else if (i < 14) { |
| 599 expected_error = "Unable to read largest received."; | 597 expected_error = "Unable to read largest observed."; |
| 600 } else if (i < 15) { | 598 } else if (i < 15) { |
| 601 expected_error = "Unable to read num missing packets."; | 599 expected_error = "Unable to read num missing packets."; |
| 602 } else if (i < 21) { | 600 } else if (i < 21) { |
| 603 expected_error = "Unable to read sequence number in missing packets."; | 601 expected_error = "Unable to read sequence number in missing packets."; |
| 604 } CheckProcessingFails(packet, i + kPacketHeaderSize, expected_error, | 602 } CheckProcessingFails(packet, i + kPacketHeaderSize, expected_error, |
| 605 QUIC_INVALID_FRAME_DATA); | 603 QUIC_INVALID_FRAME_DATA); |
| 606 } | 604 } |
| 607 } | 605 } |
| 608 | 606 |
| 609 TEST_F(QuicFramerTest, CongestionFeedbackFrameTCP) { | 607 TEST_F(QuicFramerTest, CongestionFeedbackFrameTCP) { |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 // error details | 937 // error details |
| 940 'b', 'e', 'c', 'a', | 938 'b', 'e', 'c', 'a', |
| 941 'u', 's', 'e', ' ', | 939 'u', 's', 'e', ' ', |
| 942 'I', ' ', 'c', 'a', | 940 'I', ' ', 'c', 'a', |
| 943 'n', | 941 'n', |
| 944 | 942 |
| 945 // Ack frame. | 943 // Ack frame. |
| 946 // least packet sequence number awaiting an ack | 944 // least packet sequence number awaiting an ack |
| 947 0xA0, 0x9A, 0x78, 0x56, | 945 0xA0, 0x9A, 0x78, 0x56, |
| 948 0x34, 0x12, | 946 0x34, 0x12, |
| 949 // largest received packet sequence number | 947 // largest observed packet sequence number |
| 950 0xBF, 0x9A, 0x78, 0x56, | 948 0xBF, 0x9A, 0x78, 0x56, |
| 951 0x34, 0x12, | 949 0x34, 0x12, |
| 952 // num missing packets | 950 // num missing packets |
| 953 0x01, | 951 0x01, |
| 954 // missing packet | 952 // missing packet |
| 955 0xBE, 0x9A, 0x78, 0x56, | 953 0xBE, 0x9A, 0x78, 0x56, |
| 956 0x34, 0x12, | 954 0x34, 0x12, |
| 957 // congestion feedback type (inter arrival) | 955 // congestion feedback type (inter arrival) |
| 958 0x02, | 956 0x02, |
| 959 // accumulated_number_of_lost_packets | 957 // accumulated_number_of_lost_packets |
| (...skipping 11 matching lines...) Expand all Loading... |
| 971 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 969 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 972 ASSERT_TRUE(visitor_.header_.get()); | 970 ASSERT_TRUE(visitor_.header_.get()); |
| 973 | 971 |
| 974 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | 972 EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 975 | 973 |
| 976 EXPECT_EQ(0x05060708, visitor_.connection_close_frame_.error_code); | 974 EXPECT_EQ(0x05060708, visitor_.connection_close_frame_.error_code); |
| 977 EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); | 975 EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); |
| 978 | 976 |
| 979 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | 977 ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 980 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; | 978 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 981 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.received_info.largest_received); | 979 EXPECT_EQ(GG_UINT64_C(0x0123456789ABF), frame.received_info.largest_observed); |
| 982 ASSERT_EQ(1u, frame.received_info.missing_packets.size()); | 980 ASSERT_EQ(1u, frame.received_info.missing_packets.size()); |
| 983 SequenceSet::const_iterator missing_iter = | 981 SequenceSet::const_iterator missing_iter = |
| 984 frame.received_info.missing_packets.begin(); | 982 frame.received_info.missing_packets.begin(); |
| 985 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter); | 983 EXPECT_EQ(GG_UINT64_C(0x0123456789ABE), *missing_iter); |
| 986 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame.sent_info.least_unacked); | 984 EXPECT_EQ(GG_UINT64_C(0x0123456789AA0), frame.sent_info.least_unacked); |
| 987 | 985 |
| 988 // Now test framing boundaries | 986 // Now test framing boundaries |
| 989 for (size_t i = 3; i < 21; ++i) { | 987 for (size_t i = 3; i < 21; ++i) { |
| 990 string expected_error; | 988 string expected_error; |
| 991 if (i < 6) { | 989 if (i < 6) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 } | 1091 } |
| 1094 | 1092 |
| 1095 TEST_F(QuicFramerTest, ConstructAckFramePacket) { | 1093 TEST_F(QuicFramerTest, ConstructAckFramePacket) { |
| 1096 QuicPacketHeader header; | 1094 QuicPacketHeader header; |
| 1097 header.guid = GG_UINT64_C(0xFEDCBA9876543210); | 1095 header.guid = GG_UINT64_C(0xFEDCBA9876543210); |
| 1098 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); | 1096 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); |
| 1099 header.flags = PACKET_FLAGS_NONE; | 1097 header.flags = PACKET_FLAGS_NONE; |
| 1100 header.fec_group = 0; | 1098 header.fec_group = 0; |
| 1101 | 1099 |
| 1102 QuicAckFrame ack_frame; | 1100 QuicAckFrame ack_frame; |
| 1103 ack_frame.received_info.largest_received = GG_UINT64_C(0x0123456789ABF); | 1101 ack_frame.received_info.largest_observed = GG_UINT64_C(0x0123456789ABF); |
| 1104 ack_frame.received_info.missing_packets.insert(GG_UINT64_C(0x0123456789ABE)); | 1102 ack_frame.received_info.missing_packets.insert(GG_UINT64_C(0x0123456789ABE)); |
| 1105 ack_frame.sent_info.least_unacked = GG_UINT64_C(0x0123456789AA0); | 1103 ack_frame.sent_info.least_unacked = GG_UINT64_C(0x0123456789AA0); |
| 1106 | 1104 |
| 1107 QuicFrames frames; | 1105 QuicFrames frames; |
| 1108 frames.push_back(QuicFrame(&ack_frame)); | 1106 frames.push_back(QuicFrame(&ack_frame)); |
| 1109 | 1107 |
| 1110 unsigned char packet[] = { | 1108 unsigned char packet[] = { |
| 1111 // guid | 1109 // guid |
| 1112 0x10, 0x32, 0x54, 0x76, | 1110 0x10, 0x32, 0x54, 0x76, |
| 1113 0x98, 0xBA, 0xDC, 0xFE, | 1111 0x98, 0xBA, 0xDC, 0xFE, |
| 1114 // packet id | 1112 // packet id |
| 1115 0xBC, 0x9A, 0x78, 0x56, | 1113 0xBC, 0x9A, 0x78, 0x56, |
| 1116 0x34, 0x12, | 1114 0x34, 0x12, |
| 1117 // flags | 1115 // flags |
| 1118 0x00, | 1116 0x00, |
| 1119 // fec group | 1117 // fec group |
| 1120 0x00, | 1118 0x00, |
| 1121 | 1119 |
| 1122 // frame count | 1120 // frame count |
| 1123 0x01, | 1121 0x01, |
| 1124 // frame type (ack frame) | 1122 // frame type (ack frame) |
| 1125 0x02, | 1123 0x02, |
| 1126 // least packet sequence number awaiting an ack | 1124 // least packet sequence number awaiting an ack |
| 1127 0xA0, 0x9A, 0x78, 0x56, | 1125 0xA0, 0x9A, 0x78, 0x56, |
| 1128 0x34, 0x12, | 1126 0x34, 0x12, |
| 1129 // largest received packet sequence number | 1127 // largest observed packet sequence number |
| 1130 0xBF, 0x9A, 0x78, 0x56, | 1128 0xBF, 0x9A, 0x78, 0x56, |
| 1131 0x34, 0x12, | 1129 0x34, 0x12, |
| 1132 // num missing packets | 1130 // num missing packets |
| 1133 0x01, | 1131 0x01, |
| 1134 // missing packet | 1132 // missing packet |
| 1135 0xBE, 0x9A, 0x78, 0x56, | 1133 0xBE, 0x9A, 0x78, 0x56, |
| 1136 0x34, 0x12, | 1134 0x34, 0x12, |
| 1137 }; | 1135 }; |
| 1138 | 1136 |
| 1139 scoped_ptr<QuicPacket> data(framer_.ConstructFrameDataPacket(header, frames)); | 1137 scoped_ptr<QuicPacket> data(framer_.ConstructFrameDataPacket(header, frames)); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1382 header.guid = GG_UINT64_C(0xFEDCBA9876543210); | 1380 header.guid = GG_UINT64_C(0xFEDCBA9876543210); |
| 1383 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); | 1381 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); |
| 1384 header.flags = PACKET_FLAGS_NONE; | 1382 header.flags = PACKET_FLAGS_NONE; |
| 1385 header.fec_group = 0; | 1383 header.fec_group = 0; |
| 1386 | 1384 |
| 1387 QuicConnectionCloseFrame close_frame; | 1385 QuicConnectionCloseFrame close_frame; |
| 1388 close_frame.error_code = static_cast<QuicErrorCode>(0x05060708); | 1386 close_frame.error_code = static_cast<QuicErrorCode>(0x05060708); |
| 1389 close_frame.error_details = "because I can"; | 1387 close_frame.error_details = "because I can"; |
| 1390 | 1388 |
| 1391 QuicAckFrame* ack_frame = &close_frame.ack_frame; | 1389 QuicAckFrame* ack_frame = &close_frame.ack_frame; |
| 1392 ack_frame->received_info.largest_received = GG_UINT64_C(0x0123456789ABF); | 1390 ack_frame->received_info.largest_observed = GG_UINT64_C(0x0123456789ABF); |
| 1393 ack_frame->received_info.missing_packets.insert(GG_UINT64_C(0x0123456789ABE)); | 1391 ack_frame->received_info.missing_packets.insert(GG_UINT64_C(0x0123456789ABE)); |
| 1394 ack_frame->sent_info.least_unacked = GG_UINT64_C(0x0123456789AA0); | 1392 ack_frame->sent_info.least_unacked = GG_UINT64_C(0x0123456789AA0); |
| 1395 | 1393 |
| 1396 QuicFrames frames; | 1394 QuicFrames frames; |
| 1397 frames.push_back(QuicFrame(&close_frame)); | 1395 frames.push_back(QuicFrame(&close_frame)); |
| 1398 | 1396 |
| 1399 unsigned char packet[] = { | 1397 unsigned char packet[] = { |
| 1400 // guid | 1398 // guid |
| 1401 0x10, 0x32, 0x54, 0x76, | 1399 0x10, 0x32, 0x54, 0x76, |
| 1402 0x98, 0xBA, 0xDC, 0xFE, | 1400 0x98, 0xBA, 0xDC, 0xFE, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1419 // error details | 1417 // error details |
| 1420 'b', 'e', 'c', 'a', | 1418 'b', 'e', 'c', 'a', |
| 1421 'u', 's', 'e', ' ', | 1419 'u', 's', 'e', ' ', |
| 1422 'I', ' ', 'c', 'a', | 1420 'I', ' ', 'c', 'a', |
| 1423 'n', | 1421 'n', |
| 1424 | 1422 |
| 1425 // Ack frame. | 1423 // Ack frame. |
| 1426 // least packet sequence number awaiting an ack | 1424 // least packet sequence number awaiting an ack |
| 1427 0xA0, 0x9A, 0x78, 0x56, | 1425 0xA0, 0x9A, 0x78, 0x56, |
| 1428 0x34, 0x12, | 1426 0x34, 0x12, |
| 1429 // largest received packet sequence number | 1427 // largest observed packet sequence number |
| 1430 0xBF, 0x9A, 0x78, 0x56, | 1428 0xBF, 0x9A, 0x78, 0x56, |
| 1431 0x34, 0x12, | 1429 0x34, 0x12, |
| 1432 // num missing packets | 1430 // num missing packets |
| 1433 0x01, | 1431 0x01, |
| 1434 // missing packet | 1432 // missing packet |
| 1435 0xBE, 0x9A, 0x78, 0x56, | 1433 0xBE, 0x9A, 0x78, 0x56, |
| 1436 0x34, 0x12, | 1434 0x34, 0x12, |
| 1437 }; | 1435 }; |
| 1438 | 1436 |
| 1439 scoped_ptr<QuicPacket> data(framer_.ConstructFrameDataPacket(header, frames)); | 1437 scoped_ptr<QuicPacket> data(framer_.ConstructFrameDataPacket(header, frames)); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1516 } | 1514 } |
| 1517 | 1515 |
| 1518 // TODO(rch): re-enable after https://codereview.chromium.org/11820005/ | 1516 // TODO(rch): re-enable after https://codereview.chromium.org/11820005/ |
| 1519 // lands. Currently this is causing valgrind problems, but it should be | 1517 // lands. Currently this is causing valgrind problems, but it should be |
| 1520 // fixed in the followup CL. | 1518 // fixed in the followup CL. |
| 1521 TEST_F(QuicFramerTest, DISABLED_CalculateLargestReceived) { | 1519 TEST_F(QuicFramerTest, DISABLED_CalculateLargestReceived) { |
| 1522 SequenceSet missing; | 1520 SequenceSet missing; |
| 1523 missing.insert(1); | 1521 missing.insert(1); |
| 1524 missing.insert(5); | 1522 missing.insert(5); |
| 1525 missing.insert(7); | 1523 missing.insert(7); |
| 1526 missing.insert(8); | |
| 1527 missing.insert(9); | |
| 1528 | 1524 |
| 1529 // These two we just walk to the next gap, and return the largest seen. | 1525 // These two we just walk to the next gap, and return the largest seen. |
| 1530 EXPECT_EQ(4u, QuicFramer::CalculateLargestReceived(missing, missing.find(1))); | 1526 EXPECT_EQ(4u, QuicFramer::CalculateLargestObserved(missing, missing.find(1))); |
| 1531 EXPECT_EQ(6u, QuicFramer::CalculateLargestReceived(missing, missing.find(5))); | 1527 EXPECT_EQ(6u, QuicFramer::CalculateLargestObserved(missing, missing.find(5))); |
| 1532 | 1528 |
| 1533 missing.insert(2); | 1529 missing.insert(2); |
| 1534 // For 1, we can't go forward as 2 would be implicitly acked. We must go | 1530 // For 1, we can't go forward as 2 would be implicitly acked so we return the |
| 1535 // backwards. | 1531 // largest missing packet. |
| 1536 EXPECT_EQ(0u, QuicFramer::CalculateLargestReceived(missing, missing.find(1))); | 1532 EXPECT_EQ(1u, QuicFramer::CalculateLargestObserved(missing, missing.find(1))); |
| 1537 // For 2, we've seen 3 and 4, so can admit to a largest received. | 1533 // For 2, we've seen 3 and 4, so can admit to a largest observed. |
| 1538 EXPECT_EQ(4u, QuicFramer::CalculateLargestReceived(missing, missing.find(2))); | 1534 EXPECT_EQ(4u, QuicFramer::CalculateLargestObserved(missing, missing.find(2))); |
| 1539 | |
| 1540 // 7+ are fun because there is no subsequent gap: we have to walk before | |
| 1541 // them to find 6. | |
| 1542 EXPECT_EQ(6u, QuicFramer::CalculateLargestReceived(missing, missing.find(7))); | |
| 1543 EXPECT_EQ(6u, QuicFramer::CalculateLargestReceived(missing, missing.find(8))); | |
| 1544 EXPECT_EQ(6u, QuicFramer::CalculateLargestReceived(missing, missing.find(9))); | |
| 1545 | |
| 1546 // Fill in the gap of 6 to make sure we handle a gap of more than 1 by | |
| 1547 // returning 4 rather than 3. | |
| 1548 missing.insert(6); | |
| 1549 EXPECT_EQ(4u, QuicFramer::CalculateLargestReceived(missing, missing.find(9))); | |
| 1550 | |
| 1551 // Fill in the rest of the gaps: we should walk to 1 and return 0. | |
| 1552 missing.insert(4); | |
| 1553 missing.insert(3); | |
| 1554 missing.insert(2); | |
| 1555 EXPECT_EQ(0u, QuicFramer::CalculateLargestReceived(missing, missing.find(7))); | |
| 1556 | |
| 1557 // If we add a gap after 7-9, we will return that only for 9. | |
| 1558 missing.insert(11); | |
| 1559 EXPECT_EQ(0u, QuicFramer::CalculateLargestReceived(missing, | |
| 1560 missing.find(7))); | |
| 1561 EXPECT_EQ(0u, QuicFramer::CalculateLargestReceived(missing, | |
| 1562 missing.find(8))); | |
| 1563 EXPECT_EQ(10u, QuicFramer::CalculateLargestReceived(missing, | |
| 1564 missing.find(9))); | |
| 1565 } | 1535 } |
| 1566 | 1536 |
| 1567 TEST_F(QuicFramerTest, Truncation) { | 1537 TEST_F(QuicFramerTest, Truncation) { |
| 1568 QuicPacketHeader header; | 1538 QuicPacketHeader header; |
| 1569 header.guid = GG_UINT64_C(0xFEDCBA9876543210); | 1539 header.guid = GG_UINT64_C(0xFEDCBA9876543210); |
| 1570 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); | 1540 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); |
| 1571 header.flags = PACKET_FLAGS_NONE; | 1541 header.flags = PACKET_FLAGS_NONE; |
| 1572 header.fec_group = 0; | 1542 header.fec_group = 0; |
| 1573 | 1543 |
| 1574 QuicConnectionCloseFrame close_frame; | 1544 QuicConnectionCloseFrame close_frame; |
| 1575 QuicAckFrame* ack_frame = &close_frame.ack_frame; | 1545 QuicAckFrame* ack_frame = &close_frame.ack_frame; |
| 1576 close_frame.error_code = static_cast<QuicErrorCode>(0x05060708); | 1546 close_frame.error_code = static_cast<QuicErrorCode>(0x05060708); |
| 1577 close_frame.error_details = "because I can"; | 1547 close_frame.error_details = "because I can"; |
| 1578 ack_frame->received_info.largest_received = 201; | 1548 ack_frame->received_info.largest_observed = 201; |
| 1579 for (uint64 i = 1; i < ack_frame->received_info.largest_received; ++i) { | 1549 for (uint64 i = 1; i < ack_frame->received_info.largest_observed; ++i) { |
| 1580 ack_frame->received_info.missing_packets.insert(i); | 1550 ack_frame->received_info.missing_packets.insert(i); |
| 1581 } | 1551 } |
| 1582 | 1552 |
| 1583 // Create a packet with just the ack | 1553 // Create a packet with just the ack |
| 1584 QuicFrame frame; | 1554 QuicFrame frame; |
| 1585 frame.type = ACK_FRAME; | 1555 frame.type = ACK_FRAME; |
| 1586 frame.ack_frame = ack_frame; | 1556 frame.ack_frame = ack_frame; |
| 1587 QuicFrames frames; | 1557 QuicFrames frames; |
| 1588 frames.push_back(frame); | 1558 frames.push_back(frame); |
| 1589 | 1559 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1615 ASSERT_EQ(self_address_, visitor_.self_address_); | 1585 ASSERT_EQ(self_address_, visitor_.self_address_); |
| 1616 EXPECT_EQ(1u, visitor_.ack_frames_.size()); | 1586 EXPECT_EQ(1u, visitor_.ack_frames_.size()); |
| 1617 | 1587 |
| 1618 // And do the same for the close frame. | 1588 // And do the same for the close frame. |
| 1619 ASSERT_TRUE(framer_.ProcessPacket(self_address_, peer_address_, | 1589 ASSERT_TRUE(framer_.ProcessPacket(self_address_, peer_address_, |
| 1620 *close_packet)); | 1590 *close_packet)); |
| 1621 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1591 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1622 EXPECT_EQ(0x05060708, visitor_.connection_close_frame_.error_code); | 1592 EXPECT_EQ(0x05060708, visitor_.connection_close_frame_.error_code); |
| 1623 EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); | 1593 EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); |
| 1624 | 1594 |
| 1625 ValidateTruncatedAck(visitor_.ack_frames_[0], 190); | 1595 ValidateTruncatedAck(visitor_.ack_frames_[0], 194); |
| 1626 ValidateTruncatedAck(&visitor_.connection_close_frame_.ack_frame, 180); | 1596 ValidateTruncatedAck(&visitor_.connection_close_frame_.ack_frame, 191); |
| 1627 } | 1597 } |
| 1628 | 1598 |
| 1629 } // namespace test | 1599 } // namespace test |
| 1630 } // namespace net | 1600 } // namespace net |
| OLD | NEW |