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