OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/general_loss_algorithm.h" | 5 #include "net/quic/congestion_control/general_loss_algorithm.h" |
6 | 6 |
7 #include "net/quic/congestion_control/rtt_stats.h" | 7 #include "net/quic/congestion_control/rtt_stats.h" |
8 #include "net/quic/quic_bug_tracker.h" | 8 #include "net/quic/quic_bug_tracker.h" |
9 #include "net/quic/quic_flags.h" | 9 #include "net/quic/quic_flags.h" |
10 #include "net/quic/quic_protocol.h" | 10 #include "net/quic/quic_protocol.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 SendAlgorithmInterface::CongestionVector* packets_lost) { | 60 SendAlgorithmInterface::CongestionVector* packets_lost) { |
61 QuicPacketNumber largest_observed = unacked_packets.largest_observed(); | 61 QuicPacketNumber largest_observed = unacked_packets.largest_observed(); |
62 if (FLAGS_quic_loss_recovery_use_largest_acked) { | 62 if (FLAGS_quic_loss_recovery_use_largest_acked) { |
63 largest_observed = largest_newly_acked; | 63 largest_observed = largest_newly_acked; |
64 } | 64 } |
65 loss_detection_timeout_ = QuicTime::Zero(); | 65 loss_detection_timeout_ = QuicTime::Zero(); |
66 QuicTime::Delta max_rtt = | 66 QuicTime::Delta max_rtt = |
67 QuicTime::Delta::Max(rtt_stats.previous_srtt(), rtt_stats.latest_rtt()); | 67 QuicTime::Delta::Max(rtt_stats.previous_srtt(), rtt_stats.latest_rtt()); |
68 QuicTime::Delta loss_delay = | 68 QuicTime::Delta loss_delay = |
69 QuicTime::Delta::Max(QuicTime::Delta::FromMilliseconds(kMinLossDelayMs), | 69 QuicTime::Delta::Max(QuicTime::Delta::FromMilliseconds(kMinLossDelayMs), |
70 max_rtt.Add(max_rtt >> reordering_shift_)); | 70 max_rtt + (max_rtt >> reordering_shift_)); |
71 QuicPacketNumber packet_number = unacked_packets.GetLeastUnacked(); | 71 QuicPacketNumber packet_number = unacked_packets.GetLeastUnacked(); |
72 for (QuicUnackedPacketMap::const_iterator it = unacked_packets.begin(); | 72 for (QuicUnackedPacketMap::const_iterator it = unacked_packets.begin(); |
73 it != unacked_packets.end() && packet_number <= largest_observed; | 73 it != unacked_packets.end() && packet_number <= largest_observed; |
74 ++it, ++packet_number) { | 74 ++it, ++packet_number) { |
75 if (!it->in_flight) { | 75 if (!it->in_flight) { |
76 continue; | 76 continue; |
77 } | 77 } |
78 | 78 |
79 if (loss_type_ == kNack) { | 79 if (loss_type_ == kNack) { |
80 // FACK based loss detection. | 80 // FACK based loss detection. |
81 if (largest_observed - packet_number >= | 81 if (largest_observed - packet_number >= |
82 kNumberOfNacksBeforeRetransmission) { | 82 kNumberOfNacksBeforeRetransmission) { |
83 packets_lost->push_back(std::make_pair(packet_number, it->bytes_sent)); | 83 packets_lost->push_back(std::make_pair(packet_number, it->bytes_sent)); |
84 continue; | 84 continue; |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 // Only early retransmit(RFC5827) when the last packet gets acked and | 88 // Only early retransmit(RFC5827) when the last packet gets acked and |
89 // there are retransmittable packets in flight. | 89 // there are retransmittable packets in flight. |
90 // This also implements a timer-protected variant of FACK. | 90 // This also implements a timer-protected variant of FACK. |
91 if ((!it->retransmittable_frames.empty() && | 91 if ((!it->retransmittable_frames.empty() && |
92 unacked_packets.largest_sent_packet() == largest_observed) || | 92 unacked_packets.largest_sent_packet() == largest_observed) || |
93 (loss_type_ == kTime || loss_type_ == kAdaptiveTime)) { | 93 (loss_type_ == kTime || loss_type_ == kAdaptiveTime)) { |
94 QuicTime when_lost = it->sent_time.Add(loss_delay); | 94 QuicTime when_lost = it->sent_time + loss_delay; |
95 if (time < when_lost) { | 95 if (time < when_lost) { |
96 loss_detection_timeout_ = when_lost; | 96 loss_detection_timeout_ = when_lost; |
97 break; | 97 break; |
98 } | 98 } |
99 packets_lost->push_back(std::make_pair(packet_number, it->bytes_sent)); | 99 packets_lost->push_back(std::make_pair(packet_number, it->bytes_sent)); |
100 continue; | 100 continue; |
101 } | 101 } |
102 | 102 |
103 // NACK-based loss detection allows for a max reordering window of 1 RTT. | 103 // NACK-based loss detection allows for a max reordering window of 1 RTT. |
104 if (it->sent_time.Add(rtt_stats.smoothed_rtt()) < | 104 if (it->sent_time + rtt_stats.smoothed_rtt() < |
105 unacked_packets.GetTransmissionInfo(largest_observed).sent_time) { | 105 unacked_packets.GetTransmissionInfo(largest_observed).sent_time) { |
106 packets_lost->push_back(std::make_pair(packet_number, it->bytes_sent)); | 106 packets_lost->push_back(std::make_pair(packet_number, it->bytes_sent)); |
107 continue; | 107 continue; |
108 } | 108 } |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 QuicTime GeneralLossAlgorithm::GetLossTimeout() const { | 112 QuicTime GeneralLossAlgorithm::GetLossTimeout() const { |
113 return loss_detection_timeout_; | 113 return loss_detection_timeout_; |
114 } | 114 } |
115 | 115 |
116 void GeneralLossAlgorithm::SpuriousRetransmitDetected( | 116 void GeneralLossAlgorithm::SpuriousRetransmitDetected( |
117 const QuicUnackedPacketMap& unacked_packets, | 117 const QuicUnackedPacketMap& unacked_packets, |
118 QuicTime time, | 118 QuicTime time, |
119 const RttStats& rtt_stats, | 119 const RttStats& rtt_stats, |
120 QuicPacketNumber spurious_retransmission) { | 120 QuicPacketNumber spurious_retransmission) { |
121 if (loss_type_ != kAdaptiveTime || reordering_shift_ == 0) { | 121 if (loss_type_ != kAdaptiveTime || reordering_shift_ == 0) { |
122 return; | 122 return; |
123 } | 123 } |
124 if (spurious_retransmission <= largest_sent_on_spurious_retransmit_) { | 124 if (spurious_retransmission <= largest_sent_on_spurious_retransmit_) { |
125 return; | 125 return; |
126 } | 126 } |
127 largest_sent_on_spurious_retransmit_ = unacked_packets.largest_sent_packet(); | 127 largest_sent_on_spurious_retransmit_ = unacked_packets.largest_sent_packet(); |
128 // Calculate the extra time needed so this wouldn't have been declared lost. | 128 // Calculate the extra time needed so this wouldn't have been declared lost. |
129 // Extra time needed is based on how long it's been since the spurious | 129 // Extra time needed is based on how long it's been since the spurious |
130 // retransmission was sent, because the SRTT and latest RTT may have changed. | 130 // retransmission was sent, because the SRTT and latest RTT may have changed. |
131 QuicTime::Delta extra_time_needed = time.Subtract( | 131 QuicTime::Delta extra_time_needed = |
132 unacked_packets.GetTransmissionInfo(spurious_retransmission).sent_time); | 132 time - |
| 133 unacked_packets.GetTransmissionInfo(spurious_retransmission).sent_time; |
133 // Increase the reordering fraction until enough time would be allowed. | 134 // Increase the reordering fraction until enough time would be allowed. |
134 QuicTime::Delta max_rtt = | 135 QuicTime::Delta max_rtt = |
135 QuicTime::Delta::Max(rtt_stats.previous_srtt(), rtt_stats.latest_rtt()); | 136 QuicTime::Delta::Max(rtt_stats.previous_srtt(), rtt_stats.latest_rtt()); |
136 QuicTime::Delta proposed_extra_time(QuicTime::Delta::Zero()); | 137 QuicTime::Delta proposed_extra_time(QuicTime::Delta::Zero()); |
137 do { | 138 do { |
138 proposed_extra_time = max_rtt >> reordering_shift_; | 139 proposed_extra_time = max_rtt >> reordering_shift_; |
139 --reordering_shift_; | 140 --reordering_shift_; |
140 } while (proposed_extra_time < extra_time_needed && reordering_shift_ > 0); | 141 } while (proposed_extra_time < extra_time_needed && reordering_shift_ > 0); |
141 } | 142 } |
142 | 143 |
143 } // namespace net | 144 } // namespace net |
OLD | NEW |