Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / net / quic / quic_connection_logger.h
blob1d0e62f93ea5af70e1836c59a20081293ecd541e
1 // Copyright (c) 2013 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.
5 #ifndef NET_QUIC_QUIC_CONNECTION_LOGGER_H_
6 #define NET_QUIC_QUIC_CONNECTION_LOGGER_H_
8 #include <bitset>
10 #include "net/base/ip_endpoint.h"
11 #include "net/base/network_change_notifier.h"
12 #include "net/log/net_log.h"
13 #include "net/quic/quic_connection.h"
14 #include "net/quic/quic_protocol.h"
15 #include "net/quic/quic_spdy_session.h"
17 namespace net {
18 namespace test {
19 class QuicConnectionLoggerPeer;
20 } // namespace test
22 class CryptoHandshakeMessage;
23 class CertVerifyResult;
25 // This class is a debug visitor of a QuicConnection which logs
26 // events to |net_log|.
27 class NET_EXPORT_PRIVATE QuicConnectionLogger
28 : public QuicConnectionDebugVisitor {
29 public:
30 QuicConnectionLogger(QuicSpdySession* session,
31 const char* const connection_description,
32 const BoundNetLog& net_log);
34 ~QuicConnectionLogger() override;
36 // QuicPacketGenerator::DebugDelegateInterface
37 void OnFrameAddedToPacket(const QuicFrame& frame) override;
39 // QuicConnectionDebugVisitorInterface
40 void OnPacketSent(const SerializedPacket& serialized_packet,
41 QuicPacketNumber original_packet_number,
42 EncryptionLevel level,
43 TransmissionType transmission_type,
44 const QuicEncryptedPacket& packet,
45 QuicTime sent_time) override;
46 void OnPacketReceived(const IPEndPoint& self_address,
47 const IPEndPoint& peer_address,
48 const QuicEncryptedPacket& packet) override;
49 void OnUnauthenticatedHeader(const QuicPacketHeader& header) override;
50 void OnIncorrectConnectionId(QuicConnectionId connection_id) override;
51 void OnUndecryptablePacket() override;
52 void OnDuplicatePacket(QuicPacketNumber packet_number) override;
53 void OnProtocolVersionMismatch(QuicVersion version) override;
54 void OnPacketHeader(const QuicPacketHeader& header) override;
55 void OnStreamFrame(const QuicStreamFrame& frame) override;
56 void OnAckFrame(const QuicAckFrame& frame) override;
57 void OnStopWaitingFrame(const QuicStopWaitingFrame& frame) override;
58 void OnRstStreamFrame(const QuicRstStreamFrame& frame) override;
59 void OnConnectionCloseFrame(const QuicConnectionCloseFrame& frame) override;
60 void OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override;
61 void OnBlockedFrame(const QuicBlockedFrame& frame) override;
62 void OnGoAwayFrame(const QuicGoAwayFrame& frame) override;
63 void OnPingFrame(const QuicPingFrame& frame) override;
64 void OnPublicResetPacket(const QuicPublicResetPacket& packet) override;
65 void OnVersionNegotiationPacket(
66 const QuicVersionNegotiationPacket& packet) override;
67 void OnRevivedPacket(const QuicPacketHeader& revived_header,
68 base::StringPiece payload) override;
69 void OnConnectionClosed(QuicErrorCode error, bool from_peer) override;
70 void OnSuccessfulVersionNegotiation(const QuicVersion& version) override;
72 void OnCryptoHandshakeMessageReceived(
73 const CryptoHandshakeMessage& message);
74 void OnCryptoHandshakeMessageSent(
75 const CryptoHandshakeMessage& message);
76 void UpdateReceivedFrameCounts(QuicStreamId stream_id,
77 int num_frames_received,
78 int num_duplicate_frames_received);
79 void OnCertificateVerified(const CertVerifyResult& result);
81 // Returns connection's overall packet loss rate in fraction.
82 float ReceivedPacketLossRate() const;
84 private:
85 friend class test::QuicConnectionLoggerPeer;
87 // Do a factory get for a histogram for recording data, about individual
88 // packet numbers, that was gathered in the vectors
89 // received_packets_ and received_acks_. |statistic_name| identifies which
90 // element of data is recorded, and is used to form the histogram name.
91 base::HistogramBase* GetPacketNumberHistogram(
92 const char* statistic_name) const;
93 // Do a factory get for a histogram to record a 6-packet loss-sequence as a
94 // sample. The histogram will record the 64 distinct possible combinations.
95 // |which_6| is used to adjust the name of the histogram to distinguish the
96 // first 6 packets in a connection, vs. some later 6 packets.
97 base::HistogramBase* Get6PacketHistogram(const char* which_6) const;
98 // Do a factory get for a histogram to record cumulative stats across a 21
99 // packet sequence. |which_21| is used to adjust the name of the histogram
100 // to distinguish the first 21 packets' loss data, vs. some later 21 packet
101 // sequences' loss data.
102 base::HistogramBase* Get21CumulativeHistogram(const char* which_21) const;
103 // Add samples associated with a |bit_mask_of_packets| to the given histogram
104 // that was provided by Get21CumulativeHistogram(). The LSB of that mask
105 // corresponds to the oldest packet number in the series of packets,
106 // and the bit in the 2^20 position corresponds to the most recently received
107 // packet. Of the maximum of 21 bits that are valid (correspond to packets),
108 // only the most significant |valid_bits_in_mask| are processed.
109 // A bit value of 0 indicates that a packet was never received, and a 1
110 // indicates the packet was received.
111 static void AddTo21CumulativeHistogram(base::HistogramBase* histogram,
112 int bit_mask_of_packets,
113 int valid_bits_in_mask);
114 // For connections longer than 21 received packets, this call will calculate
115 // the overall packet loss rate, and record it into a histogram.
116 void RecordAggregatePacketLossRate() const;
117 // At destruction time, this records results of |pacaket_received_| into
118 // histograms for specific connection types.
119 void RecordLossHistograms() const;
121 BoundNetLog net_log_;
122 QuicSpdySession* session_; // Unowned.
123 // The last packet number received.
124 QuicPacketNumber last_received_packet_number_;
125 // The size of the most recently received packet.
126 size_t last_received_packet_size_;
127 // The size of the previously received packet.
128 size_t previous_received_packet_size_;
129 // The largest packet number received. In the case where a packet is
130 // received late (out of order), this value will not be updated.
131 QuicPacketNumber largest_received_packet_number_;
132 // The largest packet number which the peer has failed to
133 // receive, according to the missing packet set in their ack frames.
134 QuicPacketNumber largest_received_missing_packet_number_;
135 // Number of times that the current received packet number is
136 // smaller than the last received packet number.
137 size_t num_out_of_order_received_packets_;
138 // Number of times that the current received packet number is
139 // smaller than the last received packet number and where the
140 // size of the current packet is larger than the size of the previous
141 // packet.
142 size_t num_out_of_order_large_received_packets_;
143 // The number of times that OnPacketHeader was called.
144 // If the network replicates packets, then this number may be slightly
145 // different from the real number of distinct packets received.
146 QuicPacketCount num_packets_received_;
147 // Number of times a truncated ACK frame was sent.
148 size_t num_truncated_acks_sent_;
149 // Number of times a truncated ACK frame was received.
150 size_t num_truncated_acks_received_;
151 // The kCADR value provided by the server in ServerHello.
152 IPEndPoint local_address_from_shlo_;
153 // The first local address from which a packet was received.
154 IPEndPoint local_address_from_self_;
155 // Count of the number of frames received.
156 int num_frames_received_;
157 // Count of the number of duplicate frames received.
158 int num_duplicate_frames_received_;
159 // Count of the number of packets received with incorrect connection IDs.
160 int num_incorrect_connection_ids_;
161 // Count of the number of undecryptable packets received.
162 int num_undecryptable_packets_;
163 // Count of the number of duplicate packets received.
164 int num_duplicate_packets_;
165 // Count of the number of BLOCKED frames received.
166 int num_blocked_frames_received_;
167 // Count of the number of BLOCKED frames sent.
168 int num_blocked_frames_sent_;
169 // Vector of inital packets status' indexed by packet numbers, where
170 // false means never received. Zero is not a valid packet number, so
171 // that offset is never used, and we'll track 150 packets.
172 std::bitset<151> received_packets_;
173 // Vector to indicate which of the initial 150 received packets turned out to
174 // contain solo ACK frames. An element is true iff an ACK frame was in the
175 // corresponding packet, and there was very little else.
176 std::bitset<151> received_acks_;
177 // The available type of connection (WiFi, 3G, etc.) when connection was first
178 // used.
179 const char* const connection_description_;
181 DISALLOW_COPY_AND_ASSIGN(QuicConnectionLogger);
184 } // namespace net
186 #endif // NET_QUIC_QUIC_CONNECTION_LOGGER_H_