ngtcp2_qlog.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * ngtcp2
  3. *
  4. * Copyright (c) 2019 ngtcp2 contributors
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef NGTCP2_QLOG_H
  26. #define NGTCP2_QLOG_H
  27. #ifdef HAVE_CONFIG_H
  28. # include <config.h>
  29. #endif /* defined(HAVE_CONFIG_H) */
  30. #include <ngtcp2/ngtcp2.h>
  31. #include "ngtcp2_pkt.h"
  32. #include "ngtcp2_cc.h"
  33. #include "ngtcp2_buf.h"
  34. #include "ngtcp2_rtb.h"
  35. /* NGTCP2_QLOG_BUFLEN is the length of heap allocated buffer for
  36. qlog. */
  37. #define NGTCP2_QLOG_BUFLEN 4096
  38. typedef enum ngtcp2_qlog_side {
  39. NGTCP2_QLOG_SIDE_LOCAL,
  40. NGTCP2_QLOG_SIDE_REMOTE,
  41. } ngtcp2_qlog_side;
  42. typedef struct ngtcp2_qlog {
  43. /* write is a callback function to write qlog. */
  44. ngtcp2_qlog_write write;
  45. /* ts is the initial timestamp */
  46. ngtcp2_tstamp ts;
  47. /* last_ts is the timestamp observed last time. */
  48. ngtcp2_tstamp last_ts;
  49. /* buf is a heap allocated buffer to write exclusively
  50. packet_received and packet_sent. */
  51. ngtcp2_buf buf;
  52. /* user_data is an opaque pointer which is passed to write
  53. callback. */
  54. void *user_data;
  55. } ngtcp2_qlog;
  56. /*
  57. * ngtcp2_qlog_init initializes |qlog|.
  58. */
  59. void ngtcp2_qlog_init(ngtcp2_qlog *qlog, ngtcp2_qlog_write write,
  60. ngtcp2_tstamp ts, void *user_data);
  61. /*
  62. * ngtcp2_qlog_start writes qlog preamble.
  63. */
  64. void ngtcp2_qlog_start(ngtcp2_qlog *qlog, const ngtcp2_cid *odcid, int server);
  65. /*
  66. * ngtcp2_qlog_end writes closing part of qlog.
  67. */
  68. void ngtcp2_qlog_end(ngtcp2_qlog *qlog);
  69. /*
  70. * ngtcp2_qlog_write_frame writes |fr| to qlog->buf.
  71. * ngtcp2_qlog_pkt_received_start or ngtcp2_qlog_pkt_sent_start must
  72. * be called before calling this function.
  73. */
  74. void ngtcp2_qlog_write_frame(ngtcp2_qlog *qlog, const ngtcp2_frame *fr);
  75. /*
  76. * ngtcp2_qlog_pkt_received_start starts to write packet_received
  77. * event. It initializes qlog->buf. It writes qlog to qlog->buf.
  78. * ngtcp2_qlog_pkt_received_end will flush the content of qlog->buf to
  79. * write callback.
  80. */
  81. void ngtcp2_qlog_pkt_received_start(ngtcp2_qlog *qlog);
  82. /*
  83. * ngtcp2_qlog_pkt_received_end ends packet_received event and sends
  84. * the content of qlog->buf to qlog->write callback.
  85. */
  86. void ngtcp2_qlog_pkt_received_end(ngtcp2_qlog *qlog, const ngtcp2_pkt_hd *hd,
  87. size_t pktlen);
  88. /*
  89. * ngtcp2_qlog_pkt_sent_start starts to write packet_sent event. It
  90. * initializes qlog->buf. It writes qlog to qlog->buf.
  91. * ngtcp2_qlog_pkt_sent_end will flush the content of qlog->buf to
  92. * write callback.
  93. */
  94. void ngtcp2_qlog_pkt_sent_start(ngtcp2_qlog *qlog);
  95. /*
  96. * ngtcp2_qlog_pkt_sent_end ends packet_sent event and sends the
  97. * content of qlog->buf to qlog->write callback.
  98. */
  99. void ngtcp2_qlog_pkt_sent_end(ngtcp2_qlog *qlog, const ngtcp2_pkt_hd *hd,
  100. size_t pktlen);
  101. /*
  102. * ngtcp2_qlog_parameters_set_transport_params writes |params| to qlog
  103. * as parameters_set event. |server| is nonzero if the local endpoint
  104. * is server. If |local| is nonzero, it is "owner" field becomes
  105. * "local", otherwise "remote".
  106. */
  107. void ngtcp2_qlog_parameters_set_transport_params(
  108. ngtcp2_qlog *qlog, const ngtcp2_transport_params *params, int server,
  109. ngtcp2_qlog_side side);
  110. /*
  111. * ngtcp2_qlog_metrics_updated writes metrics_updated event of
  112. * recovery category.
  113. */
  114. void ngtcp2_qlog_metrics_updated(ngtcp2_qlog *qlog,
  115. const ngtcp2_conn_stat *cstat);
  116. /*
  117. * ngtcp2_qlog_pkt_lost writes packet_lost event.
  118. */
  119. void ngtcp2_qlog_pkt_lost(ngtcp2_qlog *qlog, ngtcp2_rtb_entry *ent);
  120. /*
  121. * ngtcp2_qlog_retry_pkt_received writes packet_received event for a
  122. * received Retry packet.
  123. */
  124. void ngtcp2_qlog_retry_pkt_received(ngtcp2_qlog *qlog, const ngtcp2_pkt_hd *hd,
  125. const ngtcp2_pkt_retry *retry);
  126. /*
  127. * ngtcp2_qlog_stateless_reset_pkt_received writes packet_received
  128. * event for a received Stateless Reset packet.
  129. */
  130. void ngtcp2_qlog_stateless_reset_pkt_received(
  131. ngtcp2_qlog *qlog, const ngtcp2_pkt_stateless_reset *sr);
  132. /*
  133. * ngtcp2_qlog_version_negotiation_pkt_received writes packet_received
  134. * event for a received Version Negotiation packet.
  135. */
  136. void ngtcp2_qlog_version_negotiation_pkt_received(ngtcp2_qlog *qlog,
  137. const ngtcp2_pkt_hd *hd,
  138. const uint32_t *sv,
  139. size_t nsv);
  140. #endif /* !defined(NGTCP2_QLOG_H) */