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_connection.h" | 5 #include "net/quic/quic_connection.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 1584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1595 size_t payload_length; | 1595 size_t payload_length; |
1596 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining | 1596 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining |
1597 // packet length. The size of the offset field in a stream frame is 0 for | 1597 // packet length. The size of the offset field in a stream frame is 0 for |
1598 // offset 0, and 2 for non-zero offsets up through 64K. Increase | 1598 // offset 0, and 2 for non-zero offsets up through 64K. Increase |
1599 // max_packet_length by 2 so that subsequent packets containing subsequent | 1599 // max_packet_length by 2 so that subsequent packets containing subsequent |
1600 // stream frames with non-zero offets will fit within the packet length. | 1600 // stream frames with non-zero offets will fit within the packet length. |
1601 size_t length = 2 + GetPacketLengthForOneStream( | 1601 size_t length = 2 + GetPacketLengthForOneStream( |
1602 connection_.version(), kIncludeVersion, | 1602 connection_.version(), kIncludeVersion, |
1603 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, | 1603 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, |
1604 IN_FEC_GROUP, &payload_length); | 1604 IN_FEC_GROUP, &payload_length); |
1605 creator_->set_max_packet_length(length); | 1605 creator_->SetMaxPacketLength(length); |
1606 | 1606 |
1607 // Send 4 protected data packets, which should also trigger 1 FEC packet. | 1607 // Send 4 protected data packets, which should also trigger 1 FEC packet. |
1608 EXPECT_CALL(*send_algorithm_, | 1608 EXPECT_CALL(*send_algorithm_, |
1609 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(5); | 1609 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(5); |
1610 // The first stream frame will have 2 fewer overhead bytes than the other 3. | 1610 // The first stream frame will have 2 fewer overhead bytes than the other 3. |
1611 const string payload(payload_length * 4 + 2, 'a'); | 1611 const string payload(payload_length * 4 + 2, 'a'); |
1612 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); | 1612 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); |
1613 // Expect the FEC group to be closed after SendStreamDataWithString. | 1613 // Expect the FEC group to be closed after SendStreamDataWithString. |
1614 EXPECT_FALSE(creator_->IsFecGroupOpen()); | 1614 EXPECT_FALSE(creator_->IsFecGroupOpen()); |
1615 EXPECT_FALSE(creator_->IsFecProtected()); | 1615 EXPECT_FALSE(creator_->IsFecProtected()); |
1616 } | 1616 } |
1617 | 1617 |
1618 TEST_P(QuicConnectionTest, FECQueueing) { | 1618 TEST_P(QuicConnectionTest, FECQueueing) { |
1619 // All packets carry version info till version is negotiated. | 1619 // All packets carry version info till version is negotiated. |
1620 size_t payload_length; | 1620 size_t payload_length; |
1621 size_t length = GetPacketLengthForOneStream( | 1621 size_t length = GetPacketLengthForOneStream( |
1622 connection_.version(), kIncludeVersion, | 1622 connection_.version(), kIncludeVersion, |
1623 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, | 1623 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, |
1624 IN_FEC_GROUP, &payload_length); | 1624 IN_FEC_GROUP, &payload_length); |
1625 creator_->set_max_packet_length(length); | 1625 creator_->SetMaxPacketLength(length); |
1626 EXPECT_TRUE(creator_->IsFecEnabled()); | 1626 EXPECT_TRUE(creator_->IsFecEnabled()); |
1627 | 1627 |
1628 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1628 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
1629 BlockOnNextWrite(); | 1629 BlockOnNextWrite(); |
1630 const string payload(payload_length, 'a'); | 1630 const string payload(payload_length, 'a'); |
1631 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); | 1631 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); |
1632 EXPECT_FALSE(creator_->IsFecGroupOpen()); | 1632 EXPECT_FALSE(creator_->IsFecGroupOpen()); |
1633 EXPECT_FALSE(creator_->IsFecProtected()); | 1633 EXPECT_FALSE(creator_->IsFecProtected()); |
1634 // Expect the first data packet and the fec packet to be queued. | 1634 // Expect the first data packet and the fec packet to be queued. |
1635 EXPECT_EQ(2u, connection_.NumQueuedPackets()); | 1635 EXPECT_EQ(2u, connection_.NumQueuedPackets()); |
(...skipping 1641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3277 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 3277 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
3278 } | 3278 } |
3279 | 3279 |
3280 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { | 3280 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { |
3281 // All packets carry version info till version is negotiated. | 3281 // All packets carry version info till version is negotiated. |
3282 size_t payload_length; | 3282 size_t payload_length; |
3283 size_t length = GetPacketLengthForOneStream( | 3283 size_t length = GetPacketLengthForOneStream( |
3284 connection_.version(), kIncludeVersion, | 3284 connection_.version(), kIncludeVersion, |
3285 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, | 3285 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, |
3286 NOT_IN_FEC_GROUP, &payload_length); | 3286 NOT_IN_FEC_GROUP, &payload_length); |
3287 creator_->set_max_packet_length(length); | 3287 creator_->SetMaxPacketLength(length); |
3288 | 3288 |
3289 // Queue the first packet. | 3289 // Queue the first packet. |
3290 EXPECT_CALL(*send_algorithm_, | 3290 EXPECT_CALL(*send_algorithm_, |
3291 TimeUntilSend(_, _, _)).WillOnce( | 3291 TimeUntilSend(_, _, _)).WillOnce( |
3292 testing::Return(QuicTime::Delta::FromMicroseconds(10))); | 3292 testing::Return(QuicTime::Delta::FromMicroseconds(10))); |
3293 const string payload(payload_length, 'a'); | 3293 const string payload(payload_length, 'a'); |
3294 EXPECT_EQ(0u, connection_.SendStreamDataWithString(3, payload, 0, !kFin, | 3294 EXPECT_EQ(0u, connection_.SendStreamDataWithString(3, payload, 0, !kFin, |
3295 nullptr).bytes_consumed); | 3295 nullptr).bytes_consumed); |
3296 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 3296 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
3297 } | 3297 } |
3298 | 3298 |
3299 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { | 3299 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { |
3300 // All packets carry version info till version is negotiated. | 3300 // All packets carry version info till version is negotiated. |
3301 size_t payload_length; | 3301 size_t payload_length; |
3302 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining | 3302 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining |
3303 // packet length. The size of the offset field in a stream frame is 0 for | 3303 // packet length. The size of the offset field in a stream frame is 0 for |
3304 // offset 0, and 2 for non-zero offsets up through 16K. Increase | 3304 // offset 0, and 2 for non-zero offsets up through 16K. Increase |
3305 // max_packet_length by 2 so that subsequent packets containing subsequent | 3305 // max_packet_length by 2 so that subsequent packets containing subsequent |
3306 // stream frames with non-zero offets will fit within the packet length. | 3306 // stream frames with non-zero offets will fit within the packet length. |
3307 size_t length = 2 + GetPacketLengthForOneStream( | 3307 size_t length = 2 + GetPacketLengthForOneStream( |
3308 connection_.version(), kIncludeVersion, | 3308 connection_.version(), kIncludeVersion, |
3309 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, | 3309 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, |
3310 NOT_IN_FEC_GROUP, &payload_length); | 3310 NOT_IN_FEC_GROUP, &payload_length); |
3311 creator_->set_max_packet_length(length); | 3311 creator_->SetMaxPacketLength(length); |
3312 | 3312 |
3313 // Queue the first packet. | 3313 // Queue the first packet. |
3314 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7); | 3314 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7); |
3315 // The first stream frame will have 2 fewer overhead bytes than the other six. | 3315 // The first stream frame will have 2 fewer overhead bytes than the other six. |
3316 const string payload(payload_length * 7 + 2, 'a'); | 3316 const string payload(payload_length * 7 + 2, 'a'); |
3317 EXPECT_EQ(payload.size(), | 3317 EXPECT_EQ(payload.size(), |
3318 connection_.SendStreamDataWithString(1, payload, 0, !kFin, nullptr) | 3318 connection_.SendStreamDataWithString(1, payload, 0, !kFin, nullptr) |
3319 .bytes_consumed); | 3319 .bytes_consumed); |
3320 } | 3320 } |
3321 | 3321 |
(...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4407 // Regression test for b/18594622 | 4407 // Regression test for b/18594622 |
4408 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 4408 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
4409 EXPECT_DFATAL( | 4409 EXPECT_DFATAL( |
4410 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), | 4410 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), |
4411 "Attempt to send empty stream frame"); | 4411 "Attempt to send empty stream frame"); |
4412 } | 4412 } |
4413 | 4413 |
4414 } // namespace | 4414 } // namespace |
4415 } // namespace test | 4415 } // namespace test |
4416 } // namespace net | 4416 } // namespace net |
OLD | NEW |