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