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
FixRateSender(const RttStats * rtt_stats)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
~FixRateSender()33 FixRateSender::~FixRateSender() {
34 }
35
SetFromConfig(const QuicConfig & config,bool is_server)36 void FixRateSender::SetFromConfig(const QuicConfig& config, bool is_server) {
37 }
38
OnIncomingQuicCongestionFeedbackFrame(const QuicCongestionFeedbackFrame & feedback,QuicTime feedback_receive_time)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
OnCongestionEvent(bool rtt_updated,QuicByteCount bytes_in_flight,const CongestionMap & acked_packets,const CongestionMap & lost_packets)51 void FixRateSender::OnCongestionEvent(bool rtt_updated,
52 QuicByteCount bytes_in_flight,
53 const CongestionMap& acked_packets,
54 const CongestionMap& lost_packets) {
55 }
56
OnPacketSent(QuicTime sent_time,QuicByteCount,QuicPacketSequenceNumber,QuicByteCount bytes,HasRetransmittableData)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
OnRetransmissionTimeout(bool packets_retransmitted)68 void FixRateSender::OnRetransmissionTimeout(bool packets_retransmitted) { }
69
TimeUntilSend(QuicTime now,QuicByteCount,HasRetransmittableData) const70 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
CongestionWindow() const77 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
BandwidthEstimate() const84 QuicBandwidth FixRateSender::BandwidthEstimate() const {
85 return bitrate_;
86 }
87
88
RetransmissionDelay() const89 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
GetCongestionWindow() const95 QuicByteCount FixRateSender::GetCongestionWindow() const {
96 return 0;
97 }
98
99 } // namespace net
100