blob: d574e511888b8d1c3e9c25b1133694ea69b3d953 [file] [log] [blame]
[email protected]c995c572013-01-18 05:43:201// 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// This is the interface from the QuicConnection into the QUIC
[email protected]fee17f72013-02-03 07:47:416// congestion control code. It wraps the SendAlgorithmInterface and
7// ReceiveAlgorithmInterface and provides a single interface
[email protected]c995c572013-01-18 05:43:208// for consumers.
9
10#ifndef NET_QUIC_CONGESTION_CONTROL_QUIC_CONGESTION_MANAGER_H_
11#define NET_QUIC_CONGESTION_CONTROL_QUIC_CONGESTION_MANAGER_H_
12
13#include "base/basictypes.h"
14#include "base/memory/scoped_ptr.h"
[email protected]fee17f72013-02-03 07:47:4115#include "net/quic/congestion_control/send_algorithm_interface.h"
16#include "net/quic/quic_bandwidth.h"
[email protected]c995c572013-01-18 05:43:2017#include "net/quic/quic_protocol.h"
18
19namespace net {
20
21namespace test {
22class QuicConnectionPeer;
[email protected]fee17f72013-02-03 07:47:4123class QuicCongestionManagerPeer;
[email protected]c995c572013-01-18 05:43:2024} // namespace test
25
26class QuicClock;
[email protected]fee17f72013-02-03 07:47:4127class ReceiveAlgorithmInterface;
[email protected]c995c572013-01-18 05:43:2028
[email protected]5ba236e2013-04-10 22:46:5929class NET_EXPORT_PRIVATE QuicCongestionManager {
[email protected]c995c572013-01-18 05:43:2030 public:
31 QuicCongestionManager(const QuicClock* clock,
32 CongestionFeedbackType congestion_type);
33 virtual ~QuicCongestionManager();
34
35 // Called when we have received an ack frame from peer.
[email protected]9db443912013-02-25 05:27:0336 virtual void OnIncomingAckFrame(const QuicAckFrame& frame,
37 QuicTime ack_receive_time);
[email protected]c995c572013-01-18 05:43:2038
39 // Called when a congestion feedback frame is received from peer.
40 virtual void OnIncomingQuicCongestionFeedbackFrame(
[email protected]9db443912013-02-25 05:27:0341 const QuicCongestionFeedbackFrame& frame,
42 QuicTime feedback_receive_time);
[email protected]c995c572013-01-18 05:43:2043
44 // Called when we have sent bytes to the peer. This informs the manager both
45 // the number of bytes sent and if they were retransmitted.
[email protected]efecff92013-09-24 07:49:2346 virtual void OnPacketSent(QuicPacketSequenceNumber sequence_number,
47 QuicTime sent_time,
48 QuicByteCount bytes,
49 TransmissionType transmission_type,
50 HasRetransmittableData has_retransmittable_data);
[email protected]14e8106c2013-03-14 16:25:3351
52 // Called when a packet is timed out.
[email protected]efecff92013-09-24 07:49:2353 virtual void OnPacketAbandoned(QuicPacketSequenceNumber sequence_number);
[email protected]c995c572013-01-18 05:43:2054
55 // Calculate the time until we can send the next packet to the wire.
56 // Note 1: When kUnknownWaitTime is returned, there is no need to poll
57 // TimeUntilSend again until we receive an OnIncomingAckFrame event.
58 // Note 2: Send algorithms may or may not use |retransmit| in their
59 // calculations.
[email protected]9db443912013-02-25 05:27:0360 virtual QuicTime::Delta TimeUntilSend(QuicTime now,
[email protected]c67a82cb2013-09-24 02:53:2161 TransmissionType transmission_type,
[email protected]575cce62013-08-03 02:06:4362 HasRetransmittableData retransmittable,
63 IsHandshake handshake);
[email protected]c995c572013-01-18 05:43:2064
65 // Should be called before sending an ACK packet, to decide if we need
66 // to attach a QuicCongestionFeedbackFrame block.
67 // Returns false if no QuicCongestionFeedbackFrame block is needed.
68 // Otherwise fills in feedback and returns true.
69 virtual bool GenerateCongestionFeedback(
70 QuicCongestionFeedbackFrame* feedback);
71
72 // Should be called for each incoming packet.
[email protected]14e8106c2013-03-14 16:25:3373 // bytes: the packet size in bytes including Quic Headers.
[email protected]c995c572013-01-18 05:43:2074 // sequence_number: the unique sequence number from the QUIC packet header.
75 // timestamp: the arrival time of the packet.
76 // revived: true if the packet was lost and then recovered with help of a
77 // FEC packet.
[email protected]fee17f72013-02-03 07:47:4178 virtual void RecordIncomingPacket(QuicByteCount bytes,
[email protected]c995c572013-01-18 05:43:2079 QuicPacketSequenceNumber sequence_number,
80 QuicTime timestamp,
81 bool revived);
82
[email protected]fee17f72013-02-03 07:47:4183 const QuicTime::Delta DefaultRetransmissionTime();
84
[email protected]24e5bc52013-09-18 15:36:5885 // Returns amount of time for delayed ack timer.
86 const QuicTime::Delta DelayedAckTime();
87
[email protected]fee17f72013-02-03 07:47:4188 const QuicTime::Delta GetRetransmissionDelay(
[email protected]9db443912013-02-25 05:27:0389 size_t unacked_packets_count,
[email protected]fee17f72013-02-03 07:47:4190 size_t number_retransmissions);
91
[email protected]14e8106c2013-03-14 16:25:3392 // Returns the estimated smoothed RTT calculated by the congestion algorithm.
93 const QuicTime::Delta SmoothedRtt();
94
95 // Returns the estimated bandwidth calculated by the congestion algorithm.
96 QuicBandwidth BandwidthEstimate();
97
[email protected]c995c572013-01-18 05:43:2098 private:
99 friend class test::QuicConnectionPeer;
[email protected]fee17f72013-02-03 07:47:41100 friend class test::QuicCongestionManagerPeer;
101 typedef std::map<QuicPacketSequenceNumber, size_t> PendingPacketsMap;
[email protected]c995c572013-01-18 05:43:20102
[email protected]14e8106c2013-03-14 16:25:33103 // Get the current(last) rtt. Infinite is returned if invalid.
104 const QuicTime::Delta rtt();
105
[email protected]fee17f72013-02-03 07:47:41106 void CleanupPacketHistory();
107
108 const QuicClock* clock_;
109 scoped_ptr<ReceiveAlgorithmInterface> receive_algorithm_;
110 scoped_ptr<SendAlgorithmInterface> send_algorithm_;
111 SendAlgorithmInterface::SentPacketsMap packet_history_map_;
112 PendingPacketsMap pending_packets_;
[email protected]9db443912013-02-25 05:27:03113 QuicPacketSequenceNumber largest_missing_;
[email protected]14e8106c2013-03-14 16:25:33114 QuicTime::Delta current_rtt_;
[email protected]fee17f72013-02-03 07:47:41115
116 DISALLOW_COPY_AND_ASSIGN(QuicCongestionManager);
[email protected]c995c572013-01-18 05:43:20117};
118
119} // namespace net
120
121#endif // NET_QUIC_CONGESTION_CONTROL_QUIC_CONGESTION_MANAGER_H_