| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/time_loss_algorithm.h" | 5 #include "net/quic/congestion_control/time_loss_algorithm.h" |
| 6 | 6 |
| 7 #include "net/quic/congestion_control/rtt_stats.h" |
| 7 #include "net/quic/quic_protocol.h" | 8 #include "net/quic/quic_protocol.h" |
| 8 | 9 |
| 9 namespace net { | 10 namespace net { |
| 10 namespace { | 11 namespace { |
| 11 | 12 |
| 12 // The minimum delay before a packet will be considered lost, | 13 // The minimum delay before a packet will be considered lost, |
| 13 // regardless of SRTT. Half of the minimum TLP, since the loss algorithm only | 14 // regardless of SRTT. Half of the minimum TLP, since the loss algorithm only |
| 14 // triggers when a nack has been receieved for the packet. | 15 // triggers when a nack has been receieved for the packet. |
| 15 static const size_t kMinLossDelayMs = 5; | 16 static const size_t kMinLossDelayMs = 5; |
| 16 | 17 |
| 17 // How many RTTs the algorithm waits before determining a packet is lost. | 18 // How many RTTs the algorithm waits before determining a packet is lost. |
| 18 static const double kLossDelayMultiplier = 1.25; | 19 static const double kLossDelayMultiplier = 1.25; |
| 19 | 20 |
| 20 } // namespace | 21 } // namespace |
| 21 | 22 |
| 22 TimeLossAlgorithm::TimeLossAlgorithm() | 23 TimeLossAlgorithm::TimeLossAlgorithm() |
| 23 : loss_detection_timeout_(QuicTime::Zero()) { } | 24 : loss_detection_timeout_(QuicTime::Zero()) { } |
| 24 | 25 |
| 25 SequenceNumberSet TimeLossAlgorithm::DetectLostPackets( | 26 SequenceNumberSet TimeLossAlgorithm::DetectLostPackets( |
| 26 const QuicUnackedPacketMap& unacked_packets, | 27 const QuicUnackedPacketMap& unacked_packets, |
| 27 const QuicTime& time, | 28 const QuicTime& time, |
| 28 QuicPacketSequenceNumber largest_observed, | 29 QuicPacketSequenceNumber largest_observed, |
| 29 QuicTime::Delta srtt, | 30 const RttStats& rtt_stats) { |
| 30 QuicTime::Delta latest_rtt) { | |
| 31 SequenceNumberSet lost_packets; | 31 SequenceNumberSet lost_packets; |
| 32 loss_detection_timeout_ = QuicTime::Zero(); | 32 loss_detection_timeout_ = QuicTime::Zero(); |
| 33 QuicTime::Delta loss_delay = QuicTime::Delta::Max( | 33 QuicTime::Delta loss_delay = QuicTime::Delta::Max( |
| 34 QuicTime::Delta::FromMilliseconds(kMinLossDelayMs), | 34 QuicTime::Delta::FromMilliseconds(kMinLossDelayMs), |
| 35 QuicTime::Delta::Max(srtt, latest_rtt).Multiply(kLossDelayMultiplier)); | 35 QuicTime::Delta::Max(rtt_stats.SmoothedRtt(), rtt_stats.latest_rtt()) |
| 36 .Multiply(kLossDelayMultiplier)); |
| 36 | 37 |
| 37 for (QuicUnackedPacketMap::const_iterator it = unacked_packets.begin(); | 38 for (QuicUnackedPacketMap::const_iterator it = unacked_packets.begin(); |
| 38 it != unacked_packets.end() && it->first <= largest_observed; ++it) { | 39 it != unacked_packets.end() && it->first <= largest_observed; ++it) { |
| 39 if (!it->second.pending) { | 40 if (!it->second.pending) { |
| 40 continue; | 41 continue; |
| 41 } | 42 } |
| 42 LOG_IF(DFATAL, it->second.nack_count == 0) | 43 LOG_IF(DFATAL, it->second.nack_count == 0) |
| 43 << "All packets less than largest observed should have been nacked."; | 44 << "All packets less than largest observed should have been nacked."; |
| 44 | 45 |
| 45 // Packets are sent in order, so break when we haven't waited long enough | 46 // Packets are sent in order, so break when we haven't waited long enough |
| 46 // to lose any more packets and leave the loss_time_ set for the timeout. | 47 // to lose any more packets and leave the loss_time_ set for the timeout. |
| 47 QuicTime when_lost = it->second.sent_time.Add(loss_delay); | 48 QuicTime when_lost = it->second.sent_time.Add(loss_delay); |
| 48 if (time < when_lost) { | 49 if (time < when_lost) { |
| 49 loss_detection_timeout_ = when_lost; | 50 loss_detection_timeout_ = when_lost; |
| 50 break; | 51 break; |
| 51 } | 52 } |
| 52 lost_packets.insert(it->first); | 53 lost_packets.insert(it->first); |
| 53 } | 54 } |
| 54 | 55 |
| 55 return lost_packets; | 56 return lost_packets; |
| 56 } | 57 } |
| 57 | 58 |
| 58 // loss_time_ is updated in DetectLostPackets, which must be called every time | 59 // loss_time_ is updated in DetectLostPackets, which must be called every time |
| 59 // an ack is received or the timeout expires. | 60 // an ack is received or the timeout expires. |
| 60 QuicTime TimeLossAlgorithm::GetLossTimeout() const { | 61 QuicTime TimeLossAlgorithm::GetLossTimeout() const { |
| 61 return loss_detection_timeout_; | 62 return loss_detection_timeout_; |
| 62 } | 63 } |
| 63 | 64 |
| 64 } // namespace net | 65 } // namespace net |
| OLD | NEW |