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.
5 #include "net/quic/quic_connection_logger.h"
8 #include "base/callback.h"
9 #include "base/string_number_conversions.h"
10 #include "base/values.h"
11 #include "net/base/net_log.h"
17 Value
* NetLogQuicPacketCallback(const IPEndPoint
* self_address
,
18 const IPEndPoint
* peer_address
,
20 NetLog::LogLevel
/* log_level */) {
21 DictionaryValue
* dict
= new DictionaryValue();
22 dict
->SetString("self_address", self_address
->ToString());
23 dict
->SetString("peer_address", peer_address
->ToString());
24 dict
->SetInteger("size", packet_size
);
28 Value
* NetLogQuicPacketHeaderCallback(const QuicPacketHeader
* header
,
29 NetLog::LogLevel
/* log_level */) {
30 DictionaryValue
* dict
= new DictionaryValue();
31 dict
->SetString("guid",
32 base::Uint64ToString(header
->public_header
.guid
));
33 dict
->SetInteger("reset_flag", header
->public_header
.reset_flag
);
34 dict
->SetInteger("version_flag", header
->public_header
.version_flag
);
35 dict
->SetString("packet_sequence_number",
36 base::Uint64ToString(header
->packet_sequence_number
));
37 dict
->SetInteger("entropy_flag", header
->entropy_flag
);
38 dict
->SetInteger("fec_flag", header
->fec_flag
);
39 dict
->SetInteger("fec_entropy_flag", header
->fec_entropy_flag
);
40 dict
->SetInteger("fec_group", header
->fec_group
);
44 Value
* NetLogQuicStreamFrameCallback(const QuicStreamFrame
* frame
,
45 NetLog::LogLevel
/* log_level */) {
46 DictionaryValue
* dict
= new DictionaryValue();
47 dict
->SetInteger("stream_id", frame
->stream_id
);
48 dict
->SetBoolean("fin", frame
->fin
);
49 dict
->SetString("offset", base::Uint64ToString(frame
->offset
));
50 dict
->SetInteger("length", frame
->data
.length());
54 Value
* NetLogQuicAckFrameCallback(const QuicAckFrame
* frame
,
55 NetLog::LogLevel
/* log_level */) {
56 DictionaryValue
* dict
= new DictionaryValue();
57 DictionaryValue
* sent_info
= new DictionaryValue();
58 dict
->Set("sent_info", sent_info
);
59 sent_info
->SetString("least_unacked",
60 base::Uint64ToString(frame
->sent_info
.least_unacked
));
61 DictionaryValue
* received_info
= new DictionaryValue();
62 dict
->Set("received_info", received_info
);
63 received_info
->SetString(
65 base::Uint64ToString(frame
->received_info
.largest_observed
));
66 ListValue
* missing
= new ListValue();
67 received_info
->Set("missing_packets", missing
);
68 const SequenceNumberSet
& missing_packets
=
69 frame
->received_info
.missing_packets
;
70 for (SequenceNumberSet::const_iterator it
= missing_packets
.begin();
71 it
!= missing_packets
.end(); ++it
) {
72 missing
->Append(new base::StringValue(base::Uint64ToString(*it
)));
77 Value
* NetLogQuicCongestionFeedbackFrameCallback(
78 const QuicCongestionFeedbackFrame
* frame
,
79 NetLog::LogLevel
/* log_level */) {
80 DictionaryValue
* dict
= new DictionaryValue();
81 switch (frame
->type
) {
83 dict
->SetString("type", "InterArrival");
84 dict
->SetInteger("accumulated_number_of_lost_packets",
85 frame
->inter_arrival
.accumulated_number_of_lost_packets
);
86 ListValue
* received
= new ListValue();
87 dict
->Set("received_packets", received
);
88 for (TimeMap::const_iterator it
=
89 frame
->inter_arrival
.received_packet_times
.begin();
90 it
!= frame
->inter_arrival
.received_packet_times
.end(); ++it
) {
91 std::string value
= base::Uint64ToString(it
->first
) + "@" +
92 base::Uint64ToString(it
->second
.ToDebuggingValue());
93 received
->Append(new base::StringValue(value
));
98 dict
->SetString("type", "FixRate");
99 dict
->SetInteger("bitrate_in_bytes_per_second",
100 frame
->fix_rate
.bitrate
.ToBytesPerSecond());
103 dict
->SetString("type", "TCP");
104 dict
->SetInteger("accumulated_number_of_lost_packets",
105 frame
->tcp
.accumulated_number_of_lost_packets
);
106 dict
->SetInteger("receive_window", frame
->tcp
.receive_window
);
113 Value
* NetLogQuicRstStreamFrameCallback(const QuicRstStreamFrame
* frame
,
114 NetLog::LogLevel
/* log_level */) {
115 DictionaryValue
* dict
= new DictionaryValue();
116 dict
->SetInteger("stream_id", frame
->stream_id
);
117 dict
->SetInteger("error_code", frame
->error_code
);
118 dict
->SetString("details", frame
->error_details
);
122 Value
* NetLogQuicConnectionCloseFrameCallback(
123 const QuicConnectionCloseFrame
* frame
,
124 NetLog::LogLevel
/* log_level */) {
125 DictionaryValue
* dict
= new DictionaryValue();
126 dict
->SetInteger("error_code", frame
->error_code
);
127 dict
->SetString("details", frame
->error_details
);
133 QuicConnectionLogger::QuicConnectionLogger(const BoundNetLog
& net_log
)
134 : net_log_(net_log
) {
137 QuicConnectionLogger::~QuicConnectionLogger() {
140 // QuicConnectionDebugVisitorInterface
141 void QuicConnectionLogger::OnPacketReceived(const IPEndPoint
& self_address
,
142 const IPEndPoint
& peer_address
,
143 const QuicEncryptedPacket
& packet
) {
145 NetLog::TYPE_QUIC_SESSION_PACKET_RECEIVED
,
146 base::Bind(&NetLogQuicPacketCallback
, &self_address
, &peer_address
,
150 void QuicConnectionLogger::OnProtocolVersionMismatch(
151 QuicVersionTag received_version
) {
152 // TODO(rtenneti): Add logging.
155 void QuicConnectionLogger::OnPacketHeader(const QuicPacketHeader
& header
) {
157 NetLog::TYPE_QUIC_SESSION_PACKET_HEADER_RECEIVED
,
158 base::Bind(&NetLogQuicPacketHeaderCallback
, &header
));
161 void QuicConnectionLogger::OnStreamFrame(const QuicStreamFrame
& frame
) {
163 NetLog::TYPE_QUIC_SESSION_STREAM_FRAME_RECEIVED
,
164 base::Bind(&NetLogQuicStreamFrameCallback
, &frame
));
167 void QuicConnectionLogger::OnAckFrame(const QuicAckFrame
& frame
) {
169 NetLog::TYPE_QUIC_SESSION_ACK_FRAME_RECEIVED
,
170 base::Bind(&NetLogQuicAckFrameCallback
, &frame
));
173 void QuicConnectionLogger::OnCongestionFeedbackFrame(
174 const QuicCongestionFeedbackFrame
& frame
) {
176 NetLog::TYPE_QUIC_SESSION_CONGESTION_FEEDBACK_FRAME_RECEIVED
,
177 base::Bind(&NetLogQuicCongestionFeedbackFrameCallback
, &frame
));
180 void QuicConnectionLogger::OnRstStreamFrame(const QuicRstStreamFrame
& frame
) {
182 NetLog::TYPE_QUIC_SESSION_RST_STREAM_FRAME_RECEIVED
,
183 base::Bind(&NetLogQuicRstStreamFrameCallback
, &frame
));
186 void QuicConnectionLogger::OnConnectionCloseFrame(
187 const QuicConnectionCloseFrame
& frame
) {
189 NetLog::TYPE_QUIC_SESSION_CONNECTION_CLOSE_FRAME_RECEIVED
,
190 base::Bind(&NetLogQuicConnectionCloseFrameCallback
, &frame
));
193 void QuicConnectionLogger::OnPublicResetPacket(
194 const QuicPublicResetPacket
& packet
) {
197 void QuicConnectionLogger::OnVersionNegotiationPacket(
198 const QuicVersionNegotiationPacket
& packet
) {
201 void QuicConnectionLogger::OnRevivedPacket(
202 const QuicPacketHeader
& revived_header
,
203 base::StringPiece payload
) {