packet_history.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. /**
  46. * tfrc_tx_hist_entry - Simple singly-linked TX history list
  47. * @next: next oldest entry (LIFO order)
  48. * @seqno: sequence number of this entry
  49. * @stamp: send time of packet with sequence number @seqno
  50. */
  51. struct tfrc_tx_hist_entry {
  52. struct tfrc_tx_hist_entry *next;
  53. u64 seqno;
  54. ktime_t stamp;
  55. };
  56. extern int tfrc_tx_hist_add(struct tfrc_tx_hist_entry **headp, u64 seqno);
  57. extern void tfrc_tx_hist_purge(struct tfrc_tx_hist_entry **headp);
  58. extern struct tfrc_tx_hist_entry *
  59. tfrc_tx_hist_find_entry(struct tfrc_tx_hist_entry *head, u64 ackno);
  60. /*
  61. * Receiver History data structures and declarations
  62. */
  63. struct dccp_rx_hist_entry {
  64. struct list_head dccphrx_node;
  65. u64 dccphrx_seqno:48,
  66. dccphrx_ccval:4,
  67. dccphrx_type:4;
  68. u32 dccphrx_ndp; /* In fact it is from 8 to 24 bits */
  69. ktime_t dccphrx_tstamp;
  70. };
  71. struct dccp_rx_hist {
  72. struct kmem_cache *dccprxh_slab;
  73. };
  74. extern struct dccp_rx_hist *dccp_rx_hist_new(const char *name);
  75. extern void dccp_rx_hist_delete(struct dccp_rx_hist *hist);
  76. static inline struct dccp_rx_hist_entry *
  77. dccp_rx_hist_entry_new(struct dccp_rx_hist *hist,
  78. const u32 ndp,
  79. const struct sk_buff *skb,
  80. const gfp_t prio)
  81. {
  82. struct dccp_rx_hist_entry *entry = kmem_cache_alloc(hist->dccprxh_slab,
  83. prio);
  84. if (entry != NULL) {
  85. const struct dccp_hdr *dh = dccp_hdr(skb);
  86. entry->dccphrx_seqno = DCCP_SKB_CB(skb)->dccpd_seq;
  87. entry->dccphrx_ccval = dh->dccph_ccval;
  88. entry->dccphrx_type = dh->dccph_type;
  89. entry->dccphrx_ndp = ndp;
  90. entry->dccphrx_tstamp = ktime_get_real();
  91. }
  92. return entry;
  93. }
  94. static inline struct dccp_rx_hist_entry *
  95. dccp_rx_hist_head(struct list_head *list)
  96. {
  97. struct dccp_rx_hist_entry *head = NULL;
  98. if (!list_empty(list))
  99. head = list_entry(list->next, struct dccp_rx_hist_entry,
  100. dccphrx_node);
  101. return head;
  102. }
  103. extern int dccp_rx_hist_find_entry(const struct list_head *list, const u64 seq,
  104. u8 *ccval);
  105. extern struct dccp_rx_hist_entry *
  106. dccp_rx_hist_find_data_packet(const struct list_head *list);
  107. extern void dccp_rx_hist_add_packet(struct dccp_rx_hist *hist,
  108. struct list_head *rx_list,
  109. struct list_head *li_list,
  110. struct dccp_rx_hist_entry *packet,
  111. u64 nonloss_seqno);
  112. static inline void dccp_rx_hist_entry_delete(struct dccp_rx_hist *hist,
  113. struct dccp_rx_hist_entry *entry)
  114. {
  115. if (entry != NULL)
  116. kmem_cache_free(hist->dccprxh_slab, entry);
  117. }
  118. extern void dccp_rx_hist_purge(struct dccp_rx_hist *hist,
  119. struct list_head *list);
  120. static inline int
  121. dccp_rx_hist_entry_data_packet(const struct dccp_rx_hist_entry *entry)
  122. {
  123. return entry->dccphrx_type == DCCP_PKT_DATA ||
  124. entry->dccphrx_type == DCCP_PKT_DATAACK;
  125. }
  126. extern u64 dccp_rx_hist_detect_loss(struct list_head *rx_list,
  127. struct list_head *li_list, u8 *win_loss);
  128. #endif /* _DCCP_PKT_HIST_ */