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 max capacity of the channel. 7 // We can only use packet pair that are sent out faster than the acctual 8 // channel capacity. 9 #ifndef NET_QUIC_CONGESTION_CONTROL_CHANNEL_ESTIMATOR_H_ 10 #define NET_QUIC_CONGESTION_CONTROL_CHANNEL_ESTIMATOR_H_ 11 12 #include <list> 13 #include <map> 14 15 #include "base/basictypes.h" 16 #include "net/base/net_export.h" 17 #include "net/quic/congestion_control/quic_max_sized_map.h" 18 #include "net/quic/quic_bandwidth.h" 19 #include "net/quic/quic_protocol.h" 20 #include "net/quic/quic_time.h" 21 22 namespace net { 23 24 enum ChannelEstimateState { 25 kChannelEstimateUnknown = 0, 26 kChannelEstimateUncertain = 1, 27 kChannelEstimateGood = 2 28 }; 29 30 class NET_EXPORT_PRIVATE ChannelEstimator { 31 public: 32 ChannelEstimator(); 33 ~ChannelEstimator(); 34 35 // This method should be called each time we acquire a receive time for a 36 // packet we previously sent. It calculates deltas between consecutive 37 // receive times, and may use that to update the channel bandwidth estimate. 38 void OnAcknowledgedPacket(QuicPacketSequenceNumber sequence_number, 39 QuicByteCount packet_size, 40 QuicTime send_time, 41 QuicTime receive_time); 42 43 // Get the current estimated state and channel capacity. 44 // Note: estimate will not be valid when kChannelEstimateUnknown is returned. 45 ChannelEstimateState GetChannelEstimate(QuicBandwidth* estimate) const; 46 47 private: 48 void UpdateFilter(QuicTime::Delta received_delta, QuicByteCount size_delta, 49 QuicPacketSequenceNumber sequence_number); 50 51 QuicPacketSequenceNumber last_sequence_number_; 52 QuicTime last_send_time_; 53 QuicTime last_receive_time_; 54 QuicMaxSizedMap<QuicBandwidth, QuicPacketSequenceNumber> 55 sorted_bitrate_estimates_; 56 57 DISALLOW_COPY_AND_ASSIGN(ChannelEstimator); 58 }; 59 60 } // namespace net 61 #endif // NET_QUIC_CONGESTION_CONTROL_CHANNEL_ESTIMATOR_H_ 62