Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / net / quic / quic_connection_logger.h
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 OnCongestionFeedbackFrame(
55       const QuicCongestionFeedbackFrame& 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;
70
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);
79
80  private:
81   friend class test::QuicConnectionLoggerPeer;
82
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;
116
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 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   // The number of times that OnPacketHeader was called.
133   // If the network replicates packets, then this number may be slightly
134   // different from the real number of distinct packets received.
135   QuicPacketSequenceNumber num_packets_received_;
136   // Number of times a truncated ACK frame was sent.
137   size_t num_truncated_acks_sent_;
138   // Number of times a truncated ACK frame was received.
139   size_t num_truncated_acks_received_;
140   // The kCADR value provided by the server in ServerHello.
141   IPEndPoint local_address_from_shlo_;
142   // The first local address from which a packet was received.
143   IPEndPoint local_address_from_self_;
144   // Count of the number of frames received.
145   int num_frames_received_;
146   // Count of the number of duplicate frames received.
147   int num_duplicate_frames_received_;
148   // Count of the number of packets received with incorrect connection IDs.
149   int num_incorrect_connection_ids_;
150   // Count of the number of undecryptable packets received.
151   int num_undecryptable_packets_;
152   // Count of the number of duplicate packets received.
153   int num_duplicate_packets_;
154   // Count of the number of BLOCKED frames received.
155   int num_blocked_frames_received_;
156   // Count of the number of BLOCKED frames sent.
157   int num_blocked_frames_sent_;
158   // Vector of inital packets status' indexed by packet sequence numbers, where
159   // false means never received.  Zero is not a valid packet sequence number, so
160   // that offset is never used, and we'll track 150 packets.
161   std::bitset<151> received_packets_;
162   // Vector to indicate which of the initial 150 received packets turned out to
163   // contain solo ACK frames.  An element is true iff an ACK frame was in the
164   // corresponding packet, and there was very little else.
165   std::bitset<151> received_acks_;
166   // The available type of connection (WiFi, 3G, etc.) when connection was first
167   // used.
168   const char* const connection_description_;
169
170   DISALLOW_COPY_AND_ASSIGN(QuicConnectionLogger);
171 };
172
173 }  // namespace net
174
175 #endif  // NET_QUIC_QUIC_CONNECTION_LOGGER_H_