blob: 432980531be806dc0919d32abed05916fefab3a2 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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 "net/third_party/quiche/src/quic/core/frames/quic_stream_frame.h"
11#include "net/third_party/quiche/src/quic/core/quic_interval.h"
12#include "net/third_party/quiche/src/quic/core/quic_interval_set.h"
13#include "net/third_party/quiche/src/quic/core/quic_types.h"
14#include "net/third_party/quiche/src/quic/platform/api/quic_containers.h"
15
16namespace quic {
17
18// This converter converts sent QUIC frames to connection byte offset (just like
19// TCP byte sequence number).
20class 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,
28 QuicByteCount data_length);
29
30 QuicInterval<QuicStreamOffset> stream_data;
31 uint64_t connection_offset;
32 };
33
34 QuicTcpLikeTraceConverter();
35 QuicTcpLikeTraceConverter(const QuicTcpLikeTraceConverter& other) = delete;
36 QuicTcpLikeTraceConverter(QuicTcpLikeTraceConverter&& other) = delete;
37
38 ~QuicTcpLikeTraceConverter() {}
39
40 // Called when a stream frame is sent. Returns the corresponding connection
41 // offsets.
42 QuicIntervalSet<uint64_t> OnStreamFrameSent(QuicStreamId stream_id,
43 QuicStreamOffset offset,
44 QuicByteCount data_length,
45 bool fin);
46
47 // Called when a control frame is sent. Returns the corresponding connection
48 // offsets.
49 QuicInterval<uint64_t> OnControlFrameSent(QuicControlFrameId control_frame_id,
50 QuicByteCount control_frame_length);
51
52 private:
53 struct StreamInfo {
54 StreamInfo();
55
56 // Stores contiguous connection offset pieces.
57 std::vector<StreamOffsetSegment> segments;
58 // Indicates whether fin has been sent.
59 bool fin;
60 };
61
62 QuicUnorderedMap<QuicStreamId, StreamInfo> streams_info_;
63 QuicUnorderedMap<QuicControlFrameId, QuicInterval<uint64_t>>
64 control_frames_info_;
65
66 QuicControlFrameId largest_observed_control_frame_id_;
67
68 uint64_t connection_offset_;
69};
70
71} // namespace quic
72
73#endif // QUICHE_QUIC_TOOLS_QUIC_TCP_LIKE_TRACE_CONVERTER_H_