Land Recent QUIC Changes
[chromium-blink-merge.git] / net / quic / congestion_control / inter_arrival_sender.h
blobe0812f1111e1b55dccc5964826174e7443dee115
1 // Copyright (c) 2013 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 #ifndef NET_QUIC_CONGESTION_CONTROL_INTER_ARRIVAL_SENDER_H_
6 #define NET_QUIC_CONGESTION_CONTROL_INTER_ARRIVAL_SENDER_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "net/base/net_export.h"
11 #include "net/quic/congestion_control/channel_estimator.h"
12 #include "net/quic/congestion_control/inter_arrival_bitrate_ramp_up.h"
13 #include "net/quic/congestion_control/inter_arrival_overuse_detector.h"
14 #include "net/quic/congestion_control/inter_arrival_probe.h"
15 #include "net/quic/congestion_control/inter_arrival_state_machine.h"
16 #include "net/quic/congestion_control/paced_sender.h"
17 #include "net/quic/congestion_control/send_algorithm_interface.h"
18 #include "net/quic/quic_bandwidth.h"
19 #include "net/quic/quic_clock.h"
20 #include "net/quic/quic_protocol.h"
21 #include "net/quic/quic_time.h"
23 namespace net {
25 class NET_EXPORT_PRIVATE InterArrivalSender : public SendAlgorithmInterface {
26 public:
27 InterArrivalSender(const QuicClock* clock, const RttStats* rtt_stats);
28 virtual ~InterArrivalSender();
30 // Start implementation of SendAlgorithmInterface.
31 virtual void SetFromConfig(const QuicConfig& config, bool is_server) OVERRIDE;
32 virtual void OnIncomingQuicCongestionFeedbackFrame(
33 const QuicCongestionFeedbackFrame& feedback,
34 QuicTime feedback_receive_time) OVERRIDE;
35 virtual void OnPacketAcked(QuicPacketSequenceNumber acked_sequence_number,
36 QuicByteCount acked_bytes) OVERRIDE;
37 virtual void OnPacketLost(QuicPacketSequenceNumber sequence_number,
38 QuicTime ack_receive_time) OVERRIDE;
39 virtual bool OnPacketSent(
40 QuicTime sent_time,
41 QuicPacketSequenceNumber sequence_number,
42 QuicByteCount bytes,
43 HasRetransmittableData has_retransmittable_data) OVERRIDE;
44 virtual void OnRetransmissionTimeout(bool packets_retransmitted) OVERRIDE;
45 virtual void OnPacketAbandoned(QuicPacketSequenceNumber sequence_number,
46 QuicByteCount abandoned_bytes) OVERRIDE;
47 virtual QuicTime::Delta TimeUntilSend(
48 QuicTime now,
49 HasRetransmittableData has_retransmittable_data) OVERRIDE;
50 virtual QuicBandwidth BandwidthEstimate() const OVERRIDE;
51 virtual void UpdateRtt(QuicTime::Delta rtt_sample) OVERRIDE;
52 virtual QuicTime::Delta RetransmissionDelay() const OVERRIDE;
53 virtual QuicByteCount GetCongestionWindow() const OVERRIDE;
54 // End implementation of SendAlgorithmInterface.
56 private:
57 class SentPacket {
58 public:
59 SentPacket(QuicByteCount bytes, QuicTime timestamp)
60 : bytes_sent_(bytes),
61 send_timestamp_(timestamp) { }
62 QuicByteCount bytes_sent() const { return bytes_sent_; }
63 const QuicTime& send_timestamp() const { return send_timestamp_; }
65 private:
66 QuicByteCount bytes_sent_;
67 QuicTime send_timestamp_;
70 typedef std::map<QuicPacketSequenceNumber, SentPacket*> SentPacketsMap;
72 QuicBandwidth CalculateSentBandwidth(QuicTime feedback_receive_time) const;
73 void EstimateDelayBandwidth(QuicTime feedback_receive_time,
74 QuicBandwidth sent_bandwidth);
75 void EstimateNewBandwidth(QuicTime feedback_receive_time,
76 QuicBandwidth sent_bandwidth);
77 void EstimateNewBandwidthAfterDraining(
78 QuicTime feedback_receive_time,
79 QuicTime::Delta estimated_congestion_delay);
80 void EstimateBandwidthAfterLossEvent(QuicTime feedback_receive_time);
81 void EstimateBandwidthAfterDelayEvent(
82 QuicTime feedback_receive_time,
83 QuicTime::Delta estimated_congestion_delay);
84 void ResetCurrentBandwidth(QuicTime feedback_receive_time,
85 QuicBandwidth new_rate);
86 bool ProbingPhase(QuicTime feedback_receive_time);
87 void CleanupPacketHistory();
89 // Tracks the send time and size of sent packets. Packets are
90 // removed 5 seconds and they've been added.
91 SentPacketsMap packet_history_map_;
93 const QuicClock* clock_;
94 const RttStats* rtt_stats_;
95 bool probing_; // Are we currently in the probing phase?
96 QuicByteCount max_segment_size_;
97 QuicBandwidth current_bandwidth_;
98 QuicTime::Delta smoothed_rtt_;
99 scoped_ptr<ChannelEstimator> channel_estimator_;
100 scoped_ptr<InterArrivalBitrateRampUp> bitrate_ramp_up_;
101 scoped_ptr<InterArrivalOveruseDetector> overuse_detector_;
102 scoped_ptr<InterArrivalProbe> probe_;
103 scoped_ptr<InterArrivalStateMachine> state_machine_;
104 scoped_ptr<PacedSender> paced_sender_;
105 BandwidthUsage bandwidth_usage_state_;
106 QuicTime back_down_time_; // Time when we decided to back down.
107 QuicBandwidth back_down_bandwidth_; // Bandwidth before backing down.
108 QuicTime::Delta back_down_congestion_delay_; // Delay when backing down.
110 DISALLOW_COPY_AND_ASSIGN(InterArrivalSender);
113 } // namespace net
114 #endif // NET_QUIC_CONGESTION_CONTROL_INTER_ARRIVAL_SENDER_H_