Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / net / quic / quic_connection_logger.h
blobafb60435a3dd9f83e762088c5e96d51df0e76a87
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/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"
16 namespace net {
18 class CryptoHandshakeMessage;
19 class CertVerifyResult;
21 // This class is a debug visitor of a QuicConnection which logs
22 // events to |net_log|.
23 class NET_EXPORT_PRIVATE QuicConnectionLogger
24 : public QuicConnectionDebugVisitor {
25 public:
26 explicit QuicConnectionLogger(const BoundNetLog& net_log);
28 virtual ~QuicConnectionLogger();
30 // QuicPacketGenerator::DebugDelegateInterface
31 virtual void OnFrameAddedToPacket(const QuicFrame& frame) OVERRIDE;
33 // QuicConnectionDebugVisitorInterface
34 virtual void OnPacketSent(QuicPacketSequenceNumber sequence_number,
35 EncryptionLevel level,
36 TransmissionType transmission_type,
37 const QuicEncryptedPacket& packet,
38 WriteResult result) OVERRIDE;
39 virtual void OnPacketRetransmitted(
40 QuicPacketSequenceNumber old_sequence_number,
41 QuicPacketSequenceNumber new_sequence_number) OVERRIDE;
42 virtual void OnPacketReceived(const IPEndPoint& self_address,
43 const IPEndPoint& peer_address,
44 const QuicEncryptedPacket& packet) OVERRIDE;
45 virtual void OnIncorrectConnectionId(
46 QuicConnectionId connection_id) OVERRIDE;
47 virtual void OnUndecryptablePacket() OVERRIDE;
48 virtual void OnDuplicatePacket(QuicPacketSequenceNumber sequence_number)
49 OVERRIDE;
50 virtual void OnProtocolVersionMismatch(QuicVersion version) OVERRIDE;
51 virtual void OnPacketHeader(const QuicPacketHeader& header) OVERRIDE;
52 virtual void OnStreamFrame(const QuicStreamFrame& frame) OVERRIDE;
53 virtual void OnAckFrame(const QuicAckFrame& frame) OVERRIDE;
54 virtual void OnCongestionFeedbackFrame(
55 const QuicCongestionFeedbackFrame& frame) OVERRIDE;
56 virtual void OnStopWaitingFrame(const QuicStopWaitingFrame& frame) OVERRIDE;
57 virtual void OnRstStreamFrame(const QuicRstStreamFrame& frame) OVERRIDE;
58 virtual void OnConnectionCloseFrame(
59 const QuicConnectionCloseFrame& frame) OVERRIDE;
60 virtual void OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) OVERRIDE;
61 virtual void OnBlockedFrame(const QuicBlockedFrame& frame) OVERRIDE;
62 virtual void OnGoAwayFrame(const QuicGoAwayFrame& frame) OVERRIDE;
63 virtual void OnPingFrame(const QuicPingFrame& frame) OVERRIDE;
64 virtual void OnPublicResetPacket(
65 const QuicPublicResetPacket& packet) OVERRIDE;
66 virtual void OnVersionNegotiationPacket(
67 const QuicVersionNegotiationPacket& packet) OVERRIDE;
68 virtual void OnRevivedPacket(const QuicPacketHeader& revived_header,
69 base::StringPiece payload) OVERRIDE;
70 virtual void OnConnectionClosed(QuicErrorCode error, bool from_peer) OVERRIDE;
72 void OnCryptoHandshakeMessageReceived(
73 const CryptoHandshakeMessage& message);
74 void OnCryptoHandshakeMessageSent(
75 const CryptoHandshakeMessage& message);
76 void OnSuccessfulVersionNegotiation(const QuicVersion& version);
77 void UpdateReceivedFrameCounts(QuicStreamId stream_id,
78 int num_frames_received,
79 int num_duplicate_frames_received);
80 void OnCertificateVerified(const CertVerifyResult& result);
82 private:
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 // The last packet sequence number received.
119 QuicPacketSequenceNumber last_received_packet_sequence_number_;
120 // The size of the most recently received packet.
121 size_t last_received_packet_size_;
122 // The largest packet sequence number received. In the case where a packet is
123 // received late (out of order), this value will not be updated.
124 QuicPacketSequenceNumber largest_received_packet_sequence_number_;
125 // The largest packet sequence number which the peer has failed to
126 // receive, according to the missing packet set in their ack frames.
127 QuicPacketSequenceNumber largest_received_missing_packet_sequence_number_;
128 // Number of times that the current received packet sequence number is
129 // smaller than the last received packet sequence number.
130 size_t num_out_of_order_received_packets_;
131 // The number of times that OnPacketHeader was called.
132 // If the network replicates packets, then this number may be slightly
133 // different from the real number of distinct packets received.
134 QuicPacketSequenceNumber num_packets_received_;
135 // Number of times a truncated ACK frame was sent.
136 size_t num_truncated_acks_sent_;
137 // Number of times a truncated ACK frame was received.
138 size_t num_truncated_acks_received_;
139 // The kCADR value provided by the server in ServerHello.
140 IPEndPoint local_address_from_shlo_;
141 // The first local address from which a packet was received.
142 IPEndPoint local_address_from_self_;
143 // Count of the number of frames received.
144 int num_frames_received_;
145 // Count of the number of duplicate frames received.
146 int num_duplicate_frames_received_;
147 // Count of the number of packets received with incorrect connection IDs.
148 int num_incorrect_connection_ids_;
149 // Count of the number of undecryptable packets received.
150 int num_undecryptable_packets_;
151 // Count of the number of duplicate packets received.
152 int num_duplicate_packets_;
153 // Vector of inital packets status' indexed by packet sequence numbers, where
154 // false means never received. Zero is not a valid packet sequence number, so
155 // that offset is never used, and we'll track 150 packets.
156 std::bitset<151> received_packets_;
157 // Vector to indicate which of the initial 150 received packets turned out to
158 // contain solo ACK frames. An element is true iff an ACK frame was in the
159 // corresponding packet, and there was very little else.
160 std::bitset<151> received_acks_;
161 // The available type of connection (WiFi, 3G, etc.) when connection was first
162 // used.
163 const char* const connection_description_;
165 DISALLOW_COPY_AND_ASSIGN(QuicConnectionLogger);
168 } // namespace net
170 #endif // NET_QUIC_QUIC_CONNECTION_LOGGER_H_