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 // The pure virtual class for send side loss detection algorithm.
6 
7 #ifndef QUICHE_QUIC_CORE_CONGESTION_CONTROL_LOSS_DETECTION_INTERFACE_H_
8 #define QUICHE_QUIC_CORE_CONGESTION_CONTROL_LOSS_DETECTION_INTERFACE_H_
9 
10 #include "quiche/quic/core/congestion_control/send_algorithm_interface.h"
11 #include "quiche/quic/core/quic_config.h"
12 #include "quiche/quic/core/quic_packets.h"
13 #include "quiche/quic/core/quic_time.h"
14 #include "quiche/quic/core/quic_types.h"
15 #include "quiche/quic/platform/api/quic_export.h"
16 
17 namespace quic {
18 
19 class QuicUnackedPacketMap;
20 class RttStats;
21 
22 class QUICHE_EXPORT LossDetectionInterface {
23  public:
~LossDetectionInterface()24   virtual ~LossDetectionInterface() {}
25 
26   virtual void SetFromConfig(const QuicConfig& config,
27                              Perspective perspective) = 0;
28 
29   struct QUICHE_EXPORT DetectionStats {
30     // Maximum sequence reordering observed in newly acked packets.
31     QuicPacketCount sent_packets_max_sequence_reordering = 0;
32     QuicPacketCount sent_packets_num_borderline_time_reorderings = 0;
33     // Total detection response time for lost packets from this detection.
34     // See QuicConnectionStats for the definition of detection response time.
35     float total_loss_detection_response_time = 0.0;
36   };
37 
38   // Called when a new ack arrives or the loss alarm fires.
39   virtual DetectionStats DetectLosses(
40       const QuicUnackedPacketMap& unacked_packets, QuicTime time,
41       const RttStats& rtt_stats, QuicPacketNumber largest_newly_acked,
42       const AckedPacketVector& packets_acked,
43       LostPacketVector* packets_lost) = 0;
44 
45   // Get the time the LossDetectionAlgorithm wants to re-evaluate losses.
46   // Returns QuicTime::Zero if no alarm needs to be set.
47   virtual QuicTime GetLossTimeout() const = 0;
48 
49   // Called when |packet_number| was detected lost but gets acked later.
50   virtual void SpuriousLossDetected(
51       const QuicUnackedPacketMap& unacked_packets, const RttStats& rtt_stats,
52       QuicTime ack_receive_time, QuicPacketNumber packet_number,
53       QuicPacketNumber previous_largest_acked) = 0;
54 
55   virtual void OnConfigNegotiated() = 0;
56 
57   virtual void OnMinRttAvailable() = 0;
58 
59   virtual void OnUserAgentIdKnown() = 0;
60 
61   virtual void OnConnectionClosed() = 0;
62 
63   // Called when a reordering is detected by the loss algorithm, but _before_
64   // the reordering_shift and reordering_threshold are consulted to see whether
65   // it is a loss.
66   virtual void OnReorderingDetected() = 0;
67 };
68 
69 }  // namespace quic
70 
71 #endif  // QUICHE_QUIC_CORE_CONGESTION_CONTROL_LOSS_DETECTION_INTERFACE_H_
72