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 "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/quic/congestion_control/receive_algorithm_interface.h" | 10 #include "net/quic/congestion_control/receive_algorithm_interface.h" |
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 ProcessAckPacket(&frame); | 749 ProcessAckPacket(&frame); |
750 | 750 |
751 // Force an ack to be sent. | 751 // Force an ack to be sent. |
752 SendAckPacketToPeer(); | 752 SendAckPacketToPeer(); |
753 EXPECT_TRUE(IsMissing(4)); | 753 EXPECT_TRUE(IsMissing(4)); |
754 } | 754 } |
755 | 755 |
756 TEST_F(QuicConnectionTest, RejectPacketTooFarOut) { | 756 TEST_F(QuicConnectionTest, RejectPacketTooFarOut) { |
757 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a | 757 // Call ProcessDataPacket rather than ProcessPacket, as we should not get a |
758 // packet call to the visitor. | 758 // packet call to the visitor. |
| 759 EXPECT_CALL(visitor_, ConnectionClose(QUIC_INVALID_PACKET_HEADER, false)); |
759 ProcessDataPacket(6000, 0, !kEntropyFlag); | 760 ProcessDataPacket(6000, 0, !kEntropyFlag); |
760 | |
761 SendAckPacketToPeer(); // Packet 2 | |
762 EXPECT_EQ(0u, outgoing_ack()->received_info.largest_observed); | |
763 } | 761 } |
764 | 762 |
765 TEST_F(QuicConnectionTest, TruncatedAck) { | 763 TEST_F(QuicConnectionTest, TruncatedAck) { |
766 EXPECT_CALL(visitor_, OnAck(_)).Times(testing::AnyNumber()); | 764 EXPECT_CALL(visitor_, OnAck(_)).Times(testing::AnyNumber()); |
767 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); | 765 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(2); |
768 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); | 766 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); |
769 for (int i = 0; i < 200; ++i) { | 767 for (int i = 0; i < 200; ++i) { |
770 SendStreamDataToPeer(1, "foo", i * 3, !kFin, NULL); | 768 SendStreamDataToPeer(1, "foo", i * 3, !kFin, NULL); |
771 } | 769 } |
772 | 770 |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1112 // Second udp packet will force an ack frame. | 1110 // Second udp packet will force an ack frame. |
1113 EXPECT_CALL(*send_algorithm_, | 1111 EXPECT_CALL(*send_algorithm_, |
1114 SentPacket(_, _, _, NOT_RETRANSMISSION)); | 1112 SentPacket(_, _, _, NOT_RETRANSMISSION)); |
1115 ProcessAckPacket(&frame); | 1113 ProcessAckPacket(&frame); |
1116 // Third nack should retransmit the largest observed packet. | 1114 // Third nack should retransmit the largest observed packet. |
1117 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, packet_size - kQuicVersionSize, | 1115 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, packet_size - kQuicVersionSize, |
1118 IS_RETRANSMISSION)); | 1116 IS_RETRANSMISSION)); |
1119 ProcessAckPacket(&frame); | 1117 ProcessAckPacket(&frame); |
1120 } | 1118 } |
1121 | 1119 |
| 1120 TEST_F(QuicConnectionTest, RetransmitNackedPacketsOnTruncatedAck) { |
| 1121 for (int i = 0; i < 200; ++i) { |
| 1122 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(1); |
| 1123 connection_.SendStreamData(1, "foo", i * 3, !kFin); |
| 1124 } |
| 1125 |
| 1126 // Make a truncated ack frame. |
| 1127 QuicAckFrame frame(0, QuicTime::Zero(), 1); |
| 1128 frame.received_info.largest_observed = 192; |
| 1129 InsertMissingPacketsBetween(&frame.received_info, 1, 192); |
| 1130 frame.received_info.entropy_hash = |
| 1131 QuicConnectionPeer::GetSentEntropyHash(&connection_, 192) ^ |
| 1132 QuicConnectionPeer::GetSentEntropyHash(&connection_, 191); |
| 1133 |
| 1134 |
| 1135 EXPECT_CALL(*send_algorithm_, OnIncomingAck(_, _, _)).Times(1); |
| 1136 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); |
| 1137 EXPECT_CALL(visitor_, OnAck(_)).Times(1); |
| 1138 ProcessAckPacket(&frame); |
| 1139 EXPECT_TRUE(QuicConnectionPeer::GetReceivedTruncatedAck(&connection_)); |
| 1140 |
| 1141 QuicConnectionPeer::SetMaxPacketsPerRetransmissionAlarm(&connection_, 200); |
| 1142 const QuicTime::Delta kDefaultRetransmissionTime = |
| 1143 QuicTime::Delta::FromMilliseconds(500); |
| 1144 clock_.AdvanceTime(kDefaultRetransmissionTime); |
| 1145 // Only packets that are less than largest observed should be retransmitted. |
| 1146 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(191); |
| 1147 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(191); |
| 1148 connection_.OnRetransmissionTimeout(); |
| 1149 |
| 1150 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( |
| 1151 2 * kDefaultRetransmissionTime.ToMicroseconds())); |
| 1152 // Retransmit already retransmitted packets event though the sequence number |
| 1153 // greater than the largest observed. |
| 1154 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(191); |
| 1155 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(191); |
| 1156 connection_.OnRetransmissionTimeout(); |
| 1157 } |
| 1158 |
1122 TEST_F(QuicConnectionTest, LimitPacketsPerNack) { | 1159 TEST_F(QuicConnectionTest, LimitPacketsPerNack) { |
1123 EXPECT_CALL(*send_algorithm_, OnIncomingAck(12, _, _)).Times(1); | 1160 EXPECT_CALL(*send_algorithm_, OnIncomingAck(12, _, _)).Times(1); |
1124 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); | 1161 EXPECT_CALL(*send_algorithm_, OnIncomingLoss(_)).Times(1); |
1125 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(11); | 1162 EXPECT_CALL(*send_algorithm_, AbandoningPacket(_, _)).Times(11); |
1126 int offset = 0; | 1163 int offset = 0; |
1127 // Send packets 1 to 12 | 1164 // Send packets 1 to 12 |
1128 for (int i = 0; i < 12; ++i) { | 1165 for (int i = 0; i < 12; ++i) { |
1129 SendStreamDataToPeer(1, "foo", offset, !kFin, NULL); | 1166 SendStreamDataToPeer(1, "foo", offset, !kFin, NULL); |
1130 offset += 3; | 1167 offset += 3; |
1131 } | 1168 } |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1480 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _, _)); | 1517 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _, _)); |
1481 ProcessFecPacket(2, 1, true, !kEntropyFlag); | 1518 ProcessFecPacket(2, 1, true, !kEntropyFlag); |
1482 } | 1519 } |
1483 | 1520 |
1484 TEST_F(QuicConnectionTest, InitialTimeout) { | 1521 TEST_F(QuicConnectionTest, InitialTimeout) { |
1485 EXPECT_TRUE(connection_.connected()); | 1522 EXPECT_TRUE(connection_.connected()); |
1486 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false)); | 1523 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false)); |
1487 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); | 1524 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); |
1488 | 1525 |
1489 QuicTime default_timeout = clock_.ApproximateNow().Add( | 1526 QuicTime default_timeout = clock_.ApproximateNow().Add( |
1490 QuicTime::Delta::FromMicroseconds(kDefaultTimeoutUs)); | 1527 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); |
1491 EXPECT_EQ(default_timeout, helper_->timeout_alarm()); | 1528 EXPECT_EQ(default_timeout, helper_->timeout_alarm()); |
1492 | 1529 |
1493 // Simulate the timeout alarm firing | 1530 // Simulate the timeout alarm firing |
1494 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(kDefaultTimeoutUs)); | 1531 clock_.AdvanceTime( |
| 1532 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); |
1495 EXPECT_TRUE(connection_.CheckForTimeout()); | 1533 EXPECT_TRUE(connection_.CheckForTimeout()); |
1496 EXPECT_FALSE(connection_.connected()); | 1534 EXPECT_FALSE(connection_.connected()); |
1497 } | 1535 } |
1498 | 1536 |
1499 TEST_F(QuicConnectionTest, TimeoutAfterSend) { | 1537 TEST_F(QuicConnectionTest, TimeoutAfterSend) { |
1500 EXPECT_TRUE(connection_.connected()); | 1538 EXPECT_TRUE(connection_.connected()); |
1501 | 1539 |
1502 QuicTime default_timeout = clock_.ApproximateNow().Add( | 1540 QuicTime default_timeout = clock_.ApproximateNow().Add( |
1503 QuicTime::Delta::FromMicroseconds(kDefaultTimeoutUs)); | 1541 QuicTime::Delta::FromSeconds(kDefaultInitialTimeoutSecs)); |
1504 | 1542 |
1505 // When we send a packet, the timeout will change to 5000 + kDefaultTimeout. | 1543 // When we send a packet, the timeout will change to 5000 + |
| 1544 // kDefaultInitialTimeoutSecs. |
1506 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); | 1545 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
1507 | 1546 |
1508 // Send an ack so we don't set the retransimission alarm. | 1547 // Send an ack so we don't set the retransimission alarm. |
1509 SendAckPacketToPeer(); | 1548 SendAckPacketToPeer(); |
1510 EXPECT_EQ(default_timeout, helper_->timeout_alarm()); | 1549 EXPECT_EQ(default_timeout, helper_->timeout_alarm()); |
1511 | 1550 |
1512 // The original alarm will fire. We should not time out because we had a | 1551 // The original alarm will fire. We should not time out because we had a |
1513 // network event at t=5000. The alarm will reregister. | 1552 // network event at t=5000. The alarm will reregister. |
1514 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( | 1553 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( |
1515 kDefaultTimeoutUs - 5000)); | 1554 kDefaultInitialTimeoutSecs * 1000000 - 5000)); |
1516 EXPECT_EQ(default_timeout, clock_.ApproximateNow()); | 1555 EXPECT_EQ(default_timeout, clock_.ApproximateNow()); |
1517 EXPECT_FALSE(connection_.CheckForTimeout()); | 1556 EXPECT_FALSE(connection_.CheckForTimeout()); |
1518 EXPECT_TRUE(connection_.connected()); | 1557 EXPECT_TRUE(connection_.connected()); |
1519 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)), | 1558 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)), |
1520 helper_->timeout_alarm()); | 1559 helper_->timeout_alarm()); |
1521 | 1560 |
1522 // This time, we should time out. | 1561 // This time, we should time out. |
1523 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false)); | 1562 EXPECT_CALL(visitor_, ConnectionClose(QUIC_CONNECTION_TIMED_OUT, false)); |
1524 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); | 1563 EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)); |
1525 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); | 1564 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1986 Return(QuicBandwidth::Zero())); | 2025 Return(QuicBandwidth::Zero())); |
1987 | 2026 |
1988 const QuicConnectionStats& stats = connection_.GetStats(); | 2027 const QuicConnectionStats& stats = connection_.GetStats(); |
1989 EXPECT_EQ(received_bytes, stats.bytes_received); | 2028 EXPECT_EQ(received_bytes, stats.bytes_received); |
1990 EXPECT_EQ(4u, stats.packets_received); | 2029 EXPECT_EQ(4u, stats.packets_received); |
1991 | 2030 |
1992 EXPECT_EQ(1u, stats.packets_revived); | 2031 EXPECT_EQ(1u, stats.packets_revived); |
1993 EXPECT_EQ(1u, stats.packets_dropped); | 2032 EXPECT_EQ(1u, stats.packets_dropped); |
1994 } | 2033 } |
1995 | 2034 |
| 2035 TEST_F(QuicConnectionTest, TestFecGroupLimits) { |
| 2036 // Create and return a group for 1 |
| 2037 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 1) != NULL); |
| 2038 |
| 2039 // Create and return a group for 2 |
| 2040 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 2) != NULL); |
| 2041 |
| 2042 // Create and return a group for 4. This should remove 1 but not 2. |
| 2043 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 4) != NULL); |
| 2044 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 1) == NULL); |
| 2045 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 2) != NULL); |
| 2046 |
| 2047 // Create and return a group for 3. This will kill off 2. |
| 2048 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 3) != NULL); |
| 2049 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 2) == NULL); |
| 2050 |
| 2051 // Verify that adding 5 kills off 3, despite 4 being created before 3. |
| 2052 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 5) != NULL); |
| 2053 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 4) != NULL); |
| 2054 ASSERT_TRUE(QuicConnectionPeer::GetFecGroup(&connection_, 3) == NULL); |
| 2055 } |
| 2056 |
| 2057 TEST_F(QuicConnectionTest, DontProcessFramesIfPacketClosedConnection) { |
| 2058 // Construct a packet with stream frame and connection close frame. |
| 2059 header_.public_header.guid = guid_; |
| 2060 header_.packet_sequence_number = 1; |
| 2061 header_.public_header.reset_flag = false; |
| 2062 header_.public_header.version_flag = false; |
| 2063 header_.entropy_flag = false; |
| 2064 header_.fec_flag = false; |
| 2065 header_.fec_entropy_flag = false; |
| 2066 header_.fec_group = 0; |
| 2067 |
| 2068 QuicConnectionCloseFrame qccf; |
| 2069 qccf.error_code = QUIC_PEER_GOING_AWAY; |
| 2070 qccf.ack_frame = QuicAckFrame(0, QuicTime::Zero(), 1); |
| 2071 QuicFrame close_frame(&qccf); |
| 2072 QuicFrame stream_frame(&frame1_); |
| 2073 |
| 2074 QuicFrames frames; |
| 2075 frames.push_back(stream_frame); |
| 2076 frames.push_back(close_frame); |
| 2077 scoped_ptr<QuicPacket> packet( |
| 2078 framer_.ConstructFrameDataPacket(header_, frames).packet); |
| 2079 EXPECT_TRUE(NULL != packet.get()); |
| 2080 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPacket( |
| 2081 ENCRYPTION_NONE, 1, *packet)); |
| 2082 |
| 2083 EXPECT_CALL(visitor_, ConnectionClose(QUIC_PEER_GOING_AWAY, true)); |
| 2084 EXPECT_CALL(visitor_, OnPacket(_, _, _, _)).Times(0); |
| 2085 |
| 2086 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); |
| 2087 } |
| 2088 |
1996 } // namespace | 2089 } // namespace |
1997 } // namespace test | 2090 } // namespace test |
1998 } // namespace net | 2091 } // namespace net |
OLD | NEW |