[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 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 | // This is the interface from the QuicConnection into the QUIC |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 6 | // congestion control code. It wraps the SendAlgorithmInterface and |
| 7 | // ReceiveAlgorithmInterface and provides a single interface |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 8 | // 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] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 15 | #include "net/quic/congestion_control/send_algorithm_interface.h" |
| 16 | #include "net/quic/quic_bandwidth.h" |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 17 | #include "net/quic/quic_protocol.h" |
| 18 | |
| 19 | namespace net { |
| 20 | |
| 21 | namespace test { |
| 22 | class QuicConnectionPeer; |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 23 | class QuicCongestionManagerPeer; |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 24 | } // namespace test |
| 25 | |
| 26 | class QuicClock; |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 27 | class ReceiveAlgorithmInterface; |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 28 | |
[email protected] | 5ba236e | 2013-04-10 22:46:59 | [diff] [blame] | 29 | class NET_EXPORT_PRIVATE QuicCongestionManager { |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 30 | 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] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 36 | virtual void OnIncomingAckFrame(const QuicAckFrame& frame, |
| 37 | QuicTime ack_receive_time); |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 38 | |
| 39 | // Called when a congestion feedback frame is received from peer. |
| 40 | virtual void OnIncomingQuicCongestionFeedbackFrame( |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 41 | const QuicCongestionFeedbackFrame& frame, |
| 42 | QuicTime feedback_receive_time); |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 43 | |
| 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] | efecff9 | 2013-09-24 07:49:23 | [diff] [blame^] | 46 | virtual void OnPacketSent(QuicPacketSequenceNumber sequence_number, |
| 47 | QuicTime sent_time, |
| 48 | QuicByteCount bytes, |
| 49 | TransmissionType transmission_type, |
| 50 | HasRetransmittableData has_retransmittable_data); |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 51 | |
| 52 | // Called when a packet is timed out. |
[email protected] | efecff9 | 2013-09-24 07:49:23 | [diff] [blame^] | 53 | virtual void OnPacketAbandoned(QuicPacketSequenceNumber sequence_number); |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 54 | |
| 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] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 60 | virtual QuicTime::Delta TimeUntilSend(QuicTime now, |
[email protected] | c67a82cb | 2013-09-24 02:53:21 | [diff] [blame] | 61 | TransmissionType transmission_type, |
[email protected] | 575cce6 | 2013-08-03 02:06:43 | [diff] [blame] | 62 | HasRetransmittableData retransmittable, |
| 63 | IsHandshake handshake); |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 64 | |
| 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] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 73 | // bytes: the packet size in bytes including Quic Headers. |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 74 | // 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] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 78 | virtual void RecordIncomingPacket(QuicByteCount bytes, |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 79 | QuicPacketSequenceNumber sequence_number, |
| 80 | QuicTime timestamp, |
| 81 | bool revived); |
| 82 | |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 83 | const QuicTime::Delta DefaultRetransmissionTime(); |
| 84 | |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 85 | // Returns amount of time for delayed ack timer. |
| 86 | const QuicTime::Delta DelayedAckTime(); |
| 87 | |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 88 | const QuicTime::Delta GetRetransmissionDelay( |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 89 | size_t unacked_packets_count, |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 90 | size_t number_retransmissions); |
| 91 | |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 92 | // 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] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 98 | private: |
| 99 | friend class test::QuicConnectionPeer; |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 100 | friend class test::QuicCongestionManagerPeer; |
| 101 | typedef std::map<QuicPacketSequenceNumber, size_t> PendingPacketsMap; |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 102 | |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 103 | // Get the current(last) rtt. Infinite is returned if invalid. |
| 104 | const QuicTime::Delta rtt(); |
| 105 | |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 106 | 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] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 113 | QuicPacketSequenceNumber largest_missing_; |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 114 | QuicTime::Delta current_rtt_; |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 115 | |
| 116 | DISALLOW_COPY_AND_ASSIGN(QuicCongestionManager); |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | } // namespace net |
| 120 | |
| 121 | #endif // NET_QUIC_CONGESTION_CONTROL_QUIC_CONGESTION_MANAGER_H_ |