2 * net/dccp/packet_history.c
4 * Copyright (c) 2005-6 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 - ian.mcdonald@jandi.co.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/module.h>
38 #include <linux/string.h>
39 #include "packet_history.h"
42 * Transmitter History Routines
44 struct dccp_tx_hist
*dccp_tx_hist_new(const char *name
)
46 struct dccp_tx_hist
*hist
= kmalloc(sizeof(*hist
), GFP_ATOMIC
);
47 static const char dccp_tx_hist_mask
[] = "tx_hist_%s";
53 slab_name
= kmalloc(strlen(name
) + sizeof(dccp_tx_hist_mask
) - 1,
55 if (slab_name
== NULL
)
58 sprintf(slab_name
, dccp_tx_hist_mask
, name
);
59 hist
->dccptxh_slab
= kmem_cache_create(slab_name
,
60 sizeof(struct dccp_tx_hist_entry
),
61 0, SLAB_HWCACHE_ALIGN
,
63 if (hist
->dccptxh_slab
== NULL
)
64 goto out_free_slab_name
;
75 EXPORT_SYMBOL_GPL(dccp_tx_hist_new
);
77 void dccp_tx_hist_delete(struct dccp_tx_hist
*hist
)
79 const char* name
= kmem_cache_name(hist
->dccptxh_slab
);
81 kmem_cache_destroy(hist
->dccptxh_slab
);
86 EXPORT_SYMBOL_GPL(dccp_tx_hist_delete
);
88 struct dccp_tx_hist_entry
*
89 dccp_tx_hist_find_entry(const struct list_head
*list
, const u64 seq
)
91 struct dccp_tx_hist_entry
*packet
= NULL
, *entry
;
93 list_for_each_entry(entry
, list
, dccphtx_node
)
94 if (entry
->dccphtx_seqno
== seq
) {
102 EXPORT_SYMBOL_GPL(dccp_tx_hist_find_entry
);
104 void dccp_tx_hist_purge(struct dccp_tx_hist
*hist
, struct list_head
*list
)
106 struct dccp_tx_hist_entry
*entry
, *next
;
108 list_for_each_entry_safe(entry
, next
, list
, dccphtx_node
) {
109 list_del_init(&entry
->dccphtx_node
);
110 dccp_tx_hist_entry_delete(hist
, entry
);
114 EXPORT_SYMBOL_GPL(dccp_tx_hist_purge
);
116 void dccp_tx_hist_purge_older(struct dccp_tx_hist
*hist
,
117 struct list_head
*list
,
118 struct dccp_tx_hist_entry
*packet
)
120 struct dccp_tx_hist_entry
*next
;
122 list_for_each_entry_safe_continue(packet
, next
, list
, dccphtx_node
) {
123 list_del_init(&packet
->dccphtx_node
);
124 dccp_tx_hist_entry_delete(hist
, packet
);
128 EXPORT_SYMBOL_GPL(dccp_tx_hist_purge_older
);
131 * Receiver History Routines
133 struct dccp_rx_hist
*dccp_rx_hist_new(const char *name
)
135 struct dccp_rx_hist
*hist
= kmalloc(sizeof(*hist
), GFP_ATOMIC
);
136 static const char dccp_rx_hist_mask
[] = "rx_hist_%s";
142 slab_name
= kmalloc(strlen(name
) + sizeof(dccp_rx_hist_mask
) - 1,
144 if (slab_name
== NULL
)
147 sprintf(slab_name
, dccp_rx_hist_mask
, name
);
148 hist
->dccprxh_slab
= kmem_cache_create(slab_name
,
149 sizeof(struct dccp_rx_hist_entry
),
150 0, SLAB_HWCACHE_ALIGN
,
152 if (hist
->dccprxh_slab
== NULL
)
153 goto out_free_slab_name
;
164 EXPORT_SYMBOL_GPL(dccp_rx_hist_new
);
166 void dccp_rx_hist_delete(struct dccp_rx_hist
*hist
)
168 const char* name
= kmem_cache_name(hist
->dccprxh_slab
);
170 kmem_cache_destroy(hist
->dccprxh_slab
);
175 EXPORT_SYMBOL_GPL(dccp_rx_hist_delete
);
177 int dccp_rx_hist_find_entry(const struct list_head
*list
, const u64 seq
,
180 struct dccp_rx_hist_entry
*packet
= NULL
, *entry
;
182 list_for_each_entry(entry
, list
, dccphrx_node
)
183 if (entry
->dccphrx_seqno
== seq
) {
189 *ccval
= packet
->dccphrx_ccval
;
191 return packet
!= NULL
;
194 EXPORT_SYMBOL_GPL(dccp_rx_hist_find_entry
);
195 struct dccp_rx_hist_entry
*
196 dccp_rx_hist_find_data_packet(const struct list_head
*list
)
198 struct dccp_rx_hist_entry
*entry
, *packet
= NULL
;
200 list_for_each_entry(entry
, list
, dccphrx_node
)
201 if (entry
->dccphrx_type
== DCCP_PKT_DATA
||
202 entry
->dccphrx_type
== DCCP_PKT_DATAACK
) {
210 EXPORT_SYMBOL_GPL(dccp_rx_hist_find_data_packet
);
212 void dccp_rx_hist_add_packet(struct dccp_rx_hist
*hist
,
213 struct list_head
*rx_list
,
214 struct list_head
*li_list
,
215 struct dccp_rx_hist_entry
*packet
,
218 struct dccp_rx_hist_entry
*entry
, *next
;
221 list_add(&packet
->dccphrx_node
, rx_list
);
223 num_later
= TFRC_RECV_NUM_LATE_LOSS
+ 1;
225 if (!list_empty(li_list
)) {
226 list_for_each_entry_safe(entry
, next
, rx_list
, dccphrx_node
) {
227 if (num_later
== 0) {
228 if (after48(nonloss_seqno
,
229 entry
->dccphrx_seqno
)) {
230 list_del_init(&entry
->dccphrx_node
);
231 dccp_rx_hist_entry_delete(hist
, entry
);
233 } else if (dccp_rx_hist_entry_data_packet(entry
))
238 u8 win_count
= 0; /* Not needed, but lets shut up gcc */
241 * We have no loss interval history so we need at least one
242 * rtt:s of data packets to approximate rtt.
244 list_for_each_entry_safe(entry
, next
, rx_list
, dccphrx_node
) {
245 if (num_later
== 0) {
249 /* OK, find next data packet */
254 /* OK, find next data packet */
256 win_count
= entry
->dccphrx_ccval
;
259 tmp
= win_count
- entry
->dccphrx_ccval
;
261 tmp
+= TFRC_WIN_COUNT_LIMIT
;
262 if (tmp
> TFRC_WIN_COUNT_PER_RTT
+ 1) {
264 * We have found a packet older
265 * than one rtt remove the rest
268 } else /* OK, find next data packet */
272 list_del_init(&entry
->dccphrx_node
);
273 dccp_rx_hist_entry_delete(hist
, entry
);
276 } else if (dccp_rx_hist_entry_data_packet(entry
))
282 EXPORT_SYMBOL_GPL(dccp_rx_hist_add_packet
);
284 void dccp_rx_hist_purge(struct dccp_rx_hist
*hist
, struct list_head
*list
)
286 struct dccp_rx_hist_entry
*entry
, *next
;
288 list_for_each_entry_safe(entry
, next
, list
, dccphrx_node
) {
289 list_del_init(&entry
->dccphrx_node
);
290 kmem_cache_free(hist
->dccprxh_slab
, entry
);
294 EXPORT_SYMBOL_GPL(dccp_rx_hist_purge
);
297 MODULE_AUTHOR("Ian McDonald <ian.mcdonald@jandi.co.nz>, "
298 "Arnaldo Carvalho de Melo <acme@ghostprotocols.net>");
299 MODULE_DESCRIPTION("DCCP TFRC library");
300 MODULE_LICENSE("GPL");