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