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_
10 #include "net/base/ip_endpoint.h"
11 #include "net/base/net_log.h"
12 #include "net/base/network_change_notifier.h"
13 #include "net/quic/quic_connection.h"
14 #include "net/quic/quic_protocol.h"
15 #include "net/quic/quic_session.h"
19 class QuicConnectionLoggerPeer
;
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
{
30 QuicConnectionLogger(QuicSession
* 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 QuicPacketSequenceNumber original_sequence_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 OnIncorrectConnectionId(QuicConnectionId connection_id
) override
;
50 void OnUndecryptablePacket() override
;
51 void OnDuplicatePacket(QuicPacketSequenceNumber sequence_number
) override
;
52 void OnProtocolVersionMismatch(QuicVersion version
) override
;
53 void OnPacketHeader(const QuicPacketHeader
& header
) override
;
54 void OnStreamFrame(const QuicStreamFrame
& frame
) override
;
55 void OnAckFrame(const QuicAckFrame
& frame
) override
;
56 void OnStopWaitingFrame(const QuicStopWaitingFrame
& frame
) override
;
57 void OnRstStreamFrame(const QuicRstStreamFrame
& frame
) override
;
58 void OnConnectionCloseFrame(const QuicConnectionCloseFrame
& frame
) override
;
59 void OnWindowUpdateFrame(const QuicWindowUpdateFrame
& frame
) override
;
60 void OnBlockedFrame(const QuicBlockedFrame
& frame
) override
;
61 void OnGoAwayFrame(const QuicGoAwayFrame
& frame
) override
;
62 void OnPingFrame(const QuicPingFrame
& frame
) override
;
63 void OnPublicResetPacket(const QuicPublicResetPacket
& packet
) override
;
64 void OnVersionNegotiationPacket(
65 const QuicVersionNegotiationPacket
& packet
) override
;
66 void OnRevivedPacket(const QuicPacketHeader
& revived_header
,
67 base::StringPiece payload
) override
;
68 void OnConnectionClosed(QuicErrorCode error
, bool from_peer
) override
;
69 void OnSuccessfulVersionNegotiation(const QuicVersion
& version
) override
;
71 void OnCryptoHandshakeMessageReceived(
72 const CryptoHandshakeMessage
& message
);
73 void OnCryptoHandshakeMessageSent(
74 const CryptoHandshakeMessage
& message
);
75 void UpdateReceivedFrameCounts(QuicStreamId stream_id
,
76 int num_frames_received
,
77 int num_duplicate_frames_received
);
78 void OnCertificateVerified(const CertVerifyResult
& result
);
81 friend class test::QuicConnectionLoggerPeer
;
83 // Do a factory get for a histogram for recording data, about individual
84 // packet sequence numbers, that was gathered in the vectors
85 // received_packets_ and received_acks_. |statistic_name| identifies which
86 // element of data is recorded, and is used to form the histogram name.
87 base::HistogramBase
* GetPacketSequenceNumberHistogram(
88 const char* statistic_name
) const;
89 // Do a factory get for a histogram to record a 6-packet loss-sequence as a
90 // sample. The histogram will record the 64 distinct possible combinations.
91 // |which_6| is used to adjust the name of the histogram to distinguish the
92 // first 6 packets in a connection, vs. some later 6 packets.
93 base::HistogramBase
* Get6PacketHistogram(const char* which_6
) const;
94 // Do a factory get for a histogram to record cumulative stats across a 21
95 // packet sequence. |which_21| is used to adjust the name of the histogram
96 // to distinguish the first 21 packets' loss data, vs. some later 21 packet
97 // sequences' loss data.
98 base::HistogramBase
* Get21CumulativeHistogram(const char* which_21
) const;
99 // Add samples associated with a |bit_mask_of_packets| to the given histogram
100 // that was provided by Get21CumulativeHistogram(). The LSB of that mask
101 // corresponds to the oldest packet sequence number in the series of packets,
102 // and the bit in the 2^20 position corresponds to the most recently received
103 // packet. Of the maximum of 21 bits that are valid (correspond to packets),
104 // only the most significant |valid_bits_in_mask| are processed.
105 // A bit value of 0 indicates that a packet was never received, and a 1
106 // indicates the packet was received.
107 static void AddTo21CumulativeHistogram(base::HistogramBase
* histogram
,
108 int bit_mask_of_packets
,
109 int valid_bits_in_mask
);
110 // For connections longer than 21 received packets, this call will calculate
111 // the overall packet loss rate, and record it into a histogram.
112 void RecordAggregatePacketLossRate() const;
113 // At destruction time, this records results of |pacaket_received_| into
114 // histograms for specific connection types.
115 void RecordLossHistograms() const;
117 BoundNetLog net_log_
;
118 QuicSession
* session_
; // Unowned.
119 // The last packet sequence number received.
120 QuicPacketSequenceNumber last_received_packet_sequence_number_
;
121 // The size of the most recently received packet.
122 size_t last_received_packet_size_
;
123 // The size of the previously received packet.
124 size_t previous_received_packet_size_
;
125 // The largest packet sequence number received. In the case where a packet is
126 // received late (out of order), this value will not be updated.
127 QuicPacketSequenceNumber largest_received_packet_sequence_number_
;
128 // The largest packet sequence number which the peer has failed to
129 // receive, according to the missing packet set in their ack frames.
130 QuicPacketSequenceNumber largest_received_missing_packet_sequence_number_
;
131 // Number of times that the current received packet sequence number is
132 // smaller than the last received packet sequence number.
133 size_t num_out_of_order_received_packets_
;
134 // Number of times that the current received packet sequence number is
135 // smaller than the last received packet sequence number and where the
136 // size of the current packet is larger than the size of the previous
138 size_t num_out_of_order_large_received_packets_
;
139 // The number of times that OnPacketHeader was called.
140 // If the network replicates packets, then this number may be slightly
141 // different from the real number of distinct packets received.
142 QuicPacketCount num_packets_received_
;
143 // Number of times a truncated ACK frame was sent.
144 size_t num_truncated_acks_sent_
;
145 // Number of times a truncated ACK frame was received.
146 size_t num_truncated_acks_received_
;
147 // The kCADR value provided by the server in ServerHello.
148 IPEndPoint local_address_from_shlo_
;
149 // The first local address from which a packet was received.
150 IPEndPoint local_address_from_self_
;
151 // Count of the number of frames received.
152 int num_frames_received_
;
153 // Count of the number of duplicate frames received.
154 int num_duplicate_frames_received_
;
155 // Count of the number of packets received with incorrect connection IDs.
156 int num_incorrect_connection_ids_
;
157 // Count of the number of undecryptable packets received.
158 int num_undecryptable_packets_
;
159 // Count of the number of duplicate packets received.
160 int num_duplicate_packets_
;
161 // Count of the number of BLOCKED frames received.
162 int num_blocked_frames_received_
;
163 // Count of the number of BLOCKED frames sent.
164 int num_blocked_frames_sent_
;
165 // Vector of inital packets status' indexed by packet sequence numbers, where
166 // false means never received. Zero is not a valid packet sequence number, so
167 // that offset is never used, and we'll track 150 packets.
168 std::bitset
<151> received_packets_
;
169 // Vector to indicate which of the initial 150 received packets turned out to
170 // contain solo ACK frames. An element is true iff an ACK frame was in the
171 // corresponding packet, and there was very little else.
172 std::bitset
<151> received_acks_
;
173 // The available type of connection (WiFi, 3G, etc.) when connection was first
175 const char* const connection_description_
;
177 DISALLOW_COPY_AND_ASSIGN(QuicConnectionLogger
);
182 #endif // NET_QUIC_QUIC_CONNECTION_LOGGER_H_