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 "base/basictypes.h"
14#include "net/base/net_export.h"
15#include "net/quic/quic_bandwidth.h"
16#include "net/quic/quic_clock.h"
17#include "net/quic/quic_config.h"
18#include "net/quic/quic_connection_stats.h"
19#include "net/quic/quic_protocol.h"
20#include "net/quic/quic_time.h"
21
22namespace net {
23
24class RttStats;
25
26class NET_EXPORT_PRIVATE SendAlgorithmInterface {
27 public:
28  typedef std::map<QuicPacketSequenceNumber, TransmissionInfo> CongestionMap;
29
30  static SendAlgorithmInterface* Create(const QuicClock* clock,
31                                        const RttStats* rtt_stats,
32                                        CongestionFeedbackType type,
33                                        QuicConnectionStats* stats);
34
35  virtual ~SendAlgorithmInterface() {}
36
37  virtual void SetFromConfig(const QuicConfig& config, bool is_server) = 0;
38
39  // Called when we receive congestion feedback from remote peer.
40  virtual void OnIncomingQuicCongestionFeedbackFrame(
41      const QuicCongestionFeedbackFrame& feedback,
42      QuicTime feedback_receive_time) = 0;
43
44  // Indicates an update to the congestion state, caused either by an incoming
45  // ack or loss event timeout.  |rtt_updated| indicates whether a new
46  // latest_rtt sample has been taken, |byte_in_flight| the bytes in flight
47  // prior to the congestion event.  |acked_packets| and |lost_packets| are
48  // any packets considered acked or lost as a result of the congestion event.
49  virtual void OnCongestionEvent(bool rtt_updated,
50                                 QuicByteCount bytes_in_flight,
51                                 const CongestionMap& acked_packets,
52                                 const CongestionMap& lost_packets) = 0;
53
54  // Inform that we sent |bytes| to the wire, and if the packet is
55  // retransmittable. Returns true if the packet should be tracked by the
56  // congestion manager and included in bytes_in_flight, false otherwise.
57  // |bytes_in_flight| is the number of bytes in flight before the packet was
58  // sent.
59  // Note: this function must be called for every packet sent to the wire.
60  virtual bool OnPacketSent(QuicTime sent_time,
61                            QuicByteCount bytes_in_flight,
62                            QuicPacketSequenceNumber sequence_number,
63                            QuicByteCount bytes,
64                            HasRetransmittableData is_retransmittable) = 0;
65
66  // Called when the retransmission timeout fires.  Neither OnPacketAbandoned
67  // nor OnPacketLost will be called for these packets.
68  virtual void OnRetransmissionTimeout(bool packets_retransmitted) = 0;
69
70  // Calculate the time until we can send the next packet.
71  virtual QuicTime::Delta TimeUntilSend(
72      QuicTime now,
73      QuicByteCount bytes_in_flight,
74      HasRetransmittableData has_retransmittable_data) const = 0;
75
76  // What's the current estimated bandwidth in bytes per second.
77  // Returns 0 when it does not have an estimate.
78  virtual QuicBandwidth BandwidthEstimate() const = 0;
79
80  // Get the send algorithm specific retransmission delay, called RTO in TCP,
81  // Note 1: the caller is responsible for sanity checking this value.
82  // Note 2: this will return zero if we don't have enough data for an estimate.
83  virtual QuicTime::Delta RetransmissionDelay() const = 0;
84
85  // Returns the size of the current congestion window in bytes.  Note, this is
86  // not the *available* window.  Some send algorithms may not use a congestion
87  // window and will return 0.
88  virtual QuicByteCount GetCongestionWindow() const = 0;
89};
90
91}  // namespace net
92
93#endif  // NET_QUIC_CONGESTION_CONTROL_SEND_ALGORITHM_INTERFACE_H_
94