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