Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 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 | |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 8 | #include <bitset> |
| 9 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 10 | #include "net/base/ip_endpoint.h" |
Ben Murdoch | 0529e5d | 2014-04-24 10:50:13 +0100 | [diff] [blame] | 11 | #include "net/base/net_log.h" |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 12 | #include "net/base/network_change_notifier.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 13 | #include "net/quic/quic_connection.h" |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 14 | #include "net/quic/quic_protocol.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 15 | |
| 16 | namespace net { |
| 17 | |
Torne (Richard Coles) | 3551c9c | 2013-08-23 16:39:15 +0100 | [diff] [blame] | 18 | class CryptoHandshakeMessage; |
Torne (Richard Coles) | 5f1c943 | 2014-08-12 13:47:38 +0100 | [diff] [blame] | 19 | class CertVerifyResult; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 20 | |
| 21 | // This class is a debug visitor of a QuicConnection which logs |
| 22 | // events to |net_log|. |
| 23 | class NET_EXPORT_PRIVATE QuicConnectionLogger |
Torne (Richard Coles) | 46d4c2b | 2014-06-09 12:00:27 +0100 | [diff] [blame] | 24 | : public QuicConnectionDebugVisitor { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 25 | public: |
| 26 | explicit QuicConnectionLogger(const BoundNetLog& net_log); |
| 27 | |
| 28 | virtual ~QuicConnectionLogger(); |
| 29 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 30 | // QuicPacketGenerator::DebugDelegateInterface |
| 31 | virtual void OnFrameAddedToPacket(const QuicFrame& frame) OVERRIDE; |
| 32 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 33 | // QuicConnectionDebugVisitorInterface |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 34 | virtual void OnPacketSent(QuicPacketSequenceNumber sequence_number, |
| 35 | EncryptionLevel level, |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 36 | TransmissionType transmission_type, |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 37 | const QuicEncryptedPacket& packet, |
Torne (Richard Coles) | 4e180b6 | 2013-10-18 15:46:22 +0100 | [diff] [blame] | 38 | WriteResult result) OVERRIDE; |
Torne (Richard Coles) | 3551c9c | 2013-08-23 16:39:15 +0100 | [diff] [blame] | 39 | virtual void OnPacketRetransmitted( |
| 40 | QuicPacketSequenceNumber old_sequence_number, |
| 41 | QuicPacketSequenceNumber new_sequence_number) OVERRIDE; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 42 | virtual void OnPacketReceived(const IPEndPoint& self_address, |
| 43 | const IPEndPoint& peer_address, |
| 44 | const QuicEncryptedPacket& packet) OVERRIDE; |
Ben Murdoch | 558790d | 2013-07-30 15:19:42 +0100 | [diff] [blame] | 45 | virtual void OnProtocolVersionMismatch(QuicVersion version) OVERRIDE; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 46 | virtual void OnPacketHeader(const QuicPacketHeader& header) OVERRIDE; |
| 47 | virtual void OnStreamFrame(const QuicStreamFrame& frame) OVERRIDE; |
| 48 | virtual void OnAckFrame(const QuicAckFrame& frame) OVERRIDE; |
| 49 | virtual void OnCongestionFeedbackFrame( |
| 50 | const QuicCongestionFeedbackFrame& frame) OVERRIDE; |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 51 | virtual void OnStopWaitingFrame(const QuicStopWaitingFrame& frame) OVERRIDE; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 52 | virtual void OnRstStreamFrame(const QuicRstStreamFrame& frame) OVERRIDE; |
| 53 | virtual void OnConnectionCloseFrame( |
| 54 | const QuicConnectionCloseFrame& frame) OVERRIDE; |
Torne (Richard Coles) | f8ee788 | 2014-06-20 14:52:04 +0100 | [diff] [blame] | 55 | virtual void OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) OVERRIDE; |
| 56 | virtual void OnBlockedFrame(const QuicBlockedFrame& frame) OVERRIDE; |
| 57 | virtual void OnGoAwayFrame(const QuicGoAwayFrame& frame) OVERRIDE; |
| 58 | virtual void OnPingFrame(const QuicPingFrame& frame) OVERRIDE; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 59 | virtual void OnPublicResetPacket( |
| 60 | const QuicPublicResetPacket& packet) OVERRIDE; |
| 61 | virtual void OnVersionNegotiationPacket( |
| 62 | const QuicVersionNegotiationPacket& packet) OVERRIDE; |
| 63 | virtual void OnRevivedPacket(const QuicPacketHeader& revived_header, |
| 64 | base::StringPiece payload) OVERRIDE; |
Torne (Richard Coles) | 6e8cce6 | 2014-08-19 13:00:08 +0100 | [diff] [blame^] | 65 | virtual void OnConnectionClosed(QuicErrorCode error, bool from_peer) OVERRIDE; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 66 | |
Torne (Richard Coles) | 3551c9c | 2013-08-23 16:39:15 +0100 | [diff] [blame] | 67 | void OnCryptoHandshakeMessageReceived( |
| 68 | const CryptoHandshakeMessage& message); |
| 69 | void OnCryptoHandshakeMessageSent( |
| 70 | const CryptoHandshakeMessage& message); |
Torne (Richard Coles) | d0247b1 | 2013-09-19 22:36:51 +0100 | [diff] [blame] | 71 | void OnSuccessfulVersionNegotiation(const QuicVersion& version); |
Ben Murdoch | c5cede9 | 2014-04-10 11:22:14 +0100 | [diff] [blame] | 72 | void UpdateReceivedFrameCounts(QuicStreamId stream_id, |
| 73 | int num_frames_received, |
| 74 | int num_duplicate_frames_received); |
Torne (Richard Coles) | 5f1c943 | 2014-08-12 13:47:38 +0100 | [diff] [blame] | 75 | void OnCertificateVerified(const CertVerifyResult& result); |
Torne (Richard Coles) | 3551c9c | 2013-08-23 16:39:15 +0100 | [diff] [blame] | 76 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 77 | private: |
Torne (Richard Coles) | 23730a6 | 2014-03-21 14:25:57 +0000 | [diff] [blame] | 78 | // Do a factory get for a histogram for recording data, about individual |
| 79 | // packet sequence numbers, that was gathered in the vectors |
| 80 | // received_packets_ and received_acks_. |statistic_name| identifies which |
| 81 | // element of data is recorded, and is used to form the histogram name. |
| 82 | base::HistogramBase* GetPacketSequenceNumberHistogram( |
| 83 | const char* statistic_name) const; |
| 84 | // Do a factory get for a histogram to record a 6-packet loss-sequence as a |
| 85 | // sample. The histogram will record the 64 distinct possible combinations. |
| 86 | // |which_6| is used to adjust the name of the histogram to distinguish the |
| 87 | // first 6 packets in a connection, vs. some later 6 packets. |
| 88 | base::HistogramBase* Get6PacketHistogram(const char* which_6) const; |
| 89 | // Do a factory get for a histogram to record cumulative stats across a 21 |
| 90 | // packet sequence. |which_21| is used to adjust the name of the histogram |
| 91 | // to distinguish the first 21 packets' loss data, vs. some later 21 packet |
| 92 | // sequences' loss data. |
| 93 | base::HistogramBase* Get21CumulativeHistogram(const char* which_21) const; |
| 94 | // Add samples associated with a |bit_mask_of_packets| to the given histogram |
| 95 | // that was provided by Get21CumulativeHistogram(). The LSB of that mask |
| 96 | // corresponds to the oldest packet sequence number in the series of packets, |
| 97 | // and the bit in the 2^20 position corresponds to the most recently received |
| 98 | // packet. Of the maximum of 21 bits that are valid (correspond to packets), |
| 99 | // only the most significant |valid_bits_in_mask| are processed. |
| 100 | // A bit value of 0 indicates that a packet was never received, and a 1 |
| 101 | // indicates the packet was received. |
| 102 | static void AddTo21CumulativeHistogram(base::HistogramBase* histogram, |
| 103 | int bit_mask_of_packets, |
| 104 | int valid_bits_in_mask); |
| 105 | // For connections longer than 21 received packets, this call will calculate |
| 106 | // the overall packet loss rate, and record it into a histogram. |
| 107 | void RecordAggregatePacketLossRate() const; |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 108 | // At destruction time, this records results of |pacaket_received_| into |
| 109 | // histograms for specific connection types. |
Torne (Richard Coles) | 23730a6 | 2014-03-21 14:25:57 +0000 | [diff] [blame] | 110 | void RecordLossHistograms() const; |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 111 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 112 | BoundNetLog net_log_; |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 113 | // The last packet sequence number received. |
| 114 | QuicPacketSequenceNumber last_received_packet_sequence_number_; |
Torne (Richard Coles) | 23730a6 | 2014-03-21 14:25:57 +0000 | [diff] [blame] | 115 | // The size of the most recently received packet. |
| 116 | size_t last_received_packet_size_; |
| 117 | // The largest packet sequence number received. In the case where a packet is |
| 118 | // received late (out of order), this value will not be updated. |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 119 | QuicPacketSequenceNumber largest_received_packet_sequence_number_; |
| 120 | // The largest packet sequence number which the peer has failed to |
| 121 | // receive, according to the missing packet set in their ack frames. |
| 122 | QuicPacketSequenceNumber largest_received_missing_packet_sequence_number_; |
| 123 | // Number of times that the current received packet sequence number is |
| 124 | // smaller than the last received packet sequence number. |
Torne (Richard Coles) | 23730a6 | 2014-03-21 14:25:57 +0000 | [diff] [blame] | 125 | size_t num_out_of_order_received_packets_; |
| 126 | // The number of times that OnPacketHeader was called. |
| 127 | // If the network replicates packets, then this number may be slightly |
| 128 | // different from the real number of distinct packets received. |
| 129 | QuicPacketSequenceNumber num_packets_received_; |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 130 | // Number of times a truncated ACK frame was sent. |
| 131 | size_t num_truncated_acks_sent_; |
| 132 | // Number of times a truncated ACK frame was received. |
| 133 | size_t num_truncated_acks_received_; |
| 134 | // The kCADR value provided by the server in ServerHello. |
Torne (Richard Coles) | 010d83a | 2014-05-14 12:12:37 +0100 | [diff] [blame] | 135 | IPEndPoint local_address_from_shlo_; |
| 136 | // The first local address from which a packet was received. |
| 137 | IPEndPoint local_address_from_self_; |
Ben Murdoch | c5cede9 | 2014-04-10 11:22:14 +0100 | [diff] [blame] | 138 | // Count of the number of frames received. |
| 139 | int num_frames_received_; |
| 140 | // Count of the number of duplicate frames received. |
| 141 | int num_duplicate_frames_received_; |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 142 | // Vector of inital packets status' indexed by packet sequence numbers, where |
| 143 | // false means never received. Zero is not a valid packet sequence number, so |
Torne (Richard Coles) | 23730a6 | 2014-03-21 14:25:57 +0000 | [diff] [blame] | 144 | // that offset is never used, and we'll track 150 packets. |
| 145 | std::bitset<151> received_packets_; |
| 146 | // Vector to indicate which of the initial 150 received packets turned out to |
| 147 | // contain solo ACK frames. An element is true iff an ACK frame was in the |
| 148 | // corresponding packet, and there was very little else. |
| 149 | std::bitset<151> received_acks_; |
Torne (Richard Coles) | a140131 | 2014-03-18 10:20:56 +0000 | [diff] [blame] | 150 | // The available type of connection (WiFi, 3G, etc.) when connection was first |
| 151 | // used. |
| 152 | const char* const connection_description_; |
Ben Murdoch | 0529e5d | 2014-04-24 10:50:13 +0100 | [diff] [blame] | 153 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 154 | DISALLOW_COPY_AND_ASSIGN(QuicConnectionLogger); |
| 155 | }; |
| 156 | |
| 157 | } // namespace net |
| 158 | |
| 159 | #endif // NET_QUIC_QUIC_CONNECTION_LOGGER_H_ |