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" | 11 #include "net/quic/congestion_control/tcp_receiver.h" |
12 #include "net/quic/crypto/crypto_protocol.h" | 12 #include "net/quic/crypto/crypto_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::min; | 19 using std::min; |
19 | 20 |
20 namespace net { | 21 namespace net { |
21 namespace test { | 22 namespace test { |
22 | 23 |
23 const uint32 kDefaultWindowTCP = 10 * kDefaultTCPMSS; | 24 const uint32 kDefaultWindowTCP = 10 * kDefaultTCPMSS; |
24 | 25 |
25 // TODO(ianswett): Remove 10000 once b/10075719 is fixed. | 26 // TODO(ianswett): Remove 10000 once b/10075719 is fixed. |
26 const QuicTcpCongestionWindow kDefaultMaxCongestionWindowTCP = 10000; | 27 const QuicTcpCongestionWindow kDefaultMaxCongestionWindowTCP = 10000; |
27 | 28 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 clock_.Now(), bytes_in_flight_, HAS_RETRANSMITTABLE_DATA).IsZero(); | 80 clock_.Now(), bytes_in_flight_, HAS_RETRANSMITTABLE_DATA).IsZero(); |
80 } | 81 } |
81 return packets_sent; | 82 return packets_sent; |
82 } | 83 } |
83 | 84 |
84 // Normal is that TCP acks every other segment. | 85 // Normal is that TCP acks every other segment. |
85 void AckNPackets(int n) { | 86 void AckNPackets(int n) { |
86 sender_->rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(60), | 87 sender_->rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(60), |
87 QuicTime::Delta::Zero(), | 88 QuicTime::Delta::Zero(), |
88 clock_.Now()); | 89 clock_.Now()); |
89 SendAlgorithmInterface::CongestionMap acked_packets; | 90 SendAlgorithmInterface::CongestionVector acked_packets; |
90 SendAlgorithmInterface::CongestionMap lost_packets; | 91 SendAlgorithmInterface::CongestionVector lost_packets; |
91 for (int i = 0; i < n; ++i) { | 92 for (int i = 0; i < n; ++i) { |
92 ++acked_sequence_number_; | 93 ++acked_sequence_number_; |
93 acked_packets[acked_sequence_number_] = standard_packet_; | 94 acked_packets.push_back( |
| 95 make_pair(acked_sequence_number_, standard_packet_)); |
94 } | 96 } |
95 sender_->OnCongestionEvent( | 97 sender_->OnCongestionEvent( |
96 true, bytes_in_flight_, acked_packets, lost_packets); | 98 true, bytes_in_flight_, acked_packets, lost_packets); |
97 bytes_in_flight_ -= n * kDefaultTCPMSS; | 99 bytes_in_flight_ -= n * kDefaultTCPMSS; |
98 clock_.AdvanceTime(one_ms_); | 100 clock_.AdvanceTime(one_ms_); |
99 } | 101 } |
100 | 102 |
101 void LoseNPackets(int n) { | 103 void LoseNPackets(int n) { |
102 SendAlgorithmInterface::CongestionMap acked_packets; | 104 SendAlgorithmInterface::CongestionVector acked_packets; |
103 SendAlgorithmInterface::CongestionMap lost_packets; | 105 SendAlgorithmInterface::CongestionVector lost_packets; |
104 for (int i = 0; i < n; ++i) { | 106 for (int i = 0; i < n; ++i) { |
105 ++acked_sequence_number_; | 107 ++acked_sequence_number_; |
106 lost_packets[acked_sequence_number_] = standard_packet_; | 108 lost_packets.push_back( |
| 109 make_pair(acked_sequence_number_, standard_packet_)); |
107 } | 110 } |
108 sender_->OnCongestionEvent( | 111 sender_->OnCongestionEvent( |
109 false, bytes_in_flight_, acked_packets, lost_packets); | 112 false, bytes_in_flight_, acked_packets, lost_packets); |
110 bytes_in_flight_ -= n * kDefaultTCPMSS; | 113 bytes_in_flight_ -= n * kDefaultTCPMSS; |
111 } | 114 } |
112 | 115 |
113 // Does not increment acked_sequence_number_. | 116 // Does not increment acked_sequence_number_. |
114 void LosePacket(QuicPacketSequenceNumber sequence_number) { | 117 void LosePacket(QuicPacketSequenceNumber sequence_number) { |
115 SendAlgorithmInterface::CongestionMap acked_packets; | 118 SendAlgorithmInterface::CongestionVector acked_packets; |
116 SendAlgorithmInterface::CongestionMap lost_packets; | 119 SendAlgorithmInterface::CongestionVector lost_packets; |
117 lost_packets[sequence_number] = standard_packet_; | 120 lost_packets.push_back( |
| 121 make_pair(sequence_number, standard_packet_)); |
118 sender_->OnCongestionEvent( | 122 sender_->OnCongestionEvent( |
119 false, bytes_in_flight_, acked_packets, lost_packets); | 123 false, bytes_in_flight_, acked_packets, lost_packets); |
120 bytes_in_flight_ -= kDefaultTCPMSS; | 124 bytes_in_flight_ -= kDefaultTCPMSS; |
121 } | 125 } |
122 | 126 |
123 const QuicTime::Delta one_ms_; | 127 const QuicTime::Delta one_ms_; |
124 MockClock clock_; | 128 MockClock clock_; |
125 scoped_ptr<TcpCubicSenderPeer> sender_; | 129 scoped_ptr<TcpCubicSenderPeer> sender_; |
126 scoped_ptr<TcpReceiver> receiver_; | 130 scoped_ptr<TcpReceiver> receiver_; |
127 QuicPacketSequenceNumber sequence_number_; | 131 QuicPacketSequenceNumber sequence_number_; |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 } | 615 } |
612 | 616 |
613 // Next ack should cause congestion window to grow by 1MSS. | 617 // Next ack should cause congestion window to grow by 1MSS. |
614 AckNPackets(2); | 618 AckNPackets(2); |
615 expected_send_window += kDefaultTCPMSS; | 619 expected_send_window += kDefaultTCPMSS; |
616 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 620 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
617 } | 621 } |
618 | 622 |
619 } // namespace test | 623 } // namespace test |
620 } // namespace net | 624 } // namespace net |
OLD | NEW |