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