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
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 #include <linux/config.h>
38 #include <linux/module.h>
39 #include <linux/string.h>
41 #include "packet_history.h"
43 struct dccp_rx_hist
*dccp_rx_hist_new(const char *name
)
45 struct dccp_rx_hist
*hist
= kmalloc(sizeof(*hist
), GFP_ATOMIC
);
46 static const char dccp_rx_hist_mask
[] = "rx_hist_%s";
52 slab_name
= kmalloc(strlen(name
) + sizeof(dccp_rx_hist_mask
) - 1,
54 if (slab_name
== NULL
)
57 sprintf(slab_name
, dccp_rx_hist_mask
, name
);
58 hist
->dccprxh_slab
= kmem_cache_create(slab_name
,
59 sizeof(struct dccp_rx_hist_entry
),
60 0, SLAB_HWCACHE_ALIGN
,
62 if (hist
->dccprxh_slab
== NULL
)
63 goto out_free_slab_name
;
74 EXPORT_SYMBOL_GPL(dccp_rx_hist_new
);
76 void dccp_rx_hist_delete(struct dccp_rx_hist
*hist
)
78 const char* name
= kmem_cache_name(hist
->dccprxh_slab
);
80 kmem_cache_destroy(hist
->dccprxh_slab
);
85 EXPORT_SYMBOL_GPL(dccp_rx_hist_delete
);
87 void dccp_rx_hist_purge(struct dccp_rx_hist
*hist
, struct list_head
*list
)
89 struct dccp_rx_hist_entry
*entry
, *next
;
91 list_for_each_entry_safe(entry
, next
, list
, dccphrx_node
) {
92 list_del_init(&entry
->dccphrx_node
);
93 kmem_cache_free(hist
->dccprxh_slab
, entry
);
97 EXPORT_SYMBOL_GPL(dccp_rx_hist_purge
);
99 struct dccp_rx_hist_entry
*
100 dccp_rx_hist_find_data_packet(const struct list_head
*list
)
102 struct dccp_rx_hist_entry
*entry
, *packet
= NULL
;
104 list_for_each_entry(entry
, list
, dccphrx_node
)
105 if (entry
->dccphrx_type
== DCCP_PKT_DATA
||
106 entry
->dccphrx_type
== DCCP_PKT_DATAACK
) {
114 EXPORT_SYMBOL_GPL(dccp_rx_hist_find_data_packet
);
116 int dccp_rx_hist_add_packet(struct dccp_rx_hist
*hist
,
117 struct list_head
*rx_list
,
118 struct list_head
*li_list
,
119 struct dccp_rx_hist_entry
*packet
)
121 struct dccp_rx_hist_entry
*entry
, *next
, *iter
;
124 iter
= dccp_rx_hist_head(rx_list
);
126 dccp_rx_hist_add_entry(rx_list
, packet
);
128 const u64 seqno
= packet
->dccphrx_seqno
;
130 if (after48(seqno
, iter
->dccphrx_seqno
))
131 dccp_rx_hist_add_entry(rx_list
, packet
);
133 if (dccp_rx_hist_entry_data_packet(iter
))
136 list_for_each_entry_continue(iter
, rx_list
,
138 if (after48(seqno
, iter
->dccphrx_seqno
)) {
139 dccp_rx_hist_add_entry(&iter
->dccphrx_node
,
144 if (dccp_rx_hist_entry_data_packet(iter
))
147 if (num_later
== TFRC_RECV_NUM_LATE_LOSS
) {
148 dccp_rx_hist_entry_delete(hist
, packet
);
153 if (num_later
< TFRC_RECV_NUM_LATE_LOSS
)
154 dccp_rx_hist_add_entry(rx_list
, packet
);
156 * FIXME: else what? should we destroy the packet
164 * Trim history (remove all packets after the NUM_LATE_LOSS + 1
167 num_later
= TFRC_RECV_NUM_LATE_LOSS
+ 1;
169 if (!list_empty(li_list
)) {
170 list_for_each_entry_safe(entry
, next
, rx_list
, dccphrx_node
) {
171 if (num_later
== 0) {
172 list_del_init(&entry
->dccphrx_node
);
173 dccp_rx_hist_entry_delete(hist
, entry
);
174 } else if (dccp_rx_hist_entry_data_packet(entry
))
179 u8 win_count
= 0; /* Not needed, but lets shut up gcc */
182 * We have no loss interval history so we need at least one
183 * rtt:s of data packets to approximate rtt.
185 list_for_each_entry_safe(entry
, next
, rx_list
, dccphrx_node
) {
186 if (num_later
== 0) {
190 /* OK, find next data packet */
195 /* OK, find next data packet */
197 win_count
= entry
->dccphrx_ccval
;
200 tmp
= win_count
- entry
->dccphrx_ccval
;
202 tmp
+= TFRC_WIN_COUNT_LIMIT
;
203 if (tmp
> TFRC_WIN_COUNT_PER_RTT
+ 1) {
205 * We have found a packet older
206 * than one rtt remove the rest
209 } else /* OK, find next data packet */
213 list_del_init(&entry
->dccphrx_node
);
214 dccp_rx_hist_entry_delete(hist
, entry
);
217 } else if (dccp_rx_hist_entry_data_packet(entry
))
225 EXPORT_SYMBOL_GPL(dccp_rx_hist_add_packet
);
227 u64
dccp_rx_hist_detect_loss(struct list_head
*rx_list
,
228 struct list_head
*li_list
, u8
*win_loss
)
230 struct dccp_rx_hist_entry
*entry
, *next
, *packet
;
231 struct dccp_rx_hist_entry
*a_loss
= NULL
;
232 struct dccp_rx_hist_entry
*b_loss
= NULL
;
233 u64 seq_loss
= DCCP_MAX_SEQNO
+ 1;
234 u8 num_later
= TFRC_RECV_NUM_LATE_LOSS
;
236 list_for_each_entry_safe(entry
, next
, rx_list
, dccphrx_node
) {
237 if (num_later
== 0) {
240 } else if (dccp_rx_hist_entry_data_packet(entry
))
248 list_for_each_entry_safe_continue(entry
, next
, rx_list
, dccphrx_node
) {
249 if (num_later
== 0) {
252 } else if (dccp_rx_hist_entry_data_packet(entry
))
256 if (a_loss
== NULL
) {
257 if (list_empty(li_list
)) {
258 /* no loss event have occured yet */
259 LIMIT_NETDEBUG("%s: TODO: find a lost data packet by "
260 "comparing to initial seqno\n",
264 LIMIT_NETDEBUG("%s: Less than 4 data pkts in history!",
270 /* Locate a lost data packet */
271 entry
= packet
= b_loss
;
272 list_for_each_entry_safe_continue(entry
, next
, rx_list
, dccphrx_node
) {
273 u64 delta
= dccp_delta_seqno(entry
->dccphrx_seqno
,
274 packet
->dccphrx_seqno
);
277 if (dccp_rx_hist_entry_data_packet(packet
))
280 * FIXME: check this, probably this % usage is because
281 * in earlier drafts the ndp count was just 8 bits
282 * long, but now it cam be up to 24 bits long.
285 if (delta
% DCCP_NDP_LIMIT
!=
286 (packet
->dccphrx_ndp
-
287 entry
->dccphrx_ndp
) % DCCP_NDP_LIMIT
)
289 if (delta
!= packet
->dccphrx_ndp
- entry
->dccphrx_ndp
) {
290 seq_loss
= entry
->dccphrx_seqno
;
291 dccp_inc_seqno(&seq_loss
);
295 if (packet
== a_loss
)
299 if (seq_loss
!= DCCP_MAX_SEQNO
+ 1)
300 *win_loss
= a_loss
->dccphrx_ccval
;
302 *win_loss
= 0; /* Paranoia */
307 EXPORT_SYMBOL_GPL(dccp_rx_hist_detect_loss
);
309 struct dccp_tx_hist
*dccp_tx_hist_new(const char *name
)
311 struct dccp_tx_hist
*hist
= kmalloc(sizeof(*hist
), GFP_ATOMIC
);
312 static const char dccp_tx_hist_mask
[] = "tx_hist_%s";
318 slab_name
= kmalloc(strlen(name
) + sizeof(dccp_tx_hist_mask
) - 1,
320 if (slab_name
== NULL
)
323 sprintf(slab_name
, dccp_tx_hist_mask
, name
);
324 hist
->dccptxh_slab
= kmem_cache_create(slab_name
,
325 sizeof(struct dccp_tx_hist_entry
),
326 0, SLAB_HWCACHE_ALIGN
,
328 if (hist
->dccptxh_slab
== NULL
)
329 goto out_free_slab_name
;
340 EXPORT_SYMBOL_GPL(dccp_tx_hist_new
);
342 void dccp_tx_hist_delete(struct dccp_tx_hist
*hist
)
344 const char* name
= kmem_cache_name(hist
->dccptxh_slab
);
346 kmem_cache_destroy(hist
->dccptxh_slab
);
351 EXPORT_SYMBOL_GPL(dccp_tx_hist_delete
);
353 struct dccp_tx_hist_entry
*
354 dccp_tx_hist_find_entry(const struct list_head
*list
, const u64 seq
)
356 struct dccp_tx_hist_entry
*packet
= NULL
, *entry
;
358 list_for_each_entry(entry
, list
, dccphtx_node
)
359 if (entry
->dccphtx_seqno
== seq
) {
367 EXPORT_SYMBOL_GPL(dccp_tx_hist_find_entry
);
369 void dccp_tx_hist_purge_older(struct dccp_tx_hist
*hist
,
370 struct list_head
*list
,
371 struct dccp_tx_hist_entry
*packet
)
373 struct dccp_tx_hist_entry
*next
;
375 list_for_each_entry_safe_continue(packet
, next
, list
, dccphtx_node
) {
376 list_del_init(&packet
->dccphtx_node
);
377 dccp_tx_hist_entry_delete(hist
, packet
);
381 EXPORT_SYMBOL_GPL(dccp_tx_hist_purge_older
);
383 void dccp_tx_hist_purge(struct dccp_tx_hist
*hist
, struct list_head
*list
)
385 struct dccp_tx_hist_entry
*entry
, *next
;
387 list_for_each_entry_safe(entry
, next
, list
, dccphtx_node
) {
388 list_del_init(&entry
->dccphtx_node
);
389 dccp_tx_hist_entry_delete(hist
, entry
);
393 EXPORT_SYMBOL_GPL(dccp_tx_hist_purge
);
395 MODULE_AUTHOR("Ian McDonald <iam4@cs.waikato.ac.nz>, "
396 "Arnaldo Carvalho de Melo <acme@ghostprotocols.net>");
397 MODULE_DESCRIPTION("DCCP TFRC library");
398 MODULE_LICENSE("GPL");