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; | 18 using std::make_pair; |
19 using std::min; | 19 using std::min; |
20 | 20 |
21 namespace net { | 21 namespace net { |
22 namespace test { | 22 namespace test { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 RttStats rtt_stats_; | 58 RttStats rtt_stats_; |
59 QuicConnectionStats stats_; | 59 QuicConnectionStats stats_; |
60 }; | 60 }; |
61 | 61 |
62 class TcpCubicSenderTest : public ::testing::Test { | 62 class TcpCubicSenderTest : public ::testing::Test { |
63 protected: | 63 protected: |
64 TcpCubicSenderTest() | 64 TcpCubicSenderTest() |
65 : one_ms_(QuicTime::Delta::FromMilliseconds(1)), | 65 : one_ms_(QuicTime::Delta::FromMilliseconds(1)), |
66 sender_(new TcpCubicSenderPeer(&clock_, true, | 66 sender_(new TcpCubicSenderPeer(&clock_, true, |
67 kMaxTcpCongestionWindow)), | 67 kMaxTcpCongestionWindow)), |
68 receiver_(new TcpReceiver()), | |
69 sequence_number_(1), | 68 sequence_number_(1), |
70 acked_sequence_number_(0), | 69 acked_sequence_number_(0), |
71 bytes_in_flight_(0) { | 70 bytes_in_flight_(0) { |
72 standard_packet_.bytes_sent = kDefaultTCPMSS; | 71 standard_packet_.bytes_sent = kDefaultTCPMSS; |
73 } | 72 } |
74 | 73 |
75 int SendAvailableSendWindow() { | 74 int SendAvailableSendWindow() { |
76 // Send as long as TimeUntilSend returns Zero. | 75 // Send as long as TimeUntilSend returns Zero. |
77 int packets_sent = 0; | 76 int packets_sent = 0; |
78 bool can_send = sender_->TimeUntilSend( | 77 bool can_send = sender_->TimeUntilSend( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 lost_packets.push_back( | 125 lost_packets.push_back( |
127 make_pair(sequence_number, standard_packet_)); | 126 make_pair(sequence_number, standard_packet_)); |
128 sender_->OnCongestionEvent( | 127 sender_->OnCongestionEvent( |
129 false, bytes_in_flight_, acked_packets, lost_packets); | 128 false, bytes_in_flight_, acked_packets, lost_packets); |
130 bytes_in_flight_ -= kDefaultTCPMSS; | 129 bytes_in_flight_ -= kDefaultTCPMSS; |
131 } | 130 } |
132 | 131 |
133 const QuicTime::Delta one_ms_; | 132 const QuicTime::Delta one_ms_; |
134 MockClock clock_; | 133 MockClock clock_; |
135 scoped_ptr<TcpCubicSenderPeer> sender_; | 134 scoped_ptr<TcpCubicSenderPeer> sender_; |
136 scoped_ptr<TcpReceiver> receiver_; | |
137 QuicPacketSequenceNumber sequence_number_; | 135 QuicPacketSequenceNumber sequence_number_; |
138 QuicPacketSequenceNumber acked_sequence_number_; | 136 QuicPacketSequenceNumber acked_sequence_number_; |
139 QuicByteCount bytes_in_flight_; | 137 QuicByteCount bytes_in_flight_; |
140 TransmissionInfo standard_packet_; | 138 TransmissionInfo standard_packet_; |
141 }; | 139 }; |
142 | 140 |
143 TEST_F(TcpCubicSenderTest, SimpleSender) { | 141 TEST_F(TcpCubicSenderTest, SimpleSender) { |
144 // At startup make sure we are at the default. | 142 // At startup make sure we are at the default. |
145 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); | 143 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); |
146 // At startup make sure we can send. | 144 // At startup make sure we can send. |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 | 754 |
757 cached_network_params.set_bandwidth_estimate_bytes_per_second( | 755 cached_network_params.set_bandwidth_estimate_bytes_per_second( |
758 (kMinCongestionWindowForBandwidthResumption - 1) * kMaxPacketSize); | 756 (kMinCongestionWindowForBandwidthResumption - 1) * kMaxPacketSize); |
759 EXPECT_TRUE(sender_->ResumeConnectionState(cached_network_params)); | 757 EXPECT_TRUE(sender_->ResumeConnectionState(cached_network_params)); |
760 EXPECT_EQ(kMinCongestionWindowForBandwidthResumption, | 758 EXPECT_EQ(kMinCongestionWindowForBandwidthResumption, |
761 sender_->congestion_window()); | 759 sender_->congestion_window()); |
762 } | 760 } |
763 | 761 |
764 } // namespace test | 762 } // namespace test |
765 } // namespace net | 763 } // namespace net |
OLD | NEW |