packet_history.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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/ktime.h>
  38. #include <linux/list.h>
  39. #include <linux/slab.h>
  40. #include "../../dccp.h"
  41. /* Number of later packets received before one is considered lost */
  42. #define TFRC_RECV_NUM_LATE_LOSS 3
  43. #define TFRC_WIN_COUNT_PER_RTT 4
  44. #define TFRC_WIN_COUNT_LIMIT 16
  45. struct tfrc_tx_hist_entry;
  46. extern int tfrc_tx_hist_add(struct tfrc_tx_hist_entry **headp, u64 seqno);
  47. extern void tfrc_tx_hist_purge(struct tfrc_tx_hist_entry **headp);
  48. extern u32 tfrc_tx_hist_rtt(struct tfrc_tx_hist_entry *head,
  49. const u64 seqno, const ktime_t now);
  50. /*
  51. * Receiver History data structures and declarations
  52. */
  53. struct dccp_rx_hist_entry {
  54. struct list_head dccphrx_node;
  55. u64 dccphrx_seqno:48,
  56. dccphrx_ccval:4,
  57. dccphrx_type:4;
  58. u32 dccphrx_ndp; /* In fact it is from 8 to 24 bits */
  59. ktime_t dccphrx_tstamp;
  60. };
  61. struct dccp_rx_hist {
  62. struct kmem_cache *dccprxh_slab;
  63. };
  64. extern struct dccp_rx_hist *dccp_rx_hist_new(const char *name);
  65. extern void dccp_rx_hist_delete(struct dccp_rx_hist *hist);
  66. static inline struct dccp_rx_hist_entry *
  67. dccp_rx_hist_entry_new(struct dccp_rx_hist *hist,
  68. const u32 ndp,
  69. const struct sk_buff *skb,
  70. const gfp_t prio)
  71. {
  72. struct dccp_rx_hist_entry *entry = kmem_cache_alloc(hist->dccprxh_slab,
  73. prio);
  74. if (entry != NULL) {
  75. const struct dccp_hdr *dh = dccp_hdr(skb);
  76. entry->dccphrx_seqno = DCCP_SKB_CB(skb)->dccpd_seq;
  77. entry->dccphrx_ccval = dh->dccph_ccval;
  78. entry->dccphrx_type = dh->dccph_type;
  79. entry->dccphrx_ndp = ndp;
  80. entry->dccphrx_tstamp = ktime_get_real();
  81. }
  82. return entry;
  83. }
  84. static inline struct dccp_rx_hist_entry *
  85. dccp_rx_hist_head(struct list_head *list)
  86. {
  87. struct dccp_rx_hist_entry *head = NULL;
  88. if (!list_empty(list))
  89. head = list_entry(list->next, struct dccp_rx_hist_entry,
  90. dccphrx_node);
  91. return head;
  92. }
  93. extern int dccp_rx_hist_find_entry(const struct list_head *list, const u64 seq,
  94. u8 *ccval);
  95. extern struct dccp_rx_hist_entry *
  96. dccp_rx_hist_find_data_packet(const struct list_head *list);
  97. extern void dccp_rx_hist_add_packet(struct dccp_rx_hist *hist,
  98. struct list_head *rx_list,
  99. struct list_head *li_list,
  100. struct dccp_rx_hist_entry *packet,
  101. u64 nonloss_seqno);
  102. static inline void dccp_rx_hist_entry_delete(struct dccp_rx_hist *hist,
  103. struct dccp_rx_hist_entry *entry)
  104. {
  105. if (entry != NULL)
  106. kmem_cache_free(hist->dccprxh_slab, entry);
  107. }
  108. extern void dccp_rx_hist_purge(struct dccp_rx_hist *hist,
  109. struct list_head *list);
  110. static inline int
  111. dccp_rx_hist_entry_data_packet(const struct dccp_rx_hist_entry *entry)
  112. {
  113. return entry->dccphrx_type == DCCP_PKT_DATA ||
  114. entry->dccphrx_type == DCCP_PKT_DATAACK;
  115. }
  116. extern u64 dccp_rx_hist_detect_loss(struct list_head *rx_list,
  117. struct list_head *li_list, u8 *win_loss);
  118. #endif /* _DCCP_PKT_HIST_ */