OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Manages the packet entropy calculation for both sent and received packets | 5 // Manages the packet entropy calculation for both sent and received packets |
6 // for a connection. | 6 // for a connection. |
7 | 7 |
8 #ifndef NET_QUIC_QUIC_RECEIVED_PACKET_MANAGER_H_ | 8 #ifndef NET_QUIC_QUIC_RECEIVED_PACKET_MANAGER_H_ |
9 #define NET_QUIC_QUIC_RECEIVED_PACKET_MANAGER_H_ | 9 #define NET_QUIC_QUIC_RECEIVED_PACKET_MANAGER_H_ |
10 | 10 |
| 11 #include <deque> |
| 12 |
11 #include "net/quic/congestion_control/receive_algorithm_interface.h" | 13 #include "net/quic/congestion_control/receive_algorithm_interface.h" |
12 #include "net/quic/quic_framer.h" | 14 #include "net/quic/quic_framer.h" |
13 #include "net/quic/quic_protocol.h" | 15 #include "net/quic/quic_protocol.h" |
14 | 16 |
15 namespace net { | 17 namespace net { |
16 | 18 |
17 namespace test { | 19 namespace test { |
18 class EntropyTrackerPeer; | 20 class EntropyTrackerPeer; |
19 class QuicConnectionPeer; | 21 class QuicConnectionPeer; |
20 class QuicReceivedPacketManagerPeer; | 22 class QuicReceivedPacketManagerPeer; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 54 |
53 // Sets the entropy hash up to but not including a sequence number based | 55 // Sets the entropy hash up to but not including a sequence number based |
54 // on the hash provided by a StopWaiting frame. Clears older packet | 56 // on the hash provided by a StopWaiting frame. Clears older packet |
55 // entropy entries and performs garbage collection up to the first gap. | 57 // entropy entries and performs garbage collection up to the first gap. |
56 void SetCumulativeEntropyUpTo(QuicPacketSequenceNumber sequence_number, | 58 void SetCumulativeEntropyUpTo(QuicPacketSequenceNumber sequence_number, |
57 QuicPacketEntropyHash entropy_hash); | 59 QuicPacketEntropyHash entropy_hash); |
58 | 60 |
59 private: | 61 private: |
60 friend class test::EntropyTrackerPeer; | 62 friend class test::EntropyTrackerPeer; |
61 | 63 |
62 typedef std::map<QuicPacketSequenceNumber, | 64 // A deque indexed by sequence number storing the packet's hash and whether |
63 QuicPacketEntropyHash> ReceivedEntropyMap; | 65 // a hash was recorded for that sequence number. |
| 66 typedef std::deque<std::pair<QuicPacketEntropyHash, bool>> |
| 67 ReceivedEntropyHashes; |
64 | 68 |
65 // Recomputes first_gap_ and removes packets_entropy_ entries that are no | 69 // Recomputes first_gap_ and removes packets_entropy_ entries that are no |
66 // longer needed to compute EntropyHash. | 70 // longer needed to compute EntropyHash. |
67 void AdvanceFirstGapAndGarbageCollectEntropyMap(); | 71 void AdvanceFirstGapAndGarbageCollectEntropyMap(); |
68 | 72 |
69 // TODO(satyamshekhar): Can be optimized using an interval set like data | |
70 // structure. | |
71 // Map of received sequence numbers to their corresponding entropy. | 73 // Map of received sequence numbers to their corresponding entropy. |
72 // Stores an entry for every received packet whose sequence_number is larger | 74 // Stores an entry for every received packet whose sequence_number is larger |
73 // than first_gap_. Packets without the entropy bit set have an entropy | 75 // than first_gap_. Packets without the entropy bit set have an entropy |
74 // value of 0. | 76 // value of 0. |
75 // TODO(ianswett): When the entropy flag is off, the entropy | 77 ReceivedEntropyHashes packets_entropy_; |
76 // should not be 0. | |
77 ReceivedEntropyMap packets_entropy_; | |
78 | 78 |
79 // Cumulative hash of entropy of all received packets. | 79 // Cumulative hash of entropy of all received packets. |
80 QuicPacketEntropyHash packets_entropy_hash_; | 80 QuicPacketEntropyHash packets_entropy_hash_; |
81 | 81 |
82 // Sequence number of the first packet that we do not know the entropy of. | 82 // Sequence number of the first packet that we do not know the entropy of. |
83 // If there are no gaps in the received packet sequence, | 83 // If there are no gaps in the received packet sequence, |
84 // packets_entropy_ will be empty and first_gap_ will be equal to | 84 // packets_entropy_ will be empty and first_gap_ will be equal to |
85 // 'largest_observed_ + 1' since that's the first packet for which | 85 // 'largest_observed_ + 1' since that's the first packet for which |
86 // entropy is unknown. If there are gaps, packets_entropy_ will | 86 // entropy is unknown. If there are gaps, packets_entropy_ will |
87 // contain entries for all received packets with sequence_number > | 87 // contain entries for all received packets with sequence_number > |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 // Otherwise fills in feedback and returns true. | 124 // Otherwise fills in feedback and returns true. |
125 virtual bool GenerateCongestionFeedback( | 125 virtual bool GenerateCongestionFeedback( |
126 QuicCongestionFeedbackFrame* feedback); | 126 QuicCongestionFeedbackFrame* feedback); |
127 | 127 |
128 // QuicReceivedEntropyHashCalculatorInterface | 128 // QuicReceivedEntropyHashCalculatorInterface |
129 // Called by QuicFramer, when the outgoing ack gets truncated, to recalculate | 129 // Called by QuicFramer, when the outgoing ack gets truncated, to recalculate |
130 // the received entropy hash for the truncated ack frame. | 130 // the received entropy hash for the truncated ack frame. |
131 virtual QuicPacketEntropyHash EntropyHash( | 131 virtual QuicPacketEntropyHash EntropyHash( |
132 QuicPacketSequenceNumber sequence_number) const OVERRIDE; | 132 QuicPacketSequenceNumber sequence_number) const OVERRIDE; |
133 | 133 |
134 // Updates internal state based on |ack_frame|. | |
135 void UpdatePacketInformationReceivedByPeer(const QuicAckFrame& ack_frame); | |
136 // Updates internal state based on |stop_waiting|. | 134 // Updates internal state based on |stop_waiting|. |
137 void UpdatePacketInformationSentByPeer( | 135 void UpdatePacketInformationSentByPeer( |
138 const QuicStopWaitingFrame& stop_waiting); | 136 const QuicStopWaitingFrame& stop_waiting); |
139 | 137 |
140 // Returns whether the peer is missing packets. | |
141 bool HasMissingPackets(); | |
142 | |
143 // Returns true when there are new missing packets to be reported within 3 | 138 // Returns true when there are new missing packets to be reported within 3 |
144 // packets of the largest observed. | 139 // packets of the largest observed. |
145 bool HasNewMissingPackets(); | 140 bool HasNewMissingPackets(); |
146 | 141 |
147 QuicPacketSequenceNumber peer_largest_observed_packet() { | |
148 return peer_largest_observed_packet_; | |
149 } | |
150 | |
151 QuicPacketSequenceNumber least_packet_awaited_by_peer() { | |
152 return least_packet_awaited_by_peer_; | |
153 } | |
154 | |
155 QuicPacketSequenceNumber peer_least_packet_awaiting_ack() { | 142 QuicPacketSequenceNumber peer_least_packet_awaiting_ack() { |
156 return peer_least_packet_awaiting_ack_; | 143 return peer_least_packet_awaiting_ack_; |
157 } | 144 } |
158 | 145 |
159 private: | 146 private: |
160 friend class test::QuicConnectionPeer; | 147 friend class test::QuicConnectionPeer; |
161 friend class test::QuicReceivedPacketManagerPeer; | 148 friend class test::QuicReceivedPacketManagerPeer; |
162 | 149 |
163 // Deletes all missing packets before least unacked. The connection won't | 150 // Deletes all missing packets before least unacked. The connection won't |
164 // process any packets with sequence number before |least_unacked| that it | 151 // process any packets with sequence number before |least_unacked| that it |
165 // received after this call. Returns true if there were missing packets before | 152 // received after this call. Returns true if there were missing packets before |
166 // |least_unacked| unacked, false otherwise. | 153 // |least_unacked| unacked, false otherwise. |
167 bool DontWaitForPacketsBefore(QuicPacketSequenceNumber least_unacked); | 154 bool DontWaitForPacketsBefore(QuicPacketSequenceNumber least_unacked); |
168 | 155 |
169 // Tracks entropy hashes of received packets. | 156 // Tracks entropy hashes of received packets. |
170 EntropyTracker entropy_tracker_; | 157 EntropyTracker entropy_tracker_; |
171 | 158 |
172 // Track some peer state so we can do less bookkeeping. | |
173 // Largest sequence number that the peer has observed. Mostly received, | |
174 // missing in case of truncated acks. | |
175 QuicPacketSequenceNumber peer_largest_observed_packet_; | |
176 // Least sequence number which the peer is still waiting for. | |
177 QuicPacketSequenceNumber least_packet_awaited_by_peer_; | |
178 // Least sequence number of the the packet sent by the peer for which it | 159 // Least sequence number of the the packet sent by the peer for which it |
179 // hasn't received an ack. | 160 // hasn't received an ack. |
180 QuicPacketSequenceNumber peer_least_packet_awaiting_ack_; | 161 QuicPacketSequenceNumber peer_least_packet_awaiting_ack_; |
181 | 162 |
182 // Received packet information used to produce acks. | 163 // Received packet information used to produce acks. |
183 QuicAckFrame ack_frame_; | 164 QuicAckFrame ack_frame_; |
184 | 165 |
185 // The time we received the largest_observed sequence number, or zero if | 166 // The time we received the largest_observed sequence number, or zero if |
186 // no sequence numbers have been received since UpdateReceivedPacketInfo. | 167 // no sequence numbers have been received since UpdateReceivedPacketInfo. |
187 // Needed for calculating delta_time_largest_observed. | 168 // Needed for calculating delta_time_largest_observed. |
188 QuicTime time_largest_observed_; | 169 QuicTime time_largest_observed_; |
189 | 170 |
190 scoped_ptr<ReceiveAlgorithmInterface> receive_algorithm_; | 171 scoped_ptr<ReceiveAlgorithmInterface> receive_algorithm_; |
191 | 172 |
192 QuicConnectionStats* stats_; | 173 QuicConnectionStats* stats_; |
193 | 174 |
194 DISALLOW_COPY_AND_ASSIGN(QuicReceivedPacketManager); | 175 DISALLOW_COPY_AND_ASSIGN(QuicReceivedPacketManager); |
195 }; | 176 }; |
196 | 177 |
197 } // namespace net | 178 } // namespace net |
198 | 179 |
199 #endif // NET_QUIC_QUIC_RECEIVED_PACKET_MANAGER_H_ | 180 #endif // NET_QUIC_QUIC_RECEIVED_PACKET_MANAGER_H_ |
OLD | NEW |