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