Home | History | Annotate | Download | only in congestion_control
      1 // Copyright (c) 2012 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 #include "net/quic/congestion_control/fix_rate_sender.h"
      6 
      7 #include <math.h>
      8 
      9 #include <algorithm>
     10 
     11 #include "base/logging.h"
     12 #include "net/quic/congestion_control/rtt_stats.h"
     13 #include "net/quic/quic_protocol.h"
     14 
     15 using std::max;
     16 
     17 namespace {
     18   const int kInitialBitrate = 100000;  // In bytes per second.
     19   const uint64 kWindowSizeUs = 10000;  // 10 ms.
     20 }
     21 
     22 namespace net {
     23 
     24 FixRateSender::FixRateSender(const RttStats* rtt_stats)
     25     : rtt_stats_(rtt_stats),
     26       bitrate_(QuicBandwidth::FromBytesPerSecond(kInitialBitrate)),
     27       max_segment_size_(kDefaultMaxPacketSize),
     28       fix_rate_leaky_bucket_(bitrate_),
     29       latest_rtt_(QuicTime::Delta::Zero()) {
     30   DVLOG(1) << "FixRateSender";
     31 }
     32 
     33 FixRateSender::~FixRateSender() {
     34 }
     35 
     36 void FixRateSender::SetFromConfig(const QuicConfig& config, bool is_server) {
     37 }
     38 
     39 void FixRateSender::OnIncomingQuicCongestionFeedbackFrame(
     40     const QuicCongestionFeedbackFrame& feedback,
     41     QuicTime feedback_receive_time) {
     42   LOG_IF(DFATAL, feedback.type != kFixRate) <<
     43       "Invalid incoming CongestionFeedbackType:" << feedback.type;
     44   if (feedback.type == kFixRate) {
     45     bitrate_ = feedback.fix_rate.bitrate;
     46     fix_rate_leaky_bucket_.SetDrainingRate(feedback_receive_time, bitrate_);
     47   }
     48   // Silently ignore invalid messages in release mode.
     49 }
     50 
     51 void FixRateSender::OnCongestionEvent(bool rtt_updated,
     52                                       QuicByteCount bytes_in_flight,
     53                                       const CongestionMap& acked_packets,
     54                                       const CongestionMap& lost_packets) {
     55 }
     56 
     57 bool FixRateSender::OnPacketSent(
     58     QuicTime sent_time,
     59     QuicByteCount /*bytes_in_flight*/,
     60     QuicPacketSequenceNumber /*sequence_number*/,
     61     QuicByteCount bytes,
     62     HasRetransmittableData /*has_retransmittable_data*/) {
     63   fix_rate_leaky_bucket_.Add(sent_time, bytes);
     64 
     65   return true;
     66 }
     67 
     68 void FixRateSender::OnRetransmissionTimeout(bool packets_retransmitted) { }
     69 
     70 QuicTime::Delta FixRateSender::TimeUntilSend(
     71     QuicTime now,
     72     QuicByteCount /*bytes_in_flight*/,
     73     HasRetransmittableData /*has_retransmittable_data*/) const {
     74   return fix_rate_leaky_bucket_.TimeRemaining(now);
     75 }
     76 
     77 QuicByteCount FixRateSender::CongestionWindow() const {
     78   QuicByteCount window_size_bytes = bitrate_.ToBytesPerPeriod(
     79       QuicTime::Delta::FromMicroseconds(kWindowSizeUs));
     80   // Make sure window size is not less than a packet.
     81   return max(kDefaultMaxPacketSize, window_size_bytes);
     82 }
     83 
     84 QuicBandwidth FixRateSender::BandwidthEstimate() const {
     85   return bitrate_;
     86 }
     87 
     88 
     89 QuicTime::Delta FixRateSender::RetransmissionDelay() const {
     90   // TODO(pwestin): Calculate and return retransmission delay.
     91   // Use 2 * the latest RTT for now.
     92   return latest_rtt_.Add(latest_rtt_);
     93 }
     94 
     95 QuicByteCount FixRateSender::GetCongestionWindow() const {
     96   return 0;
     97 }
     98 
     99 }  // namespace net
    100