Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / net / quic / congestion_control / tcp_loss_algorithm.cc
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.
4
5 #include "net/quic/congestion_control/tcp_loss_algorithm.h"
6
7 #include "net/quic/congestion_control/rtt_stats.h"
8 #include "net/quic/quic_protocol.h"
9
10 namespace net {
11
12 namespace {
13 // How many RTTs the algorithm waits before determining a packet is lost due
14 // to early retransmission.
15 static const double kEarlyRetransmitLossDelayMultiplier = 1.25;
16 }
17
18 TCPLossAlgorithm::TCPLossAlgorithm()
19     : loss_detection_timeout_(QuicTime::Zero()) { }
20
21 LossDetectionType TCPLossAlgorithm::GetLossDetectionType() const {
22   return kNack;
23 }
24
25 // Uses nack counts to decide when packets are lost.
26 SequenceNumberSet TCPLossAlgorithm::DetectLostPackets(
27     const QuicUnackedPacketMap& unacked_packets,
28     const QuicTime& time,
29     QuicPacketSequenceNumber largest_observed,
30     const RttStats& rtt_stats) {
31   SequenceNumberSet lost_packets;
32   loss_detection_timeout_ = QuicTime::Zero();
33   QuicTime::Delta loss_delay =
34       rtt_stats.smoothed_rtt().Multiply(kEarlyRetransmitLossDelayMultiplier);
35   QuicPacketSequenceNumber sequence_number = unacked_packets.GetLeastUnacked();
36   for (QuicUnackedPacketMap::const_iterator it = unacked_packets.begin();
37        it != unacked_packets.end() && sequence_number <= largest_observed;
38        ++it, ++sequence_number) {
39     if (!it->in_flight) {
40       continue;
41     }
42
43     LOG_IF(DFATAL, it->nack_count == 0)
44         << "All packets less than largest observed should have been nacked."
45         << "sequence_number:" << sequence_number
46         << " largest_observed:" << largest_observed;
47     if (it->nack_count >= kNumberOfNacksBeforeRetransmission) {
48       lost_packets.insert(sequence_number);
49       continue;
50     }
51
52     // Only early retransmit(RFC5827) when the last packet gets acked and
53     // there are retransmittable packets in flight.
54     // This also implements a timer-protected variant of FACK.
55     if (it->retransmittable_frames &&
56         unacked_packets.largest_sent_packet() == largest_observed) {
57       // Early retransmit marks the packet as lost once 1.25RTTs have passed
58       // since the packet was sent and otherwise sets an alarm.
59       if (time >= it->sent_time.Add(loss_delay)) {
60         lost_packets.insert(sequence_number);
61       } else {
62         // Set the timeout for the earliest retransmittable packet where early
63         // retransmit applies.
64         loss_detection_timeout_ = it->sent_time.Add(loss_delay);
65         break;
66       }
67     }
68   }
69
70   return lost_packets;
71 }
72
73 QuicTime TCPLossAlgorithm::GetLossTimeout() const {
74   return loss_detection_timeout_;
75 }
76
77 }  // namespace net