OLD | NEW |
| (Empty) |
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_bug_tracker.h" | |
9 #include "net/quic/quic_protocol.h" | |
10 | |
11 namespace net { | |
12 | |
13 namespace { | |
14 | |
15 // The minimum delay before a packet will be considered lost, | |
16 // regardless of SRTT. Half of the minimum TLP, since the loss algorithm only | |
17 // triggers when a nack has been receieved for the packet. | |
18 static const size_t kMinLossDelayMs = 5; | |
19 | |
20 // How many RTTs the algorithm waits before determining a packet is lost due | |
21 // to early retransmission. | |
22 static const double kEarlyRetransmitLossDelayMultiplier = 1.25; | |
23 | |
24 } // namespace | |
25 | |
26 TCPLossAlgorithm::TCPLossAlgorithm() | |
27 : loss_detection_timeout_(QuicTime::Zero()) {} | |
28 | |
29 LossDetectionType TCPLossAlgorithm::GetLossDetectionType() const { | |
30 return kNack; | |
31 } | |
32 | |
33 // Uses nack counts to decide when packets are lost. | |
34 PacketNumberSet TCPLossAlgorithm::DetectLostPackets( | |
35 const QuicUnackedPacketMap& unacked_packets, | |
36 const QuicTime& time, | |
37 QuicPacketNumber largest_observed, | |
38 const RttStats& rtt_stats) { | |
39 PacketNumberSet lost_packets; | |
40 loss_detection_timeout_ = QuicTime::Zero(); | |
41 QuicTime::Delta early_retransmit_delay = QuicTime::Delta::Max( | |
42 QuicTime::Delta::FromMilliseconds(kMinLossDelayMs), | |
43 rtt_stats.smoothed_rtt().Multiply(kEarlyRetransmitLossDelayMultiplier)); | |
44 | |
45 QuicPacketNumber packet_number = unacked_packets.GetLeastUnacked(); | |
46 for (QuicUnackedPacketMap::const_iterator it = unacked_packets.begin(); | |
47 it != unacked_packets.end() && packet_number <= largest_observed; | |
48 ++it, ++packet_number) { | |
49 if (!it->in_flight) { | |
50 continue; | |
51 } | |
52 | |
53 QUIC_BUG_IF(it->nack_count == 0 && it->sent_time.IsInitialized()) | |
54 << "All packets less than largest observed should have been nacked." | |
55 << " packet_number:" << packet_number | |
56 << " largest_observed:" << largest_observed; | |
57 if (it->nack_count >= kNumberOfNacksBeforeRetransmission) { | |
58 lost_packets.insert(packet_number); | |
59 continue; | |
60 } | |
61 | |
62 // Immediately lose the packet if it's been an srtt between the sent time | |
63 // of it and the largest observed. This speeds recovery from timer based | |
64 // retransmissions, such as TLP and RTO, when there may be fewer than | |
65 // kNumberOfNacksBeforeRetransmission nacks. | |
66 if (it->sent_time.Add(rtt_stats.smoothed_rtt()) < | |
67 unacked_packets.GetTransmissionInfo(largest_observed).sent_time) { | |
68 lost_packets.insert(packet_number); | |
69 continue; | |
70 } | |
71 | |
72 // Only early retransmit(RFC5827) when the last packet gets acked and | |
73 // there are retransmittable packets in flight. | |
74 // This also implements a timer-protected variant of FACK. | |
75 if (!it->retransmittable_frames.empty() && | |
76 unacked_packets.largest_sent_packet() == largest_observed) { | |
77 // Early retransmit marks the packet as lost once 1.25RTTs have passed | |
78 // since the packet was sent and otherwise sets an alarm. | |
79 if (time >= it->sent_time.Add(early_retransmit_delay)) { | |
80 lost_packets.insert(packet_number); | |
81 } else { | |
82 // Set the timeout for the earliest retransmittable packet where early | |
83 // retransmit applies. | |
84 loss_detection_timeout_ = it->sent_time.Add(early_retransmit_delay); | |
85 break; | |
86 } | |
87 } | |
88 } | |
89 | |
90 return lost_packets; | |
91 } | |
92 | |
93 void TCPLossAlgorithm::DetectLosses( | |
94 const QuicUnackedPacketMap& unacked_packets, | |
95 const QuicTime& time, | |
96 const RttStats& rtt_stats, | |
97 SendAlgorithmInterface::CongestionVector* packets_lost) { | |
98 QUIC_BUG << "DetectLoss is unsupported by TCPLossAlgorithm."; | |
99 } | |
100 | |
101 QuicTime TCPLossAlgorithm::GetLossTimeout() const { | |
102 return loss_detection_timeout_; | |
103 } | |
104 | |
105 } // namespace net | |
OLD | NEW |