| 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 "net/quic/quic_framer.h" | 5 #include "net/quic/quic_framer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 2026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2037 expected_error = "Unable to read receive window."; | 2037 expected_error = "Unable to read receive window."; |
| 2038 } | 2038 } |
| 2039 CheckProcessingFails( | 2039 CheckProcessingFails( |
| 2040 packet, | 2040 packet, |
| 2041 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 2041 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
| 2042 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), | 2042 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), |
| 2043 expected_error, QUIC_INVALID_CONGESTION_FEEDBACK_DATA); | 2043 expected_error, QUIC_INVALID_CONGESTION_FEEDBACK_DATA); |
| 2044 } | 2044 } |
| 2045 } | 2045 } |
| 2046 | 2046 |
| 2047 TEST_P(QuicFramerTest, CongestionFeedbackFrameTimestamp) { | |
| 2048 unsigned char packet[] = { | |
| 2049 // public flags (8 byte connection_id) | |
| 2050 0x3C, | |
| 2051 // connection_id | |
| 2052 0x10, 0x32, 0x54, 0x76, | |
| 2053 0x98, 0xBA, 0xDC, 0xFE, | |
| 2054 // packet sequence number | |
| 2055 0xBC, 0x9A, 0x78, 0x56, | |
| 2056 0x34, 0x12, | |
| 2057 // private flags | |
| 2058 0x00, | |
| 2059 | |
| 2060 // frame type (congestion feedback frame) | |
| 2061 0x20, | |
| 2062 // congestion feedback type (timestamp) | |
| 2063 0x01, | |
| 2064 // num received packets | |
| 2065 0x03, | |
| 2066 // lowest sequence number | |
| 2067 0xBA, 0x9A, 0x78, 0x56, | |
| 2068 0x34, 0x12, | |
| 2069 // receive time | |
| 2070 0x87, 0x96, 0xA5, 0xB4, | |
| 2071 0xC3, 0xD2, 0xE1, 0x07, | |
| 2072 // sequence delta | |
| 2073 0x01, 0x00, | |
| 2074 // time delta | |
| 2075 0x01, 0x00, 0x00, 0x00, | |
| 2076 // sequence delta (skip one packet) | |
| 2077 0x03, 0x00, | |
| 2078 // time delta | |
| 2079 0x02, 0x00, 0x00, 0x00, | |
| 2080 }; | |
| 2081 | |
| 2082 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 2083 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 2084 | |
| 2085 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 2086 ASSERT_TRUE(visitor_.header_.get()); | |
| 2087 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); | |
| 2088 | |
| 2089 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | |
| 2090 ASSERT_EQ(1u, visitor_.congestion_feedback_frames_.size()); | |
| 2091 const QuicCongestionFeedbackFrame& frame = | |
| 2092 *visitor_.congestion_feedback_frames_[0]; | |
| 2093 ASSERT_EQ(kTimestamp, frame.type); | |
| 2094 ASSERT_EQ(3u, frame.timestamp.received_packet_times.size()); | |
| 2095 TimeMap::const_iterator iter = | |
| 2096 frame.timestamp.received_packet_times.begin(); | |
| 2097 EXPECT_EQ(GG_UINT64_C(0x0123456789ABA), iter->first); | |
| 2098 EXPECT_EQ(GG_INT64_C(0x07E1D2C3B4A59687), | |
| 2099 iter->second.Subtract(start_).ToMicroseconds()); | |
| 2100 ++iter; | |
| 2101 EXPECT_EQ(GG_UINT64_C(0x0123456789ABB), iter->first); | |
| 2102 EXPECT_EQ(GG_INT64_C(0x07E1D2C3B4A59688), | |
| 2103 iter->second.Subtract(start_).ToMicroseconds()); | |
| 2104 ++iter; | |
| 2105 EXPECT_EQ(GG_UINT64_C(0x0123456789ABD), iter->first); | |
| 2106 EXPECT_EQ(GG_INT64_C(0x07E1D2C3B4A59689), | |
| 2107 iter->second.Subtract(start_).ToMicroseconds()); | |
| 2108 | |
| 2109 // Now test framing boundaries | |
| 2110 for (size_t i = kQuicFrameTypeSize; i < 29; ++i) { | |
| 2111 string expected_error; | |
| 2112 if (i < 2) { | |
| 2113 expected_error = "Unable to read congestion feedback type."; | |
| 2114 } else if (i < 3) { | |
| 2115 expected_error = "Unable to read num received packets."; | |
| 2116 } else if (i < 9) { | |
| 2117 expected_error = "Unable to read smallest received."; | |
| 2118 } else if (i < 17) { | |
| 2119 expected_error = "Unable to read time received."; | |
| 2120 } else if (i < 19) { | |
| 2121 expected_error = "Unable to read sequence delta in received packets."; | |
| 2122 } else if (i < 23) { | |
| 2123 expected_error = "Unable to read time delta in received packets."; | |
| 2124 } else if (i < 25) { | |
| 2125 expected_error = "Unable to read sequence delta in received packets."; | |
| 2126 } else if (i < 29) { | |
| 2127 expected_error = "Unable to read time delta in received packets."; | |
| 2128 } | |
| 2129 CheckProcessingFails( | |
| 2130 packet, | |
| 2131 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | |
| 2132 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), | |
| 2133 expected_error, QUIC_INVALID_CONGESTION_FEEDBACK_DATA); | |
| 2134 } | |
| 2135 } | |
| 2136 | |
| 2137 TEST_P(QuicFramerTest, CongestionFeedbackFrameInvalidFeedback) { | 2047 TEST_P(QuicFramerTest, CongestionFeedbackFrameInvalidFeedback) { |
| 2138 unsigned char packet[] = { | 2048 unsigned char packet[] = { |
| 2139 // public flags (8 byte connection_id) | 2049 // public flags (8 byte connection_id) |
| 2140 0x3C, | 2050 0x3C, |
| 2141 // connection_id | 2051 // connection_id |
| 2142 0x10, 0x32, 0x54, 0x76, | 2052 0x10, 0x32, 0x54, 0x76, |
| 2143 0x98, 0xBA, 0xDC, 0xFE, | 2053 0x98, 0xBA, 0xDC, 0xFE, |
| 2144 // packet sequence number | 2054 // packet sequence number |
| 2145 0xBC, 0x9A, 0x78, 0x56, | 2055 0xBC, 0x9A, 0x78, 0x56, |
| 2146 0x34, 0x12, | 2056 0x34, 0x12, |
| (...skipping 1274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3421 }; | 3331 }; |
| 3422 | 3332 |
| 3423 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | 3333 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 3424 ASSERT_TRUE(data != NULL); | 3334 ASSERT_TRUE(data != NULL); |
| 3425 | 3335 |
| 3426 test::CompareCharArraysWithHexError("constructed packet", | 3336 test::CompareCharArraysWithHexError("constructed packet", |
| 3427 data->data(), data->length(), | 3337 data->data(), data->length(), |
| 3428 AsChars(packet), arraysize(packet)); | 3338 AsChars(packet), arraysize(packet)); |
| 3429 } | 3339 } |
| 3430 | 3340 |
| 3431 TEST_P(QuicFramerTest, BuildCongestionFeedbackFramePacketTimestamp) { | |
| 3432 QuicPacketHeader header; | |
| 3433 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); | |
| 3434 header.public_header.reset_flag = false; | |
| 3435 header.public_header.version_flag = false; | |
| 3436 header.fec_flag = false; | |
| 3437 header.entropy_flag = false; | |
| 3438 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); | |
| 3439 header.fec_group = 0; | |
| 3440 | |
| 3441 QuicCongestionFeedbackFrame frame; | |
| 3442 frame.type = kTimestamp; | |
| 3443 frame.timestamp.received_packet_times.insert( | |
| 3444 make_pair(GG_UINT64_C(0x0123456789ABA), | |
| 3445 start_.Add(QuicTime::Delta::FromMicroseconds( | |
| 3446 GG_UINT64_C(0x07E1D2C3B4A59687))))); | |
| 3447 frame.timestamp.received_packet_times.insert( | |
| 3448 make_pair(GG_UINT64_C(0x0123456789ABB), | |
| 3449 start_.Add(QuicTime::Delta::FromMicroseconds( | |
| 3450 GG_UINT64_C(0x07E1D2C3B4A59688))))); | |
| 3451 frame.timestamp.received_packet_times.insert( | |
| 3452 make_pair(GG_UINT64_C(0x0123456789ABD), | |
| 3453 start_.Add(QuicTime::Delta::FromMicroseconds( | |
| 3454 GG_UINT64_C(0x07E1D2C3B4A59689))))); | |
| 3455 QuicFrames frames; | |
| 3456 frames.push_back(QuicFrame(&frame)); | |
| 3457 | |
| 3458 unsigned char packet[] = { | |
| 3459 // public flags (8 byte connection_id) | |
| 3460 0x3C, | |
| 3461 // connection_id | |
| 3462 0x10, 0x32, 0x54, 0x76, | |
| 3463 0x98, 0xBA, 0xDC, 0xFE, | |
| 3464 // packet sequence number | |
| 3465 0xBC, 0x9A, 0x78, 0x56, | |
| 3466 0x34, 0x12, | |
| 3467 // private flags | |
| 3468 0x00, | |
| 3469 | |
| 3470 // frame type (congestion feedback frame) | |
| 3471 0x20, | |
| 3472 // congestion feedback type (timestamp) | |
| 3473 0x01, | |
| 3474 // num received packets | |
| 3475 0x03, | |
| 3476 // lowest sequence number | |
| 3477 0xBA, 0x9A, 0x78, 0x56, | |
| 3478 0x34, 0x12, | |
| 3479 // receive time | |
| 3480 0x87, 0x96, 0xA5, 0xB4, | |
| 3481 0xC3, 0xD2, 0xE1, 0x07, | |
| 3482 // sequence delta | |
| 3483 0x01, 0x00, | |
| 3484 // time delta | |
| 3485 0x01, 0x00, 0x00, 0x00, | |
| 3486 // sequence delta (skip one packet) | |
| 3487 0x03, 0x00, | |
| 3488 // time delta | |
| 3489 0x02, 0x00, 0x00, 0x00, | |
| 3490 }; | |
| 3491 | |
| 3492 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 3493 ASSERT_TRUE(data != NULL); | |
| 3494 | |
| 3495 test::CompareCharArraysWithHexError("constructed packet", | |
| 3496 data->data(), data->length(), | |
| 3497 AsChars(packet), arraysize(packet)); | |
| 3498 } | |
| 3499 | |
| 3500 TEST_P(QuicFramerTest, BuildStopWaitingPacket) { | 3341 TEST_P(QuicFramerTest, BuildStopWaitingPacket) { |
| 3501 QuicPacketHeader header; | 3342 QuicPacketHeader header; |
| 3502 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); | 3343 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); |
| 3503 header.public_header.reset_flag = false; | 3344 header.public_header.reset_flag = false; |
| 3504 header.public_header.version_flag = false; | 3345 header.public_header.version_flag = false; |
| 3505 header.fec_flag = false; | 3346 header.fec_flag = false; |
| 3506 header.entropy_flag = true; | 3347 header.entropy_flag = true; |
| 3507 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8); | 3348 header.packet_sequence_number = GG_UINT64_C(0x770123456789AA8); |
| 3508 header.fec_group = 0; | 3349 header.fec_group = 0; |
| 3509 | 3350 |
| (...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4326 EXPECT_CALL(visitor, OnPacketComplete()); | 4167 EXPECT_CALL(visitor, OnPacketComplete()); |
| 4327 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); | 4168 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); |
| 4328 | 4169 |
| 4329 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 4170 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 4330 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 4171 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 4331 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 4172 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4332 } | 4173 } |
| 4333 | 4174 |
| 4334 } // namespace test | 4175 } // namespace test |
| 4335 } // namespace net | 4176 } // namespace net |
| OLD | NEW |