blob: 771d93e32856dee12c8c6862b1fa5fc545d644c9 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// Copyright (c) 2016 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#ifndef QUICHE_QUIC_CORE_FRAMES_QUIC_ACK_FRAME_H_
6#define QUICHE_QUIC_CORE_FRAMES_QUIC_ACK_FRAME_H_
7
8#include <ostream>
9
10#include "net/third_party/quiche/src/quic/core/quic_interval.h"
11#include "net/third_party/quiche/src/quic/core/quic_types.h"
12#include "net/third_party/quiche/src/quic/platform/api/quic_containers.h"
13#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
14#include "net/third_party/quiche/src/quic/platform/api/quic_flags.h"
15
16namespace quic {
17
18// A sequence of packet numbers where each number is unique. Intended to be used
19// in a sliding window fashion, where smaller old packet numbers are removed and
20// larger new packet numbers are added, with the occasional random access.
21class QUIC_EXPORT_PRIVATE PacketNumberQueue {
22 public:
23 PacketNumberQueue();
24 PacketNumberQueue(const PacketNumberQueue& other);
25 PacketNumberQueue(PacketNumberQueue&& other);
26 ~PacketNumberQueue();
27
28 PacketNumberQueue& operator=(const PacketNumberQueue& other);
29 PacketNumberQueue& operator=(PacketNumberQueue&& other);
30
31 typedef QuicDeque<QuicInterval<QuicPacketNumber>>::const_iterator
32 const_iterator;
33 typedef QuicDeque<QuicInterval<QuicPacketNumber>>::const_reverse_iterator
34 const_reverse_iterator;
35
36 // Adds |packet_number| to the set of packets in the queue.
37 void Add(QuicPacketNumber packet_number);
38
39 // Adds packets between [lower, higher) to the set of packets in the queue. It
40 // is undefined behavior to call this with |higher| < |lower|.
41 void AddRange(QuicPacketNumber lower, QuicPacketNumber higher);
42
43 // Removes packets with values less than |higher| from the set of packets in
44 // the queue. Returns true if packets were removed.
45 bool RemoveUpTo(QuicPacketNumber higher);
46
47 // Removes the smallest interval in the queue.
48 void RemoveSmallestInterval();
49
50 // Clear this packet number queue.
51 void Clear();
52
53 // Returns true if the queue contains |packet_number|.
54 bool Contains(QuicPacketNumber packet_number) const;
55
56 // Returns true if the queue is empty.
57 bool Empty() const;
58
59 // Returns the minimum packet number stored in the queue. It is undefined
60 // behavior to call this if the queue is empty.
61 QuicPacketNumber Min() const;
62
63 // Returns the maximum packet number stored in the queue. It is undefined
64 // behavior to call this if the queue is empty.
65 QuicPacketNumber Max() const;
66
67 // Returns the number of unique packets stored in the queue. Inefficient; only
68 // exposed for testing.
69 QuicPacketCount NumPacketsSlow() const;
70
71 // Returns the number of disjoint packet number intervals contained in the
72 // queue.
73 size_t NumIntervals() const;
74
75 // Returns the length of last interval.
76 QuicPacketCount LastIntervalLength() const;
77
78 // Returns iterators over the packet number intervals.
79 const_iterator begin() const;
80 const_iterator end() const;
81 const_reverse_iterator rbegin() const;
82 const_reverse_iterator rend() const;
83
84 friend QUIC_EXPORT_PRIVATE std::ostream& operator<<(
85 std::ostream& os,
86 const PacketNumberQueue& q);
87
88 private:
89 QuicDeque<QuicInterval<QuicPacketNumber>> packet_number_deque_;
90};
91
92struct QUIC_EXPORT_PRIVATE QuicAckFrame {
93 QuicAckFrame();
94 QuicAckFrame(const QuicAckFrame& other);
95 ~QuicAckFrame();
96
97 void Clear();
98
99 friend QUIC_EXPORT_PRIVATE std::ostream& operator<<(
100 std::ostream& os,
101 const QuicAckFrame& ack_frame);
102
103 // The highest packet number we've observed from the peer. When |packets| is
104 // not empty, it should always be equal to packets.Max(). The |LargestAcked|
105 // function ensures this invariant in debug mode.
106 QuicPacketNumber largest_acked;
107
108 // Time elapsed since largest_observed() was received until this Ack frame was
109 // sent.
110 QuicTime::Delta ack_delay_time;
111
112 // Vector of <packet_number, time> for when packets arrived.
113 PacketTimeVector received_packet_times;
114
115 // Set of packets.
116 PacketNumberQueue packets;
117
118 // ECN counters, used only in version 99's ACK frame and valid only when
119 // |ecn_counters_populated| is true.
120 bool ecn_counters_populated;
121 QuicPacketCount ect_0_count;
122 QuicPacketCount ect_1_count;
123 QuicPacketCount ecn_ce_count;
124};
125
126// The highest acked packet number we've observed from the peer. If no packets
127// have been observed, return 0.
128inline QUIC_EXPORT_PRIVATE QuicPacketNumber
129LargestAcked(const QuicAckFrame& frame) {
130 DCHECK(frame.packets.Empty() || frame.packets.Max() == frame.largest_acked);
131 return frame.largest_acked;
132}
133
134// True if the packet number is greater than largest_observed or is listed
135// as missing.
136// Always returns false for packet numbers less than least_unacked.
137QUIC_EXPORT_PRIVATE bool IsAwaitingPacket(
138 const QuicAckFrame& ack_frame,
139 QuicPacketNumber packet_number,
140 QuicPacketNumber peer_least_packet_awaiting_ack);
141
142} // namespace quic
143
144#endif // QUICHE_QUIC_CORE_FRAMES_QUIC_ACK_FRAME_H_