1 // Copyright (c) 2018 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_TOOLS_QUIC_TCP_LIKE_TRACE_CONVERTER_H_ 6 #define QUICHE_QUIC_TOOLS_QUIC_TCP_LIKE_TRACE_CONVERTER_H_ 7 8 #include <vector> 9 10 #include "absl/container/flat_hash_map.h" 11 #include "quiche/quic/core/frames/quic_stream_frame.h" 12 #include "quiche/quic/core/quic_interval.h" 13 #include "quiche/quic/core/quic_interval_set.h" 14 #include "quiche/quic/core/quic_types.h" 15 16 namespace quic { 17 18 // This converter converts sent QUIC frames to connection byte offset (just like 19 // TCP byte sequence number). 20 class QuicTcpLikeTraceConverter { 21 public: 22 // StreamOffsetSegment stores a stream offset range which has contiguous 23 // connection offset. 24 struct StreamOffsetSegment { 25 StreamOffsetSegment(); 26 StreamOffsetSegment(QuicStreamOffset stream_offset, 27 uint64_t connection_offset, QuicByteCount data_length); 28 29 QuicInterval<QuicStreamOffset> stream_data; 30 uint64_t connection_offset; 31 }; 32 33 QuicTcpLikeTraceConverter(); 34 QuicTcpLikeTraceConverter(const QuicTcpLikeTraceConverter& other) = delete; 35 QuicTcpLikeTraceConverter(QuicTcpLikeTraceConverter&& other) = delete; 36 ~QuicTcpLikeTraceConverter()37 ~QuicTcpLikeTraceConverter() {} 38 39 // Called when a crypto frame is sent. Returns the corresponding connection 40 // offsets. 41 QuicIntervalSet<uint64_t> OnCryptoFrameSent(EncryptionLevel level, 42 QuicStreamOffset offset, 43 QuicByteCount data_length); 44 45 // Called when a stream frame is sent. Returns the corresponding connection 46 // offsets. 47 QuicIntervalSet<uint64_t> OnStreamFrameSent(QuicStreamId stream_id, 48 QuicStreamOffset offset, 49 QuicByteCount data_length, 50 bool fin); 51 52 // Called when a control frame is sent. Returns the corresponding connection 53 // offsets. 54 QuicInterval<uint64_t> OnControlFrameSent(QuicControlFrameId control_frame_id, 55 QuicByteCount control_frame_length); 56 57 private: 58 struct StreamInfo { 59 StreamInfo(); 60 61 // Stores contiguous connection offset pieces. 62 std::vector<StreamOffsetSegment> segments; 63 // Indicates whether fin has been sent. 64 bool fin; 65 }; 66 67 // Called when frame with |offset|, |data_length| and |fin| has been sent. 68 // Update |info| and returns connection offsets. 69 QuicIntervalSet<uint64_t> OnFrameSent(QuicStreamOffset offset, 70 QuicByteCount data_length, bool fin, 71 StreamInfo* info); 72 73 StreamInfo crypto_frames_info_[NUM_ENCRYPTION_LEVELS]; 74 absl::flat_hash_map<QuicStreamId, StreamInfo> streams_info_; 75 absl::flat_hash_map<QuicControlFrameId, QuicInterval<uint64_t>> 76 control_frames_info_; 77 78 QuicControlFrameId largest_observed_control_frame_id_; 79 80 uint64_t connection_offset_; 81 }; 82 83 } // namespace quic 84 85 #endif // QUICHE_QUIC_TOOLS_QUIC_TCP_LIKE_TRACE_CONVERTER_H_ 86