| 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 2119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2130 expected_error = "Unable to read time delta in received packets."; | 2130 expected_error = "Unable to read time delta in received packets."; |
| 2131 } | 2131 } |
| 2132 CheckProcessingFails( | 2132 CheckProcessingFails( |
| 2133 packet, | 2133 packet, |
| 2134 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 2134 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
| 2135 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), | 2135 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), |
| 2136 expected_error, QUIC_INVALID_CONGESTION_FEEDBACK_DATA); | 2136 expected_error, QUIC_INVALID_CONGESTION_FEEDBACK_DATA); |
| 2137 } | 2137 } |
| 2138 } | 2138 } |
| 2139 | 2139 |
| 2140 TEST_P(QuicFramerTest, CongestionFeedbackFrameFixRate) { | |
| 2141 unsigned char packet[] = { | |
| 2142 // public flags (8 byte connection_id) | |
| 2143 0x3C, | |
| 2144 // connection_id | |
| 2145 0x10, 0x32, 0x54, 0x76, | |
| 2146 0x98, 0xBA, 0xDC, 0xFE, | |
| 2147 // packet sequence number | |
| 2148 0xBC, 0x9A, 0x78, 0x56, | |
| 2149 0x34, 0x12, | |
| 2150 // private flags | |
| 2151 0x00, | |
| 2152 | |
| 2153 // frame type (congestion feedback frame) | |
| 2154 0x20, | |
| 2155 // congestion feedback type (fix rate) | |
| 2156 0x02, | |
| 2157 // bitrate_in_bytes_per_second; | |
| 2158 0x01, 0x02, 0x03, 0x04, | |
| 2159 }; | |
| 2160 | |
| 2161 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 2162 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 2163 | |
| 2164 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 2165 ASSERT_TRUE(visitor_.header_.get()); | |
| 2166 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); | |
| 2167 | |
| 2168 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | |
| 2169 ASSERT_EQ(1u, visitor_.congestion_feedback_frames_.size()); | |
| 2170 const QuicCongestionFeedbackFrame& frame = | |
| 2171 *visitor_.congestion_feedback_frames_[0]; | |
| 2172 ASSERT_EQ(kFixRate, frame.type); | |
| 2173 EXPECT_EQ(static_cast<uint32>(0x04030201), | |
| 2174 frame.fix_rate.bitrate.ToBytesPerSecond()); | |
| 2175 | |
| 2176 // Now test framing boundaries | |
| 2177 for (size_t i = kQuicFrameTypeSize; i < 6; ++i) { | |
| 2178 string expected_error; | |
| 2179 if (i < 2) { | |
| 2180 expected_error = "Unable to read congestion feedback type."; | |
| 2181 } else if (i < 6) { | |
| 2182 expected_error = "Unable to read bitrate."; | |
| 2183 } | |
| 2184 CheckProcessingFails( | |
| 2185 packet, | |
| 2186 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | |
| 2187 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), | |
| 2188 expected_error, QUIC_INVALID_CONGESTION_FEEDBACK_DATA); | |
| 2189 } | |
| 2190 } | |
| 2191 | |
| 2192 TEST_P(QuicFramerTest, CongestionFeedbackFrameInvalidFeedback) { | 2140 TEST_P(QuicFramerTest, CongestionFeedbackFrameInvalidFeedback) { |
| 2193 unsigned char packet[] = { | 2141 unsigned char packet[] = { |
| 2194 // public flags (8 byte connection_id) | 2142 // public flags (8 byte connection_id) |
| 2195 0x3C, | 2143 0x3C, |
| 2196 // connection_id | 2144 // connection_id |
| 2197 0x10, 0x32, 0x54, 0x76, | 2145 0x10, 0x32, 0x54, 0x76, |
| 2198 0x98, 0xBA, 0xDC, 0xFE, | 2146 0x98, 0xBA, 0xDC, 0xFE, |
| 2199 // packet sequence number | 2147 // packet sequence number |
| 2200 0xBC, 0x9A, 0x78, 0x56, | 2148 0xBC, 0x9A, 0x78, 0x56, |
| 2201 0x34, 0x12, | 2149 0x34, 0x12, |
| (...skipping 1389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3591 }; | 3539 }; |
| 3592 | 3540 |
| 3593 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | 3541 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 3594 ASSERT_TRUE(data != NULL); | 3542 ASSERT_TRUE(data != NULL); |
| 3595 | 3543 |
| 3596 test::CompareCharArraysWithHexError("constructed packet", | 3544 test::CompareCharArraysWithHexError("constructed packet", |
| 3597 data->data(), data->length(), | 3545 data->data(), data->length(), |
| 3598 AsChars(packet), arraysize(packet)); | 3546 AsChars(packet), arraysize(packet)); |
| 3599 } | 3547 } |
| 3600 | 3548 |
| 3601 TEST_P(QuicFramerTest, BuildCongestionFeedbackFramePacketFixRate) { | |
| 3602 QuicPacketHeader header; | |
| 3603 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); | |
| 3604 header.public_header.reset_flag = false; | |
| 3605 header.public_header.version_flag = false; | |
| 3606 header.fec_flag = false; | |
| 3607 header.entropy_flag = false; | |
| 3608 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); | |
| 3609 header.fec_group = 0; | |
| 3610 | |
| 3611 QuicCongestionFeedbackFrame congestion_feedback_frame; | |
| 3612 congestion_feedback_frame.type = kFixRate; | |
| 3613 congestion_feedback_frame.fix_rate.bitrate | |
| 3614 = QuicBandwidth::FromBytesPerSecond(0x04030201); | |
| 3615 | |
| 3616 QuicFrames frames; | |
| 3617 frames.push_back(QuicFrame(&congestion_feedback_frame)); | |
| 3618 | |
| 3619 unsigned char packet[] = { | |
| 3620 // public flags (8 byte connection_id) | |
| 3621 0x3C, | |
| 3622 // connection_id | |
| 3623 0x10, 0x32, 0x54, 0x76, | |
| 3624 0x98, 0xBA, 0xDC, 0xFE, | |
| 3625 // packet sequence number | |
| 3626 0xBC, 0x9A, 0x78, 0x56, | |
| 3627 0x34, 0x12, | |
| 3628 // private flags | |
| 3629 0x00, | |
| 3630 | |
| 3631 // frame type (congestion feedback frame) | |
| 3632 0x20, | |
| 3633 // congestion feedback type (fix rate) | |
| 3634 0x02, | |
| 3635 // bitrate_in_bytes_per_second; | |
| 3636 0x01, 0x02, 0x03, 0x04, | |
| 3637 }; | |
| 3638 | |
| 3639 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 3640 ASSERT_TRUE(data != NULL); | |
| 3641 | |
| 3642 test::CompareCharArraysWithHexError("constructed packet", | |
| 3643 data->data(), data->length(), | |
| 3644 AsChars(packet), arraysize(packet)); | |
| 3645 } | |
| 3646 | |
| 3647 TEST_P(QuicFramerTest, BuildCongestionFeedbackFramePacketInvalidFeedback) { | 3549 TEST_P(QuicFramerTest, BuildCongestionFeedbackFramePacketInvalidFeedback) { |
| 3648 QuicPacketHeader header; | 3550 QuicPacketHeader header; |
| 3649 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); | 3551 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); |
| 3650 header.public_header.reset_flag = false; | 3552 header.public_header.reset_flag = false; |
| 3651 header.public_header.version_flag = false; | 3553 header.public_header.version_flag = false; |
| 3652 header.fec_flag = false; | 3554 header.fec_flag = false; |
| 3653 header.entropy_flag = false; | 3555 header.entropy_flag = false; |
| 3654 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); | 3556 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); |
| 3655 header.fec_group = 0; | 3557 header.fec_group = 0; |
| 3656 | 3558 |
| 3657 QuicCongestionFeedbackFrame congestion_feedback_frame; | 3559 QuicCongestionFeedbackFrame congestion_feedback_frame; |
| 3658 congestion_feedback_frame.type = | 3560 congestion_feedback_frame.type = |
| 3659 static_cast<CongestionFeedbackType>(kFixRate + 1); | 3561 static_cast<CongestionFeedbackType>(kInterArrival + 1); |
| 3660 | 3562 |
| 3661 QuicFrames frames; | 3563 QuicFrames frames; |
| 3662 frames.push_back(QuicFrame(&congestion_feedback_frame)); | 3564 frames.push_back(QuicFrame(&congestion_feedback_frame)); |
| 3663 | 3565 |
| 3664 scoped_ptr<QuicPacket> data; | 3566 scoped_ptr<QuicPacket> data; |
| 3665 EXPECT_DFATAL( | 3567 EXPECT_DFATAL( |
| 3666 data.reset(BuildDataPacket(header, frames)), | 3568 data.reset(BuildDataPacket(header, frames)), |
| 3667 "AppendCongestionFeedbackFrame failed"); | 3569 "AppendCongestionFeedbackFrame failed"); |
| 3668 ASSERT_TRUE(data == NULL); | 3570 ASSERT_TRUE(data == NULL); |
| 3669 } | 3571 } |
| (...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4427 EXPECT_CALL(visitor, OnPacketComplete()); | 4329 EXPECT_CALL(visitor, OnPacketComplete()); |
| 4428 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); | 4330 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); |
| 4429 | 4331 |
| 4430 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 4332 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 4431 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 4333 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 4432 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 4334 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4433 } | 4335 } |
| 4434 | 4336 |
| 4435 } // namespace test | 4337 } // namespace test |
| 4436 } // namespace net | 4338 } // namespace net |
| OLD | NEW |