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