OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 // | |
5 // TCP cubic send side congestion algorithm, emulates the behavior of | |
6 // TCP cubic. | |
7 | |
8 #ifndef NET_QUIC_CONGESTION_CONTROL_TCP_CUBIC_SENDER_H_ | |
9 #define NET_QUIC_CONGESTION_CONTROL_TCP_CUBIC_SENDER_H_ | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/compiler_specific.h" | |
13 #include "net/base/net_export.h" | |
14 #include "net/quic/congestion_control/cubic.h" | |
15 #include "net/quic/congestion_control/hybrid_slow_start.h" | |
16 #include "net/quic/congestion_control/prr_sender.h" | |
17 #include "net/quic/congestion_control/send_algorithm_interface.h" | |
18 #include "net/quic/crypto/cached_network_parameters.h" | |
19 #include "net/quic/quic_bandwidth.h" | |
20 #include "net/quic/quic_connection_stats.h" | |
21 #include "net/quic/quic_protocol.h" | |
22 #include "net/quic/quic_time.h" | |
23 | |
24 namespace net { | |
25 | |
26 class RttStats; | |
27 | |
28 namespace test { | |
29 class TcpCubicSenderPeer; | |
30 } // namespace test | |
31 | |
32 class NET_EXPORT_PRIVATE TcpCubicSender : public SendAlgorithmInterface { | |
33 public: | |
34 // Reno option and max_tcp_congestion_window are provided for testing. | |
35 TcpCubicSender(const QuicClock* clock, | |
36 const RttStats* rtt_stats, | |
37 bool reno, | |
38 QuicPacketCount initial_tcp_congestion_window, | |
39 QuicPacketCount max_tcp_congestion_window, | |
40 QuicConnectionStats* stats); | |
41 ~TcpCubicSender() override; | |
42 | |
43 // Start implementation of SendAlgorithmInterface. | |
44 void SetFromConfig(const QuicConfig& config, | |
45 bool is_server, | |
46 bool using_pacing) override; | |
47 bool ResumeConnectionState( | |
48 const CachedNetworkParameters& cached_network_params) override; | |
49 void SetNumEmulatedConnections(int num_connections) override; | |
50 void OnCongestionEvent(bool rtt_updated, | |
51 QuicByteCount bytes_in_flight, | |
52 const CongestionVector& acked_packets, | |
53 const CongestionVector& lost_packets) override; | |
54 bool OnPacketSent(QuicTime sent_time, | |
55 QuicByteCount bytes_in_flight, | |
56 QuicPacketSequenceNumber sequence_number, | |
57 QuicByteCount bytes, | |
58 HasRetransmittableData is_retransmittable) override; | |
59 void OnRetransmissionTimeout(bool packets_retransmitted) override; | |
60 void RevertRetransmissionTimeout() override; | |
61 QuicTime::Delta TimeUntilSend( | |
62 QuicTime now, | |
63 QuicByteCount bytes_in_flight, | |
64 HasRetransmittableData has_retransmittable_data) const override; | |
65 QuicBandwidth PacingRate() const override; | |
66 QuicBandwidth BandwidthEstimate() const override; | |
67 bool HasReliableBandwidthEstimate() const override; | |
68 QuicTime::Delta RetransmissionDelay() const override; | |
69 QuicByteCount GetCongestionWindow() const override; | |
70 bool InSlowStart() const override; | |
71 bool InRecovery() const override; | |
72 QuicByteCount GetSlowStartThreshold() const override; | |
73 CongestionControlType GetCongestionControlType() const override; | |
74 // End implementation of SendAlgorithmInterface. | |
75 | |
76 private: | |
77 friend class test::TcpCubicSenderPeer; | |
78 | |
79 // Compute the TCP Reno beta based on the current number of connections. | |
80 float RenoBeta() const; | |
81 | |
82 // TODO(ianswett): Remove these and migrate to OnCongestionEvent. | |
83 void OnPacketAcked(QuicPacketSequenceNumber acked_sequence_number, | |
84 QuicByteCount acked_bytes, | |
85 QuicByteCount bytes_in_flight); | |
86 void OnPacketLost(QuicPacketSequenceNumber largest_loss, | |
87 QuicByteCount bytes_in_flight); | |
88 | |
89 void MaybeIncreaseCwnd(QuicPacketSequenceNumber acked_sequence_number, | |
90 QuicByteCount bytes_in_flight); | |
91 bool IsCwndLimited(QuicByteCount bytes_in_flight) const; | |
92 | |
93 HybridSlowStart hybrid_slow_start_; | |
94 Cubic cubic_; | |
95 PrrSender prr_; | |
96 const RttStats* rtt_stats_; | |
97 QuicConnectionStats* stats_; | |
98 | |
99 // If true, Reno congestion control is used instead of Cubic. | |
100 const bool reno_; | |
101 | |
102 // Number of connections to simulate. | |
103 uint32 num_connections_; | |
104 | |
105 // ACK counter for the Reno implementation. | |
106 uint64 congestion_window_count_; | |
107 | |
108 // Track the largest packet that has been sent. | |
109 QuicPacketSequenceNumber largest_sent_sequence_number_; | |
110 | |
111 // Track the largest packet that has been acked. | |
112 QuicPacketSequenceNumber largest_acked_sequence_number_; | |
113 | |
114 // Track the largest sequence number outstanding when a CWND cutback occurs. | |
115 QuicPacketSequenceNumber largest_sent_at_last_cutback_; | |
116 | |
117 // Congestion window in packets. | |
118 QuicPacketCount congestion_window_; | |
119 | |
120 // Congestion window before the last RTO. | |
121 // Must be 0 before or after RTO recovery. | |
122 QuicPacketCount previous_congestion_window_; | |
123 | |
124 // Slow start congestion window in packets, aka ssthresh. | |
125 QuicPacketCount slowstart_threshold_; | |
126 | |
127 // Slow start threshold before the last loss event or RTO. | |
128 QuicPacketCount previous_slowstart_threshold_; | |
129 | |
130 // Whether the last loss event caused us to exit slowstart. | |
131 // Used for stats collection of slowstart_packets_lost | |
132 bool last_cutback_exited_slowstart_; | |
133 | |
134 // Maximum number of outstanding packets for tcp. | |
135 QuicPacketCount max_tcp_congestion_window_; | |
136 | |
137 const QuicClock* clock_; | |
138 | |
139 DISALLOW_COPY_AND_ASSIGN(TcpCubicSender); | |
140 }; | |
141 | |
142 } // namespace net | |
143 | |
144 #endif // NET_QUIC_CONGESTION_CONTROL_TCP_CUBIC_SENDER_H_ | |
OLD | NEW |