[CCID3]: Move ccid3_hc_rx_detect_loss to packet_history.c
[linux-2.6/kvm.git] / net / dccp / ccids / lib / packet_history.h
blobfb90a91aa93d64816789dc2c250fdebcd6923784
1 /*
2 * net/dccp/packet_history.h
4 * Copyright (c) 2005 The University of Waikato, Hamilton, New Zealand.
6 * An implementation of the DCCP protocol
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
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
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>.
20 * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
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.
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.
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.
37 #ifndef _DCCP_PKT_HIST_
38 #define _DCCP_PKT_HIST_
40 #include <linux/config.h>
41 #include <linux/list.h>
42 #include <linux/slab.h>
43 #include <linux/time.h>
45 #include "../../dccp.h"
47 /* Number of later packets received before one is considered lost */
48 #define TFRC_RECV_NUM_LATE_LOSS 3
50 #define TFRC_WIN_COUNT_PER_RTT 4
51 #define TFRC_WIN_COUNT_LIMIT 16
53 struct dccp_tx_hist_entry {
54 struct list_head dccphtx_node;
55 u64 dccphtx_seqno:48,
56 dccphtx_ccval:4,
57 dccphtx_sent:1;
58 u32 dccphtx_rtt;
59 struct timeval dccphtx_tstamp;
62 struct dccp_rx_hist_entry {
63 struct list_head dccphrx_node;
64 u64 dccphrx_seqno:48,
65 dccphrx_ccval:4,
66 dccphrx_type:4;
67 u32 dccphrx_ndp; /* In fact it is from 8 to 24 bits */
68 struct timeval dccphrx_tstamp;
71 struct dccp_tx_hist {
72 kmem_cache_t *dccptxh_slab;
75 extern struct dccp_tx_hist *dccp_tx_hist_new(const char *name);
76 extern void dccp_tx_hist_delete(struct dccp_tx_hist *hist);
78 struct dccp_rx_hist {
79 kmem_cache_t *dccprxh_slab;
82 extern struct dccp_rx_hist *dccp_rx_hist_new(const char *name);
83 extern void dccp_rx_hist_delete(struct dccp_rx_hist *hist);
84 extern struct dccp_rx_hist_entry *
85 dccp_rx_hist_find_data_packet(const struct list_head *list);
87 static inline struct dccp_tx_hist_entry *
88 dccp_tx_hist_entry_new(struct dccp_tx_hist *hist,
89 const unsigned int __nocast prio)
91 struct dccp_tx_hist_entry *entry = kmem_cache_alloc(hist->dccptxh_slab,
92 prio);
94 if (entry != NULL)
95 entry->dccphtx_sent = 0;
97 return entry;
100 static inline void dccp_tx_hist_entry_delete(struct dccp_tx_hist *hist,
101 struct dccp_tx_hist_entry *entry)
103 if (entry != NULL)
104 kmem_cache_free(hist->dccptxh_slab, entry);
107 extern struct dccp_tx_hist_entry *
108 dccp_tx_hist_find_entry(const struct list_head *list,
109 const u64 seq);
111 static inline void dccp_tx_hist_add_entry(struct list_head *list,
112 struct dccp_tx_hist_entry *entry)
114 list_add(&entry->dccphtx_node, list);
117 extern void dccp_tx_hist_purge_older(struct dccp_tx_hist *hist,
118 struct list_head *list,
119 struct dccp_tx_hist_entry *next);
121 extern void dccp_tx_hist_purge(struct dccp_tx_hist *hist,
122 struct list_head *list);
124 static inline struct dccp_tx_hist_entry *
125 dccp_tx_hist_head(struct list_head *list)
127 struct dccp_tx_hist_entry *head = NULL;
129 if (!list_empty(list))
130 head = list_entry(list->next, struct dccp_tx_hist_entry,
131 dccphtx_node);
132 return head;
135 static inline struct dccp_rx_hist_entry *
136 dccp_rx_hist_entry_new(struct dccp_rx_hist *hist,
137 const u32 ndp,
138 const struct sk_buff *skb,
139 const unsigned int __nocast prio)
141 struct dccp_rx_hist_entry *entry = kmem_cache_alloc(hist->dccprxh_slab,
142 prio);
144 if (entry != NULL) {
145 const struct dccp_hdr *dh = dccp_hdr(skb);
147 entry->dccphrx_seqno = DCCP_SKB_CB(skb)->dccpd_seq;
148 entry->dccphrx_ccval = dh->dccph_ccval;
149 entry->dccphrx_type = dh->dccph_type;
150 entry->dccphrx_ndp = ndp;
151 do_gettimeofday(&(entry->dccphrx_tstamp));
154 return entry;
157 static inline void dccp_rx_hist_entry_delete(struct dccp_rx_hist *hist,
158 struct dccp_rx_hist_entry *entry)
160 if (entry != NULL)
161 kmem_cache_free(hist->dccprxh_slab, entry);
164 extern void dccp_rx_hist_purge(struct dccp_rx_hist *hist,
165 struct list_head *list);
167 static inline void dccp_rx_hist_add_entry(struct list_head *list,
168 struct dccp_rx_hist_entry *entry)
170 list_add(&entry->dccphrx_node, list);
173 static inline struct dccp_rx_hist_entry *
174 dccp_rx_hist_head(struct list_head *list)
176 struct dccp_rx_hist_entry *head = NULL;
178 if (!list_empty(list))
179 head = list_entry(list->next, struct dccp_rx_hist_entry,
180 dccphrx_node);
181 return head;
184 static inline int
185 dccp_rx_hist_entry_data_packet(const struct dccp_rx_hist_entry *entry)
187 return entry->dccphrx_type == DCCP_PKT_DATA ||
188 entry->dccphrx_type == DCCP_PKT_DATAACK;
191 extern int dccp_rx_hist_add_packet(struct dccp_rx_hist *hist,
192 struct list_head *rx_list,
193 struct list_head *li_list,
194 struct dccp_rx_hist_entry *packet);
196 extern u64 dccp_rx_hist_detect_loss(struct list_head *rx_list,
197 struct list_head *li_list, u8 *win_loss);
199 #endif /* _DCCP_PKT_HIST_ */