| 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "net/quic/congestion_control/rtt_stats.h" | 9 #include "net/quic/congestion_control/rtt_stats.h" |
| 10 #include "net/quic/congestion_control/tcp_cubic_sender.h" | 10 #include "net/quic/congestion_control/tcp_cubic_sender.h" |
| 11 #include "net/quic/congestion_control/tcp_receiver.h" | |
| 12 #include "net/quic/crypto/crypto_protocol.h" | 11 #include "net/quic/crypto/crypto_protocol.h" |
| 12 #include "net/quic/quic_protocol.h" |
| 13 #include "net/quic/quic_utils.h" | 13 #include "net/quic/quic_utils.h" |
| 14 #include "net/quic/test_tools/mock_clock.h" | 14 #include "net/quic/test_tools/mock_clock.h" |
| 15 #include "net/quic/test_tools/quic_config_peer.h" | 15 #include "net/quic/test_tools/quic_config_peer.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 using std::make_pair; | |
| 19 using std::min; | 18 using std::min; |
| 20 | 19 |
| 21 namespace net { | 20 namespace net { |
| 22 namespace test { | 21 namespace test { |
| 23 | 22 |
| 24 // TODO(ianswett): A number of theses tests were written with the assumption of | 23 // TODO(ianswett): A number of theses tests were written with the assumption of |
| 25 // an initial CWND of 10. They have carefully calculated values which should be | 24 // an initial CWND of 10. They have carefully calculated values which should be |
| 26 // updated to be based on kInitialCongestionWindowInsecure. | 25 // updated to be based on kInitialCongestionWindowInsecure. |
| 27 const uint32 kInitialCongestionWindowPackets = 10; | 26 const uint32 kInitialCongestionWindowPackets = 10; |
| 28 const uint32 kDefaultWindowTCP = | 27 const uint32 kDefaultWindowTCP = |
| (...skipping 29 matching lines...) Expand all Loading... |
| 58 RttStats rtt_stats_; | 57 RttStats rtt_stats_; |
| 59 QuicConnectionStats stats_; | 58 QuicConnectionStats stats_; |
| 60 }; | 59 }; |
| 61 | 60 |
| 62 class TcpCubicSenderTest : public ::testing::Test { | 61 class TcpCubicSenderTest : public ::testing::Test { |
| 63 protected: | 62 protected: |
| 64 TcpCubicSenderTest() | 63 TcpCubicSenderTest() |
| 65 : one_ms_(QuicTime::Delta::FromMilliseconds(1)), | 64 : one_ms_(QuicTime::Delta::FromMilliseconds(1)), |
| 66 sender_(new TcpCubicSenderPeer(&clock_, true, | 65 sender_(new TcpCubicSenderPeer(&clock_, true, |
| 67 kMaxTcpCongestionWindow)), | 66 kMaxTcpCongestionWindow)), |
| 68 receiver_(new TcpReceiver()), | |
| 69 sequence_number_(1), | 67 sequence_number_(1), |
| 70 acked_sequence_number_(0), | 68 acked_sequence_number_(0), |
| 71 bytes_in_flight_(0) { | 69 bytes_in_flight_(0) { |
| 72 standard_packet_.bytes_sent = kDefaultTCPMSS; | 70 standard_packet_.bytes_sent = kDefaultTCPMSS; |
| 73 } | 71 } |
| 74 | 72 |
| 75 int SendAvailableSendWindow() { | 73 int SendAvailableSendWindow() { |
| 76 // Send as long as TimeUntilSend returns Zero. | 74 // Send as long as TimeUntilSend returns Zero. |
| 77 int packets_sent = 0; | 75 int packets_sent = 0; |
| 78 bool can_send = sender_->TimeUntilSend( | 76 bool can_send = sender_->TimeUntilSend( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 91 // Normal is that TCP acks every other segment. | 89 // Normal is that TCP acks every other segment. |
| 92 void AckNPackets(int n) { | 90 void AckNPackets(int n) { |
| 93 sender_->rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(60), | 91 sender_->rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(60), |
| 94 QuicTime::Delta::Zero(), | 92 QuicTime::Delta::Zero(), |
| 95 clock_.Now()); | 93 clock_.Now()); |
| 96 SendAlgorithmInterface::CongestionVector acked_packets; | 94 SendAlgorithmInterface::CongestionVector acked_packets; |
| 97 SendAlgorithmInterface::CongestionVector lost_packets; | 95 SendAlgorithmInterface::CongestionVector lost_packets; |
| 98 for (int i = 0; i < n; ++i) { | 96 for (int i = 0; i < n; ++i) { |
| 99 ++acked_sequence_number_; | 97 ++acked_sequence_number_; |
| 100 acked_packets.push_back( | 98 acked_packets.push_back( |
| 101 make_pair(acked_sequence_number_, standard_packet_)); | 99 std::make_pair(acked_sequence_number_, standard_packet_)); |
| 102 } | 100 } |
| 103 sender_->OnCongestionEvent( | 101 sender_->OnCongestionEvent( |
| 104 true, bytes_in_flight_, acked_packets, lost_packets); | 102 true, bytes_in_flight_, acked_packets, lost_packets); |
| 105 bytes_in_flight_ -= n * kDefaultTCPMSS; | 103 bytes_in_flight_ -= n * kDefaultTCPMSS; |
| 106 clock_.AdvanceTime(one_ms_); | 104 clock_.AdvanceTime(one_ms_); |
| 107 } | 105 } |
| 108 | 106 |
| 109 void LoseNPackets(int n) { | 107 void LoseNPackets(int n) { |
| 110 SendAlgorithmInterface::CongestionVector acked_packets; | 108 SendAlgorithmInterface::CongestionVector acked_packets; |
| 111 SendAlgorithmInterface::CongestionVector lost_packets; | 109 SendAlgorithmInterface::CongestionVector lost_packets; |
| 112 for (int i = 0; i < n; ++i) { | 110 for (int i = 0; i < n; ++i) { |
| 113 ++acked_sequence_number_; | 111 ++acked_sequence_number_; |
| 114 lost_packets.push_back( | 112 lost_packets.push_back( |
| 115 make_pair(acked_sequence_number_, standard_packet_)); | 113 std::make_pair(acked_sequence_number_, standard_packet_)); |
| 116 } | 114 } |
| 117 sender_->OnCongestionEvent( | 115 sender_->OnCongestionEvent( |
| 118 false, bytes_in_flight_, acked_packets, lost_packets); | 116 false, bytes_in_flight_, acked_packets, lost_packets); |
| 119 bytes_in_flight_ -= n * kDefaultTCPMSS; | 117 bytes_in_flight_ -= n * kDefaultTCPMSS; |
| 120 } | 118 } |
| 121 | 119 |
| 122 // Does not increment acked_sequence_number_. | 120 // Does not increment acked_sequence_number_. |
| 123 void LosePacket(QuicPacketSequenceNumber sequence_number) { | 121 void LosePacket(QuicPacketSequenceNumber sequence_number) { |
| 124 SendAlgorithmInterface::CongestionVector acked_packets; | 122 SendAlgorithmInterface::CongestionVector acked_packets; |
| 125 SendAlgorithmInterface::CongestionVector lost_packets; | 123 SendAlgorithmInterface::CongestionVector lost_packets; |
| 126 lost_packets.push_back( | 124 lost_packets.push_back(std::make_pair(sequence_number, standard_packet_)); |
| 127 make_pair(sequence_number, standard_packet_)); | |
| 128 sender_->OnCongestionEvent( | 125 sender_->OnCongestionEvent( |
| 129 false, bytes_in_flight_, acked_packets, lost_packets); | 126 false, bytes_in_flight_, acked_packets, lost_packets); |
| 130 bytes_in_flight_ -= kDefaultTCPMSS; | 127 bytes_in_flight_ -= kDefaultTCPMSS; |
| 131 } | 128 } |
| 132 | 129 |
| 133 const QuicTime::Delta one_ms_; | 130 const QuicTime::Delta one_ms_; |
| 134 MockClock clock_; | 131 MockClock clock_; |
| 135 scoped_ptr<TcpCubicSenderPeer> sender_; | 132 scoped_ptr<TcpCubicSenderPeer> sender_; |
| 136 scoped_ptr<TcpReceiver> receiver_; | |
| 137 QuicPacketSequenceNumber sequence_number_; | 133 QuicPacketSequenceNumber sequence_number_; |
| 138 QuicPacketSequenceNumber acked_sequence_number_; | 134 QuicPacketSequenceNumber acked_sequence_number_; |
| 139 QuicByteCount bytes_in_flight_; | 135 QuicByteCount bytes_in_flight_; |
| 140 TransmissionInfo standard_packet_; | 136 TransmissionInfo standard_packet_; |
| 141 }; | 137 }; |
| 142 | 138 |
| 143 TEST_F(TcpCubicSenderTest, SimpleSender) { | 139 TEST_F(TcpCubicSenderTest, SimpleSender) { |
| 144 // At startup make sure we are at the default. | 140 // At startup make sure we are at the default. |
| 145 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); | 141 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); |
| 146 // At startup make sure we can send. | 142 // At startup make sure we can send. |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 | 752 |
| 757 cached_network_params.set_bandwidth_estimate_bytes_per_second( | 753 cached_network_params.set_bandwidth_estimate_bytes_per_second( |
| 758 (kMinCongestionWindowForBandwidthResumption - 1) * kMaxPacketSize); | 754 (kMinCongestionWindowForBandwidthResumption - 1) * kMaxPacketSize); |
| 759 EXPECT_TRUE(sender_->ResumeConnectionState(cached_network_params)); | 755 EXPECT_TRUE(sender_->ResumeConnectionState(cached_network_params)); |
| 760 EXPECT_EQ(kMinCongestionWindowForBandwidthResumption, | 756 EXPECT_EQ(kMinCongestionWindowForBandwidthResumption, |
| 761 sender_->congestion_window()); | 757 sender_->congestion_window()); |
| 762 } | 758 } |
| 763 | 759 |
| 764 } // namespace test | 760 } // namespace test |
| 765 } // namespace net | 761 } // namespace net |
| OLD | NEW |