packet_history.h revision e7c2335794b949292ecfd01902c429e2ac3937e1
1/*
2 *  net/dccp/packet_history.h
3 *
4 *  Copyright (c) 2005-6 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 - ian.mcdonald@jandi.co.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
37#ifndef _DCCP_PKT_HIST_
38#define _DCCP_PKT_HIST_
39
40#include <linux/ktime.h>
41#include <linux/list.h>
42#include <linux/slab.h>
43#include <linux/time.h>
44
45#include "../../dccp.h"
46
47/* Number of later packets received before one is considered lost */
48#define TFRC_RECV_NUM_LATE_LOSS	 3
49
50#define TFRC_WIN_COUNT_PER_RTT	 4
51#define TFRC_WIN_COUNT_LIMIT	16
52
53/*
54 * 	Transmitter History data structures and declarations
55 */
56struct dccp_tx_hist_entry {
57	struct list_head dccphtx_node;
58	u64		 dccphtx_seqno:48,
59			 dccphtx_sent:1;
60	u32		 dccphtx_rtt;
61	struct timeval	 dccphtx_tstamp;
62};
63
64struct dccp_tx_hist {
65	struct kmem_cache *dccptxh_slab;
66};
67
68extern struct dccp_tx_hist *dccp_tx_hist_new(const char *name);
69extern void 		    dccp_tx_hist_delete(struct dccp_tx_hist *hist);
70
71static inline struct dccp_tx_hist_entry *
72			dccp_tx_hist_entry_new(struct dccp_tx_hist *hist,
73					       const gfp_t prio)
74{
75	struct dccp_tx_hist_entry *entry = kmem_cache_alloc(hist->dccptxh_slab,
76							    prio);
77
78	if (entry != NULL)
79		entry->dccphtx_sent = 0;
80
81	return entry;
82}
83
84static inline struct dccp_tx_hist_entry *
85			dccp_tx_hist_head(struct list_head *list)
86{
87	struct dccp_tx_hist_entry *head = NULL;
88
89	if (!list_empty(list))
90		head = list_entry(list->next, struct dccp_tx_hist_entry,
91				  dccphtx_node);
92	return head;
93}
94
95extern struct dccp_tx_hist_entry *
96			dccp_tx_hist_find_entry(const struct list_head *list,
97						const u64 seq);
98
99static inline void dccp_tx_hist_add_entry(struct list_head *list,
100					  struct dccp_tx_hist_entry *entry)
101{
102	list_add(&entry->dccphtx_node, list);
103}
104
105static inline void dccp_tx_hist_entry_delete(struct dccp_tx_hist *hist,
106					     struct dccp_tx_hist_entry *entry)
107{
108	if (entry != NULL)
109		kmem_cache_free(hist->dccptxh_slab, entry);
110}
111
112extern void dccp_tx_hist_purge(struct dccp_tx_hist *hist,
113			       struct list_head *list);
114
115extern void dccp_tx_hist_purge_older(struct dccp_tx_hist *hist,
116				     struct list_head *list,
117				     struct dccp_tx_hist_entry *next);
118
119/*
120 * 	Receiver History data structures and declarations
121 */
122struct dccp_rx_hist_entry {
123	struct list_head dccphrx_node;
124	u64		 dccphrx_seqno:48,
125			 dccphrx_ccval:4,
126			 dccphrx_type:4;
127	u32		 dccphrx_ndp; /* In fact it is from 8 to 24 bits */
128	ktime_t		 dccphrx_tstamp;
129};
130
131struct dccp_rx_hist {
132	struct kmem_cache *dccprxh_slab;
133};
134
135extern struct dccp_rx_hist *dccp_rx_hist_new(const char *name);
136extern void 		dccp_rx_hist_delete(struct dccp_rx_hist *hist);
137
138static inline struct dccp_rx_hist_entry *
139			dccp_rx_hist_entry_new(struct dccp_rx_hist *hist,
140					       const u32 ndp,
141					       const struct sk_buff *skb,
142					       const gfp_t prio)
143{
144	struct dccp_rx_hist_entry *entry = kmem_cache_alloc(hist->dccprxh_slab,
145							    prio);
146
147	if (entry != NULL) {
148		const struct dccp_hdr *dh = dccp_hdr(skb);
149
150		entry->dccphrx_seqno = DCCP_SKB_CB(skb)->dccpd_seq;
151		entry->dccphrx_ccval = dh->dccph_ccval;
152		entry->dccphrx_type  = dh->dccph_type;
153		entry->dccphrx_ndp   = ndp;
154		entry->dccphrx_tstamp = ktime_get_real();
155	}
156
157	return entry;
158}
159
160static inline struct dccp_rx_hist_entry *
161			dccp_rx_hist_head(struct list_head *list)
162{
163	struct dccp_rx_hist_entry *head = NULL;
164
165	if (!list_empty(list))
166		head = list_entry(list->next, struct dccp_rx_hist_entry,
167				  dccphrx_node);
168	return head;
169}
170
171extern int dccp_rx_hist_find_entry(const struct list_head *list, const u64 seq,
172				   u8 *ccval);
173extern struct dccp_rx_hist_entry *
174		dccp_rx_hist_find_data_packet(const struct list_head *list);
175
176extern void dccp_rx_hist_add_packet(struct dccp_rx_hist *hist,
177				    struct list_head *rx_list,
178				    struct list_head *li_list,
179				    struct dccp_rx_hist_entry *packet,
180				    u64 nonloss_seqno);
181
182static inline void dccp_rx_hist_entry_delete(struct dccp_rx_hist *hist,
183					     struct dccp_rx_hist_entry *entry)
184{
185	if (entry != NULL)
186		kmem_cache_free(hist->dccprxh_slab, entry);
187}
188
189extern void dccp_rx_hist_purge(struct dccp_rx_hist *hist,
190			       struct list_head *list);
191
192static inline int
193	dccp_rx_hist_entry_data_packet(const struct dccp_rx_hist_entry *entry)
194{
195	return entry->dccphrx_type == DCCP_PKT_DATA ||
196	       entry->dccphrx_type == DCCP_PKT_DATAACK;
197}
198
199extern u64 dccp_rx_hist_detect_loss(struct list_head *rx_list,
200				    struct list_head *li_list, u8 *win_loss);
201
202#endif /* _DCCP_PKT_HIST_ */
203