Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: net/quic/congestion_control/quic_congestion_manager.cc

Issue 12806002: Land Recent QUIC Changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minor comment fix Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/congestion_control/quic_congestion_manager.h" 5 #include "net/quic/congestion_control/quic_congestion_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 17 matching lines...) Expand all
28 using std::min; 28 using std::min;
29 29
30 namespace net { 30 namespace net {
31 31
32 QuicCongestionManager::QuicCongestionManager( 32 QuicCongestionManager::QuicCongestionManager(
33 const QuicClock* clock, 33 const QuicClock* clock,
34 CongestionFeedbackType type) 34 CongestionFeedbackType type)
35 : clock_(clock), 35 : clock_(clock),
36 receive_algorithm_(ReceiveAlgorithmInterface::Create(clock, type)), 36 receive_algorithm_(ReceiveAlgorithmInterface::Create(clock, type)),
37 send_algorithm_(SendAlgorithmInterface::Create(clock, type)), 37 send_algorithm_(SendAlgorithmInterface::Create(clock, type)),
38 largest_missing_(0) { 38 largest_missing_(0),
39 current_rtt_(QuicTime::Delta::Infinite()) {
39 } 40 }
40 41
41 QuicCongestionManager::~QuicCongestionManager() { 42 QuicCongestionManager::~QuicCongestionManager() {
42 STLDeleteValues(&packet_history_map_); 43 STLDeleteValues(&packet_history_map_);
43 } 44 }
44 45
45 void QuicCongestionManager::SentPacket(QuicPacketSequenceNumber sequence_number, 46 void QuicCongestionManager::SentPacket(QuicPacketSequenceNumber sequence_number,
46 QuicTime sent_time, 47 QuicTime sent_time,
47 QuicByteCount bytes, 48 QuicByteCount bytes,
48 bool is_retransmission, 49 bool is_retransmission) {
49 bool has_retransmittable_data) {
50 DCHECK(!ContainsKey(pending_packets_, sequence_number)); 50 DCHECK(!ContainsKey(pending_packets_, sequence_number));
51 send_algorithm_->SentPacket(sent_time, sequence_number, bytes, 51 send_algorithm_->SentPacket(sent_time, sequence_number, bytes,
52 is_retransmission, has_retransmittable_data); 52 is_retransmission);
53 53
54 packet_history_map_[sequence_number] = 54 packet_history_map_[sequence_number] =
55 new class SendAlgorithmInterface::SentPacket(bytes, sent_time); 55 new class SendAlgorithmInterface::SentPacket(bytes, sent_time);
56 pending_packets_[sequence_number] = bytes; 56 pending_packets_[sequence_number] = bytes;
57 CleanupPacketHistory(); 57 CleanupPacketHistory();
58 } 58 }
59 59
60 // Called when a packet is timed out.
61 void QuicCongestionManager::AbandoningPacket(
62 QuicPacketSequenceNumber sequence_number) {
63 PendingPacketsMap::iterator it = pending_packets_.find(sequence_number);
64 if (it != pending_packets_.end()) {
65 send_algorithm_->AbandoningPacket(sequence_number, it->second);
66 pending_packets_.erase(it);
67 }
68 }
69
60 void QuicCongestionManager::OnIncomingQuicCongestionFeedbackFrame( 70 void QuicCongestionManager::OnIncomingQuicCongestionFeedbackFrame(
61 const QuicCongestionFeedbackFrame& frame, QuicTime feedback_receive_time) { 71 const QuicCongestionFeedbackFrame& frame, QuicTime feedback_receive_time) {
62 QuicBandwidth sent_bandwidth = SentBandwidth(feedback_receive_time); 72 QuicBandwidth sent_bandwidth = SentBandwidth(feedback_receive_time);
63 send_algorithm_->OnIncomingQuicCongestionFeedbackFrame( 73 send_algorithm_->OnIncomingQuicCongestionFeedbackFrame(
64 frame, feedback_receive_time, sent_bandwidth, packet_history_map_); 74 frame, feedback_receive_time, sent_bandwidth, packet_history_map_);
65 } 75 }
66 76
67 void QuicCongestionManager::OnIncomingAckFrame(const QuicAckFrame& frame, 77 void QuicCongestionManager::OnIncomingAckFrame(const QuicAckFrame& frame,
68 QuicTime ack_receive_time) { 78 QuicTime ack_receive_time) {
69 // We calculate the RTT based on the highest ACKed sequence number, the lower 79 // We calculate the RTT based on the highest ACKed sequence number, the lower
70 // sequence numbers will include the ACK aggregation delay. 80 // sequence numbers will include the ACK aggregation delay.
71 QuicTime::Delta rtt = QuicTime::Delta::Zero();
72 SendAlgorithmInterface::SentPacketsMap::iterator history_it = 81 SendAlgorithmInterface::SentPacketsMap::iterator history_it =
73 packet_history_map_.find(frame.received_info.largest_observed); 82 packet_history_map_.find(frame.received_info.largest_observed);
74 if (history_it != packet_history_map_.end()) { 83 // TODO(satyamshekhar): largest_observed might be missing.
75 // TODO(pwestin): we need to add the delta to the feedback message. 84 if (history_it != packet_history_map_.end() &&
76 rtt = ack_receive_time.Subtract(history_it->second->SendTimestamp()); 85 !frame.received_info.delta_time_largest_observed.IsInfinite()) {
86 QuicTime::Delta send_delta = ack_receive_time.Subtract(
87 history_it->second->SendTimestamp());
88 if (send_delta > frame.received_info.delta_time_largest_observed) {
89 current_rtt_ = send_delta.Subtract(
90 frame.received_info.delta_time_largest_observed);
91 }
77 } 92 }
78 // We want to. 93 // We want to.
79 // * Get all packets lower(including) than largest_observed 94 // * Get all packets lower(including) than largest_observed
80 // from pending_packets_. 95 // from pending_packets_.
81 // * Remove all missing packets. 96 // * Remove all missing packets.
82 // * Send each ACK in the list to send_algorithm_. 97 // * Send each ACK in the list to send_algorithm_.
83 PendingPacketsMap::iterator it, it_upper; 98 PendingPacketsMap::iterator it, it_upper;
84 it = pending_packets_.begin(); 99 it = pending_packets_.begin();
85 it_upper = pending_packets_.upper_bound(frame.received_info.largest_observed); 100 it_upper = pending_packets_.upper_bound(frame.received_info.largest_observed);
86 101
87 bool new_packet_loss_reported = false; 102 bool new_packet_loss_reported = false;
88 while (it != it_upper) { 103 while (it != it_upper) {
89 QuicPacketSequenceNumber sequence_number = it->first; 104 QuicPacketSequenceNumber sequence_number = it->first;
90 if (!IsAwaitingPacket(frame.received_info, sequence_number)) { 105 if (!IsAwaitingPacket(frame.received_info, sequence_number)) {
91 // Not missing, hence implicitly acked. 106 // Not missing, hence implicitly acked.
92 send_algorithm_->OnIncomingAck(sequence_number, 107 send_algorithm_->OnIncomingAck(sequence_number, it->second, current_rtt_);
93 it->second,
94 rtt);
95 pending_packets_.erase(it++); // Must be incremented post to work. 108 pending_packets_.erase(it++); // Must be incremented post to work.
96 } else { 109 } else {
97 if (sequence_number > largest_missing_) { 110 if (sequence_number > largest_missing_) {
98 // We have a new loss reported. 111 // We have a new loss reported.
99 new_packet_loss_reported = true; 112 new_packet_loss_reported = true;
100 largest_missing_ = sequence_number; 113 largest_missing_ = sequence_number;
101 } 114 }
102 ++it; 115 ++it;
103 } 116 }
104 } 117 }
105 if (new_packet_loss_reported) { 118 if (new_packet_loss_reported) {
106 send_algorithm_->OnIncomingLoss(ack_receive_time); 119 send_algorithm_->OnIncomingLoss(ack_receive_time);
107 } 120 }
108 } 121 }
109 122
110 QuicTime::Delta QuicCongestionManager::TimeUntilSend(QuicTime now, 123 QuicTime::Delta QuicCongestionManager::TimeUntilSend(
111 bool is_retransmission) { 124 QuicTime now,
112 return send_algorithm_->TimeUntilSend(now, is_retransmission); 125 bool is_retransmission,
126 bool has_retransmittable_data) {
127 return send_algorithm_->TimeUntilSend(now, is_retransmission,
128 has_retransmittable_data);
113 } 129 }
114 130
115 bool QuicCongestionManager::GenerateCongestionFeedback( 131 bool QuicCongestionManager::GenerateCongestionFeedback(
116 QuicCongestionFeedbackFrame* feedback) { 132 QuicCongestionFeedbackFrame* feedback) {
117 return receive_algorithm_->GenerateCongestionFeedback(feedback); 133 return receive_algorithm_->GenerateCongestionFeedback(feedback);
118 } 134 }
119 135
120 void QuicCongestionManager::RecordIncomingPacket( 136 void QuicCongestionManager::RecordIncomingPacket(
121 QuicByteCount bytes, 137 QuicByteCount bytes,
122 QuicPacketSequenceNumber sequence_number, 138 QuicPacketSequenceNumber sequence_number,
123 QuicTime timestamp, 139 QuicTime timestamp,
124 bool revived) { 140 bool revived) {
125 receive_algorithm_->RecordIncomingPacket(bytes, sequence_number, timestamp, 141 receive_algorithm_->RecordIncomingPacket(bytes, sequence_number, timestamp,
126 revived); 142 revived);
127 } 143 }
128 144
129 // static 145 const QuicTime::Delta QuicCongestionManager::rtt() {
146 return current_rtt_;
147 }
148
130 const QuicTime::Delta QuicCongestionManager::DefaultRetransmissionTime() { 149 const QuicTime::Delta QuicCongestionManager::DefaultRetransmissionTime() {
131 return QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs); 150 return QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs);
132 } 151 }
133 152
134 // static
135 const QuicTime::Delta QuicCongestionManager::GetRetransmissionDelay( 153 const QuicTime::Delta QuicCongestionManager::GetRetransmissionDelay(
136 size_t unacked_packets_count, 154 size_t unacked_packets_count,
137 size_t number_retransmissions) { 155 size_t number_retransmissions) {
156 // TODO(pwestin): This should take the RTT into account instead of a hard
157 // coded kDefaultRetransmissionTimeMs. Ideally the variance of the RTT too.
138 if (unacked_packets_count <= kTailDropWindowSize) { 158 if (unacked_packets_count <= kTailDropWindowSize) {
139 return QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs); 159 return QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs);
140 } 160 }
141 161
142 return QuicTime::Delta::FromMilliseconds( 162 return QuicTime::Delta::FromMilliseconds(
143 kDefaultRetransmissionTimeMs * 163 kDefaultRetransmissionTimeMs *
144 (1 << min<size_t>(number_retransmissions, kMaxRetransmissions))); 164 (1 << min<size_t>(number_retransmissions, kMaxRetransmissions)));
145 } 165 }
146 166
167 const QuicTime::Delta QuicCongestionManager::SmoothedRtt() {
168 return send_algorithm_->SmoothedRtt();
169 }
170
147 QuicBandwidth QuicCongestionManager::SentBandwidth( 171 QuicBandwidth QuicCongestionManager::SentBandwidth(
148 QuicTime feedback_receive_time) const { 172 QuicTime feedback_receive_time) const {
149 const QuicTime::Delta kBitrateSmoothingPeriod = 173 const QuicTime::Delta kBitrateSmoothingPeriod =
150 QuicTime::Delta::FromMilliseconds(kBitrateSmoothingPeriodMs); 174 QuicTime::Delta::FromMilliseconds(kBitrateSmoothingPeriodMs);
151 const QuicTime::Delta kMinBitrateSmoothingPeriod = 175 const QuicTime::Delta kMinBitrateSmoothingPeriod =
152 QuicTime::Delta::FromMilliseconds(kMinBitrateSmoothingPeriodMs); 176 QuicTime::Delta::FromMilliseconds(kMinBitrateSmoothingPeriodMs);
153 177
154 QuicByteCount sum_bytes_sent = 0; 178 QuicByteCount sum_bytes_sent = 0;
155 179
156 // Sum packet from new until they are kBitrateSmoothingPeriod old. 180 // Sum packet from new until they are kBitrateSmoothingPeriod old.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 if (now.Subtract(history_it->second->SendTimestamp()) <= kHistoryPeriod) { 213 if (now.Subtract(history_it->second->SendTimestamp()) <= kHistoryPeriod) {
190 return; 214 return;
191 } 215 }
192 delete history_it->second; 216 delete history_it->second;
193 packet_history_map_.erase(history_it); 217 packet_history_map_.erase(history_it);
194 history_it = packet_history_map_.begin(); 218 history_it = packet_history_map_.begin();
195 } 219 }
196 } 220 }
197 221
198 } // namespace net 222 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/congestion_control/quic_congestion_manager.h ('k') | net/quic/congestion_control/send_algorithm_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698