send_algorithm_interface.h revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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 <map>
11
12#include "base/basictypes.h"
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_protocol.h"
17#include "net/quic/quic_time.h"
18
19namespace net {
20
21class NET_EXPORT_PRIVATE SendAlgorithmInterface {
22 public:
23  class SentPacket {
24   public:
25    SentPacket(QuicByteCount bytes, QuicTime timestamp)
26        : bytes_sent_(bytes),
27          send_timestamp_(timestamp) {
28    }
29    QuicByteCount BytesSent() { return bytes_sent_; }
30    QuicTime& SendTimestamp() { return send_timestamp_; }
31
32   private:
33    QuicByteCount bytes_sent_;
34    QuicTime send_timestamp_;
35  };
36
37  typedef std::map<QuicPacketSequenceNumber, SentPacket*> SentPacketsMap;
38
39  static SendAlgorithmInterface* Create(const QuicClock* clock,
40                                        CongestionFeedbackType type);
41
42  virtual ~SendAlgorithmInterface() {}
43
44  // Called when we receive congestion feedback from remote peer.
45  virtual void OnIncomingQuicCongestionFeedbackFrame(
46      const QuicCongestionFeedbackFrame& feedback,
47      QuicTime feedback_receive_time,
48      QuicBandwidth sent_bandwidth,
49      const SentPacketsMap& sent_packets) = 0;
50
51  // Called for each received ACK, with sequence number from remote peer.
52  virtual void OnIncomingAck(QuicPacketSequenceNumber acked_sequence_number,
53                             QuicByteCount acked_bytes,
54                             QuicTime::Delta rtt) = 0;
55
56  virtual void OnIncomingLoss(QuicTime ack_receive_time) = 0;
57
58  // Inform that we sent x bytes to the wire, and if that was a retransmission.
59  // Note: this function must be called for every packet sent to the wire.
60  virtual void SentPacket(QuicTime sent_time,
61                          QuicPacketSequenceNumber sequence_number,
62                          QuicByteCount bytes,
63                          Retransmission is_retransmission) = 0;
64
65  // Called when a packet is timed out.
66  virtual void AbandoningPacket(QuicPacketSequenceNumber sequence_number,
67                                QuicByteCount abandoned_bytes) = 0;
68
69  // Calculate the time until we can send the next packet.
70  virtual QuicTime::Delta TimeUntilSend(
71      QuicTime now,
72      Retransmission is_retransmission,
73      HasRetransmittableData has_retransmittable_data) = 0;
74
75  // What's the current estimated bandwidth in bytes per second.
76  // Returns 0 when it does not have an estimate.
77  virtual QuicBandwidth BandwidthEstimate() = 0;
78
79  // TODO(satyamshekhar): Monitor MinRtt.
80  virtual QuicTime::Delta SmoothedRtt() = 0;
81};
82
83}  // namespace net
84
85#endif  // NET_QUIC_CONGESTION_CONTROL_SEND_ALGORITHM_INTERFACE_H_
86