Land Recent QUIC Changes.
[chromium-blink-merge.git] / net / quic / congestion_control / inter_arrival_sender.h
blob2de370d7293da95d464f1d00db3d313681a968db
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 TransmissionType transmission_type,
44 HasRetransmittableData has_retransmittable_data) OVERRIDE;
45 virtual void OnRetransmissionTimeout(bool packets_retransmitted) OVERRIDE;
46 virtual void OnPacketAbandoned(QuicPacketSequenceNumber sequence_number,
47 QuicByteCount abandoned_bytes) OVERRIDE;
48 virtual QuicTime::Delta TimeUntilSend(
49 QuicTime now,
50 TransmissionType transmission_type,
51 HasRetransmittableData has_retransmittable_data,
52 IsHandshake handshake) OVERRIDE;
53 virtual QuicBandwidth BandwidthEstimate() const OVERRIDE;
54 virtual void UpdateRtt(QuicTime::Delta rtt_sample) OVERRIDE;
55 virtual QuicTime::Delta RetransmissionDelay() const OVERRIDE;
56 virtual QuicByteCount GetCongestionWindow() const OVERRIDE;
57 // End implementation of SendAlgorithmInterface.
59 private:
60 class SentPacket {
61 public:
62 SentPacket(QuicByteCount bytes, QuicTime timestamp)
63 : bytes_sent_(bytes),
64 send_timestamp_(timestamp) { }
65 QuicByteCount bytes_sent() const { return bytes_sent_; }
66 const QuicTime& send_timestamp() const { return send_timestamp_; }
68 private:
69 QuicByteCount bytes_sent_;
70 QuicTime send_timestamp_;
73 typedef std::map<QuicPacketSequenceNumber, SentPacket*> SentPacketsMap;
75 QuicBandwidth CalculateSentBandwidth(QuicTime feedback_receive_time) const;
76 void EstimateDelayBandwidth(QuicTime feedback_receive_time,
77 QuicBandwidth sent_bandwidth);
78 void EstimateNewBandwidth(QuicTime feedback_receive_time,
79 QuicBandwidth sent_bandwidth);
80 void EstimateNewBandwidthAfterDraining(
81 QuicTime feedback_receive_time,
82 QuicTime::Delta estimated_congestion_delay);
83 void EstimateBandwidthAfterLossEvent(QuicTime feedback_receive_time);
84 void EstimateBandwidthAfterDelayEvent(
85 QuicTime feedback_receive_time,
86 QuicTime::Delta estimated_congestion_delay);
87 void ResetCurrentBandwidth(QuicTime feedback_receive_time,
88 QuicBandwidth new_rate);
89 bool ProbingPhase(QuicTime feedback_receive_time);
90 void CleanupPacketHistory();
92 // Tracks the send time and size of sent packets. Packets are
93 // removed 5 seconds and they've been added.
94 SentPacketsMap packet_history_map_;
96 const QuicClock* clock_;
97 const RttStats* rtt_stats_;
98 bool probing_; // Are we currently in the probing phase?
99 QuicByteCount max_segment_size_;
100 QuicBandwidth current_bandwidth_;
101 QuicTime::Delta smoothed_rtt_;
102 scoped_ptr<ChannelEstimator> channel_estimator_;
103 scoped_ptr<InterArrivalBitrateRampUp> bitrate_ramp_up_;
104 scoped_ptr<InterArrivalOveruseDetector> overuse_detector_;
105 scoped_ptr<InterArrivalProbe> probe_;
106 scoped_ptr<InterArrivalStateMachine> state_machine_;
107 scoped_ptr<PacedSender> paced_sender_;
108 BandwidthUsage bandwidth_usage_state_;
109 QuicTime back_down_time_; // Time when we decided to back down.
110 QuicBandwidth back_down_bandwidth_; // Bandwidth before backing down.
111 QuicTime::Delta back_down_congestion_delay_; // Delay when backing down.
113 DISALLOW_COPY_AND_ASSIGN(InterArrivalSender);
116 } // namespace net
117 #endif // NET_QUIC_CONGESTION_CONTROL_INTER_ARRIVAL_SENDER_H_