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