• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-
2  * Copyright (c) 2007-2008
3  * 	Swinburne University of Technology, Melbourne, Australia.
4  * Copyright (c) 2009-2010 Lawrence Stewart <lstewart@freebsd.org>
5  * Copyright (c) 2010 The FreeBSD Foundation
6  * All rights reserved.
7  *
8  * This software was developed at the Centre for Advanced Internet
9  * Architectures, Swinburne University of Technology, by Lawrence Stewart and
10  * James Healy, made possible in part by a grant from the Cisco University
11  * Research Program Fund at Community Foundation Silicon Valley.
12  *
13  * Portions of this software were developed at the Centre for Advanced
14  * Internet Architectures, Swinburne University of Technology, Melbourne,
15  * Australia by David Hayes under sponsorship from the FreeBSD Foundation.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions
19  * are met:
20  * 1. Redistributions of source code must retain the above copyright
21  *    notice, this list of conditions and the following disclaimer.
22  * 2. Redistributions in binary form must reproduce the above copyright
23  *    notice, this list of conditions and the following disclaimer in the
24  *    documentation and/or other materials provided with the distribution.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  * $FreeBSD$
39  */
40 
41 /*
42  * This software was first released in 2007 by James Healy and Lawrence Stewart
43  * whilst working on the NewTCP research project at Swinburne University of
44  * Technology's Centre for Advanced Internet Architectures, Melbourne,
45  * Australia, which was made possible in part by a grant from the Cisco
46  * University Research Program Fund at Community Foundation Silicon Valley.
47  * More details are available at:
48  *   http://caia.swin.edu.au/urp/newtcp/
49  */
50 
51 /*
52  * samkumar: The FreeBSD implementation supports many congestion control
53  * algorithms, each represented by a struct. Each tcpcb has a pointer to the
54  * relevant congestion control struct, and the congestion control structs are
55  * themselves part of an intrusive linked list. TCPlp hardcodes the congestion
56  * control algorithm to New Reno, so the fields corresponding to maintaining
57  * the global linked list are removed.
58  */
59 
60 #ifndef TCPLP_NETINET_CC_H_
61 #define TCPLP_NETINET_CC_H_
62 
63 /* XXX: TCP_CA_NAME_MAX define lives in tcp.h for compat reasons. */
64 #include "tcp.h"
65 
66 extern const struct cc_algo newreno_cc_algo;
67 
68 /*
69  * Wrapper around transport structs that contain same-named congestion
70  * control variables. Allows algos to be shared amongst multiple CC aware
71  * transprots.
72  */
73 struct cc_var {
74 	void		*cc_data; /* Per-connection private CC algorithm data. */
75 	int		bytes_this_ack; /* # bytes acked by the current ACK. */
76 	tcp_seq		curack; /* Most recent ACK. */
77 	uint32_t	flags; /* Flags for cc_var (see below) */
78 	/* samkumar: removing type, since TCPlp uses TCP congestion control. */
79 	//int		type; /* Indicates which ptr is valid in ccvc. */
80 	union ccv_container {
81 		struct tcpcb		*tcp;
82 		struct sctp_nets	*sctp;
83 	} ccvc;
84 };
85 
86 /* cc_var flags. */
87 #define	CCF_ABC_SENTAWND	0x0001	/* ABC counted cwnd worth of bytes? */
88 #define	CCF_CWND_LIMITED	0x0002	/* Are we currently cwnd limited? */
89 #define	CCF_DELACK		0x0004	/* Is this ack delayed? */
90 #define	CCF_ACKNOW		0x0008	/* Will this ack be sent now? */
91 #define	CCF_IPHDR_CE		0x0010	/* Does this packet set CE bit? */
92 #define	CCF_TCPHDR_CWR		0x0020	/* Does this packet set CWR bit? */
93 
94 /* ACK types passed to the ack_received() hook. */
95 #define	CC_ACK		0x0001	/* Regular in sequence ACK. */
96 #define	CC_DUPACK	0x0002	/* Duplicate ACK. */
97 #define	CC_PARTIALACK	0x0004	/* Not yet. */
98 #define	CC_SACK		0x0008	/* Not yet. */
99 
100 /*
101  * Congestion signal types passed to the cong_signal() hook. The highest order 8
102  * bits (0x01000000 - 0x80000000) are reserved for CC algos to declare their own
103  * congestion signal types.
104  */
105 #define	CC_ECN		0x00000001	/* ECN marked packet received. */
106 #define	CC_RTO		0x00000002	/* RTO fired. */
107 #define	CC_RTO_ERR	0x00000004	/* RTO fired in error. */
108 #define	CC_NDUPACK	0x00000008	/* Threshold of dupack's reached. */
109 
110 #define	CC_SIGPRIVMASK	0xFF000000	/* Mask to check if sig is private. */
111 
112 /*
113  * Structure to hold data and function pointers that together represent a
114  * congestion control algorithm.
115  */
116 struct cc_algo {
117 	char	name[TCP_CA_NAME_MAX];
118 
119 	/* Init global module state on kldload. */
120 	int	(*mod_init)(void);
121 
122 	/* Cleanup global module state on kldunload. */
123 	int	(*mod_destroy)(void);
124 
125 	/* Init CC state for a new control block. */
126 	int	(*cb_init)(struct cc_var *ccv);
127 
128 	/* Cleanup CC state for a terminating control block. */
129 	void	(*cb_destroy)(struct cc_var *ccv);
130 
131 	/* Init variables for a newly established connection. */
132 	void	(*conn_init)(struct cc_var *ccv);
133 
134 	/* Called on receipt of an ack. */
135 	void	(*ack_received)(struct cc_var *ccv, uint16_t type);
136 
137 	/* Called on detection of a congestion signal. */
138 	void	(*cong_signal)(struct cc_var *ccv, uint32_t type);
139 
140 	/* Called after exiting congestion recovery. */
141 	void	(*post_recovery)(struct cc_var *ccv);
142 
143 	/* Called when data transfer resumes after an idle period. */
144 	void	(*after_idle)(struct cc_var *ccv);
145 
146 	/* Called for an additional ECN processing apart from RFC3168. */
147 	void	(*ecnpkt_handler)(struct cc_var *ccv);
148 
149 	/*
150 	 * samkumar: This field is removed since we no longer use the intrusive
151 	 * linked list.
152 	 */
153 	//STAILQ_ENTRY (cc_algo) entries;
154 };
155 
156 /* Macro to obtain the CC algo's struct ptr. */
157 //#define	CC_ALGO(tp)	((tp)->cc_algo)
158 #define CC_ALGO(tp) (&newreno_cc_algo) // samkumar: This allows the #defines in cc_newreno.c to work as intended
159 
160 /* Macro to obtain the CC algo's data ptr. */
161 #define	CC_DATA(tp)	((tp)->ccv->cc_data)
162 
163 #endif /* _NETINET_CC_H_ */
164