- add sources.
[platform/framework/web/crosswalk.git] / src / net / quic / congestion_control / inter_arrival_sender.h
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.
4
5 #ifndef NET_QUIC_CONGESTION_CONTROL_INTER_ARRIVAL_SENDER_H_
6 #define NET_QUIC_CONGESTION_CONTROL_INTER_ARRIVAL_SENDER_H_
7
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"
22
23 namespace net {
24
25 class NET_EXPORT_PRIVATE InterArrivalSender : public SendAlgorithmInterface {
26  public:
27   explicit InterArrivalSender(const QuicClock* clock);
28   virtual ~InterArrivalSender();
29
30   virtual void SetFromConfig(const QuicConfig& config, bool is_server) OVERRIDE;
31
32   static QuicBandwidth CalculateSentBandwidth(
33       const SendAlgorithmInterface::SentPacketsMap& sent_packets_map,
34       QuicTime feedback_receive_time);
35
36   // Start implementation of SendAlgorithmInterface.
37   virtual void OnIncomingQuicCongestionFeedbackFrame(
38       const QuicCongestionFeedbackFrame& feedback,
39       QuicTime feedback_receive_time,
40       const SentPacketsMap& sent_packets) OVERRIDE;
41
42   virtual void OnIncomingAck(QuicPacketSequenceNumber acked_sequence_number,
43                              QuicByteCount acked_bytes,
44                              QuicTime::Delta rtt) OVERRIDE;
45
46   virtual void OnIncomingLoss(QuicTime ack_receive_time) OVERRIDE;
47
48   virtual bool OnPacketSent(
49       QuicTime sent_time,
50       QuicPacketSequenceNumber sequence_number,
51       QuicByteCount bytes,
52       TransmissionType transmission_type,
53       HasRetransmittableData has_retransmittable_data) OVERRIDE;
54
55   virtual void OnPacketAbandoned(QuicPacketSequenceNumber sequence_number,
56                                  QuicByteCount abandoned_bytes) OVERRIDE;
57
58   virtual QuicTime::Delta TimeUntilSend(
59       QuicTime now,
60       TransmissionType transmission_type,
61       HasRetransmittableData has_retransmittable_data,
62       IsHandshake handshake) OVERRIDE;
63
64   virtual QuicBandwidth BandwidthEstimate() OVERRIDE;
65   virtual QuicTime::Delta SmoothedRtt() OVERRIDE;
66   virtual QuicTime::Delta RetransmissionDelay() OVERRIDE;
67   virtual QuicByteCount GetCongestionWindow() OVERRIDE;
68   virtual void SetCongestionWindow(QuicByteCount window) OVERRIDE;
69   // End implementation of SendAlgorithmInterface.
70
71  private:
72   void EstimateDelayBandwidth(QuicTime feedback_receive_time,
73                               QuicBandwidth sent_bandwidth);
74   void EstimateNewBandwidth(QuicTime feedback_receive_time,
75                             QuicBandwidth sent_bandwidth);
76   void EstimateNewBandwidthAfterDraining(
77       QuicTime feedback_receive_time,
78       QuicTime::Delta estimated_congestion_delay);
79   void EstimateBandwidthAfterLossEvent(QuicTime feedback_receive_time);
80   void EstimateBandwidthAfterDelayEvent(
81       QuicTime feedback_receive_time,
82       QuicTime::Delta estimated_congestion_delay);
83   void ResetCurrentBandwidth(QuicTime feedback_receive_time,
84                              QuicBandwidth new_rate);
85   bool ProbingPhase(QuicTime feedback_receive_time);
86
87   bool probing_;  // Are we currently in the probing phase?
88   QuicByteCount max_segment_size_;
89   QuicBandwidth current_bandwidth_;
90   QuicTime::Delta smoothed_rtt_;
91   scoped_ptr<ChannelEstimator> channel_estimator_;
92   scoped_ptr<InterArrivalBitrateRampUp> bitrate_ramp_up_;
93   scoped_ptr<InterArrivalOveruseDetector> overuse_detector_;
94   scoped_ptr<InterArrivalProbe> probe_;
95   scoped_ptr<InterArrivalStateMachine> state_machine_;
96   scoped_ptr<PacedSender> paced_sender_;
97   int accumulated_number_of_lost_packets_;
98   BandwidthUsage bandwidth_usage_state_;
99   QuicTime back_down_time_;  // Time when we decided to back down.
100   QuicBandwidth back_down_bandwidth_;  // Bandwidth before backing down.
101   QuicTime::Delta back_down_congestion_delay_;  // Delay when backing down.
102
103   DISALLOW_COPY_AND_ASSIGN(InterArrivalSender);
104 };
105
106 }  // namespace net
107 #endif  // NET_QUIC_CONGESTION_CONTROL_INTER_ARRIVAL_SENDER_H_