MacViews: Get c/b/ui/views/tabs to build on Mac
[chromium-blink-merge.git] / net / quic / congestion_control / tcp_loss_algorithm.cc
blobb0a5a15b4972fa0baacaf34e3638c9fab3502587
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/tcp_loss_algorithm.h"
7 #include "net/quic/congestion_control/rtt_stats.h"
8 #include "net/quic/quic_protocol.h"
10 namespace net {
12 namespace {
14 // TCP retransmits after 3 nacks.
15 static const size_t kNumberOfNacksBeforeRetransmission = 3;
17 // How many RTTs the algorithm waits before determining a packet is lost due
18 // to early retransmission.
19 static const double kEarlyRetransmitLossDelayMultiplier = 1.25;
23 TCPLossAlgorithm::TCPLossAlgorithm()
24 : loss_detection_timeout_(QuicTime::Zero()) { }
26 LossDetectionType TCPLossAlgorithm::GetLossDetectionType() const {
27 return kNack;
30 // Uses nack counts to decide when packets are lost.
31 SequenceNumberSet TCPLossAlgorithm::DetectLostPackets(
32 const QuicUnackedPacketMap& unacked_packets,
33 const QuicTime& time,
34 QuicPacketSequenceNumber largest_observed,
35 const RttStats& rtt_stats) {
36 SequenceNumberSet lost_packets;
37 loss_detection_timeout_ = QuicTime::Zero();
38 QuicTime::Delta loss_delay =
39 rtt_stats.SmoothedRtt().Multiply(kEarlyRetransmitLossDelayMultiplier);
40 QuicPacketSequenceNumber sequence_number = unacked_packets.GetLeastUnacked();
41 for (QuicUnackedPacketMap::const_iterator it = unacked_packets.begin();
42 it != unacked_packets.end() && sequence_number <= largest_observed;
43 ++it, ++sequence_number) {
44 if (!it->in_flight) {
45 continue;
48 LOG_IF(DFATAL, it->nack_count == 0)
49 << "All packets less than largest observed should have been nacked."
50 << "sequence_number:" << sequence_number
51 << " largest_observed:" << largest_observed;
52 if (it->nack_count >= kNumberOfNacksBeforeRetransmission) {
53 lost_packets.insert(sequence_number);
54 continue;
57 // Only early retransmit(RFC5827) when the last packet gets acked and
58 // there are retransmittable packets in flight.
59 // This also implements a timer-protected variant of FACK.
60 if (it->retransmittable_frames &&
61 unacked_packets.largest_sent_packet() == largest_observed) {
62 // Early retransmit marks the packet as lost once 1.25RTTs have passed
63 // since the packet was sent and otherwise sets an alarm.
64 if (time >= it->sent_time.Add(loss_delay)) {
65 lost_packets.insert(sequence_number);
66 } else {
67 // Set the timeout for the earliest retransmittable packet where early
68 // retransmit applies.
69 loss_detection_timeout_ = it->sent_time.Add(loss_delay);
70 break;
75 return lost_packets;
78 QuicTime TCPLossAlgorithm::GetLossTimeout() const {
79 return loss_detection_timeout_;
82 } // namespace net