- add sources.
[platform/framework/web/crosswalk.git] / src / net / quic / congestion_control / available_channel_estimator.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 // Based on the inter arrival time of the received packets relative to the time
6 // those packets where sent we can estimate the available capacity of the
7 // channel.
8 // We can only use packet trains that are sent out faster than the acctual
9 // available channel capacity.
10 // Note 1: this is intended to be a temporary class created when you send out a
11 // channel probing burst. Once the last packet have arrived you ask it for an
12 // estimate.
13 // Note 2: During this phase we should not update the overuse detector.
14 #ifndef NET_QUIC_CONGESTION_CONTROL_AVAILABLE_CHANNEL_ESTIMATOR_H_
15 #define NET_QUIC_CONGESTION_CONTROL_AVAILABLE_CHANNEL_ESTIMATOR_H_
16
17 #include "base/basictypes.h"
18 #include "net/base/net_export.h"
19 #include "net/quic/quic_bandwidth.h"
20 #include "net/quic/quic_protocol.h"
21 #include "net/quic/quic_time.h"
22
23 namespace net {
24
25 enum NET_EXPORT_PRIVATE AvailableChannelEstimateState {
26   kAvailableChannelEstimateUnknown = 0,
27   kAvailableChannelEstimateUncertain = 1,
28   kAvailableChannelEstimateGood = 2,
29   kAvailableChannelEstimateSenderLimited = 3,
30 };
31
32 class NET_EXPORT_PRIVATE AvailableChannelEstimator {
33  public:
34   explicit AvailableChannelEstimator(
35       QuicPacketSequenceNumber first_sequence_number,
36       QuicTime first_send_time,
37       QuicTime first_receive_time);
38
39   // Update the statistics with each receive time, for every packet we get a
40   // feedback message for.
41   void OnIncomingFeedback(QuicPacketSequenceNumber sequence_number,
42                           QuicByteCount packet_size,
43                           QuicTime sent_time,
44                           QuicTime receive_time);
45
46   // Get the current estimated available channel capacity.
47   // bandwidth_estimate is invalid if kAvailableChannelEstimateUnknown
48   // is returned.
49   AvailableChannelEstimateState GetAvailableChannelEstimate(
50       QuicBandwidth* bandwidth_estimate) const;
51
52  private:
53   const QuicPacketSequenceNumber first_sequence_number_;
54   const QuicTime first_send_time_;
55   const QuicTime first_receive_time_;
56   QuicPacketSequenceNumber last_incorporated_sequence_number_;
57   QuicTime last_time_sent_;
58   QuicTime last_receive_time_;
59   int number_of_sequence_numbers_;
60   QuicByteCount received_bytes_;
61 };
62
63 }  // namespace net
64 #endif  // NET_QUIC_CONGESTION_CONTROL_AVAILABLE_CHANNEL_ESTIMATOR_H_