packet_history.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * net/dccp/packet_history.h
  3. *
  4. * Copyright (c) 2005 The University of Waikato, Hamilton, New Zealand.
  5. *
  6. * An implementation of the DCCP protocol
  7. *
  8. * This code has been developed by the University of Waikato WAND
  9. * research group. For further information please see http://www.wand.net.nz/
  10. * or e-mail Ian McDonald - iam4@cs.waikato.ac.nz
  11. *
  12. * This code also uses code from Lulea University, rereleased as GPL by its
  13. * authors:
  14. * Copyright (c) 2003 Nils-Erik Mattsson, Joacim Haggmark, Magnus Erixzon
  15. *
  16. * Changes to meet Linux coding standards, to make it meet latest ccid3 draft
  17. * and to make it work as a loadable module in the DCCP stack written by
  18. * Arnaldo Carvalho de Melo <acme@conectiva.com.br>.
  19. *
  20. * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  21. *
  22. * This program is free software; you can redistribute it and/or modify
  23. * it under the terms of the GNU General Public License as published by
  24. * the Free Software Foundation; either version 2 of the License, or
  25. * (at your option) any later version.
  26. *
  27. * This program is distributed in the hope that it will be useful,
  28. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30. * GNU General Public License for more details.
  31. *
  32. * You should have received a copy of the GNU General Public License
  33. * along with this program; if not, write to the Free Software
  34. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  35. */
  36. #ifndef _DCCP_PKT_HIST_
  37. #define _DCCP_PKT_HIST_
  38. #include <linux/config.h>
  39. #include <linux/list.h>
  40. #include <linux/slab.h>
  41. #include <linux/time.h>
  42. #include "../../dccp.h"
  43. /* Number of later packets received before one is considered lost */
  44. #define TFRC_RECV_NUM_LATE_LOSS 3
  45. #define TFRC_WIN_COUNT_PER_RTT 4
  46. #define TFRC_WIN_COUNT_LIMIT 16
  47. struct dccp_tx_hist_entry {
  48. struct list_head dccphtx_node;
  49. u64 dccphtx_seqno:48,
  50. dccphtx_ccval:4,
  51. dccphtx_sent:1;
  52. u32 dccphtx_rtt;
  53. struct timeval dccphtx_tstamp;
  54. };
  55. struct dccp_rx_hist_entry {
  56. struct list_head dccphrx_node;
  57. u64 dccphrx_seqno:48,
  58. dccphrx_ccval:4,
  59. dccphrx_type:4;
  60. u32 dccphrx_ndp; /* In fact it is from 8 to 24 bits */
  61. struct timeval dccphrx_tstamp;
  62. };
  63. struct dccp_tx_hist {
  64. kmem_cache_t *dccptxh_slab;
  65. };
  66. extern struct dccp_tx_hist *dccp_tx_hist_new(const char *name);
  67. extern void dccp_tx_hist_delete(struct dccp_tx_hist *hist);
  68. struct dccp_rx_hist {
  69. kmem_cache_t *dccprxh_slab;
  70. };
  71. extern struct dccp_rx_hist *dccp_rx_hist_new(const char *name);
  72. extern void dccp_rx_hist_delete(struct dccp_rx_hist *hist);
  73. extern struct dccp_rx_hist_entry *
  74. dccp_rx_hist_find_data_packet(const struct list_head *list);
  75. static inline struct dccp_tx_hist_entry *
  76. dccp_tx_hist_entry_new(struct dccp_tx_hist *hist,
  77. const gfp_t prio)
  78. {
  79. struct dccp_tx_hist_entry *entry = kmem_cache_alloc(hist->dccptxh_slab,
  80. prio);
  81. if (entry != NULL)
  82. entry->dccphtx_sent = 0;
  83. return entry;
  84. }
  85. static inline void dccp_tx_hist_entry_delete(struct dccp_tx_hist *hist,
  86. struct dccp_tx_hist_entry *entry)
  87. {
  88. if (entry != NULL)
  89. kmem_cache_free(hist->dccptxh_slab, entry);
  90. }
  91. extern struct dccp_tx_hist_entry *
  92. dccp_tx_hist_find_entry(const struct list_head *list,
  93. const u64 seq);
  94. static inline void dccp_tx_hist_add_entry(struct list_head *list,
  95. struct dccp_tx_hist_entry *entry)
  96. {
  97. list_add(&entry->dccphtx_node, list);
  98. }
  99. extern void dccp_tx_hist_purge_older(struct dccp_tx_hist *hist,
  100. struct list_head *list,
  101. struct dccp_tx_hist_entry *next);
  102. extern void dccp_tx_hist_purge(struct dccp_tx_hist *hist,
  103. struct list_head *list);
  104. static inline struct dccp_tx_hist_entry *
  105. dccp_tx_hist_head(struct list_head *list)
  106. {
  107. struct dccp_tx_hist_entry *head = NULL;
  108. if (!list_empty(list))
  109. head = list_entry(list->next, struct dccp_tx_hist_entry,
  110. dccphtx_node);
  111. return head;
  112. }
  113. static inline struct dccp_rx_hist_entry *
  114. dccp_rx_hist_entry_new(struct dccp_rx_hist *hist,
  115. const struct sock *sk,
  116. const u32 ndp,
  117. const struct sk_buff *skb,
  118. const gfp_t prio)
  119. {
  120. struct dccp_rx_hist_entry *entry = kmem_cache_alloc(hist->dccprxh_slab,
  121. prio);
  122. if (entry != NULL) {
  123. const struct dccp_hdr *dh = dccp_hdr(skb);
  124. entry->dccphrx_seqno = DCCP_SKB_CB(skb)->dccpd_seq;
  125. entry->dccphrx_ccval = dh->dccph_ccval;
  126. entry->dccphrx_type = dh->dccph_type;
  127. entry->dccphrx_ndp = ndp;
  128. dccp_timestamp(sk, &entry->dccphrx_tstamp);
  129. }
  130. return entry;
  131. }
  132. static inline void dccp_rx_hist_entry_delete(struct dccp_rx_hist *hist,
  133. struct dccp_rx_hist_entry *entry)
  134. {
  135. if (entry != NULL)
  136. kmem_cache_free(hist->dccprxh_slab, entry);
  137. }
  138. extern void dccp_rx_hist_purge(struct dccp_rx_hist *hist,
  139. struct list_head *list);
  140. static inline void dccp_rx_hist_add_entry(struct list_head *list,
  141. struct dccp_rx_hist_entry *entry)
  142. {
  143. list_add(&entry->dccphrx_node, list);
  144. }
  145. static inline struct dccp_rx_hist_entry *
  146. dccp_rx_hist_head(struct list_head *list)
  147. {
  148. struct dccp_rx_hist_entry *head = NULL;
  149. if (!list_empty(list))
  150. head = list_entry(list->next, struct dccp_rx_hist_entry,
  151. dccphrx_node);
  152. return head;
  153. }
  154. static inline int
  155. dccp_rx_hist_entry_data_packet(const struct dccp_rx_hist_entry *entry)
  156. {
  157. return entry->dccphrx_type == DCCP_PKT_DATA ||
  158. entry->dccphrx_type == DCCP_PKT_DATAACK;
  159. }
  160. extern int dccp_rx_hist_add_packet(struct dccp_rx_hist *hist,
  161. struct list_head *rx_list,
  162. struct list_head *li_list,
  163. struct dccp_rx_hist_entry *packet);
  164. extern u64 dccp_rx_hist_detect_loss(struct list_head *rx_list,
  165. struct list_head *li_list, u8 *win_loss);
  166. #endif /* _DCCP_PKT_HIST_ */