loss_interval.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef _DCCP_LI_HIST_
  3. #define _DCCP_LI_HIST_
  4. /*
  5. * Copyright (c) 2007 The University of Aberdeen, Scotland, UK
  6. * Copyright (c) 2005-7 The University of Waikato, Hamilton, New Zealand.
  7. * Copyright (c) 2005-7 Ian McDonald <ian.mcdonald@jandi.co.nz>
  8. * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  9. */
  10. #include <linux/ktime.h>
  11. #include <linux/list.h>
  12. #include <linux/slab.h>
  13. /*
  14. * Number of loss intervals (RFC 4342, 8.6.1). The history size is one more than
  15. * NINTERVAL, since the `open' interval I_0 is always stored as the first entry.
  16. */
  17. #define NINTERVAL 8
  18. #define LIH_SIZE (NINTERVAL + 1)
  19. /**
  20. * tfrc_loss_interval - Loss history record for TFRC-based protocols
  21. * @li_seqno: Highest received seqno before the start of loss
  22. * @li_ccval: The CCVal belonging to @li_seqno
  23. * @li_is_closed: Whether @li_seqno is older than 1 RTT
  24. * @li_length: Loss interval sequence length
  25. */
  26. struct tfrc_loss_interval {
  27. u64 li_seqno:48,
  28. li_ccval:4,
  29. li_is_closed:1;
  30. u32 li_length;
  31. };
  32. /**
  33. * tfrc_loss_hist - Loss record database
  34. * @ring: Circular queue managed in LIFO manner
  35. * @counter: Current count of entries (can be more than %LIH_SIZE)
  36. * @i_mean: Current Average Loss Interval [RFC 3448, 5.4]
  37. */
  38. struct tfrc_loss_hist {
  39. struct tfrc_loss_interval *ring[LIH_SIZE];
  40. u8 counter;
  41. u32 i_mean;
  42. };
  43. static inline void tfrc_lh_init(struct tfrc_loss_hist *lh)
  44. {
  45. memset(lh, 0, sizeof(struct tfrc_loss_hist));
  46. }
  47. static inline u8 tfrc_lh_is_initialised(struct tfrc_loss_hist *lh)
  48. {
  49. return lh->counter > 0;
  50. }
  51. static inline u8 tfrc_lh_length(struct tfrc_loss_hist *lh)
  52. {
  53. return min(lh->counter, (u8)LIH_SIZE);
  54. }
  55. struct tfrc_rx_hist;
  56. int tfrc_lh_interval_add(struct tfrc_loss_hist *, struct tfrc_rx_hist *,
  57. u32 (*first_li)(struct sock *), struct sock *);
  58. u8 tfrc_lh_update_i_mean(struct tfrc_loss_hist *lh, struct sk_buff *);
  59. void tfrc_lh_cleanup(struct tfrc_loss_hist *lh);
  60. #endif /* _DCCP_LI_HIST_ */