Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(425)

Side by Side Diff: net/quic/quic_packet_creator.h

Issue 1495263002: QuicPacketCreator knows when to start FEC protection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@108738647
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | net/quic/quic_packet_creator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // Accumulates frames for the next packet until more frames no longer fit or 5 // Accumulates frames for the next packet until more frames no longer fit or
6 // it's time to create a packet from them. Also provides packet creation of 6 // it's time to create a packet from them. Also provides packet creation of
7 // FEC packets based on previously created packets. 7 // FEC packets based on previously created packets.
8 8
9 #ifndef NET_QUIC_QUIC_PACKET_CREATOR_H_ 9 #ifndef NET_QUIC_QUIC_PACKET_CREATOR_H_
10 #define NET_QUIC_QUIC_PACKET_CREATOR_H_ 10 #define NET_QUIC_QUIC_PACKET_CREATOR_H_
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 QuicFramer* framer, 45 QuicFramer* framer,
46 QuicRandom* random_generator, 46 QuicRandom* random_generator,
47 DelegateInterface* delegate); 47 DelegateInterface* delegate);
48 48
49 ~QuicPacketCreator(); 49 ~QuicPacketCreator();
50 50
51 // Checks if it's time to send an FEC packet. |force_close| forces this to 51 // Checks if it's time to send an FEC packet. |force_close| forces this to
52 // return true if an FEC group is open. 52 // return true if an FEC group is open.
53 bool ShouldSendFec(bool force_close) const; 53 bool ShouldSendFec(bool force_close) const;
54 54
55 // Turn on FEC protection for subsequent packets. If no FEC group is currently
56 // open, this method flushes current open packet and then turns FEC on.
57 void MaybeStartFecProtection();
58
59 // If ShouldSendFec returns true, serializes currently constructed FEC packet 55 // If ShouldSendFec returns true, serializes currently constructed FEC packet
60 // and calls the delegate on the packet. Resets current FEC group if FEC 56 // and calls the delegate on the packet. Resets current FEC group if FEC
61 // protection policy is FEC_ALARM_TRIGGER but |is_fec_timeout| is false. 57 // protection policy is FEC_ALARM_TRIGGER but |is_fec_timeout| is false.
62 // Also tries to turn off FEC protection if should_fec_protect_ is false. 58 // Also tries to turn off FEC protection if should_fec_protect_next_packet is
59 // false.
63 void MaybeSendFecPacketAndCloseGroup(bool force_send_fec, 60 void MaybeSendFecPacketAndCloseGroup(bool force_send_fec,
64 bool is_fec_timeout); 61 bool is_fec_timeout);
65 62
66 // Returns true if an FEC packet is under construction. 63 // Returns true if an FEC packet is under construction.
67 bool IsFecGroupOpen() const; 64 bool IsFecGroupOpen() const;
68 65
69 // Called after sending |packet_number| to determine whether an FEC alarm 66 // Called after sending |packet_number| to determine whether an FEC alarm
70 // should be set for sending out an FEC packet. Returns a positive and finite 67 // should be set for sending out an FEC packet. Returns a positive and finite
71 // timeout if an FEC alarm should be set, and infinite if no alarm should be 68 // timeout if an FEC alarm should be set, and infinite if no alarm should be
72 // set. 69 // set.
(...skipping 13 matching lines...) Expand all
86 bool include_version, 83 bool include_version,
87 QuicPacketNumberLength packet_number_length, 84 QuicPacketNumberLength packet_number_length,
88 QuicStreamOffset offset, 85 QuicStreamOffset offset,
89 InFecGroup is_in_fec_group); 86 InFecGroup is_in_fec_group);
90 87
91 // Returns false and flushes all pending frames if current open packet is 88 // Returns false and flushes all pending frames if current open packet is
92 // full. 89 // full.
93 // If current packet is not full, converts a raw payload into a stream frame 90 // If current packet is not full, converts a raw payload into a stream frame
94 // that fits into the open packet and adds it to the packet. 91 // that fits into the open packet and adds it to the packet.
95 // The payload begins at |iov_offset| into the |iov|. 92 // The payload begins at |iov_offset| into the |iov|.
93 // Also tries to start FEC protection depends on |fec_protection|.
96 bool ConsumeData(QuicStreamId id, 94 bool ConsumeData(QuicStreamId id,
97 QuicIOVector iov, 95 QuicIOVector iov,
98 size_t iov_offset, 96 size_t iov_offset,
99 QuicStreamOffset offset, 97 QuicStreamOffset offset,
100 bool fin, 98 bool fin,
101 bool needs_padding, 99 bool needs_padding,
102 QuicFrame* frame); 100 QuicFrame* frame,
101 FecProtection fec_protection);
103 102
104 // Returns true if current open packet can accommodate more stream frames of 103 // Returns true if current open packet can accommodate more stream frames of
105 // stream |id| at |offset|, false otherwise. 104 // stream |id| at |offset|, false otherwise.
106 bool HasRoomForStreamFrame(QuicStreamId id, QuicStreamOffset offset) const; 105 bool HasRoomForStreamFrame(QuicStreamId id, QuicStreamOffset offset) const;
107 106
108 // Serializes all frames into a single packet. All frames must fit into a 107 // Serializes all frames into a single packet. All frames must fit into a
109 // single packet. Also, sets the entropy hash of the serialized packet to a 108 // single packet. Also, sets the entropy hash of the serialized packet to a
110 // random bool and returns that value as a member of SerializedPacket. 109 // random bool and returns that value as a member of SerializedPacket.
111 // Never returns a RetransmittableFrames in SerializedPacket. 110 // Never returns a RetransmittableFrames in SerializedPacket.
112 SerializedPacket SerializeAllFrames(const QuicFrames& frames, 111 SerializedPacket SerializeAllFrames(const QuicFrames& frames,
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 230
232 void set_fec_send_policy(FecSendPolicy fec_send_policy) { 231 void set_fec_send_policy(FecSendPolicy fec_send_policy) {
233 fec_send_policy_ = fec_send_policy; 232 fec_send_policy_ = fec_send_policy;
234 } 233 }
235 234
236 void set_rtt_multiplier_for_fec_timeout( 235 void set_rtt_multiplier_for_fec_timeout(
237 float rtt_multiplier_for_fec_timeout) { 236 float rtt_multiplier_for_fec_timeout) {
238 rtt_multiplier_for_fec_timeout_ = rtt_multiplier_for_fec_timeout; 237 rtt_multiplier_for_fec_timeout_ = rtt_multiplier_for_fec_timeout;
239 } 238 }
240 239
241 bool should_fec_protect() { return should_fec_protect_; } 240 bool should_fec_protect_next_packet() {
241 return should_fec_protect_next_packet_;
242 }
242 243
243 void set_should_fec_protect(bool should_fec_protect) { 244 void set_should_fec_protect_next_packet(bool should_fec_protect_next_packet) {
244 should_fec_protect_ = should_fec_protect; 245 should_fec_protect_next_packet_ = should_fec_protect_next_packet;
245 } 246 }
246 247
247 private: 248 private:
248 friend class test::QuicPacketCreatorPeer; 249 friend class test::QuicPacketCreatorPeer;
249 250
250 static bool ShouldRetransmit(const QuicFrame& frame); 251 static bool ShouldRetransmit(const QuicFrame& frame);
251 252
252 // Converts a raw payload to a frame which fits into the current open 253 // Converts a raw payload to a frame which fits into the current open
253 // packet. The payload begins at |iov_offset| into the |iov|. 254 // packet. The payload begins at |iov_offset| into the |iov|.
254 // Returns the number of bytes consumed from data. 255 // Returns the number of bytes consumed from data.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 // Serializes all frames which have been added and adds any which should be 301 // Serializes all frames which have been added and adds any which should be
301 // retransmitted to queued_retransmittable_frames_ if it's not nullptr. All 302 // retransmitted to queued_retransmittable_frames_ if it's not nullptr. All
302 // frames must fit into a single packet. Sets the entropy hash of the 303 // frames must fit into a single packet. Sets the entropy hash of the
303 // serialized packet to a random bool and returns that value as a member of 304 // serialized packet to a random bool and returns that value as a member of
304 // SerializedPacket. Also, sets |serialized_frames| in the SerializedPacket to 305 // SerializedPacket. Also, sets |serialized_frames| in the SerializedPacket to
305 // the corresponding RetransmittableFrames if any frames are to be 306 // the corresponding RetransmittableFrames if any frames are to be
306 // retransmitted. 307 // retransmitted.
307 // Fails if |buffer_len| isn't long enough for the encrypted packet. 308 // Fails if |buffer_len| isn't long enough for the encrypted packet.
308 SerializedPacket SerializePacket(char* encrypted_buffer, size_t buffer_len); 309 SerializedPacket SerializePacket(char* encrypted_buffer, size_t buffer_len);
309 310
311 // Turn on FEC protection for subsequent packets. If no FEC group is currently
312 // open, this method flushes current open packet and then turns FEC on.
313 void MaybeStartFecProtection();
314
310 // Turn on FEC protection for subsequently created packets. FEC should be 315 // Turn on FEC protection for subsequently created packets. FEC should be
311 // enabled first (max_packets_per_fec_group should be non-zero) for FEC 316 // enabled first (max_packets_per_fec_group should be non-zero) for FEC
312 // protection to start. 317 // protection to start.
313 void StartFecProtectingPackets(); 318 void StartFecProtectingPackets();
314 319
315 // Turn off FEC protection for subsequently created packets. If the creator 320 // Turn off FEC protection for subsequently created packets. If the creator
316 // has any open FEC group, call will fail. It is the caller's responsibility 321 // has any open FEC group, call will fail. It is the caller's responsibility
317 // to flush out FEC packets in generation, and to verify with ShouldSendFec() 322 // to flush out FEC packets in generation, and to verify with ShouldSendFec()
318 // that there is no open FEC group. 323 // that there is no open FEC group.
319 void StopFecProtectingPackets(); 324 void StopFecProtectingPackets();
320 325
321 // Resets (closes) the FEC group. This method should only be called on a 326 // Resets (closes) the FEC group. This method should only be called on a
322 // packet boundary. 327 // packet boundary.
323 void ResetFecGroup(); 328 void ResetFecGroup();
324 329
325 // Packetize FEC data. All frames must fit into a single packet. Also, sets 330 // Packetize FEC data. All frames must fit into a single packet. Also, sets
326 // the entropy hash of the serialized packet to a random bool and returns 331 // the entropy hash of the serialized packet to a random bool and returns
327 // that value as a member of SerializedPacket. 332 // that value as a member of SerializedPacket.
328 // Fails if |buffer_len| isn't long enough for the encrypted packet. 333 // Fails if |buffer_len| isn't long enough for the encrypted packet.
329 SerializedPacket SerializeFec(char* buffer, size_t buffer_len); 334 SerializedPacket SerializeFec(char* buffer, size_t buffer_len);
330 335
331 // Does not own this delegate. 336 // Does not own this delegate.
332 DelegateInterface* delegate_; 337 DelegateInterface* delegate_;
333 QuicConnectionId connection_id_; 338 QuicConnectionId connection_id_;
334 EncryptionLevel encryption_level_; 339 EncryptionLevel encryption_level_;
335 QuicFramer* framer_; 340 QuicFramer* framer_;
336 scoped_ptr<QuicRandomBoolSource> random_bool_source_; 341 scoped_ptr<QuicRandomBoolSource> random_bool_source_;
337 QuicPacketNumber packet_number_; 342 QuicPacketNumber packet_number_;
338 // True when creator is requested to turn on FEC protection. False otherwise. 343 // True when creator is requested to turn on FEC protection. False otherwise.
339 // There could be a time difference between should_fec_protect_ is true/false 344 // There is a time difference between should_fec_protect_next_packet is
340 // and FEC is actually turned on/off (e.g., The creator may have an open FEC 345 // true/false and FEC is actually turned on/off (e.g., The creator may have an
341 // group even if this variable is false). 346 // open FEC group even if this variable is false).
342 bool should_fec_protect_; 347 bool should_fec_protect_next_packet_;
343 // If true, any created packets will be FEC protected. 348 // If true, any created packets will be FEC protected.
344 // TODO(fayang): Combine should_fec_protect_ and fec_protect_ to one variable. 349 // TODO(fayang): Combine should_fec_protect_next_packet and fec_protect_ to
350 // one variable.
345 bool fec_protect_; 351 bool fec_protect_;
346 scoped_ptr<QuicFecGroup> fec_group_; 352 scoped_ptr<QuicFecGroup> fec_group_;
347 // Controls whether protocol version should be included while serializing the 353 // Controls whether protocol version should be included while serializing the
348 // packet. 354 // packet.
349 bool send_version_in_packet_; 355 bool send_version_in_packet_;
350 // Maximum length including headers and encryption (UDP payload length.) 356 // Maximum length including headers and encryption (UDP payload length.)
351 QuicByteCount max_packet_length_; 357 QuicByteCount max_packet_length_;
352 // 0 indicates FEC is disabled. 358 // 0 indicates FEC is disabled.
353 size_t max_packets_per_fec_group_; 359 size_t max_packets_per_fec_group_;
354 // Length of connection_id to send over the wire. 360 // Length of connection_id to send over the wire.
(...skipping 23 matching lines...) Expand all
378 // The multiplication factor for FEC timeout based on RTT. 384 // The multiplication factor for FEC timeout based on RTT.
379 // TODO(rtenneti): Delete this code after the 0.25 RTT FEC experiment. 385 // TODO(rtenneti): Delete this code after the 0.25 RTT FEC experiment.
380 float rtt_multiplier_for_fec_timeout_; 386 float rtt_multiplier_for_fec_timeout_;
381 387
382 DISALLOW_COPY_AND_ASSIGN(QuicPacketCreator); 388 DISALLOW_COPY_AND_ASSIGN(QuicPacketCreator);
383 }; 389 };
384 390
385 } // namespace net 391 } // namespace net
386 392
387 #endif // NET_QUIC_QUIC_PACKET_CREATOR_H_ 393 #endif // NET_QUIC_QUIC_PACKET_CREATOR_H_
OLDNEW
« no previous file with comments | « no previous file | net/quic/quic_packet_creator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698