| 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 2027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2038 expected_error = "Unable to read receive window."; | 2038 expected_error = "Unable to read receive window."; |
| 2039 } | 2039 } |
| 2040 CheckProcessingFails( | 2040 CheckProcessingFails( |
| 2041 packet, | 2041 packet, |
| 2042 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 2042 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
| 2043 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), | 2043 PACKET_6BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), |
| 2044 expected_error, QUIC_INVALID_CONGESTION_FEEDBACK_DATA); | 2044 expected_error, QUIC_INVALID_CONGESTION_FEEDBACK_DATA); |
| 2045 } | 2045 } |
| 2046 } | 2046 } |
| 2047 | 2047 |
| 2048 TEST_P(QuicFramerTest, CongestionFeedbackFrameInterArrival) { | 2048 TEST_P(QuicFramerTest, CongestionFeedbackFrameTimestamp) { |
| 2049 unsigned char packet[] = { | 2049 unsigned char packet[] = { |
| 2050 // public flags (8 byte connection_id) | 2050 // public flags (8 byte connection_id) |
| 2051 0x3C, | 2051 0x3C, |
| 2052 // connection_id | 2052 // connection_id |
| 2053 0x10, 0x32, 0x54, 0x76, | 2053 0x10, 0x32, 0x54, 0x76, |
| 2054 0x98, 0xBA, 0xDC, 0xFE, | 2054 0x98, 0xBA, 0xDC, 0xFE, |
| 2055 // packet sequence number | 2055 // packet sequence number |
| 2056 0xBC, 0x9A, 0x78, 0x56, | 2056 0xBC, 0x9A, 0x78, 0x56, |
| 2057 0x34, 0x12, | 2057 0x34, 0x12, |
| 2058 // private flags | 2058 // private flags |
| 2059 0x00, | 2059 0x00, |
| 2060 | 2060 |
| 2061 // frame type (congestion feedback frame) | 2061 // frame type (congestion feedback frame) |
| 2062 0x20, | 2062 0x20, |
| 2063 // congestion feedback type (inter arrival) | 2063 // congestion feedback type (timestamp) |
| 2064 0x01, | 2064 0x01, |
| 2065 // num received packets | 2065 // num received packets |
| 2066 0x03, | 2066 0x03, |
| 2067 // lowest sequence number | 2067 // lowest sequence number |
| 2068 0xBA, 0x9A, 0x78, 0x56, | 2068 0xBA, 0x9A, 0x78, 0x56, |
| 2069 0x34, 0x12, | 2069 0x34, 0x12, |
| 2070 // receive time | 2070 // receive time |
| 2071 0x87, 0x96, 0xA5, 0xB4, | 2071 0x87, 0x96, 0xA5, 0xB4, |
| 2072 0xC3, 0xD2, 0xE1, 0x07, | 2072 0xC3, 0xD2, 0xE1, 0x07, |
| 2073 // sequence delta | 2073 // sequence delta |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2084 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 2084 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 2085 | 2085 |
| 2086 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 2086 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2087 ASSERT_TRUE(visitor_.header_.get()); | 2087 ASSERT_TRUE(visitor_.header_.get()); |
| 2088 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); | 2088 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); |
| 2089 | 2089 |
| 2090 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | 2090 EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 2091 ASSERT_EQ(1u, visitor_.congestion_feedback_frames_.size()); | 2091 ASSERT_EQ(1u, visitor_.congestion_feedback_frames_.size()); |
| 2092 const QuicCongestionFeedbackFrame& frame = | 2092 const QuicCongestionFeedbackFrame& frame = |
| 2093 *visitor_.congestion_feedback_frames_[0]; | 2093 *visitor_.congestion_feedback_frames_[0]; |
| 2094 ASSERT_EQ(kInterArrival, frame.type); | 2094 ASSERT_EQ(kTimestamp, frame.type); |
| 2095 ASSERT_EQ(3u, frame.inter_arrival.received_packet_times.size()); | 2095 ASSERT_EQ(3u, frame.timestamp.received_packet_times.size()); |
| 2096 TimeMap::const_iterator iter = | 2096 TimeMap::const_iterator iter = |
| 2097 frame.inter_arrival.received_packet_times.begin(); | 2097 frame.timestamp.received_packet_times.begin(); |
| 2098 EXPECT_EQ(GG_UINT64_C(0x0123456789ABA), iter->first); | 2098 EXPECT_EQ(GG_UINT64_C(0x0123456789ABA), iter->first); |
| 2099 EXPECT_EQ(GG_INT64_C(0x07E1D2C3B4A59687), | 2099 EXPECT_EQ(GG_INT64_C(0x07E1D2C3B4A59687), |
| 2100 iter->second.Subtract(start_).ToMicroseconds()); | 2100 iter->second.Subtract(start_).ToMicroseconds()); |
| 2101 ++iter; | 2101 ++iter; |
| 2102 EXPECT_EQ(GG_UINT64_C(0x0123456789ABB), iter->first); | 2102 EXPECT_EQ(GG_UINT64_C(0x0123456789ABB), iter->first); |
| 2103 EXPECT_EQ(GG_INT64_C(0x07E1D2C3B4A59688), | 2103 EXPECT_EQ(GG_INT64_C(0x07E1D2C3B4A59688), |
| 2104 iter->second.Subtract(start_).ToMicroseconds()); | 2104 iter->second.Subtract(start_).ToMicroseconds()); |
| 2105 ++iter; | 2105 ++iter; |
| 2106 EXPECT_EQ(GG_UINT64_C(0x0123456789ABD), iter->first); | 2106 EXPECT_EQ(GG_UINT64_C(0x0123456789ABD), iter->first); |
| 2107 EXPECT_EQ(GG_INT64_C(0x07E1D2C3B4A59689), | 2107 EXPECT_EQ(GG_INT64_C(0x07E1D2C3B4A59689), |
| (...skipping 1314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3422 }; | 3422 }; |
| 3423 | 3423 |
| 3424 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | 3424 scoped_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 3425 ASSERT_TRUE(data != NULL); | 3425 ASSERT_TRUE(data != NULL); |
| 3426 | 3426 |
| 3427 test::CompareCharArraysWithHexError("constructed packet", | 3427 test::CompareCharArraysWithHexError("constructed packet", |
| 3428 data->data(), data->length(), | 3428 data->data(), data->length(), |
| 3429 AsChars(packet), arraysize(packet)); | 3429 AsChars(packet), arraysize(packet)); |
| 3430 } | 3430 } |
| 3431 | 3431 |
| 3432 TEST_P(QuicFramerTest, BuildCongestionFeedbackFramePacketInterArrival) { | 3432 TEST_P(QuicFramerTest, BuildCongestionFeedbackFramePacketTimestamp) { |
| 3433 QuicPacketHeader header; | 3433 QuicPacketHeader header; |
| 3434 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); | 3434 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); |
| 3435 header.public_header.reset_flag = false; | 3435 header.public_header.reset_flag = false; |
| 3436 header.public_header.version_flag = false; | 3436 header.public_header.version_flag = false; |
| 3437 header.fec_flag = false; | 3437 header.fec_flag = false; |
| 3438 header.entropy_flag = false; | 3438 header.entropy_flag = false; |
| 3439 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); | 3439 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); |
| 3440 header.fec_group = 0; | 3440 header.fec_group = 0; |
| 3441 | 3441 |
| 3442 QuicCongestionFeedbackFrame frame; | 3442 QuicCongestionFeedbackFrame frame; |
| 3443 frame.type = kInterArrival; | 3443 frame.type = kTimestamp; |
| 3444 frame.inter_arrival.received_packet_times.insert( | 3444 frame.timestamp.received_packet_times.insert( |
| 3445 make_pair(GG_UINT64_C(0x0123456789ABA), | 3445 make_pair(GG_UINT64_C(0x0123456789ABA), |
| 3446 start_.Add(QuicTime::Delta::FromMicroseconds( | 3446 start_.Add(QuicTime::Delta::FromMicroseconds( |
| 3447 GG_UINT64_C(0x07E1D2C3B4A59687))))); | 3447 GG_UINT64_C(0x07E1D2C3B4A59687))))); |
| 3448 frame.inter_arrival.received_packet_times.insert( | 3448 frame.timestamp.received_packet_times.insert( |
| 3449 make_pair(GG_UINT64_C(0x0123456789ABB), | 3449 make_pair(GG_UINT64_C(0x0123456789ABB), |
| 3450 start_.Add(QuicTime::Delta::FromMicroseconds( | 3450 start_.Add(QuicTime::Delta::FromMicroseconds( |
| 3451 GG_UINT64_C(0x07E1D2C3B4A59688))))); | 3451 GG_UINT64_C(0x07E1D2C3B4A59688))))); |
| 3452 frame.inter_arrival.received_packet_times.insert( | 3452 frame.timestamp.received_packet_times.insert( |
| 3453 make_pair(GG_UINT64_C(0x0123456789ABD), | 3453 make_pair(GG_UINT64_C(0x0123456789ABD), |
| 3454 start_.Add(QuicTime::Delta::FromMicroseconds( | 3454 start_.Add(QuicTime::Delta::FromMicroseconds( |
| 3455 GG_UINT64_C(0x07E1D2C3B4A59689))))); | 3455 GG_UINT64_C(0x07E1D2C3B4A59689))))); |
| 3456 QuicFrames frames; | 3456 QuicFrames frames; |
| 3457 frames.push_back(QuicFrame(&frame)); | 3457 frames.push_back(QuicFrame(&frame)); |
| 3458 | 3458 |
| 3459 unsigned char packet[] = { | 3459 unsigned char packet[] = { |
| 3460 // public flags (8 byte connection_id) | 3460 // public flags (8 byte connection_id) |
| 3461 0x3C, | 3461 0x3C, |
| 3462 // connection_id | 3462 // connection_id |
| 3463 0x10, 0x32, 0x54, 0x76, | 3463 0x10, 0x32, 0x54, 0x76, |
| 3464 0x98, 0xBA, 0xDC, 0xFE, | 3464 0x98, 0xBA, 0xDC, 0xFE, |
| 3465 // packet sequence number | 3465 // packet sequence number |
| 3466 0xBC, 0x9A, 0x78, 0x56, | 3466 0xBC, 0x9A, 0x78, 0x56, |
| 3467 0x34, 0x12, | 3467 0x34, 0x12, |
| 3468 // private flags | 3468 // private flags |
| 3469 0x00, | 3469 0x00, |
| 3470 | 3470 |
| 3471 // frame type (congestion feedback frame) | 3471 // frame type (congestion feedback frame) |
| 3472 0x20, | 3472 0x20, |
| 3473 // congestion feedback type (inter arrival) | 3473 // congestion feedback type (timestamp) |
| 3474 0x01, | 3474 0x01, |
| 3475 // num received packets | 3475 // num received packets |
| 3476 0x03, | 3476 0x03, |
| 3477 // lowest sequence number | 3477 // lowest sequence number |
| 3478 0xBA, 0x9A, 0x78, 0x56, | 3478 0xBA, 0x9A, 0x78, 0x56, |
| 3479 0x34, 0x12, | 3479 0x34, 0x12, |
| 3480 // receive time | 3480 // receive time |
| 3481 0x87, 0x96, 0xA5, 0xB4, | 3481 0x87, 0x96, 0xA5, 0xB4, |
| 3482 0xC3, 0xD2, 0xE1, 0x07, | 3482 0xC3, 0xD2, 0xE1, 0x07, |
| 3483 // sequence delta | 3483 // sequence delta |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3549 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); | 3549 header.public_header.connection_id = GG_UINT64_C(0xFEDCBA9876543210); |
| 3550 header.public_header.reset_flag = false; | 3550 header.public_header.reset_flag = false; |
| 3551 header.public_header.version_flag = false; | 3551 header.public_header.version_flag = false; |
| 3552 header.fec_flag = false; | 3552 header.fec_flag = false; |
| 3553 header.entropy_flag = false; | 3553 header.entropy_flag = false; |
| 3554 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); | 3554 header.packet_sequence_number = GG_UINT64_C(0x123456789ABC); |
| 3555 header.fec_group = 0; | 3555 header.fec_group = 0; |
| 3556 | 3556 |
| 3557 QuicCongestionFeedbackFrame congestion_feedback_frame; | 3557 QuicCongestionFeedbackFrame congestion_feedback_frame; |
| 3558 congestion_feedback_frame.type = | 3558 congestion_feedback_frame.type = |
| 3559 static_cast<CongestionFeedbackType>(kInterArrival + 1); | 3559 static_cast<CongestionFeedbackType>(kTimestamp + 1); |
| 3560 | 3560 |
| 3561 QuicFrames frames; | 3561 QuicFrames frames; |
| 3562 frames.push_back(QuicFrame(&congestion_feedback_frame)); | 3562 frames.push_back(QuicFrame(&congestion_feedback_frame)); |
| 3563 | 3563 |
| 3564 scoped_ptr<QuicPacket> data; | 3564 scoped_ptr<QuicPacket> data; |
| 3565 EXPECT_DFATAL( | 3565 EXPECT_DFATAL( |
| 3566 data.reset(BuildDataPacket(header, frames)), | 3566 data.reset(BuildDataPacket(header, frames)), |
| 3567 "AppendCongestionFeedbackFrame failed"); | 3567 "AppendCongestionFeedbackFrame failed"); |
| 3568 ASSERT_TRUE(data == NULL); | 3568 ASSERT_TRUE(data == NULL); |
| 3569 } | 3569 } |
| (...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4327 EXPECT_CALL(visitor, OnPacketComplete()); | 4327 EXPECT_CALL(visitor, OnPacketComplete()); |
| 4328 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); | 4328 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); |
| 4329 | 4329 |
| 4330 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 4330 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 4331 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 4331 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 4332 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 4332 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4333 } | 4333 } |
| 4334 | 4334 |
| 4335 } // namespace test | 4335 } // namespace test |
| 4336 } // namespace net | 4336 } // namespace net |
| OLD | NEW |