Land Recent QUIC Changes.
[chromium-blink-merge.git] / net / quic / congestion_control / time_loss_algorithm.cc
blobc11f1ad1b648a8a6c5f1bf809ee069c6a728f347
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
3 // found in the LICENSE file.
5 #include "net/quic/congestion_control/time_loss_algorithm.h"
7 #include "net/quic/quic_protocol.h"
9 namespace net {
10 namespace {
12 // 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 // triggers when a nack has been receieved for the packet.
15 static const size_t kMinLossDelayMs = 5;
17 // How many RTTs the algorithm waits before determining a packet is lost.
18 static const double kLossDelayMultiplier = 1.25;
20 } // namespace
22 TimeLossAlgorithm::TimeLossAlgorithm()
23 : loss_detection_timeout_(QuicTime::Zero()) { }
25 SequenceNumberSet TimeLossAlgorithm::DetectLostPackets(
26 const QuicUnackedPacketMap& unacked_packets,
27 const QuicTime& time,
28 QuicPacketSequenceNumber largest_observed,
29 QuicTime::Delta srtt,
30 QuicTime::Delta latest_rtt) {
31 SequenceNumberSet lost_packets;
32 loss_detection_timeout_ = QuicTime::Zero();
33 QuicTime::Delta loss_delay = QuicTime::Delta::Max(
34 QuicTime::Delta::FromMilliseconds(kMinLossDelayMs),
35 QuicTime::Delta::Max(srtt, latest_rtt).Multiply(kLossDelayMultiplier));
37 for (QuicUnackedPacketMap::const_iterator it = unacked_packets.begin();
38 it != unacked_packets.end() && it->first <= largest_observed; ++it) {
39 if (!it->second.pending) {
40 continue;
42 LOG_IF(DFATAL, it->second.nack_count == 0)
43 << "All packets less than largest observed should have been nacked.";
45 // 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 QuicTime when_lost = it->second.sent_time.Add(loss_delay);
48 if (time < when_lost) {
49 loss_detection_timeout_ = when_lost;
50 break;
52 lost_packets.insert(it->first);
55 return lost_packets;
58 // loss_time_ is updated in DetectLostPackets, which must be called every time
59 // an ack is received or the timeout expires.
60 QuicTime TimeLossAlgorithm::GetLossTimeout() const {
61 return loss_detection_timeout_;
64 } // namespace net