packet_history.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Packet RX/TX history data structures and routines for TFRC-based protocols.
  3. *
  4. * Copyright (c) 2007 The University of Aberdeen, Scotland, UK
  5. * Copyright (c) 2005-6 The University of Waikato, Hamilton, New Zealand.
  6. *
  7. * This code has been developed by the University of Waikato WAND
  8. * research group. For further information please see http://www.wand.net.nz/
  9. * or e-mail Ian McDonald - ian.mcdonald@jandi.co.nz
  10. *
  11. * This code also uses code from Lulea University, rereleased as GPL by its
  12. * authors:
  13. * Copyright (c) 2003 Nils-Erik Mattsson, Joacim Haggmark, Magnus Erixzon
  14. *
  15. * Changes to meet Linux coding standards, to make it meet latest ccid3 draft
  16. * and to make it work as a loadable module in the DCCP stack written by
  17. * Arnaldo Carvalho de Melo <acme@conectiva.com.br>.
  18. *
  19. * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  20. *
  21. * This program is free software; you can redistribute it and/or modify
  22. * it under the terms of the GNU General Public License as published by
  23. * the Free Software Foundation; either version 2 of the License, or
  24. * (at your option) any later version.
  25. *
  26. * This program is distributed in the hope that it will be useful,
  27. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  29. * GNU General Public License for more details.
  30. *
  31. * You should have received a copy of the GNU General Public License
  32. * along with this program; if not, write to the Free Software
  33. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  34. */
  35. #ifndef _DCCP_PKT_HIST_
  36. #define _DCCP_PKT_HIST_
  37. #include <linux/list.h>
  38. #include <linux/slab.h>
  39. #include "tfrc.h"
  40. struct tfrc_tx_hist_entry;
  41. extern int tfrc_tx_hist_add(struct tfrc_tx_hist_entry **headp, u64 seqno);
  42. extern void tfrc_tx_hist_purge(struct tfrc_tx_hist_entry **headp);
  43. extern u32 tfrc_tx_hist_rtt(struct tfrc_tx_hist_entry *head,
  44. const u64 seqno, const ktime_t now);
  45. /* Subtraction a-b modulo-16, respects circular wrap-around */
  46. #define SUB16(a, b) (((a) + 16 - (b)) & 0xF)
  47. /* Number of packets to wait after a missing packet (RFC 4342, 6.1) */
  48. #define TFRC_NDUPACK 3
  49. /**
  50. * tfrc_rx_hist_entry - Store information about a single received packet
  51. * @tfrchrx_seqno: DCCP packet sequence number
  52. * @tfrchrx_ccval: window counter value of packet (RFC 4342, 8.1)
  53. * @tfrchrx_ndp: the NDP count (if any) of the packet
  54. * @tfrchrx_tstamp: actual receive time of packet
  55. */
  56. struct tfrc_rx_hist_entry {
  57. u64 tfrchrx_seqno:48,
  58. tfrchrx_ccval:4,
  59. tfrchrx_type:4;
  60. u64 tfrchrx_ndp:48;
  61. ktime_t tfrchrx_tstamp;
  62. };
  63. /**
  64. * tfrc_rx_hist - RX history structure for TFRC-based protocols
  65. *
  66. * @ring: Packet history for RTT sampling and loss detection
  67. * @loss_count: Number of entries in circular history
  68. * @loss_start: Movable index (for loss detection)
  69. * @rtt_sample_prev: Used during RTT sampling, points to candidate entry
  70. */
  71. struct tfrc_rx_hist {
  72. struct tfrc_rx_hist_entry *ring[TFRC_NDUPACK + 1];
  73. u8 loss_count:2,
  74. loss_start:2;
  75. #define rtt_sample_prev loss_start
  76. };
  77. /**
  78. * tfrc_rx_hist_index - index to reach n-th entry after loss_start
  79. */
  80. static inline u8 tfrc_rx_hist_index(const struct tfrc_rx_hist *h, const u8 n)
  81. {
  82. return (h->loss_start + n) & TFRC_NDUPACK;
  83. }
  84. /**
  85. * tfrc_rx_hist_last_rcv - entry with highest-received-seqno so far
  86. */
  87. static inline struct tfrc_rx_hist_entry *
  88. tfrc_rx_hist_last_rcv(const struct tfrc_rx_hist *h)
  89. {
  90. return h->ring[tfrc_rx_hist_index(h, h->loss_count)];
  91. }
  92. /**
  93. * tfrc_rx_hist_entry - return the n-th history entry after loss_start
  94. */
  95. static inline struct tfrc_rx_hist_entry *
  96. tfrc_rx_hist_entry(const struct tfrc_rx_hist *h, const u8 n)
  97. {
  98. return h->ring[tfrc_rx_hist_index(h, n)];
  99. }
  100. /**
  101. * tfrc_rx_hist_loss_prev - entry with highest-received-seqno before loss was detected
  102. */
  103. static inline struct tfrc_rx_hist_entry *
  104. tfrc_rx_hist_loss_prev(const struct tfrc_rx_hist *h)
  105. {
  106. return h->ring[h->loss_start];
  107. }
  108. /* indicate whether previously a packet was detected missing */
  109. static inline bool tfrc_rx_hist_loss_pending(const struct tfrc_rx_hist *h)
  110. {
  111. return h->loss_count > 0;
  112. }
  113. extern void tfrc_rx_hist_add_packet(struct tfrc_rx_hist *h,
  114. const struct sk_buff *skb, const u64 ndp);
  115. extern int tfrc_rx_hist_duplicate(struct tfrc_rx_hist *h, struct sk_buff *skb);
  116. struct tfrc_loss_hist;
  117. extern int tfrc_rx_handle_loss(struct tfrc_rx_hist *h,
  118. struct tfrc_loss_hist *lh,
  119. struct sk_buff *skb, const u64 ndp,
  120. u32 (*first_li)(struct sock *sk),
  121. struct sock *sk);
  122. extern u32 tfrc_rx_hist_sample_rtt(struct tfrc_rx_hist *h,
  123. const struct sk_buff *skb);
  124. extern int tfrc_rx_hist_alloc(struct tfrc_rx_hist *h);
  125. extern void tfrc_rx_hist_purge(struct tfrc_rx_hist *h);
  126. #endif /* _DCCP_PKT_HIST_ */