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 // The pure virtual class for send side congestion control algorithm. | |
6 | |
7 #ifndef NET_QUIC_CONGESTION_CONTROL_SEND_ALGORITHM_INTERFACE_H_ | |
8 #define NET_QUIC_CONGESTION_CONTROL_SEND_ALGORITHM_INTERFACE_H_ | |
9 | |
10 #include <algorithm> | |
11 #include <map> | |
12 | |
13 #include "net/base/net_export.h" | |
14 #include "net/quic/quic_bandwidth.h" | |
15 #include "net/quic/quic_clock.h" | |
16 #include "net/quic/quic_config.h" | |
17 #include "net/quic/quic_connection_stats.h" | |
18 #include "net/quic/quic_protocol.h" | |
19 #include "net/quic/quic_time.h" | |
20 | |
21 namespace net { | |
22 | |
23 class CachedNetworkParameters; | |
24 class RttStats; | |
25 | |
26 const QuicPacketCount kDefaultMaxCongestionWindowPackets = 2000; | |
27 | |
28 class NET_EXPORT_PRIVATE SendAlgorithmInterface { | |
29 public: | |
30 // A sorted vector of packets. | |
31 typedef std::vector<std::pair<QuicPacketNumber, QuicPacketLength>> | |
32 CongestionVector; | |
33 | |
34 static SendAlgorithmInterface* Create( | |
35 const QuicClock* clock, | |
36 const RttStats* rtt_stats, | |
37 CongestionControlType type, | |
38 QuicConnectionStats* stats, | |
39 QuicPacketCount initial_congestion_window); | |
40 | |
41 virtual ~SendAlgorithmInterface() {} | |
42 | |
43 virtual void SetFromConfig(const QuicConfig& config, | |
44 Perspective perspective) = 0; | |
45 | |
46 // Sets the number of connections to emulate when doing congestion control, | |
47 // particularly for congestion avoidance. Can be set any time. | |
48 virtual void SetNumEmulatedConnections(int num_connections) = 0; | |
49 | |
50 // Indicates an update to the congestion state, caused either by an incoming | |
51 // ack or loss event timeout. |rtt_updated| indicates whether a new | |
52 // latest_rtt sample has been taken, |byte_in_flight| the bytes in flight | |
53 // prior to the congestion event. |acked_packets| and |lost_packets| are | |
54 // any packets considered acked or lost as a result of the congestion event. | |
55 virtual void OnCongestionEvent(bool rtt_updated, | |
56 QuicByteCount bytes_in_flight, | |
57 const CongestionVector& acked_packets, | |
58 const CongestionVector& lost_packets) = 0; | |
59 | |
60 // Inform that we sent |bytes| to the wire, and if the packet is | |
61 // retransmittable. Returns true if the packet should be tracked by the | |
62 // congestion manager and included in bytes_in_flight, false otherwise. | |
63 // |bytes_in_flight| is the number of bytes in flight before the packet was | |
64 // sent. | |
65 // Note: this function must be called for every packet sent to the wire. | |
66 virtual bool OnPacketSent(QuicTime sent_time, | |
67 QuicByteCount bytes_in_flight, | |
68 QuicPacketNumber packet_number, | |
69 QuicByteCount bytes, | |
70 HasRetransmittableData is_retransmittable) = 0; | |
71 | |
72 // Called when the retransmission timeout fires. Neither OnPacketAbandoned | |
73 // nor OnPacketLost will be called for these packets. | |
74 virtual void OnRetransmissionTimeout(bool packets_retransmitted) = 0; | |
75 | |
76 // Called when connection migrates and cwnd needs to be reset. | |
77 virtual void OnConnectionMigration() = 0; | |
78 | |
79 // Calculate the time until we can send the next packet. | |
80 virtual QuicTime::Delta TimeUntilSend( | |
81 QuicTime now, | |
82 QuicByteCount bytes_in_flight) const = 0; | |
83 | |
84 // The pacing rate of the send algorithm. May be zero if the rate is unknown. | |
85 virtual QuicBandwidth PacingRate(QuicByteCount bytes_in_flight) const = 0; | |
86 | |
87 // What's the current estimated bandwidth in bytes per second. | |
88 // Returns 0 when it does not have an estimate. | |
89 virtual QuicBandwidth BandwidthEstimate() const = 0; | |
90 | |
91 // Get the send algorithm specific retransmission delay, called RTO in TCP, | |
92 // Note 1: the caller is responsible for sanity checking this value. | |
93 // Note 2: this will return zero if we don't have enough data for an estimate. | |
94 virtual QuicTime::Delta RetransmissionDelay() const = 0; | |
95 | |
96 // Returns the size of the current congestion window in bytes. Note, this is | |
97 // not the *available* window. Some send algorithms may not use a congestion | |
98 // window and will return 0. | |
99 virtual QuicByteCount GetCongestionWindow() const = 0; | |
100 | |
101 // Whether the send algorithm is currently in slow start. When true, the | |
102 // BandwidthEstimate is expected to be too low. | |
103 virtual bool InSlowStart() const = 0; | |
104 | |
105 // Whether the send algorithm is currently in recovery. | |
106 virtual bool InRecovery() const = 0; | |
107 | |
108 // Returns the size of the slow start congestion window in bytes, | |
109 // aka ssthresh. Some send algorithms do not define a slow start | |
110 // threshold and will return 0. | |
111 virtual QuicByteCount GetSlowStartThreshold() const = 0; | |
112 | |
113 virtual CongestionControlType GetCongestionControlType() const = 0; | |
114 | |
115 // Called by the Session when we get a bandwidth estimate from the client. | |
116 // Uses the max bandwidth in the params if |max_bandwidth_resumption| is true. | |
117 virtual void ResumeConnectionState( | |
118 const CachedNetworkParameters& cached_network_params, | |
119 bool max_bandwidth_resumption) = 0; | |
120 }; | |
121 | |
122 } // namespace net | |
123 | |
124 #endif // NET_QUIC_CONGESTION_CONTROL_SEND_ALGORITHM_INTERFACE_H_ | |
OLD | NEW |